axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r778060 - in /webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http: AxisServlet.java HTTPTransportUtils.java SimpleHTTPServer.java
Date Sat, 23 May 2009 23:10:30 GMT
Author: veithen
Date: Sat May 23 23:10:29 2009
New Revision: 778060

URL: http://svn.apache.org/viewvc?rev=778060&view=rev
Log:
AXIS2-3843: Merged the code in AxisServlet#getEPRsForService and SimpleHTTPServer#getEPRsForService
into a single method in HTTPTransportUtils and implemented support for the httpFrontendHostUrl
parameter (as promised by the sample axis2.xml file shipped with Axis2...).

Modified:
    webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/AxisServlet.java
    webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
    webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/SimpleHTTPServer.java

Modified: webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/AxisServlet.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/AxisServlet.java?rev=778060&r1=778059&r2=778060&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/AxisServlet.java
(original)
+++ webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/AxisServlet.java
Sat May 23 23:10:29 2009
@@ -47,12 +47,10 @@
 import org.apache.axis2.transport.RequestResponseTransport;
 import org.apache.axis2.transport.TransportListener;
 import org.apache.axis2.transport.TransportUtils;
-import org.apache.axis2.transport.http.server.HttpUtils;
 import org.apache.axis2.transport.http.util.QueryStringParser;
 import org.apache.axis2.transport.http.util.RESTUtil;
 import org.apache.axis2.util.JavaUtils;
 import org.apache.axis2.util.MessageContextBuilder;
-import org.apache.axis2.util.Utils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -576,32 +574,11 @@
 
     public EndpointReference[] getEPRsForService(String serviceName, String ip) throws AxisFault
{
         //RUNNING_PORT
-        String port = (String) configContext.getProperty(ListingAgent.RUNNING_PORT);
-        if (port == null) {
-            port = "8080";
-        }
-        if (ip == null) {
-            try {
-                ip = Utils.getIpAddress(axisConfiguration);
-                if (ip == null) {
-                    ip = "localhost";
-                }
-            } catch (SocketException e) {
-                throw AxisFault.makeFault(e);
-            }
-        }
-
-        String endpointRefernce = "http://" + ip + ":" + port;
-        if (configContext.getServiceContextPath().startsWith("/")) {
-            endpointRefernce = endpointRefernce +
-                    configContext.getServiceContextPath() + "/" + serviceName;
-        } else {
-            endpointRefernce = endpointRefernce + '/' +
-                    configContext.getServiceContextPath() + "/" + serviceName;
-        }
-        EndpointReference endpoint = new EndpointReference(endpointRefernce + "/");
-
-        return new EndpointReference[]{endpoint};
+        String portString = (String) configContext.getProperty(ListingAgent.RUNNING_PORT);
+        // TODO: there is something strange here because we never generate EPRs for https
+        return HTTPTransportUtils.getEPRsForService(configContext,
+                configContext.getAxisConfiguration().getTransportIn("http"),
+                serviceName, ip, portString == null ? 8080 : Integer.parseInt(portString));
     }
 
     /**

Modified: webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/HTTPTransportUtils.java?rev=778060&r1=778059&r2=778060&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
(original)
+++ webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
Sat May 23 23:10:29 2009
@@ -39,23 +39,29 @@
 import org.apache.axis2.context.OperationContext;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.Parameter;
+import org.apache.axis2.description.TransportInDescription;
+import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.engine.AxisEngine;
 import org.apache.axis2.engine.Handler.InvocationResponse;
+import org.apache.axis2.transport.TransportListener;
 import org.apache.axis2.transport.TransportUtils;
 import org.apache.axis2.util.JavaUtils;
 import org.apache.axis2.util.Utils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import javax.xml.parsers.FactoryConfigurationError;
 import javax.xml.stream.XMLStreamException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.net.SocketException;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.zip.GZIPInputStream;
 
 public class HTTPTransportUtils {
-
+    private static final Log log = LogFactory.getLog(HTTPTransportUtils.class);
 
     /**
      * @deprecated This was used only by the now deprecated processHTTPGetRequest() method.
@@ -273,4 +279,65 @@
                 contentType.indexOf(HTTPConstants.MEDIA_TYPE_X_WWW_FORM) > -1 ||
                 contentType.indexOf(HTTPConstants.MEDIA_TYPE_MULTIPART_FORM_DATA) > -1);
     }
+    
+    public static EndpointReference[] getEPRsForService(ConfigurationContext configurationContext,
+            TransportInDescription trpInDesc, String serviceName, String ip, int port) throws
AxisFault {
+        
+        AxisConfiguration axisConfiguration = configurationContext.getAxisConfiguration();
+        Parameter param = axisConfiguration.getParameter(Constants.HTTP_FRONTEND_HOST_URL);
+        StringBuilder epr = new StringBuilder();
+        if (param != null) {
+            epr.append(param.getValue());
+            String servicePath = configurationContext.getServicePath();
+            if (epr.charAt(epr.length()-1) != '/' && !servicePath.startsWith("/"))
{
+                epr.append('/');
+            }
+            epr.append(servicePath);
+        } else {
+            param = trpInDesc.getParameter(TransportListener.HOST_ADDRESS);
+            if (param != null) {
+                // TODO: Need to decide if we really want to deprecate this parameter.
+                //       Reason to deprecate it is that it has a misleading name ("hostname"
+                //       while it is actually a URL), that its role overlaps with that
+                //       of the "httpFrontendHostUrl" parameter in the Axis configuration
and
+                //       that there might be a confusion with the "hostname" parameter in
the
+                //       Axis configuration (which has a different meaning).
+                //       If we deprecate it, we need to remove it from all the axis2.xml
sample
+                //       files. Note that the same parameter seems to be used by the TCP
transport,
+                //       but it's role is not very clear (since TCP has no concept of request
URI).
+                log.warn("Transport '" + trpInDesc.getName()
+                        + "' is configured with deprecated parameter '"
+                        + TransportListener.HOST_ADDRESS + "'. Please set '"
+                        + Constants.HTTP_FRONTEND_HOST_URL
+                        + "' in the Axis configuration instead.");
+                epr.append(param.getValue());
+            } else {
+                if (ip == null){
+                    try {
+                        ip = Utils.getIpAddress(configurationContext.getAxisConfiguration());
+                    } catch (SocketException ex) {
+                        AxisFault.makeFault(ex);
+                    }
+                }
+                String scheme = trpInDesc.getName();
+                epr.append(scheme);
+                epr.append("://");
+                epr.append(ip);
+                if (!(scheme.equals("http") && port == 80
+                        || scheme.equals("https") && port == 443)) {
+                    epr.append(':');
+                    epr.append(port);
+                }
+            }
+            String serviceContextPath = configurationContext.getServiceContextPath();
+            if (epr.charAt(epr.length()-1) != '/' && !serviceContextPath.startsWith("/"))
{
+                epr.append('/');
+            }
+            epr.append(serviceContextPath);
+        }
+        epr.append('/');
+        epr.append(serviceName);
+        epr.append('/');
+        return new EndpointReference[]{new EndpointReference(epr.toString())};
+    }
 }

Modified: webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/SimpleHTTPServer.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/SimpleHTTPServer.java?rev=778060&r1=778059&r2=778060&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/SimpleHTTPServer.java
(original)
+++ webservices/axis2/trunk/java/modules/transport/http/src/org/apache/axis2/transport/http/SimpleHTTPServer.java
Sat May 23 23:10:29 2009
@@ -32,18 +32,15 @@
 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;
 
 /**
@@ -60,14 +57,12 @@
      * 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;
+    private TransportInDescription trpInDesc;
     protected HttpFactory httpFactory;
     private SessionManager sessionManager;
 
@@ -106,6 +101,7 @@
             throws AxisFault {
         try {
             this.configurationContext = axisConf;
+            this.trpInDesc = transprtIn;
 
             Parameter param = transprtIn.getParameter(PARAM_PORT);
             if (param != null) {
@@ -115,13 +111,6 @@
             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);
         }
@@ -252,55 +241,10 @@
      * @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 {
+        if (embedded == null) {
             throw new AxisFault("Unable to generate EPR for the transport : http");
         }
+        return HTTPTransportUtils.getEPRsForService(configurationContext, trpInDesc, serviceName,
ip, embedded.getPort());
     }
 
     /**



Mime
View raw message