WebService_Service svc = new WebService_Service( null, new QName("http://www.example.com/ws", "WebService")); WebService port = svc.getPort(WebService.class); BindingProvider bindingProvider = (BindingProvider) port; bindingProvider.getRequestContext() .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://www.example.com/real_endpoint_url_goes_here");
@Test public void test() throws Exception { QName serviceName = new QName("http://www.jboss.org/jbossas/quickstarts/wshelloworld/HelloWorld", "HelloWorldService"); Service service = Service.create(new URL("http://localhost:" + getPort()), serviceName); HelloWorldService helloWorldService = service.getPort(HelloWorldService.class); assertThat(helloWorldService).isInstanceOf(BindingProvider.class); final BindingProvider bindingProvider = (BindingProvider) helloWorldService; boolean clientHandlerFound = false; for (Handler handler : bindingProvider.getBinding().getHandlerChain()) { if (handler instanceof TracingClientSOAPHandler) { clientHandlerFound = true; } } assertThat(clientHandlerFound).overridingErrorMessage("No %s found in %s", TracingClientSOAPHandler.class.getSimpleName(), bindingProvider.getBinding().getHandlerChain()).isTrue(); }
@Override public Object call() throws Exception { Service service = Service.create( url, new QName( NAMESPACE_URI, serviceName ) ); T port = service.getPort( clazz ); // add TRUST_USER if necessary if ( StringUtils.isNotBlank( System.getProperty( "pentaho.repository.client.attemptTrust" ) ) ) { ( (BindingProvider) port ).getRequestContext().put( MessageContext.HTTP_REQUEST_HEADERS, Collections.singletonMap( TRUST_USER, Collections.singletonList( username ) ) ); } else { // http basic authentication ( (BindingProvider) port ).getRequestContext().put( BindingProvider.USERNAME_PROPERTY, username ); ( (BindingProvider) port ).getRequestContext().put( BindingProvider.PASSWORD_PROPERTY, password ); } // accept cookies to maintain session on server ( (BindingProvider) port ).getRequestContext().put( BindingProvider.SESSION_MAINTAIN_PROPERTY, true ); // support streaming binary data // TODO mlowery this is not portable between JAX-WS implementations (uses com.sun) ( (BindingProvider) port ).getRequestContext().put( JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 8192 ); SOAPBinding binding = (SOAPBinding) ( (BindingProvider) port ).getBinding(); binding.setMTOMEnabled( true ); return port; } } );
@org.junit.Test public void testSoap12() throws Exception { SpringBusFactory bf = new SpringBusFactory(); URL busFile = FaultTest.class.getResource("client.xml"); Bus bus = bf.createBus(busFile.toString()); BusFactory.setDefaultBus(bus); BusFactory.setThreadDefaultBus(bus); URL wsdl = FaultTest.class.getResource("DoubleItFault.wsdl"); Service service = Service.create(wsdl, SERVICE_QNAME); QName portQName = new QName(NAMESPACE, "DoubleItSoap12Port"); DoubleItPortType utPort = service.getPort(portQName, DoubleItPortType.class); updateAddressPort(utPort, PORT); // Make a successful invocation ((BindingProvider)utPort).getRequestContext().put(SecurityConstants.USERNAME, "alice"); assertEquals(50, utPort.doubleIt(25)); // Now make an invocation using another username ((BindingProvider)utPort).getRequestContext().put(SecurityConstants.USERNAME, "bob"); ((BindingProvider)utPort).getRequestContext().put("security.password", "password"); try { utPort.doubleIt(25); fail("Expected failure on bob"); } catch (Exception ex) { assertTrue(ex.getMessage().contains("This is a fault")); } ((java.io.Closeable)utPort).close(); bus.shutdown(true); }
@org.junit.Test public void testAESIncludedAsync() throws Exception { SpringBusFactory bf = new SpringBusFactory(); URL busFile = CipherSuitesTest.class.getResource("ciphersuites-client.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); // Enable Async ((BindingProvider)port).getRequestContext().put("use.async.http.conduit", true); updateAddressPort(port, PORT); assertEquals(port.greetMe("Kitty"), "Hello Kitty"); ((java.io.Closeable)port).close(); bus.shutdown(true); }
javax.xml.ws.Service service = Service.create( new URL("http://example.org/stocks.wsdl"), new QName("http://example.org/stocks", "StockQuoteService")); com.example.StockQuoteProvider proxy = service.getPort(portName, com.example.StockQuoteProvider.class) javax.xml.ws.BindingProvider bp = (javax.xml.ws.BindingProvider)proxy; Map<String,Object> context = bp.getRequestContext(); context.setProperty("javax.xml.ws.session.maintain", Boolean.TRUE); proxy.getLastTradePrice("ACME");
public DefaultImexCentralClient( String username, String password, String endPoint ) throws ImexCentralException { this.endPoint = endPoint; try { URL url = new URL( endPoint + "?wsdl" ); log.debug( "WSDL: " + endPoint + "?wsdl" ); QName qn = new QName( "http://imex.mbi.ucla.edu/icentral/ws", "ics20" ); service = new IcentralService( url, qn ); port = service.getIcp20(); ( ( BindingProvider ) port ).getRequestContext().put( BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endPoint ); ( ( BindingProvider ) port ).getRequestContext().put( BindingProvider.USERNAME_PROPERTY, username ); ( ( BindingProvider ) port ).getRequestContext().put( BindingProvider.PASSWORD_PROPERTY, password ); } catch ( MalformedURLException e ) { throw new ImexCentralException( "Error while initializing IMEx Central Client", e ); } }
com.csd.Service service = null; URL url = new URL("https://service.demo.com/ResService.svc?wsdl"); service = new com.csd.Service(url); com.csd.IService port = service.getBasicHttpBindingIService(); BindingProvider bindingProvider = (BindingProvider)port; Binding binding = bindingProvider.getBinding(); List<Handler> handlerChain = binding.getHandlerChain(); handlerChain.add(new LogMessageHandler()); binding.setHandlerChain(handlerChain);
public RepositoryClient(Lock lock, URL endpointUrl, String username, String password) { IllegalArgumentAssertion.assertNotNull(endpointUrl, "endpointUrl"); IllegalArgumentAssertion.assertNotNull(lock, "lock"); this.endpointUrl = endpointUrl; this.lock = lock; URL wsdlUrl = getClass().getClassLoader().getResource("/jaxws/repository-endpoint.wsdl"); this.delegate = Service.create(wsdlUrl, RepositoryService.SERVICE_QNAME).getPort(RepositoryService.class); if (username != null && password != null) { BindingProvider bp = (BindingProvider) delegate; bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl.toString()); bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username); bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password); } }
private void assertSoapHeader(BindingProvider serviceProxy) { List<?> headers = (List<?>) serviceProxy.getResponseContext().get(Header.HEADER_LIST); QName testQName = new QName("http://test", "test"); if (headers != null) { for (Object o : headers) { if (o instanceof SoapHeader) { SoapHeader soapHeader = (SoapHeader) o; QName qName = soapHeader.getName(); if (testQName.getNamespaceURI().equals(qName.getNamespaceURI()) && testQName.getLocalPart().equals(qName.getLocalPart())) { Node returnedContent = (Node) soapHeader.getObject(); assertEquals("test", returnedContent.getTextContent()); return; } } } } fail("Header not found"); }
bus = new SpringBusFactory().createBus("org/apache/cxf/systest/ws/wssec11/client.xml"); } else { bus = new SpringBusFactory().createBus( "org/apache/cxf/systest/ws/wssec11/client_restricted.xml"); BusFactory.setDefaultBus(bus); BusFactory.setThreadDefaultBus(bus); final IPingService port = svc.getPort( new QName("http://WSSec/wssec11", portPrefix + "_IPingService"), IPingService.class ); ((BindingProvider)port).getRequestContext().put( SecurityConstants.ENABLE_STREAMING_SECURITY, "true" ); ((BindingProvider)port).getResponseContext().put( SecurityConstants.ENABLE_STREAMING_SECURITY, "true" ); assertEquals(INPUT, output); ((java.io.Closeable)port).close(); bus.shutdown(true);
@Test public void testBindingVersionError() throws Exception { QName serviceName = new QName(SERVICE_NS, "JMSGreeterService"); QName portName = new QName(SERVICE_NS, "GreeterPort"); URL wsdl = getWSDLURL(WSDL); JMSGreeterService service = new JMSGreeterService(wsdl, serviceName); JMSGreeterPortType greeter = markForClose(service.getPort(portName, JMSGreeterPortType.class, cff)); BindingProvider bp = (BindingProvider)greeter; Map<String, Object> requestContext = bp.getRequestContext(); JMSMessageHeadersType requestHeader = new JMSMessageHeadersType(); requestHeader.setSOAPJMSBindingVersion("0.3"); requestContext.put(JMSConstants.JMS_CLIENT_REQUEST_HEADERS, requestHeader); try { greeter.greetMe("Milestone-"); Assert.fail("Should have thrown a fault"); } catch (SOAPFaultException ex) { Assert.assertTrue(ex.getMessage().contains("0.3")); Map<String, Object> responseContext = bp.getResponseContext(); JMSMessageHeadersType responseHdr = (JMSMessageHeadersType)responseContext .get(JMSConstants.JMS_CLIENT_RESPONSE_HEADERS); if (responseHdr == null) { Assert.fail("response Header should not be null"); } Assert.assertTrue(responseHdr.isSOAPJMSIsFault()); } }
@Test public void testWithManualMultiplexEprCreation() throws Exception { Service numService = Service.create(NumberFactoryImpl.NUMBER_SERVICE_QNAME); Number num = numService.getPort(Number.class); InvocationHandler handler = Proxy.getInvocationHandler(num); BindingProvider bp = (BindingProvider)handler; bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, NUMBER_SERVANT_ADDRESS_ROOT + "103"); IsEvenResponse numResp = num.isEven(); assertTrue("103 is not even", Boolean.FALSE.equals(numResp.isEven())); }
service = getWebServicePort(getWSDLLocation()); BindingProvider bindingProvider = (BindingProvider) service; bindingProvider.getRequestContext().put("com.sun.xml.internal.ws.transport.https.client.SSLSocketFactory", getCustomSocketFactory());
public static void enableStreaming(BindingProvider bindingProvider) { bindingProvider.getRequestContext().put( SecurityConstants.ENABLE_STREAMING_SECURITY, "true" ); bindingProvider.getResponseContext().put( SecurityConstants.ENABLE_STREAMING_SECURITY, "true" ); }
/** * Configures SOAP binding of the given SOAP port. */ private void configureBinding(Object port) { BindingProvider bindingProvider = (BindingProvider) port; Map<String, Object> reqContext = bindingProvider.getRequestContext(); reqContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceUrl); Binding binding = bindingProvider.getBinding(); SOAPBinding soapBinding = (SOAPBinding) binding; soapBinding.setMTOMEnabled(wsTransactionConfiguration.isMtom()); }
@Advice.OnMethodExit private static void setHandlerChain(@Advice.Return Object portOrDispatch) { if (portOrDispatch instanceof BindingProvider) { final Binding binding = ((BindingProvider) portOrDispatch).getBinding(); final List<Handler> handlerChain = binding.getHandlerChain(); if (handlerChain != null) { binding.setHandlerChain(handlerChain); } else { binding.setHandlerChain(new ArrayList<Handler>()); } } }
@Override public Map<String, Object> getResponseContext() { return ((BindingProvider) inquiryService).getResponseContext(); }
@org.junit.Test public void testSoap11PolicyWithParts() throws Exception { SpringBusFactory bf = new SpringBusFactory(); URL busFile = FaultTest.class.getResource("client.xml"); Bus bus = bf.createBus(busFile.toString()); BusFactory.setDefaultBus(bus); BusFactory.setThreadDefaultBus(bus); URL wsdl = FaultTest.class.getResource("DoubleItFault.wsdl"); Service service = Service.create(wsdl, SERVICE_QNAME); QName portQName = new QName(NAMESPACE, "DoubleItSoap11PolicyWithPartsPort"); DoubleItPortType utPort = service.getPort(portQName, DoubleItPortType.class); updateAddressPort(utPort, PORT); // Make a successful invocation ((BindingProvider)utPort).getRequestContext().put(SecurityConstants.USERNAME, "alice"); assertEquals(50, utPort.doubleIt(25)); // Now make an invocation using another username ((BindingProvider)utPort).getRequestContext().put(SecurityConstants.USERNAME, "bob"); ((BindingProvider)utPort).getRequestContext().put("security.password", "password"); try { utPort.doubleIt(25); fail("Expected failure on bob"); } catch (Exception ex) { assertTrue(ex.getMessage().contains("This is a fault")); } ((java.io.Closeable)utPort).close(); bus.shutdown(true); }
@org.junit.Test public void testDHEIncludedAsync() throws Exception { SpringBusFactory bf = new SpringBusFactory(); URL busFile = CipherSuitesTest.class.getResource("ciphersuites-dhe-client.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); // Enable Async ((BindingProvider)port).getRequestContext().put("use.async.http.conduit", true); updateAddressPort(port, PORT2); assertEquals(port.greetMe("Kitty"), "Hello Kitty"); ((java.io.Closeable)port).close(); bus.shutdown(true); }