Package com.sun.jersey.api.client

Examples of com.sun.jersey.api.client.WebResource.addFilter()


    public Event readEvent(@Nonnull String eventUrl) throws EventApiException {

        logger.info("GET " + eventUrl);

        WebResource wr = restClient.client.resource(UriBuilder.fromPath(eventUrl).build());
        wr.addFilter(new BearerTokenFilter(accessToken));
        try{
            wr.header("Authorization", createBearerAuthorizationHeader(accessToken));
            ClientResponse cr = wr.get(ClientResponse.class);
            return restClient.objectMapper.readValue(cr.getEntityInputStream(), Event.class);
        }catch(IOException e){
View Full Code Here


     * @throws IOException
     */
    public  List<Event> query(String evenQueryUrl) throws EventApiException {
        logger.info("Query: "+evenQueryUrl);
        WebResource wr = restClient.client.resource(evenQueryUrl);
        wr.addFilter(new BearerTokenFilter(accessToken));
        try{
            wr.header("Authorization", createBearerAuthorizationHeader(accessToken));
            ClientResponse cr = wr.get(ClientResponse.class);
            return restClient.objectMapper.readValue(cr.getEntityInputStream(), new TypeReference<List<Event>>() {});
        }catch(IOException e){
View Full Code Here

    public boolean delete(@Nonnull String eventUrl) throws EventApiException {
        logger.info("Delete " + eventUrl);

        WebResource wr = restClient.client.resource(UriBuilder.fromPath(eventUrl).build());
        wr.addFilter(new BearerTokenFilter(accessToken));

        try {
            wr.header("Authorization", createBearerAuthorizationHeader(accessToken));
        } catch (UnsupportedEncodingException e) {
            throw new EventApiException(e.getMessage(), e);
View Full Code Here

    }

    @Test
    public void testHello() {
        WebResource r = resource().path("1");
        r.addFilter(new LoggingFilter());

        assertTrue(r.get(String.class).contains("Pavel"));
    }

    @Test
View Full Code Here

    }

    @Test
    public void testAutoTemplate() {
        WebResource r = resource().path("2");
        r.addFilter(new LoggingFilter());

        assertTrue(r.get(String.class).contains("Pavel"));
    }

    @Test
View Full Code Here

    }

    @Test
    public void testAutoTemplateWithoutSuffix() {
        WebResource r = resource().path("3");
        r.addFilter(new LoggingFilter());

        assertTrue(r.get(String.class).contains("Pavel"));
    }

}
View Full Code Here

     * @throws java.lang.Exception
     */
    @Test
    public void testHelloWorld() throws Exception {
        WebResource webResource = resource();
        webResource.addFilter(new LoggingFilter());
        ClientResponse response = webResource.path("1").get(ClientResponse.class);
        List<String> linkHeaders = response.getHeaders().get("Link");
        Assert.assertEquals(2, linkHeaders.size());
    }
}
View Full Code Here

    }

    @Test
    public void testCustomers() throws Exception {
        WebResource webResource = resource().path("customers");
        webResource.addFilter(new LoggingFilter());
        GenericType<Collection<Customer>> genericType =
                new GenericType<Collection<Customer>>() {};
       

        Collection<Customer> customers = webResource.accept(MediaType.APPLICATION_XML).get(genericType);
View Full Code Here

    }

    @Test
    public void testCustomer() throws Exception {
        WebResource webResource = resource().path("customers/1");
        webResource.addFilter(new LoggingFilter());

        Customer customer = webResource.accept(MediaType.APPLICATION_XML).get(Customer.class);
        customer.setName("Tom Dooley");
        webResource.type(MediaType.APPLICATION_XML).put(customer);
View Full Code Here

     */
    @Test
    public void doTestPutPrinterBasedOnId() {
        WebResource webResource = resource();
        LoggingFilter loggingFilter = new LoggingFilter();
        webResource.addFilter(loggingFilter);
        Printer printer = webResource.path("printers").path("ids").path("P01").accept(MediaType.APPLICATION_JSON).get(Printer.class);
        String printerModel = printer.model;
        String printerLocation = printer.location;
        String printerUrl = printer.url;
        printer = new Printer("P01", "Xerox", printerLocation, printerUrl);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.