Q: How do I Embed SimpleHTTPServer in My Application and Deploy a POJO?
|
Date: Tue, 9th May, 2006
Level:
Reads: 13792 Comments: 15 |
Login or register to post comments |
|
|
|
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
Bookmark/Search this post with:
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
NICE
Re:
thanks giving
thanks for sharing such nicely written post, enjoyed reading it.
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
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
There is a SimpleHTTPServer
There is a SimpleHTTPServer with SSL that runs over HTTPS?
I'd like to embed Axis2 with Security mechanism!
Good post overall. Enjoyed
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
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
Technology News
Echo JAVA is much better, thanks for the info
Technology News
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?
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.
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