Library Link To Toggle Frames Print Feedback

Writing a Server Mainline

If you used the Java first development model or you do not want to use the generated server mainline you can write your own. To write your server mainline you must do the following:

  1. Instantiate an javax.xml.ws.Endpoint object for the endpoint.

  2. Create an optional server context to use when publishing the endpoint.

  3. Publish the endpoint using one of the publish().

Instantiating an Endpoint

You can instantiate an Endpoint using one of the following three methods provided by Endpoint:

  • static Endpoint create(Object implementor);

    This create() method returns an Endpoint for the specified service implementation. The created Endpoint is created using the information provided by the implementation class'javax.xml.ws.BindingType annotation if it is present. If the annotation is not present, the Endpoint will use a default SOAP 1.1/HTTP binding.

  • static Endpoint create(URI bindingID,
                           Object implementor);

    This create() method returns an Endpoint for the specified implementation object using the specified binding. This method overrides the binding information provided by the javax.xml.ws.BindingType annotation if it is present. If the bindingID cannot be resolved, or is null, the binding specified in the javax.xml.ws.BindingType is used to create the Endpoint. If neither the bindingID or the javax.xml.ws.BindingType can be used, the Endpoint is created using a default SOAP 1.1/HTTP binding.

  • static Endpoint publish(String address,
                            Object implementor);

    The publish() method creates an Endpoint for the specified implementation and publishes it. The binding used for the Endpoint is determined by the URL scheme of the provided address. The list of bindings available to the implementation are scanned for a binding that supports the URL scheme. If one is found the Endpoint is created and published. If one is not found, the method fails.

    [Tip] Tip

    Using publish() is the same as invoking one of the create() methods and then invoking the publish() method discussed in Publishing to an address.

[Important] Important

The implementation object passed to any of the Endpoint creation methods must either be an instance of a class annotated with javax.jws.WebService and meeting the requirements for being an SEI implementation or be an instance of a class annotated with javax.xml.ws.WebServiceProvider and implementing the Provider interface.

Publishing an endpoint

You can publish an endpoint using one of the following Endpoint methods:

  • void publish(String address);

    This publish() method publishes the endpoint at the address specified.

    [Important] Important

    The address's URL scheme must be compatible with one of the endpoint's bindings.

  • void publish(Object serverContext);

    This publish() method publishes the endpoint based on the information provided in the specified server context. The server context must define an address for the endpoint and it also must be compatible with one of the endpoint's available bindings.

Example

Example 6.2, “Custom Server Mainline” shows code for publishing an endpoint.

Example 6.2. Custom Server Mainline

package org.apache.hello_world_soap_http;

import javax.xml.ws.Endpoint;

public class GreeterServer
{
  protected GreeterServer() throws Exception
  {
  }
    
  public static void main(String args[]) throws Exception
  { 
1    GreeterImpl impl = new GreeterImpl();
2    Endpoint endpt.create(impl);
3    endpt.publish("http://localhost:9000/SoapContext/SoapPort");

    boolean done = false;
4   while(!done)
    {
      ...
    }

    System.exit(0);
  }
}

The code in Example 6.2, “Custom Server Mainline” does the following:

1

Instantiates a copy of the service's implementation object.

2

Creates an unpublished Endpoint for the service implementation.

3

Publish the endpoint at http://localhost:9000/SoapContext/SoapPort.

4

Loop until the server should be shutdown.