Skip to content

Commit

Permalink
Use GlobalProxyConfig as proxy bean to wrap location
Browse files Browse the repository at this point in the history
  • Loading branch information
yma96 committed Aug 9, 2024
1 parent f090f35 commit 44cf512
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.commonjava.maven.galley.transport.NoOpLocationExpander;
import org.commonjava.maven.galley.transport.SimpleUrlLocationResolver;
import org.commonjava.maven.galley.transport.htcli.conf.GlobalHttpConfiguration;
import org.commonjava.maven.galley.transport.htcli.conf.GlobalProxyConfig;
import org.commonjava.o11yphant.metrics.AbstractTrafficClassifier;
import org.commonjava.o11yphant.metrics.TrafficClassifier;
import org.commonjava.o11yphant.metrics.conf.DefaultMetricsConfig;
Expand Down Expand Up @@ -100,6 +101,33 @@ public String getMetricUniqueName( Location location )
}
};

private final GlobalProxyConfig globalProxyConfig = new GlobalProxyConfig()
{
@Override
public String getHost()
{
return "proxy.com";
}

@Override
public int getPort()
{
return 3128;
}

@Override
public String getUser()
{
return null;
}

@Override
public List<String> getAllowHttpJobTypes()
{
return new ArrayList<>();
}
};

@Inject
private PathGenerator pathGenerator;

Expand Down Expand Up @@ -191,6 +219,13 @@ public TransportMetricConfig getTransportMetricConfig()
return transportMetricConfig;
}

@Produces
@Default
public GlobalProxyConfig getGlobalProxyConfig()
{
return globalProxyConfig;
}

@Produces
@Default
public MetricsConfig getMetricsConfig()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void before()
new TransferDecoratorManager( new NoOpTransferDecorator() ), false );

transport = new HttpClientTransport( new HttpImpl( new MemoryPasswordManager() ), new ObjectMapper(),
new GlobalHttpConfiguration(), null, null );
new GlobalHttpConfiguration().getGlobalProxyConfig(), null, null );
}

@BMRules( rules = { @BMRule( name = "init rendezvous", targetClass = "DownloadHandler", targetMethod = "<init>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.commonjava.maven.galley.spi.transport.ListingJob;
import org.commonjava.maven.galley.spi.transport.PublishJob;
import org.commonjava.maven.galley.spi.transport.Transport;
import org.commonjava.maven.galley.transport.htcli.conf.GlobalHttpConfiguration;
import org.commonjava.maven.galley.transport.htcli.conf.GlobalProxyConfig;
import org.commonjava.maven.galley.transport.htcli.conf.HttpJobType;
import org.commonjava.maven.galley.transport.htcli.internal.HttpDownload;
import org.commonjava.maven.galley.transport.htcli.internal.HttpExistence;
Expand Down Expand Up @@ -67,7 +67,7 @@ public class HttpClientTransport
private Http http;

@Inject
private GlobalHttpConfiguration globalConfig;
private GlobalProxyConfig globalProxyConfig;

@Inject
private ObjectMapper mapper;
Expand All @@ -87,12 +87,12 @@ public HttpClientTransport( final Http http )
this( http, new ObjectMapper(), null, null, null );
}

public HttpClientTransport( final Http http, final ObjectMapper mapper, final GlobalHttpConfiguration globalConfig,
public HttpClientTransport( final Http http, final ObjectMapper mapper, final GlobalProxyConfig globalProxyConfig,
final MetricRegistry metricRegistry, final TransportMetricConfig metricConfig )
{
this.http = http;
this.mapper = mapper;
this.globalConfig = globalConfig;
this.globalProxyConfig = globalProxyConfig;
this.metricRegistry = metricRegistry;
this.metricConfig = metricConfig;
}
Expand Down Expand Up @@ -168,7 +168,8 @@ private HttpLocation getHttpLocation( final Location repository, HttpJobType htt
{
try
{
return new WrapperHttpLocation( repository, globalConfig, httpJobType );
logger.debug( "Wrap location with the global proxy config, host: {}", globalProxyConfig.getHost() );
return new WrapperHttpLocation( repository, globalProxyConfig, httpJobType );
}
catch ( final MalformedURLException e )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
public class GlobalHttpConfiguration
{

ProxyConfig proxyConfig;
GlobalProxyConfig globalProxyConfig;

public GlobalHttpConfiguration()
{
}

public GlobalHttpConfiguration( ProxyConfig proxyConfig )
public GlobalHttpConfiguration( GlobalProxyConfig globalProxyConfig )
{
this.proxyConfig = proxyConfig;
this.globalProxyConfig = globalProxyConfig;
}

public ProxyConfig getProxyConfig()
public GlobalProxyConfig getGlobalProxyConfig()
{
return proxyConfig;
return globalProxyConfig;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import java.util.List;

public interface ProxyConfig
public interface GlobalProxyConfig
{

String getHost();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
package org.commonjava.maven.galley.transport.htcli.internal.model;

import org.commonjava.maven.galley.model.Location;
import org.commonjava.maven.galley.transport.htcli.conf.GlobalHttpConfiguration;
import org.commonjava.maven.galley.transport.htcli.conf.GlobalProxyConfig;
import org.commonjava.maven.galley.transport.htcli.conf.HttpJobType;
import org.commonjava.maven.galley.transport.htcli.conf.ProxyConfig;
import org.commonjava.maven.galley.transport.htcli.model.HttpLocation;
import org.commonjava.maven.galley.transport.htcli.model.LocationTrustType;

Expand All @@ -34,16 +33,16 @@ public class WrapperHttpLocation

private final URL url;

private final GlobalHttpConfiguration globalConfig;
private final GlobalProxyConfig globalProxyConfig;

private final HttpJobType httpJobType;

public WrapperHttpLocation( final Location delegate, final GlobalHttpConfiguration globalConfig,
public WrapperHttpLocation( final Location delegate, final GlobalProxyConfig globalProxyConfig,
final HttpJobType httpJobType )
throws MalformedURLException
{
this.delegate = delegate;
this.globalConfig = globalConfig;
this.globalProxyConfig = globalProxyConfig;
this.url = new URL( delegate.getUri() );
this.httpJobType = httpJobType;
}
Expand Down Expand Up @@ -117,21 +116,21 @@ public String getUser()
@Override
public String getProxyHost()
{
ProxyConfig proxy = getProxyConfig();
GlobalProxyConfig proxy = getGlobalProxyConfig();
return isProxyAllowHttpJobType( proxy ) ? proxy.getHost() : null;
}

@Override
public String getProxyUser()
{
ProxyConfig proxy = getProxyConfig();
GlobalProxyConfig proxy = getGlobalProxyConfig();
return isProxyAllowHttpJobType( proxy ) ? proxy.getUser() : null;
}

@Override
public int getProxyPort()
{
ProxyConfig proxy = getProxyConfig();
GlobalProxyConfig proxy = getGlobalProxyConfig();
return isProxyAllowHttpJobType( proxy ) ? proxy.getPort() : 8080;
}

Expand Down Expand Up @@ -214,12 +213,12 @@ public String getName()
return delegate.getName();
}

private ProxyConfig getProxyConfig()
private GlobalProxyConfig getGlobalProxyConfig()
{
return globalConfig == null ? null : globalConfig.getProxyConfig();
return globalProxyConfig;
}

private boolean isProxyAllowHttpJobType( ProxyConfig proxy )
private boolean isProxyAllowHttpJobType( GlobalProxyConfig proxy )
{
return proxy != null && proxy.getAllowHttpJobTypes().contains( httpJobType.name() );
}
Expand Down

0 comments on commit 44cf512

Please sign in to comment.