Refine search
static JAXRSClientFactoryBean getBean(String baseAddress, String configLocation) { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); if (configLocation != null) { SpringBusFactory bf = new SpringBusFactory(); Bus bus = bf.createBus(configLocation); bean.setBus(bus); } bean.setAddress(baseAddress); return bean; }
ProxyClassLoader classLoader = new ProxyClassLoader(); classLoader.addLoader(resourceApiClass.getClassLoader()); classLoader.addLoader(JAXRSClientFactoryBean.class.getClassLoader()); JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(baseUrl); bean.setServiceClass(resourceApiClass); bean.setClassLoader(classLoader); return bean.create(resourceApiClass);
private WebClient createClient(String address, String userName, String password) { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(address); bean.setUsername(userName); bean.setPassword(password); bean.getOutInterceptors().add(new LoggingOutInterceptor()); bean.getInInterceptors().add(new LoggingInInterceptor()); return bean.createWebClient(); }
/** * Creates WebClient * @param baseAddress baseAddress */ public static WebClient create(String baseAddress) { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(baseAddress); return bean.createWebClient(); }
/** * Create a Client instance. Proxies and WebClients are Clients. * @return the client */ public Client create() { if (serviceClass == WebClient.class) { return createWebClient(); } return createWithValues(); }
private static JAXRSClientFactoryBean cleanFactory(JAXRSClientFactoryBean bean) { bean.setUsername(null); bean.setPassword(null); bean.setInitialState(null); bean.setFeatures(Arrays.<AbstractFeature>asList()); return bean; }
private BookStore createBookStoreTwoRecipients(String address) throws Exception { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); SpringBusFactory bf = new SpringBusFactory(); URL busFile = JAXRSJweJsonTest.class.getResource("client.xml"); Bus springBus = bf.createBus(busFile.toString()); bean.setBus(springBus); bean.setServiceClass(BookStore.class); bean.setAddress(address); bean.setProvider(new JweJsonWriterInterceptor()); List<String> properties = new ArrayList<>(); properties.add("org/apache/cxf/systest/jaxrs/security/jwejson1.properties"); properties.add("org/apache/cxf/systest/jaxrs/security/jwejson2.properties"); bean.getProperties(true).put(JoseConstants.RSSEC_ENCRYPTION_PROPS, properties); return bean.create(BookStore.class); }
private WebClient createRsWebClient(String address, ClientAccessToken at, String clientContext) { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(address); SpringBusFactory bf = new SpringBusFactory(); URL busFile = JAXRSOAuth2TlsTest.class.getResource(clientContext); Bus springBus = bf.createBus(busFile.toString()); bean.setBus(springBus); WebClient wc = bean.createWebClient(); wc.accept(MediaType.APPLICATION_XML); wc.authorization(at); return wc; }
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(address); SpringBusFactory bf = new SpringBusFactory(); URL busFile = JAXRSXmlSecTest.class.getResource("client.xml"); Bus springBus = bf.createBus(busFile.toString()); bean.setBus(springBus); properties.put(SecurityConstants.SIGNATURE_PROPERTIES, "org/apache/cxf/systest/jaxrs/security/bethal.properties"); bean.setProperties(properties); if (test.streaming) { XmlSecOutInterceptor sigOutInterceptor = new XmlSecOutInterceptor(); sigOutInterceptor.setSignRequest(true); bean.getOutInterceptors().add(sigOutInterceptor); bean.setProvider(sigInInterceptor); } else { XmlSigOutInterceptor sigOutInterceptor = new XmlSigOutInterceptor(); bean.getOutInterceptors().add(sigOutInterceptor); bean.getInInterceptors().add(sigInInterceptor); WebClient wc = bean.createWebClient(); WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000L); try { wc.type("application/xml").post(new Book("CXF", 126L), Book.class); fail("Failure expected on signature trust failure"); } catch (ProcessingException ex) {
@Test public void testInvalidSAMLTokenAsHeader() throws Exception { String address = "https://localhost:" + PORT + "/samlheader/bookstore/books/123"; JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(address); SpringBusFactory bf = new SpringBusFactory(); URL busFile = JAXRSSamlTest.class.getResource("client.xml"); Bus springBus = bf.createBus(busFile.toString()); bean.setBus(springBus); WebClient wc = bean.createWebClient(); wc.header("Authorization", "SAML invalid_grant"); Response r = wc.get(); assertEquals(401, r.getStatus()); }
@Test public void testPostGetBookFastinfoset() throws Exception { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress("http://localhost:" + PORT + "/test/services/rest3/bookstore/fastinfoset"); bean.getOutInterceptors().add(new FIStaxOutInterceptor()); bean.getInInterceptors().add(new FIStaxInInterceptor()); JAXBElementProvider<?> p = new JAXBElementProvider<>(); p.setConsumeMediaTypes(Collections.singletonList("application/fastinfoset")); p.setProduceMediaTypes(Collections.singletonList("application/fastinfoset")); bean.setProvider(p); Map<String, Object> props = new HashMap<>(); props.put(FIStaxOutInterceptor.FI_ENABLED, Boolean.TRUE); bean.setProperties(props); WebClient client = bean.createWebClient(); Book b = new Book("CXF", 1L); Book b2 = client.type("application/fastinfoset").accept("application/fastinfoset") .post(b, Book.class); assertEquals(b2.getName(), b.getName()); assertEquals(b2.getId(), b.getId()); }
@Test public void testOtherInterceptorDrainingStream() throws Exception { String baseAddress = "http://localhost:" + PORT + "/test/services/rest"; JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(baseAddress); bean.getInInterceptors().add(new TestStreamDrainInterptor()); WebClient client = bean.createWebClient(); client.path("/bookstore/123").accept(MediaType.APPLICATION_XML_TYPE); Book b = client.get(Book.class); assertEquals(123, b.getId()); assertEquals("CXF in Action", b.getName()); }
@Test public void testGetBook123UserModelAuthorize() throws Exception { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress("http://localhost:" + PORT + "/usermodel/bookstore/books"); bean.setUsername("Barry"); bean.setPassword("password"); bean.setModelRef("classpath:org/apache/cxf/systest/jaxrs/resources/resources.xml"); WebClient proxy = bean.createWebClient(); proxy.path("{id}/authorize", 123); Book book = proxy.get(Book.class); assertEquals(123L, book.getId()); }
@Test public void testAddFeatureToClient() throws Exception { String baseAddress = "http://localhost:" + PORT + "/test/services/rest"; JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(baseAddress); bean.setResourceClass(BookStoreJaxrsJaxws.class); TestFeature testFeature = new TestFeature(); List<AbstractFeature> features = new ArrayList<>(); features.add(testFeature); bean.setFeatures(features); BookStoreJaxrsJaxws proxy = (BookStoreJaxrsJaxws)bean.create(); Book b = proxy.getBook(Long.valueOf("123")); assertTrue("Out Interceptor not invoked", testFeature.handleMessageOnOutInterceptorCalled()); assertTrue("In Interceptor not invoked", testFeature.handleMessageOnInInterceptorCalled()); assertEquals(123, b.getId()); assertEquals("CXF in Action", b.getName()); }
protected JAXRSClientFactoryBean getClientFactory() { if (null == cachedClientFactory) { JAXRSClientFactoryBean factoryBean = new JAXRSClientFactoryBean(); factoryBean.setThreadSafe(true); factoryBean.setAddress(getServerURL()); if (Authentication.BASIC == auxiliaryStorageAuthentication) { factoryBean.setUsername(authenticationUser); factoryBean.setPassword(authenticationPassword); } if (Authentication.SAML == auxiliaryStorageAuthentication) { STSClient stsClient = STSClientCreator.create(factoryBean.getBus(), stsProps); STSRESTOutInterceptor outInterceptor = new STSRESTOutInterceptor(); outInterceptor.setStsClient(stsClient); factoryBean.getOutInterceptors().add(outInterceptor); factoryBean.getOutInterceptors().add(new SamlHeaderOutInterceptor()); } cachedClientFactory = factoryBean; } return cachedClientFactory; }
@Test public void testGetStringList() throws Exception { String address = "http://localhost:" + PORT; JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setProvider(new BookStore.StringListBodyReaderWriter()); bean.setAddress(address); bean.setResourceClass(BookStore.class); BookStore store = bean.create(BookStore.class); List<String> str = store.getBookListArray(); assertEquals("Good book", str.get(0)); }
@Test public void testEmptyPostProxy2() throws Exception { String address = "http://localhost:" + PORT; JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(address); bean.setResourceClass(BookStore.class); BookStore store = bean.create(BookStore.class); store.emptypostNoPath(); assertEquals(204, WebClient.client(store).getResponse().getStatus()); }
protected JAXRSClientFactoryBean defaultRestClientFactoryBean() { JAXRSClientFactoryBean defaultRestClientFactoryBean = new JAXRSClientFactoryBean(); defaultRestClientFactoryBean.setHeaders(new HashMap<>()); if (StringUtils.isBlank(address)) { throw new IllegalArgumentException("Property 'address' is missing"); } defaultRestClientFactoryBean.setAddress(address); if (StringUtils.isNotBlank(domain)) { defaultRestClientFactoryBean.getHeaders().put(RESTHeaders.DOMAIN, Collections.singletonList(domain)); } defaultRestClientFactoryBean.setThreadSafe(true); defaultRestClientFactoryBean.setInheritHeaders(true); List<Feature> features = new ArrayList<>(); features.add(new LoggingFeature()); defaultRestClientFactoryBean.setFeatures(features); List<Object> providers = new ArrayList<>(4); providers.add(new DateParamConverterProvider()); providers.add(getJaxbProvider()); providers.add(getJsonProvider()); providers.add(getExceptionMapper()); defaultRestClientFactoryBean.setProviders(providers); return defaultRestClientFactoryBean; }
/** * Creates a proxy which will do basic authentication * @param baseAddress baseAddress * @param cls proxy class, if not interface then a CGLIB proxy will be created * @param providers list of providers * @param username username * @param password password * @param configLocation classpath location of the configuration resource * @return typed proxy */ public static <T> T create(String baseAddress, Class<T> cls, List<?> providers, String username, String password, String configLocation) { JAXRSClientFactoryBean bean = getBean(baseAddress, cls, configLocation); bean.setUsername(username); bean.setPassword(password); bean.setProviders(providers); return bean.create(cls); }
/** * Creates WebClient which will do basic authentication * @param baseAddress baseAddress * @param username username * @param password password * @param configLocation classpath location of the configuration resource, can be null * @return WebClient instance */ public static WebClient create(String baseAddress, String username, String password, String configLocation) { JAXRSClientFactoryBean bean = getBean(baseAddress, configLocation); bean.setUsername(username); bean.setPassword(password); return bean.createWebClient(); }