AbsWebServicesServiceImpl.java

00001 
00026 package org.objectweb.jonas.ws;
00027 
00028 import java.io.File;
00029 import java.io.IOException;
00030 import java.io.UnsupportedEncodingException;
00031 import java.net.MalformedURLException;
00032 import java.net.URL;
00033 import java.net.URLClassLoader;
00034 import java.net.URLEncoder;
00035 import java.util.HashMap;
00036 import java.util.Iterator;
00037 import java.util.List;
00038 import java.util.Map;
00039 import java.util.Stack;
00040 import java.util.StringTokenizer;
00041 
00042 import javax.naming.Context;
00043 import javax.naming.InitialContext;
00044 import javax.naming.NamingException;
00045 import javax.naming.Reference;
00046 import javax.naming.StringRefAddr;
00047 import javax.xml.namespace.QName;
00048 
00049 import org.objectweb.jonas_lib.I18n;
00050 import org.objectweb.jonas_lib.loader.WebappClassLoader;
00051 import org.objectweb.jonas_lib.naming.ContainerNaming;
00052 import org.objectweb.jonas_lib.naming.factory.URLFactory;
00053 
00054 import org.objectweb.jonas_web.deployment.api.WebContainerDeploymentDesc;
00055 import org.objectweb.jonas_web.deployment.api.WebContainerDeploymentDescException;
00056 import org.objectweb.jonas_web.deployment.lib.wrapper.WebManagerWrapper;
00057 
00058 import org.objectweb.jonas_ws.deployment.api.JaxRpcPortComponentDesc;
00059 import org.objectweb.jonas_ws.deployment.api.PortComponentDesc;
00060 import org.objectweb.jonas_ws.deployment.api.SSBPortComponentDesc;
00061 import org.objectweb.jonas_ws.deployment.api.ServiceDesc;
00062 import org.objectweb.jonas_ws.deployment.api.WSDLFile;
00063 import org.objectweb.jonas_ws.deployment.api.WSDeploymentDesc;
00064 import org.objectweb.jonas_ws.deployment.api.WSDeploymentDescException;
00065 import org.objectweb.jonas_ws.deployment.lib.wrapper.WSManagerWrapper;
00066 
00067 import org.objectweb.jonas.common.JProp;
00068 import org.objectweb.jonas.common.Log;
00069 import org.objectweb.jonas.ear.EarServiceImpl;
00070 import org.objectweb.jonas.naming.CompNamingContext;
00071 import org.objectweb.jonas.naming.NamingManager;
00072 import org.objectweb.jonas.service.AbsServiceImpl;
00073 import org.objectweb.jonas.service.ServiceException;
00074 import org.objectweb.jonas.service.ServiceManager;
00075 import org.objectweb.jonas.web.JWebContainerService;
00076 import org.objectweb.jonas.web.JWebContainerServiceException;
00077 import org.objectweb.jonas.ws.handler.WSDLHandler;
00078 import org.objectweb.jonas.ws.handler.WSDLHandlerFactory;
00079 
00080 import org.objectweb.util.monolog.api.BasicLevel;
00081 import org.objectweb.util.monolog.api.Logger;
00082 
00089 public abstract class AbsWebServicesServiceImpl extends AbsServiceImpl implements WebServicesService,
00090         AbsWebServicesServiceImplMBean {
00091 
00095     public static final String CLASSLOADER_CTX_PARAM = "classloader";
00096 
00101     public static final String PARSINGWITHVALIDATION = "jonas.service.ws.parsingwithvalidation";
00102 
00104     public static final String WSDL_HANDLERS = "jonas.service.ws.wsdlhandlers";
00105 
00110     public static final String WS_BASE = "jonas.service.ws.";
00111 
00113     private static Logger logger = null;
00114 
00116     private static I18n i18n = I18n.getInstance(AbsWebServicesServiceImpl.class);
00117 
00119     private WSDLManager wsdlManager = null;
00120 
00122     private JWebContainerService webService = null;
00123 
00127     private Map deployments = null;
00128 
00134     protected void doInit(Context ctx) throws ServiceException {
00135         // Init the logger
00136         logger = Log.getLogger(Log.JONAS_WS_PREFIX);
00137 
00138         // Init variables
00139         deployments = new HashMap();
00140 
00141         // Set the XML parsing mode to no validation
00142         String parsingMode = "false";
00143 
00144         try {
00145             parsingMode = (String) ctx.lookup(PARSINGWITHVALIDATION);
00146         } catch (NamingException e) {
00147             // No problem if there is no value for 'parsingwithvalidation'
00148             // (false by default)
00149             parsingMode = "false";
00150         }
00151 
00152         WSManagerWrapper.setParsingWithValidation("true".equalsIgnoreCase(parsingMode));
00153 
00154         if ("false".equalsIgnoreCase(parsingMode)) {
00155             logger.log(BasicLevel.DEBUG, "WebServices XML parsing without validation");
00156         } else {
00157             logger.log(BasicLevel.DEBUG, "WebServices XML parsing with validation");
00158         }
00159 
00160         // Init the wsdl Manager
00161         wsdlManager = new WSDLManager();
00162 
00163         // Get publishing parameters in jonas properties
00164         JProp jp = null;
00165 
00166         try {
00167             jp = JProp.getInstance();
00168         } catch (Exception e) {
00169             String err = i18n.getMessage("AbsWebServicesServiceImpl.doInit.noJProp");
00170             logger.log(BasicLevel.ERROR, err + " " + e.getMessage());
00171             throw new WSServiceException(err, e);
00172         }
00173 
00174         String[] handlers = jp.getValueAsArray(WSDL_HANDLERS);
00175 
00176         if (handlers == null) {
00177             String err = i18n.getMessage("AbsWebServicesServiceImpl.doInit.noHandlers", WSDL_HANDLERS);
00178             logger.log(BasicLevel.ERROR, err);
00179             throw new WSServiceException(err);
00180         }
00181 
00182         // Build WSDLHandlers
00183 
00184         WSDLHandlerFactory factory = WSDLHandlerFactory.newInstance();
00185 
00186         // build each specified handlers and add it in the WSDLManager.
00187         for (int i = 0; i < handlers.length; i++) {
00188 
00189             // Create the handler
00190             WSDLHandler handler = factory.newHandler(handlers[i]);
00191 
00192             if (logger.isLoggable(BasicLevel.DEBUG)) {
00193                 logger.log(BasicLevel.DEBUG, "Adding WSDLHandler '" + handlers[i] + "'");
00194             }
00195 
00196             // Add the created Handler
00197             wsdlManager.addHandler(handler);
00198         }
00199     }
00200 
00215     public void deployWebServices(Context ctx) throws WSServiceException {
00222         // Cannot get webContainer at startup (cycles)
00223         if (webService == null) {
00224             try {
00225                 webService = (JWebContainerService) ServiceManager.getInstance().getWebContainerService();
00226             } catch (Exception e) {
00227                 String err = i18n.getMessage("AbsWebServicesServiceImpl.deployWebServices.noWeb");
00228                 logger.log(BasicLevel.ERROR, err);
00229                 throw new WSServiceException(err, e);
00230             }
00231         }
00232 
00233         // Get context parameters.
00234         URL[] jarUrls = null;
00235         URL[] warUrls = null;
00236         URL earURL = null;
00237         ClassLoader ejbClassLoader = null;
00238         ClassLoader earClassLoader = null;
00239         Map warCtxRootMapping = null;
00240         String unpackDir = null;
00241 
00242         // EAR & Webapp case common information
00243         try {
00244             jarUrls = (URL[]) ctx.lookup("jarUrls");
00245             warUrls = (URL[]) ctx.lookup("warUrls");
00246             unpackDir = (String) ctx.lookup("unpackDir");
00247         } catch (NamingException e) {
00248             String err = i18n.getMessage("AbsWebServicesServiceImpl.deployWebServices.ctxParamProblem");
00249             logger.log(BasicLevel.ERROR, err + e.getMessage());
00250             throw new WSServiceException(err, e);
00251         }
00252 
00253         // EAR case specific information
00254         try {
00255             earURL = (URL) ctx.lookup("earURL");
00256             earClassLoader = (ClassLoader) ctx.lookup("earClassLoader");
00257             warCtxRootMapping = (Map) ctx.lookup("warCtxRootMapping");
00258             ejbClassLoader = (ClassLoader) ctx.lookup("ejbClassLoader");
00259         } catch (NamingException ne) {
00260             // WebApp case
00261             earURL = null;
00262             earClassLoader = null;
00263             warCtxRootMapping = null;
00264             ejbClassLoader = null;
00265         }
00266 
00267         // Deploy wars Web services.
00268         URLClassLoader loaderForCls = null;
00269         String earAppName = null;
00270         if (earURL != null) {
00271             earAppName = EarServiceImpl.buildJ2eeApplicationName(earURL);
00272         }
00273 
00274         String fileName = null;
00275         WSDeploymentDesc wsDD = null;
00276 
00277         for (int i = 0; i < warUrls.length; i++) {
00278             // Get the name of a war to deploy.
00279             fileName = warUrls[i].getFile();
00280             logger.log(BasicLevel.DEBUG, "Analyzing war '" + fileName + "' for web services");
00281 
00282             // Get the class loader for the current war.
00283             loaderForCls = webService.getClassLoader(warUrls[i], earAppName, ejbClassLoader);
00284 
00285             WebappClassLoader webLoader = (WebappClassLoader) loaderForCls;
00286             URL url = webLoader.getBaseURL();
00287 
00288             // Get the deployment descriptor from file.
00289             try {
00290                 wsDD = WSManagerWrapper.getDeploymentDesc(warUrls[i], url, loaderForCls, earClassLoader);
00291             } catch (WSDeploymentDescException wsdde) {
00292                 String err = i18n.getMessage("AbsWebServicesServiceImpl.deployWebServices.wsddEx", fileName);
00293                 logger.log(BasicLevel.ERROR, err + ": " + wsdde);
00294                 throw new WSServiceException(err, wsdde);
00295             }
00296 
00297             if (wsDD != null) {
00298                 // The current War contains Webservices
00299                 try {
00300                     Context compCtx = new CompNamingContext(fileName);
00301                     compCtx.rebind("wsDD", wsDD);
00302                     compCtx.rebind("cl", loaderForCls);
00303 
00304                     if (earClassLoader != null) {
00305                         compCtx.rebind("earCL", earClassLoader);
00306                     }
00307                     compCtx.rebind("warURL", warUrls[i]);
00308 
00309                     // ear case
00310                     if (warCtxRootMapping != null) {
00311                         compCtx.rebind("warContextRoot", warCtxRootMapping.get(warUrls[i]));
00312 
00313                         // non-ear case
00314                     } else {
00315                         compCtx.rebind("warContextRoot", "");
00316                     }
00317 
00318                     doDeployWebServices(compCtx);
00319                 } catch (NamingException ne) {
00320                     String err = i18n.getMessage("AbsWebServicesServiceImpl.deployWebServices.bindError", fileName);
00321                     logger.log(BasicLevel.ERROR, err);
00322                     throw new WSServiceException(err, ne);
00323                 }
00324             }
00325         }
00326         // End deploy wars Web services.
00327 
00328         // Deploy jars Web services.
00329         // Check warCtxRootMapping presence
00330         if ((jarUrls.length != 0) && (warCtxRootMapping == null)) {
00331             String err = i18n.getMessage("AbsWebServicesServiceImpl.deployWebServices.ctxRootMappingMissing");
00332             logger.log(BasicLevel.ERROR, err);
00333             throw new WSServiceException(err);
00334         }
00335 
00336         for (int i = 0; i < jarUrls.length; i++) {
00337             // Get the name of a war to deploy.
00338             fileName = jarUrls[i].getFile();
00339             logger.log(BasicLevel.DEBUG, "Analyzing EjbJar '" + fileName + "' for web services");
00340 
00341             URLClassLoader webClassLoader = null;
00342 
00343             // Get the deployment descriptor from file.
00344             try {
00345                 wsDD = WSManagerWrapper.getDeploymentDesc(jarUrls[i], ejbClassLoader, earClassLoader);
00346             } catch (WSDeploymentDescException wsdde) {
00347                 String err = i18n.getMessage("AbsWebServicesServiceImpl.deployWebServices.wsddEx", fileName);
00348                 logger.log(BasicLevel.ERROR, err + ": " + wsdde);
00349                 throw new WSServiceException(err, wsdde);
00350             }
00351 
00352             if (wsDD != null) {
00353                 // The current Jar contains Webservices
00354                 URL warURL = null;
00355 
00356                 try {
00361                     if (wsDD.getWarFile() != null) {
00362                         // use getCanonicalFile to fix Bug #300658
00363                         //new File(new URL(dirName + File.separator + s).getFile()).getCanonicalFile().toURL();
00364                         warURL = new File(new URL(unpackDir + File.separator + wsDD.getWarFile()).getFile()).getCanonicalFile().toURL();
00365                         //warURL = new URL(unpackDir + "/" + wsDD.getWarFile());
00366                     } else {
00367                         String ejb = new File(jarUrls[i].getFile()).getName();
00368                         String war = ejb.substring(0, ejb.length() - ".jar".length());
00369                         //warURL = new URL(unpackDir + "/" + war + ".war");
00370                         warURL = new File(new URL(unpackDir + File.separator + war + ".war").getFile()).getCanonicalFile().toURL();
00371                     }
00372                     logger.log(BasicLevel.DEBUG, "Unpack Dir : " + unpackDir);
00373                     logger.log(BasicLevel.DEBUG, "Computed URL : " + warURL);
00374 
00375                     // check if webapp is present
00376                     boolean present = false;
00377 
00378                     for (int w = 0; w < warUrls.length; w++) {
00379                         if (warUrls[w].equals(warURL)) {
00380                             present = true;
00381                         }
00382                         logger.log(BasicLevel.DEBUG, "warUrls[" + w + "]=" + warUrls[w]);
00383                     }
00384 
00385                     // get the linked web classloader
00386                     webClassLoader = webService.getClassLoader(warURL, earAppName, ejbClassLoader);
00387 
00388                     if (!present) {
00389                         String err = i18n.getMessage("AbsWebServicesServiceImpl.deployWebServices.webappNotFound",
00390                                 warURL);
00391                         logger.log(BasicLevel.ERROR, err);
00392                         throw new WSServiceException(err);
00393                     }
00394                 } catch (MalformedURLException mue) {
00395                     String err = i18n.getMessage("AbsWebServicesServiceImpl.deployWebServices.mue");
00396                     logger.log(BasicLevel.ERROR, mue.getMessage());
00397                     throw new WSServiceException(err, mue);
00398                 } catch (IOException ioe) {
00399                     // TODO add i18n
00400                     String err = "Cannot locate file : " + ioe.getMessage();
00401                     logger.log(BasicLevel.ERROR, err);
00402                     throw new WSServiceException(err, ioe);
00403                 }
00404 
00405                 try {
00406                     Context compCtx = new CompNamingContext(fileName);
00407                     compCtx.rebind("wsDD", wsDD);
00408 
00409                     // Using WebClassLoader ()
00410                     compCtx.rebind("cl", webClassLoader);
00411                     compCtx.rebind("earCL", earClassLoader);
00412 
00413                     compCtx.rebind("warURL", warURL);
00414 
00415                     // warContextRoot cannot be null in ejb case
00416                     // because an ejb needs a webapp for webservices
00417                     compCtx.rebind("warContextRoot", warCtxRootMapping.get(warURL));
00418                     doDeployWebServices(compCtx);
00419                 } catch (NamingException ne) {
00420                     String err = i18n.getMessage("AbsWebServicesServiceImpl.deployWebServices.bindError", fileName);
00421                     logger.log(BasicLevel.ERROR, err);
00422                     throw new WSServiceException(err, ne);
00423                 }
00424             }
00425         }
00426 
00427         // End deploy jars Web services.
00428     }
00429 
00435     protected void doDeployWebServices(Context ctx) throws WSServiceException {
00442         WSDeploymentDesc wsDD = null;
00443         ClassLoader cl = null;
00444         ClassLoader earCL = null;
00445         String warContextRoot = null;
00446         URL warURL = null;
00447 
00448         try {
00449             wsDD = (WSDeploymentDesc) ctx.lookup("wsDD");
00450             cl = (ClassLoader) ctx.lookup("cl");
00451             warContextRoot = (String) ctx.lookup("warContextRoot");
00452             warURL = (URL) ctx.lookup("warURL");
00453         } catch (NamingException ne) {
00454             String err = i18n.getMessage("AbsWebServicesServiceImpl.doDeployWebServices.namingError");
00455             logger.log(BasicLevel.ERROR, err);
00456             throw new WSServiceException(err, ne);
00457         }
00458 
00459         if (logger.isLoggable(BasicLevel.DEBUG)) {
00460             logger.log(BasicLevel.DEBUG, "Deploying WebServices for '" + warURL + "'");
00461         }
00462 
00463         try {
00464             earCL = (ClassLoader) ctx.lookup("earCL");
00465         } catch (NamingException ne) {
00466             // Nothing to do : non EAR case
00467             earCL = null;
00468         }
00469 
00470         // store WSDeployInfo for later use (completeWSDeployment method)
00471         ClassLoader key = cl;
00472         if (earCL != null) {
00473             key = earCL;
00474         }
00475         Stack s = (Stack) deployments.get(key);
00476         if (s == null) {
00477             s = new Stack();
00478             deployments.put(key, s);
00479         }
00480         s.push(new WSDeployInfo(warURL, wsDD));
00481 
00482         List sds = wsDD.getServiceDescs();
00483 
00484         // for each WSDL contained in the component
00485         for (Iterator i = sds.iterator(); i.hasNext();) {
00486             ServiceDesc sd = (ServiceDesc) i.next();
00487             WSDLFile wsdl = sd.getWSDL();
00488 
00489             // get the endpoint URL for each port-component
00490             // update the WSDL Definition
00491             for (Iterator pc = sd.getPortComponents().iterator(); pc.hasNext();) {
00492                 PortComponentDesc pcd = (PortComponentDesc) pc.next();
00493                 QName portQName = pcd.getQName();
00494                 URL endpoint = null;
00495                 if (pcd.hasJaxRpcImpl()) {
00496                     endpoint = getEndpointURL(wsDD, (JaxRpcPortComponentDesc) pcd, warURL, warContextRoot);
00497                 } else {
00498                     endpoint = getEndpointURL(wsDD, (SSBPortComponentDesc) pcd, warURL, cl, earCL, warContextRoot);
00499                 }
00500 
00501                 pcd.setEndpointURL(endpoint);
00502                 wsdl.setLocation(portQName, endpoint);
00503 
00504                 // add endpoint URL into JNDI namespace to allow application
00505                 // clients (that are not running in the same JVM) to use
00506                 // port-component-link
00507                 Context registry;
00508                 try {
00509                     registry = new InitialContext();
00510                     Reference urlRef = new Reference(URL.class.getName(), URLFactory.class.getName(), null);
00511                     urlRef.add(new StringRefAddr("url", endpoint.toString()));
00512                     registry.rebind(pcd.getName(), urlRef);
00513                     logger.log(BasicLevel.DEBUG, "Bind updated URL (" + endpoint + ") in " + pcd.getName());
00514                 } catch (NamingException ne) {
00515                     throw new WSServiceException("Cannot bind updated URL for port-component '" + pcd.getName()
00516                             + "'", ne);
00517                 }
00518             }
00519 
00520             // publish WSDL
00521             wsdlManager.publish(sd);
00522         }
00523     }
00524 
00534     private URL getEndpointURL(WSDeploymentDesc wsDD, JaxRpcPortComponentDesc jpcd, URL warURL, String contextRoot)
00535             throws WSServiceException {
00536 
00537         logger.log(BasicLevel.DEBUG, "get endpoint for JaxRpc Port Component");
00538 
00539         return getEndpointURL(wsDD, jpcd.getWebDesc(), warURL, contextRoot, jpcd);
00540 
00541     }
00542 
00554     private URL getEndpointURL(WSDeploymentDesc wsDD, SSBPortComponentDesc spcd, URL warURL, ClassLoader cl,
00555             ClassLoader earCL, String contextRoot) throws WSServiceException {
00556 
00557         logger.log(BasicLevel.DEBUG, "get endpoint for StatelessSessionBean Port Component");
00558 
00559         WebContainerDeploymentDesc webDD = null;
00560 
00561         try {
00562             webDD = WebManagerWrapper.getDeploymentDesc(warURL, cl, earCL);
00563         } catch (WebContainerDeploymentDescException e) {
00564             String err = i18n.getMessage("AbsWebServicesServiceImpl.getEndpointURL.webDDException", warURL.getFile());
00565             logger.log(BasicLevel.ERROR, err);
00566             throw new WSServiceException(err, e);
00567         }
00568 
00569         return getEndpointURL(wsDD, webDD, warURL, contextRoot, spcd);
00570 
00571     }
00572 
00585     private URL getEndpointURL(WSDeploymentDesc wsDD, WebContainerDeploymentDesc webDD, URL warURL,
00586             String warContextRoot, PortComponentDesc pcd) throws WSServiceException {
00587 
00588         // Resolve :
00589         // - hostname
00590         // - http/https port
00591         // Priority order : 1. the ones specified in jonas-web.xml
00592         //                  2. default web container values (if any)
00593         String servletName = pcd.getSibLink();
00594         String pcName = pcd.getQName().getLocalPart();
00595 
00596         logger.log(BasicLevel.DEBUG, "SOAP Servlet name '" + servletName + "'");
00597 
00598         String hostname = webDD.getHost();
00599         String port = webDD.getPort();
00600         String scheme = "";
00601         String contextRoot = null;
00602         String mapping = null;
00603 
00604         if (wsDD.getContextRoot() != null && (pcd instanceof SSBPortComponentDesc)) {
00605             contextRoot = wsDD.getContextRoot();
00606         } else {
00607             contextRoot = getContextRoot(warContextRoot, webDD, warURL);
00608         }
00609 
00610         boolean needPortName = true;
00611         if (pcd.getEndpointURI() != null) {
00612             mapping = pcd.getEndpointURI();
00613             needPortName = false;
00614         } else {
00615             mapping = getServletMapping(servletName, webDD);
00616         }
00617 
00618         // get default host value
00619         if (hostname == null) {
00620             // get hostname
00621             try {
00622                 hostname = webService.getDefaultHost();
00623             } catch (JWebContainerServiceException e) {
00624                 String err = i18n
00625                         .getMessage("AbsWebServicesServiceImpl.getEndpointURL.noDefaultHost", warURL.getFile());
00626                 logger.log(BasicLevel.ERROR, err);
00627                 throw new WSServiceException(err, e);
00628             }
00629         }
00630 
00631         // get default port and scheme value
00632         if (port == null) {
00633             // get Http informations
00634             try {
00635                 port = webService.getDefaultHttpPort();
00636                 scheme = "http";
00637             } catch (JWebContainerServiceException e) {
00638                 // Http Fails
00639                 // Try Https informations
00640                 try {
00641                     port = webService.getDefaultHttpsPort();
00642                     scheme = "https";
00643                 } catch (JWebContainerServiceException e2) {
00644                     String err = i18n.getMessage("AbsWebServicesServiceImpl.getEndpointURL.noDefaultHTTPPort", warURL
00645                             .getFile());
00646                     logger.log(BasicLevel.ERROR, err);
00647                     throw new WSServiceException(err, e2);
00648                 }
00649             }
00650         }
00651 
00652         // construct URL
00653         if (port.equals("80")) {
00654             port = "";
00655         } else {
00656             port = ":" + port;
00657         }
00658 
00659         String url = null;
00660         if (needPortName) {
00661             String encodedPortName = null;
00662             try {
00663                 encodedPortName = URLEncoder.encode(pcName, "UTF-8");
00664             } catch (UnsupportedEncodingException e) {
00665                 // should never occurs since utf-8 is mandatory on all JVM
00666                 encodedPortName = pcName;
00667             }
00668             url = scheme + "://" + hostname + port + "/" + contextRoot + "/" + mapping + "/" + encodedPortName;
00669         } else {
00670             url = scheme + "://" + hostname + port + "/" + contextRoot + mapping;
00671         }
00672 
00673         URL endpoint = null;
00674 
00675         try {
00676             endpoint = new URL(url);
00677         } catch (MalformedURLException mue) {
00678             String err = i18n.getMessage("AbsWebServicesServiceImpl.getEndpointURL.endpointURLError", pcName, url);
00679             logger.log(BasicLevel.ERROR, err);
00680             throw new WSServiceException(err, mue);
00681         }
00682 
00683         if (logger.isLoggable(BasicLevel.DEBUG)) {
00684             logger.log(BasicLevel.DEBUG, "Constructed URL for '" + pcName + "' : '" + endpoint + "'");
00685         }
00686 
00687         return endpoint;
00688     }
00689 
00697     private static String getContextRoot(String ctxRoot, WebContainerDeploymentDesc webDD, URL warURL) {
00698         // Set the right context root for the web application, the priority is
00699         // the following :
00700         //    1 - context-root of application.xml
00701         //    2 - context-root of jonas-web.xml
00702         //    3 - context-root is the name of the file without .war.
00703         String contextRoot = null;
00704 
00705         if ("".equals(ctxRoot)) {
00706             String cRoot = webDD.getContextRoot();
00707 
00708             if (cRoot == null) {
00709                 String file = new File(warURL.getFile()).getName();
00710 
00711                 if (file.toLowerCase().endsWith(".war")) {
00712                     contextRoot = file.substring(0, file.length() - ".war".length());
00713                 } else {
00714                     //It's a directory which is deployed
00715                     contextRoot = file.substring(0, file.length());
00716                 }
00717             } else {
00718                 contextRoot = cRoot;
00719             }
00720         } else {
00721             contextRoot = ctxRoot;
00722         }
00723 
00724         return contextRoot;
00725     }
00726 
00731     public void doStop() throws ServiceException {
00732     }
00733 
00738     public void doStart() throws ServiceException {
00739     }
00740 
00748     private String getServletMapping(String servlet, WebContainerDeploymentDesc webDD) throws WSServiceException {
00749 
00750         List mappings = webDD.getServletMappings(servlet);
00751 
00752         logger.log(BasicLevel.DEBUG, "mapping : " + mappings);
00753 
00754         if (mappings == null) {
00755             String err = i18n.getMessage("AbsWebServicesServiceImpl.getServletMapping.noMapping", servlet);
00756             logger.log(BasicLevel.ERROR, err);
00757             throw new WSServiceException(err);
00758         }
00759 
00760         if (mappings.size() != 1) {
00761             String err = i18n.getMessage("AbsWebServicesServiceImpl.getServletMapping.1mappingOnly", servlet);
00762             logger.log(BasicLevel.ERROR, err);
00763             throw new WSServiceException(err);
00764         }
00765 
00766         String mapping = (String) mappings.get(0);
00767 
00768         // keep only the first part of the mapping :
00769         // /services/* becomes services
00770         StringTokenizer st = new StringTokenizer(mapping, "/");
00771         mapping = st.nextToken();
00772 
00773         return mapping;
00774 
00775     }
00776 
00781     public void removeCache(ClassLoader cl) {
00782         WSManagerWrapper.removeCache(cl);
00783         removeDeploymentInfoStack(cl);
00784     }
00785 
00789     protected static I18n getI18n() {
00790         return i18n;
00791     }
00792 
00796     protected static Logger getLogger() {
00797         return logger;
00798     }
00799 
00803     public void completeWSDeployment(Context ctx) throws WSServiceException {
00813         ClassLoader cl = null;
00814         try {
00815             cl = (ClassLoader) ctx.lookup(CLASSLOADER_CTX_PARAM);
00816         } catch (NamingException ne) {
00817             throw new WSServiceException("Cannot retrieve '" + CLASSLOADER_CTX_PARAM + "' from given Context", ne);
00818         }
00819 
00820         Stack s = getDeploymentInfoStack(cl);
00821 
00822         for (; s != null && !s.empty();) {
00823             WSDeployInfo di = (WSDeployInfo) s.pop();
00824             URL warURL = di.getWarURL();
00825             WSDeploymentDesc wsdd = di.getDescriptor();
00826 
00827             ContainerNaming naming = null;
00828             try {
00829                 naming = NamingManager.getInstance();
00830             } catch (NamingException ne) {
00831                 throw new WSServiceException("Cannot get NamingManager instance for " + wsdd.getDisplayName(), ne);
00832             }
00833             ClassLoader web = webService.getContextLinkedClassLoader(warURL);
00834             Context c = naming.getComponentContext(web);
00835             if (c == null) {
00836                 throw new WSServiceException("Cannot get Component Context from ClassLoader : " + web);
00837             }
00838 
00839             List sds = wsdd.getServiceDescs();
00840 
00841             // for each WSDL contained in the component
00842             for (Iterator i = sds.iterator(); i.hasNext();) {
00843                 ServiceDesc sd = (ServiceDesc) i.next();
00844 
00845                 // get the endpoint URL for each port-component
00846                 // update the WSDL Definition
00847                 for (Iterator pc = sd.getPortComponents().iterator(); pc.hasNext();) {
00848                     PortComponentDesc pcd = (PortComponentDesc) pc.next();
00849                     try {
00850                         c.rebind("comp/jonas/" + pcd.getSibLink() + "/dd", sd);
00851                     } catch (NamingException ne) {
00852                         throw new WSServiceException("Cannot bind ServiceDesc instance for servlet '" + sd.getName()
00853                                 + "'", ne);
00854                     }
00855                 }
00856             }
00857         }
00858     }
00859 
00864     private Stack getDeploymentInfoStack(ClassLoader key) {
00865         return (Stack) deployments.get(key);
00866     }
00867 
00872     private void removeDeploymentInfoStack(ClassLoader key) {
00873         deployments.remove(key);
00874     }
00875 
00880     public class WSDeployInfo {
00881 
00885         private URL war = null;
00886 
00890         private WSDeploymentDesc wsdd = null;
00891 
00897         public WSDeployInfo(URL war, WSDeploymentDesc wsdd) {
00898             this.war = war;
00899             this.wsdd = wsdd;
00900         }
00901 
00905         public URL getWarURL() {
00906             return war;
00907         }
00908 
00912         public WSDeploymentDesc getDescriptor() {
00913             return wsdd;
00914         }
00915     }
00916 
00917 }

Generated on Tue Feb 15 15:05:34 2005 for JOnAS by  doxygen 1.3.9.1