Package org.apache.wink.client

Examples of org.apache.wink.client.ClientResponse


     * {@link Produces} method results in 200 successful method invocation.
     *
     * @throws IOException
     */
    public void testNoAcceptHeaderIncomingRequestWithProducesMethod() throws IOException {
        ClientResponse response =
            client.resource(getBaseURI() + "/targeting/nullresource/withproduces").post(null);
        assertEquals(200, response.getStatusCode());
        assertEquals("calledWithProduces", response.getEntity(String.class));
        assertEquals("custom/type", response.getHeaders().getFirst("Content-Type"));
    }
View Full Code Here


     * {@link Produces} method results in 200 successful method invocation.
     *
     * @throws IOException
     */
    public void testNoAcceptHeaderIncomingRequestWithNoProducesMethod() throws IOException {
        ClientResponse response =
            client.resource(getBaseURI() + "/targeting/nullresource/withoutproduces").post(null);
        assertEquals(200, response.getStatusCode());
        assertEquals("calledWithoutProduces", response.getEntity(String.class));
        String contentType =
            (response.getHeaders().getFirst("Content-Type") == null) ? null : response.getHeaders()
                .getFirst("Content-Type");
        assertNotNull(contentType, contentType);
    }
View Full Code Here

        ByteArrayOutputStream originalContent = new ByteArrayOutputStream();
        for (int c = 0; c < 5000000; ++c) {
            originalContent.write(c);
        }
        byte[] entity = originalContent.toByteArray();
        ClientResponse response =
            client.resource(new URI(getBaseURI() + "/large")).contentType(MediaType.TEXT_XML_TYPE)
                .post(entity);
        assertEquals(277, response.getStatusCode());

        InputStream respStream = response.getEntity(InputStream.class);
        for (int c = 0; c < entity.length; ++c) {
            int respByte = respStream.read();
            assertEquals(entity[c] % 256, (byte)respByte);
        }

        StringBuffer sb = new StringBuffer();
        for (int c = 0; c < 50; ++c) {
            sb.append("abcdefghijklmnopqrstuvwxyz");
        }
        assertEquals(sb.toString(), response.getHeaders().getFirst("appendStringsHeader"));
    }
View Full Code Here

     * Tests sending a JAR file.
     *
     * @throws Exception
     */
    public void testSendJAR() throws Exception {
        ClientResponse response =
            client
                .resource(getBaseURI() + "/large/zip")
                .contentType("application/jar")
                .post(new File(
                               ServerEnvironmentInfo.getWorkDir() + "/wink-itest-targeting-0.2-incubating-SNAPSHOT.war"));
        assertEquals(290, response.getStatusCode());
        assertEquals("META-INF/DEPENDENCIES", response.getEntity(String.class));
    }
View Full Code Here

        String string = resource.get(String.class);
        assertEquals(RECEIVED_MESSAGE, string);

        // do get with response
        ClientResponse clientResponse = resource.get();
        assertEquals(RECEIVED_MESSAGE, clientResponse.getEntity(String.class));

        // test generic entity
        TestGenerics<String> tg = resource.get(new EntityType<TestGenerics<String>>() {
        });
        assertEquals(RECEIVED_MESSAGE, tg.getT());
View Full Code Here

            resource.contentType("text/plain").accept("text/plain").put(String.class, SENT_MESSAGE);
        assertEquals(RECEIVED_MESSAGE, response);
        assertEquals(SENT_MESSAGE, server.getRequestContentAsString());

        // do put with response
        ClientResponse clientResponse = resource.put(SENT_MESSAGE);
        assertEquals(RECEIVED_MESSAGE, clientResponse.getEntity(String.class));

        // test generic entity
        TestGenerics<String> tg = resource.put(new EntityType<TestGenerics<String>>() {
        }, SENT_MESSAGE);
        assertEquals(RECEIVED_MESSAGE, tg.getT());
View Full Code Here

                .post(String.class, SENT_MESSAGE);
        assertEquals(RECEIVED_MESSAGE, response);
        assertEquals(SENT_MESSAGE, server.getRequestContentAsString());

        // do post with response
        ClientResponse clientResponse = resource.post(SENT_MESSAGE);
        assertEquals(RECEIVED_MESSAGE, clientResponse.getEntity(String.class));

        // test generic entity
        TestGenerics<String> tg = resource.post(new EntityType<TestGenerics<String>>() {
        }, SENT_MESSAGE);
        assertEquals(RECEIVED_MESSAGE, tg.getT());
View Full Code Here

        Resource resource = client.resource(serviceURL);
        String response = resource.accept(MediaType.TEXT_PLAIN_TYPE).delete(String.class);
        assertEquals(RECEIVED_MESSAGE, response);

        // do delete with response
        ClientResponse clientResponse = resource.delete();
        assertEquals(RECEIVED_MESSAGE, clientResponse.getEntity(String.class));

        // test generic entity
        TestGenerics<String> tg = resource.delete(new EntityType<TestGenerics<String>>() {
        });
        assertEquals(RECEIVED_MESSAGE, tg.getT());
View Full Code Here

    public void testHttpErrorWithResponse() throws IOException {
        server.setMockResponseCode(400);
        RestClient client = getRestClient();
        Resource resource = client.resource(serviceURL);
        try {
            ClientResponse res = resource.accept("text/plain").get();
            assertTrue(res.getStatusCode() == 400);
        } catch (Exception e) {
            fail("Exception must not be thrown");
        }
    }
View Full Code Here

        String date = DateFormat.getDateTimeInstance().format(d);
        /*
         * sets a last modified date
         */
        Resource dateResource = client.resource(getBaseURI() + "/context/request/date");
        ClientResponse response = dateResource.contentType("text/string").put(date);
        assertEquals(204, response.getStatusCode());

        response = dateResource.header(HttpHeaders.IF_MODIFIED_SINCE, formatter.format(d)).get();
        /*
         * verifies that if the exact date is sent in and used in
         * If-Modified-Since header, then the server will be ok and that it will
         * return 304
         */
        assertEquals(304, response.getStatusCode());

        /*
         * verifies that if no If-Modified-Since header is sent, then the server
         * will be ok and the Request instance won't build a response.
         */
        dateResource = client.resource(getBaseURI() + "/context/request/date");
        response = dateResource.get();
        assertEquals(200, response.getStatusCode());
        assertEquals("the date: " + rfc1123Format.format(d), response.getEntity(String.class));

        rfc1123Format.setTimeZone(TimeZone.getTimeZone("GMT"));
        assertEquals(rfc1123Format.format(d), response.getHeaders()
            .getFirst(HttpHeaders.LAST_MODIFIED));
        rfc1123Format.setTimeZone(TimeZone.getDefault());

        /*
         * verifies that using Last-Modified response header sent by server as
         * If-Modified-Since request header, then the server will return a 304
         */
        String lastModified = response.getHeaders().getFirst(HttpHeaders.LAST_MODIFIED);
        dateResource = client.resource(getBaseURI() + "/context/request/date");
        response = dateResource.header(HttpHeaders.IF_MODIFIED_SINCE, lastModified).get();
        assertEquals(304, response.getStatusCode());

        /*
         * verifies that using a If-Modified-Since earlier than the
         * Last-Modified response header sent by server then the server will
         * return a 200 with entity
         */
        dateResource = client.resource(getBaseURI() + "/context/request/date");
        response = dateResource.header(HttpHeaders.IF_MODIFIED_SINCE, formatter.format(d2)).get();
        assertEquals(200, response.getStatusCode());
        assertEquals("the date: " + rfc1123Format.format(d), response.getEntity(String.class));

        rfc1123Format.setTimeZone(TimeZone.getTimeZone("GMT"));
        assertEquals(rfc1123Format.format(d), response.getHeaders()
            .getFirst(HttpHeaders.LAST_MODIFIED));
        rfc1123Format.setTimeZone(TimeZone.getDefault());

        /*
         * verifies that using a If-Modified-Since later than the Last-Modified
         * response header sent by server, then the server will return a 304
         */
        dateResource = client.resource(getBaseURI() + "/context/request/date");
        response =
            dateResource.header(HttpHeaders.IF_MODIFIED_SINCE, formatter.format(new Date())).get();
        assertEquals(304, response.getStatusCode());
    }
View Full Code Here

TOP

Related Classes of org.apache.wink.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.