/** * Change the port of the service. * * @param portName * The new port name. * @throws IllegalArgumentException * if port name is not defined in WSDL. */ public void setPort( QName portName ) { Port port = _service.getPort( portName.getLocalPart() ); if ( port == null ) { throw new IllegalArgumentException( "Port name: '" + portName + "' was not found in the WSDL file." ); } _port = port; _operationCache.clear(); }
public Wsdl( WSDLLocator wsdlLocator, QName serviceQName, String portName, String username, String password ) throws AuthenticationException { // load and parse the WSDL try { _wsdlDefinition = parse( wsdlLocator, username, password ); } catch ( AuthenticationException ae ) { // throw it again or KettleException will catch it throw ae; } catch ( WSDLException e ) { throw new RuntimeException( "Could not load WSDL file: " + e.getMessage(), e ); } catch ( KettleException e ) { throw new RuntimeException( "Could not load WSDL file: " + e.getMessage(), e ); } _service = _wsdlDefinition.getService( serviceQName ); if ( _service == null ) { throw new IllegalArgumentException( "Service: " + serviceQName + " is not defined in the WSDL file." ); } _port = _service.getPort( portName ); if ( _port == null ) { throw new IllegalArgumentException( "Port: " + portName + " is not defined in the service: " + serviceQName ); } _wsdlTypes = new WsdlTypes( _wsdlDefinition ); _operationCache = new HashMap<String, WsdlOperation>(); }
Service s = new Service(); Port port = s.getPort(); BindingProvider prov = (BindingProvider)port; prov.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "myusername"); prov.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "mypassword"); port.call();
private YourService proxy; public YourServiceWrapper() { try { final String username = "username"; final String password = "password"; Authenticator.setDefault(new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication( username, password.toCharArray()); } }); URL url = new URL("http://yourserviceurl/YourService?WSDL"); QName qname = new QName("http://targetnamespace/of/your/wsdl", "YourServiceNameInWsdl"); Service service = Service.create(url, qname); proxy = service.getPort(YourService.class); Map<String, Object> requestContext = ((BindingProvider) proxy).getRequestContext(); requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url.toString()); requestContext.put(BindingProvider.USERNAME_PROPERTY, username); requestContext.put(BindingProvider.PASSWORD_PROPERTY, password); Map<String, List<String>> headers = new HashMap<String, List<String>>(); requestContext.put(MessageContext.HTTP_REQUEST_HEADERS, headers); } catch (Exception e) { LOGGER.error("Error occurred in web service client initialization", e); } }
// Create the service Service service = Service.create(urlToWsdl, serviceQName); // Access the port return service.getPort(serviceQName, portTypeClass);
String wsdlDocumentLocation = "localVersion.wsdl"; QName serviceName = new QName("mynamespace", "myServiceName"); Service service = Service.create(wsdlDocumentLocation, serviceName); //send the port the fully qualified name of the Metro generated //client interface Object port = service.getPort("my.client.package.ClientServiceInterface");
try { Definition def = wsdlManager.getDefinition(wsdlDocumentLocation); interfaceName = def.getService(serviceName).getPort(portName.getLocalPart()).getBinding() .getPortType().getQName(); } catch (Exception e) {
URL url = new URL("http://localhost:9090/ws/hello?wsdl"); //1st argument service URI, refer to wsdl document above //2nd argument is service name, refer to wsdl document above QName qname = new QName("http://ws.service.com/", "HelloWorldImplService"); Service service = Service.create(url, qname); HelloWorld hellObj = service.getPort(HelloWorld.class);
Service s = Service.create( new URL("http://example.com/your_service?wsdl"), new QName("http://example.com/your_namespace", "YourServiceName")); ServiceInterface yourService = s.getPort( new QName("http://example.com/your_namespace", "YourPortName"), ServiceInterface.class);
try { URL wsdlURL = new URL("http://localhost:8082/cxf/services/yourservice?wsdl"); QName SERVICE_NAME = new QName("http://package.name/","PORTNAme"); Service service = Service.create(wsdlURL, SERVICE_NAME); client = service.getPort(PORTInterface.class); client.executeYourMethod() } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }
public class WSClient { public static void main(String[] args) throws Exception { URL url = new URL("http://localhost:8080/ws/hello?wsdl"); QName qname = new QName("http://bot.ws/", "HelloWorldImplService"); Service service = Service.create(url, qname); HelloWorld hello = service.getPort(HelloWorld.class); System.out.println(hello.getString("bot")); } }
// Create the service Service service = Service.create(serviceQName); // Add a Port to the service and specify the SOAP 1.2 binding service.addPort(serviceQName, javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING, wsUrl); // Access the port return service.getPort(serviceQName, portTypeClass);
private Port getPort(QName serviceQname, QName eprQname) { Service service = getService(serviceQname); if (service == null) { return null; } return service.getPort(eprQname.getLocalPart()); }
private Port getPortDefinition() { Service serviceDef = wsdl.getService(serviceName); if (serviceDef == null) { throw new NullPointerException(Messages.msgServiceDefinitionNotFound( serviceName.getLocalPart())); } return serviceDef.getPort(portName); }
URL wsdlURL = new URL("..."); QName serviceName = new QName("...", "..."); Service service = Service.create(wsdlURL, serviceName); HandlerResolver handlerResolver = new ClientHandlerResolver(); service.setHandlerResolver(handlerResolver); MyService myService = service.getPort(MyService.class); // invoke methods (operations) on myService
import javax.xml.ws.soap.MTOMFeature; public class ArchiveMessageSerializer { public String serializeArchiveReportWithDefTags(ArchiveMetadataType metaData) throws UnsupportedEncodingException { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); RedirectionTransportFactory.getRegistry().registerRedirectionInThread(buffer); final Service service = new Service(); final Port port = service.getPort(new MTOMFeature()); port.someMethod(metaData); return buffer.toString("iso-8859-1"); } }
public Port getWSDLPort() { javax.wsdl.Service service = getWSDLService(); if (service != null) { return service.getPort(getPortQName().getLocalPart()); } else { return null; } }
Service service = Service.create(url, qname); Greeting greeting = service.getPort(Greeting.class); BindingProvider bp = (BindingProvider) greeting; SOAPBinding binding = (SOAPBinding) bp.getBinding(); binding.setMTOMEnabled(true); List<Handler> handlerList = new ArrayList<Handler>(); handlerList.add(new RGBSOAPHandler()); binding.setHandlerChain(handlerList);
/** * @see #useHTTPBinding(javax.wsdl.Binding) */ public static boolean useHTTPBinding(Definition def, QName serviceName, String portName) { Service serviceDef = def.getService(serviceName); if (serviceDef == null) throw new IllegalArgumentException(msgs.msgServiceDefinitionNotFound(serviceName)); Port port = serviceDef.getPort(portName); if (port == null) throw new IllegalArgumentException(msgs.msgPortDefinitionNotFound(serviceName, portName)); return useHTTPBinding(port); }