Package org.apache.wink.client

Examples of org.apache.wink.client.Resource


        return resp;
    }

    public Response getNewsStory(String title) throws Exception {
        RestClient client = new RestClient(new ApacheHttpClientConfig());
        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


            // 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

            // 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 rssFeed = feedResource.accept(MediaType.APPLICATION_XML).get(RssFeed.class);

            // Map RSS into SyndFeed
            SyndFeed syndFeed = new SyndFeed();
            syndFeed = rssFeed.toSynd(syndFeed);
View Full Code Here

    /**
     * returns list of Google document files, the list is returned as String
     */
    public String listFiles() throws ClientWebException {
        // create a resource
        Resource listOfDocumentsResource = restClient.resource(URL);

        // invoke GET on the resource and parse the result as SyndFeed
        SyndFeed list = listOfDocumentsResource.get(SyndFeed.class);

        // convert SyndFeed to String
        return feedToString(list);
    }
View Full Code Here

     * delete file
     *
     * @param id - id as it appears in edit link
     */
    public void delete(String id) {
        Resource resource = restClient.resource(URL + id);
        ClientResponse response = resource.delete(ClientResponse.class);
        if (response.getStatusCode() != 200) {
            throw new ClientWebException(null, response);
        }
    }
View Full Code Here

     * @return location of the uploaded file
     * @throws FileNotFoundException - file was not found
     * @throws ClientWebException - error occurred during the upload
     */
    public String uploadFile(String filename) throws FileNotFoundException, ClientWebException {
        Resource listOfDocumentsResource = restClient.resource(URL);

        File file = new File(filename);
        ClientResponse clientResponse =
            listOfDocumentsResource.header("Slug", file.getName())
                .contentType(mapContentType(filename)).post(ClientResponse.class,
                                                            new FileInputStream(file));
        if (clientResponse.getStatusCode() == Status.CREATED.getStatusCode()) {
            return clientResponse.getHeaders().getFirst(HttpHeaders.LOCATION);
        }
View Full Code Here

            // Create Rest Client

            RestClient restClient = new RestClient();

            // Create new Resource on given URL
            Resource resource = restClient.resource(defectsFeed);

            AppService service =
                resource.accept(MediaTypeUtils.ATOM_SERVICE_DOCUMENT).get(AppService.class);

            // Find workspace by it's title
            AppWorkspace workspace = service.getWorkspace(WORKSPACE_TITLE);

            // Find collection by title
            AppCollection collection = workspace.getCollection(COLLECTION_TITLE);
            String href = collection.getHref();

            // Get collection of defects
            Resource feedResource = restClient.resource(href);
            AtomFeed feed = feedResource.accept(MediaType.APPLICATION_ATOM_XML).get(AtomFeed.class);

            // Browse through collection of defects.
            listDefects(feed);
            listTests(restClient, testFeed);
View Full Code Here

                + atomEntry.getTitle().getValue());
        }
    }

    private static void listTests(RestClient restClient, String url) {
        Resource feedResource = restClient.resource(url);
        AtomFeed feed = feedResource.accept(MediaType.APPLICATION_ATOM_XML).get(AtomFeed.class);
        List<AtomEntry> entries = feed.getEntries();
        for (AtomEntry atomEntry : entries) {
            System.out.println("ID> " + atomEntry.getId()
                + " Title> "
                + atomEntry.getTitle().getValue());
View Full Code Here

     * method is called after the request is processed, and before the next
     * request. Combining these into one test.
     */
    @Test
    public void testPostConstructAndPreDestroy() {
        Resource resource = client.resource(getBaseURI() + "/pojo/message");
        ClientResponse response = resource.get();
        assertEquals(204, response.getStatusCode());

        resource = client.resource(getBaseURI() + "/messageaccess");
        response = resource.get();
        assertEquals(200, response.getStatusCode());
        assertEquals("MyPOJO;myPostConstructMethod;message;myPreDestroyMethod;", response
            .getEntity(String.class));

        resource = client.resource(getBaseURI() + "/pojo/message");
        response = resource.get();
        assertEquals(204, response.getStatusCode());

        resource = client.resource(getBaseURI() + "/messageaccess");
        response = resource.get();
        assertEquals(200, response.getStatusCode());
        assertEquals("MyPOJO;myPostConstructMethod;message;myPreDestroyMethod;MyPOJO;myPostConstructMethod;message;myPreDestroyMethod;",
                     response.getEntity(String.class));
    }
View Full Code Here

    /**
     * Test things are called correctly in the Exception path.
     */
    @Test
    public void testPostConstructAndPreDestroyWithException() {
        Resource resource = client.resource(getBaseURI() + "/pojo/exception");
        ClientResponse response = resource.get();
        assertEquals(500, response.getStatusCode());

        resource = client.resource(getBaseURI() + "/messageaccess");
        response = resource.get();
        assertEquals(200, response.getStatusCode());
        assertEquals("MyPOJO;myPostConstructMethod;myPreDestroyMethod;", response
            .getEntity(String.class));
    }
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.