Package org.apache.wink.client

Examples of org.apache.wink.client.Resource


        ProxyAuthSecurityHandler proxyAuthSecurityHandler = new ProxyAuthSecurityHandler();
        proxyAuthSecurityHandler.setUserName("username");
        proxyAuthSecurityHandler.setPassword("password");
        config.handlers(proxyAuthSecurityHandler, basicAuthSecurityHandler)// proxy first, then basic, of course
        RestClient client = new RestClient(config);
        Resource resource = client.resource(serviceURL);
        ClientResponse response = resource.get();
        assertEquals(200, response.getStatusCode());
    }
View Full Code Here


            // create the rest client instance
            RestClient restClient = new RestClient();

            // create the resource instance to interact with
            String rss_url = "http://www.rssboard.org/files/rss-2.0-sample.xml";
            Resource feedResource = restClient.resource(rss_url);

            // perform a GET on the resource. The resource will be returned as
            // an Rss object
            RssFeed rss = feedResource.accept(MediaType.APPLICATION_XML_TYPE).get(RssFeed.class);

            System.out.println("RSS Title = " + rss.getChannel().getTitle());
            System.out.println("RSS Descritpion = " + rss.getChannel().getDescription());
            System.out.println("RSS Link = " + rss.getChannel().getLink());
            int itemCount = 0;
View Full Code Here

        requestHeaders = createRequestHeaders(reqHdrs);
    }

    public Response addNewsStory(NewsStory story) throws Exception {
        RestClient client = new RestClient();
        Resource resource = client.resource(baseURI);
        setRequestHeaders(resource);
        JAXBContext context = JAXBContext.newInstance(NewsStory.class);
        StringWriter sw = new StringWriter();
        context.createMarshaller().marshal(story, sw);
        ClientResponse response = resource.contentType("text/xml").post(sw.toString().getBytes());
        int status = response.getStatusCode();
        Response resp = Response.status(status).build();
        for (String key : response.getHeaders().keySet()) {
            List<String> values = response.getHeaders().get(key);
            List<Object> objValues = new ArrayList<Object>();
View Full Code Here

        return resp;
    }

    public Response updateNewsStory(NewsStory story) throws Exception {
        RestClient client = new RestClient();
        Resource resource = client.resource(baseURI);
        setRequestHeaders(resource);

        JAXBContext context = JAXBContext.newInstance(NewsStory.class);
        StringWriter sw = new StringWriter();
        context.createMarshaller().marshal(story, sw);

        ClientResponse response = resource.contentType("text/xml").put(sw.toString().getBytes());
        int status = response.getStatusCode();

        Response resp = Response.status(status).build();
        for (String key : response.getHeaders().keySet()) {
            List<String> values = response.getHeaders().get(key);
View Full Code Here

        return resp;
    }

    public Response getNewsStory(String title) throws Exception {
        RestClient client = new RestClient();
        Resource resource = client.resource(this.baseURI + "/" + title);
        setRequestHeaders(resource);

        ClientResponse response = resource.contentType("text/xml").get();
        int status = response.getStatusCode();

        InputStream is = response.getEntity(InputStream.class);

        NewsStory newsStory = null;
View Full Code Here

        server.setMockResponseContent(SENT_MESSAGE);

        ClientConfig config = new ClientConfig();
        config.handlers(new DummyHandler());
        RestClient client = new RestClient(config);
        Resource resource = client.resource(serviceURL + "/testResourcePost");
        ClientResponse response =
            resource.contentType("text/plain").accept("text/plain")
                .post(SENT_MESSAGE.toLowerCase());

        // Check that request filter converted request entity to upper
        assertEquals(SENT_MESSAGE.toUpperCase(), server.getRequestContentAsString());
View Full Code Here

    }

    public void testResourceGet() {
        server.setMockResponseCode(200);
        RestClient client = getRestClient();
        Resource resource = client.resource(serviceURL);

        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());
        assertEquals(200, clientResponse.getStatusType().getStatusCode());
        assertEquals(Family.SUCCESSFUL, clientResponse.getStatusType().getFamily());
        assertEquals("OK", clientResponse.getStatusType().getReasonPhrase());
View Full Code Here

    }

    public void testResourcePut() throws IOException {
        server.setMockResponseCode(200);
        RestClient client = getRestClient();
        Resource resource = client.resource(serviceURL + "/testResourcePut");
        String response =
            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());

        assertEquals(200, clientResponse.getStatusType().getStatusCode());
        assertEquals(Family.SUCCESSFUL, clientResponse.getStatusType().getFamily());
View Full Code Here

    }

    public void testResourcePost() throws IOException {
        server.setMockResponseCode(200);
        RestClient client = getRestClient();
        Resource resource = client.resource(serviceURL + "/testResourcePost");
        String response =
            resource.contentType("text/plain").accept("text/plain")
                .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());

        assertEquals(200, clientResponse.getStatusType().getStatusCode());
        assertEquals(Family.SUCCESSFUL, clientResponse.getStatusType().getFamily());
View Full Code Here

    }

    public void testResourceDelete() {
        server.setMockResponseCode(200);
        RestClient client = getRestClient();
        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());

        assertEquals(200, clientResponse.getStatusType().getStatusCode());
        assertEquals(Family.SUCCESSFUL, clientResponse.getStatusType().getFamily());
View Full Code Here

TOP

Related Classes of org.apache.wink.client.Resource

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.