When you want to deploy your application as a plain java application you need to implement the logic for publishing your
endpoints in the application's main()
method. FUSE Services Framework provides you two options for writing
your application's main()
method.
use the main()
method generated by the wsdl2java
tool
write a custom main()
method that publishes the endpoints
The wsdl2java tool's -server
flag makes the tool generate a simple server
mainline. The generated server mainline, as shown in Example 9.2, publishes one service
provider for each port
element in the specified WSDL contract.
For more information see wsdl2java in
Example 9.2 shows a generated server mainline.
Example 9.2. Generated Server Mainline
package org.apache.hello_world_soap_http; import javax.xml.ws.Endpoint; public class GreeterServer { protected GreeterServer() throws Exception { System.out.println("Starting Server");Object implementor = new GreeterImpl();
String address = "http://localhost:9000/SoapContext/SoapPort";
Endpoint.publish(address, implementor); } public static void main(String args[]) throws Exception { new GreeterServer(); System.out.println("Server ready..."); Thread.sleep(5 * 60 * 1000); System.out.println("Server exiting"); System.exit(0); } }
The code in Example 9.2 does the following:
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:
Instantiate an
javax.xml.ws.Endpoint
object for the service provider.
Create an optional server context to use when publishing the service provider.
Publish the service provider
using one of the publish()
methods.
Stop the service provider when the application is ready to exit.
Example 9.3 shows the code for publishing a service provider.
Example 9.3. 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 {GreeterImpl impl = new GreeterImpl();
Endpoint endpt.create(impl);
endpt.publish("http://localhost:9000/SoapContext/SoapPort"); boolean done = false;
while(!done) { ... }
endpt.stop(); System.exit(0); } }
The code in Example 9.3 does the following: