public static void enableSoapClientOutputAttachments(JaxWsProxyFactoryBean pfb){ Map<String,Object> props = new HashMap<String, Object>(); props.put(AttachmentOutInterceptor.WRITE_ATTACHMENTS, Boolean.TRUE); pfb.setProperties(props); pfb.getOutInterceptors().add(new SwAOutInterceptor()); pfb.getOutInterceptors().add(new AttachmentOutInterceptor()); }
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); // This enables FastInfoset as the communication protocol factory.getInInterceptors().add( new FIStaxInInterceptor() ); factory.getOutInterceptors().add( new FIStaxOutInterceptor() ); ... other code to set username, location, etc. goes here. client = (C360Server) factory.create();
@Value("${profile.services.url}") private String profileServiceUrl; @Bean public ProfileSoapService profileSoapService() { final JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean(); jaxWsProxyFactoryBean.setServiceClass(ProfileSoapService.class); jaxWsProxyFactoryBean.setAddress(profileServiceUrl); jaxWsProxyFactoryBean.getOutInterceptors().add(getSecurityInterceptor()); return (ProfileSoapService) jaxWsProxyFactoryBean.create(); } private WSS4JOutInterceptor getSecurityInterceptor() { ... }
public static void main(String args[]) throws Exception { JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); // I didn't need these next 2 calls, but I doubt they hurt factory.getInInterceptors().add(new LoggingInInterceptor()); factory.getOutInterceptors().add(new LoggingOutInterceptor()); factory.setServiceClass(AuthService.class); factory.setAddress("http://localhost:7001/authManager/services/cxfAuth"); // 'AuthService' is whatever your interface type is AuthService client = (AuthService) factory.create(); Employee employee = client.getEmployee("0223938"); System.out.println("Server said: " + employee.getLastName() + ", " + employee.getFirstName()); System.exit(0); }
@Override public void configure(final JaxWsProxyFactoryBean factory) { factory.getFeatures().add(new BraveClientFeature(brave)); factory.getOutInterceptors().add(new LoggingOutInterceptor()); factory.getInInterceptors().add(new LoggingInInterceptor()); } });
@Override public void configure(final JaxWsProxyFactoryBean factory) { factory.getFeatures().add(new OpenTracingClientFeature(tracer)); factory.getOutInterceptors().add(new LoggingOutInterceptor()); factory.getInInterceptors().add(new LoggingInInterceptor()); } });
private <T extends Getter> T createGetterService(final Class<T> serviceClass) { JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setAddress("http://localhost:" + PORT + "/" + serviceClass.getSimpleName()); factory.getInInterceptors().add(new LoggingInInterceptor()); factory.getOutInterceptors().add(new LoggingOutInterceptor()); return factory.create(serviceClass); }
import org.apache.cxf.interceptor.LoggingInInterceptor; import org.apache.cxf.interceptor.LoggingOutInterceptor; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; import org.junit.Test; @Test public void testWhatIsTheAnswer() { JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean(); factoryBean.getInInterceptors().add(new LoggingInInterceptor()); factoryBean.getOutInterceptors().add(new LoggingOutInterceptor()); factoryBean.setServiceClass(DeepThought.class); factoryBean.setAddress("http://localhost:8084/DeepThoughtWS/services/DeepThoughtPort"); DeepThought service = (DeepThought) factoryBean.create(); service.whatIsTheAnswer("some answer"); }
private IBookstore createClient() { final JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); // On the client-side, we only intercept outgoing requests and incoming // responses. factory.getOutInterceptors() .add(new OperationExecutionSOAPRequestOutInterceptor(this.clientMonitoringController)); factory.getInInterceptors() .add(new OperationExecutionSOAPResponseInInterceptor(this.clientMonitoringController)); factory.setServiceClass(IBookstore.class); factory.setAddress(this.serviceAddress); return (IBookstore) factory.create(); }
private IBookstore createClient() { final JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); // On the client-side, we only intercept outgoing requests and incoming responses. factory.getOutInterceptors().add(new OperationExecutionSOAPRequestOutInterceptor(this.clientMonitoringController)); factory.getInInterceptors().add(new OperationExecutionSOAPResponseInInterceptor(this.clientMonitoringController)); factory.setServiceClass(IBookstore.class); factory.setAddress(TestCXFClientServerInterceptors.SERVICE_ADDRESS); return factory.create(IBookstore.class); }
private static <T> T createPort(QName serviceName, QName portName, Class<T> serviceEndpointInterface, boolean enableMTOM) throws Exception { JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setBus(bus); factory.setServiceName(serviceName); factory.setServiceClass(serviceEndpointInterface); factory.setWsdlURL(ClientMtomXopTest.class.getResource("/wsdl/mtom_xop.wsdl").toExternalForm()); factory.setFeatures(Collections.singletonList(cff)); factory.getInInterceptors().add(new TestMultipartMessageInterceptor()); factory.getOutInterceptors().add(new TestAttachmentOutInterceptor()); @SuppressWarnings("unchecked") T proxy = (T)factory.create(); BindingProvider bp = (BindingProvider)proxy; SOAPBinding binding = (SOAPBinding)bp.getBinding(); binding.setMTOMEnabled(true); return proxy; } }
private BookStoreService createJaxWsService(final Map<String, List<String>> headers, final Configurator configurator) throws MalformedURLException { JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.getOutInterceptors().add(new LoggingOutInterceptor()); factory.getInInterceptors().add(new LoggingInInterceptor()); factory.setServiceClass(BookStoreService.class); factory.setAddress("http://localhost:" + PORT + "/BookStore"); if (configurator != null) { configurator.configure(factory); } final BookStoreService service = (BookStoreService) factory.create(); final Client proxy = ClientProxy.getClient(service); proxy.getRequestContext().put(Message.PROTOCOL_HEADERS, headers); return service; }
@Test public void testGenericCollection() throws Exception { AegisDatabinding aegisBinding = new AegisDatabinding(); JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean(); proxyFactory.setDataBinding(aegisBinding); proxyFactory.setServiceClass(SportsService.class); proxyFactory.setAddress("http://localhost:" + PORT + "/jaxwsAndAegisSports"); proxyFactory.getInInterceptors().add(new LoggingInInterceptor()); proxyFactory.getOutInterceptors().add(new LoggingOutInterceptor()); SportsService service = (SportsService) proxyFactory.create(); List<String> list = new ArrayList<>(); list.add("ffang"); String ret = service.getGeneric(list); assertEquals(ret, "ffang"); }
@Test public void testComplexMapResult() throws Exception { AegisDatabinding aegisBinding = new AegisDatabinding(); JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean(); proxyFactory.setDataBinding(aegisBinding); proxyFactory.setServiceClass(SportsService.class); proxyFactory.setAddress("http://localhost:" + PORT + "/jaxwsAndAegisSports"); proxyFactory.getInInterceptors().add(new LoggingInInterceptor()); proxyFactory.getOutInterceptors().add(new LoggingOutInterceptor()); SportsService service = (SportsService) proxyFactory.create(); Map<String, Map<Integer, Integer>> result = service.testComplexMapResult(); assertEquals(result.size(), 1); assertTrue(result.containsKey("key1")); assertNotNull(result.get("key1")); assertEquals(result.toString(), "{key1={1=3}}"); }
private BookStoreService createJaxWsService(final Map<String, List<String>> headers, final Configurator configurator) throws MalformedURLException { JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.getOutInterceptors().add(new LoggingOutInterceptor()); factory.getInInterceptors().add(new LoggingInInterceptor()); factory.setServiceClass(BookStoreService.class); factory.setAddress("http://localhost:" + PORT + "/BookStore"); if (configurator != null) { configurator.configure(factory); } final BookStoreService service = (BookStoreService) factory.create(); final Client proxy = ClientProxy.getClient(service); proxy.getRequestContext().put(Message.PROTOCOL_HEADERS, headers); return service; }
@Test public void testCollection() throws Exception { AegisDatabinding aegisBinding = new AegisDatabinding(); JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean(); proxyFactory.setDataBinding(aegisBinding); proxyFactory.setServiceClass(SportsService.class); proxyFactory.setWsdlLocation("http://localhost:" + PORT + "/jaxwsAndAegisSports?wsdl"); proxyFactory.getInInterceptors().add(new LoggingInInterceptor()); proxyFactory.getOutInterceptors().add(new LoggingOutInterceptor()); SportsService service = (SportsService) proxyFactory.create(); Collection<Team> teams = service.getTeams(); assertEquals(1, teams.size()); assertEquals("Patriots", teams.iterator().next().getName()); //CXF-1251 String s = service.testForMinOccurs0("A", null, "b"); assertEquals("Anullb", s); }
@Test public void testGenericPair() throws Exception { AegisDatabinding aegisBinding = new AegisDatabinding(); JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean(); proxyFactory.setDataBinding(aegisBinding); proxyFactory.setServiceClass(SportsService.class); proxyFactory.setAddress("http://localhost:" + PORT + "/jaxwsAndAegisSports"); proxyFactory.getInInterceptors().add(new LoggingInInterceptor()); proxyFactory.getOutInterceptors().add(new LoggingOutInterceptor()); SportsService service = (SportsService) proxyFactory.create(); Pair<String, Integer> ret = service.getReturnGenericPair("ffang", 111); assertEquals("ffang", ret.getFirst()); assertEquals(Integer.valueOf(111), ret.getSecond()); }
@Test public void testReturnQualifiedPair() throws Exception { AegisDatabinding aegisBinding = new AegisDatabinding(); JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean(); proxyFactory.setDataBinding(aegisBinding); proxyFactory.setServiceClass(SportsService.class); proxyFactory.setAddress("http://localhost:" + PORT + "/jaxwsAndAegisSports"); proxyFactory.getInInterceptors().add(new LoggingInInterceptor()); proxyFactory.getOutInterceptors().add(new LoggingOutInterceptor()); SportsService service = (SportsService) proxyFactory.create(); Pair<Integer, String> ret = service.getReturnQualifiedPair(111, "ffang"); assertEquals(Integer.valueOf(111), ret.getFirst()); assertEquals("ffang", ret.getSecond()); }
@Test public void testQualifiedPair() throws Exception { AegisDatabinding aegisBinding = new AegisDatabinding(); JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean(); proxyFactory.setDataBinding(aegisBinding); proxyFactory.setServiceClass(SportsService.class); proxyFactory.setAddress("http://localhost:" + PORT + "/jaxwsAndAegisSports"); proxyFactory.getInInterceptors().add(new LoggingInInterceptor()); proxyFactory.getOutInterceptors().add(new LoggingOutInterceptor()); SportsService service = (SportsService) proxyFactory.create(); int ret = service.getQualifiedPair(new Pair<Integer, String>(111, "ffang")); assertEquals(111, ret); }
@Test public void testReturnGenericPair() throws Exception { AegisDatabinding aegisBinding = new AegisDatabinding(); JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean(); proxyFactory.setDataBinding(aegisBinding); proxyFactory.setServiceClass(SportsService.class); proxyFactory.setAddress("http://localhost:" + PORT + "/jaxwsAndAegisSports"); proxyFactory.getInInterceptors().add(new LoggingInInterceptor()); proxyFactory.getOutInterceptors().add(new LoggingOutInterceptor()); SportsService service = (SportsService) proxyFactory.create(); int ret = service.getGenericPair(new Pair<Integer, String>(111, "String")); assertEquals(111, ret); }