@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 boolean addressChanged(String address) { return !(address == null || getClient().getEndpoint().getEndpointInfo() == null || address.equals(getClient().getEndpoint().getEndpointInfo().getAddress())); }
DispatchImpl(Client client, Service.Mode m, JAXBContext ctx, Class<T> clazz) { this.binding = ((JaxWsEndpointImpl)client.getEndpoint()).getJaxwsBinding(); this.builder = new EndpointReferenceBuilder((JaxWsEndpointImpl)client.getEndpoint()); context = ctx; cl = clazz; setupEndpointAddressContext(client.getEndpoint()); addInvokeOperation(false); addInvokeOperation(true); } else if (m == Service.Mode.MESSAGE) { SAAJOutInterceptor saajOut = new SAAJOutInterceptor(); client.getOutInterceptors().add(saajOut); client.getOutInterceptors(). add(new MessageModeOutInterceptor(saajOut, client.getEndpoint() .getBinding().getBindingInfo().getName())); client.getInInterceptors().add(new SAAJInInterceptor()); client.getInInterceptors() .add(new MessageModeInInterceptor(clazz, client.getEndpoint() .getBinding().getBindingInfo().getName()));
private void initIntercepors(Client client, AbstractBasicInterceptorProvider clientFact) { client.getInInterceptors().addAll(clientFact.getInInterceptors()); client.getOutInterceptors().addAll(clientFact.getOutInterceptors()); client.getInFaultInterceptors().addAll(clientFact.getInFaultInterceptors()); client.getOutFaultInterceptors().addAll(clientFact.getOutFaultInterceptors()); }
Client client = ClientProxy.getClient(port); client.getInInterceptors().add(new GZIPInInterceptor()); client.getOutInterceptors().add(new GZIPOutInterceptor());
@SuppressWarnings("unchecked") private Object invokeAsync(Method method, final BindingOperationInfo oi, Object[] params) throws Exception { client.setExecutor(getClient().getEndpoint().getExecutor()); AsyncHandler<Object> handler; if (params.length > 0 && params[params.length - 1] instanceof AsyncHandler) { handler = (AsyncHandler<Object>)params[params.length - 1]; Object[] newParams = new Object[params.length - 1]; for (int i = 0; i < newParams.length; i++) { newParams[i] = params[i]; } params = newParams; } else { handler = null; } ClientCallback callback = new JaxwsClientCallback<Object>(handler, this) { @Override protected Throwable mapThrowable(Throwable t) { if (t instanceof Exception) { t = mapException(null, oi, (Exception)t); } return t; } }; Response<Object> ret = new JaxwsResponseCallback<>(callback); client.invoke(callback, oi, params); return ret; }
@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); }
@org.junit.Test public void testNoOpX509TrustManager() throws Exception { SpringBusFactory bf = new SpringBusFactory(); URL busFile = TrustManagerTest.class.getResource("client-trust.xml"); Bus bus = bf.createBus(busFile.toString()); BusFactory.setDefaultBus(bus); BusFactory.setThreadDefaultBus(bus); URL url = SOAPService.WSDL_LOCATION; SOAPService service = new SOAPService(url, SOAPService.SERVICE); assertNotNull("Service is null", service); final Greeter port = service.getHttpsPort(); assertNotNull("Port is null", port); updateAddressPort(port, PORT); TLSClientParameters tlsParams = new TLSClientParameters(); X509TrustManager trustManager = new NoOpX509TrustManager(); TrustManager[] trustManagers = new TrustManager[1]; trustManagers[0] = trustManager; tlsParams.setTrustManagers(trustManagers); tlsParams.setDisableCNCheck(true); Client client = ClientProxy.getClient(port); HTTPConduit http = (HTTPConduit) client.getConduit(); http.setTlsClientParameters(tlsParams); assertEquals(port.greetMe("Kitty"), "Hello Kitty"); ((java.io.Closeable)port).close(); bus.shutdown(true); }
@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); }
@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); } } }
(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();
private void addInvokeOperation(boolean oneWay) { String name = oneWay ? INVOKE_ONEWAY_NAME : INVOKE_NAME; ServiceInfo info = client.getEndpoint().getEndpointInfo().getService(); OperationInfo opInfo = info.getInterface() .addOperation(oneWay ? INVOKE_ONEWAY_QNAME : INVOKE_QNAME); MessageInfo mInfo = opInfo.createMessage(new QName(DISPATCH_NS, name + "Request"), Type.INPUT); opInfo.setInput(name + "Request", mInfo); MessagePartInfo mpi = mInfo.addMessagePart("parameters"); if (context == null) { mpi.setTypeClass(cl); } mpi.setElement(true); if (!oneWay) { mInfo = opInfo.createMessage(new QName(DISPATCH_NS, name + "Response"), Type.OUTPUT); opInfo.setOutput(name + "Response", mInfo); mpi = mInfo.addMessagePart("parameters"); mpi.setElement(true); if (context == null) { mpi.setTypeClass(cl); } } for (BindingInfo bind : client.getEndpoint().getEndpointInfo().getService().getBindings()) { BindingOperationInfo bo = new BindingOperationInfo(bind, opInfo); bind.addOperation(bo); } }
@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")); } }
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 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 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); }
DynamicClientFactory dcf = DynamicClientFactory.newInstance(); Client client = dcf.createClient("WSDL Location"); AuthorizationPolicy authorization = ((HTTPConduit) client.getConduit()).getAuthorization(); authorization.setUserName( "user name" ); authorization.setPassword( "password" ); Object[] res = client.invoke(new QName("http://targetNameSpace/", "operationName"), params...); System.out.println("Echo response: " + res[0]);
@Override public void clientDestroyed(Client client) { if (AGENT_PORT_TYPE.equals(getEndpointName(client.getEndpoint()))) { return; } processStop(client.getEndpoint(), EventTypeEnum.CLIENT_DESTROY); }
private void configure(final Client client, final Properties properties) { if (properties == null) { return; } for (final String suffix : asList("", client.getEndpoint().getEndpointInfo().getName().toString() + ".")) { // here (ie at runtime) we have no idea which services were linked to the app // so using tomee.xml ones for now (not that shocking since we externalize the config with this class) configureInterceptors(client, CXF_JAXWS_CLIENT_PREFIX + suffix, lazyServiceInfoList(properties), properties); } }
= ((JaxWsClientEndpointImpl)client.getEndpoint()).getFeatures(); List<Feature> allFeatures; if (client.getBus().getFeatures() != null) { allFeatures = new ArrayList<>(endpointFeatures.size() + client.getBus().getFeatures().size()); allFeatures.addAll(endpointFeatures); allFeatures.addAll(client.getBus().getFeatures()); } else { allFeatures = endpointFeatures; client.getEndpoint().getBinding().getBindingInfo(), hasOpName); if (findDispatchOp && !payloadOPMap.isEmpty()) { QName payloadElementName = null; QName expectedElementName = payloadOPMap.get(opName.toString()); if (expectedElementName == null || !expectedElementName.toString().equals( payloadElementName.toString())) { client.getEndpoint().getBinding().getBindingInfo(), hasOpName); BindingOperationInfo dbop = client.getEndpoint().getBinding().getBindingInfo() .getOperation(dispatchedOpName); if (dbop != null) {