Submitted on May 8, 2006 - 19:01.
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;Echo.java
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();
}
}
package samples;
public class Echo {
public String echo(String in) {
return in;
}
}
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?