You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by de...@apache.org on 2008/06/24 13:07:10 UTC

svn commit: r671127 [3/8] - in /webservices/axis2/trunk/java: ./ modules/addressing/ modules/clustering/ modules/clustering/test/org/apache/axis2/clustering/ modules/integration/ modules/integration/test-resources/deployment/ modules/integration/test/o...

Modified: webservices/axis2/trunk/java/modules/osgi/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/osgi/pom.xml?rev=671127&r1=671126&r2=671127&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/osgi/pom.xml (original)
+++ webservices/axis2/trunk/java/modules/osgi/pom.xml Tue Jun 24 04:07:03 2008
@@ -158,6 +158,12 @@
             <version>1.0.0</version>
             <scope>provided</scope>
         </dependency>
+<dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>axis2-transports</artifactId>
+            <version>${version}</version>
+        </dependency>
+
         <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.osgi.compendium</artifactId>

Modified: webservices/axis2/trunk/java/modules/saaj/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/saaj/pom.xml?rev=671127&r1=671126&r2=671127&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/saaj/pom.xml (original)
+++ webservices/axis2/trunk/java/modules/saaj/pom.xml Tue Jun 24 04:07:03 2008
@@ -42,6 +42,12 @@
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-saaj_1.3_spec</artifactId>
         </dependency>
+<dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>axis2-transports</artifactId>
+            <version>${version}</version>
+        </dependency>
+
         <dependency>
             <groupId>org.apache.axis2</groupId>
             <artifactId>axis2-kernel</artifactId>

Added: webservices/axis2/trunk/java/modules/transports/pom.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transports/pom.xml?rev=671127&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/transports/pom.xml (added)
+++ webservices/axis2/trunk/java/modules/transports/pom.xml Tue Jun 24 04:07:03 2008
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.axis2</groupId>
+        <artifactId>axis2-parent</artifactId>
+        <version>SNAPSHOT</version>
+        <relativePath>../parent/pom.xml</relativePath>
+    </parent>
+    <artifactId>axis2-transports</artifactId>
+    <name>Apache Axis2 - Transports</name>
+    <description>This inclues all the available transports in Axis2 </description>
+    <dependencies>
+         <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>axis2-kernel</artifactId>
+            <version>${version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-ws-metadata_2.0_spec</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>commons-httpclient</groupId>
+            <artifactId>commons-httpclient</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>commons-fileupload</groupId>
+            <artifactId>commons-fileupload</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpcore</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${stax.impl.groupid}</groupId>
+            <artifactId>${stax.impl.artifact}</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+        </dependency>
+
+        <!-- Smack Jabber client libraries to be included -->
+        <dependency>
+            <groupId>org.igniterealtime</groupId>
+            <artifactId>smack</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>commons-lang</groupId>
+            <artifactId>commons-lang</artifactId>
+        </dependency>
+    </dependencies>
+    <build>
+        <sourceDirectory>src</sourceDirectory>
+        <testSourceDirectory>test</testSourceDirectory>
+        <resources>
+            <resource>
+                <directory>conf</directory>
+                <excludes>
+                    <exclude>**/*.properties</exclude>
+                </excludes>
+                <filtering>false</filtering>
+            </resource>
+            <resource>
+                <directory>src</directory>
+                <excludes>
+                    <exclude>**/*.java</exclude>
+                </excludes>
+            </resource>
+        </resources>
+    </build>
+</project>

Added: webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/AbstractAgent.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/AbstractAgent.java?rev=671127&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/AbstractAgent.java (added)
+++ webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/AbstractAgent.java Tue Jun 24 04:07:03 2008
@@ -0,0 +1,168 @@
+/*
+ * 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.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * The AbstractAgent acts as a simple dispatcher for http requests.
+ * It delegates incoming requests to processXyz methods while Xyz
+ * is the part of the request uri past last /.
+ */
+public class AbstractAgent {
+    protected static final String DEFAULT_INDEX_JSP = "index.jsp";
+
+    private static final String METHOD_PREFIX = "process";
+    private static final Log log = LogFactory.getLog(AbstractAgent.class);
+
+    protected transient Map operationCache = new HashMap();
+    protected transient ConfigurationContext configContext;
+
+    public AbstractAgent(ConfigurationContext aConfigContext) {
+        configContext = aConfigContext;
+        preloadMethods();
+    }
+
+    public void handle(HttpServletRequest httpServletRequest,
+                       HttpServletResponse httpServletResponse)
+            throws IOException, ServletException {
+
+
+        String requestURI = httpServletRequest.getRequestURI();
+
+        String operation;
+        int i = requestURI.lastIndexOf('/');
+        if (i < 0) {
+            processUnknown(httpServletRequest, httpServletResponse);
+            return;
+        } else if (i == requestURI.length() - 1) {
+            processIndex(httpServletRequest, httpServletResponse);
+            return;
+        } else {
+            operation = requestURI.substring(i + 1);
+        }
+
+
+        Method method = (Method) operationCache.get(operation.toLowerCase());
+        if (method != null) {
+            try {
+                method.invoke(this, new Object[]{httpServletRequest, httpServletResponse});
+            } catch (Exception e) {
+                log.warn("Error dispatching request " + requestURI, e);
+                httpServletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+            }
+        } else {
+            processUnknown(httpServletRequest, httpServletResponse);
+        }
+    }
+
+    /**
+     * Callback method for index page. Forwards to {@link DEFAULT_INDEX_JSP} by default.
+     *
+     * @param httpServletRequest  The incoming request.
+     * @param httpServletResponse The outgoing response.
+     */
+    protected void processIndex(HttpServletRequest httpServletRequest,
+                                HttpServletResponse httpServletResponse)
+            throws IOException, ServletException {
+        renderView(DEFAULT_INDEX_JSP, httpServletRequest, httpServletResponse);
+    }
+
+    /**
+     * Callback method for unknown/unsupported requests. Returns HTTP Status 404 by default.
+     *
+     * @param httpServletRequest  The incoming request.
+     * @param httpServletResponse The outgoing response.
+     */
+
+    protected void processUnknown(HttpServletRequest httpServletRequest,
+                                  HttpServletResponse httpServletResponse)
+            throws IOException, ServletException {
+        httpServletResponse
+                .sendError(HttpServletResponse.SC_NOT_FOUND, httpServletRequest.getRequestURI());
+    }
+
+
+    protected void renderView(String jspName,
+                              HttpServletRequest httpServletRequest,
+                              HttpServletResponse httpServletResponse)
+            throws IOException, ServletException {
+        httpServletResponse.setContentType("text/html");
+        try {
+            httpServletRequest.getRequestDispatcher(Constants.AXIS_WEB_CONTENT_ROOT + jspName)
+                    .include(httpServletRequest, httpServletResponse);
+        } catch (Throwable t) {
+            log.info("Old Servlet API :" + t);
+        }
+    }
+
+    private void preloadMethods() {
+        Class clazz = getClass();
+        while (clazz != null && !clazz.equals(Object.class)) {
+            examineMethods(clazz.getDeclaredMethods());
+            clazz = clazz.getSuperclass();
+        }
+    }
+
+    private void examineMethods(Method[] aDeclaredMethods) {
+        for (int i = 0; i < aDeclaredMethods.length; i++) {
+            Method method = aDeclaredMethods[i];
+
+            Class[] parameterTypes = method.getParameterTypes();
+            if (
+                    (Modifier.isProtected(method.getModifiers()) ||
+                            Modifier.isPublic(method.getModifiers())) &&
+                            method.getName().startsWith(METHOD_PREFIX) &&
+                            parameterTypes.length == 2 &&
+                            parameterTypes[0].equals(HttpServletRequest.class) &&
+                            parameterTypes[1].equals(HttpServletResponse.class)) {
+
+                String key = method.getName().substring(METHOD_PREFIX.length()).toLowerCase();
+
+                // ensure we don't overwrite existing method with superclass method
+                if (!operationCache.containsKey(key)) {
+                    operationCache.put(key, method);
+                }
+            }
+        }
+    }
+
+    protected void populateSessionInformation(HttpServletRequest req) {
+        HashMap services = configContext.getAxisConfiguration().getServices();
+        try {
+            req.getSession().setAttribute(Constants.SERVICE_MAP, services);
+            req.getSession().setAttribute(Constants.SERVICE_PATH, configContext.getServicePath());
+        } catch (Throwable t){
+            log.info("Old Servlet API :" + t);    
+        }
+    }
+}

Added: webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/AbstractHTTPSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/AbstractHTTPSender.java?rev=671127&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/AbstractHTTPSender.java (added)
+++ webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/AbstractHTTPSender.java Tue Jun 24 04:07:03 2008
@@ -0,0 +1,607 @@
+/*
+ * 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.OMAttribute;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.OperationContext;
+import org.apache.axis2.description.TransportOutDescription;
+import org.apache.axis2.i18n.Messages;
+import org.apache.axis2.transport.MessageFormatter;
+import org.apache.axis2.transport.TransportUtils;
+import org.apache.axis2.util.JavaUtils;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HeaderElement;
+import org.apache.commons.httpclient.HostConfiguration;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpConnectionManager;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpMethodBase;
+import org.apache.commons.httpclient.HttpVersion;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.commons.httpclient.NTCredentials;
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthPolicy;
+import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.protocol.Protocol;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.zip.GZIPInputStream;
+
+public abstract class AbstractHTTPSender {
+    protected static final String ANONYMOUS = "anonymous";
+    protected static final String PROXY_HOST_NAME = "proxy_host";
+    protected static final String PROXY_PORT = "proxy_port";
+    protected boolean chunked = false;
+    protected String httpVersion = HTTPConstants.HEADER_PROTOCOL_11;
+    private static final Log log = LogFactory.getLog(AbstractHTTPSender.class);
+
+    protected static final String PROTOCOL_HTTP = "http";
+    protected static final String PROTOCOL_HTTPS = "https";
+
+    /**
+     * proxydiscription
+     */
+    protected TransportOutDescription proxyOutSetting = null;
+    protected OMOutputFormat format = new OMOutputFormat();
+
+    /**
+     * isAllowedRetry will be using to check where the
+     * retry should be allowed or not.
+     */
+    protected boolean isAllowedRetry = false;
+
+    public void setChunked(boolean chunked) {
+        this.chunked = chunked;
+    }
+
+    public void setHttpVersion(String version) throws AxisFault {
+        if (version != null) {
+            if (HTTPConstants.HEADER_PROTOCOL_11.equals(version)) {
+                this.httpVersion = HTTPConstants.HEADER_PROTOCOL_11;
+            } else if (HTTPConstants.HEADER_PROTOCOL_10.equals(version)) {
+                this.httpVersion = HTTPConstants.HEADER_PROTOCOL_10;
+                // chunked is not possible with HTTP/1.0
+                this.chunked = false;
+            } else {
+                throw new AxisFault(
+                        "Parameter " + HTTPConstants.PROTOCOL_VERSION
+                                + " Can have values only HTTP/1.0 or HTTP/1.1");
+            }
+        }
+    }
+
+    /**
+     * Collect the HTTP header information and set them in the message context
+     *
+     * @param method HttpMethodBase from which to get information
+     * @param msgContext the MessageContext in which to place the information... OR NOT!
+     * @throws AxisFault if problems occur
+     */
+    protected void obtainHTTPHeaderInformation(HttpMethodBase method,
+                                               MessageContext msgContext) throws AxisFault {
+        // Set RESPONSE properties onto the REQUEST message context.  They will need to be copied off the request context onto
+        // the response context elsewhere, for example in the OutInOperationClient.
+        Map transportHeaders = new CommonsTransportHeaders(method.getResponseHeaders());
+        msgContext.setProperty(MessageContext.TRANSPORT_HEADERS, transportHeaders);
+        msgContext.setProperty(HTTPConstants.MC_HTTP_STATUS_CODE, new Integer(method.getStatusCode()));
+        Header header = method.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
+
+        if (header != null) {
+            HeaderElement[] headers = header.getElements();
+            MessageContext inMessageContext = msgContext.getOperationContext().getMessageContext(
+                    WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+
+            Object contentType = header.getValue();
+            Object charSetEnc = null;
+
+            for (int i = 0; i < headers.length; i++) {
+                NameValuePair charsetEnc = headers[i].getParameterByName(
+                        HTTPConstants.CHAR_SET_ENCODING);
+                if (charsetEnc != null) {
+                    charSetEnc = charsetEnc.getValue();
+                }
+            }
+
+            if (inMessageContext != null) {
+                inMessageContext
+                        .setProperty(Constants.Configuration.CONTENT_TYPE, contentType);
+                inMessageContext
+                        .setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
+            } else {
+
+                // Transport details will be stored in a HashMap so that anybody interested can
+                // retrieve them
+                HashMap transportInfoMap = new HashMap();
+                transportInfoMap.put(Constants.Configuration.CONTENT_TYPE, contentType);
+                transportInfoMap.put(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
+
+                //the HashMap is stored in the outgoing message.
+                msgContext.setProperty(Constants.Configuration.TRANSPORT_INFO_MAP,
+                                       transportInfoMap);
+            }
+        }
+
+        String sessionCookie = null;
+        // Process old style headers first
+        Header[] cookieHeaders = method.getResponseHeaders(HTTPConstants.HEADER_SET_COOKIE);
+        String customCoookiId = (String) msgContext.getProperty(Constants.CUSTOM_COOKIE_ID);
+        for (int i = 0; i < cookieHeaders.length; i++) {
+            HeaderElement[] elements = cookieHeaders[i].getElements();
+            for (int e = 0; e < elements.length; e++) {
+                HeaderElement element = elements[e];
+                if (Constants.SESSION_COOKIE.equalsIgnoreCase(element.getName()) ||
+                        Constants.SESSION_COOKIE_JSESSIONID.equalsIgnoreCase(element.getName())) {
+                    sessionCookie = processCookieHeader(element);
+                }
+                if (customCoookiId != null && customCoookiId.equalsIgnoreCase(element.getName())) {
+                    sessionCookie = processCookieHeader(element);
+                }
+            }
+        }
+        // Overwrite old style cookies with new style ones if present
+        cookieHeaders = method.getResponseHeaders(HTTPConstants.HEADER_SET_COOKIE2);
+        for (int i = 0; i < cookieHeaders.length; i++) {
+            HeaderElement[] elements = cookieHeaders[i].getElements();
+            for (int e = 0; e < elements.length; e++) {
+                HeaderElement element = elements[e];
+                if (Constants.SESSION_COOKIE.equalsIgnoreCase(element.getName()) ||
+                        Constants.SESSION_COOKIE_JSESSIONID.equalsIgnoreCase(element.getName())) {
+                    sessionCookie = processCookieHeader(element);
+                }
+                if(customCoookiId!=null&&customCoookiId.equalsIgnoreCase(element.getName())){
+                    sessionCookie = processCookieHeader(element);
+                }
+            }
+        }
+
+        if (sessionCookie != null) {
+            msgContext.getServiceContext().setProperty(HTTPConstants.COOKIE_STRING, sessionCookie);
+        }
+    }
+
+    private String processCookieHeader(HeaderElement element) {
+        String cookie = element.getName() + "=" + element.getValue();
+        NameValuePair[] parameters =  element.getParameters();
+        for (int j = 0; parameters != null && j < parameters.length; j++) {
+            NameValuePair parameter = parameters[j];
+            cookie = cookie + "; " + parameter.getName() + "=" + parameter.getValue();
+        }
+        return cookie;
+    }
+
+    protected void processResponse(HttpMethodBase httpMethod,
+                                   MessageContext msgContext)
+            throws IOException {
+        obtainHTTPHeaderInformation(httpMethod, msgContext);
+
+        InputStream in = httpMethod.getResponseBodyAsStream();
+        if (in == null) {
+            throw new AxisFault(Messages.getMessage("canNotBeNull", "InputStream"));
+        }
+        Header contentEncoding =
+                httpMethod.getResponseHeader(HTTPConstants.HEADER_CONTENT_ENCODING);
+        if (contentEncoding != null) {
+            if (contentEncoding.getValue().
+                    equalsIgnoreCase(HTTPConstants.COMPRESSION_GZIP)) {
+                in = new GZIPInputStream(in);
+            } else {
+                throw new AxisFault("HTTP :" + "unsupported content-encoding of '"
+                        + contentEncoding.getValue() + "' found");
+            }
+        }
+
+        OperationContext opContext = msgContext.getOperationContext();
+        if (opContext != null) {
+            opContext.setProperty(MessageContext.TRANSPORT_IN, in);
+        }
+    }
+
+    public abstract void send(MessageContext msgContext, URL url, String soapActionString)
+            throws IOException;
+
+    /**
+     * getting host configuration to support standard http/s, proxy and NTLM support
+     *
+     * @param client active HttpClient
+     * @param msgCtx active MessageContext
+     * @param targetURL the target URL
+     * @return a HostConfiguration set up with proxy information
+     * @throws AxisFault if problems occur
+     */
+    protected HostConfiguration getHostConfiguration(HttpClient client,
+                                                     MessageContext msgCtx,
+                                                     URL targetURL)throws AxisFault {
+
+        boolean isAuthenticationEnabled = isAuthenticationEnabled(msgCtx);
+        int port = targetURL.getPort();
+
+        String protocol = targetURL.getProtocol();
+        if (port == -1) {
+            if (PROTOCOL_HTTP.equals(protocol)) {
+                port = 80;
+            } else if (PROTOCOL_HTTPS.equals(protocol)) {
+                port = 443;
+            }
+
+        }
+
+        // to see the host is a proxy and in the proxy list - available in axis2.xml
+        HostConfiguration config = new HostConfiguration();
+
+        // one might need to set his own socket factory. Let's allow that case as well.
+        Protocol protocolHandler =
+                (Protocol)msgCtx.getOptions().getProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER);
+
+        // setting the real host configuration
+        // I assume the 90% case, or even 99% case will be no protocol handler case.
+        if (protocolHandler == null) {
+            config.setHost(targetURL.getHost(), port, targetURL.getProtocol());
+        } else {
+            config.setHost(targetURL.getHost(), port, protocolHandler);
+        }
+
+        if (isAuthenticationEnabled) {
+            // Basic, Digest, NTLM and custom authentications.
+            this.setAuthenticationInfo(client, msgCtx, config);
+        }
+        // proxy configuration
+
+        if (ProxyConfiguration.isProxyEnabled(msgCtx,targetURL)) {
+            log.debug("ProxyConfiguration");
+            ProxyConfiguration proxyConfiguration = new ProxyConfiguration();
+            proxyConfiguration.configure(msgCtx,client,config);
+        }
+
+        return config;
+    }
+
+    protected boolean isAuthenticationEnabled(MessageContext msgCtx) {
+        return (msgCtx.getProperty(HTTPConstants.AUTHENTICATE) != null);
+    }
+
+    /*
+    This will handle server Authentication, It could be either NTLM, Digest or Basic Authentication.
+    Apart from that user can change the priory or add a custom authentication scheme.
+    */
+    protected void setAuthenticationInfo(HttpClient agent,
+                                         MessageContext msgCtx,
+                                         HostConfiguration config) throws AxisFault {
+        HttpTransportProperties.Authenticator authenticator;
+        Object obj = msgCtx.getProperty(HTTPConstants.AUTHENTICATE);
+        if (obj != null) {
+            if (obj instanceof HttpTransportProperties.Authenticator) {
+                authenticator = (HttpTransportProperties.Authenticator) obj;
+
+                String username = authenticator.getUsername();
+                String password = authenticator.getPassword();
+                String host = authenticator.getHost();
+                String domain = authenticator.getDomain();
+
+                int port = authenticator.getPort();
+                String realm = authenticator.getRealm();
+
+                /* If retrying is available set it first */
+                isAllowedRetry = authenticator.isAllowedRetry();
+
+                Credentials creds;
+
+                agent.getParams()
+                        .setAuthenticationPreemptive(authenticator.getPreemptiveAuthentication());
+
+                if (host != null) {
+                    if (domain != null) {
+                        /*Credentials for NTLM Authentication*/
+                        creds = new NTCredentials(username, password, host, domain);
+                    } else {
+                        /*Credentials for Digest and Basic Authentication*/
+                        creds = new UsernamePasswordCredentials(username, password);
+                    }
+                    agent.getState().setCredentials(new AuthScope(host, port, realm), creds);
+                } else {
+                    if (domain != null) {
+                        /*Credentials for NTLM Authentication when host is ANY_HOST*/
+                        creds = new NTCredentials(username, password, AuthScope.ANY_HOST, domain);
+                        agent.getState().setCredentials(
+                                new AuthScope(AuthScope.ANY_HOST, port, realm), creds);
+                    } else {
+                        /*Credentials only for Digest and Basic Authentication*/
+                        creds = new UsernamePasswordCredentials(username, password);
+                        agent.getState().setCredentials(new AuthScope(AuthScope.ANY), creds);
+                    }
+                }
+                /* Customizing the priority Order */
+                List schemes = authenticator.getAuthSchemes();
+                if (schemes != null && schemes.size() > 0) {
+                    List authPrefs = new ArrayList(3);
+                    for (int i = 0; i < schemes.size(); i++) {
+                        if (schemes.get(i) instanceof AuthPolicy) {
+                            authPrefs.add(schemes.get(i));
+                            continue;
+                        }
+                        String scheme = (String) schemes.get(i);
+                        if (HttpTransportProperties.Authenticator.BASIC.equals(scheme)) {
+                            authPrefs.add(AuthPolicy.BASIC);
+                        } else if (HttpTransportProperties.Authenticator.NTLM.equals(scheme)) {
+                            authPrefs.add(AuthPolicy.NTLM);
+                        } else if (HttpTransportProperties.Authenticator.DIGEST.equals(scheme)) {
+                            authPrefs.add(AuthPolicy.DIGEST);
+                        }
+                    }
+                    agent.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY,
+                            authPrefs);
+                }
+
+            } else {
+                throw new AxisFault("HttpTransportProperties.Authenticator class cast exception");
+            }
+        }
+
+    }
+
+    /**
+     * Method used to copy all the common properties
+     *
+     * @param msgContext       - The messageContext of the request message
+     * @param url              - The target URL
+     * @param httpMethod       - The http method used to send the request
+     * @param httpClient       - The httpclient used to send the request
+     * @param soapActionString - The soap action atring of the request message
+     * @return MessageFormatter - The messageFormatter for the relavent request message
+     * @throws AxisFault - Thrown in case an exception occurs
+     */
+    protected MessageFormatter populateCommonProperties(MessageContext msgContext, URL url,
+                                                      HttpMethodBase httpMethod,
+                                                      HttpClient httpClient,
+                                                      String soapActionString)
+            throws AxisFault {
+
+        if (isAuthenticationEnabled(msgContext)) {
+            httpMethod.setDoAuthentication(true);
+        }
+
+        MessageFormatter messageFormatter = TransportUtils.getMessageFormatter(
+                msgContext);
+
+        url = messageFormatter.getTargetAddress(msgContext, format, url);
+
+        httpMethod.setPath(url.getPath());
+
+        httpMethod.setQueryString(url.getQuery());
+
+        httpMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
+                                    messageFormatter.getContentType(msgContext, format,
+                                                                    soapActionString));
+
+        httpMethod.setRequestHeader(HTTPConstants.HEADER_HOST, url.getHost());
+
+        if (msgContext.getOptions() != null && msgContext.getOptions().isManageSession()) {
+            // setting the cookie in the out path
+            Object cookieString = msgContext.getProperty(HTTPConstants.COOKIE_STRING);
+
+            if (cookieString != null) {
+                StringBuffer buffer = new StringBuffer();
+                buffer.append(cookieString);
+                httpMethod.setRequestHeader(HTTPConstants.HEADER_COOKIE, buffer.toString());
+            }
+        }
+
+        if (httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10)) {
+            httpClient.getParams().setVersion(HttpVersion.HTTP_1_0);
+        }
+        return messageFormatter;
+    }
+
+    /**
+     * This is used to get the dynamically set time out values from the
+     * message context. If the values are not available or invalid then
+     * the default values or the values set by the configuration will be used
+     *
+     * @param msgContext the active MessageContext
+     * @param httpClient
+     */
+    protected void initializeTimeouts(MessageContext msgContext, HttpClient httpClient) {
+        // If the SO_TIMEOUT of CONNECTION_TIMEOUT is set by dynamically the
+        // override the static config
+        Integer tempSoTimeoutProperty =
+                (Integer) msgContext.getProperty(HTTPConstants.SO_TIMEOUT);
+        Integer tempConnTimeoutProperty =
+                (Integer) msgContext
+                        .getProperty(HTTPConstants.CONNECTION_TIMEOUT);
+        long timeout = msgContext.getOptions().getTimeOutInMilliSeconds();
+
+        if (tempConnTimeoutProperty != null) {
+            int connectionTimeout = tempConnTimeoutProperty.intValue();
+            // timeout for initial connection
+            httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(connectionTimeout);
+        } else {
+            // set timeout in client
+            if (timeout > 0) {
+                httpClient.getHttpConnectionManager().getParams().setConnectionTimeout((int) timeout);
+            }
+        }
+
+        if (tempSoTimeoutProperty != null) {
+            int soTimeout = tempSoTimeoutProperty.intValue();
+            // SO_TIMEOUT -- timeout for blocking reads
+            httpClient.getHttpConnectionManager().getParams().setSoTimeout(soTimeout);
+            httpClient.getParams().setSoTimeout(soTimeout);
+        } else {
+            // set timeout in client
+            if (timeout > 0) {
+                httpClient.getHttpConnectionManager().getParams().setSoTimeout((int) timeout);
+                httpClient.getParams().setSoTimeout((int) timeout);
+            }
+        }
+    }
+
+    public void setFormat(OMOutputFormat format) {
+        this.format = format;
+    }
+
+    protected HttpClient getHttpClient(MessageContext msgContext) {
+        HttpClient httpClient;
+        Object reuse = msgContext.getOptions().getProperty(HTTPConstants.REUSE_HTTP_CLIENT);
+        if (reuse == null) {
+            reuse = msgContext.getConfigurationContext().getProperty(HTTPConstants.REUSE_HTTP_CLIENT);
+        }
+        if (reuse != null && JavaUtils.isTrueExplicitly(reuse)) {
+            httpClient = (HttpClient) msgContext.getOptions().getProperty(HTTPConstants.CACHED_HTTP_CLIENT);
+            if (httpClient == null) {
+                httpClient = (HttpClient) msgContext.getConfigurationContext()
+                        .getProperty(HTTPConstants.CACHED_HTTP_CLIENT);
+            }
+            if (httpClient != null)
+                return httpClient;
+            MultiThreadedHttpConnectionManager connectionManager =
+                new MultiThreadedHttpConnectionManager();
+            httpClient = new HttpClient(connectionManager);
+            msgContext.getConfigurationContext()
+                .setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
+        } else {
+            HttpConnectionManager connManager =
+                    (HttpConnectionManager) msgContext.getProperty(
+                            HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER);
+            if (connManager == null) {
+                connManager =
+                        (HttpConnectionManager) msgContext.getProperty(
+                                HTTPConstants.MUTTITHREAD_HTTP_CONNECTION_MANAGER);
+            }
+            if(connManager != null){
+                httpClient = new HttpClient(connManager);
+            } else {
+                //Multi threaded http connection manager has set as the default 
+                connManager = new MultiThreadedHttpConnectionManager();
+                httpClient = new HttpClient(connManager);
+            }
+        }
+
+        // Get the timeout values set in the runtime
+        initializeTimeouts(msgContext, httpClient);
+        return httpClient;
+    }
+
+    protected void executeMethod(HttpClient httpClient, MessageContext msgContext, URL url,
+                                 HttpMethod method) throws IOException {
+        HostConfiguration config = this.getHostConfiguration(httpClient, msgContext, url);
+
+        msgContext.setProperty(HTTPConstants.HTTP_METHOD, method);
+
+        // set the custom headers, if available
+        addCustomHeaders(method, msgContext);
+
+        // add compression headers if needed
+        if (msgContext.isPropertyTrue(HTTPConstants.MC_ACCEPT_GZIP)) {
+            method.addRequestHeader(HTTPConstants.HEADER_ACCEPT_ENCODING,
+                    HTTPConstants.COMPRESSION_GZIP);
+        }
+
+        if (msgContext.isPropertyTrue(HTTPConstants.MC_GZIP_REQUEST)) {
+            method.addRequestHeader(HTTPConstants.HEADER_CONTENT_ENCODING,
+                    HTTPConstants.COMPRESSION_GZIP);
+        }
+
+        String cookiePolicy = (String) msgContext.getProperty(HTTPConstants.COOKIE_POLICY);
+        if (cookiePolicy != null) {
+            method.getParams().setCookiePolicy(cookiePolicy);   
+        }
+        httpClient.executeMethod(config, method);
+    }
+
+    public void addCustomHeaders(HttpMethod method, MessageContext msgContext) {
+
+        boolean isCustomUserAgentSet = false;
+        // set the custom headers, if available
+        Object httpHeadersObj = msgContext.getProperty(HTTPConstants.HTTP_HEADERS);
+        if (httpHeadersObj != null) {
+            if (httpHeadersObj instanceof ArrayList) {
+                ArrayList httpHeaders = (ArrayList) httpHeadersObj;
+                Header header;
+                for (int i = 0; i < httpHeaders.size(); i++) {
+                    header = (Header) httpHeaders.get(i);
+                    if (HTTPConstants.HEADER_USER_AGENT.equals(header.getName())) {
+                        isCustomUserAgentSet = true;
+                    }
+                    method.addRequestHeader(header);
+                }
+    
+            }
+            if (httpHeadersObj instanceof Map) {
+                Map httpHeaders = (Map) httpHeadersObj;
+                for (Iterator iterator = httpHeaders.entrySet().iterator(); iterator.hasNext();) {
+                    Map.Entry entry  = (Map.Entry) iterator.next();
+                    String key = (String) entry.getKey();
+                    String value = (String) entry.getValue();
+                    if (HTTPConstants.HEADER_USER_AGENT.equals(key)) {
+                        isCustomUserAgentSet = true;
+                    }
+                    method.addRequestHeader(key, value);
+                }
+            }
+        }
+
+        if (!isCustomUserAgentSet) {
+            String userAgentString = getUserAgent(msgContext);
+            method.setRequestHeader(HTTPConstants.HEADER_USER_AGENT, userAgentString);
+        }
+
+    }
+
+    private String getUserAgent(MessageContext messageContext) {
+        String userAgentString = "Axis2";
+        boolean locked = false;
+        if (messageContext.getParameter(HTTPConstants.USER_AGENT) != null) {
+            OMElement userAgentElement =
+                    messageContext.getParameter(HTTPConstants.USER_AGENT).getParameterElement();
+            userAgentString = userAgentElement.getText().trim();
+            OMAttribute lockedAttribute = userAgentElement.getAttribute(new QName("locked"));
+            if (lockedAttribute != null) {
+                if (lockedAttribute.getAttributeValue().equalsIgnoreCase("true")) {
+                    locked = true;
+                }
+            }
+        }
+        // Runtime overing part
+        if (!locked) {
+            if (messageContext.getProperty(HTTPConstants.USER_AGENT) != null) {
+                userAgentString = (String) messageContext.getProperty(HTTPConstants.USER_AGENT);
+            }
+        }
+
+        return userAgentString;
+    }
+}

Added: webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/AdminAgent.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/AdminAgent.java?rev=671127&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/AdminAgent.java (added)
+++ webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/AdminAgent.java Tue Jun 24 04:07:03 2008
@@ -0,0 +1,627 @@
+/*
+ * 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.context.ConfigurationContext;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.context.ServiceGroupContext;
+import org.apache.axis2.deployment.util.PhasesInfo;
+import org.apache.axis2.description.AxisModule;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.FileItemFactory;
+import org.apache.commons.fileupload.RequestContext;
+import org.apache.commons.fileupload.disk.DiskFileItemFactory;
+import org.apache.commons.fileupload.servlet.ServletFileUpload;
+import org.apache.commons.fileupload.servlet.ServletRequestContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.namespace.QName;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Provides methods to process axis2 admin requests.
+ */
+public class AdminAgent extends AbstractAgent {
+    private static final Log log = LogFactory.getLog(AbstractAgent.class);
+    /**
+     * Field LIST_MULTIPLE_SERVICE_JSP_NAME
+     */
+    private static final String LIST_SERVICE_GROUP_JSP = "ListServiceGroup.jsp";
+    private static final String LIST_SERVICES_JSP_NAME = "listService.jsp";
+    private static final String LIST_SINGLE_SERVICES_JSP_NAME = "listSingleService.jsp";
+    private static final String SELECT_SERVICE_JSP_NAME = "SelectService.jsp";
+    private static final String IN_ACTIVATE_SERVICE_JSP_NAME = "InActivateService.jsp";
+    private static final String ACTIVATE_SERVICE_JSP_NAME = "ActivateService.jsp";
+
+    /**
+     * Field LIST_SINGLE_SERVICE_JSP_NAME
+     */
+    private static final String LIST_PHASES_JSP_NAME = "viewphases.jsp";
+    private static final String LIST_GLOABLLY_ENGAGED_MODULES_JSP_NAME = "globalModules.jsp";
+    private static final String LIST_AVAILABLE_MODULES_JSP_NAME = "listModules.jsp";
+    private static final String ENGAGING_MODULE_TO_SERVICE_JSP_NAME = "engagingtoaservice.jsp";
+    private static final String ENGAGING_MODULE_TO_SERVICE_GROUP_JSP_NAME =
+            "EngageToServiceGroup.jsp";
+    private static final String ENGAGING_MODULE_GLOBALLY_JSP_NAME = "engagingglobally.jsp";
+    public static final String ADMIN_JSP_NAME = "admin.jsp";
+    private static final String VIEW_GLOBAL_HANDLERS_JSP_NAME = "ViewGlobalHandlers.jsp";
+    private static final String VIEW_SERVICE_HANDLERS_JSP_NAME = "ViewServiceHandlers.jsp";
+    private static final String SERVICE_PARA_EDIT_JSP_NAME = "ServiceParaEdit.jsp";
+    private static final String ENGAGE_TO_OPERATION_JSP_NAME = "engagingtoanoperation.jsp";
+    private static final String LOGIN_JSP_NAME = "Login.jsp";
+
+    private File serviceDir;
+
+    public AdminAgent(ConfigurationContext aConfigContext) {
+        super(aConfigContext);
+        try {
+            if (configContext.getAxisConfiguration().getRepository() != null) {
+                File repoDir =
+                        new File(configContext.getAxisConfiguration().getRepository().getFile());
+                serviceDir = new File(repoDir, "services");
+                if (!serviceDir.exists()) {
+                    serviceDir.mkdirs();
+                }
+            }
+        } catch (Exception e) {
+            log.info(e.getMessage(), e);
+        } catch (Throwable e) {
+            log.error(e.getMessage(), e);
+        }
+    }
+
+    public void handle(HttpServletRequest httpServletRequest,
+                       HttpServletResponse httpServletResponse)
+            throws IOException, ServletException {
+
+        // We forward to login page if axis2 security is enabled
+        // and the user is not authorized
+        // TODO Fix workaround for login test
+        if (axisSecurityEnabled() && authorizationRequired(httpServletRequest)) {
+            renderView(LOGIN_JSP_NAME, httpServletRequest, httpServletResponse);
+        } else {
+            super.handle(httpServletRequest, httpServletResponse);
+        }
+    }
+
+    protected void processIndex(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        renderView(ADMIN_JSP_NAME, req, res);
+    }
+
+    // supported web operations
+
+    protected void processUpload(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        String hasHotDeployment =
+                (String) configContext.getAxisConfiguration().getParameterValue("hotdeployment");
+        String hasHotUpdate =
+                (String) configContext.getAxisConfiguration().getParameterValue("hotupdate");
+        req.setAttribute("hotDeployment", (hasHotDeployment.equals("true")) ? "enabled"
+                : "disabled");
+        req.setAttribute("hotUpdate", (hasHotUpdate.equals("true")) ? "enabled" : "disabled");
+        RequestContext reqContext = new ServletRequestContext(req);
+
+        boolean isMultipart = ServletFileUpload.isMultipartContent(reqContext);
+        if (isMultipart) {
+
+            try {
+                //Create a factory for disk-based file items
+                FileItemFactory factory = new DiskFileItemFactory();
+                //Create a new file upload handler
+                ServletFileUpload upload = new ServletFileUpload(factory);
+                List items = upload.parseRequest(req);
+                // Process the uploaded items
+                Iterator iter = items.iterator();
+                while (iter.hasNext()) {
+                    FileItem item = (FileItem) iter.next();
+                    if (!item.isFormField()) {
+
+                        String fileName = item.getName();
+                        String fileExtesion = fileName;
+                        fileExtesion = fileExtesion.toLowerCase();
+                        if (!(fileExtesion.endsWith(".jar") || fileExtesion.endsWith(".aar"))) {
+                            req.setAttribute("status", "failure");
+                            req.setAttribute("cause", "Unsupported file type " + fileExtesion);
+                        } else {
+
+                            String fileNameOnly;
+                            if (fileName.indexOf("\\") < 0) {
+                                fileNameOnly =
+                                        fileName.substring(fileName.lastIndexOf("/") + 1, fileName
+                                                .length());
+                            } else {
+                                fileNameOnly =
+                                        fileName.substring(fileName.lastIndexOf("\\") + 1, fileName
+                                                .length());
+                            }
+
+                            File uploadedFile = new File(serviceDir, fileNameOnly);
+                            item.write(uploadedFile);
+                            req.setAttribute("status", "success");
+                            req.setAttribute("filename", fileNameOnly);
+                        }
+                    }
+                }
+            } catch (Exception e) {
+                req.setAttribute("status", "failure");
+                req.setAttribute("cause", e.getMessage());
+
+            }
+        }
+        renderView("upload.jsp", req, res);
+    }
+
+
+    protected void processLogin(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        String username = req.getParameter("userName");
+        String password = req.getParameter("password");
+
+        if ((username == null) || (password == null) || username.trim().length() == 0
+                || password.trim().length() == 0) {
+            req.setAttribute("errorMessage", "Invalid auth credentials!");
+            renderView(LOGIN_JSP_NAME, req, res);
+            return;
+        }
+
+        String adminUserName = (String) configContext.getAxisConfiguration().getParameter(
+                Constants.USER_NAME).getValue();
+        String adminPassword = (String) configContext.getAxisConfiguration().getParameter(
+                Constants.PASSWORD).getValue();
+
+        if (username.equals(adminUserName) && password.equals(adminPassword)) {
+            req.getSession().setAttribute(Constants.LOGGED, "Yes");
+            renderView(ADMIN_JSP_NAME, req, res);
+        } else {
+            req.setAttribute("errorMessage", "Invalid auth credentials!");
+            renderView(LOGIN_JSP_NAME, req, res);
+        }
+    }
+
+    protected void processEditServicePara(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        String serviceName = req.getParameter("axisService");
+        if (req.getParameter("changePara") != null) {
+            AxisService service = configContext.getAxisConfiguration().getService(serviceName);
+            if (service != null) {
+                ArrayList service_para = service.getParameters();
+
+                for (int i = 0; i < service_para.size(); i++) {
+                    Parameter parameter = (Parameter) service_para.get(i);
+                    String para = req.getParameter(serviceName + "_" + parameter.getName());
+                    service.addParameter(new Parameter(parameter.getName(), para));
+                }
+
+                for (Iterator iterator = service.getOperations(); iterator.hasNext();) {
+                    AxisOperation axisOperation = (AxisOperation) iterator.next();
+                    String op_name = axisOperation.getName().getLocalPart();
+                    ArrayList operation_para = axisOperation.getParameters();
+
+                    for (int i = 0; i < operation_para.size(); i++) {
+                        Parameter parameter = (Parameter) operation_para.get(i);
+                        String para = req.getParameter(op_name + "_" + parameter.getName());
+
+                        axisOperation.addParameter(new Parameter(parameter.getName(), para));
+                    }
+                }
+            }
+            res.setContentType("text/html");
+            req.setAttribute("status", "Parameters Changed Successfully.");
+            req.getSession().removeAttribute(Constants.SERVICE);
+        } else {
+            AxisService serviceTemp =
+                    configContext.getAxisConfiguration().getServiceForActivation(serviceName);
+            if (serviceTemp.isActive()) {
+
+                if (serviceName != null) {
+                    req.getSession().setAttribute(Constants.SERVICE,
+                                                  configContext.getAxisConfiguration().getService(
+                                                          serviceName));
+                }
+            } else {
+                req.setAttribute("status", "Service " + serviceName + " is not an active service" +
+                        ". \n Only parameters of active services can be edited.");
+            }
+        }
+        renderView(SERVICE_PARA_EDIT_JSP_NAME, req, res);
+    }
+
+    protected void processEngagingGlobally(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        HashMap modules = configContext.getAxisConfiguration().getModules();
+
+        req.getSession().setAttribute(Constants.MODULE_MAP, modules);
+
+        String moduleName = req.getParameter("modules");
+
+        req.getSession().setAttribute(Constants.ENGAGE_STATUS, null);
+
+        if (moduleName != null) {
+            try {
+                configContext.getAxisConfiguration().engageModule(moduleName);
+                req.getSession().setAttribute(Constants.ENGAGE_STATUS,
+                                              moduleName + " module engaged globally successfully");
+            } catch (AxisFault axisFault) {
+                req.getSession().setAttribute(Constants.ENGAGE_STATUS, axisFault.getMessage());
+            }
+        }
+
+        req.getSession().setAttribute("modules", null);
+        renderView(ENGAGING_MODULE_GLOBALLY_JSP_NAME, req, res);
+
+    }
+
+    protected void processListOperations(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        HashMap modules = configContext.getAxisConfiguration().getModules();
+
+        req.getSession().setAttribute(Constants.MODULE_MAP, modules);
+
+        String moduleName = req.getParameter("modules");
+
+        req.getSession().setAttribute(Constants.ENGAGE_STATUS, null);
+        req.getSession().setAttribute("modules", null);
+
+        String serviceName = req.getParameter("axisService");
+
+        if (serviceName != null) {
+            req.getSession().setAttribute("service", serviceName);
+        } else {
+            serviceName = (String) req.getSession().getAttribute("service");
+        }
+
+        req.getSession().setAttribute(
+                Constants.OPERATION_MAP,
+                configContext.getAxisConfiguration().getService(serviceName).getOperations());
+        req.getSession().setAttribute(Constants.ENGAGE_STATUS, null);
+
+        String operationName = req.getParameter("axisOperation");
+
+        if ((serviceName != null) && (moduleName != null) && (operationName != null)) {
+            try {
+                AxisOperation od = configContext.getAxisConfiguration().getService(
+                        serviceName).getOperation(new QName(operationName));
+
+                od.engageModule(
+                        configContext.getAxisConfiguration().getModule(moduleName));
+                req.getSession().setAttribute(Constants.ENGAGE_STATUS,
+                                              moduleName
+                                                      +
+                                                      " module engaged to the operation successfully");
+            } catch (AxisFault axisFault) {
+                req.getSession().setAttribute(Constants.ENGAGE_STATUS, axisFault.getMessage());
+            }
+        }
+
+        req.getSession().setAttribute("operation", null);
+        renderView(ENGAGE_TO_OPERATION_JSP_NAME, req, res);
+    }
+
+    protected void processEngageToService(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        HashMap modules = configContext.getAxisConfiguration().getModules();
+
+        req.getSession().setAttribute(Constants.MODULE_MAP, modules);
+        populateSessionInformation(req);
+
+        String moduleName = req.getParameter("modules");
+
+        req.getSession().setAttribute(Constants.ENGAGE_STATUS, null);
+        req.getSession().setAttribute("modules", null);
+
+        String serviceName = req.getParameter("axisService");
+
+        req.getSession().setAttribute(Constants.ENGAGE_STATUS, null);
+
+        if ((serviceName != null) && (moduleName != null)) {
+            try {
+                configContext.getAxisConfiguration().getService(serviceName).engageModule(
+                        configContext.getAxisConfiguration().getModule(moduleName));
+                req.getSession().setAttribute(Constants.ENGAGE_STATUS,
+                                              moduleName
+                                                      +
+                                                      " module engaged to the service successfully");
+            } catch (AxisFault axisFault) {
+                req.getSession().setAttribute(Constants.ENGAGE_STATUS, axisFault.getMessage());
+            }
+        }
+
+        req.getSession().setAttribute("axisService", null);
+        renderView(ENGAGING_MODULE_TO_SERVICE_JSP_NAME, req, res);
+    }
+
+    protected void processEngageToServiceGroup(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        HashMap modules = configContext.getAxisConfiguration().getModules();
+
+        req.getSession().setAttribute(Constants.MODULE_MAP, modules);
+
+        Iterator services = configContext.getAxisConfiguration().getServiceGroups();
+
+        req.getSession().setAttribute(Constants.SERVICE_GROUP_MAP, services);
+
+        String moduleName = req.getParameter("modules");
+
+        req.getSession().setAttribute(Constants.ENGAGE_STATUS, null);
+        req.getSession().setAttribute("modules", null);
+
+        String serviceName = req.getParameter("axisService");
+
+        req.getSession().setAttribute(Constants.ENGAGE_STATUS, null);
+
+        if ((serviceName != null) && (moduleName != null)) {
+            configContext.getAxisConfiguration().getServiceGroup(serviceName).engageModule(
+                    configContext.getAxisConfiguration().getModule(moduleName));
+            req.getSession().setAttribute(Constants.ENGAGE_STATUS,
+                                          moduleName
+                                                  +
+                                                  " module engaged to the service group successfully");
+        }
+
+        req.getSession().setAttribute("axisService", null);
+        renderView(ENGAGING_MODULE_TO_SERVICE_GROUP_JSP_NAME, req, res);
+    }
+
+
+    protected void processLogout(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        req.getSession().invalidate();
+        renderView("index.jsp", req, res);
+    }
+
+    protected void processviewServiceGroupConetxt(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        String type = req.getParameter("TYPE");
+        String sgID = req.getParameter("ID");
+        ServiceGroupContext sgContext = configContext.getServiceGroupContext(sgID);
+        req.getSession().setAttribute("ServiceGroupContext",sgContext);
+        req.getSession().setAttribute("TYPE",type);
+        req.getSession().setAttribute("ConfigurationContext",configContext);
+        renderView("viewServiceGroupContext.jsp", req, res);
+    }
+
+    protected void processviewServiceContext(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        String type = req.getParameter("TYPE");
+        String sgID = req.getParameter("PID");
+        String ID = req.getParameter("ID");
+        ServiceGroupContext sgContext = configContext.getServiceGroupContext(sgID);
+        if (sgContext != null) {
+            AxisService service = sgContext.getDescription().getService(ID);
+            ServiceContext serviceContext = sgContext.getServiceContext(service);
+            req.setAttribute("ServiceContext",serviceContext);
+            req.setAttribute("TYPE",type);
+        } else {
+            req.setAttribute("ServiceContext",null);
+            req.setAttribute("TYPE",type);
+        }
+        renderView("viewServiceContext.jsp", req, res);
+    }
+
+    protected void processSelectServiceParaEdit(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        populateSessionInformation(req);
+        req.getSession().setAttribute(Constants.SELECT_SERVICE_TYPE, "SERVICE_PARAMETER");
+        renderView(SELECT_SERVICE_JSP_NAME, req, res);
+    }
+
+    protected void processListOperation(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        populateSessionInformation(req);
+        req.getSession().setAttribute(Constants.SELECT_SERVICE_TYPE, "MODULE");
+
+        renderView(SELECT_SERVICE_JSP_NAME, req, res);
+    }
+
+    protected void processActivateService(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        if (req.getParameter("submit") != null) {
+            String serviceName = req.getParameter("axisService");
+            String turnon = req.getParameter("turnon");
+            if (serviceName != null) {
+                if (turnon != null) {
+                    configContext.getAxisConfiguration().startService(serviceName);
+                }
+            }
+        }
+        populateSessionInformation(req);
+        renderView(ACTIVATE_SERVICE_JSP_NAME, req, res);
+    }
+
+    protected void processDeactivateService(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        if (req.getParameter("submit") != null) {
+            String serviceName = req.getParameter("axisService");
+            String turnoff = req.getParameter("turnoff");
+            if (serviceName != null) {
+                if (turnoff != null) {
+                    configContext.getAxisConfiguration().stopService(serviceName);
+                }
+                populateSessionInformation(req);
+            }
+        } else {
+            populateSessionInformation(req);
+        }
+
+        renderView(IN_ACTIVATE_SERVICE_JSP_NAME, req, res);
+    }
+
+
+    protected void processViewGlobalHandlers(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        req.getSession().setAttribute(Constants.GLOBAL_HANDLERS,
+                                      configContext.getAxisConfiguration());
+
+        renderView(VIEW_GLOBAL_HANDLERS_JSP_NAME, req, res);
+    }
+
+    protected void processViewServiceHandlers(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        String service = req.getParameter("axisService");
+
+        if (service != null) {
+            req.getSession().setAttribute(Constants.SERVICE_HANDLERS,
+                                          configContext.getAxisConfiguration().getService(service));
+        }
+
+        renderView(VIEW_SERVICE_HANDLERS_JSP_NAME, req, res);
+    }
+
+
+    protected void processListPhases(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        PhasesInfo info = configContext.getAxisConfiguration().getPhasesInfo();
+        req.getSession().setAttribute(Constants.PHASE_LIST, info);
+        renderView(LIST_PHASES_JSP_NAME, req, res);
+    }
+
+    protected void processListServiceGroups(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        Iterator serviceGroups = configContext.getAxisConfiguration().getServiceGroups();
+        populateSessionInformation(req);
+        req.getSession().setAttribute(Constants.SERVICE_GROUP_MAP, serviceGroups);
+
+        renderView(LIST_SERVICE_GROUP_JSP, req, res);
+    }
+
+    protected void processListService(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        populateSessionInformation(req);
+        req.getSession().setAttribute(Constants.ERROR_SERVICE_MAP,
+                                      configContext.getAxisConfiguration().getFaultyServices());
+
+        renderView(LIST_SERVICES_JSP_NAME, req, res);
+    }
+
+    protected void processListSingleService(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        req.getSession().setAttribute(Constants.IS_FAULTY, ""); //Clearing out any old values.
+        String serviceName = req.getParameter("serviceName");
+        if (serviceName != null) {
+            AxisService service = configContext.getAxisConfiguration().getService(serviceName);
+            req.getSession().setAttribute(Constants.SINGLE_SERVICE, service);
+        }
+        renderView(LIST_SINGLE_SERVICES_JSP_NAME, req, res);
+    }
+
+
+    protected void processListContexts(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        req.getSession().setAttribute(Constants.CONFIG_CONTEXT, configContext);
+        renderView("ViewContexts.jsp", req, res);
+    }
+
+    protected void processglobalModules(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        Collection modules = configContext.getAxisConfiguration().getEngagedModules();
+
+        req.getSession().setAttribute(Constants.MODULE_MAP, modules);
+
+        renderView(LIST_GLOABLLY_ENGAGED_MODULES_JSP_NAME, req, res);
+    }
+
+    protected void processListModules(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        HashMap modules = configContext.getAxisConfiguration().getModules();
+
+        req.getSession().setAttribute(Constants.MODULE_MAP, modules);
+        req.getSession().setAttribute(Constants.ERROR_MODULE_MAP,
+                                      configContext.getAxisConfiguration().getFaultyModules());
+
+        renderView(LIST_AVAILABLE_MODULES_JSP_NAME, req, res);
+    }
+
+    protected void processdisengageModule(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        String type = req.getParameter("type");
+        String serviceName = req.getParameter("serviceName");
+        String moduleName = req.getParameter("module");
+        AxisConfiguration axisConfiguration = configContext.getAxisConfiguration();
+        AxisService service = axisConfiguration.getService(serviceName);
+        AxisModule module = axisConfiguration.getModule(moduleName);
+        if (type.equals("operation")) {
+            if (service.isEngaged(module.getName()) ||
+                    axisConfiguration.isEngaged(module.getName())) {
+                req.getSession().setAttribute("status", "Can not disengage module " + moduleName +
+                        ". This module is engaged at a higher level.");
+            } else {
+                String opName = req.getParameter("operation");
+                AxisOperation op = service.getOperation(new QName(opName));
+                op.disengageModule(module);
+                req.getSession()
+                        .setAttribute("status", "Module " + moduleName + " was disengaged from " +
+                                "operation " + opName + " in service " + serviceName + ".");
+            }
+        } else {
+            if (axisConfiguration.isEngaged(module.getName())) {
+                req.getSession()
+                        .setAttribute("status", "Can not disengage module " + moduleName + ". " +
+                                "This module is engaged at a higher level.");
+            } else {
+                service.disengageModule(axisConfiguration.getModule(moduleName));
+                req.getSession()
+                        .setAttribute("status", "Module " + moduleName + " was disengaged from" +
+                                " service " + serviceName + ".");
+            }
+        }
+        renderView("disengage.jsp", req, res);
+    }
+
+    protected void processSelectService(HttpServletRequest req, HttpServletResponse res)
+            throws IOException, ServletException {
+        populateSessionInformation(req);
+        req.getSession().setAttribute(Constants.SELECT_SERVICE_TYPE, "VIEW");
+
+        renderView(SELECT_SERVICE_JSP_NAME, req, res);
+    }
+
+
+    private boolean authorizationRequired
+            (HttpServletRequest
+                    httpServletRequest) {
+        return httpServletRequest.getSession().getAttribute(Constants.LOGGED) == null &&
+                !httpServletRequest.getRequestURI().endsWith("login");
+    }
+
+    private boolean axisSecurityEnabled
+            () {
+        Parameter parameter = configContext.getAxisConfiguration()
+                .getParameter(Constants.ADMIN_SECURITY_DISABLED);
+        return parameter == null || !"true".equals(parameter.getValue());
+    }
+
+}

Added: webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/AxisAdminServlet.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/AxisAdminServlet.java?rev=671127&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/AxisAdminServlet.java (added)
+++ webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/AxisAdminServlet.java Tue Jun 24 04:07:03 2008
@@ -0,0 +1,69 @@
+/*
+ * 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 javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ *
+ */
+public class AxisAdminServlet extends AxisServlet {
+
+    protected transient AdminAgent agent;
+
+    protected void doPost(HttpServletRequest req, HttpServletResponse res)
+            throws ServletException, IOException {
+        doGet(req, res);
+    }
+
+    protected void doGet(HttpServletRequest req,
+                         HttpServletResponse resp) throws ServletException, IOException {
+        try {
+            req.getSession().setAttribute(Constants.SERVICE_PATH, configContext.getServicePath());
+            agent.handle(req, resp);
+        } catch (Exception e) {
+            throw new ServletException(e);
+        }
+    }
+
+    public void init(ServletConfig config) throws ServletException {
+        super.init(config);
+        ServletContext servletContext = config.getServletContext();
+        this.configContext =
+                (ConfigurationContext) servletContext.getAttribute(CONFIGURATION_CONTEXT);
+        servletContext.setAttribute(this.getClass().getName(), this);
+        agent = new AdminAgent(configContext);
+        this.servletConfig = config;
+    }
+
+    public void init() throws ServletException {
+        if (this.servletConfig != null) {
+            init(this.servletConfig);
+        }
+    }
+}

Added: webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/AxisRequestEntity.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/AxisRequestEntity.java?rev=671127&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/AxisRequestEntity.java (added)
+++ webservices/axis2/trunk/java/modules/transports/src/org/apache/axis2/transport/http/AxisRequestEntity.java Tue Jun 24 04:07:03 2008
@@ -0,0 +1,120 @@
+/*
+ * 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.OMOutputFormat;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.transport.MessageFormatter;
+import org.apache.axis2.util.JavaUtils;
+import org.apache.commons.httpclient.methods.RequestEntity;
+
+import javax.xml.stream.FactoryConfigurationError;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.zip.GZIPOutputStream;
+
+/**
+ * This Request Entity is used by the HTTPCommonsTransportSender. This wraps the
+ * Axis2 message formatter object.
+ */
+public class AxisRequestEntity implements RequestEntity {
+
+    private MessageFormatter messageFormatter;
+
+    private boolean chunked = false;
+
+    private MessageContext messageContext;
+
+    private byte[] bytes;
+
+    private boolean isAllowedRetry;
+
+    private OMOutputFormat format;
+
+    private String soapAction;
+
+    /**
+     * Method calls to this request entity are delegated to the following Axis2
+     * message formatter object.
+     *
+     * @param messageFormatter
+     */
+    public AxisRequestEntity(MessageFormatter messageFormatter,
+                             MessageContext msgContext, OMOutputFormat format, String soapAction,
+                             boolean chunked, boolean isAllowedRetry) {
+        this.messageFormatter = messageFormatter;
+        this.messageContext = msgContext;
+        this.chunked = chunked;
+        this.isAllowedRetry = isAllowedRetry;
+        this.format = format;
+        this.soapAction = soapAction;
+    }
+
+    public boolean isRepeatable() {
+        // All Axis2 request entity implementations were returning this true
+        // So we return true as defualt
+        return true;
+    }
+
+    public void writeRequest(OutputStream outStream) throws IOException {
+        Object gzip = messageContext.getOptions().getProperty(HTTPConstants.MC_GZIP_REQUEST);
+        if (gzip != null && JavaUtils.isTrueExplicitly(gzip) && chunked) {
+            outStream = new GZIPOutputStream(outStream);
+        }
+        try {
+            if (chunked) {
+                messageFormatter.writeTo(messageContext, format, outStream, isAllowedRetry);
+            } else {
+                if (bytes == null) {
+                    bytes = messageFormatter.getBytes(messageContext, format);
+                }
+                outStream.write(bytes);
+            }
+            if (outStream instanceof GZIPOutputStream) {
+                ((GZIPOutputStream) outStream).finish();
+            }
+            outStream.flush();
+        } catch (FactoryConfigurationError e) {
+            throw AxisFault.makeFault(e);
+        } catch (IOException e) {
+            throw AxisFault.makeFault(e);
+        }
+
+    }
+
+    public long getContentLength() {
+        if (chunked) {
+            return -1;
+        }
+        if (bytes == null) {
+            try {
+                bytes = messageFormatter.getBytes(messageContext, format);
+            } catch (AxisFault e) {
+                return -1;
+            }
+        }
+        return bytes.length;
+    }
+
+    public String getContentType() {
+        return messageFormatter.getContentType(messageContext, format, soapAction);
+    }
+}