Java Code Examples for org.apache.cxf.jaxrs.client.JAXRSClientFactory#create()
The following examples show how to use
org.apache.cxf.jaxrs.client.JAXRSClientFactory#create() .
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: JaxRsClientStarter.java From paymentgateway with GNU General Public License v3.0 | 6 votes |
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 2
Source File: JAXRSAsyncClientTest.java From cxf with Apache License 2.0 | 6 votes |
@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 3
Source File: JAXRSClientServerBookTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testGetBookFromResponseWithProxy() throws Exception { BookStore bs = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class); Response r = bs.getGenericResponseBook("123"); assertEquals(200, r.getStatus()); Book book = r.readEntity(Book.class); assertEquals(123L, book.getId()); }
Example 4
Source File: DossierStatisticApiTest.java From opencps-v2 with GNU Affero General Public License v3.0 | 5 votes |
@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 5
Source File: JAXRSLocalTransportTest.java From cxf with Apache License 2.0 | 5 votes |
@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 6
Source File: AnotherFakeApiTest.java From openapi-generator with Apache License 2.0 | 5 votes |
@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 7
Source File: JAXRSLocalTransportTest.java From cxf with Apache License 2.0 | 5 votes |
@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 8
Source File: AbstractArchivaRestTest.java From archiva with Apache License 2.0 | 5 votes |
protected BrowseService getBrowseService( String authzHeader, boolean useXml ) { // START SNIPPET: cxf-browseservice-creation BrowseService service = JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/", BrowseService.class, Arrays.asList( new JacksonJaxbJsonProvider( ), new JacksonJaxbXMLProvider( ) ) ); // to add authentification if ( authzHeader != null ) { WebClient.client( service ).header( "Authorization", authzHeader ); } // Set the Referer header to your archiva server url WebClient.client(service).header("Referer","http://localhost:"+getServerPort()); WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000000 ); if ( useXml ) { WebClient.client( service ).accept( MediaType.APPLICATION_XML_TYPE ); WebClient.client( service ).type( MediaType.APPLICATION_XML_TYPE ); } else { WebClient.client( service ).accept( MediaType.APPLICATION_JSON_TYPE ); WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE ); } return service; // END SNIPPET: cxf-browseservice-creation }
Example 9
Source File: JAXRSLocalTransportTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testProxyServerInFaultDirectDispatch() throws Exception { BookStore localProxy = JAXRSClientFactory.create("local://books", BookStore.class); WebClient.getConfig(localProxy).getRequestContext().put(LocalConduit.DIRECT_DISPATCH, "true"); WebClient.getConfig(localProxy).getInFaultInterceptors().add(new TestFaultInInterceptor()); Response r = localProxy.infault2(); assertEquals(500, r.getStatus()); }
Example 10
Source File: StoreApiTest.java From openapi-generator with Apache License 2.0 | 5 votes |
@Before public void setup() { JacksonJsonProvider provider = new JacksonJsonProvider(); List providers = new ArrayList(); providers.add(provider); api = JAXRSClientFactory.create("http://petstore.swagger.io:80/v2", StoreApi.class, providers); org.apache.cxf.jaxrs.client.Client client = WebClient.client(api); ClientConfiguration config = WebClient.getConfig(client); }
Example 11
Source File: JAXRSLocalTransportTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testProxyWithQuery() throws Exception { BookStore localProxy = JAXRSClientFactory.create("local://books", BookStore.class); WebClient.getConfig(localProxy).getRequestContext().put(LocalConduit.DIRECT_DISPATCH, Boolean.TRUE); Book book = localProxy.getBookByURLQuery(new String[] {"1", "2", "3"}); assertEquals(123L, book.getId()); }
Example 12
Source File: StoreApiTest.java From openapi-generator with Apache License 2.0 | 5 votes |
@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 13
Source File: AbstractArchivaRestTest.java From archiva with Apache License 2.0 | 5 votes |
protected NetworkProxyService getNetworkProxyService() { NetworkProxyService service = JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/", NetworkProxyService.class, Arrays.asList( new JacksonJaxbJsonProvider( ), new JacksonJaxbXMLProvider( ) ) ); WebClient.client( service ).header( "Authorization", authorizationHeader ); WebClient.client(service).header("Referer","http://localhost:"+getServerPort()); WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 ); WebClient.client( service ).accept( MediaType.APPLICATION_JSON_TYPE ); WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE ); return service; }
Example 14
Source File: JAXRSSoapBookTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testGetBookSubresourceParamExtensions() throws Exception { String baseAddress = "http://localhost:" + PORT + "/test/services/rest"; BookStoreJaxrsJaxws proxy = JAXRSClientFactory.create(baseAddress, BookStoreJaxrsJaxws.class); WebClient.getConfig(proxy).getOutInterceptors().add(new LoggingOutInterceptor()); BookSubresource bs = proxy.getBookSubresource("139"); Book bean = new Book("CXF Rocks", 139L); Book b = bs.getTheBook4(bean, bean, bean, bean); assertEquals(139, b.getId()); assertEquals("CXF Rocks", b.getName()); }
Example 15
Source File: UserApiTest.java From openapi-generator with Apache License 2.0 | 5 votes |
@Before public void setup() { List<?> providers = Arrays.asList(new JacksonJsonProvider(), new JacksonXMLProvider(), new MultipartProvider()); api = JAXRSClientFactory.create("http://localhost:" + serverPort + "/services", UserApi.class, providers); org.apache.cxf.jaxrs.client.Client client = WebClient.client(api); ClientConfiguration config = WebClient.getConfig(client); }
Example 16
Source File: JAXRSClientServerResourceJacksonSpringProviderTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testEchoGenericSuperBookCollectionProxy() throws Exception { String endpointAddress = "http://localhost:" + PORT + "/webapp/custombus/genericstore"; GenericBookStoreSpring proxy = JAXRSClientFactory.create(endpointAddress, GenericBookStoreSpring.class, Collections.singletonList(new JacksonJsonProvider())); List<SuperBook> books = proxy.echoSuperBookCollectionJson(Collections.singletonList(new SuperBook("Super", 124L, true))); assertEquals(124L, books.get(0).getId()); assertTrue(books.get(0).isSuperBook()); }
Example 17
Source File: UDDIInquiryJAXRSTest.java From juddi with Apache License 2.0 | 5 votes |
public UDDIInquiryJAXRSTest() { List<Object> providers = new ArrayList<Object>(); // add custom providers if any providers.add(new org.apache.cxf.jaxrs.provider.JAXBElementProvider()); Map<String, Object> properties = new HashMap<String, Object>(); // Create a mapping between the XML namespaces and the JSON prefixes. // The JSON prefix can be "" to specify that you don't want any prefix. HashMap<String, String> nstojns = new HashMap<String, String>(); nstojns.put("urn:uddi-org:api_v3", "urn:uddi-org:api_v3"); nstojns.put("urn:uddi-org:sub_v3", "urn:uddi-org:sub_v3"); nstojns.put("urn:uddi-org:custody_v3", "urn:uddi-org:custody_v3"); nstojns.put("urn:uddi-org:repl_v3", "urn:uddi-org:repl_v3"); nstojns.put("urn:uddi-org:subr_v3", "urn:uddi-org:subr_v3"); nstojns.put("urn:uddi-org:repl_v3", "urn:uddi-org:repl_v3"); nstojns.put("urn:uddi-org:vs_v3", "urn:uddi-org:vs_v3"); nstojns.put("urn:uddi-org:vscache_v3", "urn:uddi-org:vscache_v3"); nstojns.put("urn:uddi-org:policy_v3", "urn:uddi-org:policy_v3"); nstojns.put("urn:uddi-org:policy_instanceParms_v3", "urn:uddi-org:policy_instanceParms_v3"); nstojns.put("http://www.w3.org/2000/09/xmldsig#", "http://www.w3.org/2000/09/xmldsig#"); properties.put("namespaceMap", nstojns); JSONProvider jsonProvider = new org.apache.cxf.jaxrs.provider.json.JSONProvider(); jsonProvider.setNamespaceMap(nstojns); providers.add(jsonProvider); instance = JAXRSClientFactory.create(ENDPOINT_ADDRESS, UDDIInquiryJAXRS.class, providers); }
Example 18
Source File: JAXRSClientServerSpringBookTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testPostBookXsiTypeProxy() throws Exception { String address = "http://localhost:" + PORT + "/the/thebooksxsi/bookstore"; JAXBElementProvider<Book> provider = new JAXBElementProvider<>(); provider.setExtraClass(new Class[]{SuperBook.class}); provider.setJaxbElementClassNames(Collections.singletonList(Book.class.getName())); BookStoreSpring bookStore = JAXRSClientFactory.create(address, BookStoreSpring.class, Collections.singletonList(provider)); SuperBook book = new SuperBook("SuperBook2", 999L, true); Book book2 = bookStore.postGetBookXsiType(book); assertEquals("SuperBook2", book2.getName()); }
Example 19
Source File: Client.java From cxf with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { String keyStoreLoc = "src/main/config/clientKeystore.jks"; KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(new FileInputStream(keyStoreLoc), "cspass".toCharArray()); SSLContext sslcontext = SSLContexts.custom() .loadTrustMaterial(keyStore, null) .loadKeyMaterial(keyStore, "ckpass".toCharArray()) .useProtocol("TLSv1.2") .build(); /* * Send HTTP GET request to query customer info using portable HttpClient * object from Apache HttpComponents */ SSLConnectionSocketFactory sf = new SSLConnectionSocketFactory(sslcontext); System.out.println("Sending HTTPS GET request to query customer info"); CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sf).build(); HttpGet httpget = new HttpGet(BASE_SERVICE_URL + "/123"); BasicHeader bh = new BasicHeader("Accept", "text/xml"); httpget.addHeader(bh); CloseableHttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); entity.writeTo(System.out); response.close(); httpclient.close(); /* * Send HTTP PUT request to update customer info, using CXF WebClient method * Note: if need to use basic authentication, use the WebClient.create(baseAddress, * username,password,configFile) variant, where configFile can be null if you're * not using certificates. */ System.out.println("\n\nSending HTTPS PUT to update customer name"); WebClient wc = WebClient.create(BASE_SERVICE_URL, CLIENT_CONFIG_FILE); Customer customer = new Customer(); customer.setId(123); customer.setName("Mary"); Response resp = wc.put(customer); /* * Send HTTP POST request to add customer, using JAXRSClientProxy * Note: if need to use basic authentication, use the JAXRSClientFactory.create(baseAddress, * username,password,configFile) variant, where configFile can be null if you're * not using certificates. */ System.out.println("\n\nSending HTTPS POST request to add customer"); CustomerService proxy = JAXRSClientFactory.create(BASE_SERVICE_URL, CustomerService.class, CLIENT_CONFIG_FILE); customer = new Customer(); customer.setName("Jack"); resp = wc.post(customer); System.out.println("\n"); System.exit(0); }
Example 20
Source File: JAXRSLocalTransportTest.java From cxf with Apache License 2.0 | 4 votes |
@Test public void testProxyServerInFaultEscaped() throws Exception { BookStore localProxy = JAXRSClientFactory.create("local://books", BookStore.class); Response r = localProxy.infault2(); assertEquals(500, r.getStatus()); }