use of org.apache.synapse.transport.http.conn.ProxyConfig in project wso2-synapse by wso2.
the class ProxyConfigBuilder method build.
/**
* Tries to read the axis2.xml transport sender's proxy configuration
* @param transportOut axis2 transport out description
* @return ProxyConfig
* @throws AxisFault
*/
public ProxyConfig build(TransportOutDescription transportOut) throws AxisFault {
name = transportOut.getName();
Map<String, ProxyProfileConfig> proxyProfileConfigMap = getProxyProfiles(transportOut);
// if proxy profile is configured we only read profile related configuration
if (proxyProfileConfigMap == null) {
String proxyHost = null;
int proxyPort = -1;
Parameter proxyHostParam = transportOut.getParameter(PassThroughConstants.HTTP_PROXY_HOST);
if (proxyHostParam != null) {
proxyHost = (String) proxyHostParam.getValue();
Parameter proxyPortParam = transportOut.getParameter(PassThroughConstants.HTTP_PROXY_PORT);
if (proxyPortParam != null) {
proxyPort = Integer.parseInt((String) proxyPortParam.getValue());
}
}
if (proxyHost == null) {
proxyHost = System.getProperty(PassThroughConstants.HTTP_PROXY_HOST);
if (proxyHost != null) {
String s = System.getProperty(PassThroughConstants.HTTP_PROXY_PORT);
if (s != null) {
proxyPort = Integer.parseInt(s);
}
}
}
if (proxyHost != null) {
proxy = new HttpHost(proxyHost, proxyPort >= 0 ? proxyPort : 80);
String bypassListStr = null;
Parameter bypassListParam = transportOut.getParameter(PassThroughConstants.HTTP_NON_PROXY_HOST);
if (bypassListParam == null) {
bypassListStr = System.getProperty(PassThroughConstants.HTTP_NON_PROXY_HOST);
} else {
bypassListStr = (String) bypassListParam.getValue();
}
if (bypassListStr != null) {
proxyBypass = bypassListStr.split("\\|");
}
Parameter proxyUsernameParam = transportOut.getParameter(PassThroughConstants.HTTP_PROXY_USERNAME);
Parameter proxyPasswordParam = transportOut.getParameter(PassThroughConstants.HTTP_PROXY_PASSWORD);
if (proxyUsernameParam != null) {
proxyCredentials = new UsernamePasswordCredentials((String) proxyUsernameParam.getValue(), proxyPasswordParam != null ? (String) proxyPasswordParam.getValue() : "");
}
}
}
return new ProxyConfig(proxy, proxyCredentials, proxyBypass, proxyProfileConfigMap);
}
use of org.apache.synapse.transport.http.conn.ProxyConfig in project wso2-synapse by wso2.
the class DeliveryAgentTest method test.
/**
* This method tests whether the message is queued by the delivery agent when the connection is null
*
* @throws Exception
*/
@Test
public void test() throws Exception {
MessageContext messageContext = new MessageContext();
ServiceContext svcCtx = new ServiceContext();
OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx);
messageContext.setServiceContext(svcCtx);
messageContext.setOperationContext(opCtx);
TargetConfiguration targetConfiguration = PowerMockito.mock(TargetConfiguration.class);
TargetConnections conns = PowerMockito.mock(TargetConnections.class);
ProxyConfig config = PowerMockito.mock(ProxyConfig.class);
EndpointReference epr = new EndpointReference("http://127.0.0.1:3001/services");
DeliveryAgent agent = new DeliveryAgent(targetConfiguration, conns, config);
agent.submit(messageContext, epr);
Assert.assertEquals("127.0.0.1", messageContext.getProperty("PROXY_PROFILE_TARGET_HOST"));
}
Aggregations