cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r512187 - in /incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport: http/AbstractHTTPDestination.java http/JettyHTTPDestination.java servlet/ServletDestination.java
Date Tue, 27 Feb 2007 09:20:14 GMT
Author: ningjiang
Date: Tue Feb 27 01:20:12 2007
New Revision: 512187

URL: http://svn.apache.org/viewvc?view=rev&rev=512187
Log:
CXF-343 Refactoring to make ServletDestination share some common code with JettyHTTPDestination

Modified:
    incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
    incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java
    incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java

Modified: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java?view=diff&rev=512187&r1=512186&r2=512187
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
(original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
Tue Feb 27 01:20:12 2007
@@ -20,6 +20,7 @@
 package org.apache.cxf.transport.http;
 
 import java.io.IOException;
+import java.net.HttpURLConnection;
 import java.net.URL;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -40,6 +41,7 @@
 import org.apache.cxf.transport.AbstractDestination;
 import org.apache.cxf.transport.ConduitInitiator;
 import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
+import org.apache.cxf.ws.addressing.EndpointReferenceType;
 
 /**
  * Common base for HTTP Destination implementations.
@@ -66,21 +68,25 @@
      * @param b the associated Bus
      * @param ci the associated conduit initiator
      * @param ei the endpoint info of the destination 
+     * @param dp ture for adding the default port if it is missing
      * @throws IOException
      */    
     public AbstractHTTPDestination(Bus b,
                                    ConduitInitiator ci,
-                                   EndpointInfo ei)
+                                   EndpointInfo ei,
+                                   boolean dp)
         throws IOException {
-        super(getTargetReference(getAddressValue(ei)), ei);  
+        super(getTargetReference(getAddressValue(ei, dp)), ei);  
         bus = b;
         conduitInitiator = ci;
         
         initConfig();
  
-        nurl = new URL(getAddressValue(ei));
+        nurl = new URL(getAddressValue(ei, dp));
         name = nurl.getPath();
     }
+    
+    
 
     /**
      * Cache HTTP headers in message.
@@ -145,8 +151,31 @@
                                                Map<String, List<String>> headers);
 
     protected static String getAddressValue(EndpointInfo ei) {       
-        return StringUtils.addDefaultPortIfMissing(ei.getAddress());
-    }        
+        return getAddressValue(ei, false);
+    } 
+    
+    protected static String getAddressValue(EndpointInfo ei, boolean dp) {       
+        if (dp) {
+            return StringUtils.addDefaultPortIfMissing(ei.getAddress());
+        } else {
+            return ei.getAddress();
+        }
+    }  
+    
+    /**
+     * Mark message as a partial message.
+     * 
+     * @param partialResponse the partial response message
+     * @param the decoupled target
+     * @return true iff partial responses are supported
+     */
+    protected boolean markPartialResponse(Message partialResponse,
+                                       EndpointReferenceType decoupledTarget) {
+        // setup the outbound message to for 202 Accepted
+        partialResponse.put(Message.RESPONSE_CODE, HttpURLConnection.HTTP_ACCEPTED);
+        partialResponse.getExchange().put(EndpointReferenceType.class, decoupledTarget);
+        return true;
+    }
 
     private void initConfig() {
         this.server = endpointInfo.getTraversedExtensor(new HTTPServerPolicy(), HTTPServerPolicy.class);

Modified: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java?view=diff&rev=512187&r1=512186&r2=512187
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java
(original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/JettyHTTPDestination.java
Tue Feb 27 01:20:12 2007
@@ -45,7 +45,6 @@
 import org.apache.cxf.transport.ConduitInitiator;
 import org.apache.cxf.transports.http.QueryHandler;
 import org.apache.cxf.transports.http.QueryHandlerRegistry;
-import org.apache.cxf.ws.addressing.EndpointReferenceType;
 import org.mortbay.http.HttpRequest;
 import org.mortbay.http.HttpResponse;
 import org.mortbay.http.handler.AbstractHttpHandler;
@@ -83,7 +82,8 @@
      */
     public JettyHTTPDestination(Bus b, ConduitInitiator ci, EndpointInfo endpointInfo, ServerEngine
eng)
         throws IOException {
-        super(b, ci, endpointInfo);
+        //Add the defualt port if the address is missing it
+        super(b, ci, endpointInfo, true);
         alternateEngine = eng;
     }
 
@@ -150,21 +150,7 @@
         HttpResponse response = (HttpResponse)inMessage.get(HTTP_RESPONSE);
         return new BackChannelConduit(response);
     }
-
-    /**
-     * Mark message as a partial message.
-     * 
-     * @param partialResponse the partial response message
-     * @param the decoupled target
-     * @return true iff partial responses are supported
-     */
-    protected boolean markPartialResponse(Message partialResponse,
-                                       EndpointReferenceType decoupledTarget) {
-        // setup the outbound message to for 202 Accepted
-        partialResponse.put(Message.RESPONSE_CODE, HttpURLConnection.HTTP_ACCEPTED);
-        partialResponse.getExchange().put(EndpointReferenceType.class, decoupledTarget);
-        return true;
-    }
+   
 
     /**
      * @return the associated conduit initiator

Modified: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java?view=diff&rev=512187&r1=512186&r2=512187
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java
(original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletDestination.java
Tue Feb 27 01:20:12 2007
@@ -25,7 +25,6 @@
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Enumeration;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.logging.Level;
@@ -35,10 +34,6 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.cxf.Bus;
-import org.apache.cxf.common.util.Base64Exception;
-import org.apache.cxf.common.util.Base64Utility;
-import org.apache.cxf.configuration.security.AuthorizationPolicy;
-import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.HttpHeaderHelper;
 import org.apache.cxf.io.AbstractWrappedOutputStream;
 import org.apache.cxf.message.Message;
@@ -48,10 +43,10 @@
 import org.apache.cxf.transport.Conduit;
 import org.apache.cxf.transport.ConduitInitiator;
 import org.apache.cxf.transport.MessageObserver;
-import org.apache.cxf.ws.addressing.EndpointReferenceType;
+import org.apache.cxf.transport.http.AbstractHTTPDestination;
 
 
-public class ServletDestination extends AbstractDestination {
+public class ServletDestination extends AbstractHTTPDestination {
 
     public static final String HTTP_REQUEST =
         "HTTP_SERVLET_REQUEST";
@@ -61,9 +56,7 @@
     static final Logger LOG = Logger.getLogger(ServletDestination.class.getName());
         
     private static final long serialVersionUID = 1L;        
-
-    protected final Bus bus;
-    protected final ConduitInitiator conduitInitiator;
+    
     protected String name;
     protected URL nurl;
     
@@ -81,53 +74,8 @@
                               ConduitInitiator ci,
                               EndpointInfo ei)
         throws IOException {
-        super(getTargetReference(ei.getAddress()), ei);  
-        bus = b;
-        conduitInitiator = ci;
-    }
-
-    /**
-     * Cache HTTP headers in message.
-     * 
-     * @param message the current message
-     */
-    protected void setHeaders(Message message) {
-        Map<String, List<String>> requestHeaders = new HashMap<String, List<String>>();
-        copyRequestHeaders(message, requestHeaders);
-        message.put(Message.PROTOCOL_HEADERS, requestHeaders);
-
-        if (requestHeaders.containsKey("Authorization")) {
-            List<String> authorizationLines = requestHeaders.get("Authorization");

-            String credentials = authorizationLines.get(0);
-            String authType = credentials.split(" ")[0];
-            if ("Basic".equals(authType)) {
-                String authEncoded = credentials.split(" ")[1];
-                try {
-                    String authDecoded = new String(Base64Utility.decode(authEncoded));
-                    String authInfo[] = authDecoded.split(":");
-                    String username = authInfo[0];
-                    String password = authInfo[1];
-                    
-                    AuthorizationPolicy policy = new AuthorizationPolicy();
-                    policy.setUserName(username);
-                    policy.setPassword(password);
-                    
-                    message.put(AuthorizationPolicy.class, policy);
-                } catch (Base64Exception ex) {
-                    //ignore, we'll leave things alone.  They can try decoding it themselves
-                }
-            }
-        }
-           
-    }
-    
-    protected void updateResponseHeaders(Message message) {
-        Map<String, List<String>> responseHeaders =
-            CastUtils.cast((Map)message.get(Message.PROTOCOL_HEADERS));
-        if (responseHeaders == null) {
-            responseHeaders = new HashMap<String, List<String>>();
-            message.put(Message.PROTOCOL_HEADERS, responseHeaders);         
-        }
+        // would add the default port to the address
+        super(b, ci, ei, false);
     }
     
     protected Logger getLogger() {
@@ -143,20 +91,7 @@
         return new BackChannelConduit(response);
     }
    
-    /**
-     * Mark message as a partial message.
-     * 
-     * @param partialResponse the partial response message
-     * @param the decoupled target
-     * @return true iff partial responses are supported
-     */
-    protected boolean markPartialResponse(Message partialResponse,
-                                          EndpointReferenceType decoupledTarget) {
-        partialResponse.put(Message.RESPONSE_CODE,
-                            HttpURLConnection.HTTP_ACCEPTED);
-        partialResponse.getExchange().put(EndpointReferenceType.class, decoupledTarget);
-        return true;
-    }
+   
         
     /**
      * Copy the request headers into the message.



Mime
View raw message