Search in sources :

Example 86 with WebClient

use of org.apache.cxf.jaxrs.client.WebClient in project cxf by apache.

the class JAXRSSoapBookTest method testPostBookTransform.

@Test
public void testPostBookTransform() throws Exception {
    String address = "http://localhost:" + PORT + "/test/v1/rest-transform/bookstore/books";
    TransformOutInterceptor out = new TransformOutInterceptor();
    out.setOutTransformElements(Collections.singletonMap("{http://www.example.org/books}*", "{http://www.example.org/super-books}*"));
    TransformInInterceptor in = new TransformInInterceptor();
    Map<String, String> map = new HashMap<>();
    // If Book2 didn't have {http://www.example.org/books}Book
    // then we'd just do '"*" : "{http://www.example.org/books}*'
    // but given that we have TheBook being returned, we need
    map.put("TheBook", "{http://www.example.org/books}Book");
    map.put("id", "{http://www.example.org/books}id");
    in.setInTransformElements(map);
    WebClient client = WebClient.create(address);
    WebClient.getConfig(client).getInInterceptors().add(in);
    WebClient.getConfig(client).getOutInterceptors().add(out);
    Book2 book = client.type("application/xml").accept("text/xml").post(new Book2(), Book2.class);
    assertEquals(124L, book.getId());
}
Also used : HashMap(java.util.HashMap) TransformOutInterceptor(org.apache.cxf.interceptor.transform.TransformOutInterceptor) WebClient(org.apache.cxf.jaxrs.client.WebClient) TransformInInterceptor(org.apache.cxf.interceptor.transform.TransformInInterceptor) Test(org.junit.Test)

Example 87 with WebClient

use of org.apache.cxf.jaxrs.client.WebClient in project cxf by apache.

the class JAXRSUriInfoTest method checkUriInfo.

private void checkUriInfo(String address, String path, String pathParam) {
    WebClient wc = WebClient.create(address);
    wc.accept("text/plain");
    String data = wc.get(String.class);
    assertEquals("http://localhost:" + PORT + "/app/v1/," + path + "," + pathParam, data);
}
Also used : WebClient(org.apache.cxf.jaxrs.client.WebClient)

Example 88 with WebClient

use of org.apache.cxf.jaxrs.client.WebClient in project cxf by apache.

the class JAXRSUriInfoTest method checkUriInfoXForwarded.

private void checkUriInfoXForwarded(String address, String path, String pathParam) {
    WebClient wc = WebClient.create(address);
    wc.accept("text/plain");
    wc.header("USE_XFORWARDED", true);
    String data = wc.get(String.class);
    assertEquals("https://external:8090/reverse/app/v1/," + path + "," + pathParam, data);
}
Also used : WebClient(org.apache.cxf.jaxrs.client.WebClient)

Example 89 with WebClient

use of org.apache.cxf.jaxrs.client.WebClient in project cxf by apache.

the class AbstractSwagger2ServiceDescriptionTest method testApiListingIsProperlyReturnedYAML.

@Test
@Ignore
public void testApiListingIsProperlyReturnedYAML() throws Exception {
    final WebClient client = createWebClient("/swagger.yaml");
    try {
        final Response r = client.get();
        assertEquals(Status.OK.getStatusCode(), r.getStatus());
        // REVISIT find a better way of reliably comparing two yaml instances.
        // I noticed that yaml.load instantiates a Map and
        // for an integer valued key, an Integer or a String is arbitrarily instantiated,
        // which leads to the assertion error. So, we serilialize the yamls and compare the re-serialized texts.
        Yaml yaml = new Yaml();
        assertEquals(yaml.load(getExpectedValue(getExpectedFileYaml(), getPort())).toString(), yaml.load(IOUtils.readStringFromStream((InputStream) r.getEntity())).toString());
    } finally {
        client.close();
    }
}
Also used : Response(javax.ws.rs.core.Response) InputStream(java.io.InputStream) WebClient(org.apache.cxf.jaxrs.client.WebClient) Yaml(org.yaml.snakeyaml.Yaml) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 90 with WebClient

use of org.apache.cxf.jaxrs.client.WebClient in project cxf by apache.

the class AbstractSwagger2ServiceDescriptionTest method testNonUiResource.

@Test
public void testNonUiResource() {
    // Test that Swagger UI resources do not interfere with
    // application-specific ones.
    WebClient uiClient = WebClient.create("http://localhost:" + getPort() + "/css/book.css").accept("text/css");
    String css = uiClient.get(String.class);
    assertThat(css, equalTo("body { background-color: lightblue; }"));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Aggregations

WebClient (org.apache.cxf.jaxrs.client.WebClient)723 Test (org.junit.Test)400 Response (javax.ws.rs.core.Response)351 URL (java.net.URL)198 HashMap (java.util.HashMap)100 Book (org.apache.cxf.systest.jaxrs.security.Book)94 ArrayList (java.util.ArrayList)88 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)87 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)77 ClientAccessToken (org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)60 Bus (org.apache.cxf.Bus)48 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)46 Test (org.testng.annotations.Test)46 Form (javax.ws.rs.core.Form)44 JwtToken (org.apache.cxf.rs.security.jose.jwt.JwtToken)42 JwtClaims (org.apache.cxf.rs.security.jose.jwt.JwtClaims)40 JwtAuthenticationClientFilter (org.apache.cxf.rs.security.jose.jaxrs.JwtAuthenticationClientFilter)32 InputStream (java.io.InputStream)28 ResponseProcessingException (javax.ws.rs.client.ResponseProcessingException)28 Document (org.w3c.dom.Document)27