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 de...@apache.org on 2008/09/13 19:22:40 UTC

svn commit: r694988 [4/7] - in /webservices/commons/trunk/modules/transport: ./ modules/ modules/http/ modules/http/src/ modules/http/src/org/ modules/http/src/org/apache/ modules/http/src/org/apache/axis2/ modules/http/src/org/apache/axis2/transport/ ...

Added: webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/ProxyConfiguration.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/ProxyConfiguration.java?rev=694988&view=auto
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/ProxyConfiguration.java (added)
+++ webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/ProxyConfiguration.java Sat Sep 13 10:22:37 2008
@@ -0,0 +1,521 @@
+/*
+ * 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.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.Parameter;
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.HostConfiguration;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.NTCredentials;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
+
+import javax.xml.namespace.QName;
+import java.net.URL;
+import java.util.StringTokenizer;
+
+
+/**
+ * The purpose of this class is to configure the proxy auth regardles of the protocol.
+ * Proxy will be set only for HTTP connection
+ */
+
+public class ProxyConfiguration {
+
+    protected String proxyHost;
+    protected String nonProxyHosts;
+    protected int proxyPort = -1; //If port is not set, default is set to -1
+    protected String proxyUser;
+    protected String proxyPassword;
+
+    protected static final String HTTP_PROXY_HOST = "http.proxyHost";
+    protected static final String HTTP_PROXY_PORT = "http.proxyPort";
+    protected static final String HTTP_NON_PROXY_HOSTS = "http.nonProxyHosts";
+
+    protected static final String ATTR_PROXY = "Proxy";
+    protected static final String PROXY_HOST_ELEMENT = "ProxyHost";
+    protected static final String PROXY_PORT_ELEMENT = "ProxyPort";
+    protected static final String PROXY_USER_ELEMENT = "ProxyUser";
+    protected static final String PROXY_PASSWORD_ELEMENT = "ProxyPassword";
+
+    public void configure(MessageContext messageContext,
+                          HttpClient httpClient,
+                          HostConfiguration config) throws AxisFault {
+
+        //        <parameter name="Proxy">
+        //              <Configuration>
+        //                     <ProxyHost>example.org</ProxyHost>
+        //                     <ProxyPort>5678</ProxyPort>
+        //                     <ProxyUser>EXAMPLE\saminda</ProxyUser>
+        //                     <ProxyPassword>ppp</ProxyPassword>
+        //              </Configuration>
+        //        </parameter>
+        Credentials proxyCred = null;
+
+        //Getting configuration values from Axis2.xml
+        Parameter param = messageContext.getConfigurationContext().getAxisConfiguration()
+                .getParameter(ATTR_PROXY);
+
+        if (param != null) {
+            OMElement configurationEle = param.getParameterElement().getFirstElement();
+            if (configurationEle == null) {
+                throw new AxisFault(
+                        ProxyConfiguration.class.getName() + " Configuration element is missing");
+            }
+
+            OMElement proxyHostEle =
+                    configurationEle.getFirstChildWithName(new QName(PROXY_HOST_ELEMENT));
+            OMElement proxyPortEle =
+                    configurationEle.getFirstChildWithName(new QName(PROXY_PORT_ELEMENT));
+            OMElement proxyUserEle =
+                    configurationEle.getFirstChildWithName(new QName(PROXY_USER_ELEMENT));
+            OMElement proxyPasswordEle =
+                    configurationEle.getFirstChildWithName(new QName(PROXY_PASSWORD_ELEMENT));
+
+            if (proxyHostEle == null) {
+                throw new AxisFault(
+                        ProxyConfiguration.class.getName() + " ProxyHost element is missing");
+            }
+            String text = proxyHostEle.getText();
+            if (text == null) {
+                throw new AxisFault(
+                        ProxyConfiguration.class.getName() + " ProxyHost's value is missing");
+            }
+
+            this.setProxyHost(text);
+
+            if (proxyPortEle != null) {
+                this.setProxyPort(Integer.parseInt(proxyPortEle.getText()));
+            }
+
+            if (proxyUserEle != null) {
+                this.setProxyUser(proxyUserEle.getText());
+            }
+
+            if (proxyPasswordEle != null) {
+                this.setProxyPassword(proxyPasswordEle.getText());
+            }
+
+            if (this.getProxyUser() == null && this.getProxyUser() == null) {
+                proxyCred = new UsernamePasswordCredentials("", "");
+            } else {
+                proxyCred =
+                        new UsernamePasswordCredentials(this.getProxyUser(),
+                                                        this.getProxyPassword());
+            }
+
+            // if the username is in the form "DOMAIN\\user"
+            // then use NTCredentials instead.
+            if (this.getProxyUser() != null) {
+                int domainIndex = this.getProxyUser().indexOf("\\");
+                if (domainIndex > 0) {
+                    String domain = this.getProxyUser().substring(0, domainIndex);
+                    if (this.getProxyUser().length() > domainIndex + 1) {
+                        String user = this.getProxyUser().substring(domainIndex + 1);
+                        proxyCred = new NTCredentials(user,
+                                                      this.getProxyPassword(),
+                                                      this.getProxyHost(),
+                                                      domain);
+                    }
+                }
+            }
+        }
+
+        // Overide the property setting in runtime.
+        HttpTransportProperties.ProxyProperties proxyProperties =
+                (HttpTransportProperties.ProxyProperties) messageContext
+                        .getProperty(HTTPConstants.PROXY);
+
+        if (proxyProperties != null) {
+            String host = proxyProperties.getProxyHostName();
+            if (host == null || host.length() == 0) {
+                throw new AxisFault(ProxyConfiguration.class.getName() +
+                                    " Proxy host is not available. Host is a MUST parameter");
+
+            } else {
+                this.setProxyHost(host);
+            }
+
+
+            this.setProxyPort(proxyProperties.getProxyPort());
+
+            //Setting credentials
+
+            String userName = proxyProperties.getUserName();
+            String password = proxyProperties.getPassWord();
+            String domain = proxyProperties.getDomain();
+
+            if (userName == null && password == null) {
+                proxyCred = new UsernamePasswordCredentials("", "");
+            } else {
+                proxyCred = new UsernamePasswordCredentials(userName, password);
+            }
+
+            if (userName != null && password != null && domain != null) {
+                proxyCred = new NTCredentials(userName, password, host, domain);
+            }
+
+        }
+
+        //Using Java Networking Properties
+
+        String host = System.getProperty(HTTP_PROXY_HOST);
+        if (host != null) {
+            this.setProxyHost(host);
+            proxyCred = new UsernamePasswordCredentials("","");
+        }
+
+        String port = System.getProperty(HTTP_PROXY_PORT);
+
+        if (port != null) {
+            this.setProxyPort(Integer.parseInt(port));
+        }
+
+        if (proxyCred == null) {
+            throw new AxisFault(ProxyConfiguration.class.getName() +
+                                    " Minimum proxy credentials are not set");
+        }
+        httpClient.getState().setProxyCredentials(AuthScope.ANY, proxyCred);
+        config.setProxy(this.getProxyHost(), this.getProxyPort());
+    }
+
+    /**
+     * Check first if the proxy is configured or active.
+     * If yes this will return true. This is not a deep check
+     *
+     * @param messageContext
+     * @return boolean
+     */
+
+    public static boolean isProxyEnabled(MessageContext messageContext, URL targetURL)
+            throws AxisFault {
+
+        boolean state = false;
+
+
+        Parameter param = messageContext.getConfigurationContext().getAxisConfiguration()
+                .getParameter(ATTR_PROXY);
+
+        //If configuration is over ridden
+        Object obj = messageContext.getProperty(HTTPConstants.PROXY);
+
+        //From Java Networking Properties
+        String sp = System.getProperty(HTTP_PROXY_HOST);
+
+        if (param != null || obj != null || sp != null) {
+            state = true;
+        }
+
+        boolean isNonProxyHost = validateNonProxyHosts(targetURL.getHost());
+
+        return state && !isNonProxyHost;
+
+    }
+
+    /**
+     * Validates for names that shouldn't be listered as proxies.
+     * The http.nonProxyHosts can be set to specify the hosts which should be
+     * connected to directly (not through the proxy server).
+     * The value of the http.nonProxyHosts property can be a list of hosts,
+     * each separated by a |; it can also take a regular expression for matches;
+     * for example: *.sfbay.sun.com would match any fully qualified hostname in the sfbay domain.
+     *
+     * For more information refer to : http://java.sun.com/features/2002/11/hilevel_network.html
+     *
+     * false : validation fail : User can use the proxy
+     * true : validation pass ; User can't use the proxy
+     *
+     * @return boolean
+     */
+    public static boolean validateNonProxyHosts(String host) {
+        //From system property http.nonProxyHosts
+        String nonProxyHosts = System.getProperty(HTTP_NON_PROXY_HOSTS);
+        return isHostInNonProxyList(host, nonProxyHosts);
+    }
+    
+    /**
+     * Check if the specified host is in the list of non proxy hosts.
+     *
+     * @param host host name
+     * @param nonProxyHosts string containing the list of non proxy hosts
+     *
+     * @return true/false
+     */
+    public static boolean isHostInNonProxyList(String host, String nonProxyHosts) {
+        if ((nonProxyHosts == null) || (host == null)) {
+            return false;
+        }
+
+        /*
+         * The http.nonProxyHosts system property is a list enclosed in
+         * double quotes with items separated by a vertical bar.
+         */
+        StringTokenizer tokenizer = new StringTokenizer(nonProxyHosts, "|\"");
+
+        while (tokenizer.hasMoreTokens()) {
+            String pattern = tokenizer.nextToken();
+            if (match(pattern, host, false)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Matches a string against a pattern. The pattern contains two special
+     * characters:
+     * '*' which means zero or more characters,
+     *
+     * @param pattern the (non-null) pattern to match against
+     * @param str     the (non-null) string that must be matched against the
+     *                pattern
+     * @param isCaseSensitive
+     *
+     * @return <code>true</code> when the string matches against the pattern,
+     *         <code>false</code> otherwise.
+     */
+    protected static boolean match(String pattern, String str,
+                                   boolean isCaseSensitive) {
+
+        char[] patArr = pattern.toCharArray();
+        char[] strArr = str.toCharArray();
+        int patIdxStart = 0;
+        int patIdxEnd = patArr.length - 1;
+        int strIdxStart = 0;
+        int strIdxEnd = strArr.length - 1;
+        char ch;
+        boolean containsStar = false;
+
+        for (int i = 0; i < patArr.length; i++) {
+            if (patArr[i] == '*') {
+                containsStar = true;
+                break;
+            }
+        }
+        if (!containsStar) {
+
+            // No '*'s, so we make a shortcut
+            if (patIdxEnd != strIdxEnd) {
+                return false;        // Pattern and string do not have the same size
+            }
+            for (int i = 0; i <= patIdxEnd; i++) {
+                ch = patArr[i];
+                if (isCaseSensitive && (ch != strArr[i])) {
+                    return false;    // Character mismatch
+                }
+                if (!isCaseSensitive
+                        && (Character.toUpperCase(ch)
+                        != Character.toUpperCase(strArr[i]))) {
+                    return false;    // Character mismatch
+                }
+            }
+            return true;             // String matches against pattern
+        }
+        if (patIdxEnd == 0) {
+            return true;    // Pattern contains only '*', which matches anything
+        }
+
+        // Process characters before first star
+        while ((ch = patArr[patIdxStart]) != '*'
+                && (strIdxStart <= strIdxEnd)) {
+            if (isCaseSensitive && (ch != strArr[strIdxStart])) {
+                return false;    // Character mismatch
+            }
+            if (!isCaseSensitive
+                    && (Character.toUpperCase(ch)
+                    != Character.toUpperCase(strArr[strIdxStart]))) {
+                return false;    // Character mismatch
+            }
+            patIdxStart++;
+            strIdxStart++;
+        }
+        if (strIdxStart > strIdxEnd) {
+
+            // All characters in the string are used. Check if only '*'s are
+            // left in the pattern. If so, we succeeded. Otherwise failure.
+            for (int i = patIdxStart; i <= patIdxEnd; i++) {
+                if (patArr[i] != '*') {
+                    return false;
+                }
+            }
+            return true;
+        }
+
+        // Process characters after last star
+        while ((ch = patArr[patIdxEnd]) != '*' && (strIdxStart <= strIdxEnd)) {
+            if (isCaseSensitive && (ch != strArr[strIdxEnd])) {
+                return false;    // Character mismatch
+            }
+            if (!isCaseSensitive
+                    && (Character.toUpperCase(ch)
+                    != Character.toUpperCase(strArr[strIdxEnd]))) {
+                return false;    // Character mismatch
+            }
+            patIdxEnd--;
+            strIdxEnd--;
+        }
+        if (strIdxStart > strIdxEnd) {
+
+            // All characters in the string are used. Check if only '*'s are
+            // left in the pattern. If so, we succeeded. Otherwise failure.
+            for (int i = patIdxStart; i <= patIdxEnd; i++) {
+                if (patArr[i] != '*') {
+                    return false;
+                }
+            }
+            return true;
+        }
+
+        // process pattern between stars. padIdxStart and patIdxEnd point
+        // always to a '*'.
+        while ((patIdxStart != patIdxEnd) && (strIdxStart <= strIdxEnd)) {
+            int patIdxTmp = -1;
+
+            for (int i = patIdxStart + 1; i <= patIdxEnd; i++) {
+                if (patArr[i] == '*') {
+                    patIdxTmp = i;
+                    break;
+                }
+            }
+            if (patIdxTmp == patIdxStart + 1) {
+
+                // Two stars next to each other, skip the first one.
+                patIdxStart++;
+                continue;
+            }
+
+            // Find the pattern between padIdxStart & padIdxTmp in str between
+            // strIdxStart & strIdxEnd
+            int patLength = (patIdxTmp - patIdxStart - 1);
+            int strLength = (strIdxEnd - strIdxStart + 1);
+            int foundIdx = -1;
+
+            strLoop:
+            for (int i = 0; i <= strLength - patLength; i++) {
+                for (int j = 0; j < patLength; j++) {
+                    ch = patArr[patIdxStart + j + 1];
+                    if (isCaseSensitive
+                            && (ch != strArr[strIdxStart + i + j])) {
+                        continue strLoop;
+                    }
+                    if (!isCaseSensitive && (Character
+                            .toUpperCase(ch) != Character
+                            .toUpperCase(strArr[strIdxStart + i + j]))) {
+                        continue strLoop;
+                    }
+                }
+                foundIdx = strIdxStart + i;
+                break;
+            }
+            if (foundIdx == -1) {
+                return false;
+            }
+            patIdxStart = patIdxTmp;
+            strIdxStart = foundIdx + patLength;
+        }
+
+        // All characters in the string are used. Check if only '*'s are left
+        // in the pattern. If so, we succeeded. Otherwise failure.
+        for (int i = patIdxStart; i <= patIdxEnd; i++) {
+            if (patArr[i] != '*') {
+                return false;
+            }
+        }
+        return true;
+    }
+    
+    /**
+     * Retrun proxy host
+     *
+     * @return String
+     */
+    public String getProxyHost() {
+        return proxyHost;
+    }
+
+    /**
+     * set proxy host
+     *
+     * @param proxyHost
+     */
+
+    public void setProxyHost(String proxyHost) {
+        this.proxyHost = proxyHost;
+    }
+
+    /**
+     * retrun proxy port
+     *
+     * @return String
+     */
+    public int getProxyPort() {
+        return proxyPort;
+    }
+
+    /**
+     * set proxy port
+     *
+     * @param proxyPort
+     */
+    public void setProxyPort(int proxyPort) {
+        this.proxyPort = proxyPort;
+    }
+
+    /**
+     * return proxy user. Proxy user can be user/domain or user
+     *
+     * @return String
+     */
+    public String getProxyUser() {
+        return proxyUser;
+    }
+
+    /**
+     * get proxy user
+     *
+     * @param proxyUser
+     */
+    public void setProxyUser(String proxyUser) {
+        this.proxyUser = proxyUser;
+    }
+
+    /**
+     * set password
+     *
+     * @return String
+     */
+    public String getProxyPassword() {
+        return proxyPassword;
+    }
+
+    /**
+     * get password
+     *
+     * @param proxyPassword
+     */
+    public void setProxyPassword(String proxyPassword) {
+        this.proxyPassword = proxyPassword;
+    }
+
+
+}

Added: webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/RESTRequestEntity.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/RESTRequestEntity.java?rev=694988&view=auto
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/RESTRequestEntity.java (added)
+++ webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/RESTRequestEntity.java Sat Sep 13 10:22:37 2008
@@ -0,0 +1,136 @@
+/*
+ * 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.OMOutputFormat;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.commons.httpclient.methods.RequestEntity;
+
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLStreamException;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class RESTRequestEntity implements RequestEntity {
+    private byte[] bytes;
+    private String charSetEnc;
+    private boolean chunked;
+    private OMElement element;
+    private MessageContext msgCtxt;
+    private String soapActionString;
+    private OMOutputFormat format;
+
+    public RESTRequestEntity(OMElement element, boolean chunked,
+                             MessageContext msgCtxt,
+                             String charSetEncoding,
+                             String soapActionString,
+                             OMOutputFormat format) {
+        this.element = element;
+        this.chunked = chunked;
+        this.msgCtxt = msgCtxt;
+        this.charSetEnc = charSetEncoding;
+        this.soapActionString = soapActionString;
+        this.format = format;
+    }
+
+    private void handleOMOutput(OutputStream out, boolean doingMTOM)
+            throws XMLStreamException {
+        format.setDoOptimize(doingMTOM);
+        element.serializeAndConsume(out, format);
+    }
+
+    public byte[] writeBytes() throws AxisFault {
+        try {
+            ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
+            if (!format.isOptimized()) {
+                OMOutputFormat format2 = new OMOutputFormat();
+                format2.setCharSetEncoding(charSetEnc);
+                element.serializeAndConsume(bytesOut, format2);
+                return bytesOut.toByteArray();
+            } else {
+                format.setCharSetEncoding(charSetEnc);
+                format.setDoOptimize(true);
+                element.serializeAndConsume(bytesOut, format);
+                return bytesOut.toByteArray();
+            }
+        } catch (XMLStreamException e) {
+            throw AxisFault.makeFault(e);
+        } catch (FactoryConfigurationError e) {
+            throw AxisFault.makeFault(e);
+        }
+    }
+
+    public void writeRequest(OutputStream out) throws IOException {
+        try {
+            if (chunked) {
+                this.handleOMOutput(out, format.isDoingSWA());
+            } else {
+                if (bytes == null) {
+                    bytes = writeBytes();
+                }
+                out.write(bytes);
+            }
+            out.flush();
+        } catch (XMLStreamException e) {
+            throw AxisFault.makeFault(e);
+        } catch (FactoryConfigurationError e) {
+            throw AxisFault.makeFault(e);
+        } catch (IOException e) {
+            throw AxisFault.makeFault(e);
+        }
+    }
+
+    public long getContentLength() {
+        try {
+            if (chunked) {
+                return -1;
+            } else {
+                if (bytes == null) {
+                    bytes = writeBytes();
+                }
+                return bytes.length;
+            }
+        } catch (AxisFault e) {
+            return -1;
+        }
+    }
+
+    public String getContentType() {
+        String encoding = format.getCharSetEncoding();
+        String contentType = format.getContentType();
+        if (encoding != null) {
+            contentType += "; charset=" + encoding;
+        }
+
+        // action header is not mandated in SOAP 1.2. So putting it, if available
+        if (!msgCtxt.isSOAP11() && (soapActionString != null)
+                && !"".equals(soapActionString.trim()) && !"\"\"".equals(soapActionString.trim())) {
+            contentType = contentType + ";action=\"" + soapActionString + "\";";
+        }
+        return contentType;
+    }
+
+    public boolean isRepeatable() {
+        return true;
+    }
+}

Added: webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/RESTRequestEntity2.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/RESTRequestEntity2.java?rev=694988&view=auto
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/RESTRequestEntity2.java (added)
+++ webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/RESTRequestEntity2.java Sat Sep 13 10:22:37 2008
@@ -0,0 +1,51 @@
+/*
+ * 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.commons.httpclient.methods.RequestEntity;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class RESTRequestEntity2 implements RequestEntity {
+    private String contentType;
+    private String postRequestBody;
+
+    public RESTRequestEntity2(String postRequestBody, String contentType) {
+        this.postRequestBody = postRequestBody;
+        this.contentType = contentType;
+    }
+
+    public void writeRequest(OutputStream output) throws IOException {
+        output.write(postRequestBody.getBytes());
+    }
+
+    public long getContentLength() {
+        return this.postRequestBody.getBytes().length;
+    }
+
+    public String getContentType() {
+        return this.contentType;
+    }
+
+    public boolean isRepeatable() {
+        return true;
+    }
+}

Added: webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/ServletBasedOutTransportInfo.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/ServletBasedOutTransportInfo.java?rev=694988&view=auto
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/ServletBasedOutTransportInfo.java (added)
+++ webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/ServletBasedOutTransportInfo.java Sat Sep 13 10:22:37 2008
@@ -0,0 +1,45 @@
+/*
+ * 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.OutTransportInfo;
+
+import javax.servlet.http.HttpServletResponse;
+
+public class ServletBasedOutTransportInfo implements OutTransportInfo {
+    private HttpServletResponse response;
+
+    public ServletBasedOutTransportInfo(HttpServletResponse response) {
+        this.response = response;
+    }
+
+    public void setContentType(String contentType) {
+        response.setContentType(contentType);
+    }
+
+    public void addHeader(String headerName, String headerValue) {
+        response.addHeader(headerName, headerValue);
+    }
+
+    public void setStatus(int status) {
+        response.setStatus(status);
+    }
+}

Added: webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/SimpleHTTPServer.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/SimpleHTTPServer.java?rev=694988&view=auto
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/SimpleHTTPServer.java (added)
+++ webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/SimpleHTTPServer.java Sat Sep 13 10:22:37 2008
@@ -0,0 +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.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.SessionContext;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.description.TransportInDescription;
+import org.apache.axis2.engine.ListenerManager;
+import org.apache.axis2.transport.TransportListener;
+import org.apache.axis2.transport.http.server.HttpFactory;
+import org.apache.axis2.transport.http.server.HttpUtils;
+import org.apache.axis2.transport.http.server.SessionManager;
+import org.apache.axis2.transport.http.server.SimpleHttpServer;
+import org.apache.axis2.util.OptionsParser;
+import org.apache.axis2.util.Utils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+import java.io.File;
+import java.io.IOException;
+import java.net.SocketException;
+import java.util.Iterator;
+
+/**
+ * This is a simple implementation of an HTTP server for processing
+ * SOAP requests via Apache's xml-axis2.
+ * It can be used with no configuration other than the port to listen on, or it can
+ * be configured in detail with an HttpFactory.
+ */
+public class SimpleHTTPServer implements TransportListener {
+
+    private static final Log log = LogFactory.getLog(SimpleHTTPServer.class);
+
+    /**
+     * Embedded commons http core based server
+     */
+    SimpleHttpServer embedded = null;
+    private String localAddress;
+    int port = -1;
+
+    public static int DEFAULT_PORT = 8080;
+
+    private String hostAddress = null;
+
+    protected ConfigurationContext configurationContext;
+    protected HttpFactory httpFactory;
+    private SessionManager sessionManager;
+
+    public SimpleHTTPServer() {
+    }
+
+    /**
+     * Create a SimpleHTTPServer using default HttpFactory settings
+     */
+    public SimpleHTTPServer(ConfigurationContext configurationContext, int port) throws AxisFault {
+        this(new HttpFactory(configurationContext, port));
+    }
+
+    /**
+     * Create a configured SimpleHTTPServer
+     */
+    public SimpleHTTPServer(HttpFactory httpFactory) throws AxisFault {
+        this.httpFactory = httpFactory;
+        this.configurationContext = httpFactory.getConfigurationContext();
+        this.port = httpFactory.getPort();
+        TransportInDescription httpDescription =
+                new TransportInDescription(Constants.TRANSPORT_HTTP);
+        httpDescription.setReceiver(this);
+        httpFactory.getListenerManager().addListener(httpDescription, true);
+        sessionManager = new SessionManager();
+    }
+
+    /**
+     * init method in TransportListener
+     *
+     * @param axisConf
+     * @param transprtIn
+     * @throws AxisFault
+     */
+    public void init(ConfigurationContext axisConf, TransportInDescription transprtIn)
+            throws AxisFault {
+        try {
+            this.configurationContext = axisConf;
+
+            Parameter param = transprtIn.getParameter(PARAM_PORT);
+            if (param != null) {
+                this.port = Integer.parseInt((String) param.getValue());
+            }
+
+            if (httpFactory == null) {
+                httpFactory = new HttpFactory(configurationContext, port);
+            }
+
+            param = transprtIn.getParameter(HOST_ADDRESS);
+            if (param != null) {
+                hostAddress = ((String) param.getValue()).trim();
+            } else {
+                hostAddress = httpFactory.getHostAddress();
+            }
+        } catch (Exception e1) {
+            throw AxisFault.makeFault(e1);
+        }
+    }
+
+    /**
+     * Method main
+     *
+     * @param args
+     * @throws Exception
+     */
+    public static void main(String[] args) throws Exception {
+        int port = DEFAULT_PORT;
+        OptionsParser optionsParser = new OptionsParser(args);
+
+        args = optionsParser.getRemainingArgs();
+        // first check if we should print usage
+        if ((optionsParser.isFlagSet('?') > 0) || (optionsParser.isFlagSet('h') > 0) ||
+            args == null || args.length == 0 || args.length > 3) {
+            printUsage();
+        }
+        String paramPort = optionsParser.isValueSet('p');
+        if (paramPort != null) {
+            port = Integer.parseInt(paramPort);
+        }
+
+        boolean startAllTransports = "all".equals(optionsParser.isValueSet('t'));
+        String repository = optionsParser.isValueSet('r');
+        if (repository == null) {
+            args = optionsParser.getRemainingArgs();
+            if (args != null && args[0] != null && !args[0].equals("")) {
+                repository = args[0];
+            } else {
+                printUsage();
+            }
+        }
+
+        System.out.println("[SimpleHTTPServer] Starting");
+        System.out.println("[SimpleHTTPServer] Using the Axis2 Repository "
+                           + new File(repository).getAbsolutePath());
+        System.out.println("[SimpleHTTPServer] Listening on port " + port);
+        try {
+            ConfigurationContext configctx = ConfigurationContextFactory
+                    .createConfigurationContextFromFileSystem(repository, null);
+            SimpleHTTPServer receiver = new SimpleHTTPServer(configctx, port);
+            Runtime.getRuntime().addShutdownHook(new ShutdownThread(receiver));
+            receiver.start();
+            ListenerManager listenerManager = configctx .getListenerManager();
+            TransportInDescription trsIn = new TransportInDescription(Constants.TRANSPORT_HTTP);
+            trsIn.setReceiver(receiver);
+            if (listenerManager == null) {
+                listenerManager = new ListenerManager();
+                listenerManager.init(configctx);
+            }
+            listenerManager.addListener(trsIn, true);
+
+            // should all transports be started? specified as "-t all"
+            if (startAllTransports) {
+                Iterator iter = configctx.getAxisConfiguration().
+                        getTransportsIn().keySet().iterator();
+                while (iter.hasNext()) {
+                    QName trp = (QName) iter.next();
+                    if (!new QName(Constants.TRANSPORT_HTTP).equals(trp)) {
+                        trsIn = (TransportInDescription)
+                                configctx.getAxisConfiguration().getTransportsIn().get(trp);
+                        listenerManager.addListener(trsIn, false);
+                    }
+                }
+            }
+
+            System.out.println("[SimpleHTTPServer] Started");
+        } catch (Throwable t) {
+            log.fatal("Error starting SimpleHTTPServer", t);
+            System.out.println("[SimpleHTTPServer] Shutting down");
+        }
+    }
+
+    public static void printUsage() {
+        System.out.println("Usage: SimpleHTTPServer [options] -r <repository>");
+        System.out.println(" Opts: -? this message");
+        System.out.println();
+        System.out.println("       -p port :to listen on (default is 8080)");
+        System.out.println(
+                "       -t all  :to start all transports defined in the axis2 configuration");
+        System.exit(1);
+    }
+
+
+    /**
+     * Start this server as a NON-daemon.
+     */
+    public void start() throws AxisFault {
+        try {
+            embedded = new SimpleHttpServer(httpFactory, port);
+            embedded.init();
+            embedded.start();
+        } catch (IOException e) {
+            log.error(e.getMessage(), e);
+            throw AxisFault.makeFault(e);
+        }
+    }
+
+    /**
+     * Stop this server. Can be called safely if the system is already stopped,
+     * or if it was never started.
+     * This will interrupt any pending accept().
+     */
+    public void stop() {
+        System.out.println("[SimpleHTTPServer] Stop called");
+        if (embedded != null) {
+            try {
+                embedded.destroy();
+            } catch (Exception e) {
+                log.error(e.getMessage(), e);
+            }
+        }
+    }
+
+    /**
+     * replyToEPR
+     * If the user has given host address paramter then it gets the high priority and
+     * ERP will be creatd using that
+     * N:B - hostAddress should be a complete url (http://www.myApp.com/ws)
+     *
+     * @param serviceName
+     * @param ip
+     * @return an EndpointReference
+     * @see org.apache.axis2.transport.TransportListener#getEPRForService(String,String)
+     */
+    public EndpointReference[] getEPRsForService(String serviceName, String ip) throws AxisFault {
+        //if host address is present
+        if (hostAddress != null) {
+            if (embedded != null) {
+                String endpointRefernce = hostAddress ;
+                if(configurationContext.getServiceContextPath().startsWith("/")){
+                    endpointRefernce =  endpointRefernce +
+                            configurationContext.getServiceContextPath() + "/" + serviceName;
+                } else {
+                    endpointRefernce = endpointRefernce + '/' +
+                            configurationContext.getServiceContextPath() + "/" + serviceName;
+                }
+                return new EndpointReference[]{new EndpointReference(endpointRefernce + "/")};
+            } else {
+                throw new AxisFault("Unable to generate EPR for the transport : http");
+            }
+        }
+        //if the host address is not present
+        String ipAddress;
+        if (ip != null) {
+            ipAddress = ip;
+        } else {
+            try {
+                if(localAddress==null){
+                    localAddress = Utils.getIpAddress(configurationContext.getAxisConfiguration());
+                }
+                if (localAddress == null) {
+                   ipAddress = "127.0.0.1";
+                 } else {
+                    ipAddress = localAddress;
+                 }
+            } catch (SocketException e) {
+                throw AxisFault.makeFault(e);
+            }
+        }
+        if (embedded != null) {
+            String endpointRefernce = "http://" + ipAddress + ":" + embedded.getPort() ;
+            if(configurationContext.getServiceContextPath().startsWith("/")){
+                endpointRefernce =  endpointRefernce +
+                        configurationContext.getServiceContextPath() + "/" + serviceName;
+            } else {
+                endpointRefernce = endpointRefernce + '/' +
+                        configurationContext.getServiceContextPath() + "/" + serviceName;
+            }
+
+
+            return new EndpointReference[]{new EndpointReference(endpointRefernce + "/")};
+        } else {
+            throw new AxisFault("Unable to generate EPR for the transport : http");
+        }
+    }
+
+    /**
+     * Getter for httpFactory
+     */
+    public HttpFactory getHttpFactory() {
+        return httpFactory;
+    }
+
+    /**
+     * Method getConfigurationContext
+     *
+     * @return the system context
+     */
+    public ConfigurationContext getConfigurationContext() {
+        return configurationContext;
+    }
+
+    /**
+     * replyToEPR
+     * If the user has given host address paramter then it gets the high priority and
+     * ERP will be creatd using that
+     * N:B - hostAddress should be a complte url (http://www.myApp.com/ws)
+     *
+     * @param serviceName
+     * @param ip
+     * @return an EndpointReference
+     * @see org.apache.axis2.transport.TransportListener#getEPRForService(String,String)
+     */
+    public EndpointReference getEPRForService(String serviceName, String ip) throws AxisFault {
+        return getEPRsForService(serviceName, ip)[0];
+    }
+
+    /**
+     * Checks if this HTTP server instance is running.
+     *
+     * @return true/false
+     */
+    public boolean isRunning() {
+        if (embedded == null) {
+            return false;
+        }
+
+        return embedded.isRunning();
+    }
+
+    static class ShutdownThread extends Thread {
+        private SimpleHTTPServer server = null;
+
+        public ShutdownThread(SimpleHTTPServer server) {
+            super();
+            this.server = server;
+        }
+
+        public void run() {
+            System.out.println("[SimpleHTTPServer] Shutting down");
+            server.stop();
+            System.out.println("[SimpleHTTPServer] Shutdown complete");
+        }
+    }
+
+
+    public SessionContext getSessionContext(MessageContext messageContext) {
+        String sessionKey = (String) messageContext.getProperty(HTTPConstants.COOKIE_STRING);
+        return this.sessionManager.getSessionContext(sessionKey);
+    }
+
+    public void destroy() {
+        this.configurationContext = null;
+    }
+}

Added: webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/TransportHeaders.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/TransportHeaders.java?rev=694988&view=auto
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/TransportHeaders.java (added)
+++ webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/TransportHeaders.java Sat Sep 13 10:22:37 2008
@@ -0,0 +1,176 @@
+/*
+ * 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 javax.servlet.http.HttpServletRequest;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Pass-Thru / delayed get and put of the values from HttpServletRequest
+ */
+public class TransportHeaders implements Map {
+    HttpServletRequest req;
+    // This map contains the headers from the request; it will be filled in lazily if needed, 
+    // for performance 
+    HashMap headerMap = null;
+    // This map contains properties that have been put onto the map; it is not populated by values
+    // from the HttpServletRequest.  A null value means the headerMap has been fully populated and
+    // any values that were in localHeaderMap have been migrated to headerMap.
+    HashMap localHeaderMap = new HashMap();
+
+    public TransportHeaders(HttpServletRequest req) {
+        this.req = req;
+    }
+
+    /**
+     * This will fully populate the HashMap with the value from the HttpSerlvetRequest and migrate
+     * any values previously put onto localHeaderMap into the new HashMap.
+     * 
+     * Note this is a bit non-performant, so it is only done if needed.  
+     * If/when it is done, there may be properties that have been set on the localHeaderMap.  
+     * If headerMap must be created due to a call
+     * to size, or isEmpty, or some other method which requires a fully populated map, then any 
+     * previously created entries in the localHeaderMap are migrated to the new hashmap.  
+     * After that localHeaderMap is released and only headerMap is used after that. 
+     */
+    private void init() {
+        headerMap = new HashMap();
+        Enumeration headerNames = req.getHeaderNames();
+
+        while (headerNames.hasMoreElements()) {
+            String key = (String) headerNames.nextElement();
+            String value = req.getHeader(key);
+
+            headerMap.put(key, value);
+        }
+        
+        // Migrate any previously set local properties to the newly created hashmap then release
+        // the local hashmap
+        Set localHeaderSet = localHeaderMap.entrySet();
+        Iterator localHeaderIterator = localHeaderSet.iterator();
+        while (localHeaderIterator.hasNext()) {
+            Map.Entry localHeaderEntry = (Map.Entry) localHeaderIterator.next();
+            headerMap.put(localHeaderEntry.getKey(), localHeaderEntry.getValue());
+        }
+        localHeaderMap = null;
+    }
+
+    public int size() {
+        if (headerMap == null) {
+            init();
+        }
+        return headerMap.size();
+    }
+
+    public void clear() {
+        if (headerMap != null) {
+            headerMap.clear();
+        }
+        if (localHeaderMap != null) {
+            localHeaderMap.clear();
+        }
+    }
+
+    public boolean isEmpty() {
+        if (headerMap == null) {
+            init();
+        }
+        return headerMap.isEmpty();
+    }
+
+    public boolean containsKey(Object key) {
+        if (headerMap == null) {
+            init();
+        }
+        return headerMap.containsKey(key);
+    }
+
+    public boolean containsValue(Object value) {
+        if (headerMap == null) {
+            init();
+        }
+        return headerMap.containsValue(value);
+    }
+
+    public Collection values() {
+        if (headerMap == null) {
+            init();
+        }
+        return headerMap.values();
+    }
+
+    public void putAll(Map t) {
+        if (headerMap == null) {
+            init();
+        }
+        headerMap.putAll(t);
+    }
+
+    public Set entrySet() {
+        if (headerMap == null) {
+            init();
+        }
+        return headerMap.entrySet();
+    }
+
+    public Set keySet() {
+        if (headerMap == null) {
+            init();
+        }
+        return headerMap.keySet();
+    }
+
+    public Object get(Object key) {
+        // If there is a local map, look there first.
+        if (localHeaderMap != null) {
+            Object returnValue = null;
+            returnValue = localHeaderMap.get(key);
+            if (returnValue != null) {
+                return returnValue;
+            }
+        }
+        if (headerMap == null) {
+            return req.getHeader((String) key);
+        }
+        return headerMap.get(key);
+    }
+
+    public Object remove(Object key) {
+        if (headerMap == null) {
+            init();
+        }
+        return headerMap.remove(key);
+    }
+
+    public Object put(Object key, Object value) {
+        if (localHeaderMap != null) {
+            return localHeaderMap.put(key, value);
+        }
+        if (headerMap == null) {
+            init();
+        }
+        return headerMap.put(key, value);
+    }
+}

Added: webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpConnection.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpConnection.java?rev=694988&view=auto
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpConnection.java (added)
+++ webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpConnection.java Sat Sep 13 10:22:37 2008
@@ -0,0 +1,50 @@
+/*
+ * 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.server;
+
+import org.apache.http.HttpConnection;
+import org.apache.http.HttpException;
+import org.apache.http.HttpInetConnection;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public interface AxisHttpConnection extends HttpConnection, HttpInetConnection {
+
+    HttpRequest receiveRequest()
+        throws HttpException, IOException;
+    
+    InputStream getInputStream();
+    
+    void sendResponse(HttpResponse response) 
+        throws HttpException, IOException;    
+    
+    OutputStream getOutputStream();
+    
+    void flush()
+        throws IOException;
+    
+    void reset()
+        throws IOException;
+
+}

Added: webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpConnectionImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpConnectionImpl.java?rev=694988&view=auto
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpConnectionImpl.java (added)
+++ webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpConnectionImpl.java Sat Sep 13 10:22:37 2008
@@ -0,0 +1,284 @@
+/*
+ * 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.server;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.HeaderIterator;
+import org.apache.http.HttpConnectionMetrics;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpVersion;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.entity.ContentLengthStrategy;
+import org.apache.http.impl.DefaultHttpRequestFactory;
+import org.apache.http.impl.entity.StrictContentLengthStrategy;
+import org.apache.http.impl.io.ChunkedInputStream;
+import org.apache.http.impl.io.ChunkedOutputStream;
+import org.apache.http.impl.io.ContentLengthInputStream;
+import org.apache.http.impl.io.ContentLengthOutputStream;
+import org.apache.http.impl.io.HttpRequestParser;
+import org.apache.http.impl.io.HttpResponseWriter;
+import org.apache.http.impl.io.IdentityInputStream;
+import org.apache.http.impl.io.IdentityOutputStream;
+import org.apache.http.impl.io.SocketInputBuffer;
+import org.apache.http.impl.io.SocketOutputBuffer;
+import org.apache.http.io.HttpMessageParser;
+import org.apache.http.io.HttpMessageWriter;
+import org.apache.http.io.SessionInputBuffer;
+import org.apache.http.io.SessionOutputBuffer;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.SocketException;
+
+public class AxisHttpConnectionImpl implements AxisHttpConnection {
+
+    private static final Log HEADERLOG =
+        LogFactory.getLog("org.apache.axis2.transport.http.server.wire");
+
+    private final Socket socket;
+    private final SessionOutputBuffer outbuffer;
+    private final SessionInputBuffer inbuffer;
+    private final HttpMessageParser requestParser;
+    private final HttpMessageWriter responseWriter;
+    private final ContentLengthStrategy contentLenStrategy;
+
+    private OutputStream out = null;
+    private InputStream in = null;
+    
+    public AxisHttpConnectionImpl(final Socket socket, final HttpParams params) 
+            throws IOException {
+        super();
+        if (socket == null) {
+            throw new IllegalArgumentException("Socket may not be null"); 
+        }
+        if (params == null) {
+            throw new IllegalArgumentException("HTTP parameters may not be null"); 
+        }
+        socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params));
+        socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params));
+        
+        int linger = HttpConnectionParams.getLinger(params);
+        if (linger >= 0) {
+            socket.setSoLinger(linger > 0, linger);
+        }
+        
+        int buffersize = HttpConnectionParams.getSocketBufferSize(params);
+        this.socket = socket;
+        this.outbuffer = new SocketOutputBuffer(socket, buffersize, params); 
+        this.inbuffer = new SocketInputBuffer(socket, buffersize, params); 
+        this.contentLenStrategy = new StrictContentLengthStrategy();
+        this.requestParser = new HttpRequestParser(
+                this.inbuffer, null, new DefaultHttpRequestFactory(), params);
+        this.responseWriter = new HttpResponseWriter(
+                this.outbuffer, null, params);
+    }
+
+    public void close() throws IOException {
+        this.outbuffer.flush();
+        try {
+            this.socket.shutdownOutput();
+        } catch (IOException ignore) {
+        }
+        try {
+            this.socket.shutdownInput();
+        } catch (IOException ignore) {
+        }
+        this.socket.close();
+    }
+
+    public boolean isOpen() {
+        return !this.socket.isClosed();
+    }
+
+    public boolean isStale() {
+        try {
+            this.inbuffer.isDataAvailable(1);
+            return false;
+        } catch (IOException ex) {
+            return true;
+        }
+    }
+
+    public void shutdown() throws IOException {
+        Socket tmpsocket = this.socket;
+        if (tmpsocket != null) {
+            tmpsocket.close();
+        }
+    }
+
+    public HttpRequest receiveRequest() throws HttpException, IOException {
+        HttpRequest request = (HttpRequest) this.requestParser.parse();
+        if (HEADERLOG.isDebugEnabled()) {
+            HEADERLOG.debug(">> " + request.getRequestLine().toString());
+            for (HeaderIterator it = request.headerIterator(); it.hasNext(); ) {
+                HEADERLOG.debug(">> " + it.nextHeader().toString());
+            }
+        }
+        
+        // Prepare input stream
+        this.in = null;
+        if (request instanceof HttpEntityEnclosingRequest) {
+            long len = this.contentLenStrategy.determineLength(request);
+            if (len == ContentLengthStrategy.CHUNKED) {
+                this.in = new ChunkedInputStream(this.inbuffer);
+            } else if (len == ContentLengthStrategy.IDENTITY) {
+                this.in = new IdentityInputStream(this.inbuffer);                            
+            } else {
+                this.in = new ContentLengthInputStream(inbuffer, len);
+            }
+        }
+        return request;
+    }
+    
+    public void sendResponse(final HttpResponse response) 
+            throws HttpException, IOException {
+        if (response == null) {
+            throw new IllegalArgumentException("HTTP response may not be null");
+        }
+
+        if (HEADERLOG.isDebugEnabled()) {
+            HEADERLOG.debug("<< " + response.getStatusLine().toString());
+            for (HeaderIterator it = response.headerIterator(); it.hasNext(); ) {
+                HEADERLOG.debug("<< " + it.nextHeader().toString());
+            }
+        }
+        
+        this.responseWriter.write(response);
+
+        // Prepare output stream
+        this.out = null;
+        ProtocolVersion ver = response.getStatusLine().getProtocolVersion();
+        HttpEntity entity = response.getEntity();
+        if (entity != null) {
+            long len = entity.getContentLength();
+            if (entity.isChunked() && ver.greaterEquals(HttpVersion.HTTP_1_1)) {
+                this.out = new ChunkedOutputStream(this.outbuffer);
+            } else if (len >= 0) {
+                this.out = new ContentLengthOutputStream(this.outbuffer, len);
+            } else {
+                this.out = new IdentityOutputStream(this.outbuffer); 
+            }
+        } else {
+            this.outbuffer.flush();
+        }
+    }
+    
+    public InputStream getInputStream() {
+        return this.in;
+    }
+
+    public OutputStream getOutputStream() {
+        return this.out;
+    }
+    
+    public void flush() throws IOException {
+        if (this.out != null) {
+            this.out.flush();
+        } else {
+            this.outbuffer.flush();
+        }
+    }
+
+    public void reset() throws IOException {
+        if (this.in != null) {
+            this.in.close();
+            this.in = null;
+        }
+        if (this.out != null) {
+            this.out.flush();
+            this.out.close();
+            this.out = null;
+        }
+    }
+    
+    public int getSocketTimeout() {
+        try {
+            return this.socket.getSoTimeout();
+        } catch (SocketException ex) {
+            return -1;
+        }
+    }
+
+    public void setSocketTimeout(int timeout) {
+        try {
+            this.socket.setSoTimeout(timeout);
+        } catch (SocketException ex) {
+        }
+    }
+
+    public InetAddress getLocalAddress() {
+        if (this.socket != null) {
+            return this.socket.getLocalAddress();
+        } else {
+            return null;
+        }
+    }
+
+    public int getLocalPort() {
+        if (this.socket != null) {
+            return this.socket.getLocalPort();
+        } else {
+            return -1;
+        }
+    }
+
+    public InetAddress getRemoteAddress() {
+        if (this.socket != null) {
+            return this.socket.getInetAddress();
+        } else {
+            return null;
+        }
+    }
+
+    public int getRemotePort() {
+        if (this.socket != null) {
+            return this.socket.getPort();
+        } else {
+            return -1;
+        }
+    }
+
+    public HttpConnectionMetrics getMetrics() {
+        return null;
+    }
+
+    public String toString() {
+        StringBuffer buffer = new StringBuffer();
+        buffer.append("[");
+        if (isOpen()) {
+            buffer.append(this.socket.getInetAddress());
+        } else {
+            buffer.append("closed");
+        }
+        buffer.append("]");
+        return buffer.toString();
+    }
+
+}

Added: webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpRequest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpRequest.java?rev=694988&view=auto
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpRequest.java (added)
+++ webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpRequest.java Sat Sep 13 10:22:37 2008
@@ -0,0 +1,36 @@
+/*
+ * 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.server;
+
+import org.apache.http.HttpMessage;
+
+import java.io.InputStream;
+
+public interface AxisHttpRequest extends HttpMessage {
+
+    String getMethod();
+    
+    String getRequestURI();
+    
+    String getContentType();
+    
+    InputStream getInputStream();
+    
+}

Added: webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpRequestImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpRequestImpl.java?rev=694988&view=auto
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpRequestImpl.java (added)
+++ webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpRequestImpl.java Sat Sep 13 10:22:37 2008
@@ -0,0 +1,163 @@
+/*
+ * 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.server;
+
+import org.apache.http.Header;
+import org.apache.http.HeaderIterator;
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.ExecutionContext;
+import org.apache.http.protocol.HTTP;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpProcessor;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class AxisHttpRequestImpl implements AxisHttpRequest {
+
+    private final HttpRequest request;
+    private final AxisHttpConnection conn;
+    private final HttpProcessor httpproc;
+    private final HttpContext context;
+    
+    public AxisHttpRequestImpl(
+            final AxisHttpConnection conn,
+            final HttpRequest request, 
+            final HttpProcessor httpproc,
+            final HttpContext context) {
+        super();
+        if (conn == null) {
+            throw new IllegalArgumentException("HTTP connection may not be null");
+        }
+        if (request == null) {
+            throw new IllegalArgumentException("HTTP request may not be null");
+        }
+        if (httpproc == null) {
+            throw new IllegalArgumentException("HTTP processor may not be null");
+        }
+        if (context == null) {
+            throw new IllegalArgumentException("HTTP context may not be null");
+        }
+        this.request = request;
+        this.conn = conn;
+        this.httpproc = httpproc;
+        this.context = context;
+    }
+    
+    public void prepare() throws IOException, HttpException {
+        this.context.setAttribute(ExecutionContext.HTTP_CONNECTION, this.conn);
+        this.context.setAttribute(ExecutionContext.HTTP_REQUEST, this.request);
+        
+        this.httpproc.process(this.request, this.context);
+    }
+
+    public String getMethod() {
+        return this.request.getRequestLine().getMethod();
+    }
+
+    public String getRequestURI() {
+        return this.request.getRequestLine().getUri();
+    }
+
+    public ProtocolVersion getProtocolVersion() {
+        return this.request.getRequestLine().getProtocolVersion();
+    }
+
+    public String getContentType() {
+        Header header = this.request.getFirstHeader(HTTP.CONTENT_TYPE);
+        if (header != null) {
+            return header.getValue();
+        } else {
+            return null;
+        }
+    }
+
+    public InputStream getInputStream() {
+        return this.conn.getInputStream();
+    }
+
+    public void addHeader(final Header header) {
+        this.request.addHeader(header);
+    }
+
+    public void addHeader(final String name, final String value) {
+        this.request.addHeader(name, value);
+    }
+
+    public boolean containsHeader(final String name) {
+        return this.request.containsHeader(name);
+    }
+
+    public Header[] getAllHeaders() {
+        return this.request.getAllHeaders();
+    }
+
+    public Header getFirstHeader(final String name) {
+        return this.request.getFirstHeader(name);
+    }
+
+    public Header[] getHeaders(String name) {
+        return this.request.getHeaders(name);
+    }
+
+    public Header getLastHeader(final String name) {
+        return this.request.getLastHeader(name);
+    }
+
+    public HeaderIterator headerIterator() {
+        return this.request.headerIterator();
+    }
+
+    public HeaderIterator headerIterator(final String name) {
+        return this.request.headerIterator(name);
+    }
+
+    public void removeHeader(final Header header) {
+        this.request.removeHeader(header);
+    }
+
+    public void removeHeaders(final String name) {
+        this.request.removeHeaders(name);
+    }
+
+    public void setHeader(final Header header) {
+        this.request.setHeader(header);
+    }
+
+    public void setHeader(final String name, final String value) {
+        this.request.setHeader(name, value);
+    }
+
+    public void setHeaders(Header[] headers) {
+        this.request.setHeaders(headers);
+    }
+
+    public HttpParams getParams() {
+        return this.request.getParams();
+    }
+
+    public void setParams(final HttpParams params) {
+        this.request.setParams(params);
+    }
+    
+}

Added: webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpResponse.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpResponse.java?rev=694988&view=auto
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpResponse.java (added)
+++ webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpResponse.java Sat Sep 13 10:22:37 2008
@@ -0,0 +1,38 @@
+/*
+ * 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.server;
+
+import org.apache.http.HttpMessage;
+
+import java.io.OutputStream;
+
+public interface AxisHttpResponse extends HttpMessage {
+
+    void setStatus(int sc);
+
+    void sendError(int sc, String msg);
+    
+    void sendError(int sc);
+
+    void setContentType(String contentType);
+    
+    OutputStream getOutputStream();
+    
+}

Added: webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpResponseImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpResponseImpl.java?rev=694988&view=auto
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpResponseImpl.java (added)
+++ webservices/commons/trunk/modules/transport/modules/http/src/org/apache/axis2/transport/http/server/AxisHttpResponseImpl.java Sat Sep 13 10:22:37 2008
@@ -0,0 +1,251 @@
+/*
+ * 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.server;
+
+import org.apache.axis2.transport.OutTransportInfo;
+import org.apache.http.Header;
+import org.apache.http.HeaderIterator;
+import org.apache.http.HttpException;
+import org.apache.http.HttpResponse;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.entity.BasicHttpEntity;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.ExecutionContext;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpProcessor;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class AxisHttpResponseImpl implements AxisHttpResponse, OutTransportInfo {
+
+    private final HttpResponse response;
+    private final AxisHttpConnection conn;
+    private final HttpProcessor httpproc;
+    private final HttpContext context;
+    
+    private AutoCommitOutputStream outstream;
+    private String contentType;
+    
+    private volatile boolean commited;
+    
+    public AxisHttpResponseImpl(
+            final AxisHttpConnection conn,
+            final HttpResponse response, 
+            final HttpProcessor httpproc,
+            final HttpContext context) {
+        super();
+        if (response == null) {
+            throw new IllegalArgumentException("HTTP response may not be null");
+        }
+        if (conn == null) {
+            throw new IllegalArgumentException("HTTP connection may not be null");
+        }
+        if (httpproc == null) {
+            throw new IllegalArgumentException("HTTP processor may not be null");
+        }
+        if (context == null) {
+            throw new IllegalArgumentException("HTTP context may not be null");
+        }
+        this.response = response;
+        this.conn = conn;
+        this.httpproc = httpproc;
+        this.context = context;
+    }
+
+    private void assertNotCommitted() {
+        if (this.commited) {
+            throw new IllegalStateException("Response already committed");
+        }
+    }
+    
+    public boolean isCommitted() {
+        return this.commited;
+    }
+    
+    public void commit() throws IOException, HttpException {
+        if (this.commited) {
+            return;
+        }
+        this.commited = true;
+        
+        this.context.setAttribute(ExecutionContext.HTTP_CONNECTION, this.conn);
+        this.context.setAttribute(ExecutionContext.HTTP_RESPONSE, this.response);
+        
+        BasicHttpEntity entity = new BasicHttpEntity();
+        entity.setChunked(true);
+        entity.setContentType(this.contentType);
+        
+        this.response.setEntity(entity);
+        
+        this.httpproc.process(this.response, this.context);
+        this.conn.sendResponse(this.response);
+    }
+    
+    public OutputStream getOutputStream() {
+        if (this.outstream == null) {
+            this.outstream = new AutoCommitOutputStream();
+        }
+        return this.outstream;
+    }
+
+    public void sendError(int sc, final String msg) {
+        assertNotCommitted();
+        ProtocolVersion ver = this.response.getProtocolVersion();
+        this.response.setStatusLine(ver, sc, msg);
+    }
+
+    public void sendError(int sc) {
+        assertNotCommitted();
+        this.response.setStatusCode(sc);
+    }
+
+    public void setStatus(int sc) {
+        assertNotCommitted();
+        this.response.setStatusCode(sc);
+    }
+
+    public void setContentType(final String contentType) {
+        assertNotCommitted();
+        this.contentType = contentType;
+    }
+
+    public ProtocolVersion getProtocolVersion() {
+        return this.response.getProtocolVersion();
+    }
+
+    public void addHeader(final Header header) {
+        assertNotCommitted();
+        this.response.addHeader(header);
+    }
+
+    public void addHeader(final String name, final String value) {
+        assertNotCommitted();
+        this.response.addHeader(name, value);
+    }
+
+    public boolean containsHeader(final String name) {
+        return this.response.containsHeader(name);
+    }
+
+    public Header[] getAllHeaders() {
+        return this.response.getAllHeaders();
+    }
+
+    public Header getFirstHeader(final String name) {
+        return this.response.getFirstHeader(name);
+    }
+
+    public Header[] getHeaders(String name) {
+        return this.response.getHeaders(name);
+    }
+
+    public Header getLastHeader(final String name) {
+        return this.response.getLastHeader(name);
+    }
+
+    public HeaderIterator headerIterator() {
+        return this.response.headerIterator();
+    }
+
+    public HeaderIterator headerIterator(String name) {
+        return this.response.headerIterator(name);
+    }
+
+    public void removeHeader(final Header header) {
+        assertNotCommitted();
+        this.response.removeHeader(header);
+    }
+
+    public void removeHeaders(final String name) {
+        assertNotCommitted();
+        this.response.removeHeaders(name);
+    }
+
+    public void setHeader(final Header header) {
+        assertNotCommitted();
+        this.response.setHeader(header);
+    }
+
+    public void setHeader(final String name, final String value) {
+        assertNotCommitted();
+        this.response.setHeader(name, value);
+    }
+
+    public void setHeaders(Header[] headers) {
+        assertNotCommitted();
+        this.response.setHeaders(headers);
+    }
+
+    public HttpParams getParams() {
+        return this.response.getParams();
+    }
+
+    public void setParams(final HttpParams params) {
+        this.response.setParams(params);
+    }
+    
+    class AutoCommitOutputStream extends OutputStream {
+
+        private OutputStream out;
+        
+        public AutoCommitOutputStream() {
+            super();
+        }
+
+        private void ensureCommitted() throws IOException {
+            try {
+                commit();
+            } catch (HttpException ex) {
+                throw (IOException) new IOException().initCause(ex);  
+            }
+            if (this.out == null) {
+                this.out = conn.getOutputStream();
+            }
+        }
+        
+        public void close() throws IOException {
+            ensureCommitted();
+            this.out.close();
+        }
+
+        public void write(final byte[] b, int off, int len) throws IOException {
+            ensureCommitted();
+            this.out.write(b, off, len);
+        }
+
+        public void write(final byte[] b) throws IOException {
+            ensureCommitted();
+            this.out.write(b);
+        }
+
+        public void write(int b) throws IOException {
+            ensureCommitted();
+            this.out.write(b);
+        }
+        
+        public void flush() throws IOException {
+            ensureCommitted();
+            this.out.flush();
+        }
+
+    }
+    
+}