import javax.xml.bind.JAXBContext; import javax.xml.namespace.QName; import javax.xml.ws.Dispatch; import javax.xml.ws.Service; import javax.xml.ws.soap.SOAPBinding; import blog.jaxws.provider.*; public class Demo { public static void main(String[] args) throws Exception { QName serviceName = new QName("http://service.jaxws.blog/", "FindCustomerService"); Service service = Service.create(serviceName); QName portQName = new QName("http://example.org", "SimplePort"); service.addPort(portQName, SOAPBinding.SOAP11HTTP_BINDING, "http://localhost:8080/Provider/FindCustomerService?wsdl"); JAXBContext jc = JAXBContext.newInstance(FindCustomerRequest.class, FindCustomerResponse.class); Dispatch<Object> sourceDispatch = service.createDispatch(portQName, jc, Service.Mode.PAYLOAD); FindCustomerRequest request = new FindCustomerRequest(); FindCustomerResponse response = (FindCustomerResponse) sourceDispatch.invoke(request); System.out.println(response.getValue().getFirstName()); } }
public void addPort(QName q, String id, String addr) { checkUnsupportedMethods(ADD_PORT); serviceDelegate.addPort(q, id, addr); return; }
public Client(String address) throws MalformedURLException { // create the client from the SEI service = Service.create(SERVICE_NAME); service.addPort(PORT_NAME, javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING, address); System.out.println("Acquiring router port ..."); port = service.getPort(PORT_NAME, Greeter.class); }
public void sayHelloSoap() throws Exception { final QName serviceName = new QName("http://hello.com", "HelloWorld"); final QName portName = new QName("http://hello.com", "HelloWorldPort"); final String address = "http://localhost:" + port + "/services/soap-hello"; System.out.println("Using JAX-WS proxy to invoke on HelloWorld service"); Service service = Service.create(serviceName); service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, address); HelloWorld hw = service.getPort(HelloWorld.class); useHelloService(hw, "Fred"); }
public JAXWSResourcesServiceClient( String baseAddress, String user, String password, Long connectionTimeout, Boolean allowChunking ) { QName serviceName = new QName( "http://services.resources.remoting.xdocreport.opensagres.fr/", "ResourcesServiceService" ); QName portName = new QName( "http://services.resources.remoting.xdocreport.opensagres.fr/", "ResourcesServicePort" ); Service service = Service.create( serviceName ); service.addPort( portName, SOAPBinding.SOAP11HTTP_BINDING, baseAddress ); this.client = service.getPort( portName, JAXWSResourcesService.class ); // Specific code with CXF initializeClient( user, password, connectionTimeout, allowChunking ); }
public static void main(String[] args) throws Exception { QName serviceName = new QName("http://webservice.remote.spi.frameworkset.org/", "RPCCallService"); QName portName = new QName("http://webservice.remote.spi.frameworkset.org/", "RPCCallServicePort"); Service service = Service.create(serviceName); service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, "http://localhost:8080/rpcws/services/RPCCallServicePort"); org.frameworkset.spi.remote.webservice.RPCCallService client = service.getPort(portName, org.frameworkset.spi.remote.webservice.RPCCallService.class); client.sendRPCMessage(null); // Dispatch // Insert code to invoke methods on the client here }
private HelloWorld createSoapService(String name, String password) throws Exception { final QName serviceName = new QName("http://hello.com", "HelloWorld"); final QName portName = new QName("http://hello.com", "HelloWorldPort"); final String address = "http://localhost:" + port + "/services/hello-soap"; System.out.println("Using JAX-WS proxy to invoke on HelloWorld service"); Service service = Service.create(serviceName); service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, address); HelloWorld hw = service.getPort(HelloWorld.class); ((BindingProvider)hw).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, name); ((BindingProvider)hw).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password); return hw; }
protected Dispatch<SOAPMessage> createDispatchFromURI(String uri) { QName serviceName = wsBinding.getService().getQName(); QName portName = new QName(serviceName.getNamespaceURI(), wsBinding.getPort().getName()); Service service = Service.create(serviceName); service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, uri); return service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE); }
protected Dispatch<SOAPMessage> createDynamicDispatch() { QName serviceName = wsBinding.getService().getQName(); QName portName = new QName(serviceName.getNamespaceURI(), wsBinding.getPort().getName()); Service service = Service.create(serviceName); service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointReference.getDeployedURI()); return service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE); }
@Test public void testDocLitWrappedCodeFirstServiceNoWsdl() 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"); Service service = Service.create(servName); service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, ServerMisc.DOCLIT_CODEFIRST_URL); DocLitWrappedCodeFirstService port = service.getPort(portName, DocLitWrappedCodeFirstService.class); runDocLitTest(port); }
@Test public void testHelloSoap() throws Exception { final QName serviceName = new QName("http://hello.com", "HelloWorld"); final QName portName = new QName("http://hello.com", "HelloWorldPort"); final String address = "http://localhost:" + PORT + "/bp/services/hello-soap"; Service service = Service.create(serviceName); service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, address); HelloWorld hw = service.getPort(HelloWorld.class); useHelloService(hw); } private void useHelloService(HelloWorld service) {
@Test public void testHelloSoap() throws Exception { final QName serviceName = new QName("http://hello.com", "HelloWorld"); final QName portName = new QName("http://hello.com", "HelloWorldPort"); final String address = "http://localhost:" + PORT + "/test/services/hello-soap"; Service service = Service.create(serviceName); service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, address); HelloWorld hw = service.getPort(HelloWorld.class); useHelloService(hw); }
@Test public void testRpcLitNoWsdl() throws Exception { QName portName = new QName("http://cxf.apache.org/systest/jaxws/RpcLitCodeFirstService", "RpcLitCodimlpementor6eFirstServicePort"); QName servName = new QName("http://cxf.apache.org/systest/jaxws/RpcLitCodeFirstService", "RpcLitCodeFirstService"); Service service = Service.create(servName); service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, ServerMisc.RPCLIT_CODEFIRST_URL); RpcLitCodeFirstService port = service.getPort(portName, RpcLitCodeFirstService.class); runRpcLitTest(port); }
@Test public void testBasicConnection() throws Exception { QName serviceName = new QName("http://type_substitution.systest.cxf.apache.org/", "AppleFinder"); QName portName = new QName("http://type_substitution.systest.cxf.apache.org/", "AppleFinderPort"); Service service = Service.create(serviceName); String endpointAddress = "http://localhost:" + PORT + "/appleFind"; service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress); AppleFinder finder = service.getPort(AppleFinder.class); assertEquals(2, finder.getApple("Fuji").size()); }
@Test public void testMTOMInHashMap() 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); 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); } } }
@Test public void testEchoProviderAsync() throws Exception { String requestString = "<echo/>"; Service service = Service.create(serviceName); service.addPort(fakePortName, javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING, "http://localhost:" + PORT + "/SoapContext/AsyncEchoProvider"); Dispatch<StreamSource> dispatcher = service.createDispatch(fakePortName, StreamSource.class, Service.Mode.PAYLOAD); StreamSource request = new StreamSource(new ByteArrayInputStream(requestString.getBytes())); StreamSource response = dispatcher.invoke(request); assertEquals(requestString, StaxUtils.toString(response)); }
@Test public void testServerAsync() throws Exception { Service service = Service.create(serviceName); service.addPort(fakePortName, javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING, "http://localhost:" + PORT + "/SoapContext/AsyncSoapPort"); Greeter greeter = service.getPort(fakePortName, Greeter.class); String resp = greeter.greetMe("World"); assertEquals("Hello World", resp); }
@Test public void testClientOutTransformation() { Service service = Service.create(SERVICE_NAME); String endpoint = "http://localhost:" + PORT + "/EchoContext/EchoPort"; service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpoint); Echo port = service.getPort(PORT_NAME, Echo.class); Client client = ClientProxy.getClient(port); XSLTOutInterceptor outInterceptor = new XSLTOutInterceptor(XSLT_REQUEST_PATH); client.getOutInterceptors().add(outInterceptor); String response = port.echo("test"); assertTrue("Request was not transformed", response.contains(TRANSFORMED_CONSTANT)); }
@Test public void testClientInTransformation() { Service service = Service.create(SERVICE_NAME); String endpoint = "http://localhost:" + PORT + "/EchoContext/EchoPort"; service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpoint); Echo port = service.getPort(PORT_NAME, Echo.class); Client client = ClientProxy.getClient(port); XSLTInInterceptor inInterceptor = new XSLTInInterceptor(XSLT_RESPONSE_PATH); client.getInInterceptors().add(inInterceptor); String response = port.echo("test"); assertTrue(response.contains(TRANSFORMED_CONSTANT)); } }
@Test public void testSOAPUDP() { BusFactory.setThreadDefaultBus(staticBus); Service service = Service.create(serviceName); service.addPort(localPortName, "http://schemas.xmlsoap.org/soap/", "soap.udp://localhost:" + PORT); Greeter greeter = service.getPort(localPortName, Greeter.class); String reply = greeter.greetMe("test"); assertEquals("Hello test", reply); reply = greeter.sayHi(); assertNotNull("no response received from service", reply); assertEquals("Bonjour", reply); }