Package org.apache.wink.client

Examples of org.apache.wink.client.ClientResponse


    private void checkIfUnmodifiedSinceUsingSuppliedDateFormat(SimpleDateFormat formatter)
        throws IOException, HttpException {
        Date d2 = new Date(System.currentTimeMillis() - 120000);
        Date d = new Date(System.currentTimeMillis() - 60000);
        String date = DateFormat.getDateTimeInstance().format(d);
        ClientResponse response =
            client.resource(getBaseURI() + "/context/request/date").contentType("text/string")
                .put(date);
        assertEquals(204, response.getStatusCode());

        /*
         * verifies that if the exact date is sent in and used in
         * If-Unmodified-Since header, then the server will be ok and that it
         * will return 200
         */
        response =
            client.resource(getBaseURI() + "/context/request/date")
                .header(HttpHeaders.IF_UNMODIFIED_SINCE, formatter.format(d)).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("Last-Modified"));
        rfc1123Format.setTimeZone(TimeZone.getDefault());

        /*
         * verifies that if no If-Unmodified-Since header is sent, then the
         * server will be ok and the Request instance won't build a response.
         */
        response = client.resource(getBaseURI() + "/context/request/date").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-Unmodified-Since request header, then the server will return the
         * entity
         */
        String lastModified = response.getHeaders().getFirst(HttpHeaders.LAST_MODIFIED);
        response =
            client.resource(getBaseURI() + "/context/request/date")
                .header(HttpHeaders.IF_UNMODIFIED_SINCE, lastModified).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-Unmodified-Since earlier than the
         * Last-Modified response header sent by server then the server will
         * return a 412
         */
        response =
            client.resource(getBaseURI() + "/context/request/date")
                .header(HttpHeaders.IF_UNMODIFIED_SINCE, formatter.format(d2)).get();
        assertEquals(412, response.getStatusCode());

        response =
            client.resource(getBaseURI() + "/context/request/date")
                .header(HttpHeaders.IF_UNMODIFIED_SINCE, formatter.format(new Date())).get();
        /*
         * verifies that using a If-Unmodified-Since later than the
         * Last-Modified response header sent by server, then the server will
         * return 200 and the entity
         */
        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());
    }
View Full Code Here


     * underlying client may set the header as a failsafe.
     *
     * @throws JSONException
     */
    public void testAcceptHeaderNoEntity() {
        ClientResponse resp = client.resource(getBaseURI() + "/echoaccept").get();
        /*
         * in this case the underlying client set the WILDCARD header for
         * default HttpURLConnection based client.
         */
        assertEquals("echo: " + MediaType.WILDCARD, resp.getEntity(String.class));
    }
View Full Code Here

        IOException {
        final String justTheTag = etag;
        final String setETag = isEntityTagWeak ? "W/" + justTheTag : justTheTag;
        String isWeak = isEntityTagWeak ? "true" : "false";

        ClientResponse response =
            client.resource(getBaseURI() + "/context/request/etag").contentType("text/string")
                .put(setETag);
        assertEquals(204, response.getStatusCode());

        response =
            client.resource(getBaseURI() + "/context/request/etag").header(HttpHeaders.IF_MATCH,
                                                                           setETag).get();
        assertEquals(200, response.getStatusCode());
        assertEquals("the etag: " + justTheTag + isWeak, response.getEntity(String.class));

        /*
         * verifies that a request without an If-Match header will still proceed
         */
        response = client.resource(getBaseURI() + "/context/request/etag").get();
        assertEquals(200, response.getStatusCode());
        assertEquals("the etag: " + justTheTag + isWeak, response.getEntity(String.class));

        /*
         * verifies that a misquoted entity tag is not a valid entity tag
         */
        response =
            client.resource(getBaseURI() + "/context/request/etag")
                .header(HttpHeaders.IF_MATCH, setETag.substring(1, setETag.length() - 1)).get();
        assertEquals(400, response.getStatusCode());

        /*
         * verifies that a misquoted entity tag is not a valid entity tag
         */
        response =
            client.resource(getBaseURI() + "/context/request/etag")
                .header(HttpHeaders.IF_MATCH, setETag.substring(0, setETag.length() - 1)).get();
        assertEquals(400, response.getStatusCode());

        /*
         * verifies that a misquoted entity tag is not a valid entity tag
         */
        response =
            client.resource(getBaseURI() + "/context/request/etag")
                .header(HttpHeaders.IF_MATCH, setETag.substring(1, setETag.length())).get();
        assertEquals(400, response.getStatusCode());

        /*
         * verifies that if an etag is sent that does not match the server etag,
         * that a 412 is returned
         */
        response =
            client.resource(getBaseURI() + "/context/request/etag").header(HttpHeaders.IF_MATCH,
                                                                           "\"someothervalue\"")
                .get();
        assertEquals(412, response.getStatusCode());

        /*
         * verifies that if multiple etags are sent that do not match the server
         * etag, that a 412 is returned
         */
        response =
            client.resource(getBaseURI() + "/context/request/etag")
                .header(HttpHeaders.IF_MATCH, "\"austin\", \"powers\"").get();
        assertEquals(412, response.getStatusCode());

        /*
         * verifies that if multiple etags are sent that do not match the server
         * etag, that a 412 is returned
         */
        response =
            client.resource(getBaseURI() + "/context/request/etag").header(HttpHeaders.IF_MATCH,
                                                                           "\"austin\", " + setETag
                                                                               + " , \"powers\"")
                .get();
        assertEquals(200, response.getStatusCode());
        assertEquals("the etag: " + justTheTag + isWeak, response.getEntity(String.class));
    }
View Full Code Here

    private ClientResponse processResponse(ClientRequest request,
                                           HandlerContext context,
                                           HttpResponse httpResponse) throws IllegalStateException,
        IOException {
        ClientResponse response = createResponse(request, httpResponse);
        InputStream is = httpResponse.getEntity().getContent();
        is = adaptInputStream(is, response, context.getInputStreamAdapters());
        response.setEntity(is);
        return response;
    }
View Full Code Here

        response.setEntity(is);
        return response;
    }

    private ClientResponse createResponse(ClientRequest request, HttpResponse httpResponse) {
        ClientResponse response = new ClientResponseImpl();
        StatusLine statusLine = httpResponse.getStatusLine();
        response.setStatusCode(statusLine.getStatusCode());
        response.setMessage(statusLine.getReasonPhrase());
        response.getAttributes().putAll(request.getAttributes());
        processResponseHeaders(response, httpResponse);
        return response;
    }
View Full Code Here

        }
    }

    @SuppressWarnings("unchecked")
    public <T> T invoke(String method, Class<T> responseEntity, Object requestEntity) {
        ClientResponse response = invoke(method, responseEntity, responseEntity, requestEntity);
        if (responseEntity == null) {
            return null;
        }
        if (ClientResponse.class.equals(responseEntity)) {
            return (T)response;
        }
        return response.getEntity(responseEntity);
    }
View Full Code Here

        return response.getEntity(responseEntity);
    }

    @SuppressWarnings("unchecked")
    public <T> T invoke(String method, EntityType<T> responseEntity, Object requestEntity) {
        ClientResponse response =
            invoke(method, responseEntity.getRawClass(), responseEntity.getType(), requestEntity);
        if (responseEntity == null) {
            return null;
        }
        if (ClientResponse.class.equals(responseEntity.getRawClass())) {
            return (T)response;
        }
        return response.getEntity(responseEntity);
    }
View Full Code Here

        ClientRuntimeContext runtimeContext = new ClientRuntimeContext(providersRegistry);
        RuntimeContext saved = RuntimeContextTLS.getRuntimeContext();
        RuntimeContextTLS.setRuntimeContext(runtimeContext);

        try {
            ClientResponse response = context.doChain(request);
            int statusCode = response.getStatusCode();
            if (ClientUtils.isErrorCode(statusCode)) {
                logger.info(Messages.getMessage("clientResponseIsErrorCode"), statusCode);
                throw new ClientWebException(request, response);
            }
            return response;
View Full Code Here

    private ClientResponse processResponse(ClientRequest request,
                                           HandlerContext context,
                                           HttpResponse httpResponse) throws IllegalStateException,
        IOException {
        ClientResponse response = createResponse(request, httpResponse);
        HttpEntity entity = httpResponse.getEntity();
        InputStream is = null;
        if (entity == null) {
            is = new EmptyInputStream();
        } else {
            is = entity.getContent();
        }
        is = adaptInputStream(is, response, context.getInputStreamAdapters());
        response.setEntity(is);
        return response;
    }
View Full Code Here

        }
    }

    @SuppressWarnings("unchecked")
    public <T> T invoke(String method, Class<T> responseEntity, Object requestEntity) {
        ClientResponse response = invoke(method, responseEntity, responseEntity, requestEntity);
        if (responseEntity == null) {
            return null;
        }
        if (ClientResponse.class.equals(responseEntity)) {
            return (T)response;
        }
        return response.getEntity(responseEntity);
    }
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.