@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; }
public void close() throws IOException { super.close(); binding = null; builder = null; }
@org.junit.Test public void testSignatureProgrammatic() throws Exception { SpringBusFactory bf = new SpringBusFactory(); URL busFile = ActionTest.class.getResource("client.xml"); Bus bus = bf.createBus(busFile.toString()); BusFactory.setDefaultBus(bus); BusFactory.setThreadDefaultBus(bus); URL wsdl = ActionTest.class.getResource("DoubleItAction.wsdl"); Service service = Service.create(wsdl, SERVICE_QNAME); QName portQName = new QName(NAMESPACE, "DoubleItSignatureConfigPort"); DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class); updateAddressPort(port, PORT); // Programmatic interceptor Map<String, Object> props = new HashMap<>(); props.put(ConfigurationConstants.ACTION, "Signature"); props.put(ConfigurationConstants.SIGNATURE_USER, "alice"); props.put(ConfigurationConstants.PW_CALLBACK_REF, new KeystorePasswordCallback()); props.put(ConfigurationConstants.SIG_KEY_ID, "DirectReference"); props.put(ConfigurationConstants.SIG_PROP_FILE, "alice.properties"); WSS4JOutInterceptor outInterceptor = new WSS4JOutInterceptor(props); Client client = ClientProxy.getClient(port); client.getOutInterceptors().add(outInterceptor); assertEquals(50, port.doubleIt(25)); ((java.io.Closeable)port).close(); bus.shutdown(true); }
@Test public void testUnsignedSAML2Token() throws Exception { QName serviceName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldService"); QName portName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldPort"); URL wsdl = getWSDLURL("/wsdl/jms_test.wsdl"); HelloWorldService service = new HelloWorldService(wsdl, serviceName); String response = new String("Bonjour"); HelloWorldPortType greeter = service.getPort(portName, HelloWorldPortType.class); SamlCallbackHandler callbackHandler = new SamlCallbackHandler(); callbackHandler.setSignAssertion(true); callbackHandler.setConfirmationMethod(SAML2Constants.CONF_BEARER); Map<String, Object> outProperties = new HashMap<>(); outProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_UNSIGNED); outProperties.put(ConfigurationConstants.SAML_CALLBACK_REF, callbackHandler); WSS4JOutInterceptor outInterceptor = new WSS4JOutInterceptor(outProperties); Client client = ClientProxy.getClient(greeter); client.getOutInterceptors().add(outInterceptor); String reply = greeter.sayHi(); assertNotNull("no response received from service", reply); assertEquals(response, reply); ((java.io.Closeable)greeter).close(); }
SpringBusFactory bf = new SpringBusFactory(); URL busFile = CipherSuitesTest.class.getResource("ciphersuites-client-noconfig.xml"); Bus bus = bf.createBus(busFile.toString()); BusFactory.setDefaultBus(bus); BusFactory.setThreadDefaultBus(bus); Client client = ClientProxy.getClient(port); HTTPConduit conduit = (HTTPConduit) client.getConduit(); conduit.setTlsClientParameters(tlsParams); ((java.io.Closeable)port).close(); bus.shutdown(true);
@org.junit.Test public void testSymmetric() throws Exception { SpringBusFactory bf = new SpringBusFactory(); URL busFile = CachingTest.class.getResource("client.xml"); Bus bus = bf.createBus(busFile.toString()); BusFactory.setDefaultBus(bus); BusFactory.setThreadDefaultBus(bus); QName portQName = new QName(NAMESPACE, "DoubleItCacheSymmetricPort"); Client client = ClientProxy.getClient(port); TokenStore tokenStore = (TokenStore)client.getEndpoint().getEndpointInfo().getProperty( SecurityConstants.TOKEN_STORE_CACHE_INSTANCE ); client = ClientProxy.getClient(port2); tokenStore = (TokenStore)client.getEndpoint().getEndpointInfo().getProperty( SecurityConstants.TOKEN_STORE_CACHE_INSTANCE ); ((java.io.Closeable)port).close(); ((java.io.Closeable)port2).close();
QName portQName = new QName(NAMESPACE, "DoubleItPlaintextPort"); DoubleItPortType utPort = service.getPort(portQName, DoubleItPortType.class); tlsParams.setDisableCNCheck(true); Client client = ClientProxy.getClient(utPort); HTTPConduit http = (HTTPConduit) client.getConduit(); http.setTlsClientParameters(tlsParams); ((java.io.Closeable)utPort).close();
@org.junit.Test public void testBasicAuthViaAuthorizationPolicy() throws Exception { SpringBusFactory bf = new SpringBusFactory(); URL busFile = BasicAuthTest.class.getResource("client.xml"); Bus bus = bf.createBus(busFile.toString()); BusFactory.setDefaultBus(bus); BusFactory.setThreadDefaultBus(bus); URL wsdl = BasicAuthTest.class.getResource("DoubleItBasicAuth.wsdl"); Service service = Service.create(wsdl, SERVICE_QNAME); QName portQName = new QName(NAMESPACE, "DoubleItBasicAuthPort2"); DoubleItPortType utPort = service.getPort(portQName, DoubleItPortType.class); updateAddressPort(utPort, PORT); Client client = ClientProxy.getClient(utPort); HTTPConduit http = (HTTPConduit) client.getConduit(); AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy(); authorizationPolicy.setUserName("Alice"); authorizationPolicy.setPassword("ecilA"); authorizationPolicy.setAuthorizationType("Basic"); http.setAuthorization(authorizationPolicy); assertEquals(50, utPort.doubleIt(25)); ((java.io.Closeable)utPort).close(); bus.shutdown(true); }
QName portQName = new QName(NAMESPACE, "DoubleItTransportPort"); DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class); tlsParams.setDisableCNCheck(true); Client client = ClientProxy.getClient(port); HTTPConduit http = (HTTPConduit) client.getConduit(); http.setTlsClientParameters(tlsParams); Bus clientBus = BusFactory.newInstance().createBus(); STSClient stsClient = new STSClient(clientBus); stsClient.setTlsClientParameters(tlsParams); ((java.io.Closeable)port).close();
@Test public void testDocBasicConnection() throws Exception { QName serviceName = new QName("http://apache.org/hello_world_doc_lit", "SOAPService2"); QName portName = new QName("http://apache.org/hello_world_doc_lit", "SoapPort2"); URL wsdl = getWSDLURL("/wsdl/hello_world_doc_lit.wsdl"); SOAPService2 service = new SOAPService2(wsdl, serviceName); Greeter greeter = service.getPort(portName, Greeter.class); Client client = ClientProxy.getClient(greeter); client.getEndpoint().getOutInterceptors().add(new TibcoSoapActionInterceptor()); client.getOutInterceptors().add(new LoggingOutInterceptor()); client.getInInterceptors().add(new LoggingInInterceptor()); for (int idx = 0; idx < 5; idx++) { ((java.io.Closeable)greeter).close();
@Test public void testHTTPClientPolicyViaFeature() throws Exception { SpringBusFactory bf = new SpringBusFactory(); bus = bf.createBus(POLICY_VIA_FEATURE_CFG); BusFactory.setDefaultBus(bus); (HTTPConduit)(ClientProxy.getClient(greeter).getConduit()); assertNotNull("expected HTTPConduit", c); assertNotNull("expected DecoupledEndpoint", c.getClient().getDecoupledEndpoint()); assertEquals("unexpected DecoupledEndpoint", "http://localhost:9909/decoupled_endpoint", c.getClient().getDecoupledEndpoint()); ((Closeable)greeter).close();
@Test public void testGreeterUsingJaxWSAPI() throws Exception { QName serviceName = new QName("http://apache.org/hello_world_doc_lit", "SOAPService2"); QName portName = new QName("http://apache.org/hello_world_doc_lit", "SoapPort2"); URL wsdl = getWSDLURL("/wsdl/hello_world_doc_lit.wsdl"); SOAPService2 service = new SOAPService2(wsdl, serviceName); Greeter greeter = markForClose(service.getPort(portName, Greeter.class, cff)); Client client = ClientProxy.getClient(greeter); client.getEndpoint().getOutInterceptors().add(new TibcoSoapActionInterceptor()); greeter.greetMeOneWay("test String"); String greeting = greeter.greetMe("Chris"); Assert.assertEquals("Hello Chris", greeting); }
HTTPConduit c = (HTTPConduit)ClientProxy.getClient(port).getConduit(); c.getClient().setDecoupledEndpoint("http://localhost:" + FaultToEndpointServer.FAULT_PORT2 + "/sendFaultHere"); in.indexOf("Negative numbers cant be added") > -1); ((Closeable)port).close();
@Test public void testConnectionWithProxy() throws Exception { QName serviceName = new QName("http://cxf.apache.org/systest/jaxws/", "HelloService"); HelloService service = new HelloService(null, serviceName); assertNotNull(service); Hello hello = service.getHelloPort(); Client client = ClientProxy.getClient(hello); client.getInInterceptors().add(new LoggingInInterceptor()); client.getOutInterceptors().add(new LoggingOutInterceptor()); HTTPConduit http = (HTTPConduit)client.getConduit(); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setAllowChunking(false); httpClientPolicy.setReceiveTimeout(0); httpClientPolicy.setProxyServerType(ProxyServerType.HTTP); httpClientPolicy.setProxyServer("localhost"); httpClientPolicy.setProxyServerPort(PROXY_PORT); http.setClient(httpClientPolicy); ((BindingProvider)hello).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + PORT + "/hello"); assertEquals("getSayHi", hello.sayHi("SayHi")); } }
@Test public void testClientServer() { BusFactory.setDefaultBus(getStaticBus()); BusFactory.setThreadDefaultBus(getStaticBus()); URL wsdlLocation = null; final IPingService port = svc.getPort( new QName( "http://WSSec/wssec10", test.prefix + "_IPingService" ); Client cl = ClientProxy.getClient(port); HTTPConduit http = (HTTPConduit) cl.getConduit(); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setConnectionTimeout(0); httpClientPolicy.setReceiveTimeout(0); http.setClient(httpClientPolicy); String output = port.echo(INPUT); assertEquals(INPUT, output); cl.destroy();
@Test public void testHttpWrappedContinuations() throws Exception { SpringBusFactory bf = new SpringBusFactory(); Bus bus = bf.createBus(CLIENT_CONFIG_FILE); BusFactory.setDefaultBus(bus); QName serviceName = new QName("http://cxf.apache.org/systest/jaxws", "HelloContinuationService"); URL wsdlURL = new URL("http://localhost:" + PORT + "/hellocontinuation?wsdl"); HelloContinuationService service = new HelloContinuationService(wsdlURL, serviceName); assertNotNull(service); final HelloContinuation helloPort = service.getHelloContinuationPort(); ClientProxy.getClient(helloPort).getInInterceptors().add(new LoggingInInterceptor()); ClientProxy.getClient(helloPort).getOutInterceptors().add(new LoggingOutInterceptor()); doTest(helloPort); bus.shutdown(true); }
BookSoapService service = new BookSoapService(new URL(wsdlAddress), new QName("http://books.com", "BookService")); BookStoreJaxrsJaxws store = service.getBookPort(); in.setInTransformElements(mapIn); Client cl = ClientProxy.getClient(store); ((HTTPConduit)cl.getConduit()).getClient().setReceiveTimeout(10000000); cl.getInInterceptors().add(in); cl.getOutInterceptors().add(out);
@Test public void testMTOMInHashMapWithBase64() throws Exception { Service service = Service.create(new QName("http://foo", "bar")); service.addPort(new QName("http://foo", "bar"), SOAPBinding.SOAP11HTTP_BINDING, ADDRESS); MTOMService port = service.getPort(new QName("http://foo", "bar"), MTOMService.class); ClientProxy.getClient(port).getOutInterceptors().add(new LoggingOutInterceptor()); ClientProxy.getClient(port).getInInterceptors().add(new LoggingInInterceptor()); final int count = 99; ObjectWithHashMapData data = port.getHashMapData(count); for (int y = 1; y < count; y++) { byte[] bytes = data.getKeyData().get(Integer.toHexString(y)); assertEquals(y, bytes.length); } } }
private void configureTimeouts(P port) { Client client = getClient(port); HTTPConduit conduit = (HTTPConduit) client.getConduit(); HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy(); httpClientPolicy.setConnectionTimeout(connectionTimeoutMs); httpClientPolicy.setReceiveTimeout(receiveTimeoutMs); httpClientPolicy.setAutoRedirect(true); httpClientPolicy.setAllowChunking(true); conduit.setClient(httpClientPolicy); }