org.apache.cxf.jaxrs.client.JAXRSClientFactory Java Examples

The following examples show how to use org.apache.cxf.jaxrs.client.JAXRSClientFactory. 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 7 votes vote down vote up
private void runProxies(BookStore proxy, int numberOfClients,
                        boolean threadSafe, boolean stateCanBeChanged) throws Exception {
    ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 5, 0, TimeUnit.SECONDS,
                                                        new ArrayBlockingQueue<Runnable>(10));
    CountDownLatch startSignal = new CountDownLatch(1);
    CountDownLatch doneSignal = new CountDownLatch(numberOfClients);

    for (int i = 1; i <= numberOfClients; i++) {
        // here we do a double copy : from proxy to web client and back to proxy
        BookStore bs = !threadSafe ? JAXRSClientFactory.fromClient(
               WebClient.fromClient(WebClient.client(proxy)), BookStore.class) : proxy;
        String bookName = stateCanBeChanged ? Integer.toString(i) : "TheBook";
        String bookHeader = stateCanBeChanged ? "value" + i : "CustomValue";

        executor.execute(new RootProxyWorker(bs, bookName, bookHeader,
                        startSignal, doneSignal, stateCanBeChanged));
    }
    startSignal.countDown();
    doneSignal.await(60, TimeUnit.SECONDS);
    executor.shutdownNow();
    assertEquals("Not all invocations have completed", 0, doneSignal.getCount());
}
 
Example #2
Source File: AbstractArchivaRestTest.java    From archiva with Apache License 2.0 6 votes vote down vote up
protected CommonServices getCommonServices( String authzHeader )
{
    CommonServices service =
        JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/",
                                   CommonServices.class,
                                   Arrays.asList( new JacksonJaxbJsonProvider( ), new JacksonJaxbXMLProvider( ) )  );

    if ( authzHeader != null )
    {
        WebClient.client( service ).header( "Authorization", authzHeader );
    }
    WebClient.client(service).header("Referer","http://localhost:"+getServerPort());
    WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000000 );
    WebClient.client( service ).accept( MediaType.APPLICATION_JSON_TYPE );
    WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );
    return service;
}
 
Example #3
Source File: JAXRSMultipartTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetBookJsonProxy() throws Exception {
    String address = "http://localhost:" + PORT;
    MultipartStore client = JAXRSClientFactory.create(address, MultipartStore.class);

    Map<String, Book> map = client.getBookJson();
    List<Book> result = new ArrayList<>(map.values());
    assertEquals(1, result.size());
    Book json = result.get(0);
    assertEquals("json", json.getName());
    assertEquals(1L, json.getId());

    String contentType =
        WebClient.client(client).getResponse().getMetadata().getFirst("Content-Type").toString();
    MediaType mt = MediaType.valueOf(contentType);
    assertEquals("multipart", mt.getType());
    assertEquals("mixed", mt.getSubtype());
}
 
Example #4
Source File: JAXRSJmsTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetBookFromSubresourceProxyClientWithTextJMSMessage() throws Exception {
    // setup the the client
    String endpointAddressUrlEncoded = "jms:jndi:dynamicQueues/test.jmstransport.text"
         + "?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory"
         + "&replyToName=dynamicQueues/test.jmstransport.response"
         + "&jndiURL=tcp://localhost:" + JMS_PORT
         + "&jndiConnectionFactoryName=ConnectionFactory"
         + "&messageType=text";

    JMSBookStore client = JAXRSClientFactory.create(endpointAddressUrlEncoded, JMSBookStore.class);
    Book bookProxy = client.getBookSubResource("123");
    Book book = bookProxy.retrieveState();
    assertEquals("Get a wrong response code.", 200, WebClient.client(bookProxy).getResponse().getStatus());
    assertEquals("Get a wrong book id.", 123, book.getId());
}
 
Example #5
Source File: JAXRSSoapBookTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetBookSubresourceWebClientProxyBean() throws Exception {

    WebClient client = WebClient.create("http://localhost:" + PORT + "/test/services/rest");
    client.type(MediaType.TEXT_PLAIN_TYPE)
        .accept(MediaType.APPLICATION_XML_TYPE, MediaType.TEXT_XML_TYPE);
    BookStoreJaxrsJaxws proxy =
        JAXRSClientFactory.fromClient(client, BookStoreJaxrsJaxws.class, true);

    doTestSubresource(proxy);

    BookStoreJaxrsJaxws proxy2 = JAXRSClientFactory.fromClient(
        WebClient.client(proxy), BookStoreJaxrsJaxws.class);
    doTestSubresource(proxy2);

}
 
Example #6
Source File: JAXRSAsyncClientTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testAsyncProxyBookResponse() throws Exception {
    String address = "http://localhost:" + PORT;
    final Holder<Book> holder = new Holder<>();
    final InvocationCallback<Book> callback = new InvocationCallback<Book>() {
        public void completed(Book response) {
            holder.value = response;
        }
        public void failed(Throwable error) {
        }
    };

    BookStore store = JAXRSClientFactory.create(address, BookStore.class);
    WebClient.getConfig(store).getRequestContext().put(InvocationCallback.class.getName(), callback);
    Book book = store.getBookByMatrixParams("12", "3");
    assertNull(book);
    Thread.sleep(3000);
    assertNotNull(holder.value);
    assertEquals(123L, holder.value.getId());
}
 
Example #7
Source File: JAXRSClientServerValidationSpringTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testHelloRestValidationFailsIfNameIsNull() throws Exception {
    String address = "http://localhost:" + PORT + "/bwrest";

    BookWorld service = JAXRSClientFactory.create(address, BookWorld.class);

    BookWithValidation bw = service.echoBook(new BookWithValidation("RS", "123"));
    assertEquals("123", bw.getId());

    try {
        service.echoBook(new BookWithValidation(null, "123"));
        fail("Validation failure expected");
    } catch (BadRequestException ex) {
        // complete
    }

}
 
Example #8
Source File: RuntimeInfoServiceTest.java    From archiva with Apache License 2.0 6 votes vote down vote up
@Test
public void runtimeInfoService()
    throws Exception
{
    RuntimeInfoService service =
        JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaUiServices/",
                                   RuntimeInfoService.class,
                                   Collections.singletonList( new JacksonJaxbJsonProvider() ) );

    WebClient.client(service).header("Referer","http://localhost");
    ApplicationRuntimeInfo applicationRuntimeInfo = service.getApplicationRuntimeInfo( "en" );

    assertEquals( System.getProperty( "expectedVersion" ), applicationRuntimeInfo.getVersion() );
    assertFalse( applicationRuntimeInfo.isJavascriptLog() );
    assertTrue( applicationRuntimeInfo.isLogMissingI18n() );

}
 
Example #9
Source File: JaxRsClientStarter.java    From paymentgateway with GNU General Public License v3.0 6 votes vote down vote up
public T start(Class<T> cls, String url, boolean trustAllCerts, String trustStore, String trustStorePassword, 
	List<?> providers, int connectTimeout, int receiveTimeout) {

	try {
		
		T resource = JAXRSClientFactory.create(url, cls, providers);
	    HTTPConduit conduit = WebClient.getConfig(resource).getHttpConduit();
	    WebClient.getConfig(resource).getInInterceptors().add(new LoggingInInterceptor());
	    WebClient.getConfig(resource).getOutInterceptors().add(new LoggingOutInterceptor());
		configureHTTPS(resource, conduit, trustAllCerts, trustStore, trustStorePassword);
		
	    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); 
	    httpClientPolicy.setConnectionTimeout(connectTimeout); 
	    httpClientPolicy.setReceiveTimeout(receiveTimeout); 
	    conduit.setClient(httpClientPolicy);
		
		return resource;
		
	} catch (Exception e) {
		LOG.error(" rest client '{}': NOT STARTED", url);
		return null;
	}
	
}
 
Example #10
Source File: AbstractArchivaRestTest.java    From archiva with Apache License 2.0 6 votes vote down vote up
protected ArchivaAdministrationService getArchivaAdministrationService()
{
    ArchivaAdministrationService service =
        JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/",
                                   ArchivaAdministrationService.class,
                                   Arrays.asList( new JacksonJaxbJsonProvider( ), new JacksonJaxbXMLProvider( ) )  );

    WebClient.client( service ).accept( MediaType.APPLICATION_JSON_TYPE );
    WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );

    WebClient.client( service ).header( "Authorization", authorizationHeader );
    WebClient.client(service).header("Referer","http://localhost:"+getServerPort());

    WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
    return service;
}
 
Example #11
Source File: JAXRSClientServerBookTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetBookCollection() throws Exception {
    BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class);
    Book b1 = new Book("CXF in Action", 123L);
    Book b2 = new Book("CXF Rocks", 124L);
    List<Book> books = new ArrayList<>();
    books.add(b1);
    books.add(b2);
    List<Book> books2 = store.getBookCollection(books);
    assertNotNull(books2);
    assertNotSame(books, books2);
    assertEquals(2, books2.size());
    Book b11 = books2.get(0);
    assertEquals(123L, b11.getId());
    assertEquals("CXF in Action", b11.getName());
    Book b22 = books2.get(1);
    assertEquals(124L, b22.getId());
    assertEquals("CXF Rocks", b22.getName());
}
 
Example #12
Source File: JAXRSLocalTransportTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testProxyPipedDispatchGetBookType() throws Exception {
    BookStore localProxy =
        JAXRSClientFactory.create("local://books",
                                  BookStore.class,
                                  Collections.singletonList(new JacksonJsonProvider()));
    BookType book = localProxy.getBookType();
    assertEquals(124L, book.getId());
}
 
Example #13
Source File: RemoteAccessApiTest.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", RemoteAccessApi.class, providers);
    org.apache.cxf.jaxrs.client.Client client = WebClient.client(api);
    
    ClientConfiguration config = WebClient.getConfig(client); 
}
 
Example #14
Source File: JAXRSClientServerBookTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testProxyBeanPostFormParam() throws Exception {
    BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class);
    BookStore.BookBeanForm bean = new BookStore.BookBeanForm();
    bean.setId(100L);
    bean.setId2(23L);
    bean.setId3(123);
    Book book = store.postFormBeanParamsBook(bean);
    assertEquals(123L, book.getId());
}
 
Example #15
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); 
}
 
Example #16
Source File: JAXRSClientServerNonSpringBookTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testUserModelInterfaceOneWay() throws Exception {
    BookStoreNoAnnotationsInterface proxy =
        JAXRSClientFactory.createFromModel("http://localhost:" + PORT + "/usermodel2",
                                          BookStoreNoAnnotationsInterface.class,
                          "classpath:org/apache/cxf/systest/jaxrs/resources/resources2.xml", null);

    proxy.pingBookStore();
    assertEquals(202, WebClient.client(proxy).getResponse().getStatus());
}
 
Example #17
Source File: JAXRSSoapBookTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetBookSubresourceParamOrder() throws Exception {

    String baseAddress = "http://localhost:" + PORT + "/test/services/rest";
    BookStoreJaxrsJaxws proxy = JAXRSClientFactory.create(baseAddress,
                                                          BookStoreJaxrsJaxws.class);
    BookSubresource bs = proxy.getBookSubresource("139");
    Book b = bs.getTheBook5("CXF", 555L);
    assertEquals(555, b.getId());
    assertEquals("CXF", b.getName());
}
 
Example #18
Source File: JAXRSClientServerResourceJacksonSpringProviderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetSuperBookProxy() throws Exception {

    String endpointAddress =
        "http://localhost:" + PORT + "/webapp/store2";
    BookStoreSpring proxy = JAXRSClientFactory.create(endpointAddress, BookStoreSpring.class,
        Collections.singletonList(new JacksonJsonProvider()));
    SuperBook book = proxy.getSuperBookJson();
    assertEquals(999L, book.getId());
}
 
Example #19
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 #20
Source File: JAXRSClientServerBookTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testServerWebApplicationExceptionXMLWithProxy() throws Exception {
    BookStore proxy = JAXRSClientFactory.create("http://localhost:" + PORT,
                                                BookStore.class);
    try {
        proxy.throwExceptionXML();
        fail("Exception expected");
    } catch (NotAcceptableException ex) {
        assertEquals(406, ex.getResponse().getStatus());
        Book exBook = ex.getResponse().readEntity(Book.class);
        assertEquals("Exception", exBook.getName());
        assertEquals(999L, exBook.getId());
    }
}
 
Example #21
Source File: JAXRSClientServerBookTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testServerWebApplicationExceptionWithProxy2() throws Exception {
    BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class);
    try {
        store.throwException();
        fail("Exception expected");
    } catch (WebApplicationException ex) {
        assertEquals(500, ex.getResponse().getStatus());
        assertEquals("This is a WebApplicationException", ex.getResponse().readEntity(String.class));
    }
}
 
Example #22
Source File: JAXRSLocalTransportTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubresourceProxyDirectDispatchGet() throws Exception {
    BookStore localProxy =
        JAXRSClientFactory.create("local://books", BookStore.class);

    WebClient.getConfig(localProxy).getRequestContext().put(LocalConduit.DIRECT_DISPATCH, "true");

    Book bookSubProxy = localProxy.getBookSubResource("123");
    Book book = bookSubProxy.retrieveState();
    assertEquals(123L, book.getId());
}
 
Example #23
Source File: JAXRSClientServerResourceJacksonSpringProviderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetGenericSuperBookInt2() throws Exception {

    String endpointAddress =
        "http://localhost:" + PORT + "/webapp/genericstoreInt2";
    GenericBookServiceInterface proxy = JAXRSClientFactory.create(endpointAddress,
        GenericBookServiceInterface.class, Collections.singletonList(new JacksonJsonProvider()));
    WebClient.getConfig(proxy).getHttpConduit().getClient().setReceiveTimeout(1000000000L);
    List<SuperBook> books = proxy.getSuperBook();
    assertEquals(1, books.size());
    assertEquals(111L, books.get(0).getId());

}
 
Example #24
Source File: UserRegistrationClient.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
public Response getAllClaims(String tenantDomain) {
    NotificationUsernameRecoveryResource notificationUsernameRecoveryResource = JAXRSClientFactory
            .create(url, NotificationUsernameRecoveryResource.class,
                    IdentityManagementServiceUtil.getInstance().getJSONProvider());
    Response responseObj = notificationUsernameRecoveryResource.getAllLocalSupportedClaims();
    return responseObj;
}
 
Example #25
Source File: JAXRSLocalTransportTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testProxyPipedDispatchPost() throws Exception {
    BookStoreSpring localProxy =
        JAXRSClientFactory.create("local://books", BookStoreSpring.class);

    Book response = localProxy.convertBook(new Book2("New", 124L));
    assertEquals(124L, response.getId());
}
 
Example #26
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 #27
Source File: JAXRSClientServerBookTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testBookWithSpaceProxyWithBufferedStream() throws Exception {
    BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class);
    WebClient.getConfig(store).getResponseContext().put("buffer.proxy.response", "true");
    Book book = store.getBookWithSpace("123");
    assertEquals(123L, book.getId());
    assertTrue(WebClient.client(store).getResponse().readEntity(String.class).contains("<Book"));
}
 
Example #28
Source File: AbstractDownloadTest.java    From archiva with Apache License 2.0 5 votes vote down vote up
protected RemoteRepositoriesService getRemoteRepositoriesService()
{
    RemoteRepositoriesService service =
        JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/",
                                   RemoteRepositoriesService.class,
                                   Collections.singletonList( new JacksonJaxbJsonProvider() ) );

    WebClient.client( service ).header( "Authorization", authorizationHeader );
    WebClient.client( service ).header( "Referer", "http://localhost:" + port );

    WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000L );
    return service;
}
 
Example #29
Source File: BaseRemoteAccessApiTest.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", BaseRemoteAccessApi.class, providers);
    org.apache.cxf.jaxrs.client.Client client = WebClient.client(api);
    
    ClientConfiguration config = WebClient.getConfig(client); 
}
 
Example #30
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); 
}