diff options
Diffstat (limited to 'jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebServletAnnotation.java')
-rw-r--r-- | jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebServletAnnotation.java | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebServletAnnotation.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebServletAnnotation.java index a42928ad41..493c767ac9 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebServletAnnotation.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/WebServletAnnotation.java @@ -19,7 +19,6 @@ package org.eclipse.jetty.annotations; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -54,13 +53,13 @@ public class WebServletAnnotation extends DiscoveredAnnotation { super(context, className); } - - + + public WebServletAnnotation (WebAppContext context, String className, Resource resource) { super(context, className, resource); } - + /** * @see DiscoveredAnnotation#apply() */ @@ -126,7 +125,7 @@ public class WebServletAnnotation extends DiscoveredAnnotation } } - //handle creation/completion of a servlet + //handle creation/completion of a servlet if (holder == null) { //No servlet of this name has already been defined, either by a descriptor @@ -152,8 +151,8 @@ public class WebServletAnnotation extends DiscoveredAnnotation } _context.getServletHandler().addServlet(holder); - - + + mapping = new ServletMapping(); mapping.setServletName(holder.getName()); mapping.setPathSpecs( LazyList.toStringArray(urlPatternList)); @@ -179,16 +178,16 @@ public class WebServletAnnotation extends DiscoveredAnnotation metaData.setOrigin(servletName+".servlet.init-param."+ip.name(),ip,clazz); } } - + //check the url-patterns //ServletSpec 3.0 p81 If a servlet already has url mappings from a - //webxml or fragment descriptor the annotation is ignored. - //However, we want to be able to replace mappings that were given in webdefault.xml + //webxml or fragment descriptor the annotation is ignored. + //However, we want to be able to replace mappings that were given in webdefault.xml List<ServletMapping> existingMappings = getServletMappingsForServlet(servletName); - - //if any mappings for this servlet already set by a descriptor that is not webdefault.xml forget - //about processing these url mappings + + //if any mappings for this servlet already set by a descriptor that is not webdefault.xml forget + //about processing these url mappings if (existingMappings.isEmpty() || !containsNonDefaultMappings(existingMappings)) { mapping = new ServletMapping(); @@ -197,7 +196,7 @@ public class WebServletAnnotation extends DiscoveredAnnotation } } - + //We also want to be able to replace mappings that were defined in webdefault.xml //that were for a different servlet eg a mapping in webdefault.xml for / to the jetty //default servlet should be able to be replaced by an annotation for / to a different @@ -209,7 +208,7 @@ public class WebServletAnnotation extends DiscoveredAnnotation //take a copy of the existing servlet mappings that we can iterate over and remove from. This is //because the ServletHandler interface does not support removal of individual mappings. List<ServletMapping> allMappings = ArrayUtil.asMutableList(_context.getServletHandler().getServletMappings()); - + //for each of the urls in the annotation, check if a mapping to same/different servlet exists // if mapping exists and is from a default descriptor, it can be replaced. NOTE: we do not // guard against duplicate path mapping here: that is the job of the ServletHandler @@ -221,11 +220,11 @@ public class WebServletAnnotation extends DiscoveredAnnotation String[] updatedPaths = ArrayUtil.removeFromArray(existingMapping.getPathSpecs(), p); //if we removed the last path from a servletmapping, delete the servletmapping if (updatedPaths == null || updatedPaths.length == 0) - { + { boolean success = allMappings.remove(existingMapping); if (LOG.isDebugEnabled()) LOG.debug("Removed empty mapping {} from defaults descriptor success:{}",existingMapping, success); } - else + else { existingMapping.setPathSpecs(updatedPaths); if (LOG.isDebugEnabled()) LOG.debug("Removed path {} from mapping {} from defaults descriptor ", p,existingMapping); @@ -239,8 +238,8 @@ public class WebServletAnnotation extends DiscoveredAnnotation } - - + + /** * @param name * @return @@ -261,8 +260,8 @@ public class WebServletAnnotation extends DiscoveredAnnotation } return mappings; } - - + + /** * @param mappings * @return |