Search in sources :

Example 1 with IOSession

use of org.apache.http.nio.reactor.IOSession in project wso2-synapse by wso2.

the class PassThroughHttpSenderTest method testSubmitResponse.

/**
 * This method tests the submitting of response when the source request is null
 * @throws Exception
 */
@Test
public void testSubmitResponse() throws Exception {
    MockitoAnnotations.initMocks(this);
    MessageContext messageContext = new MessageContext();
    messageContext.setProperty(Constants.Configuration.TRANSPORT_URL, "http://sample.url");
    messageContext.setProperty(NhttpConstants.FORCE_HTTP_CONTENT_LENGTH, true);
    messageContext.setProperty(PassThroughConstants.COPY_CONTENT_LENGTH_FROM_INCOMING, true);
    messageContext.setProperty(PassThroughConstants.ORGINAL_CONTEN_LENGTH, "1000");
    messageContext.setOperationContext(new OperationContext());
    IOSession session = PowerMockito.mock(IOSession.class);
    NHttpServerConnection conn = new DefaultNHttpServerConnection(session, 12);
    messageContext.setProperty(PassThroughConstants.PASS_THROUGH_SOURCE_CONNECTION, conn);
    messageContext.setProperty(PassThroughConstants.HTTP_ETAG_ENABLED, true);
    Map headers = new HashMap();
    headers.put("randomKey", "randomValue");
    messageContext.setProperty(MessageContext.TRANSPORT_HEADERS, headers);
    sender = PowerMockito.spy(sender);
    PowerMockito.when(digestGenerator.getDigest(any(MessageContext.class))).thenReturn("testString");
    sender.submitResponse(messageContext);
}
Also used : OperationContext(org.apache.axis2.context.OperationContext) NHttpServerConnection(org.apache.http.nio.NHttpServerConnection) DefaultNHttpServerConnection(org.apache.http.impl.nio.DefaultNHttpServerConnection) HashMap(java.util.HashMap) IOSession(org.apache.http.nio.reactor.IOSession) MessageContext(org.apache.axis2.context.MessageContext) HashMap(java.util.HashMap) Map(java.util.Map) DefaultNHttpServerConnection(org.apache.http.impl.nio.DefaultNHttpServerConnection) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with IOSession

use of org.apache.http.nio.reactor.IOSession in project wso2-synapse by wso2.

the class ClientConnFactory method upgrade.

public void upgrade(final UpgradableNHttpConnection conn) {
    if (ssl != null) {
        IOSession iosession = conn.getIOSession();
        if (!(iosession instanceof SSLIOSession)) {
            SSLContext customContext = getSSLContext(iosession);
            SSLIOSession ssliosession = createClientModeSSLsession(iosession, customContext);
            iosession.setAttribute(SSLIOSession.SESSION_KEY, ssliosession);
            conn.bind(ssliosession);
        }
    }
}
Also used : SSLIOSession(org.apache.http.nio.reactor.ssl.SSLIOSession) SSLIOSession(org.apache.http.nio.reactor.ssl.SSLIOSession) IOSession(org.apache.http.nio.reactor.IOSession) SSLContext(javax.net.ssl.SSLContext)

Example 3 with IOSession

use of org.apache.http.nio.reactor.IOSession in project wso2-synapse by wso2.

the class ClientConnFactory method upgrade.

public void upgrade(final UpgradableNHttpConnection conn, HttpRoute route) {
    org.apache.http.HttpHost targetHost = route.getTargetHost();
    if (ssl != null) {
        IOSession iosession = conn.getIOSession();
        if (!(iosession instanceof SSLIOSession)) {
            SSLContext customContext = getSSLContext(targetHost);
            SSLIOSession ssliosession = createClientModeSSLsession(iosession, customContext);
            iosession.setAttribute(SSLIOSession.SESSION_KEY, ssliosession);
            conn.bind(ssliosession);
        }
    }
}
Also used : SSLIOSession(org.apache.http.nio.reactor.ssl.SSLIOSession) SSLIOSession(org.apache.http.nio.reactor.ssl.SSLIOSession) IOSession(org.apache.http.nio.reactor.IOSession) SSLContext(javax.net.ssl.SSLContext) HttpHost(org.apache.http.HttpHost)

Example 4 with IOSession

use of org.apache.http.nio.reactor.IOSession in project wso2-synapse by wso2.

the class ClientConnFactory method createConnection.

public DefaultNHttpClientConnection createConnection(final IOSession iosession, final HttpRoute route) {
    IOSession customSession;
    if (ssl != null && route.isSecure() && !route.isTunnelled()) {
        SSLContext customContext = getSSLContext(iosession);
        SSLIOSession ssliosession = createClientModeSSLsession(iosession, customContext);
        iosession.setAttribute(SSLIOSession.SESSION_KEY, ssliosession);
        customSession = ssliosession;
    } else {
        customSession = iosession;
    }
    DefaultNHttpClientConnection conn = LoggingUtils.createClientConnection(customSession, responseFactory, allocator, params);
    int timeout = HttpConnectionParams.getSoTimeout(params);
    conn.setSocketTimeout(timeout);
    return conn;
}
Also used : SSLIOSession(org.apache.http.nio.reactor.ssl.SSLIOSession) SSLIOSession(org.apache.http.nio.reactor.ssl.SSLIOSession) IOSession(org.apache.http.nio.reactor.IOSession) SSLContext(javax.net.ssl.SSLContext) DefaultNHttpClientConnection(org.apache.http.impl.nio.DefaultNHttpClientConnection)

Example 5 with IOSession

use of org.apache.http.nio.reactor.IOSession in project wso2-synapse by wso2.

the class ServerConnFactory method createConnection.

public DefaultNHttpServerConnection createConnection(final IOSession iosession) {
    SSLContextDetails customSSL = null;
    if (sslByIPMap != null) {
        customSSL = sslByIPMap.get(iosession.getLocalAddress());
        if (customSSL == null && allNetworkAddress != null) {
            customSSL = sslByIPMap.get(allNetworkAddress);
        }
    }
    if (customSSL == null) {
        customSSL = ssl;
    }
    IOSession customSession;
    if (customSSL != null) {
        customSession = new SSLIOSession(iosession, SSLMode.SERVER, customSSL.getContext(), customSSL.getHandler());
        iosession.setAttribute(SSLIOSession.SESSION_KEY, customSession);
    } else {
        customSession = iosession;
    }
    DefaultNHttpServerConnection conn = LoggingUtils.createServerConnection(customSession, requestFactory, allocator, params);
    int timeout = HttpConnectionParams.getSoTimeout(params);
    conn.setSocketTimeout(timeout);
    return conn;
}
Also used : SSLIOSession(org.apache.http.nio.reactor.ssl.SSLIOSession) SSLIOSession(org.apache.http.nio.reactor.ssl.SSLIOSession) IOSession(org.apache.http.nio.reactor.IOSession) DefaultNHttpServerConnection(org.apache.http.impl.nio.DefaultNHttpServerConnection)

Aggregations

IOSession (org.apache.http.nio.reactor.IOSession)5 SSLIOSession (org.apache.http.nio.reactor.ssl.SSLIOSession)4 SSLContext (javax.net.ssl.SSLContext)3 DefaultNHttpServerConnection (org.apache.http.impl.nio.DefaultNHttpServerConnection)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 MessageContext (org.apache.axis2.context.MessageContext)1 OperationContext (org.apache.axis2.context.OperationContext)1 HttpHost (org.apache.http.HttpHost)1 DefaultNHttpClientConnection (org.apache.http.impl.nio.DefaultNHttpClientConnection)1 NHttpServerConnection (org.apache.http.nio.NHttpServerConnection)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1