login button

How do I Embed SimpleHTTPServer in My Application and Deploy a POJO?

Story :

Project :

Q: How do I Embed SimpleHTTPServer in My Application and Deploy a POJO?

A: Without much ado, here's the EmbeddedAxis2Server that shows how to add a SimpleHTTPServer in your application and deploys a web service from a plain ol' java class samples.Echo (also shown below). All you need to do is get the binary jars from Axis 1.0 Final distribution, compile the 2 classes below and voila! you have an embedded Axis2 server.

Once you have it running, you can view the runtime generated wsdl at http://localhost:8080/axis2/services/Echo?wsdl or the schema at http://localhost:8080/axis2/services/Echo?xsd Enjoy! EmbeddedAxis2Server.java

import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.rpc.receivers.RPCMessageReceiver;
import org.apache.axis2.transport.http.SimpleHTTPServer;
import samples.Echo;

public class EmbeddedAxis2Server {
public static void main(String[] args) throws Exception {
ConfigurationContext context = ConfigurationContextFactory.
createConfigurationContextFromFileSystem(null, null);
AxisService service =
AxisService.createService(Echo.class.getName(), context.getAxisConfiguration(),
RPCMessageReceiver.class, "", "http://samples");
context.getAxisConfiguration().addService(service);
SimpleHTTPServer server = new SimpleHTTPServer(context, 8080);
server.start();
}
}
Echo.java
package samples;

public class Echo {
public String echo(String in) {
return in;
}
}

Applies To:

Apache Axis2/Java 1.0 and above
5
Average: 5 (2 votes)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Axis2 with Jetty embedded server and POJO deployment


Very very helpful article!
I m newbie at Axis2 and Jetty.
I want to use Axis2 with Jetty embedded server and to deploy POJO programmatically. Jetty has nothing to do with type "ConfigurationContext" as SimpleHTTPServer do.

"SimpleHTTPServer server = new SimpleHTTPServer(context, 8080);"

How can I let jetty know about "ConfigurationContext". As, without "ConfigurationContext" one can't deploy a POJO programmatically.

Moreover Jetty is supposed to run Axis2 without Axis and webapps folder, as it is working in "EmbeddedAxis2Server".
Thanx.

AxisService.createService: bad signature

Tanks a lot for this very good article.

Just one comment: I'm using Axis 2 v1.4, and the "createService" method of the "AxisService" object has a different signature:

public static AxisService createService(String implClass, AxisConfiguration axisConfiguration, Map messageReceiverClassMap, String targetNamespace, String schemaNamespace, ClassLoader loader) throws AxisFault

Then the receiver must be put into the Map Object to be usable. Consequently, the new code is:

        ConfigurationContext context = ConfigurationContextFactory

                .createConfigurationContextFromFileSystem(null, null);

        Map<String, MessageReceiver> mrMap = new HashMap<String, MessageReceiver>();

        mrMap.put("http://www.w3.org/2004/08/wsdl/in-only",

                RPCMessageReceiver.class.newInstance());

        AxisService service = AxisService.createService(HelloWorldImpl.class

                .getName(), context.getAxisConfiguration(), mrMap, "",

                "http://samples", Main.class.getClassLoader());

        context.getAxisConfiguration().addService(service);



        SimpleHTTPServer server = new SimpleHTTPServer(context, 8080);

        server.start();

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.