Skip to content

Commit

Permalink
Use GlobalProxyConfig bean for global proxy support
Browse files Browse the repository at this point in the history
  • Loading branch information
yma96 committed Aug 9, 2024
1 parent 44b6a49 commit 348b3ba
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ private void initKojiClient( String exchangeName, boolean verifyArtifacts )
GalleyCore galley = new GalleyCoreBuilder(
new FileCacheProviderFactory( temp.newFolder( "cache" ) ) ).withEnabledTransports(
new HttpClientTransport( new HttpImpl( new org.commonjava.maven.galley.auth.MemoryPasswordManager() ),
new IndyObjectMapper( true ), new GlobalHttpConfiguration(), null, null ) ).build();
new IndyObjectMapper( true ), new GlobalHttpConfiguration().getGlobalProxyConfig(), null, null ) ).build();

WeftExecutorService rescanService =
new PoolWeftExecutorService( "test-rescan-executor", (ThreadPoolExecutor) Executors.newCachedThreadPool(), 2, 10f, false,null, null );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ protected void initBaseTestConfig( CoreServerFixture fixture )

writeConfigFile( "conf.d/folo.conf", "[folo]\nfolo.cassandra=true" + "\nfolo.cassandra.keyspace=folo"
+ "\ntrack.group.content=True" );
writeConfigFile( "conf.d/http.conf", "[http]\nproxy.host=proxy.com" + "\nproxy.port=3128" );

if ( isSchedulerEnabled() )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.commonjava.maven.galley.spi.event.FileEventManager;
import org.commonjava.maven.galley.spi.nfc.NotFoundCache;
import org.commonjava.maven.galley.transport.htcli.conf.GlobalHttpConfiguration;
import org.commonjava.maven.galley.transport.htcli.conf.GlobalProxyConfig;
import org.junit.rules.TemporaryFolder;

import javax.annotation.PostConstruct;
Expand All @@ -48,6 +49,8 @@
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.fail;

Expand Down Expand Up @@ -187,7 +190,6 @@ public WeftConfig getWeftConfig()
}

@Produces
@Alternative
public GlobalHttpConfiguration getGlobalHttpConfiguration()
{
return globalHttpConfiguration;
Expand Down
6 changes: 4 additions & 2 deletions subsys/http/src/main/conf/http.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[http]
enabled=true
##
## Below are for default site config
##
Expand All @@ -10,8 +11,9 @@
#user=

## Proxy settings
#proxy.host=http://myproxy.com
#proxy.port=8001
#proxy.host=myproxy.com
#proxy.port=3128
#proxy.allow.http.job.types=download,existence,listing
#proxy.user=proxy-user

## Trust type. Value could be either default or self-signed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package org.commonjava.indy.subsys.http;

import org.commonjava.indy.subsys.http.conf.IndyHttpConfig;
import org.commonjava.indy.subsys.http.util.IndySiteConfigLookup;
import org.commonjava.maven.galley.transport.htcli.conf.GlobalHttpConfiguration;
import org.commonjava.maven.galley.transport.htcli.conf.ProxyConfig;
import org.commonjava.maven.galley.transport.htcli.conf.GlobalProxyConfig;
import org.commonjava.util.jhttpc.model.SiteConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Default;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import java.util.ArrayList;
Expand All @@ -19,35 +16,31 @@
import static org.commonjava.indy.subsys.http.conf.IndyHttpConfig.DEFAULT_SITE;

@ApplicationScoped
public class IndyGlobalHttpConfigurationProducer
public class IndyGlobalProxyConfigProducer
{
private final Logger logger = LoggerFactory.getLogger( getClass() );

@Inject
private IndyHttpConfig config;

@Inject
private IndySiteConfigLookup siteConfigLookup;

private GlobalHttpConfiguration globalHttpConfiguration;
private GlobalProxyConfig globalProxyConfig;

private SiteConfig defaultSiteConfig;

@Produces
@Default
public GlobalHttpConfiguration getGlobalHttpConfiguration()
public GlobalProxyConfig getGlobalProxyConfig()
{
defaultSiteConfig = siteConfigLookup.lookup( DEFAULT_SITE );
if ( defaultSiteConfig != null && defaultSiteConfig.getProxyHost() != null )
{
setUpGlobalHttpConfiguration();
setupGlobalProxyConfig();
}
return globalHttpConfiguration;
return globalProxyConfig;
}

private void setUpGlobalHttpConfiguration()
private void setupGlobalProxyConfig()
{
logger.info( "Setup global http configuration" );
logger.debug( "Setup global proxy config, host: {}", defaultSiteConfig.getProxyHost() );
final String allowTypes = defaultSiteConfig.getProxyAllowHttpJobTypes();
final List<String> list = new ArrayList<>();
if ( isNotBlank( allowTypes ) )
Expand All @@ -62,7 +55,7 @@ private void setUpGlobalHttpConfiguration()
}
}
}
ProxyConfig proxyConfig = new ProxyConfig()
globalProxyConfig = new GlobalProxyConfig()
{
@Override
public String getHost()
Expand All @@ -88,6 +81,5 @@ public List<String> getAllowHttpJobTypes()
return list;
}
};
globalHttpConfiguration = new GlobalHttpConfiguration( proxyConfig );
}
}
2 changes: 1 addition & 1 deletion subsys/http/src/main/resources/default-http.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#user=

## Proxy settings
#proxy.host=http://myproxy.com
#proxy.host=myproxy.com
#proxy.port=3128
#proxy.allow.http.job.types=download,existence,listing
#proxy.user=proxy-user
Expand Down

0 comments on commit 348b3ba

Please sign in to comment.