Author: janb
Date: Tue Aug 26 17:21:38 2008
New Revision: 689299

URL: http://svn.apache.org/viewvc?rev=689299&view=rev
Log:
Ensure all http exchanges can have proxy and server authentication.

Added:
    
maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/SecureSender.java
   (with props)
Modified:
    
maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/FileExchange.java
    
maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/retrieve/FileGetExchange.java
    
maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/retrieve/RetrievalTarget.java

Modified: 
maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/FileExchange.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/FileExchange.java?rev=689299&r1=689298&r2=689299&view=diff
==============================================================================
--- 
maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/FileExchange.java
 (original)
+++ 
maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/FileExchange.java
 Tue Aug 26 17:21:38 2008
@@ -78,40 +78,7 @@
     {
         try
         {
-            if (_server != null && _server.hasProxy() && (_server.getProxy() 
!= null))
-            {
-                URL url = new URL(_url);
-                boolean ssl = "https".equalsIgnoreCase(url.getProtocol());
-                URL proxy = _server.getProxy();
-                
-                String host = proxy.getHost();
-                int port = proxy.getPort();
-                boolean proxySsl = 
"https".equalsIgnoreCase(proxy.getProtocol());
-                if (port < 0)
-                {
-                    port = proxySsl?443:80;
-                }
-                InetSocketAddress proxyAddress = new 
InetSocketAddress(host,port);
-                HttpDestination destination = 
_httpClient.getDestination(this.getAddress(), ssl);  
-                destination.setProxy(proxyAddress);
-                
-                //set up authentication for the proxy
-                Credentials proxyCredentials = _server.getProxyCredentials();
-                
-                if (proxyCredentials != null)
-                {
-                    if (proxyCredentials.isCertificate())
-                        throw new UnsupportedOperationException ("Proxy 
credential not supported");
-                    else
-                    destination.setProxyAuthentication(new ProxyAuthorization 
(proxyCredentials.getUser(), proxyCredentials.getPass()));
-                }
-                destination.send(this); 
-            }
-            else
-            { 
-                _httpClient.send( this );
-            }
-            
+            SecureSender.send(_server, _httpClient, this);
         }
         catch ( Exception e )
         {

Added: 
maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/SecureSender.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/SecureSender.java?rev=689299&view=auto
==============================================================================
--- 
maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/SecureSender.java
 (added)
+++ 
maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/SecureSender.java
 Tue Aug 26 17:21:38 2008
@@ -0,0 +1,84 @@
+/**
+ * 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.maven.mercury.spi.http.client;
+
+import java.net.InetSocketAddress;
+import java.net.URI;
+import java.net.URL;
+
+import org.apache.maven.mercury.transport.api.Credentials;
+import org.apache.maven.mercury.transport.api.Server;
+import org.mortbay.jetty.client.HttpClient;
+import org.mortbay.jetty.client.HttpDestination;
+import org.mortbay.jetty.client.HttpExchange;
+import org.mortbay.jetty.client.security.ProxyAuthorization;
+
+/**
+ * SecureSender
+ *
+ * Initiates a HttpExchange with the remote server, taking into account any 
proxy
+ * authentication required. Any non-proxy authentication required will be taken
+ * care of by the DestinationRealmResolver that is set on the HttpClient used
+ * by this class.
+ * 
+ * TODO think of a better name for this class.
+ */
+public class SecureSender
+{
+    public static void send (Server server, HttpClient httpClient, 
HttpExchange exchange)
+    throws Exception
+    {
+        if (server != null && server.hasProxy() && (server.getProxy() != null))
+        {
+            String s = exchange.getURI();
+            URI uri = new URI(s);
+            boolean ssl = "https".equalsIgnoreCase(uri.getScheme());
+            URL proxy = server.getProxy();
+            
+            String host = proxy.getHost();
+            int port = proxy.getPort();
+            boolean proxySsl = "https".equalsIgnoreCase(proxy.getProtocol());
+            if (port < 0)
+            {
+                port = proxySsl?443:80;
+            }
+            InetSocketAddress proxyAddress = new InetSocketAddress(host,port);
+            HttpDestination destination = 
httpClient.getDestination(exchange.getAddress(), ssl);  
+            destination.setProxy(proxyAddress);
+            
+            //set up authentication for the proxy
+            Credentials proxyCredentials = server.getProxyCredentials();
+            
+            if (proxyCredentials != null)
+            {
+                if (proxyCredentials.isCertificate())
+                    throw new UnsupportedOperationException ("Proxy credential 
not supported");
+                else
+                destination.setProxyAuthentication(new ProxyAuthorization 
(proxyCredentials.getUser(), proxyCredentials.getPass()));
+            }
+            destination.send(exchange); 
+        }
+        else
+        { 
+            httpClient.send(exchange);
+        } 
+    }
+
+}

Propchange: 
maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/SecureSender.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/SecureSender.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: 
maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/SecureSender.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/retrieve/FileGetExchange.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/retrieve/FileGetExchange.java?rev=689299&r1=689298&r2=689299&view=diff
==============================================================================
--- 
maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/retrieve/FileGetExchange.java
 (original)
+++ 
maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/retrieve/FileGetExchange.java
 Tue Aug 26 17:21:38 2008
@@ -72,7 +72,8 @@
     public FileGetExchange( Server server, Binding binding, File localFile, 
Set<StreamObserver> observers, HttpClient client )
     {
         super( server, binding, localFile, client );
-        _observers.addAll(observers);
+        if (observers != null)
+            _observers.addAll(observers);
     }
 
 

Modified: 
maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/retrieve/RetrievalTarget.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/retrieve/RetrievalTarget.java?rev=689299&r1=689298&r2=689299&view=diff
==============================================================================
--- 
maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/retrieve/RetrievalTarget.java
 (original)
+++ 
maven/sandbox/trunk/mercury/mercury-transport/mercury-transport-http/src/main/java/org/apache/maven/mercury/spi/http/client/retrieve/RetrievalTarget.java
 Tue Aug 26 17:21:38 2008
@@ -22,6 +22,7 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -37,6 +38,7 @@
 import org.apache.maven.mercury.crypto.api.StreamVerifierException;
 import org.apache.maven.mercury.spi.http.client.FileExchange;
 import org.apache.maven.mercury.spi.http.client.HttpClientException;
+import org.apache.maven.mercury.spi.http.client.SecureSender;
 import org.apache.maven.mercury.spi.http.validate.Validator;
 import org.apache.maven.mercury.transport.api.Binding;
 import org.apache.maven.mercury.transport.api.Server;
@@ -308,7 +310,7 @@
                     }
                     else if (_binding.isInMemory())
                     {
-                        //TODO ????
+                        //TODO Validation on in memory content?
                         //v.validate(_binding.getInboundContent()) 
                     }
                 }
@@ -360,7 +362,7 @@
 
     /** Asynchronously fetch the checksum for the target file. */
     private HttpExchange retrieveChecksum(final int index)
-    {
+    {    
         HttpExchange exchange = new HttpExchange.ContentExchange()
         {
             protected void onException( Throwable ex )
@@ -418,9 +420,9 @@
 
         try
         {
-            _retriever.getHttpClient().send( exchange );
+            SecureSender.send(_server, _retriever.getHttpClient(), exchange);
         }
-        catch ( IOException ex )
+        catch ( Exception ex )
         {
             updateChecksumState(index, ex);
         }


Reply via email to