Java Code Examples for org.apache.cxf.jaxrs.client.WebClient#client()

The following examples show how to use org.apache.cxf.jaxrs.client.WebClient#client() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JAXRSMultithreadedClientTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void invoke(int ind) throws Exception {

            String actualHeaderName = bookHeader + ind;
            String actualBookName = bookName + ind;

            if (stateCanBeChanged) {
                Client c = WebClient.client(proxy);
                MultivaluedMap<String, String> map = c.getHeaders();
                map.putSingle("CustomHeader", actualHeaderName);
                c.headers(map);
                proxy.echoBookNameAndHeader2(actualBookName);
                verifyResponse(c.getResponse(), actualBookName, actualHeaderName);
            } else {
                verifyResponse(proxy.echoBookNameAndHeader(actualHeaderName, actualBookName),
                               actualBookName, actualHeaderName);
            }
        }
 
Example 2
Source File: ReconciliationITCase.java    From syncope with Apache License 2.0 5 votes vote down vote up
@Test
public void importCSV() {
    ReconciliationService service = adminClient.getService(ReconciliationService.class);
    Client client = WebClient.client(service);
    client.type(RESTHeaders.TEXT_CSV);

    CSVPullSpec spec = new CSVPullSpec.Builder(AnyTypeKind.USER.name(), "username").build();
    InputStream csv = getClass().getResourceAsStream("/test1.csv");

    List<ProvisioningReport> results = service.pull(spec, csv);
    assertEquals(AnyTypeKind.USER.name(), results.get(0).getAnyType());
    assertNotNull(results.get(0).getKey());
    assertEquals("donizetti", results.get(0).getName());
    assertEquals("donizetti", results.get(0).getUidValue());
    assertEquals(ResourceOperation.CREATE, results.get(0).getOperation());
    assertEquals(ProvisioningReport.Status.SUCCESS, results.get(0).getStatus());

    UserTO donizetti = userService.read(results.get(0).getKey());
    assertNotNull(donizetti);
    assertEquals("Gaetano", donizetti.getPlainAttr("firstname").get().getValues().get(0));
    assertEquals(1, donizetti.getPlainAttr("loginDate").get().getValues().size());

    UserTO cimarosa = userService.read(results.get(1).getKey());
    assertNotNull(cimarosa);
    assertEquals("Domenico Cimarosa", cimarosa.getPlainAttr("fullname").get().getValues().get(0));
    assertEquals(2, cimarosa.getPlainAttr("loginDate").get().getValues().size());
}
 
Example 3
Source File: StoreApiTest.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    JacksonJsonProvider provider = new JacksonJsonProvider();
    List providers = new ArrayList();
    providers.add(provider);
    
    api = JAXRSClientFactory.create("http://petstore.swagger.io/v2", StoreApi.class, providers);
    org.apache.cxf.jaxrs.client.Client client = WebClient.client(api);
    
    ClientConfiguration config = WebClient.getConfig(client); 
}
 
Example 4
Source File: JAXRSClientConduitWebSocketTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testBookWithWebSocket() throws Exception {
    String address = "ws://localhost:" + getPort() + "/websocket";

    BookStoreWebSocket resource = JAXRSClientFactory.create(address, BookStoreWebSocket.class);
    Client client = WebClient.client(resource);
    client.header(HttpHeaders.USER_AGENT, JAXRSClientConduitWebSocketTest.class.getName());

    // call the GET service
    assertEquals("CXF in Action", new String(resource.getBookName()));

    // call the GET service in text mode
    //TODO add some way to control the client to switch between the bytes and text modes
    assertEquals("CXF in Action", new String(resource.getBookName()));

    // call another GET service
    Book book = resource.getBook(123);
    assertEquals("CXF in Action", book.getName());

    // call the POST service
    assertEquals(Long.valueOf(123), resource.echoBookId(123));

    // call the same POST service in the text mode
    //TODO add some way to control the client to switch between the bytes and text modes
    assertEquals(Long.valueOf(123), resource.echoBookId(123));

    // call the GET service returning a continous stream output
    //TODO there is no way to get the continuous stream at the moment
    //resource.getBookBought();

}
 
Example 5
Source File: AnotherFakeApiTest.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    JacksonJsonProvider provider = new JacksonJsonProvider();
    List providers = new ArrayList();
    providers.add(provider);
    
    api = JAXRSClientFactory.create("http://petstore.swagger.io:80/v2", AnotherFakeApi.class, providers);
    org.apache.cxf.jaxrs.client.Client client = WebClient.client(api);
    
    ClientConfiguration config = WebClient.getConfig(client); 
}
 
Example 6
Source File: ClientInterceptorTest.java    From gazpachoquest with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void authenticateTest() {
    AuthenticationResource authenticationResource = JAXRSClientFactory.create(BASE_URI,
            AuthenticationResource.class, Collections.singletonList(new JacksonJsonProvider()), null);
    Client client = WebClient.client(authenticationResource);
    Account account = authenticationResource.authenticate("YAS5ICHRBE");
}
 
Example 7
Source File: UserApiTest.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    JacksonJsonProvider provider = new JacksonJsonProvider();
    List providers = new ArrayList();
    providers.add(provider);
    
    api = JAXRSClientFactory.create("http://petstore.swagger.io:80/v2", UserApi.class, providers);
    org.apache.cxf.jaxrs.client.Client client = WebClient.client(api);
    
    ClientConfiguration config = WebClient.getConfig(client); 
}
 
Example 8
Source File: SyncopeClient.java    From syncope with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an instance of the given service class, with configured content type and authentication.
 *
 * @param <T> any service class
 * @param serviceClass service class reference
 * @return service instance of the given reference class
 */
public <T> T getService(final Class<T> serviceClass) {
    synchronized (restClientFactory) {
        restClientFactory.setServiceClass(serviceClass);
        T serviceInstance = restClientFactory.create(serviceClass);

        Client client = WebClient.client(serviceInstance);
        client.type(mediaType).accept(mediaType);
        if (serviceInstance instanceof AnyService || serviceInstance instanceof ExecutableService) {
            client.accept(RESTHeaders.MULTIPART_MIXED);
        }

        ClientConfiguration config = WebClient.getConfig(client);
        config.getRequestContext().put(HEADER_SPLIT_PROPERTY, true);
        config.getRequestContext().put(URLConnectionHTTPConduit.HTTPURL_CONNECTION_METHOD_REFLECTION, true);
        if (useCompression) {
            config.getInInterceptors().add(new GZIPInInterceptor());
            config.getOutInterceptors().add(new GZIPOutInterceptor());
        }
        if (tlsClientParameters != null) {
            HTTPConduit httpConduit = (HTTPConduit) config.getConduit();
            httpConduit.setTlsClientParameters(tlsClientParameters);
        }

        return serviceInstance;
    }
}
 
Example 9
Source File: CustomApiTest.java    From swagger-aem with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    JacksonJsonProvider provider = new JacksonJsonProvider();
    List providers = new ArrayList();
    providers.add(provider);
    
    api = JAXRSClientFactory.create("http://localhost", CustomApi.class, providers);
    org.apache.cxf.jaxrs.client.Client client = WebClient.client(api);
    
    ClientConfiguration config = WebClient.getConfig(client); 
}
 
Example 10
Source File: DocumentTypesApiTest.java    From opencps-v2 with GNU Affero General Public License v3.0 5 votes vote down vote up
@Before
public void setup() {
    JacksonJsonProvider provider = new JacksonJsonProvider();
    List providers = new ArrayList();
    providers.add(provider);
    
    api = JAXRSClientFactory.create("https://virtserver.swaggerhub.com/binhthgc/opencps/1.0.0", DocumentTypesApi.class, providers);
    org.apache.cxf.jaxrs.client.Client client = WebClient.client(api);
    
    ClientConfiguration config = WebClient.getConfig(client); 
}
 
Example 11
Source File: SlingApiTest.java    From swagger-aem with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    JacksonJsonProvider provider = new JacksonJsonProvider();
    List providers = new ArrayList();
    providers.add(provider);
    
    api = JAXRSClientFactory.create("http://localhost", SlingApi.class, providers);
    org.apache.cxf.jaxrs.client.Client client = WebClient.client(api);
    
    ClientConfiguration config = WebClient.getConfig(client); 
}
 
Example 12
Source File: DossierStatisticApiTest.java    From opencps-v2 with GNU Affero General Public License v3.0 5 votes vote down vote up
@Before
public void setup() {
    JacksonJsonProvider provider = new JacksonJsonProvider();
    List providers = new ArrayList();
    providers.add(provider);
    
    api = JAXRSClientFactory.create("https://virtserver.swaggerhub.com/binhthgc/opencps/1.0.0", DossierStatisticApi.class, providers);
    org.apache.cxf.jaxrs.client.Client client = WebClient.client(api);
    
    ClientConfiguration config = WebClient.getConfig(client); 
}
 
Example 13
Source File: AnotherFakeApiTest.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    List<?> providers = Arrays.asList(new JacksonJsonProvider(), new JacksonXMLProvider(), new MultipartProvider());

    api = JAXRSClientFactory.create("http://localhost:" + serverPort + "/services", AnotherFakeApi.class, providers);
    org.apache.cxf.jaxrs.client.Client client = WebClient.client(api);

    ClientConfiguration config = WebClient.getConfig(client); 
}
 
Example 14
Source File: FakeApiTest.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    List<?> providers = Arrays.asList(new JacksonJsonProvider(), new JacksonXMLProvider(), new MultipartProvider());

    api = JAXRSClientFactory.create("http://localhost:" + serverPort + "/services", FakeApi.class, providers);
    org.apache.cxf.jaxrs.client.Client client = WebClient.client(api);

    ClientConfiguration config = WebClient.getConfig(client); 
}
 
Example 15
Source File: CustomApiTest.java    From swagger-aem with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    JacksonJsonProvider provider = new JacksonJsonProvider();
    List providers = new ArrayList();
    providers.add(provider);
    
    api = JAXRSClientFactory.create("http://localhost", CustomApi.class, providers);
    org.apache.cxf.jaxrs.client.Client client = WebClient.client(api);
    
    ClientConfiguration config = WebClient.getConfig(client); 
}
 
Example 16
Source File: CrxApiTest.java    From swagger-aem with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    JacksonJsonProvider provider = new JacksonJsonProvider();
    List providers = new ArrayList();
    providers.add(provider);
    
    api = JAXRSClientFactory.create("http://localhost", CrxApi.class, providers);
    org.apache.cxf.jaxrs.client.Client client = WebClient.client(api);
    
    ClientConfiguration config = WebClient.getConfig(client); 
}
 
Example 17
Source File: BlueOceanApiTest.java    From swaggy-jenkins with MIT License 5 votes vote down vote up
@Before
public void setup() {
    JacksonJsonProvider provider = new JacksonJsonProvider();
    List providers = new ArrayList();
    providers.add(provider);
    
    api = JAXRSClientFactory.create("http://localhost", BlueOceanApi.class, providers);
    org.apache.cxf.jaxrs.client.Client client = WebClient.client(api);
    
    ClientConfiguration config = WebClient.getConfig(client); 
}
 
Example 18
Source File: StoreApiTest.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    List<?> providers = Arrays.asList(new JacksonJsonProvider(), new JacksonXMLProvider(), new MultipartProvider());

    api = JAXRSClientFactory.create("http://localhost:" + serverPort + "/services", StoreApi.class, providers);
    org.apache.cxf.jaxrs.client.Client client = WebClient.client(api);

    ClientConfiguration config = WebClient.getConfig(client); 
}
 
Example 19
Source File: ReconciliationRestClient.java    From syncope with Apache License 2.0 5 votes vote down vote up
public static ArrayList<ProvisioningReport> pull(final CSVPullSpec spec, final InputStream csv) {
    ReconciliationService service = getService(ReconciliationService.class);
    Client client = WebClient.client(service);
    client.type(RESTHeaders.TEXT_CSV);

    ArrayList<ProvisioningReport> result = service.pull(spec, csv).stream().
            collect(Collectors.toCollection(ArrayList::new));

    SyncopeConsoleSession.get().resetClient(ReconciliationService.class);

    return result;
}
 
Example 20
Source File: ConsoleApiTest.java    From swagger-aem with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    JacksonJsonProvider provider = new JacksonJsonProvider();
    List providers = new ArrayList();
    providers.add(provider);
    
    api = JAXRSClientFactory.create("http://localhost", ConsoleApi.class, providers);
    org.apache.cxf.jaxrs.client.Client client = WebClient.client(api);
    
    ClientConfiguration config = WebClient.getConfig(client); 
}