User: starksm Date: 02/04/04 10:25:13 Modified: jetty/src/main/org/jboss/jetty Tag: Branch_2_4 JBossWebApplicationContext.java Jetty.java JettyMBean.java JettyService.java JettyServiceMBean.java Removed: jetty/src/main/org/jboss/jetty Tag: Branch_2_4 JBossLogSink.java JBossUserRealm.java Log: Update jetty service for changes to AbstractWebContainer and move to Jetty-4.0.0. Revision Changes Path No revision No revision 1.34.2.3 +157 -194 contrib/jetty/src/main/org/jboss/jetty/JBossWebApplicationContext.java Index: JBossWebApplicationContext.java =================================================================== RCS file: /cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/JBossWebApplicationContext.java,v retrieving revision 1.34.2.2 retrieving revision 1.34.2.3 diff -u -r1.34.2.2 -r1.34.2.3 --- JBossWebApplicationContext.java 20 Mar 2002 20:58:31 -0000 1.34.2.2 +++ JBossWebApplicationContext.java 4 Apr 2002 18:25:12 -0000 1.34.2.3 @@ -5,7 +5,7 @@ * See terms of license at gnu.org. */ -// $Id: JBossWebApplicationContext.java,v 1.34.2.2 2002/03/20 20:58:31 jules_gosnell Exp $ +// $Id: JBossWebApplicationContext.java,v 1.34.2.3 2002/04/04 18:25:12 starksm Exp $ // A Jetty HttpServer with the interface expected by JBoss' // J2EEDeployer... @@ -16,12 +16,13 @@ //------------------------------------------------------------------------------ +import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; import javax.xml.parsers.DocumentBuilder; -import org.jboss.jetty.JBossUserRealm; +import org.jboss.jetty.security.JBossUserRealm; import org.jboss.logging.Logger; import org.jboss.web.AbstractWebContainer.WebDescriptorParser; import org.jboss.web.WebApplication; @@ -47,26 +48,27 @@ WebDescriptorParser _descriptorParser; WebApplication _webApp; DocumentBuilder _parser; - // String _subjAttrName="j_subject"; + String _subjAttrName="j_subject"; public JBossWebApplicationContext(Jetty jetty, String contextPathSpec, WebDescriptorParser descriptorParser, WebApplication webApp, - DocumentBuilder parser/*,*/ - /*String warUrl*/) + DocumentBuilder parser, + String warUrl) throws IOException { - super(jetty, contextPathSpec/*, warUrl*/); + super(jetty, contextPathSpec, warUrl); _log = Logger.getLogger(getClass().getName()+"#" + contextPathSpec); _jetty = jetty; _descriptorParser = descriptorParser; _webApp = webApp; _parser = parser; - // _subjAttrName = jetty.getSubjectAttributeName(); + _subjAttrName = jetty.getSubjectAttributeName(); + } /* ------------------------------------------------------------ */ @@ -88,7 +90,7 @@ if (realmName!=null) { // these need to be cached and reused by name...MAYBE - TODO - getHttpServer().addRealm(new JBossUserRealm(realmName)); + getHttpContext().getHttpServer().addRealm(new JBossUserRealm(realmName, _subjAttrName)); } // this is causing a printout which implies a separate @@ -107,185 +109,178 @@ getSecurityHandler() { SecurityHandler securityHandler=null; - securityHandler=(SecurityHandler)getHandler(JBossSXSecurityHandler.class); + securityHandler=(SecurityHandler)getHttpHandler(JBossSXSecurityHandler.class); if (securityHandler==null) { securityHandler=new JBossSXSecurityHandler(); - addHandler(0,securityHandler); + addHttpHandler(0,securityHandler); } return securityHandler; } // avoid Jetty maoning about things that it doesn't but AbstractWebContainer does do... - // protected void - // initWebXmlElement(String element, org.mortbay.xml.XmlParser.Node node) - // throws Exception - // { - // // this is ugly - should be dispatched through a hash-table or introspection... - // - // // these are handled by AbstractWebContainer - // if ("resource-ref".equals(element) || - // "env-entry".equals(element) || - // "ejb-ref".equals(element) || - // "ejb-local-ref".equals(element) || - // "security-domain".equals(element)) - // { - // //_log.info("Don't moan : "+element); - // } - // else if ("distributable".equals(element)) - // { - // ((DistributedHttpSessionManager)getServletHandler().getSessionManager()). - // setDistributed(true); - // } - // // these are handled by Jetty - // else - // super.initWebXmlElement(element, node); - // } + protected void + initWebXmlElement(String element, org.mortbay.xml.XmlParser.Node node) + throws Exception + { + // this is ugly - should be dispatched through a hash-table or introspection... + + // these are handled by AbstractWebContainer + if ("resource-ref".equals(element) || + "env-entry".equals(element) || + "ejb-ref".equals(element) || + "ejb-local-ref".equals(element) || + "security-domain".equals(element)) + { + //_log.info("Don't moan : "+element); + } + // these are handled by Jetty + else + super.initWebXmlElement(element, node); + } // hack our class loader to be Java2 compliant - i.e. always // delegate upwards before looking locally. This will be changed to // a non-compliant strategy later when JBoss' new ClassLoader is // ready. - // protected void initClassLoader(boolean forceContextLoader) - // throws java.net.MalformedURLException, IOException - // { - // // force the creation of a context class loader for JBoss - // // web apps - // super.initClassLoader(true); - // - // ClassLoader _loader=getClassLoader(); - // if (_loader instanceof org.mortbay.http.ContextLoader) - // ((org.mortbay.http.ContextLoader)_loader).setJava2Compliant(_jetty.getJava2ClassLoadingCompliance()); - // } + protected void initClassLoader(boolean forceContextLoader) + throws java.net.MalformedURLException, IOException + { + // force the creation of a context class loader for JBoss + // web apps + super.initClassLoader(true); + + ClassLoader _loader=getClassLoader(); + if (_loader instanceof org.mortbay.http.ContextLoader) + ((org.mortbay.http.ContextLoader)_loader).setJava2Compliant(_jetty.getJava2ClassLoadingCompliance()); + } + + String _separator=System.getProperty("path.separator"); + + public String + getFileClassPath() + { + List List=new ArrayList(); + getFileClassPath(getClassLoader(), List); + + String classpath=""; + for (Iterator i=List.iterator(); i.hasNext();) + { + URL url=(URL)i.next(); + + if (url.getProtocol().equals("njar")) + { + try + { + // force the resource we are after to be unpacked - tmp hack - thanks David Jencks! + URL dummy=new URL("njar:"+url.toString()+"^"+"/dummy.jar"); + String tmp=dummy.openConnection().getURL().toString(); + tmp=tmp.substring("jar:".length()); + tmp=tmp.substring(0, tmp.length()-"!/dummy.jar".length()); + _log.info("converting "+url+" -> "+tmp); + url=new URL(tmp); + } + catch (Exception ignore) + { + } + } + + if (!url.getProtocol().equals("file")) // tmp warning + { + _log.warn("JSP classpath: non-'file' protocol: "+url); + continue; + } + + try + { + Resource res = Resource.newResource (url); + if (res.getFile()==null) + _log.warn("bad classpath entry: "+url); + else + { + String tmp=res.getFile().getCanonicalPath(); + // _log.info("JSP FILE: "+url+" --> "+tmp+" : "+url.getProtocol()); + classpath+=(classpath.length()==0?"":_separator)+tmp; + } + } + catch (IOException ioe) + { + _log.warn ("JSP Classpath is damaged, can't convert path for :"+url, ioe); + } + } + + _log.info("JSP classpath: "+classpath); + return classpath; + } + + public void + getFileClassPath(ClassLoader cl, List list) + { + if (cl==null) + return; + + URL[] urls=null; + + if (cl instanceof java.net.URLClassLoader) + urls=((java.net.URLClassLoader)cl).getURLs(); + + // _log.info("CLASSLOADER: "+cl); + // _log.info("URLs: "+(urls!=null?urls.length:0)); + + if (urls!=null) + for (int i=0; i<urls.length; i++) + { + URL url=urls[i]; + // _log.info("URL: "+url); + if (!list.contains(url)) + list.add(url); + } + + getFileClassPath(cl.getParent(), list); + } -// String _separator=System.getProperty("path.separator"); -// // public String -// getFileClassPath() +// getFileClassPath(ClassLoader cl) // { -// List List=new ArrayList(); -// getFileClassPath(getClassLoader(), List); -// // String classpath=""; -// for (Iterator i=List.iterator(); i.hasNext();) -// { -// URL url=(URL)i.next(); -// -// // if (url.getProtocol().equals("njar")) -// // { -// // try -// // { -// // URLConnection conn=url.openConnection(); -// // //url=conn.getURL(); -// // _log.warn("JSP CONNECTION: "+conn); -// // } -// // catch (IOException ignore) -// // { -// // } -// // } +// String[] entries=_jetty.getCompileClasspath(cl); // -// if (!url.getProtocol().equals("file")) // tmp warning -// { -// _log.warn("JSP classpath: non-'file' protocol: "+url); -// continue; -// } -// -// try -// { -// Resource res = Resource.newResource (url); -// if (res.getFile()==null) -// _log.warn("bad classpath entry: "+url); -// else -// { -// String tmp=res.getFile().getCanonicalPath(); -// // _log.info("JSP FILE: "+url+" --> "+tmp+" : "+url.getProtocol()); -// if (classpath.indexOf(tmp)==-1) // TODO - we should do this -// classpath+=(classpath.length()==0?"":_separator)+tmp; -// } -// } -// catch (IOException ioe) -// { -// _log.warn ("JSP Classpath is damaged, can't convert path for :"+url, ioe); -// } +// for (int i=0; i<entries.length; i++) +// { +// try +// { +// Resource res = Resource.newResource (entries[i]); +// if (res.getFile()==null) +// _log.warn("bad classpath entry: "+entries[i]); +// else +// { +// String tmp=res.getFile().getCanonicalPath(); +// classpath+=(classpath.length()==0?"":_separator)+tmp; +// } +// } +// catch (IOException ioe) +// { +// _log.warn ("JSP Classpath is damaged, can't convert path for :"+entries[i], ioe); +// } // } // -// _log.info("JSP classpath: "+classpath); -// return classpath; -// } -// -// public void -// getFileClassPath(ClassLoader cl, List list) -// { -// if (cl==null) -// return; -// -// URL[] urls=null; -// -// /* -// if (cl instanceof org.jboss.system.UnifiedClassLoader) -// urls=((org.jboss.system.UnifiedClassLoader)cl).getAllURLs(); -// else if (cl instanceof org.jboss.system.MBeanClassLoader) -// urls=((org.jboss.system.MBeanClassLoader)cl).getURLs(); -// else */ if (cl instanceof java.net.URLClassLoader) -// urls=((java.net.URLClassLoader)cl).getURLs(); -// -// _log.info("CLASSLOADER: "+cl); -// _log.info("URLs: "+(urls!=null?urls.length:0)); +// if (_log.isDebugEnabled()) +// _log.debug("JSP classpath: "+classpath); // -// if (urls!=null) -// for (int i=0; i<urls.length; i++) -// { -// URL url=urls[i]; -// _log.info("URL: "+url); -// if (!list.contains(url)) -// list.add(url); -// } -// -// getFileClassPath(cl.getParent(), list); +// return classpath; // } - // public String - // getFileClassPath(ClassLoader cl) - // { - // String classpath=""; - // String[] entries=_jetty.getCompileClasspath(cl); - // - // for (int i=0; i<entries.length; i++) - // { - // try - // { - // Resource res = Resource.newResource (entries[i]); - // if (res.getFile()==null) - // _log.warn("bad classpath entry: "+entries[i]); - // else - // { - // String tmp=res.getFile().getCanonicalPath(); - // classpath+=(classpath.length()==0?"":_separator)+tmp; - // } - // } - // catch (IOException ioe) - // { - // _log.warn ("JSP Classpath is damaged, can't convert path for :"+entries[i], ioe); - // } - // } - // - // if (_log.isDebugEnabled()) - // _log.debug("JSP classpath: "+classpath); - // - // return classpath; - // } - // given a resource name, find the jar file that contains that resource... - // protected String - // findJarByResource(String resource) - // throws Exception - // { - // String path=getClass().getClassLoader().getResource(resource).toString(); - // // lose initial "jar:file:" and final "!/..." - // return path.substring("jar:file:".length(),path.length()-(resource.length()+2)); - // } + protected String + findJarByResource(String resource) + throws Exception + { + String path=getClass().getClassLoader().getResource(resource).toString(); + // lose initial "jar:file:" and final "!/..." + return path.substring("jar:file:".length(),path.length()-(resource.length()+2)); + } protected void startHandlers() @@ -304,41 +299,9 @@ try { - // MANDATORY - web.xml - Resource web=getResource("/WEB-INF/web.xml"); - _webApp.setWebApp(_parser.parse(new InputSource(web.toString())).getDocumentElement()); - } - catch (Exception e) - { - _log.error("problem locating web.xml", e); - } - - try - { - // OPTIONAL - jboss-web.xml - Resource jbossWeb=getResource("/WEB-INF/jboss-web.xml"); - if (jbossWeb!=null) - _webApp.setJbossWeb(_parser.parse(jbossWeb.getInputStream()).getDocumentElement()); - } - catch (FileNotFoundException e) - { - _log.debug("no jboss-web.xml found"); - } - catch (IOException e) - { - _log.debug("no jboss-web.xml found"); - } - catch (Exception e) - { - _log.error("problem locating jboss-web.xml", e); - } - - try - { _log.debug("setting up ENC..."); _descriptorParser.parseWebAppDescriptors(_webApp.getClassLoader(), - _webApp.getWebApp(), - _webApp.getJbossWeb()); + _webApp.getMetaData()); _log.debug("setting up ENC succeeded"); } catch (Exception e) 1.9.2.10 +253 -54 contrib/jetty/src/main/org/jboss/jetty/Jetty.java Index: Jetty.java =================================================================== RCS file: /cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/Jetty.java,v retrieving revision 1.9.2.9 retrieving revision 1.9.2.10 diff -u -r1.9.2.9 -r1.9.2.10 --- Jetty.java 20 Mar 2002 20:58:31 -0000 1.9.2.9 +++ Jetty.java 4 Apr 2002 18:25:12 -0000 1.9.2.10 @@ -5,7 +5,7 @@ * See terms of license at gnu.org. */ -// $Id: Jetty.java,v 1.9.2.9 2002/03/20 20:58:31 jules_gosnell Exp $ +// $Id: Jetty.java,v 1.9.2.10 2002/04/04 18:25:12 starksm Exp $ // A Jetty HttpServer with the interface expected by JBoss' // J2EEDeployer... @@ -16,28 +16,53 @@ //------------------------------------------------------------------------------ - -import java.io.FileNotFoundException; +import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.net.URL; import java.util.Hashtable; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; import org.jboss.deployment.DeploymentException; +import org.jboss.jetty.xml.JettyResolver; import org.jboss.logging.Logger; import org.jboss.security.SecurityAssociation; import org.jboss.web.AbstractWebContainer.WebDescriptorParser; import org.jboss.web.WebApplication; -import org.mortbay.http.HandlerContext; +import org.mortbay.http.HttpContext; import org.mortbay.http.HttpException; -import org.mortbay.http.HttpHandler; import org.mortbay.http.HttpRequest; import org.mortbay.http.HttpResponse; import org.mortbay.jetty.servlet.WebApplicationContext; import org.mortbay.util.MultiException; -import org.mortbay.util.Resource; +import org.mortbay.xml.XmlConfiguration; +import org.w3c.dom.Element; //------------------------------------------------------------------------------ +/** + * <description> + * + * @author <a href="mailto:[EMAIL PROTECTED]">Julian Gosnell</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Andreas Schaefer</a>. + * @version $Revision: 1.9.2.10 $ + * + * <p><b>Revisions:</b> + * + * <p><b>20011201 andreas:</b> + * <ul> + * <li>Fixed fixURL() because it is to "Unix" centric. Right now the + * method looks for the last part of the JAR URL (file:/...) which + * should be the JAR file name and add a "/." before them. Now this + * should work for Windows as well (the problem with windows was that + * after "file:" came the DRIVE LETTER which created a wrong URL). + * </ul> + **/ public class Jetty extends org.mortbay.jetty.Server { @@ -47,6 +72,12 @@ Logger _log = Logger.getLogger(Jetty.class); JettyService _service; + // the XML snippet + String _xmlConfigString = null; + + // the XML snippet as a DOM element + Element _configElement = null; + Jetty(JettyService service) { super(); @@ -57,13 +88,18 @@ JettyResolver resolver = new JettyResolver(); // populate dtd resolver - URL stdWeb22=findResourceInJar("org/mortbay/jetty/servlet/web.dtd"); + URL stdWeb22=findResourceInJar("javax/servlet/resources/web-app_2_2.dtd"); resolver.put("-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN", stdWeb22); + URL stdWeb23=findResourceInJar("javax/servlet/resources/web-app_2_3.dtd"); + resolver.put("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN", stdWeb23); URL jbossWeb2=findResourceInJar("org/jboss/metadata/jboss-web.dtd"); resolver.put("-//jBoss//DTD Web Application 2.2//EN", jbossWeb2); resolver.put("-//JBoss//DTD Web Application 2.2//EN", jbossWeb2); + URL jbossWeb3=findResourceInJar("org/jboss/metadata/jboss-web_3_0.dtd"); + resolver.put("-//JBoss//DTD Web Application 2.3//EN", jbossWeb3); + try { _parser=_factory.newDocumentBuilder(); @@ -81,23 +117,6 @@ } //---------------------------------------- - // jettyHome property - //---------------------------------------- - - synchronized void - setJettyHome(String jettyHome) // not public - { - if (jettyHome!=null) - System.setProperty("jetty.home", jettyHome); - } - - public synchronized String - getJettyHome() - { - return System.getProperty("jetty.home"); - } - - //---------------------------------------- // class loader delegation policy property //---------------------------------------- boolean _loaderCompliance = true; @@ -146,10 +165,33 @@ String _webDefault; + /** If a webdefault.xml file has been specified in + * jboss-service.xml then we try and use that. + * + * If we cannot find it, then we will use the one + * shipped as standard with Jetty and issue a warning. + * + * If the jboss-service.xml file does not specify a + * custom one, then we again default to the standard one. + * @param webDefault + */ public synchronized void setWebDefault(String webDefault) { - _webDefault=webDefault; + if (webDefault != null) + { + URL webDefaultURL = findResourceInJar(webDefault); + if (webDefaultURL != null) + _webDefault=fixURL(webDefaultURL.toString()); + else + _webDefault = null; + _log.warn ("Cannot find resource for "+webDefault+": using default"); + } + else + _webDefault = null; + + if (_log.isDebugEnabled()) + _log.debug ("webdefault specification is: "+_webDefault); } public synchronized String @@ -159,34 +201,162 @@ } //---------------------------------------- - // configuration property + // distributedStore property + //---------------------------------------- + + String _storageStrategy; + + public synchronized void + setHttpSessionStorageStrategy(String storageStrategy) + { + _storageStrategy=storageStrategy; + } + + public synchronized String + getHttpSessionStorageStrategy() + { + return _storageStrategy; + } + + //---------------------------------------- + // snapshotFrequency property //---------------------------------------- - String _configuration=null; + String _snapshotFrequency; public synchronized void - setConfiguration(String configUrl) + setHttpSessionSnapshotFrequency(String snapshotFrequency) + { + _snapshotFrequency=snapshotFrequency; + } + + public synchronized String + getHttpSessionSnapshotFrequency() { - if (configUrl==null) - return; + return _snapshotFrequency; + } + + //---------------------------------------- + // snapshotNotificationPolicy property + //---------------------------------------- + + String _snapshotNotificationPolicy; + + public synchronized void + setHttpSessionSnapshotNotificationPolicy(String snapshotNotificationPolicy) + { + _snapshotNotificationPolicy=snapshotNotificationPolicy; + } + + public synchronized String + getHttpSessionSnapshotNotificationPolicy() + { + return _snapshotNotificationPolicy; + } + + //---------------------------------------- + // subjectAttributeName property + //---------------------------------------- + + String _subjectAttributeName; + + public synchronized void + setSubjectAttributeName(String subjectAttributeName) + { + _subjectAttributeName=subjectAttributeName; + } + + public synchronized String + getSubjectAttributeName() + { + return _subjectAttributeName; + } + + //---------------------------------------- + // configuration property + //---------------------------------------- + + public Element + getConfigurationElement() + { + return _configElement; + } + + /** + * @param configElement XML fragment from jboss-service.xml + */ + public void + setConfigurationElement(Element configElement) + { + + // convert to an xml string to pass into Jetty's normal + // configuration mechanism + _configElement = configElement; try { - _log.info("loading config: "+configUrl); - configure(configUrl); - _log.info("loaded config: "+configUrl); - _configuration=configUrl; + DOMSource source = new DOMSource(configElement); + + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + + StreamResult result = new StreamResult (stream); + + TransformerFactory factory = TransformerFactory.newInstance(); + Transformer transformer = factory.newTransformer(); + transformer.transform (source, result); + + _xmlConfigString = stream.toString(); + + // get rid of the first line, as this will be prepended by + // the XmlConfiguration + int index = _xmlConfigString.indexOf("?>"); + if ( index >= 0) + { + index += 2; + + while ((_xmlConfigString.charAt(index) == '\n') + || + (_xmlConfigString.charAt(index) == '\r')) + index++; + } + + _xmlConfigString = _xmlConfigString.substring(index); + + _log.debug ("Passing xml config to jetty:\n"+_xmlConfigString); + + setXMLConfiguration (_xmlConfigString); + + } + catch (TransformerConfigurationException tce) + { + _log.error ("Can't transform config Element -> xml:", tce); + } + catch (TransformerException te) + { + _log.error ("Can't transform config Element -> xml:", te); } catch (Exception e) { - _log.error("problem loading configuration: "+configUrl, e); + _log.error("Unexpected exception converting configuration Element -> xml", e); } } - public synchronized String - getConfiguration() + /* Actually perform the configuration + * @param xmlString + */ + private void + setXMLConfiguration(String xmlString) { - return _configuration; + + try + { + XmlConfiguration xmlConfigurator = new XmlConfiguration (xmlString); + xmlConfigurator.configure(this); + } + catch (Exception e) + { + _log.error("problem configuring Jetty:", e); + } } //---------------------------------------------------------------------------- @@ -195,11 +365,11 @@ Hashtable _deployed = new Hashtable(); // use Hashtable because is is synchronised - public WebApplication - deploy(String contextPath, String warUrl, WebDescriptorParser descriptorParser) + public void + deploy(WebApplication wa, String warUrl, WebDescriptorParser descriptorParser) throws DeploymentException { - WebApplication wa=new WebApplication(); + String contextPath = wa.getMetaData().getContextRoot(); try { @@ -211,15 +381,14 @@ _log.warn("A WebApplication is already deployed in context '"+contextPath+"' - proceed at your own risk."); String fixedWarUrl=warUrl+(warUrl.endsWith("/")?"":"/"); - // String fixedWarUrl=warUrl; // deploy the WebApp WebApplicationContext app= new JBossWebApplicationContext(this, contextPath, - descriptorParser, wa, _parser/*, - fixedWarUrl*/); + descriptorParser, wa, _parser, + fixedWarUrl); + - /* // configure whether the context is to flatten the classes in // the WAR or not app.setExtractWAR (getUnpackWars()); @@ -227,8 +396,8 @@ // if a different webdefaults.xml file has been provided, use it if (getWebDefault() != null) - app.setDefaultsDescriptor (getWebDefault()); - */ + app.setDefaultsDescriptor (getWebDefault()); + String virtualHost=null; addContext(virtualHost, app); @@ -236,7 +405,6 @@ try { // finally start the app - app.initialize(fixedWarUrl, getWebDefault(), getUnpackWars()); app.start(); } catch (MultiException me) @@ -259,7 +427,6 @@ throw new DeploymentException(e.getMessage()); } - return wa; } public void @@ -274,7 +441,8 @@ app.stop(); removeContext(app); - app.destroy(); + // app.destroy(); + app=null; _deployed.remove(warUrl); @@ -314,6 +482,36 @@ return url; } + // work around broken JarURLConnection caching... + static String + fixURL(String url) + { + // Get the separator of the JAR URL and the file reference + int index = url.indexOf( '!' ); + if( index >= 0 ) { + index = url.lastIndexOf( '/', index ); + } else { + index = url.lastIndexOf( '/' ); + } + // Now add a "./" before the JAR file to add a different path + if( index >= 0 ) { + return + url.substring( 0, index ) + + "/." + + url.substring( index ); + } else { + // Now forward slash found then there is severe problem with + // the URL but here we just ignore it + return url; + } + } + + public String[] + getCompileClasspath(ClassLoader cl) + { + return _service.getCompileClasspath(cl); + } + /** Override service method to allow ditching of security info * after a request has been processed * @param request @@ -322,9 +520,9 @@ * @exception IOException * @exception HttpException */ - public org.mortbay.http.HandlerContext - service(HttpRequest request, HttpResponse response) - throws HttpException, java.io.IOException + public HttpContext + service(HttpRequest request,HttpResponse response) + throws IOException, HttpException { try { @@ -332,7 +530,8 @@ } finally { - SecurityAssociation.setPrincipal(null); + SecurityAssociation.setPrincipal(null); + SecurityAssociation.setCredential(null); } } } 1.2.2.3 +10 -10 contrib/jetty/src/main/org/jboss/jetty/JettyMBean.java Index: JettyMBean.java =================================================================== RCS file: /cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/JettyMBean.java,v retrieving revision 1.2.2.2 retrieving revision 1.2.2.3 diff -u -r1.2.2.2 -r1.2.2.3 --- JettyMBean.java 17 Sep 2001 23:10:57 -0000 1.2.2.2 +++ JettyMBean.java 4 Apr 2002 18:25:12 -0000 1.2.2.3 @@ -13,21 +13,21 @@ import javax.management.MBeanException; import javax.management.MBeanServer; import javax.management.ObjectName; -import org.mortbay.jetty.jmx.HttpServerMBean; +import org.mortbay.jetty.jmx.ServerMBean; public class JettyMBean - extends HttpServerMBean + extends ServerMBean { - public JettyMBean(Jetty jetty) - throws MBeanException, InstanceNotFoundException + public static final String JBOSS_DOMAIN = "jboss.web"; + + static { - super(jetty); + setDefaultDomain (JBOSS_DOMAIN); } - protected String - newObjectName(MBeanServer server) + public JettyMBean(Jetty jetty) + throws MBeanException, InstanceNotFoundException { - //return super.newObjectName(server); - return uniqueObjectName(server, "Jetty"+":"); + super(jetty); } } 1.15.2.5 +408 -410 contrib/jetty/src/main/org/jboss/jetty/JettyService.java Index: JettyService.java =================================================================== RCS file: /cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/JettyService.java,v retrieving revision 1.15.2.4 retrieving revision 1.15.2.5 diff -u -r1.15.2.4 -r1.15.2.5 --- JettyService.java 20 Mar 2002 20:58:31 -0000 1.15.2.4 +++ JettyService.java 4 Apr 2002 18:25:12 -0000 1.15.2.5 @@ -1,410 +1,408 @@ -/* - * jBoss, the OpenSource EJB server - * - * Distributable under GPL license. - * See terms of license at gnu.org. - */ - -// $Id: JettyService.java,v 1.15.2.4 2002/03/20 20:58:31 jules_gosnell Exp $ - -//------------------------------------------------------------------------------ - -package org.jboss.jetty; - -//------------------------------------------------------------------------------ - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Hashtable; -import java.util.Vector; -import javax.management.MBeanRegistration; -import javax.management.MBeanServer; -import javax.management.ObjectName; -import org.jboss.deployment.DeploymentException; -import org.jboss.util.ServiceMBeanSupport; -import org.jboss.web.AbstractWebContainer.WebDescriptorParser; -import org.jboss.web.AbstractWebContainer; -import org.jboss.web.WebApplication; -import org.mortbay.http.HandlerContext; -import org.mortbay.http.HttpServer; -import org.mortbay.jetty.jmx.HttpServerMBean; -import org.mortbay.jetty.servlet.WebApplicationContext; -import org.mortbay.util.Log; -import org.mortbay.xml.XmlConfiguration; - -//------------------------------------------------------------------------------ -/** - * A service to launch jetty from JMX. - * - * @see <related> - * @author <a href="mailto:[EMAIL PROTECTED]">Julian Gosnell</a> - * @version $Revision: 1.15.2.4 $ - */ - -public class JettyService - extends AbstractWebContainer - implements JettyServiceMBean, MBeanRegistration -{ - public static final String NAME = "Jetty"; - - JettyMBean _mbean = null; - Jetty _jetty = null; - MBeanServer _server = null; - - public - JettyService() - { - // moved this from initialise-time to construct-time to ensure - // that logging models are connected before configure-time (via - // MLET file) which is done before initialise-time. - ensureLogging(); - } - - //---------------------------------------------------------------------------- - - public ObjectName - preRegister(MBeanServer server, ObjectName name) - throws java.lang.Exception - { - name = getObjectName(server, name); - _server = server; - - return name; - } - - //---------------------------------------------------------------------------- - - protected void - ensureLogging() - { - // sort out a JBossLogSink for use by Jetty. This will bridge the - // API between Jetty and Log4J... - - JBossLogSink logSink = new JBossLogSink(); - try - { - logSink.initialize(log.getCategory()); - } - catch(Exception e) - { - log.error("Could not initialise logging bridge", e); - } - - logSink.start(); - Log.instance().disableLog(); // remove default logger - Log.instance().add(logSink); - - // why doesn't this work? - investigate... - // _jetty.setLogSink(logSink); - - log.info("connected JBoss and Jetty Log models"); - } - - protected void - ensureProperties() - throws IOException - { - String props="jetty.properties"; - InputStream propertiesIn = getClass().getClassLoader().getResourceAsStream(props); - - if (propertiesIn == null) - throw new IOException("failed to load "+props); - - System.getProperties().load(propertiesIn); - - log.info("loaded properties from: "+props); - } - - protected void - ensureJetty() - { - // make a Jetty... - Jetty tmp = new Jetty(this); // tmp - until we have initialised it... - tmp.setJettyHome(getJettyHome()); - tmp.setWebDefault(getWebDefault()); - tmp.setUnpackWars(getUnpackWars()); - - _jetty=tmp; // now we are initialised. - - log.info("instantiated and configured server"); - } - - protected void - ensureConfig() - { - // this must be done before config is read otherwise configs - // defined therein will not receive MBean peers. - if (getPublishMBeans()) - { - try - { - log.info("MBean peers WILL be created for Jetty Contexts"); - _mbean = new JettyMBean(_jetty); - _server.registerMBean(_mbean, new ObjectName(_mbean.newObjectName(_server))); - } - catch (Throwable e) - { - log.error("JMX Registration problem", e); - } - } - else - { - log.info("MBean peers WILL NOT be created for Jetty Contexts"); - } - - _jetty.setConfiguration(_configuration); - } - - protected void - ensureService() - throws Exception - { - ensureProperties(); - ensureJetty(); - ensureConfig(); - } - - //---------------------------------------------------------------------------- - // 'name' interface - //---------------------------------------------------------------------------- - - public ObjectName - getObjectName(MBeanServer server, ObjectName name) - throws javax.management.MalformedObjectNameException - { - return new ObjectName(OBJECT_NAME); - } - - public String - getName() - { - return NAME; - } - - //---------------------------------------------------------------------------- - // 'service' interface - //---------------------------------------------------------------------------- - - public void - initService() - throws Exception - { - if (!isInitialised()) - { - super.initService(); - try {ensureService();} catch (Exception e) {e.printStackTrace();} - } - else - log.warn("Jetty has already been initialised"); - } - - protected boolean _started=false; - - public void - startService() - throws Exception - { - if (!isStarted()) - { - super.startService(); - _jetty.start(); - _started=true; - } - else - log.warn("Jetty has already been started"); - } - - public void - stopService() - { - if (!isStopped()) - { - super.stopService(); - try - { - _jetty.stop(); - } - catch (Exception e) - { - log.error("Could not stop Jetty", e); - } - _started=false; - } - else - log.warn("Jetty has already been stopped"); - } - - public void - destroyService() - { - if (!isDestroyed()) - { - super.destroyService(); - _jetty.destroy(); - _jetty=null; - _mbean=null; - } - else - log.warn("Jetty has already been destroyed"); - } - - //---------------------------------------------------------------------------- - // 'deploy' interface - //---------------------------------------------------------------------------- - - public WebApplication - performDeploy(String path, String warUrl, WebDescriptorParser parser) - throws DeploymentException - { - return _jetty.deploy(path, warUrl, parser); - } - - public void - performUndeploy(String warUrl) - throws DeploymentException - { - _jetty.undeploy(warUrl); - } - - //---------------------------------------------------------------------------- - - protected boolean - isInitialised() - { - return (_jetty!=null); - } - - protected boolean - isStarted() - { - return (_jetty!=null && _started); - } - - protected boolean - isStopped() - { - return (!_started); - } - - protected boolean - isDestroyed() - { - return (_jetty==null); - } - - //---------------------------------------------------------------------------- - - protected boolean _publishMBeans=false; - - public boolean - getPublishMBeans() - { - return _publishMBeans; - } - - public void - setPublishMBeans(boolean publishMBeans) - { - log.info("set PublishMBeans to "+publishMBeans); - - _publishMBeans=publishMBeans; - } - - //---------------------------------------------------------------------------- - - protected boolean _unpackWars=false; - - public boolean - getUnpackWars() - { - if (isInitialised()) - return _jetty.getUnpackWars(); - else - return _unpackWars; - } - - public void - setUnpackWars(boolean unpackWars) - { - log.info("set UnpackWars to "+unpackWars); - - if (isInitialised()) - _jetty.setUnpackWars(unpackWars); - else - _unpackWars=unpackWars; - } - - //---------------------------------------------------------------------------- - - protected String _webDefault=null; - - public String - getWebDefault() - { - if (isInitialised()) - return _jetty.getWebDefault(); - else - return _webDefault; - } - - public void - setWebDefault(String webDefault) - { - log.info("set WebDefault to "+webDefault); - - if (isInitialised()) - _jetty.setWebDefault(webDefault); - else - _webDefault=webDefault; - } - - //---------------------------------------------------------------------------- - - protected String _configuration=null; - - public String - getConfiguration() - { - if (isInitialised()) - return _jetty.getConfiguration(); - else - return _configuration; - } - - public void - setConfiguration(String configUrl) - { - log.info("set Configuration to "+configUrl); - - if (isInitialised()) - _jetty.setConfiguration(configUrl); - else - _configuration=configUrl; - } - - //---------------------------------------------------------------------------- - - protected static String _jettyHome=null; - - public String - getJettyHome() - { - if (isInitialised()) - return _jetty.getJettyHome(); - else - return _jettyHome; - } - - public void - setJettyHome(String jettyHome) - { - log.info("set JettyHome to "+jettyHome); - - if (isInitialised()) - _jetty.setJettyHome(jettyHome); - else - _jettyHome=jettyHome; - } -} +/* + * jBoss, the OpenSource EJB server + * + * Distributable under GPL license. + * See terms of license at gnu.org. + */ + +// $Id: JettyService.java,v 1.15.2.5 2002/04/04 18:25:12 starksm Exp $ + +//------------------------------------------------------------------------------ + +package org.jboss.jetty; + +//------------------------------------------------------------------------------ + +import java.util.Iterator; +import javax.management.MBeanRegistration; +import javax.management.MBeanServer; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; +import org.jboss.deployment.DeploymentException; +import org.jboss.jetty.log.JBossLogSink; +import org.jboss.logging.Logger; +import org.jboss.web.AbstractWebContainer.WebDescriptorParser; +import org.jboss.web.AbstractWebContainer; +import org.jboss.web.WebApplication; +import org.mortbay.util.Log; +import org.mortbay.util.MultiException; +import org.mortbay.util.jmx.CodeMBean; +import org.mortbay.util.jmx.LogMBean; +import org.w3c.dom.Element; + +//------------------------------------------------------------------------------ +/** + * A service to launch jetty from JMX. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Julian Gosnell</a> + * @version $Revision: 1.15.2.5 $ + */ + +public class JettyService + extends AbstractWebContainer + implements JettyServiceMBean, MBeanRegistration +{ + public static final String NAME = "Jetty"; + + // delegate to Jetty + protected MBeanServer _server = null; + protected Jetty _jetty = null; + protected JettyMBean _jettyBean = null; + protected ObjectName _codeBeanName = null; + protected CodeMBean _codeBean = null; + protected ObjectName _logBeanName = null; + protected LogMBean _logbean = null; + + public + JettyService() + { + super(); + + // sort out a JBossLogSink for use by Jetty. This will bridge the + // API between Jetty and Log4J... + JBossLogSink logSink = new JBossLogSink(); + try + { + logSink.initialize(Logger.getLogger(Jetty.class.getName())); + } + catch(Exception e) + { + log.error("could not connect JBoss and Jetty Log models", e); + } + + logSink.start(); + Log.instance().disableLog(); // remove default logger + Log.instance().add(logSink); + + log.debug("connected JBoss and Jetty Log models"); + + _jetty = new Jetty(this); + } + + //---------------------------------------------------------------------------- + // utils... + //---------------------------------------------------------------------------- + + /** + * mex should implement a better printStackTrace... + */ + protected void + log(MultiException e) + { + log.error("multiple exceptions..."); + Iterator iter = e.getExceptions().iterator(); + while (iter.hasNext()) + log.error("exception", (Exception)iter.next()); + } + + //---------------------------------------------------------------------------- + + public ObjectName + preRegister(MBeanServer server, ObjectName name) + throws Exception + { + super.preRegister(server,name); + name = getObjectName(server, name); + _server = server; + + return name; + } + + public void + postRegister(Boolean done) + { + super.postRegister(done); + + // this must be done before config is read otherwise configs + // defined therein will not receive MBean peers. Since it must now + // be done before JMX has a chance to configure us, I'm removing + // the option not to have these MBeans built... + try + { + _jettyBean = new JettyMBean(_jetty); + _server.registerMBean(_jettyBean, null); + + _codeBean = new CodeMBean(); + _codeBeanName = new ObjectName(JettyMBean.JBOSS_DOMAIN+":Jetty=Debug"); + _server.registerMBean(_codeBean, _codeBeanName); + + _logbean = new LogMBean(); + _logBeanName = new ObjectName(JettyMBean.JBOSS_DOMAIN+":Jetty=Log"); + _server.registerMBean(_logbean, _logBeanName); + } + catch (Throwable e) + { + log.error("could not create MBean peers", e); + } + + log.debug("created MBean peers"); + } + + //---------------------------------------------------------------------------- + // 'name' interface + //---------------------------------------------------------------------------- + + public ObjectName + getObjectName(MBeanServer server, ObjectName name) + throws MalformedObjectNameException + { + return new ObjectName(OBJECT_NAME); + } + + public String + getName() + { + return NAME; + } + + //---------------------------------------------------------------------------- + // 'service' interface + //---------------------------------------------------------------------------- + + public void + initService() + throws Exception + { + super.initService(); + } + + public void + startService() + throws Exception + { + super.startService(); + + try + { + _jetty.start(); + } + catch (MultiException e) + { + log(e); + } + catch (Exception e) + { + log.error("could not start Jetty", e); + } + } + + public void + stopService() throws Exception + { + super.stopService(); + + try + { + _jetty.stop(); + } + catch (Exception e) + { + log.error("could not stop Jetty", e); + } + } + + public void + destroyService() + throws Exception + { + super.destroyService(); + + // this is not symmetrical - these things are created in + // postRegister, not createService()... + try + { + _jetty.destroy(); + _jetty =null; + _jettyBean=null; + } + catch (Throwable e) + { + log.error("could not destroy Jetty", e); + } + + try + { + _server.unregisterMBean(_codeBeanName); + _codeBean=null; + _server.unregisterMBean(_logBeanName); + _logbean=null; + } + catch(Exception e) + { + log.error("could not tidy up MBeans", e); + } + } + + //---------------------------------------------------------------------------- + // 'deploy' interface + //---------------------------------------------------------------------------- + + protected void performDeploy(WebApplication webApp, String warUrl, + WebDescriptorParser parser) throws DeploymentException + { + _jetty.deploy(webApp, warUrl, parser); + } + + public void + performUndeploy(String warUrl) + throws DeploymentException + { + _jetty.undeploy(warUrl); + } + + //---------------------------------------------------------------------------- + // Jetty properties - delegated directly... + //---------------------------------------------------------------------------- + + //---------------------------------------- + // class loader delegation policy property + //---------------------------------------- + + /** + * @param loaderCompliance if true, Jetty delegates class loading + *to parent class loader first, false implies servlet spec 2.3 compliance + */ + public void + setJava2ClassLoadingCompliance(boolean loaderCompliance) + { + if (log.isDebugEnabled()) + log.debug("set Java2ClassLoadingCompliance to "+ loaderCompliance); + + _jetty.setJava2ClassLoadingCompliance(loaderCompliance); + } + + /** + * @return true if Java2 style class loading delegation, false if + *servlet2.3 spec compliance + */ + public boolean + getJava2ClassLoadingCompliance() + { + return _jetty.getJava2ClassLoadingCompliance(); + } + + //---------------------------------------------------------------------------- + + public boolean + getUnpackWars() + { + return _jetty.getUnpackWars(); + } + + public void + setUnpackWars(boolean unpackWars) + { + if (log.isDebugEnabled()) + log.debug("set UnpackWars to "+unpackWars); + + _jetty.setUnpackWars(unpackWars); + } + + //---------------------------------------------------------------------------- + + public String + getWebDefault() + { + return _jetty.getWebDefault(); + } + + public void + setWebDefault(String webDefault) + { + if (log.isDebugEnabled()) + log.debug("set WebDefault to "+webDefault); + + _jetty.setWebDefault(webDefault); + } + + //---------------------------------------------------------------------------- + + public String + getHttpSessionStorageStrategy() + { + return _jetty.getHttpSessionStorageStrategy(); + } + + public void + setHttpSessionStorageStrategy(String storageStrategy) + { + if (log.isDebugEnabled()) + log.debug("set HttpSessionStorageStrategy to "+storageStrategy); + + _jetty.setHttpSessionStorageStrategy(storageStrategy); + } + + //---------------------------------------------------------------------------- + + public String + getHttpSessionSnapshotFrequency() + { + return _jetty.getHttpSessionSnapshotFrequency(); + } + + public void + setHttpSessionSnapshotFrequency(String snapshotFrequency) + { + if (log.isDebugEnabled()) + log.debug("set HttpSessionSnapshotFrequency to "+snapshotFrequency); + + _jetty.setHttpSessionSnapshotFrequency(snapshotFrequency); + } + + //---------------------------------------------------------------------------- + + public String + getHttpSessionSnapshotNotificationPolicy() + { + return _jetty.getHttpSessionSnapshotNotificationPolicy(); + } + + public void + setHttpSessionSnapshotNotificationPolicy(String snapshotNotificationPolicy) + { + if (log.isDebugEnabled()) + log.debug("set HttpSessionSnapshotNotificationPolicy to "+snapshotNotificationPolicy); + + _jetty.setHttpSessionSnapshotNotificationPolicy(snapshotNotificationPolicy); + } + + //---------------------------------------------------------------------------- + /** Get the extended Jetty configuration XML fragment + * @return Jetty XML fragment embedded in jboss-service.xml + */ + + public Element + getConfigurationElement() + { + return _jetty.getConfigurationElement(); + } + + /** Configure Jetty + * @param configElement XML fragment from jboss-service.xml + */ + public void + setConfigurationElement(Element configElement) + { + log.debug("set Configuration to xml fragment"); + _jetty.setConfigurationElement (configElement); + } + + //---------------------------------------------------------------------------- + + public String + getSubjectAttributeName() + { + return _jetty.getSubjectAttributeName(); + } + + public void + setSubjectAttributeName(String subjectAttributeName) + { + if (log.isDebugEnabled()) + log.debug("set SubjectAttributeName to "+subjectAttributeName); + + _jetty.setSubjectAttributeName(subjectAttributeName); + } + + //---------------------------------------------------------------------------- +} 1.5.2.3 +48 -47 contrib/jetty/src/main/org/jboss/jetty/JettyServiceMBean.java Index: JettyServiceMBean.java =================================================================== RCS file: /cvsroot/jboss/contrib/jetty/src/main/org/jboss/jetty/JettyServiceMBean.java,v retrieving revision 1.5.2.2 retrieving revision 1.5.2.3 diff -u -r1.5.2.2 -r1.5.2.3 --- JettyServiceMBean.java 2 Dec 2001 02:08:53 -0000 1.5.2.2 +++ JettyServiceMBean.java 4 Apr 2002 18:25:12 -0000 1.5.2.3 @@ -1,47 +1,48 @@ -/* - * jBoss, the OpenSource EJB server - * - * Distributable under GPL license. - * See terms of license at gnu.org. - */ - -// $Id: JettyServiceMBean.java,v 1.5.2.2 2001/12/02 02:08:53 starksm Exp $ - -package org.jboss.jetty; - -import org.jboss.deployment.DeploymentException; - -/** - * <description> - * - * @see <related> - * @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Alborini</a> - * @version $Revision: 1.5.2.2 $ - */ -public interface JettyServiceMBean - extends org.jboss.web.AbstractWebContainerMBean -{ - - // Constants ----------------------------------------------------- - public static final String OBJECT_NAME = ":service=Jetty"; - - // Public -------------------------------------------------------- - - public void setConfiguration(String configUrl); - public String getConfiguration(); - - // public void setProperty(String property); - // public String getProperty(); - - public boolean getPublishMBeans(); - public void setPublishMBeans(boolean publishMBeans); - - public boolean getUnpackWars(); - public void setUnpackWars(boolean unpackWars); - - public String getWebDefault(); - public void setWebDefault(String webDefault); - - public void setJettyHome(String jettyHome); - public String getJettyHome(); -} +/* + * jBoss, the OpenSource EJB server + * + * Distributable under GPL license. + * See terms of license at gnu.org. + */ + +package org.jboss.jetty; + +import javax.management.ObjectName; +import org.jboss.deployment.DeploymentException; +import org.w3c.dom.Element; + +/** + * ??? + * + * @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Alborini</a> + * @version $Revision: 1.5.2.3 $ + */ +public interface JettyServiceMBean + extends org.jboss.web.AbstractWebContainerMBean +{ + String OBJECT_NAME = "jboss.web:service=Jetty"; + + public void setConfigurationElement (Element configElement); + public Element getConfigurationElement (); + + public boolean getUnpackWars(); + public void setUnpackWars(boolean unpackWars); + + public String getWebDefault(); + public void setWebDefault(String webDefault); + + public String getHttpSessionStorageStrategy(); + public void setHttpSessionStorageStrategy(String storageStrategy); + + public String getHttpSessionSnapshotFrequency(); + public void setHttpSessionSnapshotFrequency(String snapshotFrequency); + + public String getHttpSessionSnapshotNotificationPolicy(); + public void setHttpSessionSnapshotNotificationPolicy(String snapshotNotificationPolicy); + + public String getSubjectAttributeName(); + public void setSubjectAttributeName(String subjectAttributeName); + + public boolean getJava2ClassLoadingCompliance (); + public void setJava2ClassLoadingCompliance(boolean compliance); +}
_______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development