You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2008/11/03 22:07:21 UTC

svn commit: r710158 [7/20] - in /webservices/commons/trunk/modules/transport: ./ modules/base/ modules/base/src/main/java/org/apache/axis2/format/ modules/base/src/main/java/org/apache/axis2/transport/base/ modules/base/src/main/java/org/apache/axis2/t...

Modified: webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HTTPTransportReceiver.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HTTPTransportReceiver.java?rev=710158&r1=710157&r2=710158&view=diff
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HTTPTransportReceiver.java (original)
+++ webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HTTPTransportReceiver.java Mon Nov  3 13:07:13 2008
@@ -1,184 +1,184 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-
-package org.apache.axis2.transport.http;
-
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.description.AxisOperation;
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.engine.AxisConfiguration;
-
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * Class HTTPTransportReceiver
- */
-public class HTTPTransportReceiver {
-    public static Map getGetRequestParameters(String requestURI) {
-
-        Map map = new HashMap();
-        if (requestURI == null || "".equals(requestURI)) {
-            return map;
-        }
-        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;
-    }
-
-    /**
-     * 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 Returns String.
-     */
-    public static String getServicesHTML(ConfigurationContext configurationContext) {
-        String temp = "";
-        Map services = configurationContext.getAxisConfiguration().getServices();
-        Hashtable erroneousServices =
-                configurationContext.getAxisConfiguration().getFaultyServices();
-        boolean status = false;
-
-        if ((services != null) && !services.isEmpty()) {
-            status = true;
-
-            Collection serviceCollection = services.values();
-
-            temp += "<h2>" + "Deployed services" + "</h2>";
-
-            for (Iterator it = serviceCollection.iterator(); it.hasNext();) {
-
-                AxisService axisService = (AxisService) it.next();
-
-                Iterator iterator = axisService.getOperations();
-
-                temp += "<h3><a href=\"" + axisService.getName() + "?wsdl\">" +
-                        axisService.getName() + "</a></h3>";
-
-                if (iterator.hasNext()) {
-                    temp += "Available operations <ul>";
-
-                    for (; iterator.hasNext();) {
-                        AxisOperation axisOperation = (AxisOperation) iterator.next();
-
-                        temp += "<li>" + axisOperation.getName().getLocalPart() + "</li>";
-                    }
-
-                    temp += "</ul>";
-                } else {
-                    temp += "No operations specified 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) {
-            temp = "<h2>There are no services deployed</h2>";
-        }
-
-        temp = "<html><head><title>Axis2: Services</title></head>" + "<body>" + temp
-                + "</body></html>";
-
-        return temp;
-    }
-
-    public static String printServiceHTML(String serviceName,
-                                          ConfigurationContext configurationContext) {
-        String temp = "";
-        try {
-            AxisConfiguration axisConfig = configurationContext.getAxisConfiguration();
-            AxisService axisService = axisConfig.getService(serviceName);
-            Iterator iterator = axisService.getOperations();
-            temp += "<h3>" + axisService.getName() + "</h3>";
-            temp += "<a href=\"" + axisService.getName() + "?wsdl\">wsdl</a> <br/> ";
-            temp += "<i>Service Description :  " + axisService.getServiceDescription() +
-                    "</i><br/><br/>";
-            if (iterator.hasNext()) {
-                temp += "Available operations <ul>";
-                for (; iterator.hasNext();) {
-                    AxisOperation axisOperation = (AxisOperation) iterator.next();
-                    temp += "<li>" + axisOperation.getName().getLocalPart() + "</li>";
-                }
-                temp += "</ul>";
-            } else {
-                temp += "No operations specified for this service";
-            }
-            temp = "<html><head><title>Axis2: Services</title></head>" + "<body>" + temp
-                    + "</body></html>";
-        }
-        catch (AxisFault axisFault) {
-            temp = "<html><head><title>Service has a fualt</title></head>" + "<body>"
-                    + "<hr><h2><font color=\"blue\">" + axisFault.getMessage() +
-                    "</font></h2></body></html>";
-        }
-        return temp;
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+
+package org.apache.axis2.transport.http;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.AxisConfiguration;
+
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Class HTTPTransportReceiver
+ */
+public class HTTPTransportReceiver {
+    public static Map getGetRequestParameters(String requestURI) {
+
+        Map map = new HashMap();
+        if (requestURI == null || "".equals(requestURI)) {
+            return map;
+        }
+        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;
+    }
+
+    /**
+     * 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 Returns String.
+     */
+    public static String getServicesHTML(ConfigurationContext configurationContext) {
+        String temp = "";
+        Map services = configurationContext.getAxisConfiguration().getServices();
+        Hashtable erroneousServices =
+                configurationContext.getAxisConfiguration().getFaultyServices();
+        boolean status = false;
+
+        if ((services != null) && !services.isEmpty()) {
+            status = true;
+
+            Collection serviceCollection = services.values();
+
+            temp += "<h2>" + "Deployed services" + "</h2>";
+
+            for (Iterator it = serviceCollection.iterator(); it.hasNext();) {
+
+                AxisService axisService = (AxisService) it.next();
+
+                Iterator iterator = axisService.getOperations();
+
+                temp += "<h3><a href=\"" + axisService.getName() + "?wsdl\">" +
+                        axisService.getName() + "</a></h3>";
+
+                if (iterator.hasNext()) {
+                    temp += "Available operations <ul>";
+
+                    for (; iterator.hasNext();) {
+                        AxisOperation axisOperation = (AxisOperation) iterator.next();
+
+                        temp += "<li>" + axisOperation.getName().getLocalPart() + "</li>";
+                    }
+
+                    temp += "</ul>";
+                } else {
+                    temp += "No operations specified 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) {
+            temp = "<h2>There are no services deployed</h2>";
+        }
+
+        temp = "<html><head><title>Axis2: Services</title></head>" + "<body>" + temp
+                + "</body></html>";
+
+        return temp;
+    }
+
+    public static String printServiceHTML(String serviceName,
+                                          ConfigurationContext configurationContext) {
+        String temp = "";
+        try {
+            AxisConfiguration axisConfig = configurationContext.getAxisConfiguration();
+            AxisService axisService = axisConfig.getService(serviceName);
+            Iterator iterator = axisService.getOperations();
+            temp += "<h3>" + axisService.getName() + "</h3>";
+            temp += "<a href=\"" + axisService.getName() + "?wsdl\">wsdl</a> <br/> ";
+            temp += "<i>Service Description :  " + axisService.getServiceDescription() +
+                    "</i><br/><br/>";
+            if (iterator.hasNext()) {
+                temp += "Available operations <ul>";
+                for (; iterator.hasNext();) {
+                    AxisOperation axisOperation = (AxisOperation) iterator.next();
+                    temp += "<li>" + axisOperation.getName().getLocalPart() + "</li>";
+                }
+                temp += "</ul>";
+            } else {
+                temp += "No operations specified for this service";
+            }
+            temp = "<html><head><title>Axis2: Services</title></head>" + "<body>" + temp
+                    + "</body></html>";
+        }
+        catch (AxisFault axisFault) {
+            temp = "<html><head><title>Service has a fualt</title></head>" + "<body>"
+                    + "<hr><h2><font color=\"blue\">" + axisFault.getMessage() +
+                    "</font></h2></body></html>";
+        }
+        return temp;
+    }
+}

Propchange: webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HTTPTransportReceiver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HTTPTransportUtils.java?rev=710158&r1=710157&r2=710158&view=diff
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HTTPTransportUtils.java (original)
+++ webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HTTPTransportUtils.java Mon Nov  3 13:07:13 2008
@@ -1,276 +1,276 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-
-package org.apache.axis2.transport.http;
-
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.soap.SOAP11Constants;
-import org.apache.axiom.soap.SOAP12Constants;
-import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axiom.soap.SOAPFactory;
-import org.apache.axiom.soap.SOAPProcessingException;
-import org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory;
-import org.apache.axiom.soap.impl.llom.soap12.SOAP12Factory;
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.Constants;
-import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.builder.BuilderUtil;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.context.OperationContext;
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.description.Parameter;
-import org.apache.axis2.engine.AxisEngine;
-import org.apache.axis2.engine.Handler.InvocationResponse;
-import org.apache.axis2.transport.TransportUtils;
-import org.apache.axis2.util.JavaUtils;
-import org.apache.axis2.util.Utils;
-
-import javax.xml.parsers.FactoryConfigurationError;
-import javax.xml.stream.XMLStreamException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.zip.GZIPInputStream;
-
-public class HTTPTransportUtils {
-
-
-    /**
-     * @deprecated This was used only by the now deprecated processHTTPGetRequest() method.
-     */
-    public static SOAPEnvelope createEnvelopeFromGetRequest(String requestUrl,
-                                                            Map map, ConfigurationContext configCtx)
-            throws AxisFault {
-        String[] values =
-                Utils.parseRequestURLForServiceAndOperation(requestUrl,
-                                                            configCtx.getServiceContextPath());
-        if (values == null) {
-            return new SOAP11Factory().getDefaultEnvelope();
-        }
-
-        if ((values[1] != null) && (values[0] != null)) {
-            String srvice = values[0];
-            AxisService service = configCtx.getAxisConfiguration().getService(srvice);
-            if (service == null) {
-                throw new AxisFault("service not found: " + srvice);
-            }
-            String operation = values[1];
-            SOAPFactory soapFactory = new SOAP11Factory();
-            SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
-            OMNamespace omNs = soapFactory.createOMNamespace(service.getSchemaTargetNamespace(),
-                                                             service.getSchemaTargetNamespacePrefix());
-            soapFactory.createOMNamespace(service.getSchemaTargetNamespace(),
-                                          service.getSchemaTargetNamespacePrefix());
-            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, omNs);
-
-                omEle.setText(value);
-                opElement.addChild(omEle);
-            }
-
-            envelope.getBody().addChild(opElement);
-
-            return envelope;
-        } else {
-            return null;
-        }
-    }
-
-    /**
-     * @param msgContext           - The MessageContext of the Request Message
-     * @param out                  - The output stream of the response
-     * @param soapAction           - SoapAction of the request
-     * @param requestURI           - The URL that the request came to
-     * @param configurationContext - The Axis Configuration Context
-     * @param requestParameters    - The parameters of the request message
-     * @return - boolean indication whether the operation was succesfull
-     * @throws AxisFault - Thrown in case a fault occurs
-     * @deprecated use RESTUtil.processURLRequest(MessageContext msgContext, OutputStream out, String contentType) instead
-     */
-
-    public static boolean processHTTPGetRequest(MessageContext msgContext,
-                                                OutputStream out, String soapAction,
-                                                String requestURI,
-                                                ConfigurationContext configurationContext,
-                                                Map requestParameters)
-            throws AxisFault {
-        if ((soapAction != null) && soapAction.startsWith("\"") && soapAction.endsWith("\"")) {
-            soapAction = soapAction.substring(1, soapAction.length() - 1);
-        }
-
-        msgContext.setSoapAction(soapAction);
-        msgContext.setTo(new EndpointReference(requestURI));
-        msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
-        msgContext.setServerSide(true);
-        SOAPEnvelope envelope = HTTPTransportUtils.createEnvelopeFromGetRequest(requestURI,
-                                                                                requestParameters,
-                                                                                configurationContext);
-
-        if (envelope == null) {
-            return false;
-        } else {
-            msgContext.setDoingREST(true);
-            msgContext.setEnvelope(envelope);
-            AxisEngine.receive(msgContext);
-            return true;
-        }
-    }
-
-    private static final int VERSION_UNKNOWN = 0;
-    private static final int VERSION_SOAP11 = 1;
-    private static final int VERSION_SOAP12 = 2;
-
-    public static InvocationResponse processHTTPPostRequest(MessageContext msgContext,
-                                                            InputStream in,
-                                                            OutputStream out,
-                                                            String contentType,
-                                                            String soapActionHeader,
-                                                            String requestURI)
-            throws AxisFault {
-        int soapVersion = VERSION_UNKNOWN;
-        try {
-            soapVersion = initializeMessageContext(msgContext, soapActionHeader, requestURI, contentType);
-            msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
-
-            msgContext.setEnvelope(
-                    TransportUtils.createSOAPMessage(
-                            msgContext,
-                            handleGZip(msgContext, in), 
-                            contentType));
-            return AxisEngine.receive(msgContext);
-        } catch (SOAPProcessingException e) {
-            throw AxisFault.makeFault(e);
-        } catch (AxisFault e) {
-            throw e;
-        } catch (IOException e) {
-            throw AxisFault.makeFault(e);
-        } catch (OMException e) {
-            throw AxisFault.makeFault(e);
-        } catch (XMLStreamException e) {
-            throw AxisFault.makeFault(e);
-        } catch (FactoryConfigurationError e) {
-            throw AxisFault.makeFault(e);
-        } finally {
-            if ((msgContext.getEnvelope() == null) && soapVersion != VERSION_SOAP11) {
-                msgContext.setEnvelope(new SOAP12Factory().getDefaultEnvelope());
-            }
-        }
-    }
-
-    public static int initializeMessageContext(MessageContext msgContext,
-                                                String soapActionHeader,
-                                                String requestURI,
-                                                String contentType) {
-        int soapVersion = VERSION_UNKNOWN;
-        // remove the starting and trailing " from the SOAP Action
-        if ((soapActionHeader != null) 
-                && soapActionHeader.length() > 0 
-                && soapActionHeader.charAt(0) == '\"'
-                && soapActionHeader.endsWith("\"")) {
-            soapActionHeader = soapActionHeader.substring(1, soapActionHeader.length() - 1);
-        }
-
-        // fill up the Message Contexts
-        msgContext.setSoapAction(soapActionHeader);
-        msgContext.setTo(new EndpointReference(requestURI));
-        msgContext.setServerSide(true);
-
-        // get the type of char encoding
-        String charSetEnc = BuilderUtil.getCharSetEncoding(contentType);
-        if (charSetEnc == null) {
-            charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING;
-        }
-        msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
-
-        if (contentType != null) {
-            if (contentType.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
-                soapVersion = VERSION_SOAP12;
-                TransportUtils.processContentTypeForAction(contentType, msgContext);
-            } else if (contentType
-                    .indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
-                soapVersion = VERSION_SOAP11;
-            } else if (isRESTRequest(contentType)) {
-                // If REST, construct a SOAP11 envelope to hold the rest message and
-                // indicate that this is a REST message.
-                soapVersion = VERSION_SOAP11;
-                msgContext.setDoingREST(true);
-            }
-            if (soapVersion == VERSION_SOAP11) {
-                // TODO Keith : Do we need this anymore
-                // Deployment configuration parameter
-                Parameter enableREST = msgContext
-                        .getParameter(Constants.Configuration.ENABLE_REST);
-                if ((soapActionHeader == null) && (enableREST != null)) {
-                    if (Constants.VALUE_TRUE.equals(enableREST.getValue())) {
-                        // If the content Type is text/xml (BTW which is the
-                        // SOAP 1.1 Content type ) and the SOAP Action is
-                        // absent it is rest !!
-                        msgContext.setDoingREST(true);
-                    }
-                }
-            }
-        }
-        return soapVersion;
-    }
-
-    public static InputStream handleGZip(MessageContext msgContext, InputStream in)
-            throws IOException {
-        Map headers = (Map) msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);
-
-        if (headers != null) {
-            if (HTTPConstants.COMPRESSION_GZIP
-                    .equals(headers.get(HTTPConstants.HEADER_CONTENT_ENCODING)) ||
-                    HTTPConstants.COMPRESSION_GZIP.equals(headers.get(
-                            HTTPConstants.HEADER_CONTENT_ENCODING_LOWERCASE))) {
-                in = new GZIPInputStream(in);
-            }
-        }
-        return in;
-    }
-
-    /**
-     * This will match for content types that will be regarded as REST in WSDL2.0.
-     * This contains,
-     * 1. application/xml
-     * 2. application/x-www-form-urlencoded
-     * 3. multipart/form-data
-     * <p/>
-     * If the request doesnot contain a content type; this will return true.
-     *
-     * @param contentType content type to check
-     * @return Boolean
-     */
-    public static boolean isRESTRequest(String contentType) {
-        return contentType != null &&
-               (contentType.indexOf(HTTPConstants.MEDIA_TYPE_APPLICATION_XML) > -1 ||
-                contentType.indexOf(HTTPConstants.MEDIA_TYPE_X_WWW_FORM) > -1 ||
-                contentType.indexOf(HTTPConstants.MEDIA_TYPE_MULTIPART_FORM_DATA) > -1);
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+
+package org.apache.axis2.transport.http;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.SOAPProcessingException;
+import org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory;
+import org.apache.axiom.soap.impl.llom.soap12.SOAP12Factory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.builder.BuilderUtil;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.OperationContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.engine.AxisEngine;
+import org.apache.axis2.engine.Handler.InvocationResponse;
+import org.apache.axis2.transport.TransportUtils;
+import org.apache.axis2.util.JavaUtils;
+import org.apache.axis2.util.Utils;
+
+import javax.xml.parsers.FactoryConfigurationError;
+import javax.xml.stream.XMLStreamException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.zip.GZIPInputStream;
+
+public class HTTPTransportUtils {
+
+
+    /**
+     * @deprecated This was used only by the now deprecated processHTTPGetRequest() method.
+     */
+    public static SOAPEnvelope createEnvelopeFromGetRequest(String requestUrl,
+                                                            Map map, ConfigurationContext configCtx)
+            throws AxisFault {
+        String[] values =
+                Utils.parseRequestURLForServiceAndOperation(requestUrl,
+                                                            configCtx.getServiceContextPath());
+        if (values == null) {
+            return new SOAP11Factory().getDefaultEnvelope();
+        }
+
+        if ((values[1] != null) && (values[0] != null)) {
+            String srvice = values[0];
+            AxisService service = configCtx.getAxisConfiguration().getService(srvice);
+            if (service == null) {
+                throw new AxisFault("service not found: " + srvice);
+            }
+            String operation = values[1];
+            SOAPFactory soapFactory = new SOAP11Factory();
+            SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
+            OMNamespace omNs = soapFactory.createOMNamespace(service.getSchemaTargetNamespace(),
+                                                             service.getSchemaTargetNamespacePrefix());
+            soapFactory.createOMNamespace(service.getSchemaTargetNamespace(),
+                                          service.getSchemaTargetNamespacePrefix());
+            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, omNs);
+
+                omEle.setText(value);
+                opElement.addChild(omEle);
+            }
+
+            envelope.getBody().addChild(opElement);
+
+            return envelope;
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * @param msgContext           - The MessageContext of the Request Message
+     * @param out                  - The output stream of the response
+     * @param soapAction           - SoapAction of the request
+     * @param requestURI           - The URL that the request came to
+     * @param configurationContext - The Axis Configuration Context
+     * @param requestParameters    - The parameters of the request message
+     * @return - boolean indication whether the operation was succesfull
+     * @throws AxisFault - Thrown in case a fault occurs
+     * @deprecated use RESTUtil.processURLRequest(MessageContext msgContext, OutputStream out, String contentType) instead
+     */
+
+    public static boolean processHTTPGetRequest(MessageContext msgContext,
+                                                OutputStream out, String soapAction,
+                                                String requestURI,
+                                                ConfigurationContext configurationContext,
+                                                Map requestParameters)
+            throws AxisFault {
+        if ((soapAction != null) && soapAction.startsWith("\"") && soapAction.endsWith("\"")) {
+            soapAction = soapAction.substring(1, soapAction.length() - 1);
+        }
+
+        msgContext.setSoapAction(soapAction);
+        msgContext.setTo(new EndpointReference(requestURI));
+        msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
+        msgContext.setServerSide(true);
+        SOAPEnvelope envelope = HTTPTransportUtils.createEnvelopeFromGetRequest(requestURI,
+                                                                                requestParameters,
+                                                                                configurationContext);
+
+        if (envelope == null) {
+            return false;
+        } else {
+            msgContext.setDoingREST(true);
+            msgContext.setEnvelope(envelope);
+            AxisEngine.receive(msgContext);
+            return true;
+        }
+    }
+
+    private static final int VERSION_UNKNOWN = 0;
+    private static final int VERSION_SOAP11 = 1;
+    private static final int VERSION_SOAP12 = 2;
+
+    public static InvocationResponse processHTTPPostRequest(MessageContext msgContext,
+                                                            InputStream in,
+                                                            OutputStream out,
+                                                            String contentType,
+                                                            String soapActionHeader,
+                                                            String requestURI)
+            throws AxisFault {
+        int soapVersion = VERSION_UNKNOWN;
+        try {
+            soapVersion = initializeMessageContext(msgContext, soapActionHeader, requestURI, contentType);
+            msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
+
+            msgContext.setEnvelope(
+                    TransportUtils.createSOAPMessage(
+                            msgContext,
+                            handleGZip(msgContext, in), 
+                            contentType));
+            return AxisEngine.receive(msgContext);
+        } catch (SOAPProcessingException e) {
+            throw AxisFault.makeFault(e);
+        } catch (AxisFault e) {
+            throw e;
+        } catch (IOException e) {
+            throw AxisFault.makeFault(e);
+        } catch (OMException e) {
+            throw AxisFault.makeFault(e);
+        } catch (XMLStreamException e) {
+            throw AxisFault.makeFault(e);
+        } catch (FactoryConfigurationError e) {
+            throw AxisFault.makeFault(e);
+        } finally {
+            if ((msgContext.getEnvelope() == null) && soapVersion != VERSION_SOAP11) {
+                msgContext.setEnvelope(new SOAP12Factory().getDefaultEnvelope());
+            }
+        }
+    }
+
+    public static int initializeMessageContext(MessageContext msgContext,
+                                                String soapActionHeader,
+                                                String requestURI,
+                                                String contentType) {
+        int soapVersion = VERSION_UNKNOWN;
+        // remove the starting and trailing " from the SOAP Action
+        if ((soapActionHeader != null) 
+                && soapActionHeader.length() > 0 
+                && soapActionHeader.charAt(0) == '\"'
+                && soapActionHeader.endsWith("\"")) {
+            soapActionHeader = soapActionHeader.substring(1, soapActionHeader.length() - 1);
+        }
+
+        // fill up the Message Contexts
+        msgContext.setSoapAction(soapActionHeader);
+        msgContext.setTo(new EndpointReference(requestURI));
+        msgContext.setServerSide(true);
+
+        // get the type of char encoding
+        String charSetEnc = BuilderUtil.getCharSetEncoding(contentType);
+        if (charSetEnc == null) {
+            charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING;
+        }
+        msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
+
+        if (contentType != null) {
+            if (contentType.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
+                soapVersion = VERSION_SOAP12;
+                TransportUtils.processContentTypeForAction(contentType, msgContext);
+            } else if (contentType
+                    .indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
+                soapVersion = VERSION_SOAP11;
+            } else if (isRESTRequest(contentType)) {
+                // If REST, construct a SOAP11 envelope to hold the rest message and
+                // indicate that this is a REST message.
+                soapVersion = VERSION_SOAP11;
+                msgContext.setDoingREST(true);
+            }
+            if (soapVersion == VERSION_SOAP11) {
+                // TODO Keith : Do we need this anymore
+                // Deployment configuration parameter
+                Parameter enableREST = msgContext
+                        .getParameter(Constants.Configuration.ENABLE_REST);
+                if ((soapActionHeader == null) && (enableREST != null)) {
+                    if (Constants.VALUE_TRUE.equals(enableREST.getValue())) {
+                        // If the content Type is text/xml (BTW which is the
+                        // SOAP 1.1 Content type ) and the SOAP Action is
+                        // absent it is rest !!
+                        msgContext.setDoingREST(true);
+                    }
+                }
+            }
+        }
+        return soapVersion;
+    }
+
+    public static InputStream handleGZip(MessageContext msgContext, InputStream in)
+            throws IOException {
+        Map headers = (Map) msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);
+
+        if (headers != null) {
+            if (HTTPConstants.COMPRESSION_GZIP
+                    .equals(headers.get(HTTPConstants.HEADER_CONTENT_ENCODING)) ||
+                    HTTPConstants.COMPRESSION_GZIP.equals(headers.get(
+                            HTTPConstants.HEADER_CONTENT_ENCODING_LOWERCASE))) {
+                in = new GZIPInputStream(in);
+            }
+        }
+        return in;
+    }
+
+    /**
+     * This will match for content types that will be regarded as REST in WSDL2.0.
+     * This contains,
+     * 1. application/xml
+     * 2. application/x-www-form-urlencoded
+     * 3. multipart/form-data
+     * <p/>
+     * If the request doesnot contain a content type; this will return true.
+     *
+     * @param contentType content type to check
+     * @return Boolean
+     */
+    public static boolean isRESTRequest(String contentType) {
+        return contentType != null &&
+               (contentType.indexOf(HTTPConstants.MEDIA_TYPE_APPLICATION_XML) > -1 ||
+                contentType.indexOf(HTTPConstants.MEDIA_TYPE_X_WWW_FORM) > -1 ||
+                contentType.indexOf(HTTPConstants.MEDIA_TYPE_MULTIPART_FORM_DATA) > -1);
+    }
+}

Propchange: webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HTTPWorker.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HTTPWorker.java?rev=710158&r1=710157&r2=710158&view=diff
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HTTPWorker.java (original)
+++ webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HTTPWorker.java Mon Nov  3 13:07:13 2008
@@ -1,374 +1,374 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-package org.apache.axis2.transport.http;
-
-import org.apache.axis2.Constants;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.deployment.DeploymentConstants;
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.engine.Handler.InvocationResponse;
-import org.apache.axis2.transport.RequestResponseTransport;
-import org.apache.axis2.transport.TransportUtils;
-import org.apache.axis2.transport.http.server.AxisHttpRequest;
-import org.apache.axis2.transport.http.server.AxisHttpResponse;
-import org.apache.axis2.transport.http.server.HttpUtils;
-import org.apache.axis2.transport.http.server.Worker;
-import org.apache.axis2.transport.http.util.RESTUtil;
-import org.apache.http.Header;
-import org.apache.http.HttpException;
-import org.apache.http.HttpStatus;
-import org.apache.http.MethodNotSupportedException;
-import org.apache.http.message.BasicHeader;
-import org.apache.http.protocol.HTTP;
-import org.apache.http.util.EncodingUtils;
-import org.apache.ws.commons.schema.XmlSchema;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ByteArrayInputStream;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-public class HTTPWorker implements Worker {
-
-    public HTTPWorker() {
-    }
-
-    public void service(
-            final AxisHttpRequest request,
-            final AxisHttpResponse response,
-            final MessageContext msgContext) throws HttpException, IOException {
-
-        ConfigurationContext configurationContext = msgContext.getConfigurationContext();
-        final String servicePath = configurationContext.getServiceContextPath();
-        final String contextPath =
-                (servicePath.startsWith("/") ? servicePath : "/" + servicePath) + "/";
-
-        String uri = request.getRequestURI();
-        String method = request.getMethod();
-        String soapAction = HttpUtils.getSoapAction(request);
-        InvocationResponse pi;
-
-        if (method.equals(HTTPConstants.HEADER_GET)) {
-            if (uri.equals("/favicon.ico")) {
-                response.setStatus(HttpStatus.SC_MOVED_PERMANENTLY);
-                response.addHeader(new BasicHeader("Location", "http://ws.apache.org/favicon.ico"));
-                return;
-            }
-            if (!uri.startsWith(contextPath)) {
-                response.setStatus(HttpStatus.SC_MOVED_PERMANENTLY);
-                response.addHeader(new BasicHeader("Location", contextPath));
-                return;
-            }
-            if (uri.endsWith("axis2/services/")) {
-                String s = HTTPTransportReceiver.getServicesHTML(configurationContext);
-                response.setStatus(HttpStatus.SC_OK);
-                response.setContentType("text/html");
-                OutputStream out = response.getOutputStream();
-                out.write(EncodingUtils.getBytes(s, HTTP.ISO_8859_1));
-                return;
-            }
-            if (uri.indexOf("?") < 0) {
-                if (!uri.endsWith(contextPath)) {
-                    if (uri.endsWith(".xsd") || uri.endsWith(".wsdl")) {
-                        HashMap services = configurationContext.getAxisConfiguration().getServices();
-                        String file = uri.substring(uri.lastIndexOf("/") + 1,
-                                uri.length());
-                        if ((services != null) && !services.isEmpty()) {
-                            Iterator i = services.values().iterator();
-                            while (i.hasNext()) {
-                                AxisService service = (AxisService) i.next();
-                                InputStream stream = service.getClassLoader().
-                                getResourceAsStream("META-INF/" + file);
-                                if (stream != null) {
-                                    OutputStream out = response.getOutputStream();
-                                    response.setContentType("text/xml");
-                                    ListingAgent.copy(stream, out);
-                                    out.flush();
-                                    out.close();
-                                    return;
-                                }
-                            }
-                        }
-                    } else {
-                        String serviceName = uri.replaceAll(contextPath, "");
-                        if (serviceName.indexOf("/") < 0) {
-                            String s = HTTPTransportReceiver
-                                    .printServiceHTML(serviceName, configurationContext);
-                            response.setStatus(HttpStatus.SC_OK);
-                            response.setContentType("text/html");
-                            OutputStream out = response.getOutputStream();
-                            out.write(EncodingUtils.getBytes(s, HTTP.ISO_8859_1));
-                            return;
-                        }
-                    }
-                }
-            }
-            if (uri.endsWith("?wsdl2")) {
-                String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.length() - 6);
-                HashMap services = configurationContext.getAxisConfiguration().getServices();
-                AxisService service = (AxisService) services.get(serviceName);
-                if (service != null) {
-                    response.setStatus(HttpStatus.SC_OK);
-                    response.setContentType("text/xml");
-                    service.printWSDL2(response.getOutputStream(), getHost(request));
-                    return;
-                }
-            }
-            if (uri.endsWith("?wsdl")) {
-                String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.length() - 5);
-                HashMap services = configurationContext.getAxisConfiguration().getServices();
-                AxisService service = (AxisService) services.get(serviceName);
-                if (service != null) {
-                    response.setStatus(HttpStatus.SC_OK);
-                    response.setContentType("text/xml");
-                    service.printWSDL(response.getOutputStream(), getHost(request));
-                    return;
-                }
-            }
-            if (uri.endsWith("?xsd")) {
-                String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.length() - 4);
-                HashMap services = configurationContext.getAxisConfiguration().getServices();
-                AxisService service = (AxisService) services.get(serviceName);
-                if (service != null) {
-                    response.setStatus(HttpStatus.SC_OK);
-                    response.setContentType("text/xml");
-                    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();
-                    XmlSchema schema = (XmlSchema) schemaTable.get(schemaName);
-                    if (schema == null) {
-                        int dotIndex = schemaName.indexOf('.');
-                        if (dotIndex > 0) {
-                            String schemaKey = schemaName.substring(0,dotIndex);
-                            schema = (XmlSchema) schemaTable.get(schemaKey);
-                        }
-                    }
-                    //schema found - write it to the stream
-                    if (schema != null) {
-                        response.setStatus(HttpStatus.SC_OK);
-                        response.setContentType("text/xml");
-                        schema.write(response.getOutputStream());
-                        return;
-                    } else {
-                        InputStream instream = service.getClassLoader()
-                            .getResourceAsStream(DeploymentConstants.META_INF + "/" + schemaName);
-                        
-                        if (instream != null) {
-                            response.setStatus(HttpStatus.SC_OK);
-                            response.setContentType("text/xml");
-                            OutputStream outstream = response.getOutputStream();
-                            boolean checkLength = true;
-                            int length = Integer.MAX_VALUE;
-                            int nextValue = instream.read();
-                            if (checkLength) length--;
-                            while (-1 != nextValue && length >= 0) {
-                                outstream.write(nextValue);
-                                nextValue = instream.read();
-                                if (checkLength) length--;
-                            }
-                            outstream.flush();
-                            return;
-                        } else {
-                            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                            int ret = service.printXSD(baos, schemaName);
-                            if(ret>0) {
-                                baos.flush();
-                                instream = new ByteArrayInputStream(baos.toByteArray());
-                                response.setStatus(HttpStatus.SC_OK);
-                                response.setContentType("text/xml");
-                                OutputStream outstream = response.getOutputStream();
-                                boolean checkLength = true;
-                                int length = Integer.MAX_VALUE;
-                                int nextValue = instream.read();
-                                if (checkLength) length--;
-                                while (-1 != nextValue && length >= 0) {
-                                    outstream.write(nextValue);
-                                    nextValue = instream.read();
-                                    if (checkLength) length--;
-                                }
-                                outstream.flush();
-                                return;
-                            }
-                            // no schema available by that name  - send 404
-                            response.sendError(HttpStatus.SC_NOT_FOUND, "Schema Not Found!");
-                            return;
-                        }
-                    }
-                }
-            }
-            if (uri.indexOf("?wsdl2=") > 0) {
-                String serviceName =
-                        uri.substring(uri.lastIndexOf("/") + 1, uri.lastIndexOf("?wsdl2="));
-                if (processInternalWSDL(uri, configurationContext, serviceName, response)) return;
-            }
-            if (uri.indexOf("?wsdl=") > 0) {
-                String serviceName =
-                        uri.substring(uri.lastIndexOf("/") + 1, uri.lastIndexOf("?wsdl="));
-                if (processInternalWSDL(uri, configurationContext, serviceName, response)) return;
-            }
-
-            String contentType = null;
-            Header[] headers = request.getHeaders(HTTPConstants.HEADER_CONTENT_TYPE);
-            if (headers != null && headers.length > 0) {
-                contentType = headers[0].getValue();
-                int index = contentType.indexOf(';');
-                if (index > 0) {
-                    contentType = contentType.substring(0, index);
-                }
-            }
-            
-            // deal with GET request
-            pi = RESTUtil.processURLRequest(
-                    msgContext, 
-                    response.getOutputStream(), 
-                    contentType);
-
-        } else if (method.equals(HTTPConstants.HEADER_POST)) {
-            // deal with POST request
-
-            String contentType = request.getContentType();
-            
-            if (HTTPTransportUtils.isRESTRequest(contentType)) {
-                pi = RESTUtil.processXMLRequest(
-                        msgContext, 
-                        request.getInputStream(),
-                        response.getOutputStream(), 
-                        contentType);
-            } else {
-                String ip = (String)msgContext.getProperty(MessageContext.TRANSPORT_ADDR);
-                if (ip != null){
-                    uri = ip + uri;
-                }
-                pi = HTTPTransportUtils.processHTTPPostRequest(
-                        msgContext, 
-                        request.getInputStream(),
-                        response.getOutputStream(),
-                        contentType, 
-                        soapAction, 
-                        uri);
-            }
-
-        } else if (method.equals(HTTPConstants.HEADER_PUT)) {
-
-            String contentType = request.getContentType();
-            msgContext.setProperty(Constants.Configuration.CONTENT_TYPE, contentType);
-            
-            pi = RESTUtil.processXMLRequest(
-                    msgContext, 
-                    request.getInputStream(),
-                    response.getOutputStream(), 
-                    contentType);
-
-        } else if (method.equals(HTTPConstants.HEADER_DELETE)) {
-
-            pi = RESTUtil.processURLRequest(
-                    msgContext, 
-                    response.getOutputStream(), 
-                    null);
-
-        } else {
-            throw new MethodNotSupportedException(method + " method not supported");
-        }
-        
-        Boolean holdResponse =
-            (Boolean) msgContext.getProperty(RequestResponseTransport.HOLD_RESPONSE);
-        if (pi.equals(InvocationResponse.SUSPEND) ||
-                (holdResponse != null && Boolean.TRUE.equals(holdResponse))) {
-            try {
-                ((RequestResponseTransport) msgContext
-                        .getProperty(RequestResponseTransport.TRANSPORT_CONTROL)).awaitResponse();
-            }
-            catch (InterruptedException e) {
-                throw new IOException("We were interrupted, so this may not function correctly:" +
-                        e.getMessage());
-            }
-        }
-        
-        // Finalize response
-        RequestResponseTransport requestResponseTransportControl =
-            (RequestResponseTransport) msgContext.
-            getProperty(RequestResponseTransport.TRANSPORT_CONTROL);
-
-        if (TransportUtils.isResponseWritten(msgContext) ||
-            ((requestResponseTransportControl != null) &&
-             requestResponseTransportControl.getStatus().equals(
-                RequestResponseTransport.RequestResponseTransportStatus.SIGNALLED))) {
-            // The response is written or signalled.  The current status is used (probably SC_OK).
-        } else {
-            // The response may be ack'd, mark the status as accepted.
-            response.setStatus(HttpStatus.SC_ACCEPTED);
-        }
-    }
-
-    private boolean processInternalWSDL(String uri, ConfigurationContext configurationContext, 
-                                        String serviceName, AxisHttpResponse response) 
-    throws IOException {
-        String wsdlName = uri.substring(uri.lastIndexOf("=") + 1);
-
-        HashMap services = configurationContext.getAxisConfiguration().getServices();
-        AxisService service = (AxisService) services.get(serviceName);
-
-        if (service != null) {
-            response.setStatus(HttpStatus.SC_OK);
-            response.setContentType("text/xml");
-            service.printUserWSDL(response.getOutputStream(), wsdlName);
-            response.getOutputStream().flush();
-            return true;
-
-        } else {
-            // no schema available by that name  - send 404
-            response.sendError(HttpStatus.SC_NOT_FOUND, "Schema Not Found!");
-            return true;
-        }
-
-    }
-
-    public String getHost(AxisHttpRequest request) throws java.net.SocketException {
-        String host = null;
-        Header hostHeader = request.getFirstHeader("host");
-        if (hostHeader != null) {
-            String parts[] = hostHeader.getValue().split("[:]");
-            if (parts.length > 0) {
-                host = parts[0].trim();
-            }
-        }
-        return host;
-    }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.axis2.transport.http;
+
+import org.apache.axis2.Constants;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.deployment.DeploymentConstants;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.Handler.InvocationResponse;
+import org.apache.axis2.transport.RequestResponseTransport;
+import org.apache.axis2.transport.TransportUtils;
+import org.apache.axis2.transport.http.server.AxisHttpRequest;
+import org.apache.axis2.transport.http.server.AxisHttpResponse;
+import org.apache.axis2.transport.http.server.HttpUtils;
+import org.apache.axis2.transport.http.server.Worker;
+import org.apache.axis2.transport.http.util.RESTUtil;
+import org.apache.http.Header;
+import org.apache.http.HttpException;
+import org.apache.http.HttpStatus;
+import org.apache.http.MethodNotSupportedException;
+import org.apache.http.message.BasicHeader;
+import org.apache.http.protocol.HTTP;
+import org.apache.http.util.EncodingUtils;
+import org.apache.ws.commons.schema.XmlSchema;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+public class HTTPWorker implements Worker {
+
+    public HTTPWorker() {
+    }
+
+    public void service(
+            final AxisHttpRequest request,
+            final AxisHttpResponse response,
+            final MessageContext msgContext) throws HttpException, IOException {
+
+        ConfigurationContext configurationContext = msgContext.getConfigurationContext();
+        final String servicePath = configurationContext.getServiceContextPath();
+        final String contextPath =
+                (servicePath.startsWith("/") ? servicePath : "/" + servicePath) + "/";
+
+        String uri = request.getRequestURI();
+        String method = request.getMethod();
+        String soapAction = HttpUtils.getSoapAction(request);
+        InvocationResponse pi;
+
+        if (method.equals(HTTPConstants.HEADER_GET)) {
+            if (uri.equals("/favicon.ico")) {
+                response.setStatus(HttpStatus.SC_MOVED_PERMANENTLY);
+                response.addHeader(new BasicHeader("Location", "http://ws.apache.org/favicon.ico"));
+                return;
+            }
+            if (!uri.startsWith(contextPath)) {
+                response.setStatus(HttpStatus.SC_MOVED_PERMANENTLY);
+                response.addHeader(new BasicHeader("Location", contextPath));
+                return;
+            }
+            if (uri.endsWith("axis2/services/")) {
+                String s = HTTPTransportReceiver.getServicesHTML(configurationContext);
+                response.setStatus(HttpStatus.SC_OK);
+                response.setContentType("text/html");
+                OutputStream out = response.getOutputStream();
+                out.write(EncodingUtils.getBytes(s, HTTP.ISO_8859_1));
+                return;
+            }
+            if (uri.indexOf("?") < 0) {
+                if (!uri.endsWith(contextPath)) {
+                    if (uri.endsWith(".xsd") || uri.endsWith(".wsdl")) {
+                        HashMap services = configurationContext.getAxisConfiguration().getServices();
+                        String file = uri.substring(uri.lastIndexOf("/") + 1,
+                                uri.length());
+                        if ((services != null) && !services.isEmpty()) {
+                            Iterator i = services.values().iterator();
+                            while (i.hasNext()) {
+                                AxisService service = (AxisService) i.next();
+                                InputStream stream = service.getClassLoader().
+                                getResourceAsStream("META-INF/" + file);
+                                if (stream != null) {
+                                    OutputStream out = response.getOutputStream();
+                                    response.setContentType("text/xml");
+                                    ListingAgent.copy(stream, out);
+                                    out.flush();
+                                    out.close();
+                                    return;
+                                }
+                            }
+                        }
+                    } else {
+                        String serviceName = uri.replaceAll(contextPath, "");
+                        if (serviceName.indexOf("/") < 0) {
+                            String s = HTTPTransportReceiver
+                                    .printServiceHTML(serviceName, configurationContext);
+                            response.setStatus(HttpStatus.SC_OK);
+                            response.setContentType("text/html");
+                            OutputStream out = response.getOutputStream();
+                            out.write(EncodingUtils.getBytes(s, HTTP.ISO_8859_1));
+                            return;
+                        }
+                    }
+                }
+            }
+            if (uri.endsWith("?wsdl2")) {
+                String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.length() - 6);
+                HashMap services = configurationContext.getAxisConfiguration().getServices();
+                AxisService service = (AxisService) services.get(serviceName);
+                if (service != null) {
+                    response.setStatus(HttpStatus.SC_OK);
+                    response.setContentType("text/xml");
+                    service.printWSDL2(response.getOutputStream(), getHost(request));
+                    return;
+                }
+            }
+            if (uri.endsWith("?wsdl")) {
+                String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.length() - 5);
+                HashMap services = configurationContext.getAxisConfiguration().getServices();
+                AxisService service = (AxisService) services.get(serviceName);
+                if (service != null) {
+                    response.setStatus(HttpStatus.SC_OK);
+                    response.setContentType("text/xml");
+                    service.printWSDL(response.getOutputStream(), getHost(request));
+                    return;
+                }
+            }
+            if (uri.endsWith("?xsd")) {
+                String serviceName = uri.substring(uri.lastIndexOf("/") + 1, uri.length() - 4);
+                HashMap services = configurationContext.getAxisConfiguration().getServices();
+                AxisService service = (AxisService) services.get(serviceName);
+                if (service != null) {
+                    response.setStatus(HttpStatus.SC_OK);
+                    response.setContentType("text/xml");
+                    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();
+                    XmlSchema schema = (XmlSchema) schemaTable.get(schemaName);
+                    if (schema == null) {
+                        int dotIndex = schemaName.indexOf('.');
+                        if (dotIndex > 0) {
+                            String schemaKey = schemaName.substring(0,dotIndex);
+                            schema = (XmlSchema) schemaTable.get(schemaKey);
+                        }
+                    }
+                    //schema found - write it to the stream
+                    if (schema != null) {
+                        response.setStatus(HttpStatus.SC_OK);
+                        response.setContentType("text/xml");
+                        schema.write(response.getOutputStream());
+                        return;
+                    } else {
+                        InputStream instream = service.getClassLoader()
+                            .getResourceAsStream(DeploymentConstants.META_INF + "/" + schemaName);
+                        
+                        if (instream != null) {
+                            response.setStatus(HttpStatus.SC_OK);
+                            response.setContentType("text/xml");
+                            OutputStream outstream = response.getOutputStream();
+                            boolean checkLength = true;
+                            int length = Integer.MAX_VALUE;
+                            int nextValue = instream.read();
+                            if (checkLength) length--;
+                            while (-1 != nextValue && length >= 0) {
+                                outstream.write(nextValue);
+                                nextValue = instream.read();
+                                if (checkLength) length--;
+                            }
+                            outstream.flush();
+                            return;
+                        } else {
+                            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                            int ret = service.printXSD(baos, schemaName);
+                            if(ret>0) {
+                                baos.flush();
+                                instream = new ByteArrayInputStream(baos.toByteArray());
+                                response.setStatus(HttpStatus.SC_OK);
+                                response.setContentType("text/xml");
+                                OutputStream outstream = response.getOutputStream();
+                                boolean checkLength = true;
+                                int length = Integer.MAX_VALUE;
+                                int nextValue = instream.read();
+                                if (checkLength) length--;
+                                while (-1 != nextValue && length >= 0) {
+                                    outstream.write(nextValue);
+                                    nextValue = instream.read();
+                                    if (checkLength) length--;
+                                }
+                                outstream.flush();
+                                return;
+                            }
+                            // no schema available by that name  - send 404
+                            response.sendError(HttpStatus.SC_NOT_FOUND, "Schema Not Found!");
+                            return;
+                        }
+                    }
+                }
+            }
+            if (uri.indexOf("?wsdl2=") > 0) {
+                String serviceName =
+                        uri.substring(uri.lastIndexOf("/") + 1, uri.lastIndexOf("?wsdl2="));
+                if (processInternalWSDL(uri, configurationContext, serviceName, response)) return;
+            }
+            if (uri.indexOf("?wsdl=") > 0) {
+                String serviceName =
+                        uri.substring(uri.lastIndexOf("/") + 1, uri.lastIndexOf("?wsdl="));
+                if (processInternalWSDL(uri, configurationContext, serviceName, response)) return;
+            }
+
+            String contentType = null;
+            Header[] headers = request.getHeaders(HTTPConstants.HEADER_CONTENT_TYPE);
+            if (headers != null && headers.length > 0) {
+                contentType = headers[0].getValue();
+                int index = contentType.indexOf(';');
+                if (index > 0) {
+                    contentType = contentType.substring(0, index);
+                }
+            }
+            
+            // deal with GET request
+            pi = RESTUtil.processURLRequest(
+                    msgContext, 
+                    response.getOutputStream(), 
+                    contentType);
+
+        } else if (method.equals(HTTPConstants.HEADER_POST)) {
+            // deal with POST request
+
+            String contentType = request.getContentType();
+            
+            if (HTTPTransportUtils.isRESTRequest(contentType)) {
+                pi = RESTUtil.processXMLRequest(
+                        msgContext, 
+                        request.getInputStream(),
+                        response.getOutputStream(), 
+                        contentType);
+            } else {
+                String ip = (String)msgContext.getProperty(MessageContext.TRANSPORT_ADDR);
+                if (ip != null){
+                    uri = ip + uri;
+                }
+                pi = HTTPTransportUtils.processHTTPPostRequest(
+                        msgContext, 
+                        request.getInputStream(),
+                        response.getOutputStream(),
+                        contentType, 
+                        soapAction, 
+                        uri);
+            }
+
+        } else if (method.equals(HTTPConstants.HEADER_PUT)) {
+
+            String contentType = request.getContentType();
+            msgContext.setProperty(Constants.Configuration.CONTENT_TYPE, contentType);
+            
+            pi = RESTUtil.processXMLRequest(
+                    msgContext, 
+                    request.getInputStream(),
+                    response.getOutputStream(), 
+                    contentType);
+
+        } else if (method.equals(HTTPConstants.HEADER_DELETE)) {
+
+            pi = RESTUtil.processURLRequest(
+                    msgContext, 
+                    response.getOutputStream(), 
+                    null);
+
+        } else {
+            throw new MethodNotSupportedException(method + " method not supported");
+        }
+        
+        Boolean holdResponse =
+            (Boolean) msgContext.getProperty(RequestResponseTransport.HOLD_RESPONSE);
+        if (pi.equals(InvocationResponse.SUSPEND) ||
+                (holdResponse != null && Boolean.TRUE.equals(holdResponse))) {
+            try {
+                ((RequestResponseTransport) msgContext
+                        .getProperty(RequestResponseTransport.TRANSPORT_CONTROL)).awaitResponse();
+            }
+            catch (InterruptedException e) {
+                throw new IOException("We were interrupted, so this may not function correctly:" +
+                        e.getMessage());
+            }
+        }
+        
+        // Finalize response
+        RequestResponseTransport requestResponseTransportControl =
+            (RequestResponseTransport) msgContext.
+            getProperty(RequestResponseTransport.TRANSPORT_CONTROL);
+
+        if (TransportUtils.isResponseWritten(msgContext) ||
+            ((requestResponseTransportControl != null) &&
+             requestResponseTransportControl.getStatus().equals(
+                RequestResponseTransport.RequestResponseTransportStatus.SIGNALLED))) {
+            // The response is written or signalled.  The current status is used (probably SC_OK).
+        } else {
+            // The response may be ack'd, mark the status as accepted.
+            response.setStatus(HttpStatus.SC_ACCEPTED);
+        }
+    }
+
+    private boolean processInternalWSDL(String uri, ConfigurationContext configurationContext, 
+                                        String serviceName, AxisHttpResponse response) 
+    throws IOException {
+        String wsdlName = uri.substring(uri.lastIndexOf("=") + 1);
+
+        HashMap services = configurationContext.getAxisConfiguration().getServices();
+        AxisService service = (AxisService) services.get(serviceName);
+
+        if (service != null) {
+            response.setStatus(HttpStatus.SC_OK);
+            response.setContentType("text/xml");
+            service.printUserWSDL(response.getOutputStream(), wsdlName);
+            response.getOutputStream().flush();
+            return true;
+
+        } else {
+            // no schema available by that name  - send 404
+            response.sendError(HttpStatus.SC_NOT_FOUND, "Schema Not Found!");
+            return true;
+        }
+
+    }
+
+    public String getHost(AxisHttpRequest request) throws java.net.SocketException {
+        String host = null;
+        Header hostHeader = request.getFirstHeader("host");
+        if (hostHeader != null) {
+            String parts[] = hostHeader.getValue().split("[:]");
+            if (parts.length > 0) {
+                host = parts[0].trim();
+            }
+        }
+        return host;
+    }
+
+}

Propchange: webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HTTPWorker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HTTPWorkerFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HTTPWorkerFactory.java?rev=710158&r1=710157&r2=710158&view=diff
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HTTPWorkerFactory.java (original)
+++ webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HTTPWorkerFactory.java Mon Nov  3 13:07:13 2008
@@ -1,35 +1,35 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- */
-
-package org.apache.axis2.transport.http;
-
-import org.apache.axis2.transport.http.server.Worker;
-import org.apache.axis2.transport.http.server.WorkerFactory;
-
-public class HTTPWorkerFactory implements WorkerFactory {
-
-    public HTTPWorkerFactory() {
-        super();
-    }
-
-    public Worker newWorker() {
-        return new HTTPWorker();
-    }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.axis2.transport.http;
+
+import org.apache.axis2.transport.http.server.Worker;
+import org.apache.axis2.transport.http.server.WorkerFactory;
+
+public class HTTPWorkerFactory implements WorkerFactory {
+
+    public HTTPWorkerFactory() {
+        super();
+    }
+
+    public Worker newWorker() {
+        return new HTTPWorker();
+    }
+
+}

Propchange: webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/HTTPWorkerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native