axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chinth...@apache.org
Subject svn commit: r432858 - in /webservices/axis2/trunk/java/modules/kernel: conf/ src/org/apache/axis2/ src/org/apache/axis2/deployment/ src/org/apache/axis2/engine/ src/org/apache/axis2/transport/http/
Date Sat, 19 Aug 2006 18:51:31 GMT
Author: chinthaka
Date: Sat Aug 19 11:51:31 2006
New Revision: 432858

URL: http://svn.apache.org/viewvc?rev=432858&view=rev
Log:
Fix for Axis2-1023 (Yet to be fully tested)
- Now there are three switches for the user
enableRESTInAxis2MainServlet - this will decide whether main servlet serves for REST requests
as well. The side advantage here is that one can have the same endpoint for both REST and
SOAP requests
disableREST - once set to true, this will completely disable REST in both the servlets
disableSeparateEndpointForREST - as you might already know, we have a separate servlet to
handle REST requests (AxisRESTServlet). If this flag is set, that servlet will be disabled.

Using the above flags user can get different combinations to fit his requirement. By default
all the above params are set to false. 

- AxisSOAPServlet was not used anywhere. Removing that.

Removed:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisSOAPServlet.java
Modified:
    webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/axis2_default.xml
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisEngine.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisRESTServlet.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java

Modified: webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml?rev=432858&r1=432857&r2=432858&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml (original)
+++ webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml Sat Aug 19 11:51:31 2006
@@ -27,6 +27,19 @@
     <!--Set the flag to true if you want to enable transport level session mangment-->
     <parameter name="manageTransportSession" locked="false">false</parameter>
 
+    <!--Following two parameters will be used to handle REST in Axis2. The default settings
will make Axis2 to have two-->
+    <!--different endpoints, one for REST (AxisRESTServlet) one for SOAP message handling
(AxisServlet). But following-->
+    <!--parameters help to tweak the message handling of two main servlets. -->
+
+    <!-- If the enableRESTInAxis2MainServlet is true, then Axis2MainServlet will handle
both SOAP and REST messages -->
+    <parameter name="enableRESTInAxis2MainServlet" locked="true">false</parameter>
+
+    <!-- Following parameter will completely disable REST handling in both the servlets-->
+    <parameter name="disableREST" locked="true">false</parameter>
+
+    <!-- This will disable the separate servlet we have for REST handling. -->
+    <parameter name="disableSeparateEndpointForREST" locked="true">false</parameter>
+
     <!-- If you have a frontend host which exposes this webservice using a different public
URL  -->
     <!-- use this parameter to override autodetected url -->
     <!--<parameter name="httpFrontendHostUrl" locked="false">https://someotherhost/context</parameter>-->

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java?rev=432858&r1=432857&r2=432858&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/Constants.java Sat Aug
19 11:51:31 2006
@@ -228,6 +228,12 @@
         
         public static final String DRILL_DOWN_TO_ROOT_CAUSE_FOR_FAULT_REASON = "drillDownToRootCauseForFaultReason";
 
+        public static final String ENABLE_REST_IN_AXIS2_MAIN_SERVLET = "enableRESTInAxis2MainServlet";
+
+        public static final String DISABLE_REST = "disableREST";
+
+        public static final String DISABLE_SEPARATE_ENDPOINT_FOR_REST = "disableSeparateEndpointForREST";
+
         // this will contain the keys of all the properties that will be in the message context
         public static final String TRANSPORT_URL = "TransportURL";
 

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/axis2_default.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/axis2_default.xml?rev=432858&r1=432857&r2=432858&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/axis2_default.xml
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/axis2_default.xml
Sat Aug 19 11:51:31 2006
@@ -25,6 +25,19 @@
     <!--Set the flag to true if you want to enable transport level session mangment-->
     <parameter name="manageTransportSession" locked="false">false</parameter>
 
+    <!--Following two parameters will be used to handle REST in Axis2. The default settings
will make Axis2 to have two-->
+    <!--different endpoints, one for REST (AxisRESTServlet) one for SOAP message handling
(AxisServlet). But following-->
+    <!--parameters help to tweak the message handling of two main servlets. -->
+
+    <!-- If the enableRESTInAxis2MainServlet is true, then Axis2MainServlet will handle
both SOAP and REST messages -->
+    <parameter name="enableRESTInAxis2MainServlet" locked="true">true</parameter>
+
+    <!-- Following parameter will completely disable REST handling in both the servlets-->
+    <parameter name="disableREST" locked="true">false</parameter>
+
+    <!-- This will disable the separate servlet we have for REST handling. -->
+    <parameter name="disableSeparateEndpointForREST" locked="true">false</parameter>
+
 
 
     <!-- ================================================= -->

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisEngine.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisEngine.java?rev=432858&r1=432857&r2=432858&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisEngine.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/AxisEngine.java
Sat Aug 19 11:51:31 2006
@@ -419,7 +419,7 @@
             sendStacktraceDetailsWithFaults = JavaUtils.isTrue(flagFromContext);
         }else{
             Parameter param = context.getParameter(Constants.Configuration.SEND_STACKTRACE_DETAILS_WITH_FAULTS);
-            sendStacktraceDetailsWithFaults = JavaUtils.isTrue(param);    
+            sendStacktraceDetailsWithFaults = JavaUtils.isTrue(param.getValue());    
         }
 
         Object faultDetail = context.getProperty(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME);

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisRESTServlet.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisRESTServlet.java?rev=432858&r1=432857&r2=432858&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisRESTServlet.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisRESTServlet.java
Sat Aug 19 11:51:31 2006
@@ -34,42 +34,46 @@
  */
 public class AxisRESTServlet extends AxisServlet {
 
-    private static final Log log = LogFactory.getLog(AxisSOAPServlet.class);
+    private static final Log log = LogFactory.getLog(AxisRESTServlet.class);
 
     protected void doGet(HttpServletRequest req,
                          HttpServletResponse resp) throws ServletException, IOException {
-        MessageContext messageContext = null;
-        try {
-            messageContext = createMessageContext(req, resp);
-            new RESTUtil(configContext).processGetRequest(messageContext,
-                    req,
-                    resp);
-        } catch (Exception e) {
-            log.error(e);
-            if (messageContext != null) {
-                resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-                handleFault(messageContext, resp.getOutputStream(), new AxisFault(e));
-            } else {
-                throw new ServletException(e);
+        if (!disableREST && !disableSeperateEndpointForREST) {
+            MessageContext messageContext = null;
+            try {
+                messageContext = createMessageContext(req, resp);
+                new RESTUtil(configContext).processGetRequest(messageContext,
+                        req,
+                        resp);
+            } catch (Exception e) {
+                log.error(e);
+                if (messageContext != null) {
+                    resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+                    handleFault(messageContext, resp.getOutputStream(), new AxisFault(e));
+                } else {
+                    throw new ServletException(e);
+                }
             }
         }
     }
 
     protected void doPost(HttpServletRequest req, HttpServletResponse resp)
             throws ServletException, IOException {
-        MessageContext messageContext = null;
-        try {
-            messageContext = createMessageContext(req, resp);
-            new RESTUtil(configContext).processPostRequest(messageContext,
-                    req,
-                    resp);
-        } catch (Exception e) {
-            log.error(e);
-            if (messageContext != null) {
-                resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-                handleFault(messageContext, resp.getOutputStream(), new AxisFault(e));
-            } else {
-                throw new ServletException(e);
+        if (!disableREST && !disableSeperateEndpointForREST) {
+            MessageContext messageContext = null;
+            try {
+                messageContext = createMessageContext(req, resp);
+                new RESTUtil(configContext).processPostRequest(messageContext,
+                        req,
+                        resp);
+            } catch (Exception e) {
+                log.error(e);
+                if (messageContext != null) {
+                    resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+                    handleFault(messageContext, resp.getOutputStream(), new AxisFault(e));
+                } else {
+                    throw new ServletException(e);
+                }
             }
         }
     }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java?rev=432858&r1=432857&r2=432858&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java
Sat Aug 19 11:51:31 2006
@@ -26,12 +26,15 @@
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.context.SessionContext;
 import org.apache.axis2.deployment.WarBasedAxisConfigurator;
+import org.apache.axis2.description.Parameter;
 import org.apache.axis2.description.TransportInDescription;
 import org.apache.axis2.description.TransportOutDescription;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.engine.AxisEngine;
 import org.apache.axis2.engine.ListenerManager;
 import org.apache.axis2.transport.TransportListener;
+import org.apache.axis2.transport.http.util.RESTUtil;
+import org.apache.axis2.util.JavaUtils;
 import org.apache.axis2.util.UUIDGenerator;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -66,12 +69,16 @@
     public static String SERVICE_PATH;
     private String contextPath;
 
+    protected boolean enableRESTInAxis2MainServlet = false;
+    protected boolean disableREST = false;
+    protected boolean disableSeperateEndpointForREST = false;
+    private static final String LIST_SERVICES_SUFIX = "/services/listServices";
+
 
     protected MessageContext
-            createAndSetInitialParamsToMsgCtxt(MessageContext msgContext,
-                                               HttpServletResponse resp,
+            createAndSetInitialParamsToMsgCtxt(HttpServletResponse resp,
                                                HttpServletRequest req) throws AxisFault {
-        msgContext = new MessageContext();
+        MessageContext msgContext = new MessageContext();
         if (axisConfiguration.isManageTransportSession()) {
             // We need to create this only if transport session is enabled.
             Object sessionContext = getSessionContext(req);
@@ -84,11 +91,11 @@
         msgContext.setTransportOut(axisConfiguration.getTransportOut(new QName(Constants.TRANSPORT_HTTP)));
 
         msgContext.setProperty(Constants.OUT_TRANSPORT_INFO,
-                               new ServletBasedOutTransportInfo(resp));
+                new ServletBasedOutTransportInfo(resp));
         msgContext.setProperty(MessageContext.REMOTE_ADDR, req.getRemoteAddr());
         msgContext.setFrom(new EndpointReference(req.getRemoteAddr()));
         msgContext.setProperty(MessageContext.TRANSPORT_HEADERS,
-                               getTransportHeaders(req));
+                getTransportHeaders(req));
         msgContext.setProperty(SESSION_ID, req.getSession().getId());
         msgContext.setProperty(Constants.Configuration.TRANSPORT_IN_URL, req.getRequestURL().toString());
         msgContext.setIncomingTransportName(Constants.TRANSPORT_HTTP);
@@ -100,7 +107,7 @@
 
     public void destroy() {
         super.destroy();
-        //stoping listern manager
+        //stoping listner manager
         try {
             configContext.getListenerManager().stop();
         } catch (AxisFault axisFault) {
@@ -117,11 +124,35 @@
 
     protected void doGet(HttpServletRequest req,
                          HttpServletResponse resp) throws ServletException, IOException {
-        try {
-            agent.handle(req, resp);
-        } catch (Exception e) {
-            throw new ServletException(e);
+        // this method is also used to serve for the listServices request.
+
+        String requestURI = req.getRequestURI();
+        System.out.println("requestURI = " + requestURI);
+        if (requestURI.endsWith(LIST_SERVICES_SUFIX)) {
+            try {
+                agent.handle(req, resp);
+            } catch (Exception e) {
+                throw new ServletException(e);
+            }
+        } else if (!disableREST && enableRESTInAxis2MainServlet) { // if the main
servlet should handle REST also
+            MessageContext messageContext = null;
+            try {
+                messageContext = createMessageContext(req, resp);
+                new RESTUtil(configContext).processGetRequest(messageContext,
+                        req,
+                        resp);
+            } catch (Exception e) {
+                log.error(e);
+                if (messageContext != null) {
+                    resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+                    handleFault(messageContext, resp.getOutputStream(), new AxisFault(e));
+                } else {
+                    throw new ServletException(e);
+                }
+            }
         }
+
+
     }
 
     /**
@@ -134,62 +165,84 @@
      */
     protected void doPost(HttpServletRequest req, HttpServletResponse res)
             throws ServletException, IOException {
-        MessageContext msgContext = null;
-        OutputStream out = null;
 
-        try {
+        MessageContext msgContext;
+        OutputStream out = res.getOutputStream();
+
+        String contentType = req.getContentType();
+
+        if (!disableREST && enableRESTInAxis2MainServlet && isRESTContentType(contentType))
{
+            msgContext = createMessageContext(req, res);
+            try {
+                new RESTUtil(configContext).processPostRequest(msgContext,
+                        req,
+                        res);
+            } catch (Exception e) {
+                log.error(e);
+                if (msgContext != null) {
+                    res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+                    handleFault(msgContext, out, new AxisFault(e));
+                } else {
+                    throw new ServletException(e);
+                }
+            }
+        } else {
+            msgContext = createAndSetInitialParamsToMsgCtxt(res, req);
+
+            try {
 //            Object sessionContext = getSessionContext(req);
 
-            msgContext = createAndSetInitialParamsToMsgCtxt(msgContext, res, req);
+                msgContext = createAndSetInitialParamsToMsgCtxt(res, req);
 
-            // adding ServletContext into msgContext;
-            out = res.getOutputStream();
-            HTTPTransportUtils.processHTTPPostRequest(msgContext, req.getInputStream(), out,
-                                                      req.getContentType(), req.getHeader(HTTPConstants.HEADER_SOAP_ACTION),
-                                                      req.getRequestURL().toString());
+                // adding ServletContext into msgContext;
+                out = res.getOutputStream();
+                HTTPTransportUtils.processHTTPPostRequest(msgContext, req.getInputStream(),
out,
+                        req.getContentType(), req.getHeader(HTTPConstants.HEADER_SOAP_ACTION),
+                        req.getRequestURL().toString());
 
-            Object contextWritten =
-                    msgContext.getOperationContext().getProperty(Constants.RESPONSE_WRITTEN);
+                Object contextWritten =
+                        msgContext.getOperationContext().getProperty(Constants.RESPONSE_WRITTEN);
 
-            res.setContentType("text/xml; charset="
-                               + msgContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING));
+                res.setContentType("text/xml; charset="
+                        + msgContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING));
 
-            if ((contextWritten == null) || !Constants.VALUE_TRUE.equals(contextWritten))
{
-                res.setStatus(HttpServletResponse.SC_ACCEPTED);
-            }
-        } catch (AxisFault e) {
-            log.debug(e);
-            if (msgContext != null) {
-                try {
-                    // If the fault is not going along the back channel we should be 202ing
-                    if (AddressingHelper.isFaultRedirected(msgContext)) {
-                        res.setStatus(HttpServletResponse.SC_ACCEPTED);
-                    } else {
-                        res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+                if ((contextWritten == null) || !Constants.VALUE_TRUE.equals(contextWritten))
{
+                    res.setStatus(HttpServletResponse.SC_ACCEPTED);
+                }
+            } catch (AxisFault e) {
+                log.debug(e);
+                if (msgContext != null) {
+                    try {
+                        // If the fault is not going along the back channel we should be
202ing
+                        if (AddressingHelper.isFaultRedirected(msgContext)) {
+                            res.setStatus(HttpServletResponse.SC_ACCEPTED);
+                        } else {
+                            res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+                        }
+                        handleFault(msgContext, out, e);
+                    } catch (AxisFault e2) {
+                        log.info(e2);
                     }
-                    handleFault(msgContext, out, e);
-                } catch (AxisFault e2) {
-                    log.info(e2);
+                } else {
+                    throw new ServletException(e);
                 }
-            } else {
-                throw new ServletException(e);
-            }
-        } catch (Throwable t) {
-            log.error(t);
-            if (msgContext != null) {
-                try {
-                    // If the fault is not going along the back channel we should be 202ing
-                    if (AddressingHelper.isFaultRedirected(msgContext)) {
-                        res.setStatus(HttpServletResponse.SC_ACCEPTED);
-                    } else {
-                        res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+            } catch (Throwable t) {
+                log.error(t);
+                if (msgContext != null) {
+                    try {
+                        // If the fault is not going along the back channel we should be
202ing
+                        if (AddressingHelper.isFaultRedirected(msgContext)) {
+                            res.setStatus(HttpServletResponse.SC_ACCEPTED);
+                        } else {
+                            res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+                        }
+                        handleFault(msgContext, out, new AxisFault(t.toString(), t));
+                    } catch (AxisFault e2) {
+                        log.info(e2);
                     }
-                    handleFault(msgContext, out, new AxisFault(t.toString(), t));
-                } catch (AxisFault e2) {
-                    log.info(e2);
+                } else {
+                    throw new ServletException(t);
                 }
-            } else {
-                throw new ServletException(t);
             }
         }
     }
@@ -226,6 +279,25 @@
             ListenerManager.defaultConfigurationContext = configContext;
             agent = new ListingAgent(configContext);
             SERVICE_PATH = configContext.getServicePath();
+
+            // do we need to enable REST in the main servlet so that it handles both REST
and SOAP messages
+            Parameter parameter = axisConfiguration.getParameter(Constants.Configuration.ENABLE_REST_IN_AXIS2_MAIN_SERVLET);
+            if (parameter != null) {
+                enableRESTInAxis2MainServlet = !JavaUtils.isFalseExplicitly(parameter.getValue());
+            }
+
+            // do we need to completely disable REST support
+            parameter = axisConfiguration.getParameter(Constants.Configuration.DISABLE_REST);
+            if (parameter != null) {
+                disableREST = !JavaUtils.isFalseExplicitly(parameter.getValue());
+            }
+
+            // Do we need to have a separate endpoint for REST
+            parameter = axisConfiguration.getParameter(Constants.Configuration.DISABLE_SEPARATE_ENDPOINT_FOR_REST);
+            if (parameter != null) {
+                disableREST = !JavaUtils.isFalseExplicitly(parameter.getValue());
+            }
+
         } catch (Exception e) {
             throw new ServletException(e);
         }
@@ -274,7 +346,7 @@
         if (sessionContext == null) {
             sessionContext = new SessionContext(null);
             httpServletRequest.getSession().setAttribute(Constants.SESSION_CONTEXT_PROPERTY,
-                                                         sessionContext);
+                    sessionContext);
         }
         return sessionContext;
     }
@@ -322,7 +394,7 @@
             }
         }
         return new EndpointReference("http://" + ip + ":" + port + '/' +
-                                     contextPath + "/" + SERVICE_PATH + "/" + serviceName);
+                contextPath + "/" + SERVICE_PATH + "/" + serviceName);
     }
 
     protected MessageContext createMessageContext(HttpServletRequest req,
@@ -353,7 +425,7 @@
         msgContext.setFrom(new EndpointReference(req.getRemoteAddr()));
         msgContext.setProperty(MessageContext.REMOTE_ADDR, req.getRemoteAddr());
         msgContext.setProperty(Constants.OUT_TRANSPORT_INFO,
-                               new ServletBasedOutTransportInfo(resp));
+                new ServletBasedOutTransportInfo(resp));
 //        msgContext.setProperty(MessageContext.TRANSPORT_OUT, resp.getOutputStream());
 
         // set the transport Headers
@@ -372,5 +444,19 @@
             headerMap.put(field, request.getAttribute(field));
         }
         return headerMap;
+    }
+
+    /**
+     * Lets only handle
+     * - text/xml
+     * - application/x-www-form-urlencoded
+     * as REST content types in this servlet.
+     *
+     * @param contentType
+     */
+    private boolean isRESTContentType(String contentType) {
+        return (contentType.indexOf(HTTPConstants.MEDIA_TYPE_TEXT_XML) > -1) ||
+                (contentType.indexOf(HTTPConstants.MEDIA_TYPE_X_WWW_FORM) > -1);
+
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org


Mime
View raw message