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;
import java.io.File;
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();
xConfig.addServiceGroup(serviceGroup);
server.start();
} catch (AxisFault axisFault) {
axisFault.printStackTrace();
}
}
/**
* Method used to stop SimpleHTTPServer
*/
public synchronized void stopHTTPServer() {
server.stop();
}
public static void main {
startHTTPServer();
stopHTTPServer()
}
}
1 comment:
Hi,
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
Post a Comment