Author: olamy Date: Wed Jul 23 04:00:37 2014 New Revision: 1612752 URL: http://svn.apache.org/r1612752 Log: Fix for MTOMCAT-177 - tomcat7:deploy ignores proxy settings
Modified: tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/deployer/TomcatManager.java tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/AbstractCatalinaMojo.java Modified: tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/deployer/TomcatManager.java URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/deployer/TomcatManager.java?rev=1612752&r1=1612751&r2=1612752&view=diff ============================================================================== --- tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/deployer/TomcatManager.java (original) +++ tomcat/maven-plugin/trunk/common-tomcat-maven-plugin/src/main/java/org/apache/tomcat/maven/common/deployer/TomcatManager.java Wed Jul 23 04:00:37 2014 @@ -34,12 +34,14 @@ import org.apache.http.client.methods.Ht import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.client.protocol.ClientContext; +import org.apache.http.conn.params.ConnRoutePNames; import org.apache.http.entity.AbstractHttpEntity; import org.apache.http.impl.auth.BasicScheme; import org.apache.http.impl.client.BasicAuthCache; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.conn.PoolingClientConnectionManager; import org.apache.http.protocol.BasicHttpContext; +import org.apache.maven.settings.Proxy; import java.io.File; import java.io.FileInputStream; @@ -108,6 +110,8 @@ public class TomcatManager * @since 2.0 */ private BasicHttpContext localContext; + + private Proxy proxy; /** * @since 2.2 @@ -188,6 +192,7 @@ public class TomcatManager PoolingClientConnectionManager poolingClientConnectionManager = new PoolingClientConnectionManager(); poolingClientConnectionManager.setMaxTotal( 5 ); this.httpClient = new DefaultHttpClient( poolingClientConnectionManager ); + if ( StringUtils.isNotEmpty( username ) ) { Credentials creds = new UsernamePasswordCredentials( username, password ); @@ -270,6 +275,37 @@ public class TomcatManager { this.userAgent = userAgent; } + + /** + * @param proxy + */ + public void setProxy(Proxy proxy) { + if( this.proxy != proxy ) { + this.proxy = proxy; + if( httpClient != null ) { + applyProxy(); + } + } + } + + /** + * {@link #setProxy(Proxy)} is called by {@link AbstractCatinalMojo#getManager()} after the constructor + */ + private void applyProxy() { + if( this.proxy != null ) { + System.out.println("proxy: " + proxy); + HttpHost proxy = new HttpHost(this.proxy.getHost(), this.proxy.getPort(), this.proxy.getProtocol()); + httpClient.getParams().setParameter( ConnRoutePNames.DEFAULT_PROXY, proxy ); + if( this.proxy.getUsername() != null ) { + httpClient.getCredentialsProvider().setCredentials( new AuthScope(this.proxy.getHost(), this.proxy.getPort()), + new UsernamePasswordCredentials(this.proxy.getUsername(), + this.proxy.getPassword()) ); + } + } else { + httpClient.getParams().removeParameter( ConnRoutePNames.DEFAULT_PROXY ); + } + } + /** * Deploys the specified WAR as a URL to the specified context path. Modified: tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/AbstractCatalinaMojo.java URL: http://svn.apache.org/viewvc/tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/AbstractCatalinaMojo.java?rev=1612752&r1=1612751&r2=1612752&view=diff ============================================================================== --- tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/AbstractCatalinaMojo.java (original) +++ tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/AbstractCatalinaMojo.java Wed Jul 23 04:00:37 2014 @@ -20,9 +20,11 @@ package org.apache.tomcat.maven.plugin.t */ import org.apache.maven.artifact.manager.WagonManager; +import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.settings.Proxy; import org.apache.maven.wagon.authentication.AuthenticationInfo; import org.apache.tomcat.maven.common.deployer.TomcatManager; import org.apache.tomcat.maven.common.deployer.TomcatManagerException; @@ -69,6 +71,12 @@ public abstract class AbstractCatalinaMo */ @Component private WagonManager wagonManager; + + /** + * The current build session instance. This is used for plugin manager API calls. + */ + @Component + private MavenSession session; /** * The full URL of the Tomcat manager instance to use. @@ -218,6 +226,12 @@ public abstract class AbstractCatalinaMo manager = new TomcatManager( url, userName, password, charset, settings.isInteractiveMode() ); manager.setUserAgent( name + "/" + version ); + + Proxy proxy = session.getSettings().getActiveProxy(); + if( proxy != null && proxy.isActive() ) { + getLog().debug("proxy: " + proxy.getHost() + ":" + proxy.getPort()); + manager.setProxy(proxy); + } } return manager; --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org