|
Glassfish example source code file (TomcatDeploymentConfig.java)
The Glassfish TomcatDeploymentConfig.java source code/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright (c) 1997-2011 Oracle and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can * obtain a copy of the License at * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html * or packager/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at packager/legal/LICENSE.txt. * * GPL Classpath Exception: * Oracle designates this particular file as subject to the "Classpath" * exception as provided by Oracle in the GPL Version 2 section of the License * file that accompanied this code. * * Modifications: * If applicable, add the following below the License Header, with the fields * enclosed by brackets [] replaced by your own identifying information: * "Portions Copyright [year] [name of copyright owner]" * * Contributor(s): * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. */ package com.sun.enterprise.web; import com.sun.enterprise.deployment.*; import com.sun.enterprise.deployment.types.EjbReference; import com.sun.enterprise.deployment.web.*; import com.sun.enterprise.web.deploy.*; import com.sun.logging.LogDomains; import org.apache.catalina.Container; import org.apache.catalina.LifecycleException; import org.apache.catalina.Wrapper; import org.apache.catalina.core.StandardWrapper; import javax.servlet.SessionCookieConfig; import javax.servlet.descriptor.JspPropertyGroupDescriptor; import java.util.Enumeration; import java.util.Iterator; import java.util.Vector; import java.util.logging.Level; import java.util.logging.Logger; /** * This class decorates all <code>com.sun.enterprise.deployment.* * objects in order to make them usuable by the Catalina container. * This avoid having duplicate memory representation of the web.xml (as well * as parsing the web.xml twice) * * @author Jean-Francois Arcand */ public class TomcatDeploymentConfig { private static final Logger logger = LogDomains.getLogger( TomcatDeploymentConfig.class, LogDomains.WEB_LOGGER); /** * Configure a <code>WebModule by applying web.xml information * contained in <code>WebBundleDescriptor. This astatic void calling * Tomcat 5 internal deployment mechanism by re-using the DOL objects. */ public static void configureWebModule(WebModule webModule, WebBundleDescriptor webModuleDescriptor) throws LifecycleException { // When context root = "/" if ( webModuleDescriptor == null ){ return; } webModule.setDisplayName(webModuleDescriptor.getDisplayName()); webModule.setDistributable(webModuleDescriptor.isDistributable()); webModule.setReplaceWelcomeFiles(true); configureStandardContext(webModule,webModuleDescriptor); configureContextParam(webModule,webModuleDescriptor); configureApplicationListener(webModule,webModuleDescriptor); configureEjbReference(webModule,webModuleDescriptor); configureContextEnvironment(webModule,webModuleDescriptor); configureErrorPage(webModule,webModuleDescriptor); configureFilterDef(webModule,webModuleDescriptor); configureFilterMap(webModule,webModuleDescriptor); configureLoginConfig(webModule,webModuleDescriptor); configureMimeMapping(webModule,webModuleDescriptor); configureResourceRef(webModule,webModuleDescriptor); configureMessageDestination(webModule,webModuleDescriptor); configureContextResource(webModule,webModuleDescriptor); configureSecurityConstraint(webModule,webModuleDescriptor); configureJspConfig(webModule,webModuleDescriptor); configureSecurityRoles(webModule, webModuleDescriptor); } /** * Configures EJB resource reference for a web application, as * represented in a <code><ejb-ref> and * <code><ejb-local-ref>element in the * deployment descriptor. */ protected static void configureEjbReference(WebModule webModule, WebBundleDescriptor wmd) { for (EjbReference ejbDescriptor : wmd.getEjbReferenceDescriptors()) { if (ejbDescriptor.isLocal()) { configureContextLocalEjb(webModule, (EjbReferenceDescriptor) ejbDescriptor); } else { configureContextEjb(webModule, (EjbReferenceDescriptor) ejbDescriptor); } } } /** * Configures EJB resource reference for a web application, as * represented in a <code><ejb-ref> in the * deployment descriptor. */ protected static void configureContextLocalEjb(WebModule webModule, EjbReferenceDescriptor ejbDescriptor) { ContextLocalEjbDecorator decorator = new ContextLocalEjbDecorator(ejbDescriptor); webModule.addLocalEjb(decorator); } /** * Configures EJB resource reference for a web application, as * represented in a <code><ejb-local-ref>element in the * deployment descriptor. */ protected static void configureContextEjb(WebModule webModule, EjbReferenceDescriptor ejbDescriptor) { ContextEjbDecorator decorator = new ContextEjbDecorator(ejbDescriptor); webModule.addEjb(decorator); } /** * Configure application environment entry, as represented by * an <code><env-entry> element in the deployment descriptor. */ protected static void configureContextEnvironment(WebModule webModule, WebBundleDescriptor wmd) { for (ContextParameter envRef : wmd.getContextParametersSet()) { webModule.addEnvironment(new ContextEnvironmentDecorator( (EnvironmentProperty) envRef)); } } /** * Configure error page element for a web application, * as represented by a <code><error-page> element in the * deployment descriptor. */ protected static void configureErrorPage(WebModule webModule, WebBundleDescriptor wmd) { Enumeration<ErrorPageDescriptor> e = wmd.getErrorPageDescriptors(); while (e.hasMoreElements()){ webModule.addErrorPage(new ErrorPageDecorator(e.nextElement())); } } /** * Configure filter definition for a web application, as represented * by a <code><filter> element in the deployment descriptor. */ protected static void configureFilterDef(WebModule webModule, WebBundleDescriptor wmd) { Vector vector = wmd.getServletFilters(); FilterDefDecorator filterDef; ServletFilter servletFilter; for (int i=0; i < vector.size(); i++) { servletFilter = (ServletFilter)vector.get(i); filterDef = new FilterDefDecorator(servletFilter); webModule.addFilterDef(filterDef); } } /** * Configure filter mapping for a web application, as represented * by a <code><filter-mapping> element in the deployment * descriptor. Each filter mapping must contain a filter name plus either * a URL pattern or a servlet name. */ protected static void configureFilterMap(WebModule webModule, WebBundleDescriptor wmd) { Vector vector = wmd.getServletFilterMappingDescriptors(); for (int i=0; i < vector.size(); i++) { webModule.addFilterMap((ServletFilterMapping)vector.get(i)); } } /** * Configure context initialization parameter that is configured * in the server configuration file, rather than the application deployment * descriptor. This is convenient for establishing default values (which * may be configured to allow application overrides or not) without having * to modify the application deployment descriptor itself. */ protected static void configureApplicationListener( WebModule webModule, WebBundleDescriptor wmd) { Vector vector = wmd.getAppListenerDescriptors(); for (int i=0; i < vector.size() ; i++){ webModule.addApplicationListener( ((AppListenerDescriptor)vector.get(i)).getListener() ); } } /** * Configure <code>jsp-config element contained in the deployment * descriptor */ protected static void configureJspConfig(WebModule webModule, WebBundleDescriptor wmd) { webModule.setJspConfigDescriptor(wmd.getJspConfigDescriptor()); JspConfigDescriptor jspConfig = wmd.getJspConfigDescriptor(); if (jspConfig != null) { for (JspPropertyGroupDescriptor jspGroup : jspConfig.getJspPropertyGroups()) { for (String urlPattern : jspGroup.getUrlPatterns()) { webModule.addJspMapping(urlPattern); } } } } /** * Configure a login configuration element for a web application, * as represented by a <code><login-config> element in the * deployment descriptor. */ protected static void configureLoginConfig(WebModule webModule, WebBundleDescriptor wmd) { LoginConfiguration loginConf = wmd.getLoginConfiguration(); if ( loginConf == null ){ return; } LoginConfigDecorator decorator = new LoginConfigDecorator(loginConf); webModule.setLoginConfig(decorator); } /** * Configure mime-mapping defined in the deployment descriptor. */ protected static void configureMimeMapping(WebModule webModule, WebBundleDescriptor wmd) { Enumeration enumeration = wmd.getMimeMappings(); MimeMapping mimeMapping; while (enumeration.hasMoreElements()){ mimeMapping = (MimeMapping)enumeration.nextElement(); webModule.addMimeMapping(mimeMapping.getExtension(), mimeMapping.getMimeType()); } } /** * Configure resource-reference defined in the deployment descriptor. */ protected static void configureResourceRef(WebModule webModule, WebBundleDescriptor wmd) { for (EnvironmentEntry envEntry : wmd.getEnvironmentProperties()) { webModule.addResourceEnvRef(envEntry.getName(), envEntry.getType()); } } /** * Configure context parameter defined in the deployment descriptor. */ protected static void configureContextParam(WebModule webModule, WebBundleDescriptor wmd) { for (ContextParameter ctxParam : wmd.getContextParametersSet()) { if ("com.sun.faces.injectionProvider".equals( ctxParam.getName()) && "com.sun.faces.vendor.GlassFishInjectionProvider".equals( ctxParam.getValue())) { // Ignore, see IT 9641 continue; } webModule.addParameter(ctxParam.getName(), ctxParam.getValue()); } } /** * Configure of a message destination for a web application, as * represented in a <code><message-destination> element * in the deployment descriptor. */ protected static void configureMessageDestination( WebModule webModule, WebBundleDescriptor wmd) { for (MessageDestinationDescriptor msgDrd : wmd.getMessageDestinations()) { webModule.addMessageDestination( new MessageDestinationDecorator(msgDrd)); } } /** * Representation of a message destination reference for a web application, * as represented by a <code><message-destination-ref> element * in the deployment descriptor. */ protected static void configureMessageDestinationRef( WebModule webModule, WebBundleDescriptor wmd) { for (MessageDestinationReferenceDescriptor msgDrd : wmd.getMessageDestinationReferenceDescriptors()) { webModule.addMessageDestinationRef( new MessageDestinationRefDecorator(msgDrd)); } } /** * Configure a resource reference for a web application, as * represented in a <code><resource-ref> element in the * deployment descriptor. */ protected static void configureContextResource(WebModule webModule, WebBundleDescriptor wmd) { for (ResourceReferenceDescriptor resRefDesc : wmd.getResourceReferenceDescriptors()) { webModule.addResource(new ContextResourceDecorator(resRefDesc)); } } /** * Configure the <code>WebModule instance by creating * <code>StandardWrapper using the information contained * in the deployment descriptor (Welcome Files, JSP, Servlets etc.) */ protected static void configureStandardContext(WebModule webModule, WebBundleDescriptor wmd) { StandardWrapper wrapper; Enumeration enumeration; SecurityRoleReference securityRoleReference; for (WebComponentDescriptor webComponentDesc : wmd.getWebComponentDescriptors()) { if (!webComponentDesc.isEnabled()) { continue; } wrapper = (StandardWrapper)webModule.createWrapper(); wrapper.setName(webComponentDesc.getCanonicalName()); String impl = webComponentDesc.getWebComponentImplementation(); if (impl != null && !impl.isEmpty()) { if (webComponentDesc.isServlet()){ wrapper.setServletClassName(impl); } else { wrapper.setJspFile(impl); } } /* * Add the wrapper only after we have set its * servletClassName, so we know whether we're dealing with * a JSF app */ webModule.addChild(wrapper); enumeration = webComponentDesc.getInitializationParameters(); InitializationParameter initP = null; while (enumeration.hasMoreElements()) { initP = (InitializationParameter)enumeration.nextElement(); wrapper.addInitParameter(initP.getName(), initP.getValue()); } if (webComponentDesc.getLoadOnStartUp() != null) { wrapper.setLoadOnStartup(webComponentDesc.getLoadOnStartUp()); } if (webComponentDesc.isAsyncSupported() != null) { wrapper.setIsAsyncSupported(webComponentDesc.isAsyncSupported()); } if (webComponentDesc.getRunAsIdentity() != null) { wrapper.setRunAs(webComponentDesc.getRunAsIdentity().getRoleName()); } for (String pattern : webComponentDesc.getUrlPatternsSet()) { webModule.addServletMapping(pattern, webComponentDesc.getCanonicalName()); } enumeration = webComponentDesc.getSecurityRoleReferences(); while (enumeration.hasMoreElements()){ securityRoleReference = (SecurityRoleReference) enumeration.nextElement(); wrapper.addSecurityReference( securityRoleReference.getRolename(), securityRoleReference.getSecurityRoleLink().getName()); } MultipartConfig mpConfig = webComponentDesc.getMultipartConfig(); if (mpConfig != null) { wrapper.setMultipartLocation(mpConfig.getLocation()); wrapper.setMultipartMaxFileSize(mpConfig.getMaxFileSize()); wrapper.setMultipartMaxRequestSize(mpConfig.getMaxRequestSize()); wrapper.setMultipartFileSizeThreshold(mpConfig.getFileSizeThreshold()); } } SessionConfig sessionConfig = wmd.getSessionConfig(); // <session-config> Other Glassfish examples (source code examples)Here is a short list of links related to this Glassfish TomcatDeploymentConfig.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.