diff options
author | Greg Wilkins | 2014-07-16 05:31:48 +0000 |
---|---|---|
committer | Greg Wilkins | 2014-07-16 05:31:48 +0000 |
commit | 853e020210d1e638c67d93bc636c0ba036986407 (patch) | |
tree | fe1cbd6e4269ab0253f46ccc35cd59731680aeb8 /jetty-quickstart | |
parent | 4d2a580c2c8ca054841697a9d8848bdceb1c97f9 (diff) | |
parent | dd5cdab54cdd6787ab25775291ff5c56716b1415 (diff) | |
download | org.eclipse.jetty.project-853e020210d1e638c67d93bc636c0ba036986407.tar.gz org.eclipse.jetty.project-853e020210d1e638c67d93bc636c0ba036986407.tar.xz org.eclipse.jetty.project-853e020210d1e638c67d93bc636c0ba036986407.zip |
Merge remote-tracking branch 'origin/master' into jetty-http2
Diffstat (limited to 'jetty-quickstart')
2 files changed, 327 insertions, 327 deletions
diff --git a/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartDescriptorGenerator.java b/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartDescriptorGenerator.java index a138ae6e57..5a56625fb0 100644 --- a/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartDescriptorGenerator.java +++ b/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartDescriptorGenerator.java @@ -23,6 +23,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.util.Collection; import java.util.Collections; import java.util.EventListener; @@ -75,21 +76,21 @@ import org.eclipse.jetty.xml.XmlAppendable; public class QuickStartDescriptorGenerator { private static final Logger LOG = Log.getLogger(QuickStartDescriptorGenerator.class); + + public static final String DEFAULT_QUICKSTART_DESCRIPTOR_NAME = "quickstart-web.xml"; + protected WebAppContext _webApp; - protected File _descriptorDir; protected String _extraXML; /** * @param w the source WebAppContext - * @param descriptorDir the directory where quickstart-web.xml should be saved * @param extraXML any extra xml snippet to append */ - public QuickStartDescriptorGenerator (WebAppContext w, File descriptorDir, String extraXML) + public QuickStartDescriptorGenerator (WebAppContext w, String extraXML) { _webApp = w; - _descriptorDir = descriptorDir; _extraXML = extraXML; } @@ -100,424 +101,406 @@ public class QuickStartDescriptorGenerator * @throws FileNotFoundException * @throws Exception */ - public File generateQuickStartWebXml () throws FileNotFoundException, IOException + public void generateQuickStartWebXml (OutputStream stream) throws FileNotFoundException, IOException { if (_webApp == null) - throw new IllegalStateException("No webapp for quickstart-web.xml"); - if (_descriptorDir == null) - throw new IllegalStateException("No location for quickstart-web.xml"); + throw new IllegalStateException("No webapp for quickstart generation"); + if (stream == null) + throw new IllegalStateException("No output for quickstart generation"); _webApp.getMetaData().getOrigins(); if (_webApp.getBaseResource()==null) throw new IllegalArgumentException("No base resource for "+this); - if (!_descriptorDir.exists()) - _descriptorDir.mkdirs(); - - File webXml = new File(_descriptorDir,"quickstart-web.xml"); - - LOG.info("Quickstart generate {}",webXml); - - try (FileOutputStream fos = new FileOutputStream(webXml)) - { - XmlAppendable out = new XmlAppendable(fos,"UTF-8"); + LOG.info("Quickstart generating"); - MetaData md = _webApp.getMetaData(); + XmlAppendable out = new XmlAppendable(stream,"UTF-8"); - Map<String, String> webappAttr = new HashMap<>(); - webappAttr.put("xmlns","http://xmlns.jcp.org/xml/ns/javaee"); - webappAttr.put("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance"); - webappAttr.put("xsi:schemaLocation","http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"); - webappAttr.put("metadata-complete","true"); - webappAttr.put("version","3.1"); + MetaData md = _webApp.getMetaData(); - out.openTag("web-app",webappAttr); - if (_webApp.getDisplayName() != null) - out.tag("display-name",_webApp.getDisplayName()); + Map<String, String> webappAttr = new HashMap<>(); + webappAttr.put("xmlns","http://xmlns.jcp.org/xml/ns/javaee"); + webappAttr.put("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance"); + webappAttr.put("xsi:schemaLocation","http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"); + webappAttr.put("metadata-complete","true"); + webappAttr.put("version","3.1"); - // Set some special context parameters + out.openTag("web-app",webappAttr); + if (_webApp.getDisplayName() != null) + out.tag("display-name",_webApp.getDisplayName()); - // The location of the war file on disk - String resourceBase = _webApp.getBaseResource().getFile().getCanonicalFile().getAbsoluteFile().toURI().toString(); + // Set some special context parameters - // The library order - addContextParamFromAttribute(out,ServletContext.ORDERED_LIBS); - //the servlet container initializers - addContextParamFromAttribute(out,AnnotationConfiguration.CONTAINER_INITIALIZERS); - //the tlds discovered - addContextParamFromAttribute(out,MetaInfConfiguration.METAINF_TLDS,resourceBase); - //the META-INF/resources discovered - addContextParamFromAttribute(out,MetaInfConfiguration.METAINF_RESOURCES,resourceBase); + // The location of the war file on disk + String resourceBase = _webApp.getBaseResource().getFile().getCanonicalFile().getAbsoluteFile().toURI().toString(); + // The library order + addContextParamFromAttribute(out,ServletContext.ORDERED_LIBS); + //the servlet container initializers + addContextParamFromAttribute(out,AnnotationConfiguration.CONTAINER_INITIALIZERS); + //the tlds discovered + addContextParamFromAttribute(out,MetaInfConfiguration.METAINF_TLDS,resourceBase); + //the META-INF/resources discovered + addContextParamFromAttribute(out,MetaInfConfiguration.METAINF_RESOURCES,resourceBase); - // init params - for (String p : _webApp.getInitParams().keySet()) - out.openTag("context-param",origin(md,"context-param." + p)) - .tag("param-name",p) - .tag("param-value",_webApp.getInitParameter(p)) - .closeTag(); - if (_webApp.getEventListeners() != null) - for (EventListener e : _webApp.getEventListeners()) - out.openTag("listener",origin(md,e.getClass().getCanonicalName() + ".listener")) - .tag("listener-class",e.getClass().getCanonicalName()) - .closeTag(); + // init params + for (String p : _webApp.getInitParams().keySet()) + out.openTag("context-param",origin(md,"context-param." + p)) + .tag("param-name",p) + .tag("param-value",_webApp.getInitParameter(p)) + .closeTag(); - ServletHandler servlets = _webApp.getServletHandler(); + if (_webApp.getEventListeners() != null) + for (EventListener e : _webApp.getEventListeners()) + out.openTag("listener",origin(md,e.getClass().getCanonicalName() + ".listener")) + .tag("listener-class",e.getClass().getCanonicalName()) + .closeTag(); - if (servlets.getFilters() != null) - { - for (FilterHolder holder : servlets.getFilters()) - outholder(out,md,"filter",holder); - } + ServletHandler servlets = _webApp.getServletHandler(); - if (servlets.getFilterMappings() != null) + if (servlets.getFilters() != null) + { + for (FilterHolder holder : servlets.getFilters()) + outholder(out,md,"filter",holder); + } + + if (servlets.getFilterMappings() != null) + { + for (FilterMapping mapping : servlets.getFilterMappings()) { - for (FilterMapping mapping : servlets.getFilterMappings()) + out.openTag("filter-mapping"); + out.tag("filter-name",mapping.getFilterName()); + if (mapping.getPathSpecs() != null) + for (String s : mapping.getPathSpecs()) + out.tag("url-pattern",s); + if (mapping.getServletNames() != null) + for (String n : mapping.getServletNames()) + out.tag("servlet-name",n); + + if (!mapping.isDefaultDispatches()) { - out.openTag("filter-mapping"); - out.tag("filter-name",mapping.getFilterName()); - if (mapping.getPathSpecs() != null) - for (String s : mapping.getPathSpecs()) - out.tag("url-pattern",s); - if (mapping.getServletNames() != null) - for (String n : mapping.getServletNames()) - out.tag("servlet-name",n); - - if (!mapping.isDefaultDispatches()) - { - if (mapping.appliesTo(DispatcherType.REQUEST)) - out.tag("dispatcher","REQUEST"); - if (mapping.appliesTo(DispatcherType.ASYNC)) - out.tag("dispatcher","ASYNC"); - if (mapping.appliesTo(DispatcherType.ERROR)) - out.tag("dispatcher","ERROR"); - if (mapping.appliesTo(DispatcherType.FORWARD)) - out.tag("dispatcher","FORWARD"); - if (mapping.appliesTo(DispatcherType.INCLUDE)) - out.tag("dispatcher","INCLUDE"); - } - out.closeTag(); + if (mapping.appliesTo(DispatcherType.REQUEST)) + out.tag("dispatcher","REQUEST"); + if (mapping.appliesTo(DispatcherType.ASYNC)) + out.tag("dispatcher","ASYNC"); + if (mapping.appliesTo(DispatcherType.ERROR)) + out.tag("dispatcher","ERROR"); + if (mapping.appliesTo(DispatcherType.FORWARD)) + out.tag("dispatcher","FORWARD"); + if (mapping.appliesTo(DispatcherType.INCLUDE)) + out.tag("dispatcher","INCLUDE"); } + out.closeTag(); } + } - if (servlets.getServlets() != null) - { - for (ServletHolder holder : servlets.getServlets()) - outholder(out,md,"servlet",holder); - } + if (servlets.getServlets() != null) + { + for (ServletHolder holder : servlets.getServlets()) + outholder(out,md,"servlet",holder); + } - if (servlets.getServletMappings() != null) + if (servlets.getServletMappings() != null) + { + for (ServletMapping mapping : servlets.getServletMappings()) { - for (ServletMapping mapping : servlets.getServletMappings()) - { - out.openTag("servlet-mapping",origin(md,mapping.getServletName() + ".servlet.mappings")); - out.tag("servlet-name",mapping.getServletName()); - if (mapping.getPathSpecs() != null) - for (String s : mapping.getPathSpecs()) - out.tag("url-pattern",s); - out.closeTag(); - } + out.openTag("servlet-mapping",origin(md,mapping.getServletName() + ".servlet.mappings")); + out.tag("servlet-name",mapping.getServletName()); + if (mapping.getPathSpecs() != null) + for (String s : mapping.getPathSpecs()) + out.tag("url-pattern",s); + out.closeTag(); } + } - // Security elements - SecurityHandler security =_webApp. getSecurityHandler(); + // Security elements + SecurityHandler security =_webApp. getSecurityHandler(); - if (security!=null && (security.getRealmName()!=null || security.getAuthMethod()!=null)) - { - out.openTag("login-config"); - if (security.getAuthMethod()!=null) - out.tag("auth-method",origin(md,"auth-method"),security.getAuthMethod()); - if (security.getRealmName()!=null) - out.tag("realm-name",origin(md,"realm-name"),security.getRealmName()); + if (security!=null && (security.getRealmName()!=null || security.getAuthMethod()!=null)) + { + out.openTag("login-config"); + if (security.getAuthMethod()!=null) + out.tag("auth-method",origin(md,"auth-method"),security.getAuthMethod()); + if (security.getRealmName()!=null) + out.tag("realm-name",origin(md,"realm-name"),security.getRealmName()); - if (Constraint.__FORM_AUTH.equalsIgnoreCase(security.getAuthMethod())) - { - out.openTag("form-login-config"); - out.tag("form-login-page",origin(md,"form-login-page"),security.getInitParameter(FormAuthenticator.__FORM_LOGIN_PAGE)); - out.tag("form-error-page",origin(md,"form-error-page"),security.getInitParameter(FormAuthenticator.__FORM_ERROR_PAGE)); - out.closeTag(); - } - + if (Constraint.__FORM_AUTH.equalsIgnoreCase(security.getAuthMethod())) + { + out.openTag("form-login-config"); + out.tag("form-login-page",origin(md,"form-login-page"),security.getInitParameter(FormAuthenticator.__FORM_LOGIN_PAGE)); + out.tag("form-error-page",origin(md,"form-error-page"),security.getInitParameter(FormAuthenticator.__FORM_ERROR_PAGE)); out.closeTag(); } - if (security instanceof ConstraintAware) + out.closeTag(); + } + + if (security instanceof ConstraintAware) + { + ConstraintAware ca = (ConstraintAware)security; + for (String r:ca.getRoles()) + out.openTag("security-role") + .tag("role-name",r) + .closeTag(); + + for (ConstraintMapping m : ca.getConstraintMappings()) { - ConstraintAware ca = (ConstraintAware)security; - for (String r:ca.getRoles()) - out.openTag("security-role") - .tag("role-name",r) - .closeTag(); + out.openTag("security-constraint"); - for (ConstraintMapping m : ca.getConstraintMappings()) + if (m.getConstraint().getAuthenticate()) { - out.openTag("security-constraint"); + out.openTag("auth-constraint"); + if (m.getConstraint().getRoles()!=null) + for (String r : m.getConstraint().getRoles()) + out.tag("role-name",r); - if (m.getConstraint().getAuthenticate()) - { - out.openTag("auth-constraint"); - if (m.getConstraint().getRoles()!=null) - for (String r : m.getConstraint().getRoles()) - out.tag("role-name",r); + out.closeTag(); + } - out.closeTag(); - } + switch (m.getConstraint().getDataConstraint()) + { + case Constraint.DC_NONE: + out.openTag("user-data-constraint").tag("transport-guarantee","NONE").closeTag(); + break; - switch (m.getConstraint().getDataConstraint()) - { - case Constraint.DC_NONE: - out.openTag("user-data-constraint").tag("transport-guarantee","NONE").closeTag(); - break; + case Constraint.DC_INTEGRAL: + out.openTag("user-data-constraint").tag("transport-guarantee","INTEGRAL").closeTag(); + break; - case Constraint.DC_INTEGRAL: - out.openTag("user-data-constraint").tag("transport-guarantee","INTEGRAL").closeTag(); - break; + case Constraint.DC_CONFIDENTIAL: + out.openTag("user-data-constraint").tag("transport-guarantee","CONFIDENTIAL").closeTag(); + break; - case Constraint.DC_CONFIDENTIAL: - out.openTag("user-data-constraint").tag("transport-guarantee","CONFIDENTIAL").closeTag(); - break; + default: + break; - default: - break; + } - } + out.openTag("web-resource-collection"); + { + if (m.getConstraint().getName()!=null) + out.tag("web-resource-name",m.getConstraint().getName()); + if (m.getPathSpec()!=null) + out.tag("url-pattern",origin(md,"constraint.url."+m.getPathSpec()),m.getPathSpec()); + if (m.getMethod()!=null) + out.tag("http-method",m.getMethod()); - out.openTag("web-resource-collection"); - { - if (m.getConstraint().getName()!=null) - out.tag("web-resource-name",m.getConstraint().getName()); - if (m.getPathSpec()!=null) - out.tag("url-pattern",origin(md,"constraint.url."+m.getPathSpec()),m.getPathSpec()); - if (m.getMethod()!=null) - out.tag("http-method",m.getMethod()); - - if (m.getMethodOmissions()!=null) - for (String o:m.getMethodOmissions()) - out.tag("http-method-omission",o); - - out.closeTag(); - } + if (m.getMethodOmissions()!=null) + for (String o:m.getMethodOmissions()) + out.tag("http-method-omission",o); out.closeTag(); - } + + out.closeTag(); + } + } - if (_webApp.getWelcomeFiles() != null) + if (_webApp.getWelcomeFiles() != null) + { + out.openTag("welcome-file-list"); + for (String welcomeFile:_webApp.getWelcomeFiles()) { - out.openTag("welcome-file-list"); - for (String welcomeFile:_webApp.getWelcomeFiles()) - { - out.tag("welcome-file", welcomeFile); - } - out.closeTag(); + out.tag("welcome-file", welcomeFile); } + out.closeTag(); + } - Map<String,String> localeEncodings = _webApp.getLocaleEncodings(); - if (localeEncodings != null && !localeEncodings.isEmpty()) + Map<String,String> localeEncodings = _webApp.getLocaleEncodings(); + if (localeEncodings != null && !localeEncodings.isEmpty()) + { + out.openTag("locale-encoding-mapping-list"); + for (Map.Entry<String, String> entry:localeEncodings.entrySet()) { - out.openTag("locale-encoding-mapping-list"); - for (Map.Entry<String, String> entry:localeEncodings.entrySet()) - { - out.openTag("locale-encoding-mapping", origin(md,"locale-encoding."+entry.getKey())); - out.tag("locale", entry.getKey()); - out.tag("encoding", entry.getValue()); - out.closeTag(); - } + out.openTag("locale-encoding-mapping", origin(md,"locale-encoding."+entry.getKey())); + out.tag("locale", entry.getKey()); + out.tag("encoding", entry.getValue()); out.closeTag(); } + out.closeTag(); + } - //session-config - if (_webApp.getSessionHandler().getSessionManager() != null) - { - out.openTag("session-config"); - int maxInactiveSec = _webApp.getSessionHandler().getSessionManager().getMaxInactiveInterval(); - out.tag("session-timeout", (maxInactiveSec==0?"0":Integer.toString(maxInactiveSec/60))); + //session-config + if (_webApp.getSessionHandler().getSessionManager() != null) + { + out.openTag("session-config"); + int maxInactiveSec = _webApp.getSessionHandler().getSessionManager().getMaxInactiveInterval(); + out.tag("session-timeout", (maxInactiveSec==0?"0":Integer.toString(maxInactiveSec/60))); - Set<SessionTrackingMode> modes =_webApp. getSessionHandler().getSessionManager().getEffectiveSessionTrackingModes(); - if (modes != null) - { - for (SessionTrackingMode mode:modes) - out.tag("tracking-mode", mode.toString()); - } + Set<SessionTrackingMode> modes =_webApp. getSessionHandler().getSessionManager().getEffectiveSessionTrackingModes(); + if (modes != null) + { + for (SessionTrackingMode mode:modes) + out.tag("tracking-mode", mode.toString()); + } - //cookie-config - SessionCookieConfig cookieConfig = _webApp.getSessionHandler().getSessionManager().getSessionCookieConfig(); - if (cookieConfig != null) - { - out.openTag("cookie-config"); - if (cookieConfig.getName() != null) - out.tag("name", origin(md,"cookie-config.name"), cookieConfig.getName()); + //cookie-config + SessionCookieConfig cookieConfig = _webApp.getSessionHandler().getSessionManager().getSessionCookieConfig(); + if (cookieConfig != null) + { + out.openTag("cookie-config"); + if (cookieConfig.getName() != null) + out.tag("name", origin(md,"cookie-config.name"), cookieConfig.getName()); - if (cookieConfig.getDomain() != null) - out.tag("domain", origin(md, "cookie-config.domain"), cookieConfig.getDomain()); + if (cookieConfig.getDomain() != null) + out.tag("domain", origin(md, "cookie-config.domain"), cookieConfig.getDomain()); - if (cookieConfig.getPath() != null) - out.tag("path", origin(md, "cookie-config.path"), cookieConfig.getPath()); + if (cookieConfig.getPath() != null) + out.tag("path", origin(md, "cookie-config.path"), cookieConfig.getPath()); - if (cookieConfig.getComment() != null) - out.tag("comment", origin(md, "cookie-config.comment"), cookieConfig.getComment()); + if (cookieConfig.getComment() != null) + out.tag("comment", origin(md, "cookie-config.comment"), cookieConfig.getComment()); - out.tag("http-only", origin(md, "cookie-config.http-only"), Boolean.toString(cookieConfig.isHttpOnly())); - out.tag("secure", origin(md, "cookie-config.secure"), Boolean.toString(cookieConfig.isSecure())); - out.tag("max-age", origin(md, "cookie-config.max-age"), Integer.toString(cookieConfig.getMaxAge())); - out.closeTag(); - } - out.closeTag(); + out.tag("http-only", origin(md, "cookie-config.http-only"), Boolean.toString(cookieConfig.isHttpOnly())); + out.tag("secure", origin(md, "cookie-config.secure"), Boolean.toString(cookieConfig.isSecure())); + out.tag("max-age", origin(md, "cookie-config.max-age"), Integer.toString(cookieConfig.getMaxAge())); + out.closeTag(); } + out.closeTag(); + } - //error-pages - Map<String,String> errorPages = ((ErrorPageErrorHandler)_webApp.getErrorHandler()).getErrorPages(); - if (errorPages != null) + //error-pages + Map<String,String> errorPages = ((ErrorPageErrorHandler)_webApp.getErrorHandler()).getErrorPages(); + if (errorPages != null) + { + for (Map.Entry<String, String> entry:errorPages.entrySet()) { - for (Map.Entry<String, String> entry:errorPages.entrySet()) + out.openTag("error-page", origin(md, "error."+entry.getKey())); + //a global or default error page has no code or exception + if (!ErrorPageErrorHandler.GLOBAL_ERROR_PAGE.equals(entry.getKey())) { - out.openTag("error-page", origin(md, "error."+entry.getKey())); - //a global or default error page has no code or exception - if (!ErrorPageErrorHandler.GLOBAL_ERROR_PAGE.equals(entry.getKey())) - { - if (entry.getKey().matches("\\d{3}")) - out.tag("error-code", entry.getKey()); - else - out.tag("exception-type", entry.getKey()); - } - out.tag("location", entry.getValue()); - out.closeTag(); + if (entry.getKey().matches("\\d{3}")) + out.tag("error-code", entry.getKey()); + else + out.tag("exception-type", entry.getKey()); } + out.tag("location", entry.getValue()); + out.closeTag(); } + } - //mime-types - MimeTypes mimeTypes = _webApp.getMimeTypes(); - if (mimeTypes != null) + //mime-types + MimeTypes mimeTypes = _webApp.getMimeTypes(); + if (mimeTypes != null) + { + for (Map.Entry<String, String> entry:mimeTypes.getMimeMap().entrySet()) { - for (Map.Entry<String, String> entry:mimeTypes.getMimeMap().entrySet()) + out.openTag("mime-mapping"); + out.tag("extension", origin(md, "extension."+entry.getKey()), entry.getKey()); + out.tag("mime-type", entry.getValue()); + out.closeTag(); + } + } + + //jsp-config + JspConfig jspConfig = (JspConfig)_webApp.getServletContext().getJspConfigDescriptor(); + if (jspConfig != null) + { + out.openTag("jsp-config"); + Collection<TaglibDescriptor> tlds = jspConfig.getTaglibs(); + if (tlds != null && !tlds.isEmpty()) + { + for (TaglibDescriptor tld:tlds) { - out.openTag("mime-mapping"); - out.tag("extension", origin(md, "extension."+entry.getKey()), entry.getKey()); - out.tag("mime-type", entry.getValue()); + out.openTag("taglib"); + out.tag("taglib-uri", tld.getTaglibURI()); + out.tag("taglib-location", tld.getTaglibLocation()); out.closeTag(); } } - //jsp-config - JspConfig jspConfig = (JspConfig)_webApp.getServletContext().getJspConfigDescriptor(); - if (jspConfig != null) + Collection<JspPropertyGroupDescriptor> jspPropertyGroups = jspConfig.getJspPropertyGroups(); + if (jspPropertyGroups != null && !jspPropertyGroups.isEmpty()) { - out.openTag("jsp-config"); - Collection<TaglibDescriptor> tlds = jspConfig.getTaglibs(); - if (tlds != null && !tlds.isEmpty()) + for (JspPropertyGroupDescriptor jspPropertyGroup:jspPropertyGroups) { - for (TaglibDescriptor tld:tlds) + out.openTag("jsp-property-group"); + Collection<String> strings = jspPropertyGroup.getUrlPatterns(); + if (strings != null && !strings.isEmpty()) { - out.openTag("taglib"); - out.tag("taglib-uri", tld.getTaglibURI()); - out.tag("taglib-location", tld.getTaglibLocation()); - out.closeTag(); + for (String urlPattern:strings) + out.tag("url-pattern", urlPattern); } - } - - Collection<JspPropertyGroupDescriptor> jspPropertyGroups = jspConfig.getJspPropertyGroups(); - if (jspPropertyGroups != null && !jspPropertyGroups.isEmpty()) - { - for (JspPropertyGroupDescriptor jspPropertyGroup:jspPropertyGroups) - { - out.openTag("jsp-property-group"); - Collection<String> strings = jspPropertyGroup.getUrlPatterns(); - if (strings != null && !strings.isEmpty()) - { - for (String urlPattern:strings) - out.tag("url-pattern", urlPattern); - } - - if (jspPropertyGroup.getElIgnored() != null) - out.tag("el-ignored", jspPropertyGroup.getElIgnored()); - - if (jspPropertyGroup.getPageEncoding() != null) - out.tag("page-encoding", jspPropertyGroup.getPageEncoding()); - if (jspPropertyGroup.getScriptingInvalid() != null) - out.tag("scripting-invalid", jspPropertyGroup.getScriptingInvalid()); + if (jspPropertyGroup.getElIgnored() != null) + out.tag("el-ignored", jspPropertyGroup.getElIgnored()); - if (jspPropertyGroup.getIsXml() != null) - out.tag("is-xml", jspPropertyGroup.getIsXml()); + if (jspPropertyGroup.getPageEncoding() != null) + out.tag("page-encoding", jspPropertyGroup.getPageEncoding()); - if (jspPropertyGroup.getDeferredSyntaxAllowedAsLiteral() != null) - out.tag("deferred-syntax-allowed-as-literal", jspPropertyGroup.getDeferredSyntaxAllowedAsLiteral()); + if (jspPropertyGroup.getScriptingInvalid() != null) + out.tag("scripting-invalid", jspPropertyGroup.getScriptingInvalid()); - if (jspPropertyGroup.getTrimDirectiveWhitespaces() != null) - out.tag("trim-directive-whitespaces", jspPropertyGroup.getTrimDirectiveWhitespaces()); + if (jspPropertyGroup.getIsXml() != null) + out.tag("is-xml", jspPropertyGroup.getIsXml()); - if (jspPropertyGroup.getDefaultContentType() != null) - out.tag("default-content-type", jspPropertyGroup.getDefaultContentType()); + if (jspPropertyGroup.getDeferredSyntaxAllowedAsLiteral() != null) + out.tag("deferred-syntax-allowed-as-literal", jspPropertyGroup.getDeferredSyntaxAllowedAsLiteral()); - if (jspPropertyGroup.getBuffer() != null) - out.tag("buffer", jspPropertyGroup.getBuffer()); + if (jspPropertyGroup.getTrimDirectiveWhitespaces() != null) + out.tag("trim-directive-whitespaces", jspPropertyGroup.getTrimDirectiveWhitespaces()); - if (jspPropertyGroup.getErrorOnUndeclaredNamespace() != null) - out.tag("error-on-undeclared-namespace", jspPropertyGroup.getErrorOnUndeclaredNamespace()); + if (jspPropertyGroup.getDefaultContentType() != null) + out.tag("default-content-type", jspPropertyGroup.getDefaultContentType()); - strings = jspPropertyGroup.getIncludePreludes(); - if (strings != null && !strings.isEmpty()) - { - for (String prelude:strings) - out.tag("include-prelude", prelude); - } + if (jspPropertyGroup.getBuffer() != null) + out.tag("buffer", jspPropertyGroup.getBuffer()); - strings = jspPropertyGroup.getIncludeCodas(); - if (strings != null && !strings.isEmpty()) - { - for (String coda:strings) - out.tag("include-coda", coda); - } + if (jspPropertyGroup.getErrorOnUndeclaredNamespace() != null) + out.tag("error-on-undeclared-namespace", jspPropertyGroup.getErrorOnUndeclaredNamespace()); - out.closeTag(); + strings = jspPropertyGroup.getIncludePreludes(); + if (strings != null && !strings.isEmpty()) + { + for (String prelude:strings) + out.tag("include-prelude", prelude); } - } - - out.closeTag(); - } - //lifecycle: post-construct, pre-destroy - LifeCycleCallbackCollection lifecycles = ((LifeCycleCallbackCollection)_webApp.getAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION)); - if (lifecycles != null) - { - Collection<LifeCycleCallback> tmp = lifecycles.getPostConstructCallbacks(); - - for (LifeCycleCallback c:tmp) - { - out.openTag("post-construct"); - out.tag("lifecycle-callback-class", c.getTargetClassName()); - out.tag("lifecycle-callback-method", c.getMethodName()); - out.closeTag(); - } + strings = jspPropertyGroup.getIncludeCodas(); + if (strings != null && !strings.isEmpty()) + { + for (String coda:strings) + out.tag("include-coda", coda); + } - tmp = lifecycles.getPreDestroyCallbacks(); - for (LifeCycleCallback c:tmp) - { - out.openTag("pre-destroy"); - out.tag("lifecycle-callback-class", c.getTargetClassName()); - out.tag("lifecycle-callback-method", c.getMethodName()); out.closeTag(); } } - out.literal(_extraXML); - out.closeTag(); } - catch (Exception e) + + //lifecycle: post-construct, pre-destroy + LifeCycleCallbackCollection lifecycles = ((LifeCycleCallbackCollection)_webApp.getAttribute(LifeCycleCallbackCollection.LIFECYCLE_CALLBACK_COLLECTION)); + if (lifecycles != null) { - if (e.getSuppressed() != null) - { - for (Throwable t:e.getSuppressed()) - t.printStackTrace(); - } + Collection<LifeCycleCallback> tmp = lifecycles.getPostConstructCallbacks(); + + for (LifeCycleCallback c:tmp) + { + out.openTag("post-construct"); + out.tag("lifecycle-callback-class", c.getTargetClassName()); + out.tag("lifecycle-callback-method", c.getMethodName()); + out.closeTag(); + } + + tmp = lifecycles.getPreDestroyCallbacks(); + for (LifeCycleCallback c:tmp) + { + out.openTag("pre-destroy"); + out.tag("lifecycle-callback-class", c.getTargetClassName()); + out.tag("lifecycle-callback-method", c.getMethodName()); + out.closeTag(); + } } - - return webXml; + + out.literal(_extraXML); + + out.closeTag(); } /** @@ -584,8 +567,18 @@ public class QuickStartDescriptorGenerator out.tag(tag + "-name",n); String ot = n + "." + tag + "."; + + if (holder instanceof FilterHolder) + out.tag(tag + "-class",origin(md,ot + tag + "-class"),holder.getClassName()); + else if (holder instanceof ServletHolder) + { + ServletHolder s = (ServletHolder)holder; + if (s.getForcedPath() != null && s.getClassName() == null) + out.tag("jsp-file",s.getForcedPath()); + else + out.tag(tag + "-class",origin(md,ot + tag + "-class"),s.getClassName()); - out.tag(tag + "-class",origin(md,ot + tag + "-class"),holder.getClassName()); + } for (String p : holder.getInitParameters().keySet()) { @@ -600,10 +593,7 @@ public class QuickStartDescriptorGenerator if (holder instanceof ServletHolder) { ServletHolder s = (ServletHolder)holder; - if (s.getForcedPath() != null) - out.tag("jsp-file",s.getForcedPath()); - - if (s.getInitOrder() != 0) + if (s.getInitOrder() >= 0) out.tag("load-on-startup",Integer.toString(s.getInitOrder())); if (s.getRunAsRole() != null) diff --git a/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartWebApp.java b/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartWebApp.java index 959cf8015c..0372e52cb9 100644 --- a/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartWebApp.java +++ b/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartWebApp.java @@ -18,6 +18,8 @@ package org.eclipse.jetty.quickstart; +import java.io.FileOutputStream; + import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.resource.JarResource; @@ -32,6 +34,8 @@ public class QuickStartWebApp extends WebAppContext { private static final Logger LOG = Log.getLogger(QuickStartWebApp.class); + + public static final String[] __configurationClasses = new String[] { org.eclipse.jetty.quickstart.QuickStartConfiguration.class.getCanonicalName(), @@ -164,8 +168,14 @@ public class QuickStartWebApp extends WebAppContext public void generateQuickstartWebXml(String extraXML) throws Exception { - QuickStartDescriptorGenerator generator = new QuickStartDescriptorGenerator(this, this.getWebInf().getFile(), extraXML); - generator.generateQuickStartWebXml(); + Resource descriptor = getWebInf().addPath(QuickStartDescriptorGenerator.DEFAULT_QUICKSTART_DESCRIPTOR_NAME); + if (!descriptor.exists()) + descriptor.getFile().createNewFile(); + QuickStartDescriptorGenerator generator = new QuickStartDescriptorGenerator(this, extraXML); + try (FileOutputStream fos = new FileOutputStream(descriptor.getFile())) + { + generator.generateQuickStartWebXml(fos); + } } |