org.ow2.petals.binding.soap.SoapComponent Maven / Gradle / Ivy
Show all versions of petals-bc-soap Show documentation
/**
* Copyright (c) 2006-2012 EBM WebSourcing, 2012-2023 Linagora
*
* This program/library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or (at your
* option) any later version.
*
* This program/library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program/library; If not, see http://www.gnu.org/licenses/
* for the GNU Lesser General Public License version 2.1.
*/
package org.ow2.petals.binding.soap;
import static org.ow2.petals.binding.soap.SoapConstants.Axis2.AXIS2_XML;
import java.io.File;
import java.util.logging.Level;
import javax.jbi.JBIException;
import javax.naming.Context;
import javax.xml.namespace.QName;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.deployment.DeploymentConstants;
import org.apache.axis2.description.Parameter;
import org.apache.axis2.description.TransportInDescription;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.transport.jms.JMSConstants;
import org.ow2.petals.binding.soap.SoapConstants.JmsTransportLayer;
import org.ow2.petals.binding.soap.listener.incoming.SoapExternalServer;
import org.ow2.petals.binding.soap.monitoring.Monitoring;
import org.ow2.petals.component.framework.bc.AbstractBindingComponent;
import org.ow2.petals.component.framework.bc.BindingComponentServiceUnitManager;
import org.ow2.petals.probes.api.exceptions.MultipleProbesFactoriesFoundException;
import org.ow2.petals.probes.api.exceptions.NoProbesFactoryFoundException;
/**
* The SOAP binding component.
* @author Christophe Hamerling - EBM WebSourcing
*/
public class SoapComponent extends AbstractBindingComponent {
/**
* The listener processing SOAP request providing from external clients.
* Incoming SOAP requests.
*/
protected SoapExternalServer externalListenerManager;
/**
* The SOAP component context
*/
protected SoapComponentContext soapContext;
/**
* The monitoring MBean
*/
private Monitoring monitoringMbean;
/**
*
* Set up the JMS transport layer by adding a default connection factory.
*
*
* The default connection factory is defined into the components extensions.
* See component extensions for more information about the configuration of
* this deafult connection factory.
*
*
* If the component extensions does not include needed values, the JMS
* transport layer will be activated without default JMS connection factory.
*
*
* The JMS transport layer is defined as (following the syntax of
* axis2.xml), italic bold value are component extensions:
* <transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener">
* <parameter name="default" locked="false">
* <parameter name="java.naming.factory.initial" locked="false">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
* <parameter name="java.naming.provider.url" locked="false">tcp://localhost:61616</parameter>
* <parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">QueueConnectionFactory</parameter>
* </parameter>
* </transportReceiver>
*
*
* @param axisConfigurationContext
* @throws AxisFault
*/
private void setUpJMSTransporter() throws AxisFault {
final AxisConfiguration axisConfiguration = soapContext.getAxis2ConfigurationContext().getAxisConfiguration();
final TransportInDescription transportIn = axisConfiguration.getTransportIn(Constants.TRANSPORT_JMS);
final String jndiInitialFactory = getComponentExtensions().get(JmsTransportLayer.JNDI_INITIAL_FACTORY);
final String jndiProviderUrl = getComponentExtensions().get(JmsTransportLayer.JNDI_PROVIDER_URL);
final String confacJndiName = getComponentExtensions().get(JmsTransportLayer.CONFAC_JNDINAME);
if (jndiInitialFactory != null && jndiProviderUrl != null && confacJndiName != null
&& !jndiInitialFactory.isEmpty() && !jndiProviderUrl.isEmpty() && !confacJndiName.isEmpty()) {
soapContext.setJmsJndiInitialFactory(jndiInitialFactory);
soapContext.setJmsJndiProviderUrl(jndiProviderUrl);
soapContext.setJmsConnectionFactoryName(confacJndiName);
getLogger().info("Create the default JMS connection factory ('" + JMSConstants.DEFAULT_CONFAC_NAME + "'):");
getLogger().info("\t" + JmsTransportLayer.JNDI_INITIAL_FACTORY + ": " + jndiInitialFactory);
getLogger().info("\t" + JmsTransportLayer.JNDI_PROVIDER_URL + ": " + jndiProviderUrl);
getLogger().info("\t" + JmsTransportLayer.CONFAC_JNDINAME + ": " + confacJndiName);
final OMFactory omFactory = OMAbstractFactory.getOMFactory();
final OMElement initialContextFactory = omFactory.createOMElement(new QName(
DeploymentConstants.TAG_PARAMETER));
initialContextFactory.addAttribute(DeploymentConstants.ATTRIBUTE_NAME,
Context.INITIAL_CONTEXT_FACTORY, null);
initialContextFactory.setText(jndiInitialFactory);
final OMElement providerUrl = omFactory.createOMElement(new QName(
DeploymentConstants.TAG_PARAMETER));
providerUrl
.addAttribute(DeploymentConstants.ATTRIBUTE_NAME, Context.PROVIDER_URL, null);
providerUrl.setText(jndiProviderUrl);
final OMElement connectionFactoryName = omFactory.createOMElement(new QName(
DeploymentConstants.TAG_PARAMETER));
connectionFactoryName.addAttribute(DeploymentConstants.ATTRIBUTE_NAME,
JMSConstants.PARAM_CONFAC_JNDI_NAME, null);
connectionFactoryName.setText(confacJndiName);
final OMElement defaultJmsTransportElt = omFactory.createOMElement(
new QName(
DeploymentConstants.TAG_PARAMETER));
defaultJmsTransportElt.addChild(initialContextFactory);
defaultJmsTransportElt.addChild(providerUrl);
defaultJmsTransportElt.addChild(connectionFactoryName);
final Parameter defaultJmsTransport = new Parameter(JMSConstants.DEFAULT_CONFAC_NAME,
defaultJmsTransportElt);
defaultJmsTransport.setParameterElement(defaultJmsTransportElt);
transportIn.addParameter(defaultJmsTransport);
} else {
getLogger().info(
"The JMS transport layer configuration is not complete. It is disabled.");
// let's remove it, because if not it will be started with the rest of Axis (through doStart())
axisConfiguration.getTransportsIn().remove(Constants.TRANSPORT_JMS);
}
}
private void setUpHTTPTransporters() throws AxisFault {
final AxisConfiguration axisConfiguration = soapContext.getAxis2ConfigurationContext().getAxisConfiguration();
soapContext.getSoapServerConfig()
.initTransportListenerForAxis(axisConfiguration.getTransportIn(Constants.TRANSPORT_HTTP));
soapContext.getSoapServerConfig()
.initTransportListenerForAxis(axisConfiguration.getTransportIn(Constants.TRANSPORT_HTTPS));
}
@Override
protected BindingComponentServiceUnitManager createServiceUnitManager() {
return new SoapSUManager(this);
}
@Override
protected org.ow2.petals.component.framework.monitoring.Monitoring createMonitoringMBean()
throws MultipleProbesFactoriesFoundException, NoProbesFactoryFoundException {
this.monitoringMbean = new Monitoring(this.getProbesTimer(),
this.getResponseTimeProbeSamplePeriod());
return this.monitoringMbean;
}
@Override
protected void doInit() throws JBIException {
// the axis2.xml is required
final File axis2File = new File(getContext().getWorkspaceRoot(), AXIS2_XML);
if (!axis2File.exists()) {
throw new JBIException("Cannot get axis2 configuration file");
}
// get axis configuration context
getLogger().log(Level.FINE, "Creating Axis configuration context...");
final ConfigurationContext axisConfigurationContext;
try {
axisConfigurationContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(
getContext().getWorkspaceRoot(), axis2File.getAbsolutePath());
} catch (final AxisFault e) {
getLogger().log(Level.SEVERE, e.getMessage(), e);
throw new JBIException("Can not initialize SOAP BC", e);
}
// create the SOAP component context
this.soapContext = new SoapComponentContext(axisConfigurationContext, this,
this.getJbiComponentDescriptor().getComponent(), getComponentExtensions(), this.monitoringMbean,
this.getLogger());
try {
setUpJMSTransporter();
setUpHTTPTransporters();
// set SOAP HTTP Server
this.externalListenerManager = new SoapExternalServer(this.soapContext);
} catch (final AxisFault e) {
getLogger().log(Level.SEVERE, e.getMessage(), e);
throw new JBIException("Can not initialize SOAP BC", e);
}
getLogger().log(Level.FINE, "Axis configuration context set.");
// Set monitored objects
this.monitoringMbean.setHttpThreadPool(this.externalListenerManager.getHttpServer()
.getHttpServer().getThreadPool());
this.monitoringMbean.setWsClientPools(this.soapContext.getServiceClientPools());
}
@Override
public void doStart() throws JBIException {
try {
// Start the HTTP/HTTPS server
this.externalListenerManager.start();
// Note: actually, JMS will also be started (if it hasn't been removed in setUpJMSTransporte()...) because
// the external listener manager starts the AxisServlet which starts the ListenerManager which starts all
// the transporters!
} catch (final AxisFault e) {
this.getLogger().log(Level.SEVERE, e.getMessage(), e);
throw new JBIException(e);
}
}
@Override
public void doStop() throws JBIException {
try {
// Stop the HTTP/HTTPS server (as well as the JMS transporter, see doStart()).
this.externalListenerManager.stop();
} catch (final AxisFault e) {
this.getLogger().log(Level.SEVERE, e.getMessage(), e);
throw new JBIException(e);
}
}
@Override
protected void doShutdown() throws JBIException {
try {
if (this.externalListenerManager != null) {
this.externalListenerManager.shutdown();
}
} catch (final AxisFault e) {
throw new JBIException("Error stopping the soap engine", e);
}
}
public SoapExternalServer getExternalListenerManager() {
return this.externalListenerManager;
}
public SoapComponentContext getSoapContext() {
return this.soapContext;
}
public Monitoring getMonitoringMbean() {
return this.monitoringMbean;
}
}