use of org.apache.synapse.transport.passthru.config.TargetConfiguration in project wso2-synapse by wso2.
the class TargetHandlerTest method testRequestReady.
/**
* Testing whether request-ready connection is processed
*
* @throws Exception
*/
@Test
public void testRequestReady() throws Exception {
DeliveryAgent deliveryAgent = mock(DeliveryAgent.class);
ClientConnFactory connFactory = mock(ClientConnFactory.class);
TargetConfiguration configuration = mock(TargetConfiguration.class);
TargetHandler targetHandler = new TargetHandler(deliveryAgent, connFactory, configuration);
NHttpClientConnection conn = mock(NHttpClientConnection.class, Mockito.RETURNS_DEEP_STUBS);
HttpContext context = mock(HttpContext.class);
when(conn.getContext()).thenReturn(context);
mockStatic(TargetContext.class);
when(TargetContext.getState(any(NHttpClientConnection.class))).thenReturn(ProtocolState.REQUEST_READY);
targetHandler.requestReady(conn);
}
use of org.apache.synapse.transport.passthru.config.TargetConfiguration in project wso2-synapse by wso2.
the class TargetResponseTest method testTrue.
/**
* Testing the starting of target response when response body is expected
*
* @throws Exception
*/
@Test
public void testTrue() throws Exception {
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);
targetConfiguration.build();
HttpResponse response = PowerMockito.mock(HttpResponse.class, Mockito.RETURNS_DEEP_STUBS);
NHttpClientConnection conn = PowerMockito.mock(NHttpClientConnection.class, Mockito.RETURNS_DEEP_STUBS);
PowerMockito.mockStatic(TargetContext.class);
TargetContext cntxt = new TargetContext(targetConfiguration);
PowerMockito.when(TargetContext.get(any(NHttpClientConnection.class))).thenReturn(cntxt);
TargetResponse targetResponse = new TargetResponse(targetConfiguration, response, conn, true, false);
try {
targetResponse.start(conn);
} catch (Exception e) {
logger.error(e);
Assert.fail("Unable to start the target response!");
}
}
use of org.apache.synapse.transport.passthru.config.TargetConfiguration in project wso2-synapse by wso2.
the class TargetResponseTest method testFalse.
/**
* Testing the starting of target response when response body is not expected
*
* @throws Exception
*/
@Test
public void testFalse() throws Exception {
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);
HttpResponse response = PowerMockito.mock(HttpResponse.class, Mockito.RETURNS_DEEP_STUBS);
NHttpClientConnection conn = PowerMockito.mock(NHttpClientConnection.class, Mockito.RETURNS_DEEP_STUBS);
TargetConnections connections = PowerMockito.mock(TargetConnections.class);
targetConfiguration.setConnections(connections);
PowerMockito.mockStatic(TargetContext.class);
TargetResponse targetResponse = new TargetResponse(targetConfiguration, response, conn, false, false);
try {
targetResponse.start(conn);
} catch (Exception e) {
logger.error(e);
Assert.fail("Unable to start the target response!");
}
}
use of org.apache.synapse.transport.passthru.config.TargetConfiguration in project wso2-synapse by wso2.
the class TargetResponseTest method testRead.
/**
* Testing reading from a pipe
* @throws Exception
*/
@Test
public void testRead() throws Exception {
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);
targetConfiguration.build();
HttpResponse response = PowerMockito.mock(HttpResponse.class, Mockito.RETURNS_DEEP_STUBS);
NHttpClientConnection conn = PowerMockito.mock(NHttpClientConnection.class, Mockito.RETURNS_DEEP_STUBS);
ContentDecoder decoder = PowerMockito.mock(ContentDecoder.class);
TargetConnections connections = PowerMockito.mock(TargetConnections.class);
targetConfiguration.setConnections(connections);
PowerMockito.mockStatic(TargetContext.class);
TargetContext cntxt = new TargetContext(targetConfiguration);
PowerMockito.when(TargetContext.get(any(NHttpClientConnection.class))).thenReturn(cntxt);
PowerMockito.when(decoder.read(any(ByteBuffer.class))).thenReturn(12);
PowerMockito.when(decoder.isCompleted()).thenReturn(true);
TargetResponse targetResponse = new TargetResponse(targetConfiguration, response, conn, true, false);
targetResponse.start(conn);
int result = targetResponse.read(conn, decoder);
Assert.assertEquals(12, result);
}
use of org.apache.synapse.transport.passthru.config.TargetConfiguration in project wso2-synapse by wso2.
the class PassThroughHttpSender method init.
public void init(ConfigurationContext configurationContext, TransportOutDescription transportOutDescription) throws AxisFault {
log.info("Initializing Pass-through HTTP/S Sender...");
namePrefix = transportOutDescription.getName().toUpperCase(Locale.US);
scheme = getScheme();
WorkerPool workerPool = null;
Object obj = configurationContext.getProperty(PassThroughConstants.PASS_THROUGH_TRANSPORT_WORKER_POOL);
if (obj != null) {
workerPool = (WorkerPool) obj;
}
PassThroughTransportMetricsCollector metrics = new PassThroughTransportMetricsCollector(false, scheme.getName());
TransportView view = new TransportView(null, this, metrics, null);
MBeanRegistrar.getInstance().registerMBean(view, "Transport", "passthru-" + namePrefix.toLowerCase() + "-sender");
proxyConfig = new ProxyConfigBuilder().build(transportOutDescription);
log.info(proxyConfig.logProxyConfig());
targetConfiguration = new TargetConfiguration(configurationContext, transportOutDescription, workerPool, metrics, proxyConfig.createProxyAuthenticator());
targetConfiguration.build();
PassThroughSenderManager.registerPassThroughHttpSender(this);
configurationContext.setProperty(PassThroughConstants.PASS_THROUGH_TRANSPORT_WORKER_POOL, targetConfiguration.getWorkerPool());
ClientConnFactoryBuilder connFactoryBuilder = initConnFactoryBuilder(transportOutDescription);
connFactory = connFactoryBuilder.createConnFactory(targetConfiguration.getHttpParams());
try {
String prefix = namePrefix + "-Sender I/O dispatcher";
ioReactor = new DefaultConnectingIOReactor(targetConfiguration.getIOReactorConfig(), new NativeThreadFactory(new ThreadGroup(prefix + " Thread Group"), prefix));
ioReactor.setExceptionHandler(new IOReactorExceptionHandler() {
public boolean handle(IOException ioException) {
log.warn("System may be unstable: " + namePrefix + " ConnectingIOReactor encountered a checked exception : " + ioException.getMessage(), ioException);
return true;
}
public boolean handle(RuntimeException runtimeException) {
log.warn("System may be unstable: " + namePrefix + " ConnectingIOReactor encountered a runtime exception : " + runtimeException.getMessage(), runtimeException);
return true;
}
});
} catch (IOReactorException e) {
handleException("Error starting " + namePrefix + " ConnectingIOReactor", e);
}
ConnectCallback connectCallback = new ConnectCallback();
targetConnections = new TargetConnections(ioReactor, targetConfiguration, connectCallback);
targetConfiguration.setConnections(targetConnections);
// create the delivery agent to hand over messages
deliveryAgent = new DeliveryAgent(targetConfiguration, targetConnections, proxyConfig);
// we need to set the delivery agent
connectCallback.setDeliveryAgent(deliveryAgent);
handler = new TargetHandler(deliveryAgent, connFactory, targetConfiguration);
ioEventDispatch = new ClientIODispatch(handler, connFactory);
// start the sender in a separate thread
Thread t = new Thread(new Runnable() {
public void run() {
try {
ioReactor.execute(ioEventDispatch);
} catch (Exception ex) {
log.fatal("Exception encountered in the " + namePrefix + " Sender. " + "No more connections will be initiated by this transport", ex);
}
log.info(namePrefix + " Sender shutdown");
}
}, "PassThrough" + namePrefix + "Sender");
t.start();
state = BaseConstants.STARTED;
log.info("Pass-through " + namePrefix + " Sender started...");
}
Aggregations