use of org.apache.axis2.context.ConfigurationContext in project pentaho-platform by pentaho.
the class WsdlPageTest method setUp.
@Before
public void setUp() {
beforeTestCfg = AxisWebServiceManager.currentAxisConfiguration;
beforeTestCtx = AxisWebServiceManager.currentAxisConfigContext;
AxisConfiguration axisCfg = new AxisConfiguration();
AxisWebServiceManager.currentAxisConfiguration = axisCfg;
AxisWebServiceManager.currentAxisConfigContext = new ConfigurationContext(axisCfg);
out = new ByteArrayOutputStream();
IOutputHandler outputHandler = new SimpleOutputHandler(out, false);
outputHandler.setMimeTypeListener(new MimeTypeListener());
StandaloneSession session = new StandaloneSession("test");
StubServiceSetup serviceSetup = new StubServiceSetup();
serviceSetup.setSession(session);
contentGenerator = new AxisServiceWsdlGenerator();
contentGenerator.setOutputHandler(outputHandler);
contentGenerator.setMessagesList(new ArrayList<String>());
contentGenerator.setSession(session);
contentGenerator.setUrlFactory(new SimpleUrlFactory(BASE_URL + "?"));
}
use of org.apache.axis2.context.ConfigurationContext 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...");
}
use of org.apache.axis2.context.ConfigurationContext in project wso2-synapse by wso2.
the class ServerWorker method createMessageContext.
/**
* Create an Axis2 message context for the given http request. The request may be in the
* process of being streamed
*
* @param request the http request to be used to create the corresponding Axis2 message context
* @return the Axis2 message context created
*/
public MessageContext createMessageContext(MessageContext msgContext, SourceRequest request) {
Map excessHeaders = request.getExcessHeaders();
ConfigurationContext cfgCtx = sourceConfiguration.getConfigurationContext();
if (msgContext == null) {
msgContext = new MessageContext();
}
msgContext.setMessageID(UIDGenerator.generateURNString());
// Axis2 spawns a new threads to send a message if this is TRUE - and it has to
// be the other way
msgContext.setProperty(MessageContext.CLIENT_API_NON_BLOCKING, Boolean.FALSE);
msgContext.setConfigurationContext(cfgCtx);
// msgContext.setTransportOut(cfgCtx.getAxisConfiguration()
// .getTransportOut(Constants.TRANSPORT_HTTP));
// msgContext.setTransportIn(cfgCtx.getAxisConfiguration()
// .getTransportIn(Constants.TRANSPORT_HTTP));
// msgContext.setIncomingTransportName(Constants.TRANSPORT_HTTP);
// msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, this);
NHttpServerConnection conn = request.getConnection();
if (sourceConfiguration.getScheme().isSSL()) {
msgContext.setTransportOut(cfgCtx.getAxisConfiguration().getTransportOut(Constants.TRANSPORT_HTTPS));
msgContext.setTransportIn(cfgCtx.getAxisConfiguration().getTransportIn(Constants.TRANSPORT_HTTPS));
msgContext.setIncomingTransportName(sourceConfiguration.getInDescription() != null ? sourceConfiguration.getInDescription().getName() : Constants.TRANSPORT_HTTPS);
SSLIOSession ssliosession = (SSLIOSession) (conn.getContext()).getAttribute(SSLIOSession.SESSION_KEY);
// set SSL certificates to message context if SSLVerifyClient parameter is set
if (ssliosession != null && msgContext.getTransportIn() != null && msgContext.getTransportIn().getParameter(NhttpConstants.SSL_VERIFY_CLIENT) != null) {
try {
msgContext.setProperty(NhttpConstants.SSL_CLIENT_AUTH_CERT_X509, ssliosession.getSSLSession().getPeerCertificateChain());
} catch (SSLPeerUnverifiedException e) {
// Peer Certificate Chain may not be available always.(in case of Mutual SSL is not enabled)
if (log.isTraceEnabled()) {
log.trace("Peer certificate chain is not available for MsgContext " + msgContext.getMessageID());
}
}
}
} else {
msgContext.setTransportOut(cfgCtx.getAxisConfiguration().getTransportOut(Constants.TRANSPORT_HTTP));
msgContext.setTransportIn(cfgCtx.getAxisConfiguration().getTransportIn(Constants.TRANSPORT_HTTP));
msgContext.setIncomingTransportName(sourceConfiguration.getInDescription() != null ? sourceConfiguration.getInDescription().getName() : Constants.TRANSPORT_HTTP);
}
msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, this);
msgContext.setServerSide(true);
msgContext.setProperty(Constants.Configuration.TRANSPORT_IN_URL, request.getUri());
// http transport header names are case insensitive
Map<String, String> headers = new TreeMap<String, String>(new Comparator<String>() {
public int compare(String o1, String o2) {
return o1.compareToIgnoreCase(o2);
}
});
Set<Map.Entry<String, String>> entries = request.getHeaders().entrySet();
for (Map.Entry<String, String> entry : entries) {
headers.put(entry.getKey(), entry.getValue());
}
msgContext.setProperty(MessageContext.TRANSPORT_HEADERS, headers);
msgContext.setProperty(NhttpConstants.EXCESS_TRANSPORT_HEADERS, excessHeaders);
if (conn instanceof HttpInetConnection) {
HttpInetConnection netConn = (HttpInetConnection) conn;
InetAddress remoteAddress = netConn.getRemoteAddress();
if (remoteAddress != null) {
msgContext.setProperty(MessageContext.REMOTE_ADDR, remoteAddress.getHostAddress());
msgContext.setProperty(NhttpConstants.REMOTE_HOST, NhttpUtil.getHostName(remoteAddress));
}
}
msgContext.setProperty(RequestResponseTransport.TRANSPORT_CONTROL, new HttpCoreRequestResponseTransport(msgContext));
return msgContext;
}
use of org.apache.axis2.context.ConfigurationContext in project wso2-synapse by wso2.
the class HttpCoreNIOSender method init.
/**
* Initialize the transport sender, and execute reactor in new separate thread
* @param cfgCtx the Axis2 configuration context
* @param transportOut the description of the http/s transport from Axis2 configuration
* @throws AxisFault thrown on an error
*/
public void init(ConfigurationContext cfgCtx, TransportOutDescription transportOut) throws AxisFault {
this.configurationContext = cfgCtx;
cfg = NHttpConfiguration.getInstance();
params = new BasicHttpParams();
params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, cfg.getProperty(NhttpConstants.SO_TIMEOUT_SENDER, 60000)).setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, cfg.getProperty(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000)).setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, cfg.getProperty(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)).setParameter(CoreProtocolPNames.USER_AGENT, "Synapse-HttpComponents-NIO");
// .setParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET,
// cfg.getStringValue(CoreProtocolPNames.HTTP_ELEMENT_CHARSET,HTTP.DEFAULT_PROTOCOL_CHARSET)); //TODO:This does not works with HTTPCore 4.3
name = transportOut.getName().toUpperCase(Locale.US) + " Sender";
ClientConnFactoryBuilder contextBuilder = initConnFactoryBuilder(transportOut);
connFactory = contextBuilder.createConnFactory(params);
connpool = new ConnectionPool();
proxyConfig = new ProxyConfigBuilder().build(transportOut);
log.info(proxyConfig.logProxyConfig());
Parameter param = transportOut.getParameter("warnOnHTTP500");
if (param != null) {
String[] warnOnHttp500 = ((String) param.getValue()).split("\\|");
cfgCtx.setNonReplicableProperty("warnOnHTTP500", warnOnHttp500);
}
IOReactorConfig ioReactorConfig = new IOReactorConfig();
ioReactorConfig.setIoThreadCount(NHttpConfiguration.getInstance().getClientIOWorkers());
ioReactorConfig.setSoTimeout(cfg.getProperty(NhttpConstants.SO_TIMEOUT_RECEIVER, 60000));
ioReactorConfig.setConnectTimeout(cfg.getProperty(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000));
ioReactorConfig.setTcpNoDelay(cfg.getProperty(CoreConnectionPNames.TCP_NODELAY, 1) == 1);
if (cfg.getBooleanValue("http.nio.interest-ops-queueing", false)) {
ioReactorConfig.setInterestOpQueued(true);
}
try {
String prefix = name + " I/O dispatcher";
ioReactor = new DefaultConnectingIOReactor(ioReactorConfig, new NativeThreadFactory(new ThreadGroup(prefix + " thread group"), prefix));
ioReactor.setExceptionHandler(new IOReactorExceptionHandler() {
public boolean handle(IOException ioException) {
log.warn("System may be unstable: IOReactor encountered a checked exception : " + ioException.getMessage(), ioException);
return true;
}
public boolean handle(RuntimeException runtimeException) {
log.warn("System may be unstable: IOReactor encountered a runtime exception : " + runtimeException.getMessage(), runtimeException);
return true;
}
});
} catch (IOException e) {
log.error("Error starting the IOReactor", e);
throw new AxisFault(e.getMessage(), e);
}
metrics = new NhttpMetricsCollector(false, transportOut.getName());
handler = new ClientHandler(connpool, connFactory, proxyConfig, cfgCtx, params, metrics);
iodispatch = new ClientIODispatch(handler, connFactory);
final IOEventDispatch ioEventDispatch = iodispatch;
// start the Sender in a new seperate thread
Thread t = new Thread(new Runnable() {
public void run() {
try {
ioReactor.execute(ioEventDispatch);
} catch (InterruptedIOException ex) {
log.fatal("Reactor Interrupted");
} catch (IOException e) {
log.fatal("Encountered an I/O error: " + e.getMessage(), e);
}
log.info(name + " Shutdown");
}
}, "HttpCoreNIOSender");
t.start();
log.info(name + " starting");
// register with JMX
mbeanSupport = new TransportMBeanSupport(this, "nio-" + transportOut.getName());
mbeanSupport.register();
state = BaseConstants.STARTED;
}
use of org.apache.axis2.context.ConfigurationContext in project wso2-synapse by wso2.
the class Axis2LoadBalanceMembershipHandler method setConfigurationContext.
public void setConfigurationContext(ConfigurationContext configCtx) {
this.configCtx = configCtx;
// The following code does the bridging between Axis2 and Synapse load balancing
ClusteringAgent clusteringAgent = configCtx.getAxisConfiguration().getClusteringAgent();
if (clusteringAgent == null) {
String msg = "In order to enable load balancing across an Axis2 cluster, " + "the cluster entry should be enabled in the axis2.xml file";
log.error(msg);
throw new SynapseException(msg);
}
groupMgtAgent = clusteringAgent.getGroupManagementAgent(lbDomain);
if (groupMgtAgent == null) {
String msg = "A LoadBalanceEventHandler has not been specified in the axis2.xml " + "file for the domain " + lbDomain;
log.error(msg);
throw new SynapseException(msg);
}
}
Aggregations