public void setProperties(Map<String, Object> properties) { if (this.getProperties() != null && properties != null) { this.getProperties().putAll(properties); } else { super.setProperties(properties); } } }
factoryBean.setProperties(Collections.singletonMap(org.apache.cxf.message.Message.MTOM_ENABLED, (Object)"true")); WebClient client = factoryBean.createWebClient();
@Test public void testNoBook357WebClient() throws Exception { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); Map<String, Object> properties = new HashMap<>(); properties.put("org.apache.cxf.http.throw_io_exceptions", Boolean.TRUE); bean.setProperties(properties); bean.setAddress("http://localhost:" + PORT + "/test/services/rest/bookstore/356"); WebClient wc = bean.createWebClient(); Response response = wc.get(); assertEquals(404, response.getStatus()); String msg = IOUtils.readStringFromStream((InputStream)response.getEntity()); assertEquals("No Book with id 356 is available", msg); }
private WebClient createWebClient(String address, Map<String, Object> extraProperties) { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(address); SpringBusFactory bf = new SpringBusFactory(); URL busFile = JAXRSSamlAuthorizationTest.class.getResource("client.xml"); Bus springBus = bf.createBus(busFile.toString()); bean.setBus(springBus); Map<String, Object> properties = new HashMap<>(); properties.put(SecurityConstants.SAML_CALLBACK_HANDLER, "org.apache.cxf.systest.jaxrs.security.saml.SamlCallbackHandler"); if (extraProperties != null) { properties.putAll(extraProperties); } bean.setProperties(properties); bean.getOutInterceptors().add(new SamlEnvelopedOutInterceptor()); return bean.createWebClient(); } }
private WebClient createWebClient(String address, Interceptor<Message> outInterceptor, Object provider, CallbackHandler samlCallbackHandler) { 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); Map<String, Object> properties = new HashMap<>(); properties.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.jaxrs.security.saml.KeystorePasswordCallback"); properties.put(SecurityConstants.SAML_CALLBACK_HANDLER, samlCallbackHandler); properties.put(SecurityConstants.SIGNATURE_USERNAME, "alice"); properties.put(SecurityConstants.SIGNATURE_PROPERTIES, "org/apache/cxf/systest/jaxrs/security/alice.properties"); bean.setProperties(properties); bean.getOutInterceptors().add(outInterceptor); if (provider != null) { bean.setProvider(provider); } return bean.createWebClient(); }
private WebClient createWebClientWithProps(String address) { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(address); SpringBusFactory bf = new SpringBusFactory(); URL busFile = JAXRSOAuth2Test.class.getResource("client.xml"); Bus springBus = bf.createBus(busFile.toString()); bean.setBus(springBus); Map<String, Object> properties = new HashMap<>(); properties.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.jaxrs.security.saml.KeystorePasswordCallback"); SamlCallbackHandler samlCallbackHandler = new SamlCallbackHandler(true); samlCallbackHandler.setIssuer("alice"); String audienceURI = "https://localhost:" + port + "/oauth2-auth/token"; samlCallbackHandler.setAudience(audienceURI); properties.put(SecurityConstants.SAML_CALLBACK_HANDLER, samlCallbackHandler); properties.put(SecurityConstants.SIGNATURE_USERNAME, "alice"); properties.put(SecurityConstants.SIGNATURE_PROPERTIES, CRYPTO_RESOURCE_PROPERTIES); bean.setProperties(properties); bean.getOutInterceptors().add(new Saml2BearerAuthOutInterceptor()); WebClient wc = bean.createWebClient(); wc.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_JSON); return wc; }
bean.setProperties(newProperties);
properties.put(SecurityConstants.SIGNATURE_PROPERTIES, "org/apache/cxf/systest/jaxrs/security/alice.properties"); bean.setProperties(properties);
@Test public void testOldConfiguration() throws Exception { String address = "https://localhost:" + test.port + "/xmlsig"; 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); Map<String, Object> newProperties = new HashMap<>(); newProperties.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.jaxrs.security.saml.KeystorePasswordCallback"); newProperties.put(SecurityConstants.SIGNATURE_USERNAME, "alice"); String cryptoUrl = "org/apache/cxf/systest/jaxrs/security/alice.properties"; newProperties.put(SecurityConstants.SIGNATURE_PROPERTIES, cryptoUrl); bean.setProperties(newProperties); if (test.streaming) { XmlSecOutInterceptor sigInterceptor = new XmlSecOutInterceptor(); sigInterceptor.setSignRequest(true); bean.getOutInterceptors().add(sigInterceptor); } else { XmlSigOutInterceptor sigInterceptor = new XmlSigOutInterceptor(); bean.getOutInterceptors().add(sigInterceptor); } bean.setServiceClass(BookStore.class); BookStore store = bean.create(BookStore.class); Book book = store.addBook(new Book("CXF", 126L)); assertEquals(126L, book.getId()); }
@Test public void testBookWithSpaceProxyPathUrlEncoded() throws Exception { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setServiceClass(BookStore.class); bean.setAddress("http://localhost:" + PORT); bean.setProperties(Collections.<String, Object>singletonMap("url.encode.client.parameters", Boolean.TRUE)); BookStore store = bean.create(BookStore.class); Book book = store.getBookWithSemicolon("123;:", "custom;:header"); assertEquals(123L, book.getId()); assertEquals("CXF in Action%3B%3A", book.getName()); }
@Test public void testGetBookFastinfoset() throws Exception { JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress("http://localhost:" + PORT + "/test/services/rest3/bookstore/fastinfoset2"); bean.getInInterceptors().add(new FIStaxInInterceptor()); JAXBElementProvider<?> p = new JAXBElementProvider<>(); p.setConsumeMediaTypes(Collections.singletonList("application/fastinfoset")); bean.setProvider(p); Map<String, Object> props = new HashMap<>(); props.put(FIStaxInInterceptor.FI_GET_SUPPORTED, Boolean.TRUE); bean.setProperties(props); WebClient client = bean.createWebClient(); Book b = client.accept("application/fastinfoset").get(Book.class); assertEquals("CXF2", b.getName()); assertEquals(2L, b.getId()); }
properties.put(SecurityConstants.SIGNATURE_PROPERTIES, "org/apache/cxf/systest/jaxrs/security/alice.properties"); bean.setProperties(properties);
@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()); }
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); bean.setAddress(address); bean.setProperties(Collections.singletonMap(org.apache.cxf.message.Message.MTOM_ENABLED, (Object)"true")); WebClient client = bean.createWebClient();
properties.put(SecurityConstants.SIGNATURE_PROPERTIES, "org/apache/cxf/systest/jaxrs/security/bethal.properties"); bean.setProperties(properties); if (test.streaming) { XmlSecOutInterceptor sigOutInterceptor = new XmlSecOutInterceptor();
properties.put(SecurityConstants.SIGNATURE_PROPERTIES, "org/apache/cxf/systest/jaxrs/security/alice.properties"); bean.setProperties(properties); if (test.streaming) { XmlSecOutInterceptor sigOutInterceptor = new XmlSecOutInterceptor();
properties.put(SecurityConstants.SIGNATURE_PROPERTIES, "org/apache/cxf/systest/jaxrs/security/bethal.properties"); bean.setProperties(properties); if (test.streaming) { XmlSecOutInterceptor sigOutInterceptor = new XmlSecOutInterceptor();
properties.put(SecurityConstants.SIGNATURE_PROPERTIES, "org/apache/cxf/systest/jaxrs/security/alice.properties"); bean.setProperties(properties); XmlSecOutInterceptor sigOutInterceptor = new XmlSecOutInterceptor(); sigOutInterceptor.setSignRequest(true);
properties.put(SecurityConstants.SIGNATURE_PROPERTIES, "org/apache/cxf/systest/jaxrs/security/alice.properties"); bean.setProperties(properties); if (streaming) { XmlSecOutInterceptor sigOutInterceptor = new XmlSecOutInterceptor();
bean.setBus(springBus); bean.setProperties(properties); if (streaming) { XmlSecOutInterceptor encInterceptor = new XmlSecOutInterceptor();