Package com.sun.jersey.api.client

Examples of com.sun.jersey.api.client.ClientResponse


    @Test
    public void testNoModifications() throws Exception {
        when(photoProvider.getPhotoInputStream("mf.jpg")).thenReturn(getImage("mf.jpg"));

        ClientResponse response = client().resource("/mf.jpg").get(ClientResponse.class);
        assertThat(response.getEntity(byte[].class), is(ByteStreams.toByteArray(getImage("mf.jpg"))));
        assertThat(response.getType().toString(), is("image/jpeg"));
    }
View Full Code Here


    @Test
    public void test404() throws Exception {
        when(photoProvider.getPhotoInputStream("doesntexist.jpg")).thenThrow(new FileNotFoundException());

        ClientResponse response = client().resource("/doesntexist.jpg").get(ClientResponse.class);
        assertThat(response.getStatus(), is(404));
    }
View Full Code Here

    @Test
    public void testFitWidth() throws Exception {
        when(photoProvider.getPhotoInputStream("mf.jpg")).thenReturn(getImage("mf.jpg"));

        ClientResponse response = client().resource("/mf.jpg;w=200").get(ClientResponse.class);
        assertThat(response.getType().toString(), is("image/jpeg"));
        BufferedImage result = ImageIO.read(response.getEntity(InputStream.class));
        assertThat(result.getWidth(), is(200));
    }
View Full Code Here

        int initialHeight = initialImage.getHeight();
        int initialWidth = initialImage.getWidth();

        when(photoProvider.getPhotoInputStream("mf.jpg")).thenReturn(getImage("mf.jpg"));

        ClientResponse response = client().resource("/mf.jpg;r=90").get(ClientResponse.class);
        assertThat(response.getType().toString(), is("image/jpeg"));
        BufferedImage result = ImageIO.read(response.getEntity(InputStream.class));
        assertThat(result.getWidth(), is(initialHeight));
        assertThat(result.getHeight(), is(initialWidth));
    }
View Full Code Here

        int w = 20;
        int h = 200;

        when(photoProvider.getPhotoInputStream("mf.jpg")).thenReturn(getImage("mf.jpg"));

        ClientResponse response = client().resource("/mf.jpg;c=" + x + "," + y + "," + w + "," + h).get(ClientResponse.class);
        assertThat(response.getType().toString(), is("image/jpeg"));
        BufferedImage result = ImageIO.read(response.getEntity(InputStream.class));
        assertThat(result.getWidth(), is(w));
        assertThat(result.getHeight(), is(h));
    }
View Full Code Here

    @Test
    public void testPNG() throws Exception {
        when(photoProvider.getPhotoInputStream("liz.png")).thenReturn(getImage("liz.png"));

        ClientResponse response = client().resource("/liz.png;w=200").get(ClientResponse.class);
        assertThat(response.getType().toString(), is("image/png"));
        BufferedImage result = ImageIO.read(response.getEntity(InputStream.class));
        assertThat(result.getWidth(), is(200));
    }
View Full Code Here

    @Test
    public void testUnsupportedType() throws Exception {
        when(photoProvider.getPhotoInputStream("fake.tiff")).thenReturn(new ByteArrayInputStream(new byte[]{1, 2, 3}));

        ClientResponse response = client().resource("/fake.tiff;w=200").get(ClientResponse.class);
        assertThat(response.getStatus(), is(501));
    }
View Full Code Here

        }
        if (jSessionId != null) {
            builder.header("Cookie", "JSESSIONID=" + jSessionId);
        }

        ClientResponse response = null;

        response = (ClientResponse) builder.get(ClientResponse.class);

        if (response.getClientResponseStatus() == ClientResponse.Status.NO_CONTENT) {
            return null;
        } else if (response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) {
            return response.getEntityInputStream();
        } else {
            throw new ApiException(
                    response.getClientResponseStatus().getStatusCode(),
                    response.getEntity(String.class));
        }
    }
View Full Code Here

        }
        if (jSessionId != null) {
            builder.header("Cookie", "JSESSIONID=" + jSessionId);
        }

        ClientResponse response = null;

        if ("GET".equals(method)) {
            response = (ClientResponse) builder.get(ClientResponse.class);
        } else if ("POST".equals(method)) {
            builder.header("Lumify-CSRF-Token", this.csrfToken);
            if (body == null) {
                response = builder.post(ClientResponse.class, serialize(body));
            } else if (body instanceof FormDataMultiPart) {
                response = builder.type(contentType).post(ClientResponse.class, body);
            } else {
                response = builder.type(contentType).post(ClientResponse.class, serialize(body));
            }
        } else if ("PUT".equals(method)) {
            builder.header("Lumify-CSRF-Token", this.csrfToken);
            if (body == null) {
                response = builder.put(ClientResponse.class, serialize(body));
            } else {
                if ("application/x-www-form-urlencoded".equals(contentType)) {
                    StringBuilder formParamBuilder = new StringBuilder();

                    // encode the form params
                    for (String key : formParams.keySet()) {
                        String value = formParams.get(key);
                        if (value != null && !"".equals(value.trim())) {
                            if (formParamBuilder.length() > 0) {
                                formParamBuilder.append("&");
                            }
                            try {
                                formParamBuilder.append(URLEncoder.encode(key, "utf8")).append("=").append(URLEncoder.encode(value, "utf8"));
                            } catch (Exception e) {
                                // move on to next
                            }
                        }
                    }
                    response = builder.type(contentType).put(ClientResponse.class, formParamBuilder.toString());
                } else
                    response = builder.type(contentType).put(ClientResponse.class, serialize(body));
            }
        } else if ("DELETE".equals(method)) {
            builder.header("Lumify-CSRF-Token", this.csrfToken);
            if (body == null) {
                response = builder.delete(ClientResponse.class, serialize(body));
            } else {
                response = builder.type(contentType).delete(ClientResponse.class, serialize(body));
            }
        } else {
            throw new ApiException(500, "unknown method type " + method);
        }
        if (response.getClientResponseStatus() == ClientResponse.Status.NO_CONTENT) {
            return null;
        } else if (response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) {
            return (String) response.getEntity(String.class);
        } else {
            throw new ApiException(
                    response.getClientResponseStatus().getStatusCode(),
                    response.getEntity(String.class));
        }
    }
View Full Code Here

     * with status "OK".
     */
    @Test
    public void testGetOnDataResource() {
        WebResource webResource = resource();
        ClientResponse response = webResource.path("data")
                .accept(MediaType.TEXT_HTML)
                .get(ClientResponse.class);
        assertEquals("Request for data doesn't give expected response.",
                Response.Status.OK, response.getResponseStatus());
    }
View Full Code Here

TOP

Related Classes of com.sun.jersey.api.client.ClientResponse

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.