in modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/PassThroughHttpSender.java [114:238]
public void init(ConfigurationContext configurationContext,
TransportOutDescription transportOutDescription) throws AxisFault {
if (log.isDebugEnabled()) {
log.debug("Initializing pass-through HTTP/S sender...");
}
// is this an SSL Sender?
SSLContext sslContext = getSSLContext(transportOutDescription);
SSLSetupHandler sslSetupHandler = getSSLSetupHandler(transportOutDescription);
// configure proxy settings
if (sslContext == null) {
Parameter proxyHostParam = transportOutDescription.getParameter("http.proxyHost");
if (proxyHostParam != null || System.getProperty("http.proxyHost") != null) {
if (proxyHostParam != null) {
proxyHost = (String) proxyHostParam.getValue();
} else {
proxyHost = System.getProperty("http.proxyHost");
}
Parameter proxyPortParam = transportOutDescription.getParameter("http.proxyPort");
if (proxyPortParam != null) {
proxyPort = Integer.parseInt((String) proxyPortParam.getValue());
} else if (System.getProperty("http.proxyPort") != null) {
proxyPort = Integer.parseInt(System.getProperty("http.proxyPort"));
}
Parameter bypassList = transportOutDescription.getParameter("http.nonProxyHosts");
if (bypassList != null) {
proxyBypassList = ((String) bypassList.getValue()).split("\\|");
} else if (System.getProperty("http.nonProxyHosts") != null) {
proxyBypassList = (System.getProperty("http.nonProxyHosts")).split("\\|");
}
log.info("HTTP sender using Proxy : "
+ proxyHost + ":" + proxyPort + " bypassing : " + Arrays.toString(proxyBypassList));
}
}
namePrefix = (sslContext == null) ? "HTTP" : "HTTPS";
WorkerPool workerPool = null;
Object obj = configurationContext.getProperty(
PassThroughConstants.PASS_THROUGH_TRANSPORT_WORKER_POOL);
if (obj != null) {
workerPool = (WorkerPool) obj;
}
targetConfiguration = new TargetConfiguration(configurationContext,
transportOutDescription, workerPool);
configurationContext.setProperty(PassThroughConstants.PASS_THROUGH_TRANSPORT_WORKER_POOL,
targetConfiguration.getWorkerPool());
PassThroughTransportMetricsCollector metrics = new
PassThroughTransportMetricsCollector(false, sslContext != null);
TransportView view = new TransportView(null, this, metrics, null);
MBeanRegistrar.getInstance().registerMBean(view, "Transport",
"passthru-" + namePrefix.toLowerCase() + "-sender");
targetConfiguration.setMetrics(metrics);
try {
String prefix = namePrefix + "-PT-Sender I/O Dispatcher";
ioReactor = new DefaultConnectingIOReactor(
targetConfiguration.getReactorConfig(false),
new NativeThreadFactory(new ThreadGroup(prefix + " Thread Group"), prefix));
ioReactor.setExceptionHandler(new IOReactorExceptionHandler() {
@Override
public boolean handle(IOException ioException) {
log.warn("System may be unstable: " + namePrefix +
" ConnectingIOReactor encountered a checked exception : " +
ioException.getMessage(), ioException);
return true;
}
@Override
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();
// manage target connections
TargetConnections targetConnections =
new TargetConnections(ioReactor, targetConfiguration, connectCallback);
targetConfiguration.setConnections(targetConnections);
// create the delivery agent to hand over messages
deliveryAgent = new DeliveryAgent(targetConfiguration, targetConnections);
// we need to set the delivery agent
connectCallback.setDeliveryAgent(deliveryAgent);
TargetHandler handler = new TargetHandler(deliveryAgent, targetConfiguration);
final IOEventDispatch ioEventDispatch =
getEventDispatch(handler, sslContext, sslSetupHandler,
targetConfiguration.getConnectionConfig(), transportOutDescription);
// start the sender in a separate thread
Thread t = new Thread(new Runnable() {
@Override
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...");
}