0001: /**
0002: * JOnAS: Java(TM) Open Application Server
0003: * Copyright (C) 1999-2005 Bull S.A.
0004: * Contact: jonas-team@objectweb.org
0005: *
0006: * This library is free software; you can redistribute it and/or
0007: * modify it under the terms of the GNU Lesser General Public
0008: * License as published by the Free Software Foundation; either
0009: * version 2.1 of the License, or any later version.
0010: *
0011: * This library is distributed in the hope that it will be useful,
0012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0014: * Lesser General Public License for more details.
0015: *
0016: * You should have received a copy of the GNU Lesser General Public
0017: * License along with this library; if not, write to the Free Software
0018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
0019: * USA
0020: *
0021: * --------------------------------------------------------------------------
0022: * $Id: AbsWebServicesServiceImpl.java 8170 2006-03-27 15:08:02Z sauthieg $
0023: * --------------------------------------------------------------------------
0024: */package org.objectweb.jonas.ws;
0025:
0026: import java.io.File;
0027: import java.io.IOException;
0028: import java.io.UnsupportedEncodingException;
0029: import java.net.MalformedURLException;
0030: import java.net.URL;
0031: import java.net.URLClassLoader;
0032: import java.net.URLEncoder;
0033: import java.util.ArrayList;
0034: import java.util.HashMap;
0035: import java.util.Iterator;
0036: import java.util.List;
0037: import java.util.Map;
0038: import java.util.Stack;
0039: import java.util.StringTokenizer;
0040:
0041: import javax.management.MBeanServer;
0042: import javax.management.MalformedObjectNameException;
0043: import javax.management.ObjectName;
0044: import javax.naming.Context;
0045: import javax.naming.InitialContext;
0046: import javax.naming.NamingException;
0047: import javax.naming.Reference;
0048: import javax.naming.StringRefAddr;
0049: import javax.xml.namespace.QName;
0050:
0051: import org.objectweb.jonas_lib.I18n;
0052: import org.objectweb.jonas_lib.deployment.api.HandlerDesc;
0053: import org.objectweb.jonas_lib.loader.WebappClassLoader;
0054: import org.objectweb.jonas_lib.naming.ContainerNaming;
0055: import org.objectweb.jonas_lib.naming.factory.URLFactory;
0056:
0057: import org.objectweb.jonas_web.deployment.api.WebContainerDeploymentDesc;
0058: import org.objectweb.jonas_web.deployment.api.WebContainerDeploymentDescException;
0059: import org.objectweb.jonas_web.deployment.lib.wrapper.WebManagerWrapper;
0060:
0061: import org.objectweb.jonas_ws.deployment.api.JaxRpcPortComponentDesc;
0062: import org.objectweb.jonas_ws.deployment.api.PortComponentDesc;
0063: import org.objectweb.jonas_ws.deployment.api.SSBPortComponentDesc;
0064: import org.objectweb.jonas_ws.deployment.api.ServiceDesc;
0065: import org.objectweb.jonas_ws.deployment.api.WSDLFile;
0066: import org.objectweb.jonas_ws.deployment.api.WSDeploymentDesc;
0067: import org.objectweb.jonas_ws.deployment.api.WSDeploymentDescException;
0068: import org.objectweb.jonas_ws.deployment.lib.wrapper.WSManagerWrapper;
0069:
0070: import org.objectweb.jonas.common.JProp;
0071: import org.objectweb.jonas.common.Log;
0072: import org.objectweb.jonas.ear.EarServiceImpl;
0073: import org.objectweb.jonas.jmx.J2eeObjectName;
0074: import org.objectweb.jonas.jmx.JmxService;
0075: import org.objectweb.jonas.naming.CompNamingContext;
0076: import org.objectweb.jonas.naming.NamingManager;
0077: import org.objectweb.jonas.service.AbsServiceImpl;
0078: import org.objectweb.jonas.service.ServiceException;
0079: import org.objectweb.jonas.service.ServiceManager;
0080: import org.objectweb.jonas.web.JWebContainerService;
0081: import org.objectweb.jonas.web.JWebContainerServiceException;
0082: import org.objectweb.jonas.ws.handler.WSDLHandler;
0083: import org.objectweb.jonas.ws.handler.WSDLHandlerFactory;
0084: import org.objectweb.jonas.ws.mbean.Handler;
0085: import org.objectweb.jonas.ws.mbean.PortComponent;
0086: import org.objectweb.jonas.ws.mbean.Service;
0087: import org.objectweb.jonas.ws.mbean.WebServicesObjectName;
0088:
0089: import org.objectweb.util.monolog.api.BasicLevel;
0090: import org.objectweb.util.monolog.api.Logger;
0091:
0092: /**
0093: * implements deployment process and declares commons abstract methods for all
0094: * (used) Web services engine. Actually we consider Glue and AXIS.
0095: * @author Guillaume Sauthier
0096: * @author Xavier Delplanque
0097: */
0098: public abstract class AbsWebServicesServiceImpl extends AbsServiceImpl
0099: implements WebServicesService, AbsWebServicesServiceImplMBean {
0100:
0101: /**
0102: * WebServices service configuration properties : Xml parsing with
0103: * validation
0104: */
0105: public static final String PARSINGWITHVALIDATION = "jonas.service.ws.parsingwithvalidation";
0106:
0107: /** WebServices service configuration properties : WSDL handlers */
0108: public static final String WSDL_HANDLERS = "jonas.service.ws.wsdlhandlers";
0109:
0110: /**
0111: * WebServices service configuration properties : base for web services
0112: * properties.
0113: */
0114: public static final String WS_BASE = "jonas.service.ws.";
0115:
0116: /** Logger for this service. */
0117: private static Logger logger = null;
0118:
0119: /** Internationalization tool */
0120: private static I18n i18n = I18n
0121: .getInstance(AbsWebServicesServiceImpl.class);
0122:
0123: /** Manager for WSDL files publishing. */
0124: private WSDLManager wsdlManager = null;
0125:
0126: /** Reference to the web container service */
0127: private JWebContainerService webService = null;
0128:
0129: /** JMX Server */
0130: private MBeanServer mbeanServer = null;
0131:
0132: /**
0133: * Map of deployments descriptor (ClassLoader -> Stack)
0134: */
0135: private Map deployments = null;
0136:
0137: /**
0138: * Map of warURL -> WebServices
0139: */
0140: private Map webservicesMBeans = null;
0141:
0142: /**
0143: * endpoint URL prefix to be used for ws endpoint
0144: */
0145: private String endpointURLPrefix = null;
0146:
0147: /**
0148: * Initialize the service.
0149: * @param ctx the configuration context of the service.
0150: * @throws ServiceException if the initialization failed.
0151: */
0152: protected void doInit(Context ctx) throws ServiceException {
0153: // Init the logger
0154: logger = Log.getLogger(Log.JONAS_WS_PREFIX);
0155:
0156: ServiceManager serviceManager = null;
0157: try {
0158: serviceManager = ServiceManager.getInstance();
0159: } catch (Exception e) {
0160: throw new ServiceException(
0161: "Cannot initialize the WebServices Service", e);
0162: }
0163:
0164: // Init variables
0165: deployments = new HashMap();
0166: webservicesMBeans = new HashMap();
0167:
0168: try {
0169: endpointURLPrefix = (String) ctx.lookup(WS_BASE
0170: + "url-prefix");
0171: } catch (NamingException ne) {
0172: endpointURLPrefix = null;
0173: }
0174:
0175: // Set the XML parsing mode to no validation
0176: String parsingMode = "false";
0177:
0178: try {
0179: parsingMode = (String) ctx.lookup(PARSINGWITHVALIDATION);
0180: } catch (NamingException e) {
0181: // No problem if there is no value for 'parsingwithvalidation'
0182: // (false by default)
0183: parsingMode = "false";
0184: }
0185:
0186: WSManagerWrapper.setParsingWithValidation("true"
0187: .equalsIgnoreCase(parsingMode));
0188:
0189: if ("false".equalsIgnoreCase(parsingMode)) {
0190: logger.log(BasicLevel.DEBUG,
0191: "WebServices XML parsing without validation");
0192: } else {
0193: logger.log(BasicLevel.DEBUG,
0194: "WebServices XML parsing with validation");
0195: }
0196:
0197: try {
0198: // Get the JMX Server via JMX Service
0199: JmxService jmxService = (JmxService) serviceManager
0200: .getJmxService();
0201: mbeanServer = jmxService.getJmxServer();
0202: } catch (ServiceException e) {
0203: // the JMX service may not be started
0204: mbeanServer = null;
0205: }
0206:
0207: // Init the wsdl Manager
0208: wsdlManager = new WSDLManager();
0209:
0210: // Get publishing parameters in jonas properties
0211: JProp jp = null;
0212:
0213: try {
0214: jp = JProp.getInstance();
0215: } catch (Exception e) {
0216: String err = i18n
0217: .getMessage("AbsWebServicesServiceImpl.doInit.noJProp");
0218: logger.log(BasicLevel.ERROR, err + " " + e.getMessage());
0219: throw new WSServiceException(err, e);
0220: }
0221:
0222: String[] handlers = jp.getValueAsArray(WSDL_HANDLERS);
0223:
0224: if (handlers == null) {
0225: String err = i18n.getMessage(
0226: "AbsWebServicesServiceImpl.doInit.noHandlers",
0227: WSDL_HANDLERS);
0228: logger.log(BasicLevel.ERROR, err);
0229: throw new WSServiceException(err);
0230: }
0231:
0232: // Build WSDLHandlers
0233:
0234: WSDLHandlerFactory factory = WSDLHandlerFactory.newInstance();
0235:
0236: // build each specified handlers and add it in the WSDLManager.
0237: for (int i = 0; i < handlers.length; i++) {
0238:
0239: // Create the handler
0240: WSDLHandler handler = factory.newHandler(handlers[i]);
0241:
0242: if (logger.isLoggable(BasicLevel.DEBUG)) {
0243: logger.log(BasicLevel.DEBUG, "Adding WSDLHandler '"
0244: + handlers[i] + "'");
0245: }
0246:
0247: // Add the created Handler
0248: wsdlManager.addHandler(handler);
0249: }
0250: }
0251:
0252: /**
0253: * Get, update and publish WSDL documents contained in a set of jars and
0254: * wars.
0255: * @param ctx the context containing the configuration to deploy the wars.
0256: * <BR>This context contains the following parameters :<BR>-
0257: * jarUrls the list of the urls of the jars to deploy. <BR>- warUrls
0258: * the list of the urls of the wars to deploy. <BR>- ejbClassLoader
0259: * the classLoader of the ejbs(used for webapps too). <BR>-
0260: * earClassLoader the ear classLoader of the j2ee app. <BR>-
0261: * warCtxRootMapping the webapps contextRoots with associated war
0262: * name. <BR>- unpackDir the directory where EAR has been unpacked
0263: * (optionnal for pure webapp webservices).
0264: * @throws WSServiceException if an error occurs during the deployment.
0265: */
0266: public void deployWebServices(Context ctx)
0267: throws WSServiceException {
0268: /**
0269: * For each Jar/WarUrls in the given ctx : - Get the jar/war deployment
0270: * desc - Get the WSDL definition - Update the WSDL location - Publish
0271: * the WSDL
0272: */
0273:
0274: // Cannot get webContainer at startup (cycles)
0275: if (webService == null) {
0276: try {
0277: webService = (JWebContainerService) ServiceManager
0278: .getInstance().getWebContainerService();
0279: } catch (Exception e) {
0280: String err = i18n
0281: .getMessage("AbsWebServicesServiceImpl.deployWebServices.noWeb");
0282: logger.log(BasicLevel.ERROR, err);
0283: throw new WSServiceException(err, e);
0284: }
0285: }
0286:
0287: // Get context parameters.
0288: URL[] jarUrls = null;
0289: URL[] warUrls = null;
0290: URL earURL = null;
0291: ClassLoader ejbClassLoader = null;
0292: ClassLoader earClassLoader = null;
0293: Map warCtxRootMapping = null;
0294: String unpackDir = null;
0295:
0296: // EAR & Webapp case common information
0297: try {
0298: jarUrls = (URL[]) ctx.lookup("jarUrls");
0299: warUrls = (URL[]) ctx.lookup("warUrls");
0300: unpackDir = (String) ctx.lookup("unpackDir");
0301: } catch (NamingException e) {
0302: String err = i18n
0303: .getMessage("AbsWebServicesServiceImpl.deployWebServices.ctxParamProblem");
0304: logger.log(BasicLevel.ERROR, err + e.getMessage());
0305: throw new WSServiceException(err, e);
0306: }
0307:
0308: // EAR case specific information
0309: try {
0310: earURL = (URL) ctx.lookup("earURL");
0311: earClassLoader = (ClassLoader) ctx.lookup("earClassLoader");
0312: warCtxRootMapping = (Map) ctx.lookup("warCtxRootMapping");
0313: ejbClassLoader = (ClassLoader) ctx.lookup("ejbClassLoader");
0314: } catch (NamingException ne) {
0315: // WebApp case
0316: earURL = null;
0317: earClassLoader = null;
0318: warCtxRootMapping = null;
0319: ejbClassLoader = null;
0320: }
0321:
0322: // Deploy wars Web services.
0323: URLClassLoader loaderForCls = null;
0324: String earAppName = null;
0325: if (earURL != null) {
0326: earAppName = EarServiceImpl
0327: .buildJ2eeApplicationName(earURL);
0328: }
0329:
0330: String fileName = null;
0331: WSDeploymentDesc wsDD = null;
0332:
0333: for (int i = 0; i < warUrls.length; i++) {
0334: // Get the name of a war to deploy.
0335: fileName = warUrls[i].getFile();
0336: logger.log(BasicLevel.DEBUG, "Analyzing war '" + fileName
0337: + "' for web services");
0338:
0339: // Get the class loader for the current war.
0340: loaderForCls = webService.getClassLoader(warUrls[i],
0341: earAppName, ejbClassLoader);
0342:
0343: WebappClassLoader webLoader = (WebappClassLoader) loaderForCls;
0344: URL url = webLoader.getBaseURL();
0345:
0346: // Get the deployment descriptor from file.
0347: try {
0348: wsDD = WSManagerWrapper.getDeploymentDesc(warUrls[i],
0349: url, loaderForCls, earClassLoader);
0350: } catch (WSDeploymentDescException wsdde) {
0351: String err = i18n
0352: .getMessage(
0353: "AbsWebServicesServiceImpl.deployWebServices.wsddEx",
0354: fileName);
0355: logger.log(BasicLevel.ERROR, err + ": " + wsdde);
0356: throw new WSServiceException(err, wsdde);
0357: }
0358:
0359: if (wsDD != null) {
0360: // The current War contains Webservices
0361: try {
0362: Context compCtx = new CompNamingContext(fileName);
0363: compCtx.rebind("wsDD", wsDD);
0364: compCtx.rebind("cl", loaderForCls);
0365:
0366: if (earClassLoader != null) {
0367: compCtx.rebind("earCL", earClassLoader);
0368: }
0369: compCtx.rebind("warURL", warUrls[i]);
0370:
0371: // ear case
0372: if (warCtxRootMapping != null) {
0373: compCtx.rebind("warContextRoot",
0374: warCtxRootMapping.get(warUrls[i]));
0375:
0376: // non-ear case
0377: } else {
0378: compCtx.rebind("warContextRoot", "");
0379: }
0380:
0381: doDeployWebServices(compCtx);
0382: } catch (NamingException ne) {
0383: String err = i18n
0384: .getMessage(
0385: "AbsWebServicesServiceImpl.deployWebServices.bindError",
0386: fileName);
0387: logger.log(BasicLevel.ERROR, err);
0388: throw new WSServiceException(err, ne);
0389: }
0390: }
0391: }
0392: // End deploy wars Web services.
0393:
0394: // Deploy jars Web services.
0395: // Check warCtxRootMapping presence
0396: if ((jarUrls.length != 0) && (warCtxRootMapping == null)) {
0397: String err = i18n
0398: .getMessage("AbsWebServicesServiceImpl.deployWebServices.ctxRootMappingMissing");
0399: logger.log(BasicLevel.ERROR, err);
0400: throw new WSServiceException(err);
0401: }
0402:
0403: for (int i = 0; i < jarUrls.length; i++) {
0404: // Get the name of a war to deploy.
0405: fileName = jarUrls[i].getFile();
0406: logger.log(BasicLevel.DEBUG, "Analyzing EjbJar '"
0407: + fileName + "' for web services");
0408:
0409: URLClassLoader webClassLoader = null;
0410:
0411: // Get the deployment descriptor from file.
0412: try {
0413: wsDD = WSManagerWrapper.getDeploymentDesc(jarUrls[i],
0414: ejbClassLoader, earClassLoader);
0415: } catch (WSDeploymentDescException wsdde) {
0416: String err = i18n
0417: .getMessage(
0418: "AbsWebServicesServiceImpl.deployWebServices.wsddEx",
0419: fileName);
0420: logger.log(BasicLevel.ERROR, err + ": " + wsdde);
0421: throw new WSServiceException(err, wsdde);
0422: }
0423:
0424: if (wsDD != null) {
0425: // The current Jar contains Webservices
0426: URL warURL = null;
0427:
0428: try {
0429: /**
0430: * Default Naming Convention for Webapp linked to Ejb
0431: * <ejb-name>.jar -> <ejb-name>.war
0432: */
0433: if (wsDD.getWarFile() != null) {
0434: // use getCanonicalFile to fix Bug #300658
0435: //new File(new URL(dirName + File.separator + s).getFile()).getCanonicalFile().toURL();
0436: warURL = new File(new URL(unpackDir
0437: + File.separator + wsDD.getWarFile())
0438: .getFile()).getCanonicalFile().toURL();
0439: //warURL = new URL(unpackDir + "/" + wsDD.getWarFile());
0440: } else {
0441: String ejb = new File(jarUrls[i].getFile())
0442: .getName();
0443: String war = ejb.substring(0, ejb.length()
0444: - ".jar".length());
0445: //warURL = new URL(unpackDir + "/" + war + ".war");
0446: warURL = new File(new URL(unpackDir
0447: + File.separator + war + ".war")
0448: .getFile()).getCanonicalFile().toURL();
0449: }
0450: logger.log(BasicLevel.DEBUG, "Unpack Dir : "
0451: + unpackDir);
0452: logger.log(BasicLevel.DEBUG, "Computed URL : "
0453: + warURL);
0454:
0455: // check if webapp is present
0456: boolean present = false;
0457:
0458: for (int w = 0; w < warUrls.length; w++) {
0459: if (warUrls[w].equals(warURL)) {
0460: present = true;
0461: }
0462: logger.log(BasicLevel.DEBUG, "warUrls[" + w
0463: + "]=" + warUrls[w]);
0464: }
0465:
0466: // get the linked web classloader
0467: webClassLoader = webService.getClassLoader(warURL,
0468: earAppName, ejbClassLoader);
0469:
0470: if (!present) {
0471: String err = i18n
0472: .getMessage(
0473: "AbsWebServicesServiceImpl.deployWebServices.webappNotFound",
0474: warURL);
0475: logger.log(BasicLevel.ERROR, err);
0476: throw new WSServiceException(err);
0477: }
0478: } catch (MalformedURLException mue) {
0479: String err = i18n
0480: .getMessage("AbsWebServicesServiceImpl.deployWebServices.mue");
0481: logger.log(BasicLevel.ERROR, mue.getMessage());
0482: throw new WSServiceException(err, mue);
0483: } catch (IOException ioe) {
0484: // TODO add i18n
0485: String err = "Cannot locate file : "
0486: + ioe.getMessage();
0487: logger.log(BasicLevel.ERROR, err);
0488: throw new WSServiceException(err, ioe);
0489: }
0490:
0491: try {
0492: Context compCtx = new CompNamingContext(fileName);
0493: compCtx.rebind("wsDD", wsDD);
0494:
0495: // Using WebClassLoader ()
0496: compCtx.rebind("cl", webClassLoader);
0497: compCtx.rebind("earCL", earClassLoader);
0498:
0499: compCtx.rebind("warURL", warURL);
0500:
0501: // warContextRoot cannot be null in ejb case
0502: // because an ejb needs a webapp for webservices
0503: compCtx.rebind("warContextRoot", warCtxRootMapping
0504: .get(warURL));
0505: doDeployWebServices(compCtx);
0506: } catch (NamingException ne) {
0507: String err = i18n
0508: .getMessage(
0509: "AbsWebServicesServiceImpl.deployWebServices.bindError",
0510: fileName);
0511: logger.log(BasicLevel.ERROR, err);
0512: throw new WSServiceException(err, ne);
0513: }
0514: }
0515: }
0516:
0517: // End deploy jars Web services.
0518: }
0519:
0520: /**
0521: * Deploy the given Web services.
0522: * @param ctx Context used for parameter passing.
0523: * @throws WSServiceException when error occurs.
0524: */
0525: protected void doDeployWebServices(Context ctx)
0526: throws WSServiceException {
0527: /**
0528: * Context structure : - wsDD Web Services deployment descriptor. - cl
0529: * Module ClassLoader - earCL Application ClassLoader - warContextRoot
0530: * the context-root of the war (null in ejb case) - warURL the url of
0531: * war dispatching SOAP requests
0532: */
0533: WSDeploymentDesc wsDD = null;
0534: ClassLoader cl = null;
0535: ClassLoader earCL = null;
0536: String warContextRoot = null;
0537: URL warURL = null;
0538:
0539: try {
0540: wsDD = (WSDeploymentDesc) ctx.lookup("wsDD");
0541: cl = (ClassLoader) ctx.lookup("cl");
0542: warContextRoot = (String) ctx.lookup("warContextRoot");
0543: warURL = (URL) ctx.lookup("warURL");
0544: } catch (NamingException ne) {
0545: String err = i18n
0546: .getMessage("AbsWebServicesServiceImpl.doDeployWebServices.namingError");
0547: logger.log(BasicLevel.ERROR, err);
0548: throw new WSServiceException(err, ne);
0549: }
0550:
0551: if (logger.isLoggable(BasicLevel.DEBUG)) {
0552: logger.log(BasicLevel.DEBUG, "Deploying WebServices for '"
0553: + warURL + "'");
0554: }
0555:
0556: try {
0557: earCL = (ClassLoader) ctx.lookup("earCL");
0558: } catch (NamingException ne) {
0559: // Nothing to do : non EAR case
0560: earCL = null;
0561: }
0562:
0563: // store WSDeployInfo for later use (completeWSDeployment method)
0564: ClassLoader key = cl;
0565: if (earCL != null) {
0566: key = earCL;
0567: }
0568: Stack s = (Stack) deployments.get(key);
0569: if (s == null) {
0570: s = new Stack();
0571: deployments.put(key, s);
0572: }
0573: s.push(new WSDeployInfo(warURL, wsDD));
0574:
0575: List sds = wsDD.getServiceDescs();
0576:
0577: // for each WSDL contained in the component
0578: for (Iterator i = sds.iterator(); i.hasNext();) {
0579: ServiceDesc sd = (ServiceDesc) i.next();
0580: WSDLFile wsdl = sd.getWSDL();
0581:
0582: // get the endpoint URL for each port-component
0583: // update the WSDL Definition
0584: for (Iterator pc = sd.getPortComponents().iterator(); pc
0585: .hasNext();) {
0586: PortComponentDesc pcd = (PortComponentDesc) pc.next();
0587: QName portQName = pcd.getQName();
0588: URL endpoint = null;
0589: if (pcd.hasJaxRpcImpl()) {
0590: endpoint = getEndpointURL(wsDD,
0591: (JaxRpcPortComponentDesc) pcd, warURL,
0592: warContextRoot);
0593: } else {
0594: endpoint = getEndpointURL(wsDD,
0595: (SSBPortComponentDesc) pcd, warURL, cl,
0596: earCL, warContextRoot);
0597: }
0598:
0599: pcd.setEndpointURL(endpoint);
0600: wsdl.setLocation(portQName, endpoint);
0601:
0602: // add endpoint URL into JNDI namespace to allow application
0603: // clients (that are not running in the same JVM) to use
0604: // port-component-link
0605: Context registry;
0606: try {
0607: registry = new InitialContext();
0608: Reference urlRef = new Reference(URL.class
0609: .getName(), URLFactory.class.getName(),
0610: null);
0611: urlRef.add(new StringRefAddr("url", endpoint
0612: .toString()));
0613: registry.rebind(pcd.getName(), urlRef);
0614: logger.log(BasicLevel.DEBUG, "Bind updated URL ("
0615: + endpoint + ") in " + pcd.getName());
0616: } catch (NamingException ne) {
0617: throw new WSServiceException(
0618: "Cannot bind updated URL for port-component '"
0619: + pcd.getName() + "'", ne);
0620: }
0621:
0622: }
0623:
0624: // publish WSDL
0625: wsdlManager.publish(sd);
0626: }
0627: }
0628:
0629: /**
0630: * Creates and adds all nested Handlers in the parent PortComponent.
0631: * @param pcMBean parent PortComponent MBean
0632: * @param pcd PortComponent Descriptor
0633: */
0634: private void addHandlerMBeansToPortComponent(PortComponent pcMBean,
0635: PortComponentDesc pcd) {
0636:
0637: // iterates over the HandlerDesc list
0638: for (Iterator i = pcd.getHandlers().iterator(); i.hasNext();) {
0639: HandlerDesc hd = (HandlerDesc) i.next();
0640:
0641: // creates the Handler MBean, and automatically
0642: // add it to the PortComponent
0643: Handler hMBean = createHandlerMBean(hd.getName(), pcMBean);
0644:
0645: hMBean.setClassname(hd.getHandlerClassName());
0646: hMBean.setName(hd.getName());
0647: // soap-headers
0648: List sh = hd.getSOAPHeaders();
0649: // transform QName to String
0650: String[] headers = new String[sh.size()];
0651: int index = 0;
0652: for (Iterator j = sh.iterator(); j.hasNext();) {
0653: // Stringify the QName
0654: headers[index++] = ((QName) j.next()).toString();
0655: }
0656: hMBean.setSoapHeaders(headers);
0657: // soap-roles
0658: List sr = hd.getSOAPRoles();
0659: hMBean.setSoapRoles((String[]) sr.toArray(new String[sr
0660: .size()]));
0661:
0662: hMBean.setInitParams(hd.getInitParams());
0663:
0664: }
0665:
0666: }
0667:
0668: /**
0669: * @param name Handler name
0670: * @param parent parent PortComponent
0671: * @return Returns the creates Handler MBean
0672: */
0673: private static Handler createHandlerMBean(String name,
0674: PortComponent parent) {
0675: Handler h = null;
0676: try {
0677: h = new Handler(WebServicesObjectName.handler(name,
0678: parent.getRealObjectName()).toString());
0679: } catch (MalformedObjectNameException e) {
0680: // should never happen
0681: logger.log(BasicLevel.DEBUG, "Should never happen", e);
0682: }
0683: // add to the parent
0684: parent.addHandlerMBean(h);
0685: return h;
0686: }
0687:
0688: /**
0689: * @param name PortComponent name
0690: * @param parent parent Service
0691: * @return Returns the created PortComponent MBean
0692: */
0693: private static PortComponent createPortComponentMBean(String name,
0694: Service parent) {
0695: PortComponent pc = null;
0696: try {
0697: pc = new PortComponent(WebServicesObjectName.portComponent(
0698: name, parent.getRealObjectName()).toString());
0699: } catch (MalformedObjectNameException e) {
0700: // should never happen
0701: logger.log(BasicLevel.DEBUG, "Should never happen", e);
0702: }
0703: return pc;
0704: }
0705:
0706: /**
0707: * @param name Service name
0708: * @param parent parent WebServices
0709: * @return Returns the created Service MBean
0710: */
0711: private static Service createServiceMBean(String name,
0712: ObjectName parent) {
0713: Service service = null;
0714: try {
0715: service = new Service(WebServicesObjectName.service(name,
0716: parent).toString());
0717: } catch (MalformedObjectNameException e) {
0718: // should never happen
0719: logger.log(BasicLevel.DEBUG, "Should never happen", e);
0720: }
0721: return service;
0722: }
0723:
0724: /**
0725: * Creates the endpointURL of a given PortComponentDesc.
0726: * @param wsDD webservices.xml
0727: * @param jpcd JaxRpcPortComponentDesc to analyze
0728: * @param warURL URL of the war file containing the PortComponent
0729: * @param contextRoot context-root of the webapp
0730: * @return the endpointURL of a given PortComponentDesc.
0731: * @throws WSServiceException When URL cannot be constructed.
0732: */
0733: private URL getEndpointURL(WSDeploymentDesc wsDD,
0734: JaxRpcPortComponentDesc jpcd, URL warURL, String contextRoot)
0735: throws WSServiceException {
0736:
0737: logger.log(BasicLevel.DEBUG,
0738: "get endpoint for JaxRpc Port Component");
0739:
0740: return getEndpointURL(wsDD, jpcd.getWebDesc(), warURL,
0741: contextRoot, jpcd);
0742:
0743: }
0744:
0745: /**
0746: * Creates the endpointURL of a given PortComponentDesc.
0747: * @param wsDD webservices.xml
0748: * @param spcd SSBPortComponentDesc to analyze
0749: * @param warURL URL of the wabapp used to expose the Bean
0750: * @param cl ejbjar classloader
0751: * @param earCL application classloader
0752: * @param contextRoot webapp context name
0753: * @return the endpointURL of a given PortComponentDesc.
0754: * @throws WSServiceException When URL cannot be created
0755: */
0756: private URL getEndpointURL(WSDeploymentDesc wsDD,
0757: SSBPortComponentDesc spcd, URL warURL, ClassLoader cl,
0758: ClassLoader earCL, String contextRoot)
0759: throws WSServiceException {
0760:
0761: logger.log(BasicLevel.DEBUG,
0762: "get endpoint for StatelessSessionBean Port Component");
0763:
0764: WebContainerDeploymentDesc webDD = null;
0765:
0766: try {
0767: webDD = WebManagerWrapper.getDeploymentDesc(warURL, cl,
0768: earCL);
0769: } catch (WebContainerDeploymentDescException e) {
0770: String err = i18n
0771: .getMessage(
0772: "AbsWebServicesServiceImpl.getEndpointURL.webDDException",
0773: warURL.getFile());
0774: logger.log(BasicLevel.ERROR, err);
0775: throw new WSServiceException(err, e);
0776: }
0777:
0778: return getEndpointURL(wsDD, webDD, warURL, contextRoot, spcd);
0779:
0780: }
0781:
0782: /**
0783: * Returns the URL used to access the endpoint.
0784: * @param wsDD webservices.xml
0785: * @param webDD the WebContainer DD of the servlet
0786: * @param warURL the url of the war containing the servlet dispatching the
0787: * SOAP request to the servant.
0788: * @param warContextRoot the application defined context-root for the webapp
0789: * (can be null).
0790: * @param pcd PortComponentDesc Port descriptor
0791: * @return the URL used to access the endpoint.
0792: * @throws WSServiceException When cannot create the endpoint URL.
0793: */
0794: private URL getEndpointURL(WSDeploymentDesc wsDD,
0795: WebContainerDeploymentDesc webDD, URL warURL,
0796: String warContextRoot, PortComponentDesc pcd)
0797: throws WSServiceException {
0798:
0799: // Resolve :
0800: // - hostname
0801: // - http/https port
0802: // Priority order : 1. the ones specified in jonas-web.xml
0803: // 2. default web container values (if any)
0804: String servletName = pcd.getSibLink();
0805: String pcName = pcd.getQName().getLocalPart();
0806:
0807: logger.log(BasicLevel.DEBUG, "SOAP Servlet name '"
0808: + servletName + "'");
0809:
0810: String hostname = webDD.getHost();
0811: String port = webDD.getPort();
0812: String scheme = "http"; // default scheme
0813: String contextRoot = null;
0814: String mapping = null;
0815:
0816: if (wsDD.getContextRoot() != null
0817: && (pcd instanceof SSBPortComponentDesc)) {
0818: contextRoot = wsDD.getContextRoot();
0819: } else {
0820: contextRoot = getContextRoot(warContextRoot, webDD, warURL);
0821: }
0822:
0823: boolean needPortName = true;
0824: if (pcd.getEndpointURI() != null) {
0825: mapping = pcd.getEndpointURI();
0826: needPortName = false;
0827: } else {
0828: mapping = getServletMapping(servletName, webDD);
0829: }
0830:
0831: String prefix = endpointURLPrefix;
0832:
0833: // if the instance does not have a specified url-prefix
0834: // we ask the server "environment" for hostname, port, ...
0835: if (endpointURLPrefix == null) {
0836: // get default host value
0837: if (hostname == null) {
0838: // get hostname
0839: try {
0840: hostname = webService.getDefaultHost();
0841: } catch (JWebContainerServiceException e) {
0842: String err = i18n
0843: .getMessage(
0844: "AbsWebServicesServiceImpl.getEndpointURL.noDefaultHost",
0845: warURL.getFile());
0846: logger.log(BasicLevel.ERROR, err);
0847: throw new WSServiceException(err, e);
0848: }
0849: }
0850:
0851: // get default port and scheme value
0852: if (port == null) {
0853: // get Http informations
0854: try {
0855: port = webService.getDefaultHttpPort();
0856: scheme = "http";
0857: } catch (JWebContainerServiceException e) {
0858: // Http Fails
0859: // Try Https informations
0860: try {
0861: port = webService.getDefaultHttpsPort();
0862: scheme = "https";
0863: } catch (JWebContainerServiceException e2) {
0864: String err = i18n
0865: .getMessage(
0866: "AbsWebServicesServiceImpl.getEndpointURL.noDefaultHTTPPort",
0867: warURL.getFile());
0868: logger.log(BasicLevel.ERROR, err);
0869: throw new WSServiceException(err, e2);
0870: }
0871: }
0872: }
0873:
0874: // construct URL
0875: if (port.equals("80")) {
0876: port = "";
0877: } else {
0878: port = ":" + port;
0879: }
0880:
0881: prefix = scheme + "://" + hostname + port;
0882: }
0883:
0884: String url = null;
0885: if (needPortName) {
0886: String encodedPortName = null;
0887: try {
0888: encodedPortName = URLEncoder.encode(pcName, "UTF-8");
0889: } catch (UnsupportedEncodingException e) {
0890: // should never occurs since utf-8 is mandatory on all JVM
0891: encodedPortName = pcName;
0892: }
0893: url = prefix + "/" + contextRoot + "/" + mapping + "/"
0894: + encodedPortName;
0895: } else {
0896: url = prefix + "/" + contextRoot + mapping;
0897: }
0898:
0899: URL endpoint = null;
0900:
0901: try {
0902: endpoint = new URL(url);
0903: } catch (MalformedURLException mue) {
0904: String err = i18n
0905: .getMessage(
0906: "AbsWebServicesServiceImpl.getEndpointURL.endpointURLError",
0907: pcName, url);
0908: logger.log(BasicLevel.ERROR, err);
0909: throw new WSServiceException(err, mue);
0910: }
0911:
0912: if (logger.isLoggable(BasicLevel.DEBUG)) {
0913: logger.log(BasicLevel.DEBUG, "Constructed URL for '"
0914: + pcName + "' : '" + endpoint + "'");
0915: }
0916:
0917: return endpoint;
0918: }
0919:
0920: /**
0921: * Returns the contextRoot used for webapp access.
0922: * @param ctxRoot The application specified context-root ("" if not).
0923: * @param webDD The web DeploymentDesc of the dispatching webapp.
0924: * @param warURL url of the webapp file.
0925: * @return The contextRoot used for webapp access.
0926: */
0927: private static String getContextRoot(String ctxRoot,
0928: WebContainerDeploymentDesc webDD, URL warURL) {
0929: // Set the right context root for the web application, the priority is
0930: // the following :
0931: // 1 - context-root of application.xml
0932: // 2 - context-root of jonas-web.xml
0933: // 3 - context-root is the name of the file without .war.
0934: String contextRoot = null;
0935:
0936: if ("".equals(ctxRoot)) {
0937: String cRoot = webDD.getContextRoot();
0938:
0939: if (cRoot == null) {
0940: String file = new File(warURL.getFile()).getName();
0941:
0942: if (file.toLowerCase().endsWith(".war")) {
0943: contextRoot = file.substring(0, file.length()
0944: - ".war".length());
0945: } else {
0946: //It's a directory which is deployed
0947: contextRoot = file.substring(0, file.length());
0948: }
0949: } else {
0950: contextRoot = cRoot;
0951: }
0952: } else {
0953: contextRoot = ctxRoot;
0954: }
0955:
0956: return contextRoot;
0957: }
0958:
0959: /**
0960: * Empty Method for WebServices (no running application).
0961: * @throws ServiceException never thrown
0962: */
0963: public void doStop() throws ServiceException {
0964: }
0965:
0966: /**
0967: * Empty Method for WebServices (no running application).
0968: * @throws ServiceException never thrown
0969: */
0970: public void doStart() throws ServiceException {
0971: }
0972:
0973: /**
0974: * Return the unique url servlet mapping.
0975: * @param servlet the servlet name.
0976: * @param webDD the web DeploymentDesc where mappings are stored.
0977: * @return the unique url servlet mapping.
0978: * @throws WSServiceException when multiple (or 0) mappings are found.
0979: */
0980: private String getServletMapping(String servlet,
0981: WebContainerDeploymentDesc webDD) throws WSServiceException {
0982:
0983: List mappings = webDD.getServletMappings(servlet);
0984:
0985: logger.log(BasicLevel.DEBUG, "mapping : " + mappings);
0986:
0987: if (mappings == null) {
0988: String err = i18n
0989: .getMessage(
0990: "AbsWebServicesServiceImpl.getServletMapping.noMapping",
0991: servlet);
0992: logger.log(BasicLevel.ERROR, err);
0993: throw new WSServiceException(err);
0994: }
0995:
0996: if (mappings.size() != 1) {
0997: String err = i18n
0998: .getMessage(
0999: "AbsWebServicesServiceImpl.getServletMapping.1mappingOnly",
1000: servlet);
1001: logger.log(BasicLevel.ERROR, err);
1002: throw new WSServiceException(err);
1003: }
1004:
1005: String mapping = (String) mappings.get(0);
1006:
1007: // keep only the first part of the mapping :
1008: // /services/* becomes services
1009: StringTokenizer st = new StringTokenizer(mapping, "/");
1010: mapping = st.nextToken();
1011:
1012: return mapping;
1013:
1014: }
1015:
1016: /**
1017: * Remove WebServices descriptors associated to the given ClassLoader
1018: * @param cl key ClassLoader
1019: */
1020: public void removeCache(ClassLoader cl) {
1021: WSManagerWrapper.removeCache(cl);
1022: removeDeploymentInfoStack(cl);
1023: }
1024:
1025: /**
1026: * @return Returns the i18n.
1027: */
1028: protected static I18n getI18n() {
1029: return i18n;
1030: }
1031:
1032: /**
1033: * @return Returns the logger.
1034: */
1035: protected static Logger getLogger() {
1036: return logger;
1037: }
1038:
1039: /**
1040: * @see org.objectweb.jonas.ws.WebServicesService#completeWSDeployment(javax.naming.Context)
1041: */
1042: public void completeWSDeployment(Context ctx)
1043: throws WSServiceException {
1044: /**
1045: * 1. Get current deployer ClassLoader
1046: * 2. Get associated Stack
1047: * 3. For each DeployInfo element from the Stack
1048: * a. Iterate through its ServiceDesc
1049: * - create ServletEndpoints instance
1050: * - fill it with PortComponentDesc info
1051: * b. Bind ServletEndpoints instance
1052: */
1053: ClassLoader cl = null;
1054: ObjectName parent = null;
1055: Boolean isInEar = Boolean.FALSE;
1056: try {
1057: cl = (ClassLoader) ctx
1058: .lookup(WebServicesService.CLASSLOADER_CTX_PARAM);
1059: parent = (ObjectName) ctx
1060: .lookup(WebServicesService.PARENT_OBJECTNAME_CTX_PARAM);
1061: isInEar = (Boolean) ctx
1062: .lookup(WebServicesService.ISINEAR_CTX_PARAM);
1063: } catch (NamingException ne) {
1064: throw new WSServiceException("Cannot retrieve '"
1065: + WebServicesService.CLASSLOADER_CTX_PARAM
1066: + "' from given Context", ne);
1067: }
1068:
1069: Stack s = getDeploymentInfoStack(cl);
1070:
1071: while ((s != null) && (!s.empty())) {
1072:
1073: WSDeployInfo di = (WSDeployInfo) s.pop();
1074: URL warURL = di.getWarURL();
1075: WSDeploymentDesc wsdd = di.getDescriptor();
1076: ObjectName parentON = parent;
1077:
1078: if (isInEar.booleanValue()) {
1079: parentON = getParentModuleObjectName(parent, wsdd);
1080: }
1081:
1082: // Store the root webservices MBeans
1083: List webservices = new ArrayList();
1084: webservicesMBeans.put(warURL, webservices);
1085:
1086: ContainerNaming naming = null;
1087: try {
1088: naming = NamingManager.getInstance();
1089: } catch (NamingException ne) {
1090: throw new WSServiceException(
1091: "Cannot get NamingManager instance for "
1092: + wsdd.getDisplayName(), ne);
1093: }
1094: ClassLoader web = webService
1095: .getContextLinkedClassLoader(warURL);
1096: Context c = naming.getComponentContext(web);
1097: if (c == null) {
1098: throw new WSServiceException(
1099: "Cannot get Component Context from ClassLoader : "
1100: + web);
1101: }
1102:
1103: List sds = wsdd.getServiceDescs();
1104:
1105: // for each WSDL contained in the component
1106: for (Iterator i = sds.iterator(); i.hasNext();) {
1107: ServiceDesc sd = (ServiceDesc) i.next();
1108:
1109: // serviceMBean
1110: Service serviceMBean = createServiceMBean(sd.getName(),
1111: parentON);
1112: serviceMBean.setName(sd.getName());
1113: serviceMBean
1114: .setMappingFilename(sd.getMappingFilename());
1115: serviceMBean.setWsdlFilename(sd.getWsdlFilename());
1116:
1117: // add the MBeans to the registration list
1118: webservices.add(serviceMBean);
1119:
1120: // get the endpoint URL for each port-component
1121: // update the WSDL Definition
1122: for (Iterator pc = sd.getPortComponents().iterator(); pc
1123: .hasNext();) {
1124: PortComponentDesc pcd = (PortComponentDesc) pc
1125: .next();
1126: try {
1127: c.rebind("comp/jonas/" + pcd.getSibLink()
1128: + "/dd", sd);
1129: } catch (NamingException ne) {
1130: throw new WSServiceException(
1131: "Cannot bind ServiceDesc instance for servlet '"
1132: + sd.getName() + "'", ne);
1133: }
1134:
1135: // Filing up MBeans
1136: PortComponent pcMBean = createPortComponentMBean(
1137: pcd.getName(), serviceMBean);
1138: pcMBean.setEndpoint(pcd.getEndpointURL()
1139: .toExternalForm());
1140: pcMBean.setName(pcd.getName());
1141: pcMBean.setServiceEndpointInterface(pcd
1142: .getServiceEndpointInterface().getName());
1143: pcMBean.setWsdlPort(pcd.getQName().toString());
1144:
1145: if (pcd.hasBeanImpl()) {
1146: // first, we must find the StatelessSessionBean MBean
1147: ObjectName ssbSearch = WebServicesObjectName
1148: .getStatelessSessionBeanQuery(parentON,
1149: pcd.getSibLink());
1150: List onList = J2eeObjectName
1151: .queryObjectNames(ssbSearch);
1152:
1153: // should have only 1 element
1154: if (!onList.isEmpty()) {
1155: ObjectName on = (ObjectName) onList
1156: .iterator().next();
1157: pcMBean
1158: .setImplementationBean(on
1159: .toString());
1160: serviceMBean.addPortComponentMBean(pcMBean);
1161: } else {
1162: logger.log(BasicLevel.WARN,
1163: "Cannot find the MBean for Stateless '"
1164: + pcd.getSibLink() + "'");
1165: }
1166: } else {
1167: // first, we must find the Servlet MBean
1168: ObjectName sSearch = WebServicesObjectName
1169: .getServletQuery(parentON, pcd
1170: .getSibLink());
1171: List onList = J2eeObjectName
1172: .queryObjectNames(sSearch);
1173:
1174: // should have only 1 element
1175: if (!onList.isEmpty()) {
1176: ObjectName on = (ObjectName) onList
1177: .iterator().next();
1178: pcMBean
1179: .setImplementationBean(on
1180: .toString());
1181: serviceMBean.addPortComponentMBean(pcMBean);
1182: } else {
1183: logger.log(BasicLevel.WARN,
1184: "Cannot find the MBean for Servlet '"
1185: + pcd.getSibLink() + "'");
1186: }
1187: }
1188:
1189: addHandlerMBeansToPortComponent(pcMBean, pcd);
1190:
1191: // WSDL URL
1192: // The same WSDL is returned for each endpoint
1193: serviceMBean.setWsdlURL(pcd.getEndpointURL()
1194: .toExternalForm()
1195: + "?JWSDL");
1196: }
1197:
1198: }
1199:
1200: // register MBeans
1201: for (Iterator l = webservices.iterator(); l.hasNext();) {
1202: Service service = (Service) l.next();
1203: service.register(this .mbeanServer);
1204: }
1205:
1206: }
1207: }
1208:
1209: /**
1210: * @param parent EAR ObjectName
1211: * @param wsdd WebServices Deployment Descriptor
1212: * @return Returns the parent Module ObjectName (WebModule or EJBModule)
1213: */
1214: private static ObjectName getParentModuleObjectName(
1215: ObjectName parent, WSDeploymentDesc wsdd) {
1216: // EAR case :
1217: // then the parent ObjectName is the EAR ObjectName
1218: // So we need to find either the WebModule or EJBModule
1219: // that is the real parent of WebServices
1220:
1221: // for this, we will take the first PortComponent and
1222: // if this is a JaxRpcPCDesc, we will search for
1223: // a WebModule ObjectName containing the servlet-link
1224: // in the other case, we will search for an EJBModule
1225:
1226: ObjectName result = null;
1227: ServiceDesc sd = (ServiceDesc) wsdd.getServiceDescs()
1228: .iterator().next();
1229: PortComponentDesc pcd = (PortComponentDesc) sd
1230: .getPortComponents().iterator().next();
1231: String key = pcd.getSibLink();
1232: if (pcd.hasBeanImpl()) {
1233: // search for an EJBModule
1234: // first, we must find the StatelessSessionBean MBean
1235: ObjectName ssbSearch = WebServicesObjectName
1236: .getStatelessSessionBeanQuery(parent, key);
1237: List onList = J2eeObjectName.queryObjectNames(ssbSearch);
1238:
1239: // should have only 1 element
1240: if (!onList.isEmpty()) {
1241: ObjectName ssb = (ObjectName) onList.iterator().next();
1242:
1243: /// Once we have this ObjectName, we can easily get his parent
1244: // name via the EJBModule property :)
1245: ObjectName emSearch = WebServicesObjectName
1246: .getEJBModule(parent, ssb
1247: .getKeyProperty("EJBModule"));
1248: onList = J2eeObjectName.queryObjectNames(emSearch);
1249:
1250: // We take the first result and we set it as parent ON
1251: result = (ObjectName) onList.iterator().next();
1252: } else {
1253: // onList is empty, so just keep the J2EEApplication as parent
1254: logger.log(BasicLevel.WARN,
1255: "Cannot find EJBModule MBean containing SSB "
1256: + key);
1257: result = parent;
1258: }
1259: } else {
1260: // search for WebModule
1261: // first, we must find the Servlet MBean
1262: ObjectName sSearch = WebServicesObjectName.getServletQuery(
1263: parent, key);
1264: List onList = J2eeObjectName.queryObjectNames(sSearch);
1265:
1266: // should have only 1 element
1267: if (!onList.isEmpty()) {
1268: ObjectName servlet = (ObjectName) onList.iterator()
1269: .next();
1270:
1271: // / Once we have this ObjectName, we can easily get his parent
1272: // name via the WebModule property :)
1273: ObjectName wmSearch = WebServicesObjectName
1274: .getWebModule(parent, servlet
1275: .getKeyProperty("WebModule"));
1276: onList = J2eeObjectName.queryObjectNames(wmSearch);
1277:
1278: // We take the first result and we set it as parent ON
1279: result = (ObjectName) onList.iterator().next();
1280: } else {
1281: // onList is empty, so just keep the J2EEApplication as parent
1282: logger.log(BasicLevel.WARN,
1283: "Cannot find WebModule MBean containing Servlet "
1284: + key);
1285: result = parent;
1286:
1287: }
1288: }
1289: return result;
1290: }
1291:
1292: /**
1293: * @param key
1294: * ClassLoader
1295: * @return Returns a Stack of DeployInfo associated to the given ClassLoader
1296: */
1297: private Stack getDeploymentInfoStack(ClassLoader key) {
1298: return (Stack) deployments.get(key);
1299: }
1300:
1301: /**
1302: * Removes the Stack associated to the given ClassLoader
1303: * @param key ClassLoader
1304: */
1305: private void removeDeploymentInfoStack(ClassLoader key) {
1306: deployments.remove(key);
1307: }
1308:
1309: /**
1310: * Store information about a webservices descriptor.
1311: * @author Guillaume Sauthier
1312: */
1313: public class WSDeployInfo {
1314:
1315: /**
1316: * URL of the webapp
1317: */
1318: private URL war = null;
1319:
1320: /**
1321: * WebServices descriptor
1322: */
1323: private WSDeploymentDesc wsdd = null;
1324:
1325: /**
1326: * Creates a new WSDeployInfo instance with given parameters
1327: * @param war URL of the webapp
1328: * @param wsdd WebServices descriptor
1329: */
1330: public WSDeployInfo(URL war, WSDeploymentDesc wsdd) {
1331: this .war = war;
1332: this .wsdd = wsdd;
1333: }
1334:
1335: /**
1336: * @return Returns the Webapp URL
1337: */
1338: public URL getWarURL() {
1339: return war;
1340: }
1341:
1342: /**
1343: * @return Returns the WebServices Descriptor
1344: */
1345: public WSDeploymentDesc getDescriptor() {
1346: return wsdd;
1347: }
1348: }
1349:
1350: /**
1351: * @see org.objectweb.jonas.ws.WebServicesService#undeployWebServices(javax.naming.Context)
1352: */
1353: public void undeployWebServices(Context ctx)
1354: throws WSServiceException {
1355:
1356: URL url = null;
1357: try {
1358: url = (URL) ctx.lookup(WebServicesService.WARURL_CTX_PARAM);
1359: } catch (NamingException e) {
1360: // should never go here, but anyway ...
1361: throw new IllegalArgumentException(e.getMessage());
1362: }
1363:
1364: List ws = (List) webservicesMBeans.get(url);
1365: if (ws != null) {
1366: // unregister if a webservices MBean has been found
1367: for (Iterator l = ws.iterator(); l.hasNext();) {
1368: Service service = (Service) l.next();
1369: service.unregister(this .mbeanServer);
1370: }
1371: }
1372:
1373: // TODO unpublish WSDL ?
1374: }
1375:
1376: }
|