In most cases, the user does not need to specify service settings himself. The methods in Registry set appropriate default settings in the background. On the other hand, when you want to customize the generation of the WSDL file, the instantiation, service instance life cycle, etc., you need to use the ServiceEndpoint and ServiceInstance classes.
![]() | Note |
---|---|
Once Web service class sources are available in the classpath, they are observed and parameter names are read from them and fed into the WSDL generated on the fly. |
ServiceEndpoint represents a published Web service.
Using this class, one can fully set up various endpoint properties and processors affecting message processing, such as header processors, interceptors, etc.
Common usage is shown in Example 51:
Example 51. Service Endpoint Usage
ServiceEndpoint serviceEndpoint = ServiceEndpoint.create( "/HelloService", new HelloService()); serviceEndpoint.set...; ... Registry.publish(service);
See the Javadoc for full information on org.systinet.wasp.webservice.ServiceEndpoint.
All create methods use the service endpoint path. The two simplest use the implementation object or the implementation class, respectively.
create(String path, Class implementationClass)
These methods make public all public methods of the implementation object or class, including interfaces. If you want to expose the methods of only one interface, that interface is specified using one of the next two methods.
create(String path, Object implementationObject, Class iface)
create(String path, Class implementationClass, Class iface)
In the previous methods, the service instance was created in the background, automatically. If you want to have one service instance shared by a number of service endpoints, you should use the following methods (Note that this is the situation in Figure 1 of WS Components and Lifecycle.):
create(String path, ServiceInstance serviceInstance)
As in 3 and 4 above, the methods of the implementation class (ServiceInstance) can be filtered by an interface:
create(String path, ServiceInstance serviceInstance, Class iface)
The last two methods are "copy constructors": they copy the parameters of an existing service endpoint to a new service endpoint. Both service endpoints share the same service instance but are accessible on different paths.
create(String path, ServiceEndpoint serviceEndpoint)
Again, the methods of the shared service instance can be filtered through an interface:
create(String path, ServiceEndpoint serviceEndpoint,Class iface)
Service endpoint location
getPath() / setPath(java.lang.String) : Returns and sets the location of the service endpoint such as /HelloService
Service endpoint internals
getServiceType() Returns the type of service, that is, raw, xml or java.
getContext() : Returns the service endpoint context. This context is created during the creation process. Its main use is to enable the storage of additional data for use during the service call.
getServiceInstance() : Returns the service instance held by the service endpoint.
getInterface() / setInterface(java.lang.Class) : Returns and sets the filtering interface for the service endpoint.
setServiceURL(java.lang.String) : If specified, the value of ServiceURL overrides the <soap:address location="..."/> attribute in the WSDL. When left unspecified, WSO2 SOA Enablement Server for Java automatically sets the <soap:address location="..."/> attribute to match the address in the GET request. For example, when a WSDL is obtained from http://localhost:6060/HelloService/wsdl, it contains the element <soap:address location="http://localhost:6060/HelloService"/>. A WSDL of the same service endpoint obtained from http://myserver.mydomain.com:6060/HelloService/wsdl contains the element <soap:address location="http://localhost:6060/HelloService"/>.
getWSDL() / setWSDL(javax.wsdl.Definition) : Obtains the WSDL file generated and held by the service endpoint. This WSDL file, if not specified by user, is created during publishing.
getWSDLServiceName() / setWSDLServiceName(javax.xml.namespace.QName) : Returns the service name from the WSDL file describing the service endpoint.
getWSDLPortName() / setWSDLPortName(java.lang.String) : Returns the service port name describing the service endpoint.
In general, a listener is an object that "listens" for events from another specific object. ServiceEndpointListener listens for a ServiceEndpoint object being published or unpublished.
Each ServiceEndpointListener must implement the following interface:
public interface ServiceEndpointListener { void onPublish(ServiceEndpoint serviceEndpoint) throws PublishException; void onUnpublish(ServiceEndpoint serviceEndpoint) throws PublishException; }
ServiceEndpointListeners can be registered as either global or local.
Global listeners must be registered on Registry via the Registry.addListener(ServiceEndpointListener listener) method and they are invoked whenever a service endpoint is published or unpublished.
Local listeners are registered on a specific ServiceEndpoint via the ServiceEndpoint.addListener(ServiceEndpointListener listener) method and called only when that particular service endpoint is published or unpublished.
For more information, please see the Javadoc org.systinet.wasp.webservice.ServiceEndpointListener.
The org.systinet.wasp.webservice.ServiceInstance class is a handle for the implementation of a Web service, represented by a ServiceEndpoint.
Typical usages are shown in Example 52 and Example 53:
Example 52. Implementation of a Web Service, Represented by a Service Endpoint (Example A)
ServiceInstance instance = ServiceInstance.create(HelloService.class); instance.setInstantiationMethod( ServiceInstance.INSTANTIATION_METHOD_PER_CLIENT); instance.set...; ... ServiceEndpoint endpoint = ServiceEndpoint.create("/HelloService", instance); Registry.publish(endpoint);
Or:
Example 53. Implementation of a Web Service, Represented by a Service Endpoint (Example B)
ServiceEndpoint endpoint = Registry.getServiceEndpoint("/HelloService"); ServiceInstance instance = endpoint.getServiceInstance(); instance.set...;
There are three methods for creating a new service instance.
create(Object implementationObject)
This method provides a pre-existing implementation object of the Web Service.
create(Class implementationClass)
The instance of the implementation class is created during publishing; otherwise it is the same as 1.
create(String implementationClass)
Use this when you want to create an instance of a class accessible by JNDI or a fully qualified class name. (For example, demo.HelloService or jndi:demo.HelloService)
getConfigurable(), setConfigurable(Configurable)
Enables the user to customize the runtime configuration of the service instance using the WSO2 SOA Enablement Server configuration framework.
Gets the ServiceInstanceContext object associated with this service instance. This ServiceInstanceContext exists from the moment of creation of the ServiceInstance.
The implementation class or object can only be set before publishing. Otherwise, an IllegalStateException is thrown.
There are four methods empowering users with control over created instances on the server side. You can decide whether a new service instance should be created when a new client (meaning a new proxy) accesses the server. You can also set the time limit for these created service instances; after the time limit, these instances are destroyed to conserve server resources. Note that this time limit countdown starts after the client's last call.
setInstantiationMethod(int instantiationMethod)
Returns and sets the type of instantiation. There are two types: per-client and shared (default). With per-client instantiation, a new service instance is created for each new proxy. With shared instantiation, the default service instance is used for every proxy.
Returns and sets the default time-to-live of a per-client service instance. The default time-to-live is ten minutes. (Shared instantiation lasts indefinitely.)
setMaxInstances(int maxInstances)
Used only for per-client instantiation. Returns and sets the number of instances created per service endpoint.