Top Navigation
Show Content

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

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();

 

The service cannot be found for the endpoint reference (EPR)

I tried to change the service's uri from /axis2/ to /foo/ with context.setContextRoot("/foo");

My service works with the new url, but the list of services formerly under /axis2/services/ does not work und /foo/services/.

What did I miss?

Technology News

Echo JAVA is much better, thanks for the info

Technology News

First of all thanks a lot

First of all thanks a lot for the informative and useful article. It was really interesting to read about the adding a SimpleHTTPServer in the application and deploying a web service from a plain ol' java class samples. I have to admit that this post a little bit difficult for me, because I am a beginner in this sphere. But the information which you have shared with us was really useful for me because I have known many new things. Thanks a lot one more time for the great entry and I will be waiting for other great posts from you in the nearest future.

Regards,

David Simpson from mobile application development

Keep up the good work.

We are at the threshold of a new world where Web Services will be used for everything. The next generation of Web Services-based middleware needs to handle all the use cases they confront. In the last few years, work on web services has matured the Web Services stack and the standards. Apache Axis2 plans to take on the next generation of Web Services by implementing a high performance web service engine that incorporates the advancements made on the Web Services stack.

free ads |jobs|tempurpedic mattress

Good post overall. Enjoyed

Good post overall. Enjoyed reading it. Henry blog

Comment viewing options

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