Wednesday, April 27, 2011

Sample java code for start axis2 simple http server with service

Some times you may want to use sample web service to communicate with your client written by java.This example will show you how to start/stop apache simple HTTP server programatically and upload axis2 service to the simple axis2 service programatically.

import org.apache.axis2.AxisFault;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.deployment.DeploymentEngine;
import org.apache.axis2.description.AxisServiceGroup;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.transport.http.SimpleHTTPServer;


public class HTTPServerManager {
private static SimpleHTTPServer server;
protected int serverPort = 9000;

public synchronized void startHTTPServer() {
ConfigurationContext context;
try {
context = ConfigurationContextFactory.
createConfigurationContextFromFileSystem(location of axis2.xml, null);
server = new SimpleHTTPServer(context, serverPort);
String resourcePath = HTTPServerManager.class.getResource("location of axis2service.aar").getPath();
AxisServiceGroup serviceGroup = DeploymentEngine.loadServiceGroup(new File(resourcePath), context);
AxisConfiguration xConfig = context.getAxisConfiguration();

} catch (AxisFault axisFault) {

* Method used to stop SimpleHTTPServer
public synchronized void stopHTTPServer() {

public static void main {

1 comment:

pcaroco said...

I also want to do something like this but instead of using a pre-compiled service I want to use an exportation class that is in the source.

Can you help me on this?

Best regards