@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; }
clientFactory = new JaxWsProxyFactoryBean(); } else { clientFactory = new ClientProxyFactoryBean(); clientFactory.getServiceFactory().setDataBinding(new AegisDatabinding()); clientFactory.setServiceClass(Class.forName(getServiceConfiguration().getServiceInterface())); } catch (ClassNotFoundException e) { throw new RiceRuntimeException("Failed to connect to soap service " + getServiceConfiguration().getServiceName() + " because failed to load interface class: " + getServiceConfiguration().getServiceInterface(), e); clientFactory.setBus(KSBServiceLocator.getCXFBus()); clientFactory.setServiceName(getServiceConfiguration().getServiceName()); clientFactory.setAddress(getActualEndpointUrl().toExternalForm()); clientFactory.getOutInterceptors().add(new LoggingOutInterceptor()); clientFactory.getOutFaultInterceptors().add(new LoggingOutInterceptor()); CXFWSS4JOutInterceptor outSecurityInterceptor = new CXFWSS4JOutInterceptor(getServiceConfiguration().getBusSecurity()); clientFactory.getOutInterceptors().add(outSecurityInterceptor); clientFactory.getOutFaultInterceptors().add(outSecurityInterceptor); if (getCredentialsSource() != null) { clientFactory.getOutInterceptors().add(new CredentialsOutHandler(getCredentialsSource(), getServiceConfiguration())); credentials.getPassword())); WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps); clientFactory.getOutInterceptors().add(wssOut); clientFactory.getOutFaultInterceptors().add(wssOut); clientFactory.getInInterceptors().add(new LoggingInInterceptor()); clientFactory.getInFaultInterceptors().add(new LoggingInInterceptor()); CXFWSS4JInInterceptor inSecurityInterceptor = new CXFWSS4JInInterceptor(getServiceConfiguration().getBusSecurity());
ClientProxyFactoryBean factory = new ClientProxyFactoryBean(new OsgiAwareAegisWsClientFactoryBean()); factory.setAddress(pPortUrl); factory.getServiceFactory().setDataBinding(new AegisDatabinding()); factory.setServiceClass(pClass); factory.setUsername(pUsername); factory.setPassword(pPassword); return (T) factory.create();
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();
@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); }
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); }
/* 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);
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); }
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"); }
/** * 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(); // Configure factory MyService serviceClient = (MyService) factory.create(MyService.class); MyService proxy = (MyService) Proxy.newProxyInstance( ServiceInvocationHandler.class.getClassLoader(), new Class[] { MyService.class }, new ServiceInvocationHandler(serviceClient));
public static LoanBrokerWS getProxy(String address) { // Now we use the simple front API to create the client proxy ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean(); ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean(); clientBean.setAddress(address); clientBean.setServiceClass(LoanBrokerWS.class); // just create a new bus for use clientBean.setBus(BusFactory.newInstance().createBus()); return (LoanBrokerWS) proxyFactory.create(); }
Object obj = super.create(); Service service = getServiceFactory().getService(); if (needWrapperClassInterceptor(service.getServiceInfos().get(0))) { List<Interceptor<? extends Message>> in = super.getInInterceptors(); List<Interceptor<? extends Message>> out = super.getOutInterceptors(); in.add(new WrapperClassInInterceptor()); in.add(new HolderInInterceptor());
ClassLoader loader = null; try { if (getBus() != null) { loader = getBus().getExtension(ClassLoader.class); if (loader != null) { orig = ClassLoaderUtils.setThreadContextClassloader(loader); configureObject(); initFeatures(); clientFactoryBean.setProperties(properties); if (getInInterceptors() != null) { c.getInInterceptors().addAll(getInInterceptors()); if (getOutInterceptors() != null) { c.getOutInterceptors().addAll(getOutInterceptors()); if (getInFaultInterceptors() != null) { c.getInFaultInterceptors().addAll(getInFaultInterceptors()); if (getOutFaultInterceptors() != null) { c.getOutFaultInterceptors().addAll(getOutFaultInterceptors()); ClientProxy handler = clientClientProxy(c); Class<?>[] classes = getImplementingClasses(); Object obj = ProxyHelper.getProxy(getClassLoader(clientFactoryBean.getServiceClass()), classes,
public Object create() { configured = true; return super.create(); } public synchronized Object getObject() throws Exception {
/** * Specifies the QName of the WSDL service the proxy implements. The * service must exist or an error will result. * * @param serviceName the QName of the service for the proxy */ public void setServiceName(QName serviceName) { getServiceFactory().setServiceName(serviceName); }
/** * Configure the client proxy factory; currently set the binding customization in the databinding (Client Side). * * @param factory */ protected void configureClientProxyFactoryBean(ClientProxyFactoryBean factory) { //Configure binding customization if (customization != null) { //customize default databinding (early pulls in ServiceFactory default databinding and configure it, as it's lazily loaded) ReflectionServiceFactoryBean serviceFactory = factory.getServiceFactory(); serviceFactory.reset(); DataBinding serviceFactoryDataBinding = serviceFactory.getDataBinding(true); configureBindingCustomization(serviceFactoryDataBinding, customization); serviceFactory.setDataBinding(serviceFactoryDataBinding); //customize user provided databinding (CXF later overrides the ServiceFactory databinding using the user provided one) if (factory.getDataBinding() == null) { //set the endpoint factory's databinding to prevent CXF resetting everything because user did not provide anything factory.setDataBinding(serviceFactoryDataBinding); } else { configureBindingCustomization(factory.getDataBinding(), customization); } } //add other configurations here below }
factory = new JaxWsProxyFactoryBean(); else if (jaxWsStrict.equalsIgnoreCase("no")) factory = new ClientProxyFactoryBean(); else { : new ClientProxyFactoryBean(); && PluginsManager.getSingleton().getConfiguration().getCurrentThreadSpecificsProperties().containsKey("PASSWORD")) { factory.setUsername(PluginsManager.getSingleton().getConfiguration().getCurrentThreadSpecificsProperties().get("USERNAME").toString()); factory.setPassword(PluginsManager.getSingleton().getConfiguration().getCurrentThreadSpecificsProperties().get("PASSWORD").toString()); factory.setServiceClass(pluginInterfaceType); factory.setAddress(pluginImplementationAddress.substring((getScheme() + ":").length())); proxies.put(pluginInterfaceType, factory.create());
/** * 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() {