geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r496024 - in /geronimo/server/trunk/modules: geronimo-axis/src/test/java/org/apache/geronimo/axis/ geronimo-axis2/src/main/java/org/apache/geronimo/axis2/ geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/ geronimo-tomcat6/src/main/j...
Date Sun, 14 Jan 2007 02:59:41 GMT
Author: dims
Date: Sat Jan 13 18:59:40 2007
New Revision: 496024

URL: http://svn.apache.org/viewvc?view=rev&rev=496024
Log:
borrow some code from Axis2's transport package and get it to compile (needs a lot of work!)

Modified:
    geronimo/server/trunk/modules/geronimo-axis/src/test/java/org/apache/geronimo/axis/AxisRequest.java
    geronimo/server/trunk/modules/geronimo-axis/src/test/java/org/apache/geronimo/axis/AxisWebServiceContainerTest.java
    geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContainer.java
    geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyEJBWebServiceContext.java
    geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatEJBWebServiceContext.java
    geronimo/server/trunk/modules/geronimo-webservices/src/main/java/org/apache/geronimo/webservices/WebServiceContainer.java
    geronimo/server/trunk/modules/geronimo-webservices/src/main/java/org/apache/geronimo/webservices/WebServiceContainerInvoker.java

Modified: geronimo/server/trunk/modules/geronimo-axis/src/test/java/org/apache/geronimo/axis/AxisRequest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis/src/test/java/org/apache/geronimo/axis/AxisRequest.java?view=diff&rev=496024&r1=496023&r2=496024
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis/src/test/java/org/apache/geronimo/axis/AxisRequest.java
(original)
+++ geronimo/server/trunk/modules/geronimo-axis/src/test/java/org/apache/geronimo/axis/AxisRequest.java
Sat Jan 13 18:59:40 2007
@@ -32,6 +32,7 @@
     private URI uri;
     private Map headers;
     private Map attributes;
+    private String remoteAddress;
 
     /**
      * 
@@ -43,7 +44,8 @@
         int method,
         Map parameters,
         URI uri,
-        Map headers) {
+        Map headers,
+        String remoteAddress) {
         this.contentType = contentType;
         this.in = in;
         this.method = method;
@@ -51,6 +53,7 @@
         this.uri = uri;
         this.headers = headers;
         this.attributes = new HashMap();
+        this.remoteAddress = remoteAddress;
     }
 
     public int getContentLength() {
@@ -91,5 +94,9 @@
 
     public void setAttribute(String name, Object value){
         attributes.put(name, value);
+    }
+
+    public String getRemoteAddr() {
+
     }
 }

Modified: geronimo/server/trunk/modules/geronimo-axis/src/test/java/org/apache/geronimo/axis/AxisWebServiceContainerTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis/src/test/java/org/apache/geronimo/axis/AxisWebServiceContainerTest.java?view=diff&rev=496024&r1=496023&r2=496024
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis/src/test/java/org/apache/geronimo/axis/AxisWebServiceContainerTest.java
(original)
+++ geronimo/server/trunk/modules/geronimo-axis/src/test/java/org/apache/geronimo/axis/AxisWebServiceContainerTest.java
Sat Jan 13 18:59:40 2007
@@ -113,7 +113,8 @@
                     0,
                     new HashMap(),
                     location,
-                    new HashMap());
+                    new HashMap(),
+                    "127.0.0.1");
             
             ByteArrayOutputStream out = new ByteArrayOutputStream();
             AxisResponse res = new AxisResponse("text/xml; charset=utf-8", "127.0.0.1", null,
null, 8080, out);

Modified: geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContainer.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContainer.java?view=diff&rev=496024&r1=496023&r2=496024
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContainer.java
(original)
+++ geronimo/server/trunk/modules/geronimo-axis2/src/main/java/org/apache/geronimo/axis2/Axis2WebServiceContainer.java
Sat Jan 13 18:59:40 2007
@@ -17,41 +17,316 @@
 
 package org.apache.geronimo.axis2;
 
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.AddressingHelper;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.ConfigurationContextFactory;
 import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.OperationContext;
 import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.TransportInDescription;
+import org.apache.axis2.description.TransportOutDescription;
+import org.apache.axis2.engine.AxisEngine;
 import org.apache.axis2.rpc.receivers.RPCMessageReceiver;
-import org.apache.axis2.transport.http.SimpleHTTPServer;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.axis2.transport.http.HTTPTransportReceiver;
+import org.apache.axis2.transport.http.HTTPTransportUtils;
+import org.apache.axis2.transport.http.server.HttpUtils;
+import org.apache.axis2.transport.OutTransportInfo;
+import org.apache.axis2.util.UUIDGenerator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.geronimo.webservices.WebServiceContainer;
+import org.apache.ws.commons.schema.XmlSchema;
+
+import javax.xml.namespace.QName;
+import java.io.PrintWriter;
+import java.net.SocketException;
+import java.util.HashMap;
+import java.util.Map;
 
 
 public class Axis2WebServiceContainer implements WebServiceContainer {
 
+    private static final Log LOG = LogFactory.getLog(Axis2WebServiceContainer.class);
+
     public static final String REQUEST = Axis2WebServiceContainer.class.getName() + "@Request";
     public static final String RESPONSE = Axis2WebServiceContainer.class.getName() + "@Response";
 
     private transient final ClassLoader classLoader;
     private final String endpointClassName;
     private final PortInfo portInfo;
+    ConfigurationContext configurationContext = ConfigurationContextFactory.createEmptyConfigurationContext();
 
     public Axis2WebServiceContainer(PortInfo portInfo, String endpointClassName, ClassLoader
classLoader) {
         this.classLoader = classLoader;
         this.endpointClassName = endpointClassName;
         this.portInfo = portInfo;
+        try {
+            AxisService service = AxisService.createService(endpointClassName, configurationContext.getAxisConfiguration(),
RPCMessageReceiver.class);
+            configurationContext.getAxisConfiguration().addService(service);
+        } catch (AxisFault af) {
+            throw new RuntimeException(af);
+        }
     }
 
     public void getWsdl(Request request, Response response) throws Exception {
-        //TODO: Implement the logic
+        doService(request, response);
     }
 
-    public void invoke(Request req, Response res) throws Exception {
-        ConfigurationContext configContext = ConfigurationContextFactory.createEmptyConfigurationContext();
+    public void invoke(Request request, Response response) throws Exception {
+        doService(request, response);
+    }
+
+    protected void doService(final Request request, final Response response)
+            throws Exception {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Target URI: " + request.getURI());
+        }
+
+        MessageContext msgContext = new MessageContext();
+        msgContext.setIncomingTransportName(Constants.TRANSPORT_HTTP);
+        msgContext.setProperty(MessageContext.REMOTE_ADDR, request.getRemoteAddr());
+
+        try {
+            TransportOutDescription transportOut = this.configurationContext.getAxisConfiguration()
+                    .getTransportOut(new QName(Constants.TRANSPORT_HTTP));
+            TransportInDescription transportIn = this.configurationContext.getAxisConfiguration()
+                    .getTransportIn(new QName(Constants.TRANSPORT_HTTP));
+
+            msgContext.setConfigurationContext(this.configurationContext);
+
+            //TODO: Port this segment for session support.
+//            String sessionKey = (String) this.httpcontext.getAttribute(HTTPConstants.COOKIE_STRING);
+//            if (this.configurationContext.getAxisConfiguration().isManageTransportSession())
{
+//                SessionContext sessionContext = this.sessionManager.getSessionContext(sessionKey);
+//                msgContext.setSessionContext(sessionContext);
+//            }
+            msgContext.setTransportIn(transportIn);
+            msgContext.setTransportOut(transportOut);
+            msgContext.setServiceGroupContextId(UUIDGenerator.getUUID());
+            msgContext.setServerSide(true);
+
+//            // set the transport Headers
+//            HashMap headerMap = new HashMap();
+//            for (Iterator it = request.headerIterator(); it.hasNext();) {
+//                Header header = (Header) it.next();
+//                headerMap.put(header.getName(), header.getValue());
+//            }
+//            msgContext.setProperty(MessageContext.TRANSPORT_HEADERS, headerMap);
+//
+//            this.httpcontext.setAttribute(AxisParams.MESSAGE_CONTEXT, msgContext);
 
-        //TODO: Change the Message Reciever to JAXWSMessageReciever
-        AxisService service = AxisService.createService(endpointClassName, configContext.getAxisConfiguration(),
RPCMessageReceiver.class);
-        configContext.getAxisConfiguration().addService(service);
+            doService2(request, response, msgContext);
+        } catch (Throwable e) {
+            try {
+                AxisEngine engine = new AxisEngine(this.configurationContext);
+
+                msgContext.setProperty(MessageContext.TRANSPORT_OUT, response.getOutputStream());
+                msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, new Axis2TransportInfo(response));
+
+                MessageContext faultContext = engine.createFaultMessageContext(msgContext,
e);
+                // If the fault is not going along the back channel we should be 202ing
+                if (AddressingHelper.isFaultRedirected(msgContext)) {
+                    response.setStatusCode(202);
+                } else {
+                    response.setStatusCode(500);
+                }
+                engine.sendFault(faultContext);
+            } catch (Exception ex) {
+                if (AddressingHelper.isFaultRedirected(msgContext)) {
+                    response.setStatusCode(202);
+                } else {
+                    response.setStatusCode(500);
+                    String msg = ex.getMessage();
+                    if (msg == null || msg.trim().length() == 0) {
+                        msg = "Exception message unknown";
+                    }
+                    response.setHeader(HTTPConstants.HEADER_CONTENT_TYPE, "text/plain");
+                    PrintWriter pw = new PrintWriter(response.getOutputStream());
+                    pw.write(msg);
+                    pw.flush();
+                }
+            }
+        }
 
-        // TODO: Lot's more to be done here.
     }
+
+    public void doService2(
+            final Request request,
+            final Response response,
+            final MessageContext msgContext) throws Exception {
+
+        ConfigurationContext configurationContext = msgContext.getConfigurationContext();
+        final String servicePath = configurationContext.getServiceContextPath();
+        final String contextPath = (servicePath.startsWith("/") ? servicePath : "/" + servicePath)
+ "/";
+
+        String uri = request.getURI().toString();
+        String soapAction = request.getHeader(HTTPConstants.HEADER_SOAP_ACTION);
+
+        // TODO: Port this section
+//        // Adjust version and content chunking based on the config
+//        boolean chunked = false;
+//        TransportOutDescription transportOut = msgContext.getTransportOut();
+//        if (transportOut != null) {
+//            Parameter p = transportOut.getParameter(HTTPConstants.PROTOCOL_VERSION);
+//            if (p != null) {
+//                if (HTTPConstants.HEADER_PROTOCOL_10.equals(p.getValue())) {
+//                    ver = HttpVersion.HTTP_1_0;
+//                }
+//            }
+//            if (ver.greaterEquals(HttpVersion.HTTP_1_1)) {
+//                p = transportOut.getParameter(HTTPConstants.HEADER_TRANSFER_ENCODING);
+//                if (p != null) {
+//                    if (HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED.equals(p.getValue()))
{
+//                        chunked = true;
+//                    }
+//                }
+//            }
+//        }
+
+        if (request.getMethod() == Request.GET) {
+            if (!uri.startsWith(contextPath)) {
+                response.setStatusCode(301);
+                response.setHeader("Location", contextPath);
+                return;
+            }
+            if (uri.indexOf("?") < 0) {
+                if (!uri.endsWith(contextPath)) {
+                    String serviceName = uri.replaceAll(contextPath, "");
+                    if (serviceName.indexOf("/") < 0) {
+                        String res = HTTPTransportReceiver.printServiceHTML(serviceName,
configurationContext);
+                        PrintWriter pw = new PrintWriter(response.getOutputStream());
+                        pw.write(res);
+                        return;
+                    }
+                }
+            }
+            if (uri.endsWith("?wsdl2")) {
+                String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.length()
- 6);
+                HashMap services = configurationContext.getAxisConfiguration().getServices();
+                final AxisService service = (AxisService) services.get(serviceName);
+                if (service != null) {
+                    final String ip = HttpUtils.getIpAddress();
+                    service.printWSDL2(response.getOutputStream(), ip, servicePath);
+                    return;
+                }
+            }
+            if (uri.endsWith("?wsdl")) {
+                String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.length()
- 5);
+                HashMap services = configurationContext.getAxisConfiguration().getServices();
+                final AxisService service = (AxisService) services.get(serviceName);
+                if (service != null) {
+                    final String ip = HttpUtils.getIpAddress();
+                    service.printWSDL(response.getOutputStream(), ip, servicePath);
+                    return;
+                }
+            }
+            if (uri.endsWith("?xsd")) {
+                String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.length()
- 4);
+                HashMap services = configurationContext.getAxisConfiguration().getServices();
+                final AxisService service = (AxisService) services.get(serviceName);
+                if (service != null) {
+                    service.printSchema(response.getOutputStream());
+                    return;
+                }
+            }
+            //cater for named xsds - check for the xsd name
+            if (uri.indexOf("?xsd=") > 0) {
+                String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.lastIndexOf("?xsd="));
+                String schemaName = uri.substring(uri.lastIndexOf("=") + 1);
+
+                HashMap services = configurationContext.getAxisConfiguration().getServices();
+                AxisService service = (AxisService) services.get(serviceName);
+                if (service != null) {
+                    //run the population logic just to be sure
+                    service.populateSchemaMappings();
+                    //write out the correct schema
+                    Map schemaTable = service.getSchemaMappingTable();
+                    final XmlSchema schema = (XmlSchema) schemaTable.get(schemaName);
+                    //schema found - write it to the stream
+                    if (schema != null) {
+                        schema.write(response.getOutputStream());
+                        return;
+                    } else {
+                        // no schema available by that name  - send 404
+                        response.setStatusCode(404);
+                        return;
+                    }
+                }
+            }
+
+            msgContext.setProperty(MessageContext.TRANSPORT_OUT, response.getOutputStream());
+            msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, new Axis2TransportInfo(response));
+
+            // deal with GET request
+            boolean processed = HTTPTransportUtils.processHTTPGetRequest(
+                    msgContext,
+                    response.getOutputStream(),
+                    soapAction,
+                    uri,
+                    configurationContext,
+                    HTTPTransportReceiver.getGetRequestParameters(uri));
+
+            if (!processed) {
+                response.setStatusCode(200);
+                String s = HTTPTransportReceiver.getServicesHTML(configurationContext);
+                PrintWriter pw = new PrintWriter(response.getOutputStream());
+                pw.write(s);
+                pw.flush();
+            }
+
+        } else if (request.getMethod() == Request.POST) {
+            // deal with POST request
+
+            msgContext.setProperty(MessageContext.TRANSPORT_OUT, response.getOutputStream());
+            msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, response.getOutputStream());
+
+            String contenttype = request.getHeader(HTTPConstants.HEADER_CONTENT_TYPE);
+            HTTPTransportUtils.processHTTPPostRequest(
+                    msgContext,
+                    request.getInputStream(),
+                    response.getOutputStream(),
+                    contenttype,
+                    soapAction,
+                    uri);
+
+        } else {
+            throw new UnsupportedOperationException("[" + request.getMethod() + " ] method
not supported");
+        }
+
+        // Finalize response
+        OperationContext operationContext = msgContext.getOperationContext();
+        Object contextWritten = null;
+        Object isTwoChannel = null;
+        if (operationContext != null) {
+            contextWritten = operationContext.getProperty(Constants.RESPONSE_WRITTEN);
+            isTwoChannel = operationContext.getProperty(Constants.DIFFERENT_EPR);
+        }
+
+
+        if ((contextWritten != null) && Constants.VALUE_TRUE.equals(contextWritten))
{
+            if ((isTwoChannel != null) && Constants.VALUE_TRUE.equals(isTwoChannel))
{
+                response.setStatusCode(202);
+                return;
+            }
+            response.setStatusCode(202);
+        } else {
+            response.setStatusCode(202);
+        }
+    }
+
+    public class Axis2TransportInfo implements OutTransportInfo {
+        private Response response;
+
+        public Axis2TransportInfo(Response response) {
+            this.response = response;
+        }
+
+        public void setContentType(String contentType) {
+            response.setHeader(HTTPConstants.HEADER_CONTENT_TYPE, contentType);
+        }
+    }
+
 }

Modified: geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyEJBWebServiceContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyEJBWebServiceContext.java?view=diff&rev=496024&r1=496023&r2=496024
==============================================================================
--- geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyEJBWebServiceContext.java
(original)
+++ geronimo/server/trunk/modules/geronimo-jetty6/src/main/java/org/apache/geronimo/jetty6/JettyEJBWebServiceContext.java
Sat Jan 13 18:59:40 2007
@@ -259,6 +259,9 @@
             request.setAttribute(name, value);
         }
 
+        public String getRemoteAddr() {
+            return request.getRemoteAddr();
+        }
 
         private static final Map methods = new HashMap();
 

Modified: geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatEJBWebServiceContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatEJBWebServiceContext.java?view=diff&rev=496024&r1=496023&r2=496024
==============================================================================
--- geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatEJBWebServiceContext.java
(original)
+++ geronimo/server/trunk/modules/geronimo-tomcat6/src/main/java/org/apache/geronimo/tomcat/TomcatEJBWebServiceContext.java
Sat Jan 13 18:59:40 2007
@@ -227,6 +227,9 @@
             request.setAttribute(name, value);
         }
 
+        public String getRemoteAddr() {
+            return request.getRemoteAddr();
+        }
 
         private static final Map methods = new HashMap();
 

Modified: geronimo/server/trunk/modules/geronimo-webservices/src/main/java/org/apache/geronimo/webservices/WebServiceContainer.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-webservices/src/main/java/org/apache/geronimo/webservices/WebServiceContainer.java?view=diff&rev=496024&r1=496023&r2=496024
==============================================================================
--- geronimo/server/trunk/modules/geronimo-webservices/src/main/java/org/apache/geronimo/webservices/WebServiceContainer.java
(original)
+++ geronimo/server/trunk/modules/geronimo-webservices/src/main/java/org/apache/geronimo/webservices/WebServiceContainer.java
Sat Jan 13 18:59:40 2007
@@ -112,6 +112,8 @@
         Object getAttribute(String name);
 
         void setAttribute(String name, Object value);
+
+        java.lang.String getRemoteAddr();
     }
 
     public interface Response {

Modified: geronimo/server/trunk/modules/geronimo-webservices/src/main/java/org/apache/geronimo/webservices/WebServiceContainerInvoker.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-webservices/src/main/java/org/apache/geronimo/webservices/WebServiceContainerInvoker.java?view=diff&rev=496024&r1=496023&r2=496024
==============================================================================
--- geronimo/server/trunk/modules/geronimo-webservices/src/main/java/org/apache/geronimo/webservices/WebServiceContainerInvoker.java
(original)
+++ geronimo/server/trunk/modules/geronimo-webservices/src/main/java/org/apache/geronimo/webservices/WebServiceContainerInvoker.java
Sat Jan 13 18:59:40 2007
@@ -159,6 +159,10 @@
             request.setAttribute(s, o);
         }
 
+        public String getRemoteAddr() {
+            return request.getRemoteAddr();
+        }
+
     }
 
     private static class ResponseAdapter implements WebServiceContainer.Response {



Mime
View raw message