Search in sources :

Example 6 with TargetConfiguration

use of org.apache.synapse.transport.passthru.config.TargetConfiguration 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)

Example 7 with TargetConfiguration

use of org.apache.synapse.transport.passthru.config.TargetConfiguration in project wso2-synapse by wso2.

the class TargetHandlerTest method testOutputReady.

/**
 * Testing whether output-ready connection is processed
 *
 * @throws Exception
 */
@Test
public void testOutputReady() throws Exception {
    DeliveryAgent deliveryAgent = mock(DeliveryAgent.class);
    ClientConnFactory connFactory = mock(ClientConnFactory.class);
    ConfigurationContext configurationContext = new ConfigurationContext(new AxisConfiguration());
    WorkerPool workerPool = new NativeWorkerPool(3, 4, 5, 5, "name", "id");
    PassThroughTransportMetricsCollector metrics = new PassThroughTransportMetricsCollector(true, "testScheme");
    TargetConfiguration targetConfiguration = new TargetConfiguration(configurationContext, null, workerPool, metrics, null);
    TargetContext targetContext = new TargetContext(targetConfiguration);
    MessageContext messageContext = new MessageContext();
    targetContext.setRequestMsgCtx(messageContext);
    TargetHandler targetHandler = new TargetHandler(deliveryAgent, connFactory, targetConfiguration);
    TargetRequest request = mock(TargetRequest.class);
    NHttpClientConnection conn = mock(NHttpClientConnection.class, Mockito.RETURNS_DEEP_STUBS);
    ContentEncoder encoder = mock(ContentEncoder.class);
    mockStatic(TargetContext.class);
    when(TargetContext.get(conn)).thenReturn(targetContext);
    when(TargetContext.getState(conn)).thenReturn(ProtocolState.REQUEST_HEAD);
    when(TargetContext.getRequest(conn)).thenReturn(request);
    when(request.hasEntityBody()).thenReturn(true);
    when(request.write(conn, encoder)).thenReturn(12);
    when(encoder.isCompleted()).thenReturn(true);
    targetHandler.outputReady(conn, encoder);
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) TargetConfiguration(org.apache.synapse.transport.passthru.config.TargetConfiguration) PassThroughTransportMetricsCollector(org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector) ContentEncoder(org.apache.http.nio.ContentEncoder) NativeWorkerPool(org.apache.axis2.transport.base.threads.NativeWorkerPool) NHttpClientConnection(org.apache.http.nio.NHttpClientConnection) WorkerPool(org.apache.axis2.transport.base.threads.WorkerPool) NativeWorkerPool(org.apache.axis2.transport.base.threads.NativeWorkerPool) ClientConnFactory(org.apache.synapse.transport.http.conn.ClientConnFactory) MessageContext(org.apache.axis2.context.MessageContext) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with TargetConfiguration

use of org.apache.synapse.transport.passthru.config.TargetConfiguration in project wso2-synapse by wso2.

the class TargetHandlerTest method testInputReady.

/**
 * Testing whether input-ready connection is processed
 *
 * @throws Exception
 */
@Test
public void testInputReady() throws Exception {
    DeliveryAgent deliveryAgent = mock(DeliveryAgent.class);
    ClientConnFactory connFactory = mock(ClientConnFactory.class);
    ConfigurationContext configurationContext = new ConfigurationContext(new AxisConfiguration());
    WorkerPool workerPool = new NativeWorkerPool(3, 4, 5, 5, "name", "id");
    PassThroughTransportMetricsCollector metrics = new PassThroughTransportMetricsCollector(true, "testScheme");
    TargetConfiguration targetConfiguration = new TargetConfiguration(configurationContext, null, workerPool, metrics, null);
    TargetContext targetContext = new TargetContext(targetConfiguration);
    MessageContext messageContext = new MessageContext();
    targetContext.setRequestMsgCtx(messageContext);
    TargetHandler targetHandler = new TargetHandler(deliveryAgent, connFactory, targetConfiguration);
    TargetResponse response = mock(TargetResponse.class);
    NHttpClientConnection conn = mock(NHttpClientConnection.class, Mockito.RETURNS_DEEP_STUBS);
    ContentDecoder decoder = mock(ContentDecoder.class);
    mockStatic(TargetContext.class);
    when(TargetContext.get(conn)).thenReturn(targetContext);
    when(TargetContext.getState(conn)).thenReturn(ProtocolState.RESPONSE_HEAD);
    when(TargetContext.getResponse(conn)).thenReturn(response);
    when(decoder.isCompleted()).thenReturn(true);
    targetHandler.inputReady(conn, decoder);
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) TargetConfiguration(org.apache.synapse.transport.passthru.config.TargetConfiguration) PassThroughTransportMetricsCollector(org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector) NativeWorkerPool(org.apache.axis2.transport.base.threads.NativeWorkerPool) ContentDecoder(org.apache.http.nio.ContentDecoder) NHttpClientConnection(org.apache.http.nio.NHttpClientConnection) WorkerPool(org.apache.axis2.transport.base.threads.WorkerPool) NativeWorkerPool(org.apache.axis2.transport.base.threads.NativeWorkerPool) ClientConnFactory(org.apache.synapse.transport.http.conn.ClientConnFactory) MessageContext(org.apache.axis2.context.MessageContext) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

TargetConfiguration (org.apache.synapse.transport.passthru.config.TargetConfiguration)8 Test (org.junit.Test)7 WorkerPool (org.apache.axis2.transport.base.threads.WorkerPool)6 NHttpClientConnection (org.apache.http.nio.NHttpClientConnection)6 PassThroughTransportMetricsCollector (org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)5 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)5 NativeWorkerPool (org.apache.axis2.transport.base.threads.NativeWorkerPool)5 TargetConnections (org.apache.synapse.transport.passthru.connections.TargetConnections)4 MessageContext (org.apache.axis2.context.MessageContext)3 HttpResponse (org.apache.http.HttpResponse)3 ClientConnFactory (org.apache.synapse.transport.http.conn.ClientConnFactory)3 ContentDecoder (org.apache.http.nio.ContentDecoder)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 RemoteException (java.rmi.RemoteException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 EndpointReference (org.apache.axis2.addressing.EndpointReference)1 OperationContext (org.apache.axis2.context.OperationContext)1