@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; }
/** * Create a proxy object that implements a specified Service Endpoint Interface. This * method is a combination of {@link #setServiceClass(Class)} and {@link #create()}. * @param <ProxyServiceType> The type for the SEI. * @param serviceClass The Java class object representing the interface you want. * @return the proxy. */ public <ProxyServiceType> ProxyServiceType create(Class<ProxyServiceType> serviceClass) { setServiceClass(serviceClass); return serviceClass.cast(create()); } private void configureObject() {
/** * Create a proxy object that implements a specified Service Endpoint Interface. This * method is a combination of {@link #setServiceClass(Class)} and {@link #create()}. * @param <ProxyServiceType> The type for the SEI. * @param serviceClass The Java class object representing the interface you want. * @return the proxy. */ public <ProxyServiceType> ProxyServiceType create(Class<ProxyServiceType> serviceClass) { setServiceClass(serviceClass); return serviceClass.cast(create()); } private void configureObject() {
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; }
@Test public void testSimpleClientWithWsdl() 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.setWsdlURL(ServerMisc.DOCLIT_CODEFIRST_URL + "?wsdl"); factory.setServiceName(servName); factory.setServiceClass(DocLitWrappedCodeFirstService.class); factory.setEndpointName(portName); DocLitWrappedCodeFirstService port = (DocLitWrappedCodeFirstService) factory.create(); assertNotNull(port); String echoMsg = port.echo("Hello"); assertEquals("Hello", echoMsg); }
@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); }