Search in sources :

Example 1 with ProxyConfig

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);
}
Also used : ProxyProfileConfig(org.apache.synapse.transport.http.conn.ProxyProfileConfig) HttpHost(org.apache.http.HttpHost) Parameter(org.apache.axis2.description.Parameter) ProxyConfig(org.apache.synapse.transport.http.conn.ProxyConfig) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 2 with ProxyConfig

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"));
}
Also used : OperationContext(org.apache.axis2.context.OperationContext) TargetConfiguration(org.apache.synapse.transport.passthru.config.TargetConfiguration) ServiceContext(org.apache.axis2.context.ServiceContext) MessageContext(org.apache.axis2.context.MessageContext) ProxyConfig(org.apache.synapse.transport.http.conn.ProxyConfig) TargetConnections(org.apache.synapse.transport.passthru.connections.TargetConnections) InOutAxisOperation(org.apache.axis2.description.InOutAxisOperation) EndpointReference(org.apache.axis2.addressing.EndpointReference) Test(org.junit.Test)

Aggregations

ProxyConfig (org.apache.synapse.transport.http.conn.ProxyConfig)2 EndpointReference (org.apache.axis2.addressing.EndpointReference)1 MessageContext (org.apache.axis2.context.MessageContext)1 OperationContext (org.apache.axis2.context.OperationContext)1 ServiceContext (org.apache.axis2.context.ServiceContext)1 InOutAxisOperation (org.apache.axis2.description.InOutAxisOperation)1 Parameter (org.apache.axis2.description.Parameter)1 HttpHost (org.apache.http.HttpHost)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 ProxyProfileConfig (org.apache.synapse.transport.http.conn.ProxyProfileConfig)1 TargetConfiguration (org.apache.synapse.transport.passthru.config.TargetConfiguration)1 TargetConnections (org.apache.synapse.transport.passthru.connections.TargetConnections)1 Test (org.junit.Test)1