@Override @SuppressWarnings("unchecked") protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcException { ClientProxyFactoryBean proxyFactoryBean = new ClientProxyFactoryBean(); proxyFactoryBean.setAddress(url.setProtocol("http").toIdentityString()); proxyFactoryBean.setServiceClass(serviceType); proxyFactoryBean.setBus(bus); T ref = (T) proxyFactoryBean.create(); Client proxy = ClientProxy.getClient(ref); HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setConnectionTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT)); policy.setReceiveTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)); conduit.setClient(policy); return ref; }
@Override @SuppressWarnings("unchecked") protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcException { ClientProxyFactoryBean proxyFactoryBean = new ClientProxyFactoryBean(); proxyFactoryBean.setAddress(url.setProtocol("http").toIdentityString()); proxyFactoryBean.setServiceClass(serviceType); proxyFactoryBean.setBus(bus); T ref = (T) proxyFactoryBean.create(); Client proxy = ClientProxy.getClient(ref); HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setConnectionTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT)); policy.setReceiveTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)); conduit.setClient(policy); return ref; }
ClientProxyFactoryBean factory = new ClientProxyFactoryBean(); factory.setServiceClass( MyPort.class ); factory.setAddress( "http://www.host.com/service" ); factory.setServiceName( new QName( targetNamespace, wsdlBindingName ) ); Object myService = factory.create(); org.apache.cxf.endpoint.Client client = ClientProxy.getClient( myService ); Map<String, List<String>> headers = new HashMap<String, List<String>>(); headers.put("SOAPAction", Arrays.asList("mySoapAction")); client.getRequestContext().put(Message.PROTOCOL_HEADERS, headers); client.invoke( operationName, request );
ClientProxyFactoryBean factory = new ClientProxyFactoryBean(); factory.setServiceClass(HelloWorld.class); factory.setAddress("http://localhost:9000/Hello"); HelloWorld client = (HelloWorld) factory.create();
public Client() { // The feature will try to create a zookeeper client itself by checking the system property of // zookeeper.url and zookeeper.password //System.getProperty("zookeeper.password", "admin"); // or we can set these option directly on the FabricLoadBalancerFeature FabricLoadBalancerFeature feature = new FabricLoadBalancerFeature(); feature.setZooKeeperPassword("admin"); feature.setZooKeeperUrl("localhost:2181"); // Feature will use this path to locate the service feature.setFabricPath("cxf/demo"); ClientProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean(); clientFactory.setServiceClass(ClientProxyFactoryBean.class); // The address is not the actual address that the client will access clientFactory.setAddress("http://someotherplace"); List<AbstractFeature> features = new ArrayList<AbstractFeature>(); features.add(feature); // we need to setup the feature on the client factory clientFactory.setFeatures(features); // create the proxy of the hello hello = clientFactory.create(Hello.class); }
/* Connect to the service */ ClientProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean(); factoryBean.setServiceClass(MyService.class); factoryBean.setAddress("service-url"); myService = (MyService) factoryBean.create(); /* Retrive HTTP client policy and set the receive timeout */ Client client = ClientProxy.getClient(myService); HTTPConduit httpConduit = (HTTPConduit) client.getConduit(); HTTPClientPolicy httpClientPolicy = httpConduit.getClient(); httpClientPolicy.setReceiveTimeout(timeoutMilliseconds);
ClientProxyFactoryBean factory = new ClientProxyFactoryBean(); factory.setServiceClass(AWSECommerceServicePortType.class); factory.setAddress("https://soap.amazon.com/onca/soap?Service=AWSECommerceService"); factory.getInInterceptors().add(new LoggingInInterceptor()); factory.getOutInterceptors().add(new LoggingOutInterceptor()); AWSECommerceServicePortType ss = (AWSECommerceServicePortType) factory.create();
protected ServiceRegistry initializeRemoteServiceRegistry() { String registryBootstrapUrl = ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.Config.REGISTRY_SERVICE_URL); if (StringUtils.isBlank(registryBootstrapUrl)) { throw new RiceRuntimeException("Failed to load registry bootstrap service from url: " + registryBootstrapUrl); } ClientProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean(); clientFactory.setServiceClass(ServiceRegistry.class); clientFactory.setBus(cxfBus); clientFactory.setAddress(registryBootstrapUrl); boolean registrySecurity = ConfigContext.getCurrentContextConfig().getBooleanProperty(SERVICE_REGISTRY_SECURITY_CONFIG, true); // Set security interceptors clientFactory.getOutInterceptors().add(new CXFWSS4JOutInterceptor(registrySecurity)); clientFactory.getInInterceptors().add(new CXFWSS4JInInterceptor(registrySecurity)); //Set transformation interceptors clientFactory.getInInterceptors().add(new ImmutableCollectionsInInterceptor()); Object service = clientFactory.create(); if (!(service instanceof ServiceRegistry)) { throw new RiceRuntimeException("Endpoint to service registry at URL '" + registryBootstrapUrl + "' was not an instance of ServiceRegistry, instead was: " + service); } return (ServiceRegistry)service; }
private void setupForTest(boolean enableClientMTOM) throws Exception { AegisDatabinding aegisBinding = new AegisDatabinding(); aegisBinding.setMtomEnabled(enableClientMTOM); ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean(); proxyFac.setDataBinding(aegisBinding); proxyFac.setAddress("http://localhost:" + PORT + "/mtom"); JaxWsProxyFactoryBean jaxwsFac = new JaxWsProxyFactoryBean(); jaxwsFac.setDataBinding(new AegisDatabinding()); jaxwsFac.setAddress("http://localhost:" + PORT + "/jaxWsMtom"); Map<String, Object> props = new HashMap<>(); if (enableClientMTOM) { props.put("mtom-enabled", Boolean.TRUE); } proxyFac.setProperties(props); client = proxyFac.create(MtomTestService.class); jaxwsClient = jaxwsFac.create(MtomTestService.class); impl = (MtomTestImpl)applicationContext.getBean("mtomImpl"); }
factoryBean.setAddress(requestInfo.getAddress());
@Override @SuppressWarnings("unchecked") protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcException { ClientProxyFactoryBean proxyFactoryBean = new ClientProxyFactoryBean(); proxyFactoryBean.setAddress(url.setProtocol("http").toIdentityString()); proxyFactoryBean.setServiceClass(serviceType); proxyFactoryBean.setBus(bus); T ref = (T) proxyFactoryBean.create(); Client proxy = ClientProxy.getClient(ref); HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setConnectionTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT)); policy.setReceiveTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)); conduit.setClient(policy); return ref; }
@SuppressWarnings("unchecked") protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcException { ClientProxyFactoryBean proxyFactoryBean = new ClientProxyFactoryBean(); proxyFactoryBean.setAddress(url.setProtocol("http").toIdentityString()); proxyFactoryBean.setServiceClass(serviceType); proxyFactoryBean.setBus(bus); T ref = (T) proxyFactoryBean.create(); Client proxy = ClientProxy.getClient(ref); HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setConnectionTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT)); policy.setReceiveTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)); conduit.setClient(policy); return ref; }
@SuppressWarnings("unchecked") protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcException { ClientProxyFactoryBean proxyFactoryBean = new ClientProxyFactoryBean(); proxyFactoryBean.setAddress(url.setProtocol("http").toIdentityString()); proxyFactoryBean.setServiceClass(serviceType); proxyFactoryBean.setBus(bus); T ref = (T) proxyFactoryBean.create(); Client proxy = ClientProxy.getClient(ref); HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setConnectionTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT)); policy.setReceiveTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)); conduit.setClient(policy); return ref; }
@Override @SuppressWarnings("unchecked") protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcException { ClientProxyFactoryBean proxyFactoryBean = new ClientProxyFactoryBean(); proxyFactoryBean.setAddress(url.setProtocol("http").toIdentityString()); proxyFactoryBean.setServiceClass(serviceType); proxyFactoryBean.setBus(bus); T ref = (T) proxyFactoryBean.create(); Client proxy = ClientProxy.getClient(ref); HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setConnectionTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT)); policy.setReceiveTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)); conduit.setClient(policy); return ref; }
@Override @SuppressWarnings("unchecked") protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcException { ClientProxyFactoryBean proxyFactoryBean = new ClientProxyFactoryBean(); proxyFactoryBean.setAddress(url.setProtocol("http").toIdentityString()); proxyFactoryBean.setServiceClass(serviceType); proxyFactoryBean.setBus(bus); T ref = (T) proxyFactoryBean.create(); Client proxy = ClientProxy.getClient(ref); HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setConnectionTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT)); policy.setReceiveTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)); conduit.setClient(policy); return ref; }
@Override @SuppressWarnings("unchecked") protected <T> T doRefer(final Class<T> serviceType, final URL url) throws RpcException { ClientProxyFactoryBean proxyFactoryBean = new ClientProxyFactoryBean(); proxyFactoryBean.setAddress(url.setProtocol("http").toIdentityString()); proxyFactoryBean.setServiceClass(serviceType); proxyFactoryBean.setBus(bus); T ref = (T) proxyFactoryBean.create(); Client proxy = ClientProxy.getClient(ref); HTTPConduit conduit = (HTTPConduit) proxy.getConduit(); HTTPClientPolicy policy = new HTTPClientPolicy(); policy.setConnectionTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT)); policy.setReceiveTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)); conduit.setClient(policy); return ref; }
private synchronized Object createClientProxy(final CXFConnectionSpec spec) { if (clientProxy == null) { validateConnectionSpec(spec); ClientProxyFactoryBean factory = null; if (EndpointUtils.hasWebServiceAnnotation(spec.getServiceClass())) { factory = new JaxWsProxyFactoryBean(); } else { factory = new ClientProxyFactoryBean(); } factory.setBus(getBus(spec.getBusConfigURL())); factory.setServiceClass(spec.getServiceClass()); factory.getServiceFactory().setEndpointName(spec.getEndpointName()); factory.getServiceFactory().setServiceName(spec.getServiceName()); factory.getServiceFactory().setWsdlURL(spec.getWsdlURL()); if (spec.getAddress() != null) { factory.setAddress(spec.getAddress()); } configureObject(spec.getEndpointName().toString() + ".jaxws-client.proxyFactory", factory); clientProxy = factory.create(); } return clientProxy; }
@Test public void testBare() throws Exception { ClientProxyFactoryBean factory = new ClientProxyFactoryBean(); factory.setServiceClass(Server.BareSoapService.class); factory.setAddress("http://localhost:" + Server.PORT + "/SOAPDocLitBareService/SoapPort1"); factory.setBus(BusFactory.newInstance().createBus()); Server.BareSoapService client = (Server.BareSoapService) factory.create(); try { client.doSomething(); fail("This should fail, ClientProxyFactoryBean doesn't support @SOAPBinding annotation"); } catch (IllegalStateException t) { //expected } factory = new JaxWsProxyFactoryBean(); factory.setServiceClass(Server.BareSoapService.class); factory.setAddress("http://localhost:" + Server.PORT + "/SOAPDocLitBareService/SoapPort1"); factory.setBus(BusFactory.newInstance().createBus()); client = (Server.BareSoapService) factory.create(); client.doSomething(); } }
@Test public void testSimpleClientWithWsdlAndBindingId() throws Exception { QName portName = new QName("http://cxf.apache.org/systest/jaxws/DocLitWrappedCodeFirstService", "DocLitWrappedCodeFirstServicePort"); QName servName = new QName("http://cxf.apache.org/systest/jaxws/DocLitWrappedCodeFirstService", "DocLitWrappedCodeFirstService"); ClientProxyFactoryBean factory = new ClientProxyFactoryBean(); factory.setBindingId("http://cxf.apache.org/bindings/xformat"); factory.setWsdlURL(ServerMisc.DOCLIT_CODEFIRST_URL_XMLBINDING + "?wsdl"); factory.setServiceName(servName); factory.setServiceClass(DocLitWrappedCodeFirstService.class); factory.setEndpointName(portName); factory.setAddress(ServerMisc.DOCLIT_CODEFIRST_URL_XMLBINDING); DocLitWrappedCodeFirstService port = (DocLitWrappedCodeFirstService) factory.create(); assertNotNull(port); assertEquals(factory.getBindingId(), "http://cxf.apache.org/bindings/xformat"); assertTrue(ClientProxy.getClient(port).getEndpoint().getBinding() instanceof XMLBinding); String echoMsg = port.echo("Hello"); assertEquals("Hello", echoMsg); }
@Test public void testAegisClient() throws Exception { AegisDatabinding aegisBinding = new AegisDatabinding(); ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean(); proxyFactory.setDataBinding(aegisBinding); proxyFactory.setServiceClass(AuthService.class); proxyFactory.setAddress("http://localhost:" + PORT + "/service"); AuthService service = (AuthService) proxyFactory.create(); assertTrue(service.authenticate("Joe", "Joe", "123")); assertFalse(service.authenticate("Joe1", "Joe", "fang")); assertTrue(service.authenticate("Joe", null, "123")); List<String> list = service.getRoles("Joe"); assertEquals(3, list.size()); assertEquals("Joe", list.get(0)); assertEquals("Joe-1", list.get(1)); assertEquals("Joe-2", list.get(2)); String[] roles = service.getRolesAsArray("Joe"); assertEquals(2, roles.length); assertEquals("Joe", roles[0]); assertEquals("Joe-1", roles[1]); assertEquals("get Joe", service.getAuthentication("Joe")); Authenticate au = new Authenticate(); au.setSid("ffang"); au.setUid("ffang"); assertTrue(service.authenticate(au)); au.setUid("ffang1"); assertFalse(service.authenticate(au)); }