axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hemap...@apache.org
Subject svn commit: r193054 - in /webservices/axis/trunk/java/modules: core/src/org/apache/axis/ core/src/org/apache/axis/engine/ core/src/org/apache/axis/transport/http/ core/src/org/apache/axis/util/ samples/test/org/apache/axis/rest/
Date Thu, 23 Jun 2005 02:36:44 GMT
Author: hemapani
Date: Wed Jun 22 19:36:43 2005
New Revision: 193054

URL: http://svn.apache.org/viewcvs?rev=193054&view=rev
Log:
updates to do REST via GET

Added:
    webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportUtils.java
Modified:
    webservices/axis/trunk/java/modules/core/src/org/apache/axis/Constants.java
    webservices/axis/trunk/java/modules/core/src/org/apache/axis/engine/RequestURIBasedDispatcher.java
    webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/AxisServlet.java
    webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportReceiver.java
    webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/SimpleHTTPServer.java
    webservices/axis/trunk/java/modules/core/src/org/apache/axis/util/Utils.java
    webservices/axis/trunk/java/modules/samples/test/org/apache/axis/rest/HttpGetRESTBasedTest.java

Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/Constants.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis/Constants.java?rev=193054&r1=193053&r2=193054&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis/Constants.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/Constants.java Wed Jun 22
19:36:43 2005
@@ -91,6 +91,8 @@
     /**
      * Field LISTSERVICES
      */
+    public static final String REQUEST_URL_PREFIX = "/services";
+    
     public static final String LISTSERVICES = "listServices";
 
     public static final String LIST_SERVICE_FOR_MODULE_ENGAMNET = "listoperation";

Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/engine/RequestURIBasedDispatcher.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis/engine/RequestURIBasedDispatcher.java?rev=193054&r1=193053&r2=193054&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis/engine/RequestURIBasedDispatcher.java
(original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/engine/RequestURIBasedDispatcher.java
Wed Jun 22 19:36:43 2005
@@ -15,14 +15,14 @@
  */
 package org.apache.axis.engine;
 
+import javax.xml.namespace.QName;
+
 import org.apache.axis.addressing.EndpointReference;
-import org.apache.axis.context.ConfigurationContext;
 import org.apache.axis.context.MessageContext;
 import org.apache.axis.description.HandlerDescription;
 import org.apache.axis.description.OperationDescription;
 import org.apache.axis.description.ServiceDescription;
-
-import javax.xml.namespace.QName;
+import org.apache.axis.util.Utils;
 
 /**
  * Class Dispatcher
@@ -58,36 +58,21 @@
     /* (non-Javadoc)
      * @see org.apache.axis.engine.AbstractDispatcher#findService(org.apache.axis.context.MessageContext)
      */
-    public ServiceDescription findService(MessageContext messageContext)
-        throws AxisFault {
-        final String URI_ID_STRING = "/services";
-            EndpointReference toEPR = messageContext.getTo();
-            if (toEPR != null) {
-                String filePart = toEPR.getAddress();
-
-                int index = filePart.lastIndexOf(URI_ID_STRING);
-                String serviceStr = null;
-                if (-1 != index) {
-                    serviceStr =
-                        filePart.substring(index + URI_ID_STRING.length() + 1);
-
-                    ConfigurationContext engineContext =
-                        messageContext.getSystemContext();
-
-                    if ((index = serviceStr.indexOf('/')) > 0) {
-                        serviceName = new QName(serviceStr.substring(0, index));
-                        operatoinName =
-                            new QName(serviceStr.substring(index + 1));
-                    } else {
-                        serviceName = new QName(serviceStr);
-                    }
-
-                    AxisConfiguration registry =
-                        messageContext.getSystemContext().getAxisConfiguration();
-                    return registry.getService(serviceName);
-                }
+    public ServiceDescription findService(MessageContext messageContext) throws AxisFault
{
+        EndpointReference toEPR = messageContext.getTo();
+        if (toEPR != null) {
+            String filePart = toEPR.getAddress();
+            String[] values = Utils.parseRequestURLForServiceAndOperation(filePart);
+            if (values[1] != null) {
+                operatoinName = new QName(values[1]);
+            }
+            if (values[0] != null) {
+                serviceName = new QName(values[0]);
+                AxisConfiguration registry =
+                    messageContext.getSystemContext().getAxisConfiguration();
+                return registry.getService(serviceName);
             }
+        }
         return null;
-
     }
 }

Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/AxisServlet.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/AxisServlet.java?rev=193054&r1=193053&r2=193054&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/AxisServlet.java
(original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/AxisServlet.java
Wed Jun 22 19:36:43 2005
@@ -19,6 +19,7 @@
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.util.Enumeration;
+import java.util.HashMap;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
@@ -43,9 +44,7 @@
 import org.apache.axis.context.SessionContext;
 import org.apache.axis.engine.AxisEngine;
 import org.apache.axis.engine.AxisFault;
-import org.apache.axis.om.OMElement;
 import org.apache.axis.om.OMException;
-import org.apache.axis.om.OMNamespace;
 import org.apache.axis.om.impl.llom.builder.StAXBuilder;
 import org.apache.axis.om.impl.llom.builder.StAXOMBuilder;
 import org.apache.axis.soap.SOAPEnvelope;
@@ -64,7 +63,7 @@
 
     private ConfigurationContext configContext;
 
-    private ListingAgent lister ;
+    private ListingAgent lister;
 
     /**
      * Method init
@@ -99,36 +98,17 @@
         throws ServletException, IOException {
 
         try {
-            String operation =
-                httpServletRequest.getParameter(Constants.REST_WITH_GET.GET_PARAMETER_OPERATION);
-            if (operation != null) {
-                SOAPFactory soapFactory = new SOAP11Factory();
-                SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
-
-                OMNamespace omNs =
-                    soapFactory.createOMNamespace(
-                        Constants.REST_WITH_GET.GET_PARAMETER_URL,
-                        "rest");
-                OMElement opElement =
-                    soapFactory.createOMElement(
-                        Constants.REST_WITH_GET.GET_PARAMETER_OPERATION,
-                        omNs);
-
-                Enumeration enu = httpServletRequest.getParameterNames();
-                while (enu.hasMoreElements()) {
-                    String name = (String) enu.nextElement();
-                    if (!Constants.REST_WITH_GET.GET_PARAMETER_OPERATION.equals(name)) {
-                        String value = httpServletRequest.getParameter(name);
-                        OMElement omEle =
-                            soapFactory.createOMElement(
-                                Constants.REST_WITH_GET.GET_PARAMETER_OPERATION,
-                                omNs);
-                        omEle.setText(value);
-                        opElement.addChild(omEle);
-                    }
-                }
+            String filePart = httpServletRequest.getRequestURL().toString();
+            Enumeration enu = httpServletRequest.getParameterNames();
+            HashMap map = new HashMap();
+            while (enu.hasMoreElements()) {
+                String name = (String) enu.nextElement();
+                String value = httpServletRequest.getParameter(name);
+                map.put(name, value);
+            }
 
-                envelope.getBody().addChild(opElement);
+            SOAPEnvelope envelope = HTTPTransportUtils.createEnvelopeFromGetRequest(filePart,
map);
+            if (envelope != null) {
                 XMLStreamWriter wrtier =
                     XMLOutputFactory.newInstance().createXMLStreamWriter(System.out);
                 envelope.serialize(wrtier);
@@ -150,7 +130,7 @@
                             new QName(Constants.TRANSPORT_HTTP)),
                         configContext.getAxisConfiguration().getTransportOut(
                             new QName(Constants.TRANSPORT_HTTP)));
-                msgContext.setProperty(Constants.Configuration.DO_REST,Constants.VALUE_TRUE);
+                msgContext.setProperty(Constants.Configuration.DO_REST, Constants.VALUE_TRUE);
 
                 msgContext.setEnvelope(envelope);
                 processSOAPMessage(msgContext, httpServletRequest, httpServletResponse);
@@ -252,8 +232,7 @@
                 req.getContentType(),
                 soapActionString,
                 msgContext);
-            msgContext.setProperty(
-                MessageContext.TRANSPORT_OUT,res.getOutputStream());
+            msgContext.setProperty(MessageContext.TRANSPORT_OUT, res.getOutputStream());
             engine.receive(msgContext);
 
             Object contextWritten = msgContext.getProperty(Constants.RESPONSE_WRITTEN);

Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportReceiver.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportReceiver.java?rev=193054&r1=193053&r2=193054&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportReceiver.java
(original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportReceiver.java
Wed Jun 22 19:36:43 2005
@@ -108,31 +108,44 @@
         SOAPEnvelope soapEnvelope = null;
 
         InputStream inStream = (InputStream) msgContext.getProperty(MessageContext.TRANSPORT_IN);
-        msgContext.setProperty(MessageContext.TRANSPORT_IN,null);
+        msgContext.setProperty(MessageContext.TRANSPORT_IN, null);
         Reader in = new InputStreamReader(inStream);
 
         if (in != null) {
             boolean serverSide = msgContext.isServerSide();
             Map map = parseTheHeaders(in, serverSide);
+
+            msgContext.setWSAAction((String) map.get(HTTPConstants.HEADER_SOAP_ACTION));
+            Utils.configureMessageContextForHTTP(
+                (String) map.get(HTTPConstants.HEADER_CONTENT_TYPE),
+                msgContext.getWSAAction(),
+                msgContext);
+
+            String requestURI = (String) map.get(HTTPConstants.REQUEST_URI);
+            msgContext.setTo(new EndpointReference(AddressingConstants.WSA_TO, requestURI));
+
             if (HTTPConstants.RESPONSE_ACK_CODE_VAL.equals(map.get(HTTPConstants.RESPONSE_CODE)))
{
                 msgContext.setProperty(
                     MessageContext.TRANSPORT_SUCCEED,
                     HTTPConstants.RESPONSE_ACK_CODE_VAL);
                 return null;
-            }else if(HTTPConstants.HEADER_GET.equals(map.get(HTTPConstants.HTTP_REQ_TYPE)))
{
-                this.handleGETRequest((String)map.get(HTTPConstants.REQUEST_URI), 
-                    (OutputStream)map.get(MessageContext.TRANSPORT_OUT),
-                    msgContext.getSystemContext());
+            } else if (HTTPConstants.HEADER_GET.equals(map.get(HTTPConstants.HTTP_REQ_TYPE)))
{
+                SOAPEnvelope envelope =
+                    HTTPTransportUtils.createEnvelopeFromGetRequest(
+                        requestURI,
+                        getGetRequestParameters(requestURI));
+                if (envelope == null) {
+                    this.handleGETRequest(
+                        requestURI,
+                        (OutputStream) map.get(MessageContext.TRANSPORT_OUT),
+                        msgContext.getSystemContext());
                     return null;
-            }else{
-                msgContext.setWSAAction((String) map.get(HTTPConstants.HEADER_SOAP_ACTION));
-                Utils.configureMessageContextForHTTP(
-                    (String) map.get(HTTPConstants.HEADER_CONTENT_TYPE),
-                    msgContext.getWSAAction(),
-                    msgContext);
+                } else {
+                    msgContext.setProperty(Constants.Configuration.DO_REST, Constants.VALUE_TRUE);
+                    return envelope;
+                }
 
-                String requestURI = (String) map.get(HTTPConstants.REQUEST_URI);
-                msgContext.setTo(new EndpointReference(AddressingConstants.WSA_TO, requestURI));
+            } else {
                 //getServiceLookUp(requestURI)));
 
                 // TODO see is it a Service request e.g. WSDL, list ....
@@ -141,7 +154,8 @@
                     //Check for the REST behaviour, if you desire rest beahaviour
                     //put a <parameter name="doREST" value="true"/> at the server.xml/client.xml
file
                     Object doREST = msgContext.getProperty(Constants.Configuration.DO_REST);
-                    XMLStreamReader xmlreader = XMLInputFactory.newInstance().createXMLStreamReader(in);
+                    XMLStreamReader xmlreader =
+                        XMLInputFactory.newInstance().createXMLStreamReader(in);
                     StAXBuilder builder = null;
                     SOAPEnvelope envelope = null;
                     if (doREST != null && "true".equals(doREST)) {
@@ -158,13 +172,13 @@
                 } catch (Exception e) {
                     throw new AxisFault(e.getMessage(), e);
                 }
-            
+
             }
         } else {
             throw new AxisFault("Input reader not found");
         }
     }
-    
+
     /**
      * This is to be called when we are certain that the message being processed is a SOAP
message
      * @param msgContext
@@ -173,16 +187,21 @@
      * @return
      * @throws AxisFault
      */
-    public SOAPEnvelope checkForMessage(MessageContext msgContext, ConfigurationContext engineContext,
Map parsedHeaders) throws AxisFault {
-    	
+    public SOAPEnvelope checkForMessage(
+        MessageContext msgContext,
+        ConfigurationContext engineContext,
+        Map parsedHeaders)
+        throws AxisFault {
+
         SOAPEnvelope soapEnvelope = null;
         InputStream inStream = (InputStream) msgContext.getProperty(MessageContext.TRANSPORT_IN);
-        msgContext.setProperty(MessageContext.TRANSPORT_IN,null);
+        msgContext.setProperty(MessageContext.TRANSPORT_IN, null);
         Reader in = new InputStreamReader(inStream);
-        
-        
+
         if (in != null) {
-            if (HTTPConstants.RESPONSE_ACK_CODE_VAL.equals(parsedHeaders.get(HTTPConstants.RESPONSE_CODE)))
{
+            if (HTTPConstants
+                .RESPONSE_ACK_CODE_VAL
+                .equals(parsedHeaders.get(HTTPConstants.RESPONSE_CODE))) {
                 msgContext.setProperty(
                     MessageContext.TRANSPORT_SUCCEED,
                     HTTPConstants.RESPONSE_ACK_CODE_VAL);
@@ -260,17 +279,17 @@
             length = readLine(reader, buf);
             if (serverSide) {
                 if ((buf[0] == 'P') && (buf[1] == 'O') && (buf[2] == 'S')
&& (buf[3] == 'T')) {
-                	map.put(HTTPConstants.HTTP_REQ_TYPE, HTTPConstants.HEADER_POST);
+                    map.put(HTTPConstants.HTTP_REQ_TYPE, HTTPConstants.HEADER_POST);
                     index = 5;
 
                 } else if ((buf[0] == 'G') && (buf[1] == 'E') && (buf[2]
== 'T')) {
-                	map.put(HTTPConstants.HTTP_REQ_TYPE, HTTPConstants.HEADER_GET);
+                    map.put(HTTPConstants.HTTP_REQ_TYPE, HTTPConstants.HEADER_GET);
                     index = 4;
 
                 } else {
-                	throw new AxisFault("Unsupported HTTP request type: Only GET and POST is
supported");
-                }                    
-                
+                    throw new AxisFault("Unsupported HTTP request type: Only GET and POST
is supported");
+                }
+
                 value = readFirstLineArg(' ');
                 map.put(HTTPConstants.REQUEST_URI, value);
                 value = readFirstLineArg('\n');
@@ -278,14 +297,14 @@
             } else {
                 index = 0;
                 value = readFirstLineArg(' ');
-                if(value != null && value.indexOf("HTTP") >= 0){
+                if (value != null && value.indexOf("HTTP") >= 0) {
                     map.put(HTTPConstants.PROTOCOL_VERSION, value);
                     value = readFirstLineArg(' ');
                     map.put(HTTPConstants.RESPONSE_CODE, value);
-                }else{
+                } else {
                     map.put(HTTPConstants.RESPONSE_CODE, value);
                 }
-                
+
                 value = readFirstLineArg('\n');
                 map.put(HTTPConstants.RESPONSE_WORD, value);
             }
@@ -522,73 +541,120 @@
         }
     }
 
-    private void handleGETRequest(String reqUri, OutputStream out,ConfigurationContext configurationContext)
{
-        
-    try {
-        out.write(this.getServicesHTML(configurationContext).getBytes());
-        out.flush();
-        out.close();
-    } catch (IOException e) {
-        e.printStackTrace();
+    private void handleGETRequest(
+        String reqUri,
+        OutputStream out,
+        ConfigurationContext configurationContext) {
+
+        try {
+            out.write(this.getServicesHTML(configurationContext).getBytes());
+            out.flush();
+            out.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
     }
-}
-    
-    
-/**
- * Returns the HTML text for the list of services deployed
- * This can be delegated to another Class as well
- * where it will handle more options of GET messages :-?
- * @return
- */
-private String getServicesHTML(ConfigurationContext configurationContext) {
-    String temp = "";
-    Map services = configurationContext.getAxisConfiguration().getServices();
-    Hashtable erroneousServices = configurationContext.getAxisConfiguration().getFaulytServices();
-    boolean status = false;
-        
-    if(services!= null && !services.isEmpty()) {
-        status = true;
-        Collection serviceCollection = services.values();
-        for(Iterator it = serviceCollection.iterator(); it.hasNext();) {
-            Map operations;
-            Collection operationsList;
-            ServiceDescription axisService = (ServiceDescription) it.next();
-            operations = axisService.getOperations();
-            operationsList = operations.values();
-            temp += "<h2>" + "Deployed services" + "</h2>";
-            temp += "<h3>" + axisService.getName().getLocalPart() + "</h3>";
-            if(operationsList.size() > 0) {
-                temp += "Available operations <ul>";
-                for (Iterator iterator1 = operationsList.iterator(); iterator1.hasNext();)
{
-                    OperationDescription axisOperation = (OperationDescription) iterator1.next();
-                    temp += "<li>" + axisOperation.getName().getLocalPart() + "</li>";
+
+    /**
+     * Returns the HTML text for the list of services deployed
+     * This can be delegated to another Class as well
+     * where it will handle more options of GET messages :-?
+     * @return
+     */
+    private String getServicesHTML(ConfigurationContext configurationContext) {
+        String temp = "";
+        Map services = configurationContext.getAxisConfiguration().getServices();
+        Hashtable erroneousServices =
+            configurationContext.getAxisConfiguration().getFaulytServices();
+        boolean status = false;
+
+        if (services != null && !services.isEmpty()) {
+            status = true;
+            Collection serviceCollection = services.values();
+            for (Iterator it = serviceCollection.iterator(); it.hasNext();) {
+                Map operations;
+                Collection operationsList;
+                ServiceDescription axisService = (ServiceDescription) it.next();
+                operations = axisService.getOperations();
+                operationsList = operations.values();
+                temp += "<h2>" + "Deployed services" + "</h2>";
+                temp += "<h3>" + axisService.getName().getLocalPart() + "</h3>";
+                if (operationsList.size() > 0) {
+                    temp += "Available operations <ul>";
+                    for (Iterator iterator1 = operationsList.iterator(); iterator1.hasNext();)
{
+                        OperationDescription axisOperation =
+                            (OperationDescription) iterator1.next();
+                        temp += "<li>" + axisOperation.getName().getLocalPart() + "</li>";
+                    }
+                    temp += "</ul>";
+                } else {
+                    temp += "No operations speficied for this service";
                 }
-                temp += "</ul>";
-            } else {
-                temp += "No operations speficied for this service";
             }
         }
-    }
-        
-    if(erroneousServices != null && !erroneousServices.isEmpty()) {
-            
-       temp += "<hr><h2><font color=\"blue\">Faulty Services</font></h2>";
-       status = true;
-       Enumeration faultyservices = erroneousServices.keys();
-       while (faultyservices.hasMoreElements()) {
-           String faultyserviceName = (String) faultyservices.nextElement();
-           temp += "<h3><font color=\"blue\">" + faultyserviceName + "</font></h3>";
-       }
-    }
 
-    if(!status) {
+        if (erroneousServices != null && !erroneousServices.isEmpty()) {
+
+            temp += "<hr><h2><font color=\"blue\">Faulty Services</font></h2>";
+            status = true;
+            Enumeration faultyservices = erroneousServices.keys();
+            while (faultyservices.hasMoreElements()) {
+                String faultyserviceName = (String) faultyservices.nextElement();
+                temp += "<h3><font color=\"blue\">" + faultyserviceName + "</font></h3>";
+            }
+        }
+
+        if (!status) {
             temp = "<h2>There are no services deployed</h2>";
+        }
+
+        temp =
+            "<html><head><title>Axis2: Services</title></head>"
+                + "<body>"
+                + temp
+                + "</body></html>";
+
+        return temp;
+    }
+
+    private Map getGetRequestParameters(String requestURI) {
+        Map map = new HashMap();
+
+        char[] chars = requestURI.toCharArray();
+        final int NOT_BEGUN = 1500;
+        final int INSIDE_NAME = 1501;
+        final int INSIDE_VALUE = 1502;
+
+        int state = NOT_BEGUN;
+        StringBuffer name = new StringBuffer();
+        StringBuffer value = new StringBuffer();
+
+        for (int index = 0; index < chars.length; index++) {
+            if (state == NOT_BEGUN) {
+                if (chars[index] == '?') {
+                    state = INSIDE_NAME;
+                }
+            } else if (state == INSIDE_NAME) {
+                if (chars[index] == '=') {
+                    state = INSIDE_VALUE;
+                } else {
+                    name.append(chars[index]);
+                }
+            } else if (state == INSIDE_VALUE) {
+                if (chars[index] == ',') {
+                    state = INSIDE_NAME;
+                    map.put(name.toString(), value.toString());
+                    name.delete(0, name.length());
+                    value.delete(0, value.length());
+                } else {
+                    value.append(chars[index]);
+                }
+            }
+        }
+        if (name.length() + value.length() > 0) {
+            map.put(name.toString(), value.toString());
+        }
+        return map;
     }
-        
-    temp = "<html><head><title>Axis2: Services</title></head>"
+
-      "<body>" + temp + "</body></html>";
-        
-    return temp;
-}
 
 }

Added: webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportUtils.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportUtils.java?rev=193054&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportUtils.java
(added)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/HTTPTransportUtils.java
Wed Jun 22 19:36:43 2005
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *  Runtime state of the engine
+ */
+package org.apache.axis.transport.http;
+
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.axis.Constants;
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMNamespace;
+import org.apache.axis.om.impl.llom.OMNamespaceImpl;
+import org.apache.axis.soap.SOAPEnvelope;
+import org.apache.axis.soap.SOAPFactory;
+import org.apache.axis.soap.impl.llom.soap11.SOAP11Factory;
+import org.apache.axis.util.Utils;
+
+public class HTTPTransportUtils {
+    public static final SOAPEnvelope createEnvelopeFromGetRequest(String requestUrl, Map
map) {
+        String[] values = Utils.parseRequestURLForServiceAndOperation(requestUrl);
+
+        if (values[1] != null && values[0] != null) {
+            String operation = values[1];
+            SOAPFactory soapFactory = new SOAP11Factory();
+            SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
+
+            OMNamespace omNs = soapFactory.createOMNamespace(values[0], "services");
+            OMNamespace defualtNs = new OMNamespaceImpl("", null);
+
+            OMElement opElement = soapFactory.createOMElement(operation, omNs);
+
+            Iterator it = map.keySet().iterator();
+            while (it.hasNext()) {
+                String name = (String) it.next();
+                String value = (String) map.get(name);
+                OMElement omEle = soapFactory.createOMElement(name, defualtNs);
+                omEle.setText(value);
+                opElement.addChild(omEle);
+            }
+
+            envelope.getBody().addChild(opElement);
+            return envelope;
+        } else {
+            return null;
+        }
+    }
+}

Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/SimpleHTTPServer.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/SimpleHTTPServer.java?rev=193054&r1=193053&r2=193054&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/SimpleHTTPServer.java
(original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/transport/http/SimpleHTTPServer.java
Wed Jun 22 19:36:43 2005
@@ -193,6 +193,7 @@
                     }
                 } catch (Throwable e) {
                     log.error(e);
+                    e.printStackTrace();
                 } finally {
                     if (socket != null) {
                         this.socket.close();

Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis/util/Utils.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis/util/Utils.java?rev=193054&r1=193053&r2=193054&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis/util/Utils.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis/util/Utils.java Wed Jun 22
19:36:43 2005
@@ -37,8 +37,8 @@
 import org.apache.wsdl.WSDLService;
 
 public class Utils {
-    
-    public static void addHandler(Flow flow,Handler handler,String phaseName){
+
+    public static void addHandler(Flow flow, Handler handler, String phaseName) {
         HandlerDescription handlerDesc = new HandlerDescription();
         PhaseRule rule = new PhaseRule(phaseName);
         handlerDesc.setRules(rule);
@@ -47,38 +47,37 @@
         flow.addHandler(handlerDesc);
     }
 
-   
-//    public static void addPhasesToServiceFromFlow(
-//        ServiceContext serviceContext,
-//        String phaseName,
-//        Flow flow,
-//        int flowtype)
-//        throws AxisFault {
-//                ArrayList faultchain = new ArrayList();
-//                Phase p = new Phase(Constants.PHASE_SERVICE);
-//                faultchain.add(p);
-//                addHandlers(flow, p);
-//                serviceContext.setPhases(faultchain, flowtype);
-//    }
-
-//    public static void createExecutionChains(ServiceContext serviceContext) throws AxisFault
{
-//        ServiceDescription service = serviceContext.getServiceConfig();
-//        addPhasesToServiceFromFlow(
-//            serviceContext,
-//            Constants.PHASE_SERVICE,
-//            service.getInFlow(),
-//            AxisConfiguration.INFLOW);
-//        addPhasesToServiceFromFlow(
-//            serviceContext,
-//            Constants.PHASE_SERVICE,
-//            service.getOutFlow(),
-//            AxisConfiguration.OUTFLOW);
-//        addPhasesToServiceFromFlow(
-//            serviceContext,
-//            Constants.PHASE_SERVICE,
-//            service.getFaultInFlow(),
-//            AxisConfiguration.FAULT_IN_FLOW);
-//    }
+    //    public static void addPhasesToServiceFromFlow(
+    //        ServiceContext serviceContext,
+    //        String phaseName,
+    //        Flow flow,
+    //        int flowtype)
+    //        throws AxisFault {
+    //                ArrayList faultchain = new ArrayList();
+    //                Phase p = new Phase(Constants.PHASE_SERVICE);
+    //                faultchain.add(p);
+    //                addHandlers(flow, p);
+    //                serviceContext.setPhases(faultchain, flowtype);
+    //    }
+
+    //    public static void createExecutionChains(ServiceContext serviceContext) throws
AxisFault {
+    //        ServiceDescription service = serviceContext.getServiceConfig();
+    //        addPhasesToServiceFromFlow(
+    //            serviceContext,
+    //            Constants.PHASE_SERVICE,
+    //            service.getInFlow(),
+    //            AxisConfiguration.INFLOW);
+    //        addPhasesToServiceFromFlow(
+    //            serviceContext,
+    //            Constants.PHASE_SERVICE,
+    //            service.getOutFlow(),
+    //            AxisConfiguration.OUTFLOW);
+    //        addPhasesToServiceFromFlow(
+    //            serviceContext,
+    //            Constants.PHASE_SERVICE,
+    //            service.getFaultInFlow(),
+    //            AxisConfiguration.FAULT_IN_FLOW);
+    //    }
 
     public static ServiceDescription createSimpleService(
         QName serviceName,
@@ -88,7 +87,7 @@
         ServiceDescription service = new ServiceDescription(serviceName);
         service.setClassLoader(Thread.currentThread().getContextClassLoader());
         service.addParameter(new ParameterImpl(AbstractMessageReceiver.SERVICE_CLASS, className));
-        
+
         OperationDescription axisOp = new OperationDescription(opName);
         axisOp.setMessageReciever(messageReceiver);
         axisOp.setStyle(WSDLService.STYLE_RPC);
@@ -96,14 +95,14 @@
         return service;
     }
 
-//    public static ServiceContext createServiceContext(
-//        ServiceDescription service,
-//        ConfigurationContext engineContext)
-//        throws AxisFault {
-//        ServiceContext serviceContext = new ServiceContext(service, engineContext);
-//        createExecutionChains(serviceContext);
-//        return serviceContext;
-//    }
+    //    public static ServiceContext createServiceContext(
+    //        ServiceDescription service,
+    //        ConfigurationContext engineContext)
+    //        throws AxisFault {
+    //        ServiceContext serviceContext = new ServiceContext(service, engineContext);
+    //        createExecutionChains(serviceContext);
+    //        return serviceContext;
+    //    }
 
     public static ServiceDescription createSimpleService(
         QName serviceName,
@@ -116,44 +115,78 @@
             opName);
     }
 
-//    public static void addHandlers(Flow flow, Phase phase) throws AxisFault {
-//        if (flow != null) {
-//            int handlerCount = flow.getHandlerCount();
-//            for (int i = 0; i < handlerCount; i++) {
-//                phase.addHandler(flow.getHandler(i).getHandler());
-//            }
-//        }
-//    }
-    public static void resolvePhases(AxisConfiguration axisconfig,ServiceDescription serviceDesc)
throws AxisFault, PhaseException{
-        PhaseResolver pr = new PhaseResolver(axisconfig,serviceDesc);
+    //    public static void addHandlers(Flow flow, Phase phase) throws AxisFault {
+    //        if (flow != null) {
+    //            int handlerCount = flow.getHandlerCount();
+    //            for (int i = 0; i < handlerCount; i++) {
+    //                phase.addHandler(flow.getHandler(i).getHandler());
+    //            }
+    //        }
+    //    }
+    public static void resolvePhases(AxisConfiguration axisconfig, ServiceDescription serviceDesc)
+        throws AxisFault, PhaseException {
+        PhaseResolver pr = new PhaseResolver(axisconfig, serviceDesc);
         pr.buildchains();
     }
-    
-    public static String getParameterValue(Parameter param){
-        if(param == null){
+
+    public static String getParameterValue(Parameter param) {
+        if (param == null) {
             return null;
-        }else{
-            return (String)param.getValue();
+        } else {
+            return (String) param.getValue();
         }
     }
-    
-    public static void configureMessageContextForHTTP(String contextType,String soapAction,
MessageContext msgCtx) throws AxisFault{
-        if(Constants.SOAP.MTOM_CONTENT_TYPE.equals(contextType)){
-            if(Constants.VALUE_TRUE.equals(msgCtx.getProperty(Constants.Configuration.ENABLE_MTOM))){
-                msgCtx.setProperty(Constants.Configuration.DO_MTOM,Constants.VALUE_TRUE);
-            }else{
+
+    public static void configureMessageContextForHTTP(
+        String contextType,
+        String soapAction,
+        MessageContext msgCtx)
+        throws AxisFault {
+        if (Constants.SOAP.MTOM_CONTENT_TYPE.equals(contextType)) {
+            if (Constants
+                .VALUE_TRUE
+                .equals(msgCtx.getProperty(Constants.Configuration.ENABLE_MTOM))) {
+                msgCtx.setProperty(Constants.Configuration.DO_MTOM, Constants.VALUE_TRUE);
+            } else {
                 throw new AxisFault("MTOTM Not supported");
             }
-        }else  if(Constants.SOAP.SOAP_12_CONTENT_TYPE.equals(contextType)){
+        } else if (Constants.SOAP.SOAP_12_CONTENT_TYPE.equals(contextType)) {
             //TODO what to do with 1.2 for REST
-        }else  if(contextType != null && contextType.indexOf(Constants.SOAP.SOAP_11_CONTENT_TYPE)
> -1){
-            if((soapAction == null || soapAction.length() == 0) 
-            && Constants.VALUE_TRUE.equals(msgCtx.getProperty(Constants.Configuration.ENABLE_REST))){
-                msgCtx.setProperty(Constants.Configuration.DO_REST,Constants.VALUE_TRUE);
+        } else if (
+            contextType != null && contextType.indexOf(Constants.SOAP.SOAP_11_CONTENT_TYPE)
> -1) {
+            if ((soapAction == null || soapAction.length() == 0)
+                && Constants.VALUE_TRUE.equals(
+                    msgCtx.getProperty(Constants.Configuration.ENABLE_REST))) {
+                msgCtx.setProperty(Constants.Configuration.DO_REST, Constants.VALUE_TRUE);
             }
         }
-    
+
     }
-    
-    
+
+    public static String[] parseRequestURLForServiceAndOperation(String filePart) {
+        String[] values = new String[2];
+
+        int index = filePart.lastIndexOf(Constants.REQUEST_URL_PREFIX);
+        String serviceStr = null;
+        if (-1 != index) {
+            serviceStr = filePart.substring(index + Constants.REQUEST_URL_PREFIX.length()
+ 1);
+            if ((index = serviceStr.indexOf('/')) > 0) {
+
+                values[0] = serviceStr.substring(0, index);
+                int lastIndex = serviceStr.indexOf('?');
+                if(lastIndex >= 0){
+                    values[1] = serviceStr.substring(index + 1,lastIndex);
+                }else{
+                    values[1] = serviceStr.substring(index + 1);
+                }
+                
+                
+                
+            } else {
+                values[0] = serviceStr;
+            }
+        }
+        return values;
+    }
+
 }

Modified: webservices/axis/trunk/java/modules/samples/test/org/apache/axis/rest/HttpGetRESTBasedTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/test/org/apache/axis/rest/HttpGetRESTBasedTest.java?rev=193054&r1=193053&r2=193054&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/samples/test/org/apache/axis/rest/HttpGetRESTBasedTest.java
(original)
+++ webservices/axis/trunk/java/modules/samples/test/org/apache/axis/rest/HttpGetRESTBasedTest.java
Wed Jun 22 19:36:43 2005
@@ -23,11 +23,19 @@
 import java.net.HttpURLConnection;
 import java.net.URL;
 
+import javax.xml.namespace.QName;
+
 import junit.framework.TestCase;
 
+import org.apache.axis.description.ServiceDescription;
+import org.apache.axis.engine.Echo;
 import org.apache.axis.integration.UtilServer;
+import org.apache.axis.util.Utils;
 
 public class HttpGetRESTBasedTest extends TestCase {
+    private QName serviceName = new QName("EchoXMLService");
+    private QName operationName = new QName("echoOMElement");
+
 
     public HttpGetRESTBasedTest() {
         super(HttpGetRESTBasedTest.class.getName());
@@ -38,29 +46,33 @@
     }
 
     protected void setUp() throws Exception {
- //       UtilServer.start();
+       UtilServer.start();
+       
+       ServiceDescription service =
+                       Utils.createSimpleService(serviceName,Echo.class.getName(),operationName);
+               UtilServer.deployService(service);
 
     }
 
     protected void tearDown() throws Exception {
-
- //       UtilServer.stop();
+        UtilServer.unDeployService(serviceName);
+       UtilServer.stop();
     }
 
     public void testEchoXMLSync() throws Exception {
         //TODO support the GET with the Simple Axis Server and enable this test case
-//        URL wsdlrequestUrl =
-//            new URL("http://127.0.0.1:8080/axis2/services/Version/getVersion?operation=getVersion");
-//
-//        HttpURLConnection connection = (HttpURLConnection) wsdlrequestUrl.openConnection();
-//        BufferedReader reader =
-//            new BufferedReader(new InputStreamReader(connection.getInputStream()));
-//        connection.getResponseCode();
-//        String line = reader.readLine();
-//        while (line != null) {
-//            System.out.println(line);
-//            line = reader.readLine();
-//        }
+        URL wsdlrequestUrl =
+            new URL("http://127.0.0.1:5555/axis2/services/EchoXMLService/echoOMElement?value1=value1,value2=value2");
+
+        HttpURLConnection connection = (HttpURLConnection) wsdlrequestUrl.openConnection();
+        BufferedReader reader =
+            new BufferedReader(new InputStreamReader(connection.getInputStream()));
+        connection.getResponseCode();
+        String line = reader.readLine();
+        while (line != null) {
+            System.out.println(line);
+            line = reader.readLine();
+        }
     }
 
 }



Mime
View raw message