Search in sources :

Example 1 with DefaultNHttpServerConnection

use of org.apache.http.impl.nio.DefaultNHttpServerConnection 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 DefaultNHttpServerConnection

use of org.apache.http.impl.nio.DefaultNHttpServerConnection 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

DefaultNHttpServerConnection (org.apache.http.impl.nio.DefaultNHttpServerConnection)2 IOSession (org.apache.http.nio.reactor.IOSession)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 NHttpServerConnection (org.apache.http.nio.NHttpServerConnection)1 SSLIOSession (org.apache.http.nio.reactor.ssl.SSLIOSession)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1