Package org.apache.cxf.jaxrs.client

Examples of org.apache.cxf.jaxrs.client.WebClient.header()


   
    private void getBookAegis(String endpointAddress, String type, String mHeader) throws Exception {
        WebClient client = WebClient.create(endpointAddress,
            Collections.singletonList(new AegisElementProvider()));
        if (mHeader != null) {
            client = client.header("X-HTTP-Method-Override", mHeader);
        }
        Book book = client.accept(type).get(Book.class);

        assertEquals(124L, book.getId());
        assertEquals("CXF in Action - 2", book.getName());
View Full Code Here


        assertEquals("123", headers.getFirst("BookId"));
        assertEquals(MultivaluedMap.class.getName(), headers.getFirst("MAP-NAME"));
       
        assertNotNull(headers.getFirst("Date"));
       
        wc.header("PLAIN-MAP", "true");
        b = wc.get(Book.class);
        assertEquals(123L, b.getId());
       
        headers = wc.getResponse().getMetadata();
        assertEquals("321", headers.getFirst("BookId"));
View Full Code Here

   
   
    @Test
    public void testOnewayWebClient() throws Exception {
        WebClient client = WebClient.create("http://localhost:" + PORT + "/bookstore/oneway");
        Response r = client.header("OnewayRequest", "true").post(null);
        assertEquals(202, r.getStatus());
    }
   
    @Test
    public void testBookWithSpace() throws Exception {
View Full Code Here

    public void testJaasFilterAuthenticationFailure() throws Exception {
        String endpointAddress =
            "http://localhost:" + PORT + "/service/jaas2/bookstorestorage/thosebooks/123";
        WebClient wc = WebClient.create(endpointAddress);
        wc.accept("text/xml");
        wc.header(HttpHeaders.AUTHORIZATION,
                  "Basic " + base64Encode("foo" + ":" + "bar1"));
        Response r = wc.get();
        assertEquals(401, r.getStatus());
        Object wwwAuthHeader = r.getMetadata().getFirst(HttpHeaders.WWW_AUTHENTICATE);
        assertNotNull(wwwAuthHeader);
View Full Code Here

    public void testJaasFilterAuthenticationFailureWithRedirection() throws Exception {
        String endpointAddress =
            "http://localhost:" + PORT + "/service/jaas2/bookstorestorage/thosebooks/123";
        WebClient wc = WebClient.create(endpointAddress);
        wc.accept("text/xml,text/html");
        wc.header(HttpHeaders.AUTHORIZATION,
                  "Basic " + base64Encode("foo" + ":" + "bar1"));
        Response r = wc.get();
        assertEquals(307, r.getStatus());
        Object locationHeader = r.getMetadata().getFirst(HttpHeaders.LOCATION);
        assertNotNull(locationHeader);
View Full Code Here

            String authorizationHeader = OAuthClientUtils.createAuthorizationHeader(
                    consumer, new OAuthClientUtils.Token(authCreditials.getAccessToken(), authCreditials.getSecretToken()),
                    requestMethod.name(), client.getCurrentURI().toString());

            client.header("Authorization", authorizationHeader)
                    .header("Accept", "application/json").header("Content-type", "application/json");
            if (requestMethod.equals(ERequestMethod.GET)) {
                response = client.get(Response.class);
            } else if (requestMethod.equals(ERequestMethod.POST)) {
                response = client.post(data, Response.class);
View Full Code Here

            AuthCreditials cloned = authCreditials.clone();
            String serviceUrl = "oauth/access_token";
            ResponseDataProvider<Form> provider = new ResponseDataProvider<>();
            WebClient client = WebClient.create("https://www.infakt.pl/", Collections.singletonList(provider));
            client.path(serviceUrl);
            client.header("Accept", "application/json").header("Content-type", "application/json");
            OAuthClientUtils.Consumer consumer = new OAuthClientUtils.Consumer(authCreditials.getConsumerKey(), authCreditials.getConsumerSecret());
            client.query("x_auth_username", username).query("x_auth_password", password).query("x_auth_mode", "oauth_token");
            OAuthClientUtils.Token accessToken = OAuthClientUtils.getRequestToken(client, consumer, new URI("https://www.infakt.pl/oauth/access_token"), null);
            cloned.setAccessToken(accessToken.getToken());
            cloned.setSecretToken(accessToken.getSecret());
View Full Code Here

   
   
    @Test
    public void testOnewayWebClient() throws Exception {
        WebClient client = WebClient.create("http://localhost:" + PORT + "/bookstore/oneway");
        Response r = client.header("OnewayRequest", "true").post(null);
        assertEquals(202, r.getStatus());
    }
   
    @Test
    public void testBookWithSpace() throws Exception {
View Full Code Here

    @Test
    public void testGetBookByHeaderPerRequestInjected() throws Exception {
        String address = "http://localhost:" + PORT + "/bookstore2/bookheaders/injected";
        WebClient wc = WebClient.create(address);
        wc.accept("application/xml");
        wc.header("BOOK", "1", "2", "3");
        Book b = wc.get(Book.class);
        assertEquals(123L, b.getId());
    }
   
    @Test
View Full Code Here

    @Test
    public void testGetBookByHeaderPerRequestInjectedFault() throws Exception {
        String address = "http://localhost:" + PORT + "/bookstore2/bookheaders/injected";
        WebClient wc = WebClient.create(address);
        wc.accept("application/xml");
        wc.header("BOOK", "2", "3");
        Response r = wc.get();
        assertEquals(400, r.getStatus());
        assertEquals("Param setter: 3 header values are required",
                     IOUtils.toString((InputStream)r.getEntity()));
    }
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.