public static void main(String[] args) throws Exception { String UrlString = "http://localhost:8080/axis/services/HelloPort?wsdl"; String nameSpaceUri = "http://hello.jaxrpc.samples/"; String serviceName = "HelloWorld"; String portName = "HelloPort"; URL helloWsdlUrl = new URL(UrlString); ServiceFactory serviceFactory = ServiceFactory.newInstance(); Service helloService = serviceFactory.createService(helloWsdlUrl, new QName(nameSpaceUri, serviceName)); java.util.List list = helloService.getHandlerRegistry().getHandlerChain(new QName(nameSpaceUri, portName)); list.add(new javax.xml.rpc.handler.HandlerInfo(ClientHandler.class,null,null)); Hello myProxy = (Hello) helloService.getPort( new QName(nameSpaceUri, portName), samples.jaxrpc.hello.Hello.class); System.out.println(myProxy.sayHello("Buzz")); }
/** * Perform a JAX-RPC dynamic call for the given AOP method invocation. * Delegates to {@link #prepareJaxRpcCall} and * {@link #postProcessJaxRpcCall} for setting up the call object. * <p>The default implementation uses method name as JAX-RPC operation name * and method arguments as arguments for the JAX-RPC call. Can be * overridden in subclasses for custom operation names and/or arguments. * @param invocation the current AOP MethodInvocation that should * be converted to a JAX-RPC call * @param service the JAX-RPC Service to use for the call * @return the return value of the invocation, if any * @throws Throwable the exception thrown by the invocation, if any * @see #prepareJaxRpcCall * @see #postProcessJaxRpcCall */ protected Object performJaxRpcCall(MethodInvocation invocation, Service service) throws Throwable { Method method = invocation.getMethod(); QName portQName = this.portQName; // Create JAX-RPC call object, using the method name as operation name. // Synchronized because of non-thread-safe Axis implementation! Call call = null; synchronized (service) { call = service.createCall(portQName, method.getName()); } // Apply properties to JAX-RPC stub. prepareJaxRpcCall(call); // Allow for custom post-processing in subclasses. postProcessJaxRpcCall(call, invocation); // Perform actual invocation. return call.invoke(invocation.getArguments()); }
@Override public Service loadService(URL url, QName qName, Properties props) throws ServiceException { try { if (!(new URL("http://myUrl1")).equals(url) || !"".equals(qName.getNamespaceURI()) || !"myService2".equals(qName.getLocalPart())) { throw new ServiceException("not supported"); } } catch (MalformedURLException ex) { } if (props == null || !"myValue".equals(props.getProperty("myKey"))) { throw new ServiceException("invalid properties"); } serviceCount++; return service1; }
/** * Constructs a new ServiceProxy wrapping given Service instance. * @param service the wrapped Service instance * @throws ServiceException should be never thrown */ public ServiceProxy(Service service) throws ServiceException { this.service = service; try { portQNameClass = Service.class.getDeclaredMethod("getPort", new Class[]{QName.class, Class.class}); portClass = Service.class.getDeclaredMethod("getPort", new Class[]{Class.class}); } catch (Exception e) { throw new ServiceException(e); } }
public StoreSoapBindingStub(Service service) throws AxisFault { if (service == null) { super.service = new org.apache.axis.client.Service(); } else { super.service = service; } ((org.apache.axis.client.Service) super.service).setTypeMappingVersion("1.2"); }
public static void main(String[] args) throws Exception { Options opts = new Options(args); String uri = "http://faults.samples"; String serviceName = "EmployeeInfoService"; ServiceFactory serviceFactory = ServiceFactory.newInstance(); Service service = serviceFactory.createService(new QName(uri, serviceName)); TypeMappingRegistry registry = service.getTypeMappingRegistry(); TypeMapping map = registry.getDefaultTypeMapping(); QName employeeQName = new QName("http://faults.samples", "Employee"); map.register(Employee.class, employeeQName, new BeanSerializerFactory(Employee.class, employeeQName), new BeanDeserializerFactory(Employee.class, employeeQName)); QName faultQName = new QName("http://faults.samples", "NoSuchEmployeeFault"); map.register(NoSuchEmployeeFault.class, faultQName, new BeanSerializerFactory(NoSuchEmployeeFault.class, faultQName), new BeanDeserializerFactory(NoSuchEmployeeFault.class, faultQName)); Call call = service.createCall(); call.setTargetEndpointAddress(new URL(opts.getURL()).toString()); call.setProperty(Call.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE); call.setProperty(Call.SOAPACTION_USE_PROPERTY, Boolean.TRUE); call.setProperty(Call.SOAPACTION_URI_PROPERTY, "http://faults.samples"); call.setOperationName( new QName(uri, "getEmployee") ); String[] args2 = opts.getRemainingArgs(); System.out.println("Trying :" + args2[0]); Employee emp = (Employee) call.invoke(new Object[]{ args2[0] }); System.out.println("Got :" + emp.getEmployeeID()); }
public static void main(String args[]) throws Exception { Options opts = new Options(args); args = opts.getRemainingArgs(); if (args == null || args.length % 2 != 0) { System.err.println("Usage: GetInfo <symbol> <datatype>"); System.exit(1); } String symbol = args[0]; Service service = ServiceFactory.newInstance().createService(null); Call call = service.createCall(); call.setTargetEndpointAddress(opts.getURL()); call.setOperationName(new QName("urn:cominfo", "getInfo")); call.addParameter("symbol", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter("info", XMLType.XSD_STRING, ParameterMode.IN); call.setReturnType(XMLType.XSD_STRING); if(opts.getUser()!=null) call.setProperty(Call.USERNAME_PROPERTY, opts.getUser()); if(opts.getPassword()!=null) call.setProperty(Call.PASSWORD_PROPERTY, opts.getPassword()); String res = (String) call.invoke(new Object[] {args[0], args[1]}); System.out.println(symbol + ": " + res); }
/** * This method does the same thing that getQuote1 does, but in * addition it reuses the Call object to make another call. */ public float getQuote3(String args[]) throws Exception { Options opts = new Options(args); args = opts.getRemainingArgs(); if (args == null) { System.err.println("Usage: GetQuote <symbol>"); System.exit(1); } /* Define the service QName and port QName */ /*******************************************/ QName servQN = new QName("urn:xmltoday-delayed-quotes", "GetQuoteService"); QName portQN = new QName("urn:xmltoday-delayed-quotes", "GetQuote"); /* Now use those QNames as pointers into the WSDL doc */ /******************************************************/ Service service = ServiceFactory.newInstance().createService( new URL("file:samples/stock/GetQuote.wsdl"), servQN); Call call = service.createCall(portQN, "getQuote"); /* Strange - but allows the user to change just certain portions of */ /* the URL we're gonna use to invoke the service. Useful when you */ /* want to run it thru tcpmon (ie. put -p81 on the cmd line). */ /********************************************************************/ opts.setDefaultURL(call.getTargetEndpointAddress()); call.setTargetEndpointAddress(opts.getURL()); /* Define some service specific properties */ /*******************************************/ call.setProperty(Call.USERNAME_PROPERTY, opts.getUser()); call.setProperty(Call.PASSWORD_PROPERTY, opts.getPassword()); /* Get symbol and invoke the service */ /*************************************/ Object result = call.invoke(new Object[] {symbol = args[0]}); /* Reuse the Call object for a different call */ /**********************************************/ call.setOperationName(new QName("urn:xmltoday-delayed-quotes", "test")); call.removeAllParameters(); call.setReturnType(XMLType.XSD_STRING); System.out.println(call.invoke(new Object[]{})); return ((Float) result).floatValue(); }
public static void main(String[] args) throws Exception { URL urlWsdl = new URL("http://localhost:8080/axis/services/Address?wsdl"); String nameSpaceUri = "http://address.jaxrpc.samples"; String serviceName = "AddressServiceService"; String portName = "Address"; ServiceFactory serviceFactory = ServiceFactory.newInstance(); Service service = serviceFactory.createService(urlWsdl, new QName(nameSpaceUri, serviceName)); AddressService myProxy = (AddressService) service.getPort(new QName(nameSpaceUri, portName), AddressService.class); AddressBean addressBean = new AddressBean(); addressBean.setStreet("55, rue des Lilas"); System.out.println(myProxy.updateAddress(addressBean, 75005)); }
/** * Create a JAX-RPC Service according to the parameters of this factory. * @see #setServiceName * @see #setWsdlDocumentUrl * @see #postProcessJaxRpcService */ public Service createJaxRpcService() throws ServiceException { ServiceFactory serviceFactory = getServiceFactory(); if (serviceFactory == null) { serviceFactory = createServiceFactory(); } // Create service based on this factory's settings. Service service = createService(serviceFactory); // Allow for custom post-processing in subclasses. postProcessJaxRpcService(service); return service; }
/** * Actually create the JAX-RPC Service instance, * based on this factory's settings. * @param serviceFactory the JAX-RPC ServiceFactory to use * @return the newly created JAX-RPC Service * @throws ServiceException if thrown by JAX-RPC methods * @see javax.xml.rpc.ServiceFactory#createService * @see javax.xml.rpc.ServiceFactory#loadService */ protected Service createService(ServiceFactory serviceFactory) throws ServiceException { if (getServiceName() == null && getJaxRpcServiceInterface() == null) { throw new IllegalArgumentException("Either 'serviceName' or 'jaxRpcServiceInterface' is required"); } if (getJaxRpcServiceInterface() != null) { // Create service via generated JAX-RPC service interface. // Only supported on JAX-RPC 1.1 if (getWsdlDocumentUrl() != null || getJaxRpcServiceProperties() != null) { return serviceFactory.loadService( getWsdlDocumentUrl(), getJaxRpcServiceInterface(), getJaxRpcServiceProperties()); } return serviceFactory.loadService(getJaxRpcServiceInterface()); } // Create service via specified JAX-RPC service name. QName serviceQName = getQName(getServiceName()); if (getJaxRpcServiceProperties() != null) { // Only supported on JAX-RPC 1.1 return serviceFactory.loadService(getWsdlDocumentUrl(), serviceQName, getJaxRpcServiceProperties()); } if (getWsdlDocumentUrl() != null) { return serviceFactory.createService(getWsdlDocumentUrl(), serviceQName); } return serviceFactory.createService(serviceQName); }
@Override public Service createService(QName qName) throws ServiceException { if (!"myNamespace".equals(qName.getNamespaceURI()) || !"myService1".equals(qName.getLocalPart())) { throw new ServiceException("not supported"); } serviceCount++; return service1; }
@Override public Service createService(URL url, QName qName) throws ServiceException { try { if (!(new URL("http://myUrl1")).equals(url) || !"".equals(qName.getNamespaceURI()) || !"myService2".equals(qName.getLocalPart())) { throw new ServiceException("not supported"); } } catch (MalformedURLException ex) { } serviceCount++; return service2; }
@Override public Service loadService(Class ifc) throws ServiceException { if (!IRemoteBean.class.equals(ifc)) { throw new ServiceException("not supported"); } serviceCount++; return service2; }
@Override public Service loadService(URL url, Class ifc, Properties props) throws ServiceException { try { if (!(new URL("http://myUrl1")).equals(url) || !IRemoteBean.class.equals(ifc)) { throw new ServiceException("not supported"); } } catch (MalformedURLException ex) { } if (props == null || !"myValue".equals(props.getProperty("myKey"))) { throw new ServiceException("invalid properties"); } serviceCount++; return service1; }
public void afterPropertiesSet() throws Exception { Stub stub = stubClass.getConstructor(Service.class).newInstance(new Object[] { null }); for (Method m : stub.getClass().getDeclaredMethods()) { if (m.getName().equals("createCall")) { m.setAccessible(true); messageContext = ((Call) m.invoke(stub)).getMessageContext(); break; } } if (messageContext == null) { throw new IllegalStateException("Could not find the createCall() method in the stub supplied!"); } }
/** * {@inheritDoc} */ @Override protected void postProcessJaxRpcService(Service service) { TypeMappingRegistry registry = service.getTypeMappingRegistry(); TypeMapping mapping = registry.createTypeMapping(); registerBeanMapping(mapping, Db2DbParams.class, "db2dbParams"); registerBeanMapping(mapping, DbReportParams.class, "dbReportParams"); registerBeanMapping(mapping, DbFindParams.class, "dbFindParams"); registerBeanMapping(mapping, DbWalkParams.class, "dbWalkParams"); registerBeanMapping(mapping, DbOrthoParams.class, "dbOrthoParams"); registry.register("http://schemas.xmlsoap.org/soap/encoding/", mapping); }
public StoreSoapBindingStub(URL endpointURL, Service service) throws AxisFault { this(service); super.cachedEndpoint = endpointURL; }
/** * This will use the WSDL to prefill all of the info needed to make * the call. All that's left is filling in the args to invoke(). */ public float getQuote1(String args[]) throws Exception { Options opts = new Options(args); args = opts.getRemainingArgs(); if (args == null) { System.err.println("Usage: GetQuote <symbol>"); System.exit(1); } /* Define the service QName and port QName */ /*******************************************/ QName servQN = new QName("urn:xmltoday-delayed-quotes", "GetQuoteService"); QName portQN = new QName("urn:xmltoday-delayed-quotes", "GetQuote"); /* Now use those QNames as pointers into the WSDL doc */ /******************************************************/ Service service = ServiceFactory.newInstance().createService( new URL("file:samples/stock/GetQuote.wsdl"), servQN); Call call = service.createCall(portQN, "getQuote"); /* Strange - but allows the user to change just certain portions of */ /* the URL we're gonna use to invoke the service. Useful when you */ /* want to run it thru tcpmon (ie. put -p81 on the cmd line). */ /********************************************************************/ opts.setDefaultURL(call.getTargetEndpointAddress()); call.setTargetEndpointAddress(opts.getURL()); /* Define some service specific properties */ /*******************************************/ call.setProperty(Call.USERNAME_PROPERTY, opts.getUser()); call.setProperty(Call.PASSWORD_PROPERTY, opts.getPassword()); /* Get symbol and invoke the service */ /*************************************/ Object result = call.invoke(new Object[] {symbol = args[0]}); return ((Float) result).floatValue(); }
/** * This will do everything manually (ie. no WSDL). */ public float getQuote2(String args[]) throws Exception { Options opts = new Options(args); args = opts.getRemainingArgs(); if (args == null) { System.err.println("Usage: GetQuote <symbol>"); System.exit(1); } /* Create default/empty Service and Call object */ /************************************************/ Service service = ServiceFactory.newInstance().createService(null); Call call = service.createCall(); /* Strange - but allows the user to change just certain portions of */ /* the URL we're gonna use to invoke the service. Useful when you */ /* want to run it thru tcpmon (ie. put -p81 on the cmd line). */ /********************************************************************/ opts.setDefaultURL("http://localhost:8080/axis/servlet/AxisServlet"); /* Set all of the stuff that would normally come from WSDL */ /***********************************************************/ call.setTargetEndpointAddress(opts.getURL()); call.setProperty(Call.SOAPACTION_USE_PROPERTY, Boolean.TRUE); call.setProperty(Call.SOAPACTION_URI_PROPERTY, "getQuote"); call.setProperty(Call.ENCODINGSTYLE_URI_PROPERTY, "http://schemas.xmlsoap.org/soap/encoding/"); call.setOperationName(new QName("urn:xmltoday-delayed-quotes", "getQuote")); call.addParameter("symbol", XMLType.XSD_STRING, ParameterMode.IN); call.setReturnType(XMLType.XSD_FLOAT); /* Define some service specific properties */ /*******************************************/ call.setProperty(Call.USERNAME_PROPERTY, opts.getUser()); call.setProperty(Call.PASSWORD_PROPERTY, opts.getPassword()); /* Get symbol and invoke the service */ /*************************************/ Object result = call.invoke(new Object[] {symbol = args[0]}); return ((Float) result).floatValue(); }
/** * Return a reference to an existing JAX-RPC Service instance, if any. */ public Service getJaxRpcService() { return this.jaxRpcService; }
/** * Create and initialize the JAX-RPC service for the specified port. * <p>Prepares a JAX-RPC stub if possible (if an RMI interface is available); * falls back to JAX-RPC dynamic calls else. Using dynamic calls can be enforced * through overriding {@link #alwaysUseJaxRpcCall} to return {@code true}. * <p>{@link #postProcessJaxRpcService} and {@link #postProcessPortStub} * hooks are available for customization in subclasses. When using dynamic calls, * each can be post-processed via {@link #postProcessJaxRpcCall}. * @throws RemoteLookupFailureException if service initialization or port stub creation failed */ public void prepare() throws RemoteLookupFailureException { if (getPortName() == null) { throw new IllegalArgumentException("Property 'portName' is required"); } synchronized (this.preparationMonitor) { this.serviceToUse = null; // Cache the QName for the port. this.portQName = getQName(getPortName()); try { Service service = getJaxRpcService(); if (service == null) { service = createJaxRpcService(); } else { postProcessJaxRpcService(service); } Class portInterface = getPortInterface(); if (portInterface != null && !alwaysUseJaxRpcCall()) { // JAX-RPC-compliant port interface -> using JAX-RPC stub for port. if (logger.isDebugEnabled()) { logger.debug("Creating JAX-RPC proxy for JAX-RPC port [" + this.portQName + "], using port interface [" + portInterface.getName() + "]"); } Remote remoteObj = service.getPort(this.portQName, portInterface); if (logger.isDebugEnabled()) { Class serviceInterface = getServiceInterface(); if (serviceInterface != null) { boolean isImpl = serviceInterface.isInstance(remoteObj); logger.debug("Using service interface [" + serviceInterface.getName() + "] for JAX-RPC port [" + this.portQName + "] - " + (!isImpl ? "not" : "") + " directly implemented"); } } if (!(remoteObj instanceof Stub)) { throw new RemoteLookupFailureException("Port stub of class [" + remoteObj.getClass().getName() + "] is not a valid JAX-RPC stub: it does not implement interface [javax.xml.rpc.Stub]"); } Stub stub = (Stub) remoteObj; // Apply properties to JAX-RPC stub. preparePortStub(stub); // Allow for custom post-processing in subclasses. postProcessPortStub(stub); this.portStub = remoteObj; } else { // No JAX-RPC-compliant port interface -> using JAX-RPC dynamic calls. if (logger.isDebugEnabled()) { logger.debug("Using JAX-RPC dynamic calls for JAX-RPC port [" + this.portQName + "]"); } } this.serviceToUse = service; } catch (ServiceException ex) { throw new RemoteLookupFailureException( "Failed to initialize service for JAX-RPC port [" + this.portQName + "]", ex); } } }
public Service getObject() throws Exception { return this.service; }
public Class<? extends Service> getObjectType() { return (this.service != null ? this.service.getClass() : Service.class); }
public MockServiceFactory() throws Exception { service1 = mock(Service.class); service2 = mock(Service.class); initMocks(); }
/** * Post-process the given JAX-RPC Service. Called by {@link #createJaxRpcService}. * Useful, for example, to register custom type mappings. * <p>The default implementation delegates to all registered * {@link JaxRpcServicePostProcessor JaxRpcServicePostProcessors}. * It is usually preferable to implement custom type mappings etc there rather * than in a subclass of this factory, to allow for reuse of the post-processors. * @param service the current JAX-RPC Service * (can be cast to an implementation-specific class if necessary) * @see #setServicePostProcessors * @see javax.xml.rpc.Service#getTypeMappingRegistry() */ protected void postProcessJaxRpcService(Service service) { JaxRpcServicePostProcessor[] postProcessors = getServicePostProcessors(); if (postProcessors != null) { for (int i = 0; i < postProcessors.length; i++) { postProcessors[i].postProcessJaxRpcService(service); } } }
/** * Set a reference to an existing JAX-RPC Service instance, * for example obtained via {@link org.springframework.jndi.JndiObjectFactoryBean}. * If not set, {@link LocalJaxRpcServiceFactory}'s properties have to be specified. * @see #setServiceFactoryClass * @see #setWsdlDocumentUrl * @see #setNamespaceUri * @see #setServiceName * @see org.springframework.jndi.JndiObjectFactoryBean */ public void setJaxRpcService(Service jaxRpcService) { this.jaxRpcService = jaxRpcService; }
/** * Post-process the given JAX-RPC {@link Service}. * @param service the current JAX-RPC {@code Service} * (can be cast to an implementation-specific class if necessary) */ void postProcessJaxRpcService(Service service);