001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2007 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id: SoapListener.java 9261 2007-09-25 17:05:45Z mpreston $
023: */
024: package com.bostechcorp.cbesb.runtime.component.http.server;
025:
026: import java.io.File;
027: import java.util.Iterator;
028:
029: import javax.wsdl.Definition;
030:
031: import org.apache.axis2.AxisFault;
032: import org.apache.axis2.Constants;
033: import org.apache.axis2.context.ConfigurationContext;
034: import org.apache.axis2.context.ConfigurationContextFactory;
035: import org.apache.axis2.description.AxisOperation;
036: import org.apache.axis2.description.AxisService;
037: import org.apache.axis2.description.WSDL11ToAxisServiceBuilder;
038: import org.apache.axis2.engine.AxisConfiguration;
039: import org.apache.commons.logging.Log;
040: import org.apache.commons.logging.LogFactory;
041: import org.mortbay.jetty.servlet.ServletHolder;
042:
043: import com.bostechcorp.cbesb.runtime.component.http.HttpEndpoint;
044:
045: public class SoapListener extends AbstractListener {
046:
047: protected final transient Log logger = LogFactory
048: .getLog(getClass());
049:
050: public SoapListener(HttpEndpoint endpoint) {
051: super (endpoint);
052: }
053:
054: protected void setServlets() {
055: ConfigurationContext axisConfigurationContext = null;
056: try {
057: axisConfigurationContext = ConfigurationContextFactory
058: .createBasicConfigurationContext("META-INF/Axis2.xml");
059: AxisConfiguration axisConfig = axisConfigurationContext
060: .getAxisConfiguration();
061: if (endpoint.isUsingMTOM()) {
062: axisConfigurationContext.setProperty(
063: Constants.Configuration.ENABLE_MTOM,
064: Constants.VALUE_TRUE);
065: axisConfigurationContext.setProperty(
066: Constants.Configuration.ENABLE_SWA,
067: Constants.VALUE_FALSE);
068: } else if (endpoint.isUsingSwA()) {
069: axisConfigurationContext.setProperty(
070: Constants.Configuration.ENABLE_MTOM,
071: Constants.VALUE_FALSE);
072: axisConfigurationContext.setProperty(
073: Constants.Configuration.ENABLE_SWA,
074: Constants.VALUE_TRUE);
075: } else {
076: axisConfigurationContext.setProperty(
077: Constants.Configuration.ENABLE_MTOM,
078: Constants.VALUE_FALSE);
079: axisConfigurationContext.setProperty(
080: Constants.Configuration.ENABLE_SWA,
081: Constants.VALUE_FALSE);
082: }
083:
084: logger.debug("Axis configuration context created.");
085: AxisService service = createServiceFromWsdl();
086: if (service != null) {
087: for (Iterator iter = service.getOperations(); iter
088: .hasNext();) {
089: AxisOperation operation = (AxisOperation) iter
090: .next();
091: if (operation.getMessageExchangePattern().equals(
092: "http://www.w3.org/ns/wsdl/in-out")) {
093: operation
094: .setMessageReceiver(new SoapInOutMessageReceiver(
095: endpoint));
096: } else {
097: operation
098: .setMessageReceiver(new SoapInOnlyMessageReceiver(
099: endpoint));
100: }
101: }
102: axisConfig.addService(service);
103: logger.debug("Axis service created: "
104: + service.getName());
105: }
106: } catch (AxisFault e) {
107: logger.error("AxisFault while creating AxisService", e);
108: } catch (Exception e) {
109: logger.error("Exception while creating AxisService", e);
110: }
111:
112: servlet = new SoapServlet(axisConfigurationContext);
113: context.addServlet(new ServletHolder(servlet), "/*");
114:
115: ListServicesServlet listServicesServlet = new ListServicesServlet(
116: axisConfigurationContext);
117: context.addServlet(new ServletHolder(listServicesServlet),
118: "/listServices");
119:
120: }
121:
122: protected AxisService createServiceFromWsdl() throws AxisFault {
123: AxisService service = null;
124: File wsdlFile = endpoint.getWsdlResourceAsFile();
125: logger.debug("Creating AxisService from WSDL: "
126: + wsdlFile.getAbsolutePath());
127:
128: Definition def = endpoint.getWsdlResourceAsDefinition();
129: WSDL11ToAxisServiceBuilder wsdlToAxisServiceBuilder = new WSDL11ToAxisServiceBuilder(
130: def, null, null);
131:
132: wsdlToAxisServiceBuilder.setAllPorts(false);
133: wsdlToAxisServiceBuilder.setCodegen(false);
134: wsdlToAxisServiceBuilder.setServerSide(true);
135: service = wsdlToAxisServiceBuilder.populateService();
136:
137: return service;
138:
139: }
140:
141: }
|