Package org.apache.cxf.jaxrs.client

Examples of org.apache.cxf.jaxrs.client.WebClient$SyncInvokerImpl


    @Test
    public void testQuotedHeaders() throws Exception {

        String endpointAddress =
            "http://localhost:" + PORT + "/bookstore/quotedheaders";
        WebClient wc = WebClient.create(endpointAddress);
        WebClient.getConfig(wc).getRequestContext().put("org.apache.cxf.http.header.split", true);
        Response r = wc.get();

        List<Object> header1 = r.getMetadata().get("SomeHeader1");
        assertEquals(1, header1.size());
        assertEquals("\"some text, some more text\"", header1.get(0));
View Full Code Here


        };

        // technically speaking, for these test cases, the client should return an error
        // however, servers do send bad data from time to time so we try to be forgiving
        for (int i = 0; i < 3; i++) {
            WebClient wc = WebClient.create(endpointAddress);
            WebClient.getConfig(wc).getRequestContext().put("org.apache.cxf.http.header.split", true);
            Response r = wc.query("type", Integer.toString(i)).get();
            assertEquals(responses[i], r.getMetadata().get("SomeHeader" + i).get(0));
        }

        // this test currently returns the WRONG result per RFC2616, however it is correct
        // per the discussion in CXF-3518
        WebClient wc = WebClient.create(endpointAddress);
        WebClient.getConfig(wc).getRequestContext().put("org.apache.cxf.http.header.split", true);
        Response r3 = wc.query("type", "3").get();
        List<Object> r3values = r3.getMetadata().get("SomeHeader3");
        assertEquals(4, r3values.size());
        assertEquals("some text", r3values.get(0));
        assertEquals("\"other quoted\"", r3values.get(1));
        assertEquals("text", r3values.get(2));
View Full Code Here

    }
   
    @Test
    public void testGetBookRoot() throws Exception {
        String address = "http://localhost:" + PORT + "/bookstore/;JSESSIONID=xxx";
        WebClient wc = WebClient.create(address);
        Book book = wc.get(Book.class);
        assertEquals(124L, book.getId());
        assertEquals("root", book.getName());
    }
View Full Code Here

    }
   
    @Test
    public void testGetBookQueryDefault() throws Exception {
        String address = "http://localhost:" + PORT + "/bookstore/books/query/default";
        WebClient wc = WebClient.create(address);
        Response r = wc.get();
        Book book = r.readEntity(Book.class);
        assertEquals(123L, book.getId());
    }
View Full Code Here

    }
   
    @Test
    public void testGetBookSameUriAutoRedirect() throws Exception {
        String address = "http://localhost:" + PORT + "/bookstore/redirect?sameuri=true";
        WebClient wc = WebClient.create(address);
        WebClient.getConfig(wc).getHttpConduit().getClient().setAutoRedirect(true);
        WebClient.getConfig(wc).getRequestContext().put(
            org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
        Response r = wc.get();
        Book book = r.readEntity(Book.class);
        assertEquals(123L, book.getId());
        String requestUri = r.getStringHeaders().getFirst("RequestURI");
        assertEquals("http://localhost:" + PORT + "/bookstore/redirect?redirect=true", requestUri);
        String theCookie = r.getStringHeaders().getFirst("TheCookie");
View Full Code Here

    }
   
    @Test
    public void testGetBookDiffUriAutoRedirect() throws Exception {
        String address = "http://localhost:" + PORT + "/bookstore/redirect?sameuri=false";
        WebClient wc = WebClient.create(address);
        WebClient.getConfig(wc).getRequestContext().put("http.redirect.same.host.only", "true");
        WebClient.getConfig(wc).getHttpConduit().getClient().setAutoRedirect(true);
        try {
            wc.get();
            fail("Redirect to different host is not allowed");
        } catch (ClientException ex) {
            Throwable cause = ex.getCause();
            assertTrue(cause.getMessage().contains("Different HTTP Scheme or Host Redirect detected on"));
        }
View Full Code Here

   

    @Test
    public void testGetBookRelativeUriAutoRedirect() throws Exception {
        String address = "http://localhost:" + PORT + "/bookstore/redirect/relative?loop=false";
        WebClient wc = WebClient.create(address);
        WebClient.getConfig(wc).getRequestContext().put("http.redirect.relative.uri", "true");
        WebClient.getConfig(wc).getHttpConduit().getClient().setAutoRedirect(true);
        Response r = wc.get();
        Book book = r.readEntity(Book.class);
        assertEquals(124L, book.getId());
    }
View Full Code Here

    }
   
    @Test
    public void testGetBookRelativeUriAutoRedirectLoop() throws Exception {
        String address = "http://localhost:" + PORT + "/bookstore/redirect/relative?loop=true";
        WebClient wc = WebClient.create(address);
        WebClient.getConfig(wc).getRequestContext().put("http.redirect.relative.uri", "true");
        WebClient.getConfig(wc).getHttpConduit().getClient().setAutoRedirect(true);
        try {
            wc.get();
            fail("Redirect loop must be detected");
        } catch (ClientException ex) {
            Throwable cause = ex.getCause();
            assertTrue(cause.getMessage().contains("Redirect loop detected on"));
        }
View Full Code Here

    }
   
    @Test
    public void testGetBookRelativeUriAutoRedirectNotAllowed() throws Exception {
        String address = "http://localhost:" + PORT + "/bookstore/redirect/relative?loop=true";
        WebClient wc = WebClient.create(address);
        WebClient.getConfig(wc).getHttpConduit().getClient().setAutoRedirect(true);
        try {
            wc.get();
            fail("relative Redirect is not allowed");
        } catch (ClientException ex) {
            Throwable cause = ex.getCause().getCause();
            assertTrue(cause.getMessage().startsWith("Relative Redirect detected on"));
        }
View Full Code Here

    }
   
    @Test
    public void testPostEmptyForm() throws Exception {
        String address = "http://localhost:" + PORT + "/bookstore/emptyform";
        WebClient wc = WebClient.create(address);
        Response r = wc.form(new org.apache.cxf.jaxrs.ext.form.Form());
        assertEquals("empty form", r.readEntity(String.class));
    }
View Full Code Here

TOP

Related Classes of org.apache.cxf.jaxrs.client.WebClient$SyncInvokerImpl

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.