Package org.springframework.http.client

Examples of org.springframework.http.client.ClientHttpRequest


        return examples.getString((String) examples.keys().next());
    }

    @Test
    public void testGetStatus_InvalidRef() throws Exception {
        ClientHttpRequest request = getPrintRequest(MapPrinterServlet.STATUS_URL + "/invalid-ref-number.json", HttpMethod.GET);
        response = request.execute();
        assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
    }
View Full Code Here


        assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
    }

    @Test
    public void testGetDownload_InvalidRef() throws Exception {
        ClientHttpRequest request = getPrintRequest(MapPrinterServlet.REPORT_URL + "/invalid-ref-number", HttpMethod.GET);
        response = request.execute();
        assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
    }
View Full Code Here

        assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
    }

    @Test
    public void testCancel_InvalidRef() throws Exception {
        ClientHttpRequest request = getPrintRequest(MapPrinterServlet.CANCEL_URL + "/invalid-ref-number", HttpMethod.DELETE);
        response = request.execute();
        assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
    }
View Full Code Here

        assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
    }

    @Test
    public void testCancel() throws Exception {
        ClientHttpRequest request = getPrintRequest("geoext" + MapPrinterServlet.REPORT_URL + ".png", HttpMethod.POST);
        setPrintSpec(getPrintSpec("examples/geoext/requestData.json"), request);
        response = request.execute();
        assertEquals(HttpStatus.OK, response.getStatusCode());
        assertEquals(getJsonMediaType(), response.getHeaders().getContentType());

        String responseAsText = getBodyAsText(response);
        response.close();

        JSONObject createResult = new JSONObject(responseAsText);
        String ref = createResult.getString(MapPrinterServlet.JSON_PRINT_JOB_REF);

        request = getPrintRequest(MapPrinterServlet.CANCEL_URL + "/" + ref, HttpMethod.DELETE);
        response = request.execute();
        assertEquals(HttpStatus.OK, response.getStatusCode());
        response.close();

        request = getPrintRequest(MapPrinterServlet.STATUS_URL + "/" + ref + ".json", HttpMethod.GET);
        response = request.execute();
        assertEquals(HttpStatus.OK, response.getStatusCode());
        final JSONObject statusResult = new JSONObject(
                getBodyAsText(response));
        assertTrue(statusResult.getBoolean(MapPrinterServlet.JSON_DONE));
        assertEquals("task canceled", statusResult.getString(MapPrinterServlet.JSON_ERROR));
View Full Code Here

        assertRequiresAuth("sec/print" + MapPrinterServlet.CAPABILITIES_URL);
        assertRequiresAuth("sec/print/dep/info.json");
    }

    private void assertRequiresAuth(String path) throws IOException, URISyntaxException {
        ClientHttpRequest request = getRequest(path, HttpMethod.GET);
        HttpURLConnection urlConnection = (HttpURLConnection) request.getURI().toURL().openConnection();
        assertEquals(HttpStatus.FOUND.value(), urlConnection.getResponseCode());
        assertEquals("https://localhost:8443/print-servlet/"+path, urlConnection.getHeaderField("Location"));
        urlConnection.disconnect();
    }
View Full Code Here

        urlConnection.disconnect();
    }

    @Test
    public void testSecuredTemplate_CreateMap() throws Exception {
        ClientHttpRequest request = getPrintRequest("secured_templates" + MapPrinterServlet.CREATE_AND_GET_URL + ".pdf", HttpMethod.POST);
        final String printSpec = getPrintSpec("examples/secured_templates/requestData.json").replace("\"A4 landscape\"", "\"secured\"");
        setPrintSpec(printSpec, request);
        response = request.execute();
        assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
        response.close();

        execCreateRequestWithAuth("jimi:jimi", HttpStatus.OK, printSpec);
        execCreateRequestWithAuth("bob:bob", HttpStatus.FORBIDDEN, printSpec);
View Full Code Here

        execCreateRequestWithAuth("bob:bob", HttpStatus.FORBIDDEN, printSpec);

    }

    private JSONArray execCapabilitiesRequestWithAut(int expectedNumberOfLayouts, String credentials) throws IOException, URISyntaxException, JSONException {
        ClientHttpRequest request = getPrintRequest("secured_templates" + MapPrinterServlet.CAPABILITIES_URL, HttpMethod.GET);
        if (credentials != null) {
            addAuthHeader(request, credentials);
        }
        response = request.execute();
        assertEquals(HttpStatus.OK, response.getStatusCode());

        String responseAsText = getBodyAsText(response);
        response.close();
View Full Code Here

        assertEquals(expectedNumberOfLayouts, layouts.length());
        return layouts;
    }

    private void execCreateRequestWithAuth(String credentials, HttpStatus expectedStatus, String printSpec) throws IOException, URISyntaxException {
        ClientHttpRequest request = getPrintRequest("secured_templates" + MapPrinterServlet.CREATE_AND_GET_URL + ".pdf", HttpMethod.POST);
        setPrintSpec(printSpec, request);
        addAuthHeader(request, credentials);
        response = request.execute();
        assertEquals(response.getStatusText(), expectedStatus, response.getStatusCode());
        response.close();
    }
View Full Code Here

        boolean done = false;
        do {
            ClientHttpResponse response = null;

            try {
                ClientHttpRequest request = getPrintRequest(
                        MapPrinterServlet.STATUS_URL + "/" + ref + ".json", HttpMethod.GET);
                response = request.execute();
                final JSONObject statusResult = new JSONObject(
                        getBodyAsText(response));
                done = statusResult.getBoolean(MapPrinterServlet.JSON_DONE);

                if (!done) {
View Full Code Here

                uri = new URI(styleRef);
            } catch (URISyntaxException e) {
                uri = new File(styleRef).toURI();
            }

            final ClientHttpRequest request = clientHttpRequestFactory.createRequest(uri, HttpMethod.GET);
            final ClientHttpResponse response = closer.register(request.execute());
            statusCode = response.getStatusCode();
            input = ByteStreams.toByteArray(response.getBody());
        } catch (Exception e) {
            return Optional.absent();
        } finally {
View Full Code Here

TOP

Related Classes of org.springframework.http.client.ClientHttpRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.