continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r685402 - in /continuum/trunk/continuum-core/src: main/java/org/apache/maven/continuum/project/builder/ main/java/org/apache/maven/continuum/project/builder/maven/ test/java/org/apache/maven/continuum/core/action/ test/java/org/apache/maven...
Date Wed, 13 Aug 2008 00:58:08 GMT
Author: olamy
Date: Tue Aug 12 17:58:08 2008
New Revision: 685402

URL: http://svn.apache.org/viewvc?rev=685402&view=rev
Log:
[CONTINUUM-1489] replace use of MungedHttpsURL with commons-httpclient 

start some jobs on using httpclient 4.0-alpha4 
TODO basic auth and https tests (at the end removing plexus-formica)


Modified:
    continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/AbstractContinuumProjectBuilder.java
    continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilder.java
    continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataTest.java
    continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/project/builder/AbstractContinuumProjectBuilderTest.java

Modified: continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/AbstractContinuumProjectBuilder.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/AbstractContinuumProjectBuilder.java?rev=685402&r1=685401&r2=685402&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/AbstractContinuumProjectBuilder.java
(original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/AbstractContinuumProjectBuilder.java
Tue Aug 12 17:58:08 2008
@@ -19,43 +19,104 @@
  * under the License.
  */
 
-import org.codehaus.plexus.formica.util.MungedHttpsURL;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
-import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.StringUtils;
-
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.UnknownHostException;
 
+import org.apache.commons.io.IOUtils;
+import org.apache.http.HttpException;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpVersion;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.params.ConnPerRouteBean;
+import org.apache.http.conn.params.HttpConnectionManagerParams;
+import org.apache.http.conn.scheme.PlainSocketFactory;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.params.HttpProtocolParams;
+import org.apache.http.util.EntityUtils;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringUtils;
+
 /**
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
  * @version $Id$
  */
 public abstract class AbstractContinuumProjectBuilder
     extends AbstractLogEnabled
-    implements ContinuumProjectBuilder
+    implements ContinuumProjectBuilder, Initializable
 {
 
     private static final String TMP_DIR = System.getProperty( "java.io.tmpdir" );
+    
+    private HttpClient httpClient;
+    
+    
+    public void initialize()
+        throws InitializationException
+    {
+        SchemeRegistry schemeRegistry = new SchemeRegistry();
+        // http scheme
+        schemeRegistry.register( new Scheme( "http",  PlainSocketFactory.getSocketFactory(),
80 ) );
+        
+        // https scheme
+        schemeRegistry.register( new Scheme( "https", SSLSocketFactory.getSocketFactory(),
443 ) );
+        
+        HttpParams params = new BasicHttpParams();
+        // TODO put this values to a configuration way ???
+        HttpConnectionManagerParams.setMaxTotalConnections( params, 30 );
+        HttpConnectionManagerParams.setMaxConnectionsPerRoute( params, new ConnPerRouteBean(
30 ) );
+        HttpProtocolParams.setVersion( params, HttpVersion.HTTP_1_1 );
+        
+        ClientConnectionManager cm = new ThreadSafeClientConnManager( params, schemeRegistry
);
+        httpClient = new DefaultHttpClient( cm, params );
 
-    protected File createMetadataFile( URL metadata, String username, String password )
-        throws IOException
+        
+    }
+
+    protected File createMetadataFile( URL metadata, String username, String password, ContinuumProjectBuildingResult
result )
+        throws IOException, URISyntaxException, HttpException
     {
         getLogger().info( "Downloading " + metadata.toExternalForm() );
 
         InputStream is = null;
-
+        
         if ( metadata.getProtocol().startsWith( "http" ) )
         {
-            is =
-                new MungedHttpsURL( metadata.toExternalForm(), username, password ).getURLConnection().getInputStream();
+            HttpGet httpGet = new HttpGet( metadata.toURI() );
+            HttpResponse httpResponse = httpClient.execute( httpGet );
+
+            // TODO check http return code 
+            int res = httpResponse.getStatusLine().getStatusCode();
+            switch (res)
+            {
+                case 401:
+                    getLogger().debug( "Error adding project: Unauthorized " + metadata,
null );
+                    result.addError( ContinuumProjectBuildingResult.ERROR_UNAUTHORIZED );
+                    return null;
+                default :
+            }
+            is = IOUtils.toInputStream( EntityUtils.toString( httpResponse.getEntity(), EntityUtils
+                .getContentCharSet( httpResponse.getEntity() ) ) );
+            //is =
+            //    new MungedHttpsURL( metadata.toExternalForm(), username, password ).getURLConnection().getInputStream();
         }
         else
         {
@@ -137,7 +198,7 @@
     {
         try
         {
-            return createMetadataFile( metadata, username, password );
+            return createMetadataFile( metadata, username, password, result );
         }
         catch ( FileNotFoundException e )
         {
@@ -149,6 +210,11 @@
             getLogger().info( "Malformed URL: " + metadata, e );
             result.addError( ContinuumProjectBuildingResult.ERROR_MALFORMED_URL );
         }
+        catch ( URISyntaxException e )
+        {
+            getLogger().info( "Malformed URL: " + metadata, e );
+            result.addError( ContinuumProjectBuildingResult.ERROR_MALFORMED_URL );
+        }        
         catch ( UnknownHostException e )
         {
             getLogger().info( "Unknown host: " + metadata, e );
@@ -159,6 +225,11 @@
             getLogger().warn( "Could not download the URL: " + metadata, e );
             result.addError( ContinuumProjectBuildingResult.ERROR_UNKNOWN );
         }
+        catch ( HttpException e )
+        {
+            getLogger().warn( "Could not download the URL: " + metadata, e );
+            result.addError( ContinuumProjectBuildingResult.ERROR_UNKNOWN );
+        }        
         return null;
     }
 

Modified: continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilder.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilder.java?rev=685402&r1=685401&r2=685402&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilder.java
(original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilder.java
Tue Aug 12 17:58:08 2008
@@ -19,9 +19,20 @@
  * under the License.
  */
 
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.ConnectException;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.continuum.dao.LocalRepositoryDao;
 import org.apache.continuum.dao.ScheduleDao;
 import org.apache.continuum.model.repository.LocalRepository;
+import org.apache.http.HttpException;
 import org.apache.maven.continuum.builddefinition.BuildDefinitionService;
 import org.apache.maven.continuum.builddefinition.BuildDefinitionServiceException;
 import org.apache.maven.continuum.configuration.ConfigurationService;
@@ -40,15 +51,6 @@
 import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.util.StringUtils;
 
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.net.ConnectException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-
 /**
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
  * @version $Id$
@@ -149,7 +151,7 @@
 
         try
         {
-            pomFile = createMetadataFile( url, username, password );
+            pomFile = createMetadataFile( url, username, password, result );
             mavenProject = builderHelper.getMavenProject( result, pomFile );
 
             if ( result.hasErrors() )
@@ -163,6 +165,12 @@
             result.addError( ContinuumProjectBuildingResult.ERROR_MALFORMED_URL );
             return;
         }
+        catch ( URISyntaxException e )
+        {
+            getLogger().debug( "Error adding project: Malformed URL " + url, e );
+            result.addError( ContinuumProjectBuildingResult.ERROR_MALFORMED_URL );
+            return;
+        }        
         catch ( FileNotFoundException e )
         {
             getLogger().debug( "Error adding project: File not found " + url, e );
@@ -177,19 +185,16 @@
         }
         catch ( IOException e )
         {
-            if ( e.getMessage() != null )
-            {
-                if ( e.getMessage().indexOf( "Server returned HTTP response code: 401" )
>= 0 )
-                {
-                    getLogger().debug( "Error adding project: Unauthorized " + url, e );
-                    result.addError( ContinuumProjectBuildingResult.ERROR_UNAUTHORIZED );
-                    return;
-                }
-            }
             getLogger().info( "Error adding project: Unknown error downloading from " + url,
e );
             result.addError( ContinuumProjectBuildingResult.ERROR_UNKNOWN );
             return;
         }
+        catch ( HttpException e )
+        {
+            getLogger().info( "Error adding project: Unknown error downloading from " + url,
e );
+            result.addError( ContinuumProjectBuildingResult.ERROR_UNKNOWN );
+            return;
+        }        
         finally
         {
             if ( pomFile != null && pomFile.exists() )

Modified: continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataTest.java?rev=685402&r1=685401&r2=685402&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataTest.java
(original)
+++ continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataTest.java
Tue Aug 12 17:58:08 2008
@@ -87,6 +87,7 @@
         return bdt;
     }
     
+    @SuppressWarnings("unchecked")
     public void testExecuteWithNonRecursiveMode()
         throws Exception
     {

Modified: continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/project/builder/AbstractContinuumProjectBuilderTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/project/builder/AbstractContinuumProjectBuilderTest.java?rev=685402&r1=685401&r2=685402&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/project/builder/AbstractContinuumProjectBuilderTest.java
(original)
+++ continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/project/builder/AbstractContinuumProjectBuilderTest.java
Tue Aug 12 17:58:08 2008
@@ -58,7 +58,7 @@
         URL url = new URL( "https://someurl/pom.xml" );
         String username = "myusername";
         String password = "mypassword";
-        builder.createMetadataFile( url, username, password );
+        builder.createMetadataFile( url, username, password, new ContinuumProjectBuildingResult()
);
     }
 
     private class ContinuumProjectBuilder



Mime
View raw message