-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2450 from yma96/master
Support global http proxy config when during http jobs
- Loading branch information
Showing
8 changed files
with
106 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
subsys/http/src/main/java/org/commonjava/indy/subsys/http/IndyGlobalProxyConfigProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.commonjava.indy.subsys.http; | ||
|
||
import org.commonjava.indy.subsys.http.util.IndySiteConfigLookup; | ||
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.Produces; | ||
import javax.inject.Inject; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.apache.commons.lang3.StringUtils.isNotBlank; | ||
import static org.commonjava.indy.subsys.http.conf.IndyHttpConfig.DEFAULT_SITE; | ||
|
||
@ApplicationScoped | ||
public class IndyGlobalProxyConfigProducer | ||
{ | ||
private final Logger logger = LoggerFactory.getLogger( getClass() ); | ||
|
||
@Inject | ||
private IndySiteConfigLookup siteConfigLookup; | ||
|
||
private GlobalProxyConfig globalProxyConfig; | ||
|
||
private SiteConfig defaultSiteConfig; | ||
|
||
@Produces | ||
public GlobalProxyConfig getGlobalProxyConfig() | ||
{ | ||
defaultSiteConfig = siteConfigLookup.lookup( DEFAULT_SITE ); | ||
if ( defaultSiteConfig != null && defaultSiteConfig.getProxyHost() != null ) | ||
{ | ||
setupGlobalProxyConfig(); | ||
} | ||
return globalProxyConfig; | ||
} | ||
|
||
private void setupGlobalProxyConfig() | ||
{ | ||
logger.debug( "Setup global proxy config, host: {}", defaultSiteConfig.getProxyHost() ); | ||
final String allowTypes = defaultSiteConfig.getProxyAllowHttpJobTypes(); | ||
final List<String> list = new ArrayList<>(); | ||
if ( isNotBlank( allowTypes ) ) | ||
{ | ||
String[] toks = allowTypes.split( "," ); | ||
for ( String s : toks ) | ||
{ | ||
s = s.trim(); | ||
if ( isNotBlank( s ) ) | ||
{ | ||
list.add( s ); | ||
} | ||
} | ||
} | ||
globalProxyConfig = new GlobalProxyConfig() | ||
{ | ||
@Override | ||
public String getHost() | ||
{ | ||
return defaultSiteConfig.getProxyHost(); | ||
} | ||
|
||
@Override | ||
public int getPort() | ||
{ | ||
return defaultSiteConfig.getProxyPort(); | ||
} | ||
|
||
@Override | ||
public String getUser() | ||
{ | ||
return defaultSiteConfig.getProxyUser(); | ||
} | ||
|
||
@Override | ||
public List<String> getAllowHttpJobTypes() | ||
{ | ||
return list; | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters