WSO2Con 2013 CFP Banner

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

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

Date: Mon, 8th May, 2006
Level:
Reads: 21744
Discuss this article on Stack Overflow
Davanum Srinivas

WSO2 Inc.

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
martinbroud.gmail.com's picture

Toronto Web Designer

Very well explained! Thanks for share.......... Oilchange.com
lyj090102.yahoo.com's picture

oakley sunglasses sale also

oakley sunglasses sale also make the water seem darker but more transparent if you look at it from an angle but not straight down.
latharangith1988.gmail.com's picture

In WSO2 Tungsten any service

In WSO2 Tungsten any service can access server's runtime environment. In this article Deepal Jayasinghe explains how to use WSO2 Tungsten as a client to make Web service invocations. He goes to mention, "There are a number of instances where a service running inside an application server requires to send a request to some other service, or needs to invoke some other service hosted in the same application server (or any other location). The above scenario can be considered a client running inside Server". seo bristol
597529167.qq.com's picture

http://www.atcoachoutletsonli

http://www.atcoachoutletsonline.net Coach Outlet http://www.getcoachfactoryoutlet.org Coach Factory http://www.louisvuittonhandbagsoutlet.org/ Louis Vuitton Handbags Outlet http://www.saleincoachoutlets.com Coach Outlet Online http://www.atcoachoutletsonline.net Coach Outlet Online http://www.getcoachfactoryoutlet.org Coach Factory Outlet http://www.louisvuittonhandbagsoutlet.org/ Louis Vuitton Handbags http://www.saleincoachoutlets.com Coach Outlet http://www.coachfactoryoutlet-s.org Coach Factory Outlet http://www.buycoachoutletonline.org Coach Outlet http://www.coachoutletonfactory.net Coach Outlet http://www.buycoachoutletonline.org Coach Outlet Online
cheaponlinedesigner.gmail.com's picture

cheaphandbags

Thanks for your opinion. discount handbags I totally like with it.I like cheap designer handbags as well and someone is looking for new era caps? People usually prefer cheap handbags online, especially when they visit some clothing store. In some areas,people like to wholesale clothing. They will find some store doing very cheap or discounted handbags outlet. Certainly, is a good way to earn money. designer handbags outlet
409848980.qq.com's picture

Chanel handbag, you gucci

Chanel handbag, you gucci bagS for cheap Chanel handbag, you chanel patent lEather shopping bag pink a39827-9184 stores Chanel handbag, you Chanel bags bags outlet Chanel handbag, you Cheap chanel black lambskin quilted bag a20997-9465
neeraj_fore.yahoo.com's picture

Problem in running this program

Hi, I am facing problem in running this program. I tried to resolve this problem since last couple of days but no luck. I am using below code with axis2 version "axis2-1.4.1". public static void main(String[] args) throws Exception { Map mep = new HashMap(); mep.put("http://www.w3.org/2004/08/wsdl/in-only", RPCInOnlyMessageReceiver.class.newInstance()); mep.put("http://www.w3.org/2004/08/wsdl/in-out", RPCMessageReceiver.class.newInstance()); // ConfigurationContext config = ConfigurationContext config = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null); AxisService service = AxisService.createService(Echo.class.getName(), config.getAxisConfiguration(), mep, null, null, EmbeddedAxis2Server.class.getClassLoader()); config.getAxisConfiguration().addService(service); SimpleHTTPServer server = new SimpleHTTPServer(config, 8080); server.start(); } It is throwing the below exception Exception in thread "main" java.lang.NoSuchMethodError: org.apache.axiom.om.impl.builder.StAXOMBuilder.releaseParserOnClose(Z)V at org.apache.axis2.util.XMLUtils.toOM(XMLUtils.java:601) at org.apache.axis2.util.XMLUtils.toOM(XMLUtils.java:581) at org.apache.axis2.deployment.DescriptionBuilder.buildOM(DescriptionBuilder.java:97) at org.apache.axis2.deployment.AxisConfigBuilder.populateConfig(AxisConfigBuilder.java:86) at org.apache.axis2.deployment.DeploymentEngine.populateAxisConfiguration(DeploymentEngine.java:641) at org.apache.axis2.deployment.FileSystemConfigurator.getAxisConfiguration(FileSystemConfigurator.java:116) at org.apache.axis2.context.ConfigurationContextFactory.createConfigurationContext(ConfigurationContextFactory.java:68) at org.apache.axis2.context.ConfigurationContextFactory.createConfigurationContextFromFileSystem(ConfigurationContextFactory.java:184) at axis.EmbeddedAxis2Server.main(EmbeddedAxis2Server.java:27) What could be reason for this. I tried to set the axis2.xml file path and axis2 repo path also in configuration Context e.g but same error ConfigurationContext config = ConfigurationContextFactory.createConfigurationContextFromFileSystem("....\\axis2-1.4.1\\repository", "...\\conf\\axis2.xml"); Please have your thoughts on it. Your help is really appreciated. Thanks
jenniferrockz21.gmail.com's picture

NICE

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. Utah Loan Modification | Loan Modification Programs
2010halloweenideas.gmail.com's picture

Re:

2010 Costume Ideas
bryan.fuller.printingblue.com's picture

thanks giving

thanks for sharing such nicely written post, enjoyed reading it.
harrison.logan011.gmail.com's picture

Deploy a POJO?

When you create objects in your project, avoid building on top classes/interfaces provided by the various architectures/frameworks. This doesn't include things that make up the core of java, but things sucked in by e.g j2ee. Bankruptcy Lawyer Miami
tte217.gmail.com's picture

Thanks for a nice share you

Thanks for a nice share you have given to us with such an large collection of information. Great work you have done by sharing them to all. simply superb. regards, http://www.superchinawholesale.com
luis.kop.gmail.com's picture

There is a SimpleHTTPServer

There is a SimpleHTTPServer with SSL that runs over HTTPS? I'd like to embed Axis2 with Security mechanism!
hnester134.gmail.com's picture

Good post overall. Enjoyed

Good post overall. Enjoyed reading it. Henry blog
dr.nathanial.dr.gmail.com's picture

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
byrmontanez.gmail.com's picture

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
tom.schavo.gmail.com's picture

Technology News

Echo JAVA is much better, thanks for the info Technology News
lcotonea's picture

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();  
fnordian's picture

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?
mrbaazi's picture

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.
austin1557.gmail.com's picture

web design new york

Web Designing has become the in thing today .There are hordes of web designers and web designing companies across the globes ready to flaunt thier designing skills innovations with latest techniques of designing. web design new york
ms.paul12.gmail.com's picture

Data Backup Chicago

Very well info present in your blog.. Thanks, www.aqueity.com/