Package org.springframework.http.client

Examples of org.springframework.http.client.ClientHttpRequest


        checkExampleRequest(getBodyAsText(response));
    }

    @Test
    public void testExampleRequestJsonp_App() throws Exception {
        ClientHttpRequest request = getPrintRequest("geoext" + MapPrinterServlet.EXAMPLE_REQUEST_URL + "?jsonp=exampleRequest", HttpMethod.GET);
        response = request.execute();
        assertEquals(HttpStatus.OK, response.getStatusCode());
        assertEquals(getJavaScriptMediaType(), response.getHeaders().getContentType());

        String responseAsText = getBodyAsText(response);
        assertTrue(responseAsText.startsWith("exampleRequest("));
View Full Code Here


        assertTrue(sampleRequest.has("attributes"));
    }

    @Test
    public void testCreateReport_WrongMethod() throws Exception {
        ClientHttpRequest request = getPrintRequest("geoext" + MapPrinterServlet.REPORT_URL + ".pdf", HttpMethod.GET);
        response = request.execute();
        assertEquals(HttpStatus.METHOD_NOT_ALLOWED, response.getStatusCode());
    }
View Full Code Here

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

    @Test
    public void testCreateReport_NoBody() throws Exception {
        ClientHttpRequest request = getPrintRequest("geoext" + MapPrinterServlet.REPORT_URL + ".pdf", HttpMethod.POST);
        response = request.execute();
        assertNotEquals(HttpStatus.OK, response.getStatusCode());
    }
View Full Code Here

        assertNotEquals(HttpStatus.OK, response.getStatusCode());
    }

    @Test
    public void testCreateReport_InvalidSpec() throws Exception {
        ClientHttpRequest request = getPrintRequest("geoext" + MapPrinterServlet.REPORT_URL + ".pdf", HttpMethod.POST);
        setPrintSpec("{", request);
        response = request.execute();
        assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
    }
View Full Code Here

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

    @Test
    public void testCreateReport_RequestTooLarge() throws Exception {
        ClientHttpRequest request = getPrintRequest("geoext" + MapPrinterServlet.REPORT_URL + ".pdf", HttpMethod.POST);
        final String printSpec = getPrintSpec("examples/geoext/requestData.json");
       
        // create a large, fake request
        StringBuilder largeRequest = new StringBuilder();
        for (int i = 0; i < 9999; i++) {
            largeRequest.append(printSpec);
        }
       
        setPrintSpec(largeRequest.toString(), request);
        response = request.execute();
        assertNotEquals(HttpStatus.OK, response.getStatusCode());
    }
View Full Code Here

        testCreateReport(MapPrinterServlet.REPORT_URL + ".pdf", printSpec);
    }

    private void testCreateReport(String requestPath, String printSpec) throws Exception,
            JSONException, Exception {
        ClientHttpRequest request = getPrintRequest(requestPath, HttpMethod.POST);
        setPrintSpec(printSpec, request);
        response = request.execute();
        assertEquals(HttpStatus.OK, response.getStatusCode());
        assertEquals(getJsonMediaType(), response.getHeaders().getContentType());

        String responseAsText = getBodyAsText(response);
        JSONObject createResult = new JSONObject(responseAsText);

        String ref = createResult.getString(MapPrinterServlet.JSON_PRINT_JOB_REF);
        String statusUrl = createResult.getString(MapPrinterServlet.JSON_STATUS_LINK);
        String downloadUrl = createResult.getString(MapPrinterServlet.JSON_DOWNLOAD_LINK);
        assertEquals("/print-servlet/print/status/" + ref + ".json", statusUrl);
        assertEquals("/print-servlet/print/report/" + ref, downloadUrl);
        response.close();

        // check status
        request = getPrintRequest(MapPrinterServlet.STATUS_URL + "/" + ref + ".json", HttpMethod.GET);
        response = request.execute();
        assertEquals(HttpStatus.OK, response.getStatusCode());
        assertEquals(getJsonMediaType(), response.getHeaders().getContentType());

        responseAsText = getBodyAsText(response);
        JSONObject statusResult = new JSONObject(responseAsText);

        assertTrue(statusResult.has(MapPrinterServlet.JSON_DONE));
        assertEquals(downloadUrl, statusResult.getString(MapPrinterServlet.JSON_DOWNLOAD_LINK));
        response.close();

        // check status with JSONP
        request = getPrintRequest(MapPrinterServlet.STATUS_URL + "/" + ref + ".json?jsonp=getStatus", HttpMethod.GET);
        response = request.execute();
        assertEquals(HttpStatus.OK, response.getStatusCode());
        assertEquals(getJavaScriptMediaType(), response.getHeaders().getContentType());

        responseAsText = getBodyAsText(response);
        assertTrue(responseAsText.startsWith("getStatus("));

        responseAsText = responseAsText.replace("getStatus(", "").replace(");", "");
        statusResult = new JSONObject(responseAsText);

        assertTrue(statusResult.has(MapPrinterServlet.JSON_DONE));
        assertEquals(downloadUrl, statusResult.getString(MapPrinterServlet.JSON_DOWNLOAD_LINK));
        response.close();

        waitUntilDoneOrError(ref);

        // check download
        request = getPrintRequest(MapPrinterServlet.REPORT_URL + "/" + ref, HttpMethod.GET);
        response = request.execute();
        assertEquals(HttpStatus.OK, response.getStatusCode());
        assertEquals(new MediaType("application", "pdf"), response.getHeaders().getContentType());
        assertTrue(response.getBody().read() >= 0);
    }
View Full Code Here

        assertTrue(response.getBody().read() >= 0);
    }

    @Test(timeout = 60000)
    public void testCreateReport_InvalidFormat() throws Exception {
        ClientHttpRequest request = getPrintRequest("geoext" + MapPrinterServlet.REPORT_URL + ".docx", 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);

        waitUntilDoneOrError(ref);

        // check status
        request = getPrintRequest(MapPrinterServlet.STATUS_URL + "/" + ref + ".json", HttpMethod.GET);
        response = request.execute();
        assertEquals(HttpStatus.OK, response.getStatusCode());
        assertEquals(getJsonMediaType(), response.getHeaders().getContentType());

        responseAsText = getBodyAsText(response);
        JSONObject statusResult = new JSONObject(responseAsText);
View Full Code Here

        assertTrue(statusResult.has(MapPrinterServlet.JSON_ERROR));
    }

    @Test(timeout = 60000)
    public void testCreateReport_Success_App_PNG() 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);

        waitUntilDoneOrError(ref);

        // check download
        request = getPrintRequest(MapPrinterServlet.REPORT_URL + "/" + ref, HttpMethod.GET);
        response = request.execute();
        assertEquals(HttpStatus.OK, response.getStatusCode());
        assertEquals(MediaType.IMAGE_PNG, response.getHeaders().getContentType());
        assertTrue(response.getBody().read() >= 0);
    }
View Full Code Here

        assertTrue(response.getBody().read() >= 0);
    }

    @Test(timeout = 60000)
    public void testCreateAndGetReport_Success_App() throws Exception {
        ClientHttpRequest request = getPrintRequest("geoext" + MapPrinterServlet.CREATE_AND_GET_URL + ".pdf", HttpMethod.POST);
        setPrintSpec(getPrintSpec("examples/geoext/requestData.json"), request);
        response = request.execute();
        assertEquals(HttpStatus.OK, response.getStatusCode());
        assertEquals(new MediaType("application", "pdf"), response.getHeaders().getContentType());
        assertTrue(response.getBody().read() >= 0);
    }
View Full Code Here

        assertTrue(response.getBody().read() >= 0);
    }

    @Test//(timeout = 60000)
    public void testCreateAndGetReport_Success_NoApp() throws Exception {
        ClientHttpRequest request = getPrintRequest(MapPrinterServlet.CREATE_AND_GET_URL + ".pdf", HttpMethod.POST);
        String example = getDefaultAppDefaultRequestSample();
        setPrintSpec(example, request);
        response = request.execute();
        assertEquals(HttpStatus.OK, response.getStatusCode());
        assertEquals(new MediaType("application", "pdf"), response.getHeaders().getContentType());
        assertTrue(response.getBody().read() >= 0);
    }
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.