Hi all,

As stated in Testing Axis2 Servlet, with the aid of Jetyy Servlet container, i believe following SimpleJettyHTTPServer would do the things perfectly. It needs an additional jar, org.mortbay.jetty.jar.

Thanks

Saminda

Saminda Abeyruwan wrote:

Saminda Abeyruwan wrote:

Hi all,

I have implemented simple axis server (SimpleJettyHTTPServer) based on jetty wrt JIRA issue 121. I'm seding this file for your review. You need org.mortbay.jetty.jar to compile the code. It can be found from,

http://64.233.161.104/custom?q=cache:pyJ8JRJwMegJ:jetty.mortbay.org/jetty/download.html+jars&hl=en&ie=UTF-8

Please download version Jetty-5.X.X.

Thanks

Saminda


------------------------------------------------------------------------

package org.apache.axis2.transport.http;

import org.apache.axis2.transport.TransportListener;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.description.TransportInDescription;
import org.apache.axis2.description.Parameter;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.mortbay.http.HttpServer;
import org.mortbay.http.SocketListener;
import org.mortbay.http.HttpContext;
import org.mortbay.http.handler.ResourceHandler;
import org.mortbay.jetty.servlet.ServletHandler;

import java.io.File;

/**
* Created by IntelliJ IDEA.
* User: saminda
* Date: Aug 6, 2005
* Time: 11:50:00 AM
* To change this template use File | Settings | File Templates.
*/
public class SimpleJettyHTTPServer extends TransportListener {

   protected Log log = LogFactory.getLog(getClass());


   HttpServer server = new HttpServer();


   SocketListener listener = new SocketListener();


   HttpContext context = new HttpContext();

   // Create a servlet container
   ServletHandler servlets = new ServletHandler();

   ConfigurationContext configurationContext;

   public SimpleJettyHTTPServer(String dir, int port) {
       // Create a context
       context.setContextPath("/axis2/*");
       this.setPort(port);
       this.setResourceBase(dir);

       server.addContext(context);


       context.addHandler(servlets);

       //mapping servlets
       servlets.addServlet(
               "AxisServlet", "/servlet/AxisServlet",
               "org.apache.axis2.transport.http.AxisServlet");
       servlets.addServlet(
               "AxisServlet", "*.jws",
               "org.apache.axis2.transport.http.AxisServlet");
       servlets.addServlet(
               "AxisServlet", "/listServices",
               "org.apache.axis2.transport.http.AxisServlet");
       servlets.addServlet(
               "AxisServlet", "/listService",
               "org.apache.axis2.transport.http.AxisServlet");
       servlets.addServlet(
               "AxisServlet", "/listModules",
               "org.apache.axis2.transport.http.AxisServlet");
       servlets.addServlet(
               "AxisServlet", "/globalModules",
               "org.apache.axis2.transport.http.AxisServlet");
       servlets.addServlet(
               "AxisServlet", "/listPhases",
               "org.apache.axis2.transport.http.AxisServlet");
       servlets.addServlet(
               "AxisServlet", "/engagingglobally",
               "org.apache.axis2.transport.http.AxisServlet");
       servlets.addServlet(
               "AxisServlet", "/engageToService",
               "org.apache.axis2.transport.http.AxisServlet");
       servlets.addServlet(
               "AxisServlet", "/adminloging",
               "org.apache.axis2.transport.http.AxisServlet");

       servlets.addServlet(
               "AxisServlet", "/viewGlobalHandlers",
               "org.apache.axis2.transport.http.AxisServlet");
       servlets.addServlet(
               "AxisServlet", "/selectService",
               "org.apache.axis2.transport.http.AxisServlet");
       servlets.addServlet(
               "AxisServlet", "/listoperation",
               "org.apache.axis2.transport.http.AxisServlet");
       servlets.addServlet(
               "AxisServlet", "/viewServiceHandlers",
               "org.apache.axis2.transport.http.AxisServlet");
       servlets.addServlet(
               "AxisServlet", "/listoperations",
               "org.apache.axis2.transport.http.AxisServlet");
       servlets.addServlet(
               "AxisServlet", "/services/*",
               "org.apache.axis2.transport.http.AxisServlet");
       servlets.addServlet(
               "AxisServlet", "/servicedit",
               "org.apache.axis2.transport.http.AxisServlet");

       servlets.addServlet(
               "AxisServlet", "/removeService",
               "org.apache.axis2.transport.http.AxisServlet");
       servlets.addServlet(
               "AxisServlet", "/editServicepara",
               "org.apache.axis2.transport.http.AxisServlet");
       servlets.addServlet(
               "AxisServlet", "/selectServiceParaEdit",
               "org.apache.axis2.transport.http.AxisServlet");
       context.addHandler(new ResourceHandler());
   }

   public void setPort(int port) {
       listener.setPort(port);
       server.addListener(listener);
   }


   public void setResourceBase(String dir) {
       context.setResourceBase(dir);
   }

   private void start0() throws Exception {
       server.start();
   }

   public void start() throws AxisFault {
       try {
           this.start0();

       } catch (Exception e) {
           throw new AxisFault(
                   "start00 SimpleJettyHTTPServer",
                   new Integer(
                           listener.getServerSocket()
                   .getLocalPort()).toString());
       }
   }

   public void init(
ConfigurationContext axisConf, TransportInDescription transprtIn)
           throws AxisFault {

       int port = 0;
       this.configurationContext = axisConf;
       Parameter param = transprtIn.getParameter(PARAM_PORT);
       if (param != null) {
           port = Integer.parseInt((String) param.getValue());
           this.setPort(port);
       }

   }


   public void stop() throws AxisFault {

   }
//
public EndpointReference replyToEPR(String serviceName) throws AxisFault {
       return new EndpointReference(
               "http://127.0.0.1:"; + (listener.getPort()) +
               "/axis/services/" + serviceName);
   }

   public static void main(String[] args) {

       if (args.length != 2) {
System.out.println("SimpleHTTPServer repositoryLocation port");
       }
       int port = 0;
       port = Integer.parseInt(args[1]);
       SimpleJettyHTTPServer receiver = new SimpleJettyHTTPServer(
               args[0], port);
       System.out.println(
               "starting SimpleHTTPServer in port "
               + args[1]
               + " using the repository "
               + new File(args[0]).getAbsolutePath());

       try {
           System.out.println(
                   "[Axis2] Using the Repository " +
                   new File(args[0]).getAbsolutePath());
           System.out.println(
"[Axis2] Starting the SimpleHTTPServer on port " + args[1]);
           receiver.start();
           System.out.println("[Axis2] SimpleHTTPServer started");

       } catch (AxisFault e) {
           e.printStackTrace();
       }
   }
}
Running code pls take as,

....
public static void main(String[] args) throws Exception {
       SimpleJettyHTTPServer sjas =
new SimpleJettyHTTPServer("/opt/jakarta-tomcat-5.0.28/webapps/axis2/", 8080);
       sjas.start();
   }
...

Saminda



Reply via email to