JBossWeb SVN: r1194 - in trunk/java/org/apache/catalina: servlets and 1 other directory.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2009-10-15 10:57:00 -0400 (Thu, 15 Oct 2009)
New Revision: 1194
Removed:
trunk/java/org/apache/catalina/servlets/InvokerHttpRequest.java
trunk/java/org/apache/catalina/servlets/InvokerServlet.java
Modified:
trunk/java/org/apache/catalina/core/ApplicationDispatcher.java
trunk/java/org/apache/catalina/core/RestrictedServlets.properties
trunk/java/org/apache/catalina/servlets/LocalStrings.properties
Log:
- Remove invoker servlet.
Modified: trunk/java/org/apache/catalina/core/ApplicationDispatcher.java
===================================================================
--- trunk/java/org/apache/catalina/core/ApplicationDispatcher.java 2009-10-14 11:57:52 UTC (rev 1193)
+++ trunk/java/org/apache/catalina/core/ApplicationDispatcher.java 2009-10-15 14:57:00 UTC (rev 1194)
@@ -911,9 +911,6 @@
while (current != null) {
if(state.hrequest == null && (current instanceof HttpServletRequest))
state.hrequest = (HttpServletRequest)current;
- if ("org.apache.catalina.servlets.InvokerHttpRequest".
- equals(current.getClass().getName()))
- break; // KLUDGE - Make nested RD.forward() using invoker work
if (!(current instanceof ServletRequestWrapper))
break;
if (current instanceof ApplicationHttpRequest)
Modified: trunk/java/org/apache/catalina/core/RestrictedServlets.properties
===================================================================
--- trunk/java/org/apache/catalina/core/RestrictedServlets.properties 2009-10-14 11:57:52 UTC (rev 1193)
+++ trunk/java/org/apache/catalina/core/RestrictedServlets.properties 2009-10-15 14:57:00 UTC (rev 1194)
@@ -1,4 +1,3 @@
org.apache.catalina.ssi.SSIServlet=restricted
org.apache.catalina.servlets.CGIServlet=restricted
-org.apache.catalina.servlets.InvokerServlet=restricted
org.apache.catalina.manager.JMXProxyServlet=restricted
Deleted: trunk/java/org/apache/catalina/servlets/InvokerHttpRequest.java
===================================================================
--- trunk/java/org/apache/catalina/servlets/InvokerHttpRequest.java 2009-10-14 11:57:52 UTC (rev 1193)
+++ trunk/java/org/apache/catalina/servlets/InvokerHttpRequest.java 2009-10-15 14:57:00 UTC (rev 1194)
@@ -1,199 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package org.apache.catalina.servlets;
-
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletRequestWrapper;
-
-
-/**
- * Wrapper around a <code>javax.servlet.http.HttpServletRequest</code>
- * utilized when <code>InvokerServlet</code> processes the initial request
- * for an invoked servlet. Subsequent requests will be mapped directly
- * to the servlet, because a new servlet mapping will have been created.
- *
- * @author Craig R. McClanahan
- * @version $Revision$ $Date$
- */
-
-class InvokerHttpRequest extends HttpServletRequestWrapper {
-
-
- // ----------------------------------------------------------- Constructors
-
-
- /**
- * Construct a new wrapped request around the specified servlet request.
- *
- * @param request The servlet request being wrapped
- */
- public InvokerHttpRequest(HttpServletRequest request) {
-
- super(request);
- this.pathInfo = request.getPathInfo();
- this.pathTranslated = request.getPathTranslated();
- this.requestURI = request.getRequestURI();
- this.servletPath = request.getServletPath();
-
- }
-
-
- // ----------------------------------------------------- Instance Variables
-
-
- /**
- * Descriptive information about this implementation.
- */
- protected static final String info =
- "org.apache.catalina.servlets.InvokerHttpRequest/1.0";
-
-
- /**
- * The path information for this request.
- */
- protected String pathInfo = null;
-
-
- /**
- * The translated path information for this request.
- */
- protected String pathTranslated = null;
-
-
- /**
- * The request URI for this request.
- */
- protected String requestURI = null;
-
-
- /**
- * The servlet path for this request.
- */
- protected String servletPath = null;
-
-
- // --------------------------------------------- HttpServletRequest Methods
-
-
- /**
- * Override the <code>getPathInfo()</code> method of the wrapped request.
- */
- public String getPathInfo() {
-
- return (this.pathInfo);
-
- }
-
-
- /**
- * Override the <code>getPathTranslated()</code> method of the
- * wrapped request.
- */
- public String getPathTranslated() {
-
- return (this.pathTranslated);
-
- }
-
-
- /**
- * Override the <code>getRequestURI()</code> method of the wrapped request.
- */
- public String getRequestURI() {
-
- return (this.requestURI);
-
- }
-
-
- /**
- * Override the <code>getServletPath()</code> method of the wrapped
- * request.
- */
- public String getServletPath() {
-
- return (this.servletPath);
-
- }
-
-
- // -------------------------------------------------------- Package Methods
-
-
-
- /**
- * Return descriptive information about this implementation.
- */
- public String getInfo() {
-
- return (info);
-
- }
-
-
- /**
- * Set the path information for this request.
- *
- * @param pathInfo The new path info
- */
- void setPathInfo(String pathInfo) {
-
- this.pathInfo = pathInfo;
-
- }
-
-
- /**
- * Set the translated path info for this request.
- *
- * @param pathTranslated The new translated path info
- */
- void setPathTranslated(String pathTranslated) {
-
- this.pathTranslated = pathTranslated;
-
- }
-
-
- /**
- * Set the request URI for this request.
- *
- * @param requestURI The new request URI
- */
- void setRequestURI(String requestURI) {
-
- this.requestURI = requestURI;
-
- }
-
-
- /**
- * Set the servlet path for this request.
- *
- * @param servletPath The new servlet path
- */
- void setServletPath(String servletPath) {
-
- this.servletPath = servletPath;
-
- }
-
-
-}
Deleted: trunk/java/org/apache/catalina/servlets/InvokerServlet.java
===================================================================
--- trunk/java/org/apache/catalina/servlets/InvokerServlet.java 2009-10-14 11:57:52 UTC (rev 1193)
+++ trunk/java/org/apache/catalina/servlets/InvokerServlet.java 2009-10-15 14:57:00 UTC (rev 1194)
@@ -1,423 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package org.apache.catalina.servlets;
-
-
-import java.io.IOException;
-
-import javax.servlet.Servlet;
-import javax.servlet.ServletException;
-import javax.servlet.UnavailableException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.catalina.ContainerServlet;
-import org.apache.catalina.Context;
-import org.apache.catalina.Globals;
-import org.apache.catalina.Wrapper;
-import org.apache.catalina.util.StringManager;
-
-
-/**
- * The default servlet-invoking servlet for most web applications,
- * used to serve requests to servlets that have not been registered
- * in the web application deployment descriptor.
- *
- * @author Craig R. McClanahan
- * @version $Revision$ $Date$
- */
-
-public final class InvokerServlet
- extends HttpServlet implements ContainerServlet {
-
-
- // ----------------------------------------------------- Instance Variables
-
-
- /**
- * The Context container associated with our web application.
- */
- private Context context = null;
-
-
- /**
- * The debugging detail level for this servlet.
- */
- private int debug = 0;
-
-
- /**
- * The string manager for this package.
- */
- private static StringManager sm =
- StringManager.getManager(Constants.Package);
-
-
- /**
- * The Wrapper container associated with this servlet.
- */
- private Wrapper wrapper = null;
-
-
- // ----------------------------------------------- ContainerServlet Methods
-
-
- /**
- * Return the Wrapper with which we are associated.
- */
- public Wrapper getWrapper() {
-
- return (this.wrapper);
-
- }
-
-
- /**
- * Set the Wrapper with which we are associated.
- *
- * @param wrapper The new wrapper
- */
- public void setWrapper(Wrapper wrapper) {
-
- this.wrapper = wrapper;
- if (wrapper == null)
- context = null;
- else
- context = (Context) wrapper.getParent();
-
- }
-
-
- // --------------------------------------------------------- Public Methods
-
-
- /**
- * Finalize this servlet.
- */
- public void destroy() {
-
- ; // No actions necessary
-
- }
-
-
- /**
- * Process a GET request for the specified resource.
- *
- * @param request The servlet request we are processing
- * @param response The servlet response we are creating
- *
- * @exception IOException if an input/output error occurs
- * @exception ServletException if a servlet-specified error occurs
- */
- public void doGet(HttpServletRequest request,
- HttpServletResponse response)
- throws IOException, ServletException {
-
- serveRequest(request, response);
-
- }
-
-
- /**
- * Process a HEAD request for the specified resource.
- *
- * @param request The servlet request we are processing
- * @param response The servlet response we are creating
- *
- * @exception IOException if an input/output error occurs
- * @exception ServletException if a servlet-specified error occurs
- */
- public void doHead(HttpServletRequest request,
- HttpServletResponse response)
- throws IOException, ServletException {
-
- serveRequest(request, response);
-
- }
-
-
- /**
- * Process a POST request for the specified resource.
- *
- * @param request The servlet request we are processing
- * @param response The servlet response we are creating
- *
- * @exception IOException if an input/output error occurs
- * @exception ServletException if a servlet-specified error occurs
- */
- public void doPost(HttpServletRequest request,
- HttpServletResponse response)
- throws IOException, ServletException {
-
- serveRequest(request, response);
-
- }
-
-
- /**
- * Initialize this servlet.
- */
- public void init() throws ServletException {
-
- // Ensure that our ContainerServlet properties have been set
- if ((wrapper == null) || (context == null))
- throw new UnavailableException
- (sm.getString("invokerServlet.noWrapper"));
-
- // Set our properties from the initialization parameters
- if (getServletConfig().getInitParameter("debug") != null)
- debug = Integer.parseInt(getServletConfig().getInitParameter("debug"));
-
- if (debug >= 1)
- log("init: Associated with Context '" + context.getPath() + "'");
-
- }
-
-
-
- // -------------------------------------------------------- Private Methods
-
-
- /**
- * Serve the specified request, creating the corresponding response.
- * After the first time a particular servlet class is requested, it will
- * be served directly (like any registered servlet) because it will have
- * been registered and mapped in our associated Context.
- *
- * @param request The servlet request we are processing
- * @param response The servlet response we are creating
- *
- * @exception IOException if an input/output error occurs
- * @exception ServletException if a servlet-specified error occurs
- */
- public void serveRequest(HttpServletRequest request,
- HttpServletResponse response)
- throws IOException, ServletException {
-
- // Disallow calling this servlet via a named dispatcher
- if (request.getAttribute(Globals.NAMED_DISPATCHER_ATTR) != null)
- throw new ServletException
- (sm.getString("invokerServlet.notNamed"));
-
- // Identify the input parameters and our "included" state
- String inRequestURI = null;
- String inServletPath = null;
- String inPathInfo = null;
- boolean included =
- (request.getAttribute(Globals.INCLUDE_REQUEST_URI_ATTR) != null);
-
- if (included) {
- inRequestURI =
- (String) request.getAttribute(Globals.INCLUDE_REQUEST_URI_ATTR);
- inServletPath =
- (String) request.getAttribute(Globals.INCLUDE_SERVLET_PATH_ATTR);
- inPathInfo =
- (String) request.getAttribute(Globals.INCLUDE_PATH_INFO_ATTR);
- } else {
- inRequestURI = request.getRequestURI();
- inServletPath = request.getServletPath();
- inPathInfo = request.getPathInfo();
- }
- if (debug >= 1) {
- log("included='" + included + "', requestURI='" +
- inRequestURI + "'");
- log(" servletPath='" + inServletPath + "', pathInfo='" +
- inPathInfo + "'");
- }
-
- // Make sure a servlet name or class name was specified
- if (inPathInfo == null) {
- if (debug >= 1)
- log("Invalid pathInfo '" + inPathInfo + "'");
- if (included)
- throw new ServletException
- (sm.getString("invokerServlet.invalidPath", inRequestURI));
- else {
- response.sendError(HttpServletResponse.SC_NOT_FOUND,
- inRequestURI);
- return;
- }
- }
-
- // Identify the outgoing servlet name or class, and outgoing path info
- String pathInfo = inPathInfo;
- String servletClass = pathInfo.substring(1);
- int slash = servletClass.indexOf('/');
- if (slash >= 0) {
- pathInfo = servletClass.substring(slash);
- servletClass = servletClass.substring(0, slash);
- } else {
- pathInfo = "";
- }
-
- if (servletClass.startsWith("org.apache.catalina")) {
- response.sendError(HttpServletResponse.SC_NOT_FOUND,
- inRequestURI);
- return;
- }
-
- if (debug >= 1)
- log("Processing servlet '" + servletClass +
- "' with path info '" + pathInfo + "'");
- String name = "org.apache.catalina.INVOKER." + servletClass;
- String pattern = inServletPath + "/" + servletClass + "/*";
- Wrapper wrapper = null;
-
- // Synchronize to avoid race conditions when multiple requests
- // try to initialize the same servlet at the same time
- synchronized (context) {
-
- // Are we referencing an existing servlet class or name?
- wrapper = (Wrapper) context.findChild(servletClass);
- if (wrapper == null)
- wrapper = (Wrapper) context.findChild(name);
- if (wrapper != null) {
- String actualServletClass = wrapper.getServletClass();
- if ((actualServletClass != null)
- && (actualServletClass.startsWith
- ("org.apache.catalina"))) {
- response.sendError(HttpServletResponse.SC_NOT_FOUND,
- inRequestURI);
- return;
- }
- if (debug >= 1)
- log("Using wrapper for servlet '" +
- wrapper.getName() + "' with mapping '" +
- pattern + "'");
- context.addServletMapping(pattern, wrapper.getName());
- }
-
- // No, create a new wrapper for the specified servlet class
- else {
-
- if (debug >= 1)
- log("Creating wrapper for '" + servletClass +
- "' with mapping '" + pattern + "'");
-
- try {
- wrapper = context.createWrapper();
- wrapper.setName(name);
- wrapper.setLoadOnStartup(1);
- wrapper.setServletClass(servletClass);
- context.addChild(wrapper);
- context.addServletMapping(pattern, name);
- } catch (Exception e) {
- log(sm.getString("invokerServlet.cannotCreate",
- inRequestURI), e);
- context.removeServletMapping(pattern);
- context.removeChild(wrapper);
- if (included)
- throw new ServletException
- (sm.getString("invokerServlet.cannotCreate",
- inRequestURI), e);
- else {
- response.sendError(HttpServletResponse.SC_NOT_FOUND,
- inRequestURI);
- return;
- }
- }
- }
-
- }
-
- // Create a request wrapper to pass on to the invoked servlet
- InvokerHttpRequest wrequest =
- new InvokerHttpRequest(request);
- wrequest.setRequestURI(inRequestURI);
- StringBuffer sb = new StringBuffer(inServletPath);
- sb.append("/");
- sb.append(servletClass);
- wrequest.setServletPath(sb.toString());
- if ((pathInfo == null) || (pathInfo.length() < 1)) {
- wrequest.setPathInfo(null);
- wrequest.setPathTranslated(null);
- } else {
- wrequest.setPathInfo(pathInfo);
- wrequest.setPathTranslated
- (getServletContext().getRealPath(pathInfo));
- }
-
- // Allocate a servlet instance to perform this request
- Servlet instance = null;
- try {
- instance = wrapper.allocate();
- } catch (ServletException e) {
- log(sm.getString("invokerServlet.allocate", inRequestURI), e);
- synchronized (context) {
- context.removeServletMapping(pattern);
- context.removeChild(wrapper);
- }
- Throwable rootCause = e.getRootCause();
- if (rootCause == null)
- rootCause = e;
- if (rootCause instanceof ClassNotFoundException) {
- response.sendError(HttpServletResponse.SC_NOT_FOUND,
- inRequestURI);
- return;
- } else if (rootCause instanceof IOException) {
- throw (IOException) rootCause;
- } else if (rootCause instanceof RuntimeException) {
- throw (RuntimeException) rootCause;
- } else if (rootCause instanceof ServletException) {
- throw (ServletException) rootCause;
- } else {
- throw new ServletException
- (sm.getString("invokerServlet.allocate", inRequestURI),
- rootCause);
- }
- }
-
- // After loading the wrapper, restore some of the fields when including
- if (included) {
- wrequest.setRequestURI(request.getRequestURI());
- wrequest.setPathInfo(request.getPathInfo());
- wrequest.setServletPath(request.getServletPath());
- }
-
- // Invoke the service() method of the allocated servlet
- try {
- String jspFile = wrapper.getJspFile();
- if (jspFile != null)
- request.setAttribute(Globals.JSP_FILE_ATTR, jspFile);
- else
- request.removeAttribute(Globals.JSP_FILE_ATTR);
- request.setAttribute(Globals.INVOKED_ATTR,
- request.getServletPath());
- instance.service(wrequest, response);
- } catch (UnavailableException e) {
- context.removeServletMapping(pattern);
- throw e;
- } finally {
- request.removeAttribute(Globals.INVOKED_ATTR);
- request.removeAttribute(Globals.JSP_FILE_ATTR);
- // Deallocate the allocated servlet instance
- try {
- wrapper.deallocate(instance);
- } catch (ServletException e) {
- log(sm.getString("invokerServlet.deallocate", inRequestURI), e);
- throw e;
- }
- }
-
- }
-
-
-}
Modified: trunk/java/org/apache/catalina/servlets/LocalStrings.properties
===================================================================
--- trunk/java/org/apache/catalina/servlets/LocalStrings.properties 2009-10-14 11:57:52 UTC (rev 1193)
+++ trunk/java/org/apache/catalina/servlets/LocalStrings.properties 2009-10-15 14:57:00 UTC (rev 1194)
@@ -3,12 +3,6 @@
defaultservlet.upto=Up to:
defaultservlet.subdirectories=Subdirectories:
defaultservlet.files=Files:
-invokerServlet.allocate=Cannot allocate servlet instance for path {0}
-invokerServlet.cannotCreate=Cannot create servlet wrapper for path {0}
-invokerServlet.deallocate=Cannot deallocate servlet instance for path {0}
-invokerServlet.invalidPath=No servlet name or class was specified in path {0}
-invokerServlet.notNamed=Cannot call invoker servlet with a named dispatcher
-invokerServlet.noWrapper=Container has not called setWrapper() for this servlet
webdavservlet.jaxpfailed=JAXP initialization failed
directory.filename=Filename
directory.lastModified=Last Modified
15 years, 2 months
JBossWeb SVN: r1193 - in trunk/java/javax/servlet: http and 1 other directory.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2009-10-14 07:57:52 -0400 (Wed, 14 Oct 2009)
New Revision: 1193
Modified:
trunk/java/javax/servlet/HttpConstraintElement.java
trunk/java/javax/servlet/ServletContextAttributeListener.java
trunk/java/javax/servlet/ServletContextListener.java
trunk/java/javax/servlet/ServletRequestAttributeListener.java
trunk/java/javax/servlet/ServletRequestListener.java
trunk/java/javax/servlet/http/HttpServletRequest.java
trunk/java/javax/servlet/http/HttpServletResponse.java
trunk/java/javax/servlet/http/HttpSessionAttributeListener.java
trunk/java/javax/servlet/http/HttpSessionListener.java
Log:
- Cosmetic spec update.
Modified: trunk/java/javax/servlet/HttpConstraintElement.java
===================================================================
--- trunk/java/javax/servlet/HttpConstraintElement.java 2009-10-11 17:55:58 UTC (rev 1192)
+++ trunk/java/javax/servlet/HttpConstraintElement.java 2009-10-14 11:57:52 UTC (rev 1193)
@@ -55,9 +55,7 @@
* Constructs a default HTTP constraint element
*/
public HttpConstraintElement() {
- this.emptyRoleSemantic = EmptyRoleSemantic.PERMIT;
- this.transportGuarantee = TransportGuarantee.NONE;
- rolesAllowed = new String[0];
+ this(EmptyRoleSemantic.PERMIT);
}
/**
@@ -66,9 +64,7 @@
* @param semantic should be EmptyRoleSemantic.DENY
*/
public HttpConstraintElement(EmptyRoleSemantic semantic) {
- this.emptyRoleSemantic = semantic;
- this.transportGuarantee = TransportGuarantee.NONE;
- rolesAllowed = new String[0];
+ this(semantic, TransportGuarantee.NONE, new String[0]);
}
/**
@@ -82,9 +78,7 @@
*/
public HttpConstraintElement(TransportGuarantee guarantee,
String... roleNames) {
- this.emptyRoleSemantic = EmptyRoleSemantic.PERMIT;
- this.transportGuarantee = guarantee;
- this.rolesAllowed = roleNames;
+ this(EmptyRoleSemantic.PERMIT, guarantee, roleNames);
}
/**
Modified: trunk/java/javax/servlet/ServletContextAttributeListener.java
===================================================================
--- trunk/java/javax/servlet/ServletContextAttributeListener.java 2009-10-11 17:55:58 UTC (rev 1192)
+++ trunk/java/javax/servlet/ServletContextAttributeListener.java 2009-10-14 11:57:52 UTC (rev 1193)
@@ -62,8 +62,9 @@
*
* <p>In order to receive these notification events, the implementation
* class must be either declared in the deployment descriptor of the web
- * application or annotated with
- * {@link javax.servlet.annotation.WebListener}.
+ * application, annotated with {@link javax.servlet.annotation.WebListener},
+ * or registered via one of the addListener methods defined on
+ * {@link ServletContext}.
*
* <p>The order in which implementations of this interface are invoked is
* unspecified.
Modified: trunk/java/javax/servlet/ServletContextListener.java
===================================================================
--- trunk/java/javax/servlet/ServletContextListener.java 2009-10-11 17:55:58 UTC (rev 1192)
+++ trunk/java/javax/servlet/ServletContextListener.java 2009-10-14 11:57:52 UTC (rev 1193)
@@ -62,8 +62,9 @@
*
* <p>In order to receive these notification events, the implementation
* class must be either declared in the deployment descriptor of the web
- * application or annotated with
- * {@link javax.servlet.annotation.WebListener}.
+ * application, annotated with {@link javax.servlet.annotation.WebListener},
+ * or registered via one of the addListener methods defined on
+ * {@link ServletContext}.
*
* <p>Implementations of this interface are invoked at their
* {@link #contextInitialized} method in the order in which they have been
Modified: trunk/java/javax/servlet/ServletRequestAttributeListener.java
===================================================================
--- trunk/java/javax/servlet/ServletRequestAttributeListener.java 2009-10-11 17:55:58 UTC (rev 1192)
+++ trunk/java/javax/servlet/ServletRequestAttributeListener.java 2009-10-14 11:57:52 UTC (rev 1193)
@@ -69,8 +69,9 @@
*
* <p>In order to receive these notification events, the implementation
* class must be either declared in the deployment descriptor of the web
- * application or annotated with
- * {@link javax.servlet.annotation.WebListener}.
+ * application, annotated with {@link javax.servlet.annotation.WebListener},
+ * or registered via one of the addListener methods defined on
+ * {@link ServletContext}.
*
* <p>The order in which implementations of this interface are invoked is
* unspecified.
Modified: trunk/java/javax/servlet/ServletRequestListener.java
===================================================================
--- trunk/java/javax/servlet/ServletRequestListener.java 2009-10-11 17:55:58 UTC (rev 1192)
+++ trunk/java/javax/servlet/ServletRequestListener.java 2009-10-14 11:57:52 UTC (rev 1193)
@@ -67,8 +67,9 @@
*
* <p>In order to receive these notification events, the implementation
* class must be either declared in the deployment descriptor of the web
- * application or annotated with
- * {@link javax.servlet.annotation.WebListener}.
+ * application, annotated with {@link javax.servlet.annotation.WebListener},
+ * or registered via one of the addListener methods defined on
+ * {@link ServletContext}.
*
* <p>Implementations of this interface are invoked at their
* {@link #requestInitialized} method in the order in which they have been
Modified: trunk/java/javax/servlet/http/HttpServletRequest.java
===================================================================
--- trunk/java/javax/servlet/http/HttpServletRequest.java 2009-10-11 17:55:58 UTC (rev 1192)
+++ trunk/java/javax/servlet/http/HttpServletRequest.java 2009-10-14 11:57:52 UTC (rev 1193)
@@ -727,16 +727,16 @@
* login mechanism has committed, in the response, the message (e.g.,
* challenge) and HTTP status code to be returned to the user.
*
- * @exception IOException if an error occurs while writing
- * the response.
+ * @throws IOException if an input or output error occurred while
+ * reading from this request or writing to the given response
*
- * @exception ServletException if the authentication failed and
- * the caller is responsible for
- * handling the error (i.e., the
- * underlying login mechanism did
- * NOT establish the message and
- * HTTP status code to be returned
- * to the user).
+ * @throws IllegalStateException if the login mechanism attempted to
+ * modify the response and it was already committed
+ *
+ * @throws ServletException if the authentication failed and
+ * the caller is responsible for handling the error (i.e., the
+ * underlying login mechanism did NOT establish the message and
+ * HTTP status code to be returned to the user)
*
* @since Servlet 3.0
*/
Modified: trunk/java/javax/servlet/http/HttpServletResponse.java
===================================================================
--- trunk/java/javax/servlet/http/HttpServletResponse.java 2009-10-11 17:55:58 UTC (rev 1192)
+++ trunk/java/javax/servlet/http/HttpServletResponse.java 2009-10-14 11:57:52 UTC (rev 1193)
@@ -171,14 +171,16 @@
/**
* Sends an error response to the client using the specified
- * status. The server defaults to creating the
+ * status and clears the buffer. The server defaults to creating the
* response to look like an HTML-formatted server error page
* containing the specified message, setting the content type
- * to "text/html", leaving cookies and other headers unmodified.
+ * to "text/html". The server will preserve cookies and may clear or
+ * update any headers needed to serve the error page as a valid response.
*
* If an error-page declaration has been made for the web application
* corresponding to the status code passed in, it will be served back in
- * preference to the suggested msg parameter.
+ * preference to the suggested msg parameter and the msg parameter will
+ * be ignored.
*
* <p>If the response has already been committed, this method throws
* an IllegalStateException.
@@ -195,7 +197,15 @@
/**
* Sends an error response to the client using the specified status
- * code and clearing the buffer.
+ * code and clears the buffer.
+ *
+ * The server will preserve cookies and may clear or
+ * update any headers needed to serve the error page as a valid response.
+ *
+ * If an error-page declaration has been made for the web application
+ * corresponding to the status code passed in, it will be served back
+ * the error page
+ *
* <p>If the response has already been committed, this method throws
* an IllegalStateException.
* After using this method, the response should be considered
@@ -211,8 +221,11 @@
/**
* Sends a temporary redirect response to the client using the
- * specified redirect location URL. This method can accept relative URLs;
- * the servlet container must convert the relative URL to an absolute URL
+ * specified redirect location URL and clears the buffer. The buffer will
+ * be replaced with the data set by this method. Calling this method sets the
+ * status code to {@link #SC_FOUND} 302 (Found).
+ * This method can accept relative URLs;the servlet container must convert
+ * the relative URL to an absolute URL
* before sending the response to the client. If the location is relative
* without a leading '/' the container interprets it as relative to
* the current request URI. If the location is relative with a leading
@@ -330,15 +343,22 @@
/**
- * Sets the status code for this response. This method is used to
- * set the return status code when there is no error (for example,
- * for the status codes SC_OK or SC_MOVED_TEMPORARILY). If there
- * is an error, and the caller wishes to invoke an error-page defined
- * in the web application, the <code>sendError</code> method should be used
- * instead.
- * <p> The container clears the buffer and sets the Location header, preserving
- * cookies and other headers.
+ * Sets the status code for this response.
*
+ * <p>This method is used to set the return status code when there is
+ * no error (for example, for the SC_OK or SC_MOVED_TEMPORARILY status
+ * codes).
+ *
+ * <p>If this method is used to set an error code, then the container's
+ * error page mechanism will not be triggered. If there is an error and
+ * the caller wishes to invoke an error page defined in the web
+ * application, then {@link #sendError} must be used instead.
+ *
+ * <p>This method preserves any cookies and other response headers.
+ *
+ * <p>Valid status codes are those in the 2XX, 3XX, 4XX, and 5XX ranges.
+ * Other status codes are treated as container specific.
+ *
* @param sc the status code
*
* @see #sendError
Modified: trunk/java/javax/servlet/http/HttpSessionAttributeListener.java
===================================================================
--- trunk/java/javax/servlet/http/HttpSessionAttributeListener.java 2009-10-11 17:55:58 UTC (rev 1192)
+++ trunk/java/javax/servlet/http/HttpSessionAttributeListener.java 2009-10-14 11:57:52 UTC (rev 1193)
@@ -62,8 +62,9 @@
*
* <p>In order to receive these notification events, the implementation
* class must be either declared in the deployment descriptor of the web
- * application or annotated with
- * {@link javax.servlet.annotation.WebListener}.
+ * application, annotated with {@link javax.servlet.annotation.WebListener},
+ * or registered via one of the addListener methods defined on
+ * {@link javax.servlet.ServletContext}.
*
* <p>The order in which implementations of this interface are invoked is
* unspecified.
Modified: trunk/java/javax/servlet/http/HttpSessionListener.java
===================================================================
--- trunk/java/javax/servlet/http/HttpSessionListener.java 2009-10-11 17:55:58 UTC (rev 1192)
+++ trunk/java/javax/servlet/http/HttpSessionListener.java 2009-10-14 11:57:52 UTC (rev 1193)
@@ -62,8 +62,9 @@
*
* <p>In order to receive these notification events, the implementation
* class must be either declared in the deployment descriptor of the web
- * application or annotated with
- * {@link javax.servlet.annotation.WebListener}.
+ * application, annotated with {@link javax.servlet.annotation.WebListener},
+ * or registered via one of the addListener methods defined on
+ * {@link javax.servlet.ServletContext}.
*
* <p>Implementations of this interface are invoked at their
* {@link #sessionCreated} method in the order in which they have been
15 years, 2 months
JBossWeb SVN: r1192 - in trunk/java/org/apache: catalina/core and 1 other directories.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2009-10-11 13:55:58 -0400 (Sun, 11 Oct 2009)
New Revision: 1192
Modified:
trunk/java/org/apache/catalina/connector/Request.java
trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java
trunk/java/org/apache/catalina/core/LocalStrings.properties
trunk/java/org/apache/catalina/core/StandardWrapperFacade.java
trunk/java/org/apache/tomcat/util/http/fileupload/DefaultFileItemFactory.java
trunk/java/org/apache/tomcat/util/http/fileupload/DiskFileUpload.java
Log:
- Add error conditions for the registrations.
- Move around some fixmes.
Modified: trunk/java/org/apache/catalina/connector/Request.java
===================================================================
--- trunk/java/org/apache/catalina/connector/Request.java 2009-10-10 01:01:00 UTC (rev 1191)
+++ trunk/java/org/apache/catalina/connector/Request.java 2009-10-11 17:55:58 UTC (rev 1192)
@@ -66,6 +66,7 @@
import javax.security.auth.Subject;
import javax.servlet.AsyncContext;
+import javax.servlet.AsyncEvent;
import javax.servlet.AsyncListener;
import javax.servlet.DispatcherType;
import javax.servlet.RequestDispatcher;
@@ -2414,6 +2415,9 @@
public void setTimeout(int timeout) {
coyoteRequest.action(ActionCode.ACTION_EVENT_TIMEOUT, timeout);
}
+ public void setTimeout0(int timeout) {
+ setTimeout(timeout);
+ }
public void resume() {
@@ -2789,8 +2793,7 @@
fu.setSizeMax(config.getMaxRequestSize());
}
if (config.getMaxFileSize() > 0) {
- // FIXME: Unimplemented per file max size
- //fu.setSizeFileMax(config.getMaxFileSize());
+ fu.setFileSizeMax(config.getMaxFileSize());
}
parts = new HashMap<String, Part>();
@@ -3005,25 +3008,24 @@
public AsyncContext startAsync(ServletRequest servletRequest,
ServletResponse servletResponse) throws IllegalStateException {
- /* TODO
- * <p>This method clears the list of {@link AsyncListener} instances
- * (if any) that were registered with the AsyncContext returned by the
- * previous call to one of the startAsync methods, after calling each
- * AsyncListener at its {@link AsyncListener#onStartAsync onStartAsync}
- * method.
- */
- int timeout = (asyncTimeout > Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int) asyncTimeout;
- if (timeout <= 0) {
- timeout = Integer.MAX_VALUE;
- }
if (CHECK_ASYNC && !isAsyncSupported()) {
throw new IllegalStateException(sm.getString("coyoteRequest.noAsync"));
}
// FIXME: if (asyncContext != null && !processing) { throw ISE }
+ LinkedHashMap<AsyncListener, AsyncListenerRegistration> localAsyncListeners = asyncListeners;
+ asyncListeners = new LinkedHashMap<AsyncListener, AsyncListenerRegistration>();
+ for (AsyncListenerRegistration registration : localAsyncListeners.values()) {
+ AsyncListener asyncListener = registration.getListener();
+ AsyncEvent asyncEvent = new AsyncEvent(asyncContext, registration.getRequest(), registration.getResponse());
+ try {
+ asyncListener.onStartAsync(asyncEvent);
+ } catch (IOException e) {
+ // FIXME: error reporting ? throw new IllegalStateException(e);
+ }
+ }
if (response.isClosed()) {
throw new IllegalStateException(sm.getString("coyoteRequest.closed"));
}
- setTimeout(timeout);
if (asyncContext == null) {
asyncContext = new AsyncContextImpl();
eventMode = true;
@@ -3286,6 +3288,11 @@
public void setTimeout(long timeout) {
asyncTimeout = timeout;
+ int realTimeout = (asyncTimeout > Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int) asyncTimeout;
+ if (realTimeout <= 0) {
+ realTimeout = Integer.MAX_VALUE;
+ }
+ setTimeout0(realTimeout);
}
}
Modified: trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java
===================================================================
--- trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java 2009-10-10 01:01:00 UTC (rev 1191)
+++ trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java 2009-10-11 17:55:58 UTC (rev 1192)
@@ -266,15 +266,20 @@
public boolean addMappingForServletNames(EnumSet<DispatcherType> dispatcherTypes,
boolean isMatchAfter, String... servletNames) {
if (context.isInitialized()) {
- throw new IllegalStateException(sm.getString("filterRegistration.addFilterMapping.ise", context.getPath()));
+ throw new IllegalStateException(sm.getString("filterRegistration.ise", context.getPath()));
}
+ if (servletNames == null || servletNames.length == 0) {
+ throw new IllegalArgumentException(sm.getString("filterRegistration.iae"));
+ }
FilterMap filterMap = new FilterMap();
for (String servletName : servletNames) {
filterMap.addServletName(servletName);
}
filterMap.setFilterName(filterDef.getFilterName());
- for (DispatcherType dispatcherType: dispatcherTypes) {
- filterMap.setDispatcher(dispatcherType.name());
+ if (dispatcherTypes != null) {
+ for (DispatcherType dispatcherType: dispatcherTypes) {
+ filterMap.setDispatcher(dispatcherType.name());
+ }
}
if (isMatchAfter) {
context.addFilterMap(filterMap);
@@ -289,15 +294,20 @@
EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter,
String... urlPatterns) {
if (context.isInitialized()) {
- throw new IllegalStateException(sm.getString("filterRegistration.addFilterMapping.ise", context.getPath()));
+ throw new IllegalStateException(sm.getString("filterRegistration.ise", context.getPath()));
}
+ if (urlPatterns == null || urlPatterns.length == 0) {
+ throw new IllegalArgumentException(sm.getString("filterRegistration.iae"));
+ }
FilterMap filterMap = new FilterMap();
for (String urlPattern : urlPatterns) {
filterMap.addURLPattern(urlPattern);
}
filterMap.setFilterName(filterDef.getFilterName());
- for (DispatcherType dispatcherType: dispatcherTypes) {
- filterMap.setDispatcher(dispatcherType.name());
+ if (dispatcherTypes != null) {
+ for (DispatcherType dispatcherType: dispatcherTypes) {
+ filterMap.setDispatcher(dispatcherType.name());
+ }
}
if (isMatchAfter) {
context.addFilterMap(filterMap);
@@ -347,6 +357,9 @@
public void setAsyncSupported(boolean asyncSupported) {
+ if (context.isInitialized()) {
+ throw new IllegalStateException(sm.getString("filterRegistration.ise", context.getPath()));
+ }
filterDef.setAsyncSupported(asyncSupported);
context.addFilterDef(filterDef);
}
@@ -359,6 +372,12 @@
public boolean setInitParameter(String name, String value) {
+ if (context.isInitialized()) {
+ throw new IllegalStateException(sm.getString("filterRegistration.ise", context.getPath()));
+ }
+ if (name == null || value == null) {
+ throw new IllegalArgumentException(sm.getString("filterRegistration.iae"));
+ }
if (filterDef.getInitParameter(name) != null) {
return false;
}
@@ -369,6 +388,12 @@
public Set<String> setInitParameters(Map<String, String> initParameters) {
+ if (context.isInitialized()) {
+ throw new IllegalStateException(sm.getString("filterRegistration.ise", context.getPath()));
+ }
+ if (initParameters == null) {
+ throw new IllegalArgumentException(sm.getString("filterRegistration.iae"));
+ }
Set<String> conflicts = new HashSet<String>();
Iterator<String> parameterNames = initParameters.keySet().iterator();
while (parameterNames.hasNext()) {
@@ -376,7 +401,11 @@
if (filterDef.getInitParameter(parameterName) != null) {
conflicts.add(parameterName);
} else {
- filterDef.addInitParameter(parameterName, initParameters.get(parameterName));
+ String value = initParameters.get(parameterName);
+ if (value == null) {
+ throw new IllegalArgumentException(sm.getString("filterRegistration.iae"));
+ }
+ filterDef.addInitParameter(parameterName, value);
}
}
context.addFilterDef(filterDef);
Modified: trunk/java/org/apache/catalina/core/LocalStrings.properties
===================================================================
--- trunk/java/org/apache/catalina/core/LocalStrings.properties 2009-10-10 01:01:00 UTC (rev 1191)
+++ trunk/java/org/apache/catalina/core/LocalStrings.properties 2009-10-11 17:55:58 UTC (rev 1192)
@@ -233,5 +233,7 @@
defaultInstanceManager.privilegedFilter=Filter of class {0} is privileged and cannot be loaded by this web application
defaultInstanceManager.restrictedListenersResources="Restricted listeners property file not found
-filterRegistration.addFilterMapping.ise=Filter mappings can not be added to context {0} at this time. See SRV.4.4.
-servletRegistration.addServletMapping.ise=Servlet mappings can not be added to context {0} at this time. See SRV.4.4.
+filterRegistration.ise=Context {0} has already been initialized.
+filterRegistration.iae=Illegal null or empty argument specified
+servletRegistration.ise=Context {0} has already been initialized.
+servletRegistration.iae=Illegal null or empty argument specified
Modified: trunk/java/org/apache/catalina/core/StandardWrapperFacade.java
===================================================================
--- trunk/java/org/apache/catalina/core/StandardWrapperFacade.java 2009-10-10 01:01:00 UTC (rev 1191)
+++ trunk/java/org/apache/catalina/core/StandardWrapperFacade.java 2009-10-11 17:55:58 UTC (rev 1192)
@@ -156,15 +156,16 @@
Set<String> conflicts = new HashSet<String>();
if (((Context) wrapper.getParent()).isInitialized()) {
throw new IllegalStateException(sm.getString
- ("servletRegistration.addServletMapping.ise", ((Context) wrapper.getParent()).getPath()));
+ ("servletRegistration.ise", ((Context) wrapper.getParent()).getPath()));
}
- if (urlPatterns != null) {
- for (int i = 0; i < urlPatterns.length; i++) {
- if (((Context) wrapper.getParent()).findServletMapping(urlPatterns[i]) != null) {
- conflicts.add(urlPatterns[i]);
- } else {
- ((Context) wrapper.getParent()).addServletMapping(urlPatterns[i], wrapper.getName());
- }
+ if (urlPatterns == null || urlPatterns.length == 0) {
+ throw new IllegalArgumentException(sm.getString("servletRegistration.iae"));
+ }
+ for (String urlPattern : urlPatterns) {
+ if (((Context) wrapper.getParent()).findServletMapping(urlPattern) != null) {
+ conflicts.add(urlPattern);
+ } else {
+ ((Context) wrapper.getParent()).addServletMapping(urlPattern, wrapper.getName());
}
}
return conflicts;
@@ -172,6 +173,10 @@
public void setAsyncSupported(boolean asyncSupported) {
+ if (((Context) wrapper.getParent()).isInitialized()) {
+ throw new IllegalStateException(sm.getString
+ ("servletRegistration.ise", ((Context) wrapper.getParent()).getPath()));
+ }
wrapper.setAsyncSupported(asyncSupported);
}
@@ -182,12 +187,30 @@
public boolean setInitParameter(String name, String value) {
- wrapper.addInitParameter(name, value);
- return true;
+ if (((Context) wrapper.getParent()).isInitialized()) {
+ throw new IllegalStateException(sm.getString
+ ("servletRegistration.ise", ((Context) wrapper.getParent()).getPath()));
+ }
+ if (name == null || value == null) {
+ throw new IllegalArgumentException(sm.getString("servletRegistration.iae"));
+ }
+ if (wrapper.findInitParameter(name) == null) {
+ wrapper.addInitParameter(name, value);
+ return true;
+ } else {
+ return false;
+ }
}
public Set<String> setInitParameters(Map<String, String> initParameters) {
+ if (((Context) wrapper.getParent()).isInitialized()) {
+ throw new IllegalStateException(sm.getString
+ ("servletRegistration.ise", ((Context) wrapper.getParent()).getPath()));
+ }
+ if (initParameters == null) {
+ throw new IllegalArgumentException(sm.getString("servletRegistration.iae"));
+ }
Set<String> conflicts = new HashSet<String>();
Iterator<String> parameterNames = initParameters.keySet().iterator();
while (parameterNames.hasNext()) {
@@ -195,7 +218,11 @@
if (wrapper.findInitParameter(parameterName) != null) {
conflicts.add(parameterName);
} else {
- wrapper.addInitParameter(parameterName, initParameters.get(parameterName));
+ String value = initParameters.get(parameterName);
+ if (value == null) {
+ throw new IllegalArgumentException(sm.getString("servletRegistration.iae"));
+ }
+ wrapper.addInitParameter(parameterName, value);
}
}
return conflicts;
@@ -203,6 +230,10 @@
public void setLoadOnStartup(int loadOnStartup) {
+ if (((Context) wrapper.getParent()).isInitialized()) {
+ throw new IllegalStateException(sm.getString
+ ("servletRegistration.ise", ((Context) wrapper.getParent()).getPath()));
+ }
wrapper.setLoadOnStartup(loadOnStartup);
}
@@ -242,14 +273,35 @@
}
public void setRunAsRole(String roleName) {
+ if (((Context) wrapper.getParent()).isInitialized()) {
+ throw new IllegalStateException(sm.getString
+ ("servletRegistration.ise", ((Context) wrapper.getParent()).getPath()));
+ }
+ if (roleName == null) {
+ throw new IllegalArgumentException(sm.getString("servletRegistration.iae"));
+ }
wrapper.setRunAs(roleName);
}
public void setServletSecurity(ServletSecurityElement servletSecurity) {
+ if (((Context) wrapper.getParent()).isInitialized()) {
+ throw new IllegalStateException(sm.getString
+ ("servletRegistration.ise", ((Context) wrapper.getParent()).getPath()));
+ }
+ if (servletSecurity == null) {
+ throw new IllegalArgumentException(sm.getString("servletRegistration.iae"));
+ }
wrapper.setServletSecurity(servletSecurity);
}
public void setMultipartConfig(MultipartConfigElement multipartConfig) {
+ if (((Context) wrapper.getParent()).isInitialized()) {
+ throw new IllegalStateException(sm.getString
+ ("servletRegistration.ise", ((Context) wrapper.getParent()).getPath()));
+ }
+ if (multipartConfig == null) {
+ throw new IllegalArgumentException(sm.getString("servletRegistration.iae"));
+ }
Multipart multipart = new Multipart();
multipart.setLocation(multipartConfig.getLocation());
multipart.setMaxFileSize(multipartConfig.getMaxFileSize());
Modified: trunk/java/org/apache/tomcat/util/http/fileupload/DefaultFileItemFactory.java
===================================================================
--- trunk/java/org/apache/tomcat/util/http/fileupload/DefaultFileItemFactory.java 2009-10-10 01:01:00 UTC (rev 1191)
+++ trunk/java/org/apache/tomcat/util/http/fileupload/DefaultFileItemFactory.java 2009-10-11 17:55:58 UTC (rev 1192)
@@ -56,6 +56,12 @@
public static final int DEFAULT_SIZE_THRESHOLD = 10240;
+ /**
+ * The default max size for a file.
+ */
+ public static final int DEFAULT_FILE_SIZE_MAX = -1;
+
+
// ----------------------------------------------------- Instance Variables
@@ -71,6 +77,12 @@
private int sizeThreshold = DEFAULT_SIZE_THRESHOLD;
+ /**
+ * The max file size.
+ */
+ private long fileSizeMax = DEFAULT_FILE_SIZE_MAX;
+
+
// ----------------------------------------------------------- Constructors
@@ -161,6 +173,32 @@
}
+ /**
+ * Returns the max size of a file.
+ *
+ * @return The size, in bytes.
+ *
+ * @see #setFileSizeMax(int)
+ */
+ public long getFileSizeMax()
+ {
+ return fileSizeMax;
+ }
+
+
+ /**
+ * Sets the max size of a file.
+ *
+ * @param fileSizeMax The size, in bytes.
+ *
+ * @see #getSizeThreshold()
+ */
+ public void setFileSizeMax(long fileSizeMax)
+ {
+ this.fileSizeMax = fileSizeMax;
+ }
+
+
// --------------------------------------------------------- Public Methods
/**
@@ -185,6 +223,7 @@
Map<String, String> headers
)
{
+ // FIXME: Add file size max
return new DefaultFileItem(fieldName, contentType,
isFormField, fileName, headers, sizeThreshold, repository);
}
Modified: trunk/java/org/apache/tomcat/util/http/fileupload/DiskFileUpload.java
===================================================================
--- trunk/java/org/apache/tomcat/util/http/fileupload/DiskFileUpload.java 2009-10-10 01:01:00 UTC (rev 1191)
+++ trunk/java/org/apache/tomcat/util/http/fileupload/DiskFileUpload.java 2009-10-11 17:55:58 UTC (rev 1192)
@@ -171,6 +171,32 @@
}
+ /**
+ * Returns the max size of a file.
+ *
+ * @return The size, in bytes.
+ *
+ * @see #setFileSizeMax(long)
+ */
+ public long getFileSizeMax()
+ {
+ return fileItemFactory.getFileSizeMax();
+ }
+
+
+ /**
+ * Sets the max size of a file.
+ *
+ * @param fileSizeMax The size, in bytes.
+ *
+ * @see #getSizeThreshold()
+ */
+ public void setFileSizeMax(long fileSizeMax)
+ {
+ fileItemFactory.setFileSizeMax(fileSizeMax);
+ }
+
+
// --------------------------------------------------------- Public methods
15 years, 2 months
JBossWeb SVN: r1191 - trunk/java/javax/servlet.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2009-10-09 21:01:00 -0400 (Fri, 09 Oct 2009)
New Revision: 1191
Modified:
trunk/java/javax/servlet/ServletContext.java
Log:
- Javadoc update.
Modified: trunk/java/javax/servlet/ServletContext.java
===================================================================
--- trunk/java/javax/servlet/ServletContext.java 2009-10-09 16:06:15 UTC (rev 1190)
+++ trunk/java/javax/servlet/ServletContext.java 2009-10-10 01:01:00 UTC (rev 1191)
@@ -1512,6 +1512,12 @@
*
* @param roleNames the role names being declared
*
+ * @throws UnsupportedOperationException if this ServletContext was
+ * passed to the {@link ServletContextListener#contextInitialized} method
+ * of a {@link ServletContextListener} that was neither declared in
+ * <code>web.xml</code> or <code>web-fragment.xml</code>, nor annotated
+ * with {@link javax.servlet.annotation.WebListener}
+ *
* @throws IllegalArgumentException if any of the argument roleNames is
* null or the empty string
*
15 years, 2 months
JBossWeb SVN: r1190 - trunk/java/org/apache/catalina/ha/backend.
by jbossweb-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2009-10-09 12:06:15 -0400 (Fri, 09 Oct 2009)
New Revision: 1190
Modified:
trunk/java/org/apache/catalina/ha/backend/CollectedInfo.java
trunk/java/org/apache/catalina/ha/backend/HeartbeatListener.java
trunk/java/org/apache/catalina/ha/backend/MultiCastSender.java
trunk/java/org/apache/catalina/ha/backend/TcpSender.java
Log:
Add a local bind otherwise for box with multi IP httpd may use the wrong port.
Modified: trunk/java/org/apache/catalina/ha/backend/CollectedInfo.java
===================================================================
--- trunk/java/org/apache/catalina/ha/backend/CollectedInfo.java 2009-10-09 16:01:52 UTC (rev 1189)
+++ trunk/java/org/apache/catalina/ha/backend/CollectedInfo.java 2009-10-09 16:06:15 UTC (rev 1190)
@@ -44,11 +44,15 @@
int ready;
int busy;
+ int port = 0;
+ String host = null;
+
public CollectedInfo(String host, int port) throws Exception {
init(host, port);
}
public void init(String host, int port) throws Exception {
- String sport = Integer.toString(port);
+ int iport = 0;
+ String shost = null;
mBeanServer = Registry.getRegistry(null, null).getMBeanServer();
String onStr = "*:type=ThreadPool,*";
ObjectName objectName = new ObjectName(onStr);
@@ -58,24 +62,29 @@
ObjectInstance oi = iterator.next();
objName = oi.getObjectName();
String name = objName.getKeyProperty("name");
+
/* Name are:
* http-8080
* jk-10.33.144.3-8009
* jk-jfcpc%2F10.33.144.3-8009
*/
+ String [] elenames = name.split("-");
+ String sport = elenames[elenames.length-1];
+ iport = Integer.parseInt(sport);
+ String [] shosts = elenames[1].split("%2F");
+ shost = shosts[0];
+
if (port==0 && host==null)
break; /* Take the first one */
- String [] elenames = name.split("-");
- if (elenames[elenames.length-1].compareTo(sport) != 0)
- continue; /* port doesn't match */
- if (host==null)
+ if (host==null && iport==port)
break; /* Only port done */
- String [] shosts = elenames[1].split("%2F");
- if (shosts[0].compareTo(host) == 0)
+ if (shost.compareTo(host) == 0)
break; /* Done port and host are the expected ones */
}
if (objName == null)
- throw(new Exception("Can't find connector for " + host + ":" + sport));
+ throw(new Exception("Can't find connector for " + host + ":" + port));
+ this.port = iport;
+ this.host = shost;
}
Modified: trunk/java/org/apache/catalina/ha/backend/HeartbeatListener.java
===================================================================
--- trunk/java/org/apache/catalina/ha/backend/HeartbeatListener.java 2009-10-09 16:01:52 UTC (rev 1189)
+++ trunk/java/org/apache/catalina/ha/backend/HeartbeatListener.java 2009-10-09 16:06:15 UTC (rev 1190)
@@ -85,27 +85,32 @@
sender = new MultiCastSender();
else
sender = new TcpSender();
-
- try {
- sender.init(this);
- } catch (Exception ex) {
- log.error("Unable to initialize Sender: " + ex);
- sender = null;
- return;
- }
}
/* Read busy and ready */
if (coll == null) {
try {
coll = new CollectedInfo(host, port);
+ this.port = coll.port;
+ this.host = coll.host;
} catch (Exception ex) {
log.error("Unable to initialize info collection: " + ex);
coll = null;
return;
}
}
+
+ /* Start or restart sender */
try {
+ sender.init(this);
+ } catch (Exception ex) {
+ log.error("Unable to initialize Sender: " + ex);
+ sender = null;
+ return;
+ }
+
+ /* refresh the connector information and send it */
+ try {
coll.refresh();
} catch (Exception ex) {
log.error("Unable to collect load information: " + ex);
Modified: trunk/java/org/apache/catalina/ha/backend/MultiCastSender.java
===================================================================
--- trunk/java/org/apache/catalina/ha/backend/MultiCastSender.java 2009-10-09 16:01:52 UTC (rev 1189)
+++ trunk/java/org/apache/catalina/ha/backend/MultiCastSender.java 2009-10-09 16:06:15 UTC (rev 1190)
@@ -22,6 +22,7 @@
import java.net.MulticastSocket;
import java.net.InetAddress;
+import java.net.InetSocketAddress;
import java.net.DatagramPacket;
import java.io.UnsupportedEncodingException;
@@ -47,7 +48,13 @@
if (s == null) {
try {
group = InetAddress.getByName(config.getGroup());
- s = new MulticastSocket(config.getMultiport());
+ if (config.host != null) {
+ InetAddress addr = InetAddress.getByName(config.host);
+ InetSocketAddress addrs = new InetSocketAddress(addr, config.getMultiport());
+ s = new MulticastSocket(addrs);
+ } else
+ s = new MulticastSocket(config.getMultiport());
+
s.setTimeToLive(config.getTtl());
s.joinGroup(group);
} catch (Exception ex) {
Modified: trunk/java/org/apache/catalina/ha/backend/TcpSender.java
===================================================================
--- trunk/java/org/apache/catalina/ha/backend/TcpSender.java 2009-10-09 16:01:52 UTC (rev 1189)
+++ trunk/java/org/apache/catalina/ha/backend/TcpSender.java 2009-10-09 16:06:15 UTC (rev 1190)
@@ -26,6 +26,7 @@
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.InetAddress;
+import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.StringTokenizer;
@@ -89,7 +90,16 @@
for (int i = 0; i < connections.length; i++) {
if (connections[i] == null) {
try {
- connections[i] = new Socket(proxies[i].address, proxies[i].port);
+ if (config.host != null) {
+ connections[i] = new Socket();
+ InetAddress addr = InetAddress.getByName(config.host);
+ InetSocketAddress addrs = new InetSocketAddress(addr, 0);
+ connections[i].setReuseAddress(true);
+ connections[i].bind(addrs);
+ addrs = new InetSocketAddress(proxies[i].address, proxies[i].port);
+ connections[i].connect(addrs);
+ } else
+ connections[i] = new Socket(proxies[i].address, proxies[i].port);
connectionReaders[i] = new BufferedReader(new InputStreamReader(connections[i].getInputStream()));
connectionWriters[i] = new BufferedWriter(new OutputStreamWriter(connections[i].getOutputStream()));
} catch (Exception ex) {
15 years, 2 months
JBossWeb SVN: r1189 - tags.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2009-10-09 12:01:52 -0400 (Fri, 09 Oct 2009)
New Revision: 1189
Added:
tags/JBOSSWEB_3_0_0_ALPHA7/
Log:
- Note: no alpha 6 (used for a custom Servlet API build).
Copied: tags/JBOSSWEB_3_0_0_ALPHA7 (from rev 1188, trunk)
15 years, 2 months
JBossWeb SVN: r1188 - branches/2.1.x/java/org/apache/catalina/ha/backend.
by jbossweb-commits@lists.jboss.org
Author: jfrederic.clere(a)jboss.com
Date: 2009-10-09 11:54:26 -0400 (Fri, 09 Oct 2009)
New Revision: 1188
Modified:
branches/2.1.x/java/org/apache/catalina/ha/backend/CollectedInfo.java
branches/2.1.x/java/org/apache/catalina/ha/backend/HeartbeatListener.java
branches/2.1.x/java/org/apache/catalina/ha/backend/MultiCastSender.java
branches/2.1.x/java/org/apache/catalina/ha/backend/TcpSender.java
Log:
Add a local bind for box with multi IP otherwise httpd may use the wrong port.
Modified: branches/2.1.x/java/org/apache/catalina/ha/backend/CollectedInfo.java
===================================================================
--- branches/2.1.x/java/org/apache/catalina/ha/backend/CollectedInfo.java 2009-10-09 15:06:35 UTC (rev 1187)
+++ branches/2.1.x/java/org/apache/catalina/ha/backend/CollectedInfo.java 2009-10-09 15:54:26 UTC (rev 1188)
@@ -44,11 +44,15 @@
int ready;
int busy;
+ int port = 0;
+ String host = null;
+
public CollectedInfo(String host, int port) throws Exception {
init(host, port);
}
public void init(String host, int port) throws Exception {
- String sport = Integer.toString(port);
+ int iport = 0;
+ String shost = null;
mBeanServer = Registry.getRegistry(null, null).getMBeanServer();
String onStr = "*:type=ThreadPool,*";
ObjectName objectName = new ObjectName(onStr);
@@ -58,24 +62,29 @@
ObjectInstance oi = iterator.next();
objName = oi.getObjectName();
String name = objName.getKeyProperty("name");
+
/* Name are:
* http-8080
* jk-10.33.144.3-8009
* jk-jfcpc%2F10.33.144.3-8009
*/
+ String [] elenames = name.split("-");
+ String sport = elenames[elenames.length-1];
+ iport = Integer.parseInt(sport);
+ String [] shosts = elenames[1].split("%2F");
+ shost = shosts[0];
+
if (port==0 && host==null)
break; /* Take the first one */
- String [] elenames = name.split("-");
- if (elenames[elenames.length-1].compareTo(sport) != 0)
- continue; /* port doesn't match */
- if (host==null)
+ if (host==null && iport==port)
break; /* Only port done */
- String [] shosts = elenames[1].split("%2F");
- if (shosts[0].compareTo(host) == 0)
+ if (shost.compareTo(host) == 0)
break; /* Done port and host are the expected ones */
}
if (objName == null)
- throw(new Exception("Can't find connector for " + host + ":" + sport));
+ throw(new Exception("Can't find connector for " + host + ":" + port));
+ this.port = iport;
+ this.host = shost;
}
Modified: branches/2.1.x/java/org/apache/catalina/ha/backend/HeartbeatListener.java
===================================================================
--- branches/2.1.x/java/org/apache/catalina/ha/backend/HeartbeatListener.java 2009-10-09 15:06:35 UTC (rev 1187)
+++ branches/2.1.x/java/org/apache/catalina/ha/backend/HeartbeatListener.java 2009-10-09 15:54:26 UTC (rev 1188)
@@ -85,27 +85,32 @@
sender = new MultiCastSender();
else
sender = new TcpSender();
-
- try {
- sender.init(this);
- } catch (Exception ex) {
- log.error("Unable to initialize Sender: " + ex);
- sender = null;
- return;
- }
}
/* Read busy and ready */
if (coll == null) {
try {
coll = new CollectedInfo(host, port);
+ this.port = coll.port;
+ this.host = coll.host;
} catch (Exception ex) {
log.error("Unable to initialize info collection: " + ex);
coll = null;
return;
}
}
+
+ /* Start or restart sender */
try {
+ sender.init(this);
+ } catch (Exception ex) {
+ log.error("Unable to initialize Sender: " + ex);
+ sender = null;
+ return;
+ }
+
+ /* refresh the connector information and send it */
+ try {
coll.refresh();
} catch (Exception ex) {
log.error("Unable to collect load information: " + ex);
Modified: branches/2.1.x/java/org/apache/catalina/ha/backend/MultiCastSender.java
===================================================================
--- branches/2.1.x/java/org/apache/catalina/ha/backend/MultiCastSender.java 2009-10-09 15:06:35 UTC (rev 1187)
+++ branches/2.1.x/java/org/apache/catalina/ha/backend/MultiCastSender.java 2009-10-09 15:54:26 UTC (rev 1188)
@@ -22,6 +22,7 @@
import java.net.MulticastSocket;
import java.net.InetAddress;
+import java.net.InetSocketAddress;
import java.net.DatagramPacket;
import java.io.UnsupportedEncodingException;
@@ -47,7 +48,13 @@
if (s == null) {
try {
group = InetAddress.getByName(config.getGroup());
- s = new MulticastSocket(config.getMultiport());
+ if (config.host != null) {
+ InetAddress addr = InetAddress.getByName(config.host);
+ InetSocketAddress addrs = new InetSocketAddress(addr, config.getMultiport());
+ s = new MulticastSocket(addrs);
+ } else
+ s = new MulticastSocket(config.getMultiport());
+
s.setTimeToLive(config.getTtl());
s.joinGroup(group);
} catch (Exception ex) {
Modified: branches/2.1.x/java/org/apache/catalina/ha/backend/TcpSender.java
===================================================================
--- branches/2.1.x/java/org/apache/catalina/ha/backend/TcpSender.java 2009-10-09 15:06:35 UTC (rev 1187)
+++ branches/2.1.x/java/org/apache/catalina/ha/backend/TcpSender.java 2009-10-09 15:54:26 UTC (rev 1188)
@@ -26,6 +26,7 @@
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.InetAddress;
+import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.StringTokenizer;
@@ -89,7 +90,16 @@
for (int i = 0; i < connections.length; i++) {
if (connections[i] == null) {
try {
- connections[i] = new Socket(proxies[i].address, proxies[i].port);
+ if (config.host != null) {
+ connections[i] = new Socket();
+ InetAddress addr = InetAddress.getByName(config.host);
+ InetSocketAddress addrs = new InetSocketAddress(addr, 0);
+ connections[i].setReuseAddress(true);
+ connections[i].bind(addrs);
+ addrs = new InetSocketAddress(proxies[i].address, proxies[i].port);
+ connections[i].connect(addrs);
+ } else
+ connections[i] = new Socket(proxies[i].address, proxies[i].port);
connectionReaders[i] = new BufferedReader(new InputStreamReader(connections[i].getInputStream()));
connectionWriters[i] = new BufferedWriter(new OutputStreamWriter(connections[i].getOutputStream()));
} catch (Exception ex) {
15 years, 2 months
JBossWeb SVN: r1187 - trunk/java/org/apache/catalina/startup.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2009-10-09 11:06:35 -0400 (Fri, 09 Oct 2009)
New Revision: 1187
Modified:
trunk/java/org/apache/catalina/startup/ContextConfig.java
Log:
- Add the ServletSecurity to security constraints translation.
Modified: trunk/java/org/apache/catalina/startup/ContextConfig.java
===================================================================
--- trunk/java/org/apache/catalina/startup/ContextConfig.java 2009-10-09 14:32:58 UTC (rev 1186)
+++ trunk/java/org/apache/catalina/startup/ContextConfig.java 2009-10-09 15:06:35 UTC (rev 1187)
@@ -56,6 +56,7 @@
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
@@ -74,14 +75,18 @@
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.servlet.DispatcherType;
+import javax.servlet.HttpMethodConstraintElement;
import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
+import javax.servlet.ServletSecurityElement;
import javax.servlet.annotation.HandlesTypes;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebListener;
import javax.servlet.annotation.WebServlet;
+import javax.servlet.annotation.ServletSecurity.EmptyRoleSemantic;
+import javax.servlet.annotation.ServletSecurity.TransportGuarantee;
import org.apache.catalina.Authenticator;
import org.apache.catalina.Container;
@@ -105,6 +110,7 @@
import org.apache.catalina.deploy.FilterDef;
import org.apache.catalina.deploy.FilterMap;
import org.apache.catalina.deploy.LoginConfig;
+import org.apache.catalina.deploy.SecurityCollection;
import org.apache.catalina.deploy.SecurityConstraint;
import org.apache.catalina.deploy.WebAbsoluteOrdering;
import org.apache.catalina.deploy.WebOrdering;
@@ -1845,7 +1851,11 @@
if (ok && !context.getIgnoreAnnotations()) {
WebAnnotationSet.loadApplicationAnnotations(context);
}
+ // Resolve security
if (ok) {
+ resolveServletSecurity();
+ }
+ if (ok) {
validateSecurityRoles();
}
@@ -2077,6 +2087,101 @@
/**
+ * Translate servlet security associated with Servlets to security constraints.
+ */
+ protected void resolveServletSecurity() {
+ Container wrappers[] = context.findChildren();
+ for (int i = 0; i < wrappers.length; i++) {
+ Wrapper wrapper = (Wrapper) wrappers[i];
+ ServletSecurityElement servletSecurity = wrapper.getServletSecurity();
+ if (servletSecurity != null) {
+
+ ArrayList<String> methodOmissions = new ArrayList<String>();
+ boolean classPA = servletSecurity.getEmptyRoleSemantic().equals(EmptyRoleSemantic.PERMIT);
+ boolean classDA = servletSecurity.getEmptyRoleSemantic().equals(EmptyRoleSemantic.DENY);
+ boolean classTP = servletSecurity.getTransportGuarantee().equals(TransportGuarantee.CONFIDENTIAL);
+ String[] classRA = servletSecurity.getRolesAllowed();
+ Collection<HttpMethodConstraintElement> httpMethodConstraints =
+ servletSecurity.getHttpMethodConstraints();
+
+ // Process method constraints
+ if (httpMethodConstraints != null && httpMethodConstraints.size() > 0)
+ {
+ for (HttpMethodConstraintElement httpMethodConstraint : httpMethodConstraints)
+ {
+ boolean methodPA = httpMethodConstraint.getEmptyRoleSemantic().equals(EmptyRoleSemantic.PERMIT);
+ boolean methodDA = httpMethodConstraint.getEmptyRoleSemantic().equals(EmptyRoleSemantic.DENY);
+ boolean methodTP = httpMethodConstraint.getTransportGuarantee().equals(TransportGuarantee.CONFIDENTIAL);
+ String[] methodRA = httpMethodConstraint.getRolesAllowed();
+ if (methodPA || methodDA || methodTP || methodRA != null)
+ {
+ methodOmissions.add(httpMethodConstraint.getMethodName());
+ // Define a constraint specific for the method
+ SecurityConstraint constraint = new SecurityConstraint();
+ if (methodDA) {
+ constraint.setAuthConstraint(true);
+ }
+ if (methodPA) {
+ constraint.addAuthRole("*");
+ }
+ if (methodRA != null) {
+ for (String role : methodRA) {
+ constraint.addAuthRole(role);
+ }
+ }
+ if (methodTP) {
+ constraint.setUserConstraint(org.apache.catalina.realm.Constants.CONFIDENTIAL_TRANSPORT);
+ }
+ SecurityCollection collection = new SecurityCollection();
+ collection.addMethod(httpMethodConstraint.getMethodName());
+ String[] urlPatterns = wrapper.findMappings();
+ for (String urlPattern : urlPatterns) {
+ collection.addPattern(urlPattern);
+ }
+ constraint.addCollection(collection);
+ context.addConstraint(constraint);
+ }
+
+ }
+
+ }
+
+ if (classPA || classDA || classTP || classRA != null)
+ {
+ // Define a constraint for the class
+ SecurityConstraint constraint = new SecurityConstraint();
+ if (classPA) {
+ constraint.addAuthRole("*");
+ }
+ if (classDA) {
+ constraint.setAuthConstraint(true);
+ }
+ if (classRA != null) {
+ for (String role : classRA) {
+ constraint.addAuthRole(role);
+ }
+ }
+ if (classTP) {
+ constraint.setUserConstraint(org.apache.catalina.realm.Constants.CONFIDENTIAL_TRANSPORT);
+ }
+ SecurityCollection collection = new SecurityCollection();
+ String[] urlPatterns = wrapper.findMappings();
+ for (String urlPattern : urlPatterns) {
+ collection.addPattern(urlPattern);
+ }
+ for (String methodOmission : methodOmissions) {
+ collection.addMethodOmission(methodOmission);
+ }
+ constraint.addCollection(collection);
+ context.addConstraint(constraint);
+ }
+
+ }
+ }
+ }
+
+
+ /**
* Validate the usage of security role names in the web application
* deployment descriptor. If any problems are found, issue warning
* messages (for backwards compatibility) and add the missing roles.
15 years, 2 months
JBossWeb SVN: r1186 - in trunk/java: javax/servlet/annotation and 2 other directories.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2009-10-09 10:32:58 -0400 (Fri, 09 Oct 2009)
New Revision: 1186
Added:
trunk/java/javax/servlet/HttpConstraintElement.java
trunk/java/javax/servlet/HttpMethodConstraintElement.java
trunk/java/javax/servlet/MultipartConfigElement.java
trunk/java/javax/servlet/ServletSecurityElement.java
Modified:
trunk/java/javax/servlet/ServletContainerInitializer.java
trunk/java/javax/servlet/ServletContext.java
trunk/java/javax/servlet/ServletRegistration.java
trunk/java/javax/servlet/annotation/WebInitParam.java
trunk/java/org/apache/catalina/Wrapper.java
trunk/java/org/apache/catalina/core/ApplicationContext.java
trunk/java/org/apache/catalina/core/ApplicationContextFacade.java
trunk/java/org/apache/catalina/core/LocalStrings.properties
trunk/java/org/apache/catalina/core/StandardWrapper.java
trunk/java/org/apache/catalina/core/StandardWrapperFacade.java
Log:
- Today's spec update.
- Adds a programmatic API for security, tied to a Servlet.
- This forces me to redo the security annotation processing, with the final config now attached to the Wrapper until resolved
internally in the Servlet container.
- TODO: add the translation in ContextConfig.completeConfig().
Added: trunk/java/javax/servlet/HttpConstraintElement.java
===================================================================
--- trunk/java/javax/servlet/HttpConstraintElement.java (rev 0)
+++ trunk/java/javax/servlet/HttpConstraintElement.java 2009-10-09 14:32:58 UTC (rev 1186)
@@ -0,0 +1,160 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2008-2009 Sun Microsystems, Inc. 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.html
+ * or glassfish/bootstrap/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 glassfish/bootstrap/legal/LICENSE.txt.
+ * Sun designates this particular file as subject to the "Classpath" exception
+ * as provided by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the License
+ * Header, with the fields enclosed by brackets [] replaced by your own
+ * identifying information: "Portions Copyrighted [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 javax.servlet;
+
+import java.util.*;
+import javax.servlet.annotation.HttpConstraint;
+import javax.servlet.annotation.ServletSecurity.EmptyRoleSemantic;
+import javax.servlet.annotation.ServletSecurity.TransportGuarantee;
+
+/**
+ * Java Class representation of an {@link HttpConstraint} annotation value.
+ *
+ * @since Servlet 3.0
+ */
+public class HttpConstraintElement {
+
+ private EmptyRoleSemantic emptyRoleSemantic;
+ private TransportGuarantee transportGuarantee;
+ private String[] rolesAllowed;
+
+ /**
+ * Constructs a default HTTP constraint element
+ */
+ public HttpConstraintElement() {
+ this.emptyRoleSemantic = EmptyRoleSemantic.PERMIT;
+ this.transportGuarantee = TransportGuarantee.NONE;
+ rolesAllowed = new String[0];
+ }
+
+ /**
+ * Convenience constructor to establish <tt>EmptyRoleSemantic.DENY</tt>
+ *
+ * @param semantic should be EmptyRoleSemantic.DENY
+ */
+ public HttpConstraintElement(EmptyRoleSemantic semantic) {
+ this.emptyRoleSemantic = semantic;
+ this.transportGuarantee = TransportGuarantee.NONE;
+ rolesAllowed = new String[0];
+ }
+
+ /**
+ * Constructor to establish non-empty getRolesAllowed and/or
+ * <tt>TransportGuarantee.CONFIDENTIAL</tt>.
+ *
+ * @param guarantee <tt>TransportGuarantee.NONE</tt> or
+ * <tt>TransportGuarantee.CONFIDENTIAL</tt>
+ * @param roleNames the names of the roles that are to be
+ * allowed access
+ */
+ public HttpConstraintElement(TransportGuarantee guarantee,
+ String... roleNames) {
+ this.emptyRoleSemantic = EmptyRoleSemantic.PERMIT;
+ this.transportGuarantee = guarantee;
+ this.rolesAllowed = roleNames;
+ }
+
+ /**
+ * Constructor to establish all of getEmptyRoleSemantic,
+ * getRolesAllowed, and getTransportGuarantee.
+ *
+ * @param semantic <tt>EmptyRoleSemantic.DENY</tt> or
+ * <tt>EmptyRoleSemantic.PERMIT</tt>
+ * @param guarantee <tt>TransportGuarantee.NONE</tt> or
+ * <tt>TransportGuarantee.CONFIDENTIAL<tt>
+ * @param roleNames the names of the roles that are to be allowed
+ * access, or missing if the semantic is <tt>EmptyRoleSemantic.DENY</tt>
+ */
+ public HttpConstraintElement(EmptyRoleSemantic semantic,
+ TransportGuarantee guarantee, String... roleNames) {
+ if (semantic == EmptyRoleSemantic.DENY && roleNames.length > 0) {
+ throw new IllegalArgumentException(
+ "Deny semantic with rolesAllowed");
+ }
+ this.emptyRoleSemantic = semantic;
+ this.transportGuarantee = guarantee;
+ this.rolesAllowed = roleNames;
+ }
+
+ /**
+ * Gets the default authorization semantic.
+ *
+ * <p>This value is insignificant when <code>getRolesAllowed</code>
+ * returns a non-empty array, and should not be specified when a
+ * non-empty array is specified for <tt>getRolesAllowed<tt>.
+ *
+ * @return the {@link EmptyRoleSemantic} to be applied when
+ * <code>getRolesAllowed</code> returns an empty (that is, zero-length)
+ * array
+ */
+ public EmptyRoleSemantic getEmptyRoleSemantic() {
+ return this.emptyRoleSemantic;
+ }
+
+ /**
+ * Gets the data protection requirement (i.e., whether or not SSL/TLS is
+ * required) that must be satisfied by the transport connection.
+ *
+ * @return the {@link TransportGuarantee} indicating the data
+ * protection that must be provided by the connection
+ */
+ public TransportGuarantee getTransportGuarantee() {
+ return this.transportGuarantee;
+ }
+
+ /**
+ * Gets the names of the authorized roles.
+ *
+ * <p>Duplicate role names appearing in getRolesAllowed are insignificant
+ * and may be discarded. The String <tt>"*"</tt> has no special meaning
+ * as a role name (should it occur in getRolesAllowed).
+ *
+ * @return a (possibly empty) array of role names. When the
+ * array is empty, its meaning depends on the value of
+ * {@link #getEmptyRoleSemantic}. If its value is <tt>DENY</tt>,
+ * and <code>getRolesAllowed</code> returns an empty array,
+ * access is to be denied independent of authentication state and
+ * identity. Conversely, if its value is <code>PERMIT</code>, it
+ * indicates that access is to be allowed independent of authentication
+ * state and identity. When the array contains the names of one or
+ * more roles, it indicates that access is contingent on membership in at
+ * least one of the named roles (independent of the value of
+ * {@link #getEmptyRoleSemantic}).
+ */
+ public String[] getRolesAllowed() {
+ return this.rolesAllowed;
+ }
+}
Added: trunk/java/javax/servlet/HttpMethodConstraintElement.java
===================================================================
--- trunk/java/javax/servlet/HttpMethodConstraintElement.java (rev 0)
+++ trunk/java/javax/servlet/HttpMethodConstraintElement.java 2009-10-09 14:32:58 UTC (rev 1186)
@@ -0,0 +1,93 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2008-2009 Sun Microsystems, Inc. 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.html
+ * or glassfish/bootstrap/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 glassfish/bootstrap/legal/LICENSE.txt.
+ * Sun designates this particular file as subject to the "Classpath" exception
+ * as provided by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the License
+ * Header, with the fields enclosed by brackets [] replaced by your own
+ * identifying information: "Portions Copyrighted [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 javax.servlet;
+
+import javax.servlet.annotation.HttpMethodConstraint;
+
+/**
+ * Java Class represntation of an {@link HttpMethodConstraint} annotation value.
+ *
+ * @since Servlet 3.0
+ */
+public class HttpMethodConstraintElement extends HttpConstraintElement {
+
+ private String methodName;
+
+ /**
+ * Constructs an instance with default {@link HttpConstraintElement}
+ * value.
+ *
+ * @param methodName the name of an HTTP protocol method. The name must
+ * not be null, or the empty string, and must be a legitimate HTTP
+ * Method name as defined by RFC 2616
+ */
+ public HttpMethodConstraintElement(String methodName) {
+ if (methodName == null || methodName.length() == 0) {
+ throw new IllegalArgumentException("invalid HTTP method name");
+ }
+ this.methodName = methodName;
+ }
+ /**
+ * Constructs an instance with specified {@link HttpConstraintElement}
+ * value.
+ *
+ * @param methodName the name of an HTTP protocol method. The name must
+ * not be null, or the empty string, and must be a legitimate HTTP
+ * Method name as defined by RFC 2616
+ *
+ * @param constraint the HTTPconstraintElement value to assign to the
+ * named HTTP method
+ */
+ public HttpMethodConstraintElement(String methodName,
+ HttpConstraintElement constraint) {
+ super(constraint.getEmptyRoleSemantic(),
+ constraint.getTransportGuarantee(),
+ constraint.getRolesAllowed());
+ if (methodName == null || methodName.length() == 0) {
+ throw new IllegalArgumentException("invalid HTTP method name");
+ }
+ this.methodName = methodName;
+ }
+
+ /**
+ * Gets the HTTP method name.
+ *
+ * @return the Http method name
+ */
+ public String getMethodName() {
+ return this.methodName;
+ }
+}
Added: trunk/java/javax/servlet/MultipartConfigElement.java
===================================================================
--- trunk/java/javax/servlet/MultipartConfigElement.java (rev 0)
+++ trunk/java/javax/servlet/MultipartConfigElement.java 2009-10-09 14:32:58 UTC (rev 1186)
@@ -0,0 +1,133 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2008-2009 Sun Microsystems, Inc. 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.html
+ * or glassfish/bootstrap/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 glassfish/bootstrap/legal/LICENSE.txt.
+ * Sun designates this particular file as subject to the "Classpath" exception
+ * as provided by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the License
+ * Header, with the fields enclosed by brackets [] replaced by your own
+ * identifying information: "Portions Copyrighted [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 javax.servlet;
+
+import javax.servlet.annotation.MultipartConfig;
+
+/**
+ * Java Class represntation of an {@link MultipartConfig} annotation value.
+ *
+ * @since Servlet 3.0
+ */
+public class MultipartConfigElement {
+
+ private String location;
+ private long maxFileSize;
+ private long maxRequestSize;
+ private int fileSizeThreshold;
+
+ /**
+ * Constructs an instance with defaults for all but location.
+ *
+ * @param location defualts to "" if values is null.
+ */
+ public MultipartConfigElement(String location) {
+ if (location == null) {
+ this.location = "";
+ }
+ this.maxFileSize = -1L;
+ this.maxRequestSize = -1L;
+ this.fileSizeThreshold = 0;
+ }
+
+ /**
+ * Constructs an instance with all values specified.
+ *
+ * @param location the directory location where files will be stored
+ * @param maxFileSize the maximum size allowed for uploaded files
+ * @param maxRequestSize the maximum size allowed for
+ * multipart/form-data requests
+ * @param fileSizeThreshold the size threshold after which files will
+ * be written to disk
+ */
+ public MultipartConfigElement(String location, long maxFileSize,
+ long maxRequestSize, int fileSizeThreshold) {
+ if (location == null) {
+ this.location = "";
+ }
+ this.maxFileSize = maxFileSize;
+ this.maxRequestSize = maxRequestSize;
+ this.fileSizeThreshold = fileSizeThreshold;
+ }
+
+ /**
+ * Constructs an instance from a {@link MultipartConfig} annotation value.
+ *
+ * @param annotation the annotation value
+ */
+ public MultipartConfigElement(MultipartConfig annotation) {
+ this.location = annotation.location();
+ this.fileSizeThreshold = annotation.fileSizeThreshold();
+ this.maxFileSize = annotation.maxFileSize();
+ this.maxRequestSize = annotation.maxRequestSize();
+ }
+
+ /**
+ * Gets the directory location where files will be stored.
+ *
+ * @return the directory location where files will be stored
+ */
+ public String getLocation() {
+ return this.location;
+ }
+
+ /**
+ * Gets the maximum size allowed for uploaded files.
+ *
+ * @return the maximum size allowed for uploaded files
+ */
+ public long getMaxFileSize() {
+ return this.maxFileSize;
+ }
+
+ /**
+ * Gets the maximum size allowed for multipart/form-data requests.
+ *
+ * @return the maximum size allowed for multipart/form-data requests
+ */
+ public long getMaxRequestSize() {
+ return this.maxRequestSize;
+ }
+
+ /**
+ * Gets the size threshold after which files will be written to disk.
+ *
+ * @return the size threshold after which files will be written to disk
+ */
+ public int getFileSizeThreshold() {
+ return this.fileSizeThreshold;
+ }
+}
Modified: trunk/java/javax/servlet/ServletContainerInitializer.java
===================================================================
--- trunk/java/javax/servlet/ServletContainerInitializer.java 2009-10-08 10:44:14 UTC (rev 1185)
+++ trunk/java/javax/servlet/ServletContainerInitializer.java 2009-10-09 14:32:58 UTC (rev 1186)
@@ -64,18 +64,15 @@
* while at the same time providing a configuration option that would
* log them.
*
- * <p>Implementations of this interface may be declared by a JAR file
+ * <p>Implementations of this interface must be declared by a JAR file
* resource located inside the <tt>META-INF/services</tt> directory and
* named for the fully qualified class name of this interface, and will be
- * discovered using the runtime's service provider lookup mechanism.
- *
- * <p>When an application is deployed, the order in which
- * ServletContainerInitializer implementations are discovered
- * by the runtime's service lookup mechanism must follow the
+ * discovered using the runtime's service provider lookup mechanism
+ * or a container specific mechanism that is semantically equivalent to
+ * it. In either case, ServletContainerInitializer services from web
+ * fragment JAR files excluded from an absolute ordering must be ignored,
+ * and the order in which these services are discovered must follow the
* application's classloading delegation model.
- * Any ServletContainerInitializer implementations declared in
- * any of the application's web fragment JAR files that are excluded
- * from absolute ordering must be ignored.
*
* @see javax.servlet.annotation.HandlesTypes
*
@@ -93,9 +90,8 @@
* startup of the bundling application. If this
* <tt>ServletContainerInitializer</tt> is bundled inside a JAR file
* outside of any <tt>WEB-INF/lib</tt> directory, but still
- * discoverable by the runtime's service provider lookup mechanism,
- * its <tt>onStartup</tt> method will be invoked every time an
- * application is started.
+ * discoverable as described above, its <tt>onStartup</tt> method
+ * will be invoked every time an application is started.
*
* @param c the Set of application classes that extend, implement, or
* have been annotated with the class types specified by the
Modified: trunk/java/javax/servlet/ServletContext.java
===================================================================
--- trunk/java/javax/servlet/ServletContext.java 2009-10-08 10:44:14 UTC (rev 1185)
+++ trunk/java/javax/servlet/ServletContext.java 2009-10-09 14:32:58 UTC (rev 1186)
@@ -1499,6 +1499,28 @@
* @since Servlet 3.0
*/
public ClassLoader getClassLoader();
+
+
+ /**
+ * Declares role names that are tested using <code>isUserInRole</code>.
+ *
+ * <p>Roles that are implicitly declared as a result of their use within
+ * the {@link ServletRegistration.Dynamic#setServletSecurity
+ * setServletSecurity} or {@link ServletRegistration.Dynamic#setRunAsRole
+ * setRunAsRole} methods of the {@link ServletRegistration} interface need
+ * not be declared.
+ *
+ * @param roleNames the role names being declared
+ *
+ * @throws IllegalArgumentException if any of the argument roleNames is
+ * null or the empty string
+ *
+ * @throws IllegalStateException if the ServletContext has already
+ * been initialized
+ *
+ * @since Servlet 3.0
+ */
+ public void declareRoles(String... roleNames);
}
Modified: trunk/java/javax/servlet/ServletRegistration.java
===================================================================
--- trunk/java/javax/servlet/ServletRegistration.java 2009-10-08 10:44:14 UTC (rev 1185)
+++ trunk/java/javax/servlet/ServletRegistration.java 2009-10-09 14:32:58 UTC (rev 1186)
@@ -78,6 +78,15 @@
public Collection<String> getMappings();
/**
+ * Gets the name of the runAs role of the Servlet represented by this
+ * <code>ServletRegistration</code>.
+ *
+ * @return the name of the runAs role, or null if the Servlet is
+ * configured to run as its caller
+ */
+ public String getRunAsRole();
+
+ /**
* Interface through which a {@link Servlet} registered via one of the
* <tt>addServlet</tt> methods on {@link ServletContext} may be further
* configured.
@@ -107,10 +116,60 @@
* @param loadOnStartup the initialization priority of the Servlet
*
* @throws IllegalStateException if the ServletContext from which
- * this dynamic ServletRegistration was obtained has already been
+ * this ServletRegistration was obtained has already been initialized
+ */
+ public void setLoadOnStartup(int loadOnStartup);
+
+ /**
+ * Sets the {@link ServletSecurityElement} to be applied to the
+ * mappings defined for this <code>ServletRegistration</code>. If this
+ * method is called multiple times, each successive call overrides the
+ * effects of the former.
+ *
+ * @param constraint the {@link ServletSecurityElement} to be applied
+ * to the patterns mapped to the registration
+ *
+ * @throws IllegalArgumentException if <tt>constraint</tt> is null
+ *
+ * @throws IllegalStateException if the {@link ServletContext} from
+ * which this ServletRegistration was obtained has already been
+ * initialized
+ */
+ public void setServletSecurity(ServletSecurityElement constraint);
+
+ /**
+ * Sets the {@link MultipartConfigElement} to be applied to the
+ * mappings defined for this <code>ServletRegistration</code>. If this
+ * method is called multiple times, each successive call overrides the
+ * effects of the former.
+ *
+ * @param multipartConfig the {@link MultipartConfigElement} to be
+ * applied to the patterns mapped to the registration
+ *
+ * @throws IllegalArgumentException if <tt>multipartConfig</tt> is
+ * null
+ *
+ * @throws IllegalStateException if the {@link ServletContext} from
+ * which this ServletRegistration was obtained has already been
* initialized
*/
- public void setLoadOnStartup(int loadOnStartup);
+ public void setMultipartConfig(
+ MultipartConfigElement multipartConfig);
+
+ /**
+ * Sets the name of the runAs role for the
+ * <code>ServletRegistration</code>.
+ *
+ * @param roleName
+ *
+ * @throws IllegalArgumentException if <tt>roleName</tt> is null
+ *
+ * @throws IllegalStateException if the {@link ServletContext} from
+ * which this ServletRegistration was obtained has already been
+ * initialized
+ */
+ public void setRunAsRole(String roleName);
+
}
}
Added: trunk/java/javax/servlet/ServletSecurityElement.java
===================================================================
--- trunk/java/javax/servlet/ServletSecurityElement.java (rev 0)
+++ trunk/java/javax/servlet/ServletSecurityElement.java 2009-10-09 14:32:58 UTC (rev 1186)
@@ -0,0 +1,189 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2008-2009 Sun Microsystems, Inc. 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.html
+ * or glassfish/bootstrap/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 glassfish/bootstrap/legal/LICENSE.txt.
+ * Sun designates this particular file as subject to the "Classpath" exception
+ * as provided by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the License
+ * Header, with the fields enclosed by brackets [] replaced by your own
+ * identifying information: "Portions Copyrighted [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 javax.servlet;
+
+import java.util.*;
+import javax.servlet.annotation.HttpMethodConstraint;
+import javax.servlet.annotation.ServletSecurity;
+
+/**
+ * Java Class represntation of a {@link ServletSecurity} annotation value.
+ *
+ * @since Servlet 3.0
+ */
+public class ServletSecurityElement extends HttpConstraintElement {
+
+ private Collection<String> methodNames;
+ private Collection<HttpMethodConstraintElement> methodConstraints;
+
+ /**
+ * Constructs an instance using the default
+ * <code>HttpConstraintElement</code> value as the default Constraint
+ * element and with no HTTP Method specific constraint elements.
+ */
+ public ServletSecurityElement() {
+ methodConstraints = new HashSet<HttpMethodConstraintElement>();
+ methodNames = new HashSet<String>();
+ }
+
+ /**
+ * Constructs an instance with a default Constraint element
+ * and with no HTTP Method specific constraint elements.
+ *
+ * @param constraint the HttpConstraintElement to be
+ * applied to all HTTP methods other than those represented in the
+ * <tt>methodConstraints</tt>
+ */
+ public ServletSecurityElement(HttpConstraintElement constraint) {
+ super(constraint.getEmptyRoleSemantic(),
+ constraint.getTransportGuarantee(),
+ constraint.getRolesAllowed());
+ methodConstraints = new HashSet<HttpMethodConstraintElement>();
+ methodNames = new HashSet<String>();
+ }
+
+ /**
+ * Constructs an instance using the default
+ * <code>HttpConstraintElement</code> value as the default Constraint
+ * element and with a collection of HTTP Method specific constraint
+ * elements.
+ *
+ * @param methodConstraints the collection of HTTP method specific
+ * constraint elements
+ *
+ * @throws IllegalArgumentException if duplicate method names are
+ * detected
+ */
+ public ServletSecurityElement(
+ Collection<HttpMethodConstraintElement> methodConstraints) {
+ this.methodConstraints = (methodConstraints == null ?
+ new HashSet<HttpMethodConstraintElement>() : methodConstraints);
+ methodNames = checkMethodNames(this.methodConstraints);
+ }
+
+ /**
+ * Constructs an instance with a default Constraint element
+ * and with a collection of HTTP Method specific constraint elements.
+ *
+ * @param constraint the HttpConstraintElement to be
+ * applied to all HTTP methods other than those represented in the
+ * <tt>methodConstraints</tt>
+ * @param methodConstraints the collection of HTTP method specific
+ * constraint elements.
+ *
+ * @throws IllegalArgumentException if duplicate method names are
+ * detected
+ */
+ public ServletSecurityElement(HttpConstraintElement constraint,
+ Collection<HttpMethodConstraintElement> methodConstraints) {
+ super(constraint.getEmptyRoleSemantic(),
+ constraint.getTransportGuarantee(),
+ constraint.getRolesAllowed());
+ this.methodConstraints = (methodConstraints == null ?
+ new HashSet<HttpMethodConstraintElement>() : methodConstraints);
+ methodNames = checkMethodNames(this.methodConstraints);
+ }
+
+ /**
+ * Constructs an instance from a {@link ServletSecurity} annotation value.
+ *
+ * @param annotation the annotation value
+ *
+ * @throws IllegalArgumentException if duplicate method names are
+ * detected
+ */
+ public ServletSecurityElement(ServletSecurity annotation) {
+ super(annotation.value().value(),
+ annotation.value().transportGuarantee(),
+ annotation.value().rolesAllowed());
+ this.methodConstraints = new HashSet<HttpMethodConstraintElement>();
+ for (HttpMethodConstraint constraint :
+ annotation.httpMethodConstraints()) {
+ this.methodConstraints.add(
+ new HttpMethodConstraintElement(
+ constraint.value(),
+ new HttpConstraintElement(constraint.emptyRoleSemantic(),
+ constraint.transportGuarantee(),
+ constraint.rolesAllowed())));
+ }
+ methodNames = checkMethodNames(this.methodConstraints);
+ }
+
+ /**
+ * Gets the (possibly empty) collection of HTTP Method specific
+ * constraint elements.
+ *
+ * @return the (possibly empty) collection of HttpMethodConstraintElement
+ * objects
+ */
+ public Collection<HttpMethodConstraintElement> getHttpMethodConstraints() {
+ return methodConstraints;
+ }
+
+ /**
+ * Gets the set of HTTP methid names named by the HttpMethodConstraints.
+ *
+ * @return the set of String method names
+ */
+ public Collection<String> getMethodNames() {
+ return methodNames;
+ }
+
+ /**
+ * Checks for duplicate method names in methodConstraints.
+ *
+ * @param methodConstraints
+ *
+ * @retrun Set of method names
+ *
+ * @throws IllegalArgumentException if duplicate method names are
+ * detected
+ */
+ private Collection<String> checkMethodNames(
+ Collection<HttpMethodConstraintElement> methodConstraints) {
+ Collection<String> methodNames = new HashSet<String>();
+ for (HttpMethodConstraintElement methodConstraint :
+ methodConstraints) {
+ String methodName = methodConstraint.getMethodName();
+ if (methodNames.contains(methodName)) {
+ throw new IllegalArgumentException(
+ "Duplicate HTTP method name: " + methodName);
+ }
+ methodNames.add(methodName);
+ }
+ return methodNames;
+ }
+}
Modified: trunk/java/javax/servlet/annotation/WebInitParam.java
===================================================================
--- trunk/java/javax/servlet/annotation/WebInitParam.java 2009-10-08 10:44:14 UTC (rev 1185)
+++ trunk/java/javax/servlet/annotation/WebInitParam.java 2009-10-09 14:32:58 UTC (rev 1186)
@@ -43,7 +43,8 @@
import java.lang.annotation.Documented;
/**
- * Used to declare init params in servlets in filters
+ * This annotation is used on a Servlet or Filter implementation class
+ * to specify an initialization parameter.
*
* @since Servlet 3.0
*/
@@ -51,19 +52,19 @@
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface WebInitParam {
+
/**
- * Name of the init param
+ * Name of the initialization parameter
*/
String name();
/**
- * Value of the init param
- */
-
+ * Value of the initialization parameter
+ */
String value();
/**
- * Description of the init param
+ * Description of the initialization parameter
*/
String description() default "";
}
Modified: trunk/java/org/apache/catalina/Wrapper.java
===================================================================
--- trunk/java/org/apache/catalina/Wrapper.java 2009-10-08 10:44:14 UTC (rev 1185)
+++ trunk/java/org/apache/catalina/Wrapper.java 2009-10-09 14:32:58 UTC (rev 1186)
@@ -22,6 +22,7 @@
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
+import javax.servlet.ServletSecurityElement;
import javax.servlet.UnavailableException;
import org.apache.catalina.deploy.Multipart;
@@ -423,5 +424,16 @@
*/
public void unload() throws ServletException;
+
+ /**
+ * Set an associated ServletSecurity.
+ */
+ public void setServletSecurity(ServletSecurityElement servletSecurity);
+
+ /**
+ * Get an associated ServletSecurity, if any.
+ */
+ public ServletSecurityElement getServletSecurity();
+
}
Modified: trunk/java/org/apache/catalina/core/ApplicationContext.java
===================================================================
--- trunk/java/org/apache/catalina/core/ApplicationContext.java 2009-10-08 10:44:14 UTC (rev 1185)
+++ trunk/java/org/apache/catalina/core/ApplicationContext.java 2009-10-09 14:32:58 UTC (rev 1186)
@@ -1216,6 +1216,23 @@
return context.getVersionMinor();
}
+ public void declareRoles(String... roleNames) {
+ if (restricted) {
+ throw new UnsupportedOperationException(sm.getString("applicationContext.restricted"));
+ }
+ if (context.isInitialized()) {
+ throw new IllegalStateException(sm.getString("applicationContext.alreadyInitialized",
+ getContextPath()));
+ }
+ for (String role: roleNames) {
+ if (role == null || "".equals(role)) {
+ throw new IllegalArgumentException(sm.getString("applicationContext.emptyRole",
+ getContextPath()));
+ }
+ context.addSecurityRole(role);
+ }
+ }
+
// -------------------------------------------------------- Package Methods
protected StandardContext getContext() {
return this.context;
Modified: trunk/java/org/apache/catalina/core/ApplicationContextFacade.java
===================================================================
--- trunk/java/org/apache/catalina/core/ApplicationContextFacade.java 2009-10-08 10:44:14 UTC (rev 1185)
+++ trunk/java/org/apache/catalina/core/ApplicationContextFacade.java 2009-10-09 14:32:58 UTC (rev 1186)
@@ -653,6 +653,14 @@
}
+ public void declareRoles(String... roleNames) {
+ if (SecurityUtil.isPackageProtectionEnabled()) {
+ doPrivileged("declareRoles", new Object[]{roleNames});
+ } else {
+ context.declareRoles(roleNames);
+ }
+ }
+
/**
* Use reflection to invoke the requested method. Cache the method object
* to speed up the process
Modified: trunk/java/org/apache/catalina/core/LocalStrings.properties
===================================================================
--- trunk/java/org/apache/catalina/core/LocalStrings.properties 2009-10-08 10:44:14 UTC (rev 1185)
+++ trunk/java/org/apache/catalina/core/LocalStrings.properties 2009-10-09 14:32:58 UTC (rev 1186)
@@ -17,6 +17,7 @@
applicationContext.restricted=Listener that attempted to call this method is restricted.
applicationContext.attributeEvent=Exception thrown by attributes event listener
applicationContext.create=Error creating instance
+applicationContext.emptyRole=Invalid empty role specified for context {0}
applicationContext.mapping.error=Error during mapping
applicationContext.requestDispatcher.iae=Path {0} does not start with a "/" character
applicationContext.resourcePaths.iae=Path {0} does not start with a "/" character
Modified: trunk/java/org/apache/catalina/core/StandardWrapper.java
===================================================================
--- trunk/java/org/apache/catalina/core/StandardWrapper.java 2009-10-08 10:44:14 UTC (rev 1185)
+++ trunk/java/org/apache/catalina/core/StandardWrapper.java 2009-10-09 14:32:58 UTC (rev 1186)
@@ -41,6 +41,7 @@
import javax.servlet.ServletRegistration;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
+import javax.servlet.ServletSecurityElement;
import javax.servlet.SingleThreadModel;
import javax.servlet.UnavailableException;
@@ -218,6 +219,13 @@
* The run-as identity for this servlet.
*/
protected String runAs = null;
+
+
+ /**
+ * Associated ServletSecurity.
+ */
+ protected ServletSecurityElement servletSecurity = null;
+
/**
* The notification sequence number.
@@ -627,8 +635,26 @@
}
+
+ /**
+ * Get an associated ServletSecurity, if any.
+ */
+ public ServletSecurityElement getServletSecurity() {
+ return servletSecurity;
+ }
+
/**
+ * Set an associated ServletSecurity.
+ */
+ public void setServletSecurity(ServletSecurityElement servletSecurity) {
+ ServletSecurityElement oldServletSecurity = this.servletSecurity;
+ this.servletSecurity = servletSecurity;
+ support.firePropertyChange("servletSecurity", oldServletSecurity, this.servletSecurity);
+ }
+
+
+ /**
* Return the fully qualified servlet class name for this servlet.
*/
public String getServletClass() {
Modified: trunk/java/org/apache/catalina/core/StandardWrapperFacade.java
===================================================================
--- trunk/java/org/apache/catalina/core/StandardWrapperFacade.java 2009-10-08 10:44:14 UTC (rev 1185)
+++ trunk/java/org/apache/catalina/core/StandardWrapperFacade.java 2009-10-09 14:32:58 UTC (rev 1186)
@@ -56,11 +56,14 @@
import java.util.Map;
import java.util.Set;
+import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletRegistration;
+import javax.servlet.ServletSecurityElement;
import org.apache.catalina.Context;
+import org.apache.catalina.deploy.Multipart;
import org.apache.catalina.util.StringManager;
@@ -232,6 +235,27 @@
public String getName() {
return wrapper.getName();
}
+
+
+ public String getRunAsRole() {
+ return wrapper.getRunAs();
+ }
-
+ public void setRunAsRole(String roleName) {
+ wrapper.setRunAs(roleName);
+ }
+
+ public void setServletSecurity(ServletSecurityElement servletSecurity) {
+ wrapper.setServletSecurity(servletSecurity);
+ }
+
+ public void setMultipartConfig(MultipartConfigElement multipartConfig) {
+ Multipart multipart = new Multipart();
+ multipart.setLocation(multipartConfig.getLocation());
+ multipart.setMaxFileSize(multipartConfig.getMaxFileSize());
+ multipart.setMaxRequestSize(multipartConfig.getMaxRequestSize());
+ multipart.setFileSizeThreshold(multipartConfig.getFileSizeThreshold());
+ wrapper.setMultipartConfig(multipart);
+ }
+
}
15 years, 2 months
JBossWeb SVN: r1185 - in trunk/java: org/apache/catalina/connector and 1 other directories.
by jbossweb-commits@lists.jboss.org
Author: remy.maucherat(a)jboss.com
Date: 2009-10-08 06:44:14 -0400 (Thu, 08 Oct 2009)
New Revision: 1185
Modified:
trunk/java/javax/servlet/AsyncContext.java
trunk/java/javax/servlet/AsyncEvent.java
trunk/java/javax/servlet/AsyncListener.java
trunk/java/javax/servlet/ServletRequest.java
trunk/java/javax/servlet/ServletRequestWrapper.java
trunk/java/org/apache/catalina/connector/Request.java
trunk/java/org/apache/catalina/connector/RequestFacade.java
trunk/java/org/apache/catalina/core/StandardWrapperValve.java
Log:
- Today's spec update.
- Add a todo for start event.
Modified: trunk/java/javax/servlet/AsyncContext.java
===================================================================
--- trunk/java/javax/servlet/AsyncContext.java 2009-10-07 11:59:37 UTC (rev 1184)
+++ trunk/java/javax/servlet/AsyncContext.java 2009-10-08 10:44:14 UTC (rev 1185)
@@ -214,9 +214,19 @@
* {@link #complete}.</li>
* </ol>
*
- * @exception IllegalStateException if {@link #complete} has already
- * been called
+ * <p>There can be at most one asynchronous dispatch operation per
+ * asynchronous cycle, which is started by a call to one of the
+ * {@link ServletRequest#startAsync} methods. Any attempt to perform an
+ * additional asynchronous dispatch operation within the same
+ * asynchronous cycle will result in an IllegalStateException.
+ * If startAsync is subsequently called on the dispatched request,
+ * then any of the dispatch or {@link #complete} methods may be called.
*
+ * @throws IllegalStateException if one of the dispatch methods
+ * has been called and the startAsync method has not been
+ * called during the resulting dispatch, or if {@link #complete}
+ * was called
+ *
* @see ServletRequest#getDispatcherType
*/
public void dispatch();
@@ -240,14 +250,24 @@
* attributes will always reflect the original path elements, even under
* repeated dispatches.
*
+ * <p>There can be at most one asynchronous dispatch operation per
+ * asynchronous cycle, which is started by a call to one of the
+ * {@link ServletRequest#startAsync} methods. Any attempt to perform an
+ * additional asynchronous dispatch operation within the same
+ * asynchronous cycle will result in an IllegalStateException.
+ * If startAsync is subsequently called on the dispatched request,
+ * then any of the dispatch or {@link #complete} methods may be called.
+ *
* <p>See {@link #dispatch()} for additional details, including error
* handling.
*
* @param path the path of the dispatch target, scoped to the
* ServletContext from which this AsyncContext was initialized
*
- * @exception IllegalStateException if {@link #complete} has already
- * been called
+ * @throws IllegalStateException if one of the dispatch methods
+ * has been called and the startAsync method has not been
+ * called during the resulting dispatch, or if {@link #complete}
+ * was called
*
* @see ServletRequest#getDispatcherType
*/
@@ -271,6 +291,14 @@
* attributes will always reflect the original path elements, even under
* repeated dispatches.
*
+ * <p>There can be at most one asynchronous dispatch operation per
+ * asynchronous cycle, which is started by a call to one of the
+ * {@link ServletRequest#startAsync} methods. Any attempt to perform an
+ * additional asynchronous dispatch operation within the same
+ * asynchronous cycle will result in an IllegalStateException.
+ * If startAsync is subsequently called on the dispatched request,
+ * then any of the dispatch or {@link #complete} methods may be called.
+ *
* <p>See {@link #dispatch()} for additional details, including error
* handling.
*
@@ -278,8 +306,10 @@
* @param path the path of the dispatch target, scoped to the given
* ServletContext
*
- * @exception IllegalStateException if {@link #complete} has already
- * been called
+ * @throws IllegalStateException if one of the dispatch methods
+ * has been called and the startAsync method has not been
+ * called during the resulting dispatch, or if {@link #complete}
+ * was called
*
* @see ServletRequest#getDispatcherType
*/
@@ -317,4 +347,105 @@
* @param run the asynchronous handler
*/
public void start(Runnable run);
+
+
+ /**
+ * Registers the given {@link AsyncListener} with the most recent
+ * asynchronous cycle that was started by a call to one of the
+ * {@link ServletRequest#startAsync} methods.
+ *
+ * <p>The given AsyncListener will receive an {@link AsyncEvent} when
+ * the asynchronous cycle completes successfully, times out, or results
+ * in an error.
+ *
+ * <p>AsyncListener instances will be notified in the order in which
+ * they were added.
+ *
+ * @param listener the AsyncListener to be registered
+ *
+ * @throws IllegalStateException if this method is called after
+ * the container-initiated dispatch, during which one of the
+ * {@link ServletRequest#startAsync} methods was called, has
+ * returned to the container
+ */
+ public void addListener(AsyncListener listener);
+
+
+ /**
+ * Registers the given {@link AsyncListener} with the most recent
+ * asynchronous cycle that was started by a call to one of the
+ * {@link ServletRequest#startAsync} methods.
+ *
+ * <p>The given AsyncListener will receive an {@link AsyncEvent} when
+ * the asynchronous cycle completes successfully, times out, or results
+ * in an error.
+ *
+ * <p>AsyncListener instances will be notified in the order in which
+ * they were added.
+ *
+ * <p>The given ServletRequest and ServletResponse objects will
+ * be made available to the given AsyncListener via the
+ * {@link AsyncEvent#getSuppliedRequest getSuppliedRequest} and
+ * {@link AsyncEvent#getSuppliedResponse getSuppliedResponse} methods,
+ * respectively, of the {@link AsyncEvent} delivered to it. These objects
+ * should not be read from or written to, respectively, at the time the
+ * AsyncEvent is delivered, because additional wrapping may have
+ * occurred since the given AsyncListener was registered, but may be used
+ * in order to release any resources associated with them.
+ *
+ * @param listener the AsyncListener to be registered
+ * @param servletRequest the ServletRequest that will be included
+ * in the AsyncEvent
+ * @param servletResponse the ServletResponse that will be included
+ * in the AsyncEvent
+ *
+ * @throws IllegalStateException if this method is called after
+ * the container-initiated dispatch, during which one of the
+ * {@link ServletRequest#startAsync} methods was called, has
+ * returned to the container
+ */
+ public void addListener(AsyncListener listener,
+ ServletRequest servletRequest,
+ ServletResponse servletResponse);
+
+
+ /**
+ * Sets the timeout (in milliseconds) for this AsyncContext.
+ *
+ * <p>The timeout applies to this AsyncContext once the
+ * container-initiated dispatch during which one of the
+ * {@link ServletRequest#startAsync} methods was called has
+ * returned to the container.
+ *
+ * <p>The timeout will expire if neither the {@link #complete} method
+ * nor any of the dispatch methods are called. A timeout value of
+ * zero or less indicates no timeout.
+ *
+ * <p>If {@link #setTimeout} is not called, then the container's
+ * default timeout, which is available via a call to
+ * {@link #getTimeout}, will apply.
+ *
+ * @param timeout the timeout in milliseconds
+ *
+ * @throws IllegalStateException if this method is called after
+ * the container-initiated dispatch, during which one of the
+ * {@link ServletRequest#startAsync} methods was called, has
+ * returned to the container
+ */
+ public void setTimeout(long timeout);
+
+
+ /**
+ * Gets the timeout (in milliseconds) for this AsyncContext.
+ *
+ * <p>This method returns the container's default timeout for
+ * asynchronous operations, or the timeout value passed to the most
+ * recent invocation of {@link #setTimeout}.
+ *
+ * <p>A timeout value of zero or less indicates no timeout.
+ *
+ * @return the timeout in milliseconds
+ */
+ public long getTimeout();
+
}
Modified: trunk/java/javax/servlet/AsyncEvent.java
===================================================================
--- trunk/java/javax/servlet/AsyncEvent.java 2009-10-07 11:59:37 UTC (rev 1184)
+++ trunk/java/javax/servlet/AsyncEvent.java 2009-10-08 10:44:14 UTC (rev 1185)
@@ -117,11 +117,11 @@
* Gets the ServletRequest from this AsyncEvent.
*
* <p>If the AsyncListener to which this AsyncEvent is being delivered
- * was added using {@link ServletRequest#addAsyncListener(AsyncListener,
+ * was added using {@link AsyncContext#addListener(AsyncListener,
* ServletRequest, ServletResponse)}, the returned ServletRequest
* will be the same as the one supplied to the above method.
* If the AsyncListener was added via
- * {@link ServletRequest#addAsyncListener(AsyncListener)}, this method
+ * {@link AsyncContext#addListener(AsyncListener)}, this method
* must return null.
*
* @return the ServletRequest that was used to initialize this AsyncEvent,
@@ -135,11 +135,11 @@
* Gets the ServletResponse from this AsyncEvent.
*
* <p>If the AsyncListener to which this AsyncEvent is being delivered
- * was added using {@link ServletRequest#addAsyncListener(AsyncListener,
+ * was added using {@link AsyncContext#addListener(AsyncListener,
* ServletRequest, ServletResponse)}, the returned ServletResponse
* will be the same as the one supplied to the above method.
* If the AsyncListener was added via
- * {@link ServletRequest#addAsyncListener(AsyncListener)}, this method
+ * {@link AsyncContext#addListener(AsyncListener)}, this method
* must return null.
*
* @return the ServletResponse that was used to initialize this AsyncEvent,
Modified: trunk/java/javax/servlet/AsyncListener.java
===================================================================
--- trunk/java/javax/servlet/AsyncListener.java 2009-10-07 11:59:37 UTC (rev 1184)
+++ trunk/java/javax/servlet/AsyncListener.java 2009-10-08 10:44:14 UTC (rev 1185)
@@ -58,7 +58,7 @@
* <tt>event</tt>.
*
* <p>In addition, if this AsyncListener had been registered via a call
- * to {@link ServletRequest#addAsyncListener(AsyncListener,
+ * to {@link AsyncContext#addListener(AsyncListener,
* ServletRequest, ServletResponse)}, the supplied ServletRequest and
* ServletResponse objects may be retrieved by calling
* {@link AsyncEvent#getSuppliedRequest getSuppliedRequest} and
@@ -84,7 +84,7 @@
* <tt>event</tt>.
*
* <p>In addition, if this AsyncListener had been registered via a call
- * to {@link ServletRequest#addAsyncListener(AsyncListener,
+ * to {@link AsyncContext#addListener(AsyncListener,
* ServletRequest, ServletResponse)}, the supplied ServletRequest and
* ServletResponse objects may be retrieved by calling
* {@link AsyncEvent#getSuppliedRequest getSuppliedRequest} and
@@ -110,7 +110,7 @@
* <tt>event</tt>.
*
* <p>In addition, if this AsyncListener had been registered via a call
- * to {@link ServletRequest#addAsyncListener(AsyncListener,
+ * to {@link AsyncContext#addListener(AsyncListener,
* ServletRequest, ServletResponse)}, the supplied ServletRequest and
* ServletResponse objects may be retrieved by calling
* {@link AsyncEvent#getSuppliedRequest getSuppliedRequest} and
@@ -125,4 +125,36 @@
*/
public void onError(AsyncEvent event) throws IOException;
+
+ /**
+ * Notifies this AsyncListener that a new asynchronous cycle is being
+ * initiated via a call to one of the {@link ServletRequest#startAsync}
+ * methods.
+ *
+ * <p>The {@link AsyncContext} corresponding to the asynchronous
+ * operation that is being reinitialized may be obtained by calling
+ * {@link AsyncEvent#getAsyncContext getAsyncContext} on the given
+ * <tt>event</tt>.
+ *
+ * <p>In addition, if this AsyncListener had been registered via a call
+ * to {@link AsyncContext#addListener(AsyncListener,
+ * ServletRequest, ServletResponse)}, the supplied ServletRequest and
+ * ServletResponse objects may be retrieved by calling
+ * {@link AsyncEvent#getSuppliedRequest getSuppliedRequest} and
+ * {@link AsyncEvent#getSuppliedResponse getSuppliedResponse},
+ * respectively, on the given <tt>event</tt>.
+ *
+ * <p>This AsyncListener will not receive any events related to the
+ * new asynchronous cycle unless it registers itself (via a call
+ * to {@link AsyncContext#addListener}) with the AsyncContext that
+ * is delivered as part of the given AsyncEvent.
+ *
+ * @param event the AsyncEvent indicating that a new asynchronous
+ * cycle is being initiated
+ *
+ * @throws IOException if an I/O related error has occurred during the
+ * processing of the given AsyncEvent
+ */
+ public void onStartAsync(AsyncEvent event) throws IOException;
+
}
Modified: trunk/java/javax/servlet/ServletRequest.java
===================================================================
--- trunk/java/javax/servlet/ServletRequest.java 2009-10-07 11:59:37 UTC (rev 1184)
+++ trunk/java/javax/servlet/ServletRequest.java 2009-10-08 10:44:14 UTC (rev 1185)
@@ -605,21 +605,13 @@
/**
* Puts this request into asynchronous mode, and initializes its
* {@link AsyncContext} with the original (unwrapped) ServletRequest
- * and ServletResponse objects and the timeout as returned by
- * {@link #getAsyncTimeout}.
+ * and ServletResponse objects.
*
* <p>Calling this method will cause committal of the associated
* response to be delayed until {@link AsyncContext#complete} is
* called on the returned {@link AsyncContext}, or the asynchronous
* operation has timed out.
*
- * <p>The timer for asynchronous timeouts will not start until the
- * container-initiated dispatch that called <tt>startAsync</tt>
- * has returned to the container.
- *
- * <p>See {@link AsyncContext} for a description of how timeouts of
- * asynchronous operations are handled by the container.
- *
* <p>Calling {@link AsyncContext#hasOriginalRequestAndResponse()} on
* the returned AsyncContext will return <code>true</code>. Any filters
* invoked in the <i>outbound</i> direction after this request was put
@@ -629,6 +621,12 @@
* operation, and therefore any of their associated resources may be
* released.
*
+ * <p>This method clears the list of {@link AsyncListener} instances
+ * (if any) that were registered with the AsyncContext returned by the
+ * previous call to one of the startAsync methods, after calling each
+ * AsyncListener at its {@link AsyncListener#onStartAsync onStartAsync}
+ * method.
+ *
* <p>Subsequent invocations of this method, or its overloaded
* variant, will return the same AsyncContext instance, reinitialized
* as appropriate.
@@ -636,11 +634,13 @@
* @return the (re)initialized AsyncContext
*
* @throws IllegalStateException if this request is within the scope of
- * a filter or servlet that does not support asynchronous operation,
- * that is, if {@link #isAsyncSupported} returns false, or if this method
- * is called again outside the scope of a dispatch resulting from an
- * {@link AsyncContext#dispatch}, or if the response has already been
- * closed
+ * a filter or servlet that does not support asynchronous operations
+ * (that is, {@link #isAsyncSupported} returns false),
+ * or if this method is called again without any asynchronous dispatch
+ * (resulting from one of the {@link AsyncContext#dispatch} methods),
+ * is called outside the scope of any such dispatch, or is called again
+ * within the scope of the same dispatch, or if the response has
+ * already been closed
*
* @since Servlet 3.0
*/
@@ -649,8 +649,7 @@
/**
* Puts this request into asynchronous mode, and initializes its
- * {@link AsyncContext} with the given request and response objects
- * and the timeout as returned by {@link #getAsyncTimeout}.
+ * {@link AsyncContext} with the given request and response objects.
*
* <p>The ServletRequest and ServletResponse arguments must be
* the same instances, or instances of {@link ServletRequestWrapper} and
@@ -664,13 +663,6 @@
* called on the returned {@link AsyncContext}, or the asynchronous
* operation has timed out.
*
- * <p>The timer for asynchronous timeouts will not start until the
- * container-initiated dispatch that called <tt>startAsync</tt>
- * has returned to the container.
- *
- * <p>See {@link AsyncContext} for a description of how timeouts of
- * asynchronous operations are handled by the container.
- *
* <p>Calling {@link AsyncContext#hasOriginalRequestAndResponse()} on
* the returned AsyncContext will return <code>false</code>,
* unless the passed in ServletRequest and ServletResponse arguments
@@ -689,6 +681,12 @@
* ServletRequestWrapper. The same holds true for ServletResponseWrapper
* instances.
*
+ * <p>This method clears the list of {@link AsyncListener} instances
+ * (if any) that were registered with the AsyncContext returned by the
+ * previous call to one of the startAsync methods, after calling each
+ * AsyncListener at its {@link AsyncListener#onStartAsync onStartAsync}
+ * method.
+ *
* <p>Subsequent invocations of this method, or its zero-argument
* variant, will return the same AsyncContext instance, reinitialized
* as appropriate. If a call to this method is followed by a call to its
@@ -704,11 +702,13 @@
* @return the (re)initialized AsyncContext
*
* @throws IllegalStateException if this request is within the scope of
- * a filter or servlet that does not support asynchronous operation,
- * that is, if {@link #isAsyncSupported} returns false, or if this method
- * is called again outside the scope of a dispatch resulting from an
- * {@link AsyncContext#dispatch}, or if the response has already been
- * closed
+ * a filter or servlet that does not support asynchronous operations
+ * (that is, {@link #isAsyncSupported} returns false),
+ * or if this method is called again without any asynchronous dispatch
+ * (resulting from one of the {@link AsyncContext#dispatch} methods),
+ * is called outside the scope of any such dispatch, or is called again
+ * within the scope of the same dispatch, or if the response has
+ * already been closed
*
* @since Servlet 3.0
*/
@@ -773,110 +773,6 @@
/**
- * Registers the given {@link AsyncListener} with this request.
- *
- * <p>If this request is put into asynchronous mode, the given
- * AsyncListener will receive an {@link AsyncEvent} when the
- * asynchronous operation completes, times out, or fails to complete.
- *
- * <p>AsyncListener instances will be notified in the order
- * in which they were added to this request.
- *
- * @param listener the AsyncListener to be registered
- *
- * @since Servlet 3.0
- */
- public void addAsyncListener(AsyncListener listener);
-
-
- /**
- * Registers the given {@link AsyncListener} with this request for
- * asynchronous complete, timeout, and error events.
- *
- * <p>If this request is put into asynchronous mode, the given
- * AsyncListener will receive an {@link AsyncEvent} when the
- * asynchronous operation completes, times out, or fails to complete.
- *
- * <p>AsyncListener instances will be notified in the order
- * in which they were added to this request.
- *
- * <p>The given ServletRequest and ServletResponse objects will
- * be made available to the given AsyncListener via the
- * {@link AsyncEvent#getSuppliedRequest getSuppliedRequest} and
- * {@link AsyncEvent#getSuppliedResponse getSuppliedResponse} methods,
- * respectively, of the {@link AsyncEvent} delivered to it. These objects
- * should not be read from or written to, respectively, at the time the
- * AsyncEvent is delivered, because additional wrapping may have
- * occurred since the given AsyncListener was registered, but may be used
- * in order to release any resources associated with them.
- *
- * @param listener the AsyncListener to be registered
- * @param servletRequest the ServletRequest that will be included
- * in the AsyncEvent
- * @param servletResponse the ServletResponse that will be included
- * in the AsyncEvent
- *
- * @since Servlet 3.0
- */
- public void addAsyncListener(AsyncListener listener,
- ServletRequest servletRequest,
- ServletResponse servletResponse);
-
-
- /**
- * Sets the timeout (in milliseconds) for any asynchronous operations
- * started on this request by a call to {@link #startAsync} or
- * {@link #startAsync(ServletRequest, ServletResponse)}.
- *
- * <p>By default, the container's default timeout for asynchronous
- * operations, which is available via a call to
- * {@link #getAsyncTimeout}, will be used.
- * A timeout value of 0 or less indicates that the asynchronous
- * operations will never time out.
- *
- * <p>See {@link AsyncContext} for a description of how timeouts of
- * asynchronous operations are handled by the container.
- *
- * <p>This method raises an <code>IllegalStateException</code> if
- * called after {@link #startAsync}, unless it is called within the
- * scope of an {@link AsyncContext#dispatch}, in which case the specified
- * timeout will be used to initialize the AsyncContext created by a new
- * call to {@link #startAsync}, or will be ignored if {@link #startAsync}
- * is not called again.
- *
- * @param timeout the timeout in milliseconds for any asynchronous
- * operations started on this request
- *
- * @throws IllegalStateException if called after {@link #startAsync},
- * unless within the scope of a dispatch resulting from an
- * {@link AsyncContext#dispatch}
- *
- * @since Servlet 3.0
- */
- public void setAsyncTimeout(long timeout);
-
-
- /**
- * Gets the timeout (in milliseconds) for any asynchronous operations
- * initiated on this request by a call to {@link #startAsync} or
- * {@link #startAsync(ServletRequest, ServletResponse)}.
- *
- * <p>This method returns the container's default timeout for
- * asynchronous operations, or the timeout value passed to the most
- * recent invocation of {@link #setAsyncTimeout}.
- *
- * <p>A timeout value of 0 or less indicates that the asynchronous
- * operation will never time out.
- *
- * @return the timeout in milliseconds for any asynchronous
- * operations started on this request
- *
- * @since Servlet 3.0
- */
- public long getAsyncTimeout();
-
-
- /**
* Gets the dispatcher type of this request.
*
* <p>The dispatcher type of a request is used by the container
Modified: trunk/java/javax/servlet/ServletRequestWrapper.java
===================================================================
--- trunk/java/javax/servlet/ServletRequestWrapper.java 2009-10-07 11:59:37 UTC (rev 1184)
+++ trunk/java/javax/servlet/ServletRequestWrapper.java 2009-10-08 10:44:14 UTC (rev 1185)
@@ -396,19 +396,19 @@
/**
- * Puts the wrapped request into asynchronous mode, and initializes its
- * {@link AsyncContext} with the original ServletRequest and
- * ServletResponse objects and the timeout derived according to
- * the rules laid out in {@link #setAsyncTimeout}.
+ * The default behavior of this method is to invoke
+ * {@link ServletRequest#startAsync} on the wrapped request object.
*
* @return the (re)initialized AsyncContext
*
- * @throws IllegalStateException if this request is within the scope of
- * a filter or servlet that does not support asynchronous operation,
- * that is, if {@link #isAsyncSupported} returns false, or if this method
- * is called again outside the scope of a dispatch resulting from an
- * {@link AsyncContext#dispatch}, or if the response has already been
- * closed
+ * @throws IllegalStateException if the request is within the scope of
+ * a filter or servlet that does not support asynchronous operations
+ * (that is, {@link #isAsyncSupported} returns false),
+ * or if this method is called again without any asynchronous dispatch
+ * (resulting from one of the {@link AsyncContext#dispatch} methods),
+ * is called outside the scope of any such dispatch, or is called again
+ * within the scope of the same dispatch, or if the response has
+ * already been closed
*
* @see ServletRequest#startAsync
*
@@ -420,10 +420,9 @@
/**
- * Puts the wrapped request into asynchronous mode, and initializes its
- * {@link AsyncContext} with the given request and response objects
- * and the timeout derived according to the rules laid out in
- * {@link #setAsyncTimeout}.
+ * The default behavior of this method is to invoke
+ * {@link ServletRequest#startAsync(ServletRequest, ServletResponse)}
+ * on the wrapped request object.
*
* @param servletRequest the ServletRequest used to initialize the
* AsyncContext
@@ -431,14 +430,16 @@
* AsyncContext
*
* @return the (re)initialized AsyncContext
- *
- * @throws IllegalStateException if this request is within the scope of
- * a filter or servlet that does not support asynchronous operation,
- * that is, if {@link #isAsyncSupported} returns false, or if this method
- * is called again outside the scope of a dispatch resulting from an
- * {@link AsyncContext#dispatch}, or if the response has already been
- * closed
*
+ * @throws IllegalStateException if the request is within the scope of
+ * a filter or servlet that does not support asynchronous operations
+ * (that is, {@link #isAsyncSupported} returns false),
+ * or if this method is called again without any asynchronous dispatch
+ * (resulting from one of the {@link AsyncContext#dispatch} methods),
+ * is called outside the scope of any such dispatch, or is called again
+ * within the scope of the same dispatch, or if the response has
+ * already been closed
+ *
* @see ServletRequest#startAsync(ServletRequest, ServletResponse)
*
* @since Servlet 3.0
@@ -505,80 +506,6 @@
/**
- * Registers the given {@link AsyncListener} with the wrapped request
- * for asynchronous complete and timeout events.
- *
- * @param listener the AsyncListener to be registered
- *
- * @see ServletRequest#addAsyncListener(AsyncListener)
- *
- * @since Servlet 3.0
- */
- public void addAsyncListener(AsyncListener listener) {
- request.addAsyncListener(listener);
- }
-
-
- /**
- * Registers the given {@link AsyncListener}, {@link ServletRequest},
- * and {@link ServletResponse} with the wrapped request for asynchronous
- * complete and timeout events.
- *
- * @param listener the AsyncListener to be registered
- * @param servletRequest the ServletRequest that will be included
- * in the AsyncEvent
- * @param servletResponse the ServletResponse that will be included
- * in the AsyncEvent
- *
- * @see ServletRequest#addAsyncListener(AsyncListener, ServletRequest,
- * ServletResponse)
- *
- * @since Servlet 3.0
- */
- public void addAsyncListener(AsyncListener listener,
- ServletRequest servletRequest,
- ServletResponse servletResponse) {
- request.addAsyncListener(listener, servletRequest, servletResponse);
- }
-
-
- /**
- * Sets the timeout (in milliseconds) for any asynchronous operations
- * initiated on the wrapped request.
- *
- * @param timeout the timeout in milliseconds for any asynchronous
- * operations initiated on the wrapped request
- *
- * @throws IllegalStateException if called after {@link #startAsync},
- * unless within the scope of a dispatch resulting from an
- * {@link AsyncContext#dispatch}
- *
- * @see ServletRequest#setAsyncTimeout
- *
- * @since Servlet 3.0
- */
- public void setAsyncTimeout(long timeout) {
- request.setAsyncTimeout(timeout);
- }
-
-
- /**
- * Gets the timeout (in milliseconds) for any asynchronous operations
- * initiated on the wrapped request.
- *
- * @return the timeout in milliseconds for any asynchronous
- * operations initiated on the wrapped request
- *
- * @see ServletRequest#getAsyncTimeout
- *
- * @since Servlet 3.0
- */
- public long getAsyncTimeout() {
- return request.getAsyncTimeout();
- }
-
-
- /**
* Checks (recursively) if this ServletRequestWrapper wraps the given
* {@link ServletRequest} instance.
*
Modified: trunk/java/org/apache/catalina/connector/Request.java
===================================================================
--- trunk/java/org/apache/catalina/connector/Request.java 2009-10-07 11:59:37 UTC (rev 1184)
+++ trunk/java/org/apache/catalina/connector/Request.java 2009-10-08 10:44:14 UTC (rev 1185)
@@ -66,7 +66,6 @@
import javax.security.auth.Subject;
import javax.servlet.AsyncContext;
-import javax.servlet.AsyncEvent;
import javax.servlet.AsyncListener;
import javax.servlet.DispatcherType;
import javax.servlet.RequestDispatcher;
@@ -270,8 +269,8 @@
/**
* Async listeners.
*/
- protected LinkedHashMap<AsyncEvent, AsyncListener> asyncListeners =
- new LinkedHashMap<AsyncEvent, AsyncListener>();
+ protected LinkedHashMap<AsyncListener, AsyncListenerRegistration> asyncListeners =
+ new LinkedHashMap<AsyncListener, AsyncListenerRegistration>();
/**
@@ -2972,16 +2971,6 @@
return true;
}
- public void addAsyncListener(AsyncListener listener,
- ServletRequest servletRequest, ServletResponse servletResponse) {
- AsyncEvent event = new AsyncEvent(asyncContext, servletRequest, servletResponse);
- asyncListeners.put(event, listener);
- }
-
- public void addAsyncListener(AsyncListener listener) {
- addAsyncListener(listener, getRequest(), response.getResponse());
- }
-
public AsyncContext getAsyncContext() {
return asyncContext;
}
@@ -3010,20 +2999,19 @@
return true;
}
- public long getAsyncTimeout() {
- return this.asyncTimeout;
- }
-
- public void setAsyncTimeout(long asyncTimeout) {
- this.asyncTimeout = asyncTimeout;
- }
-
public AsyncContext startAsync() throws IllegalStateException {
return startAsync(null, null);
}
public AsyncContext startAsync(ServletRequest servletRequest,
ServletResponse servletResponse) throws IllegalStateException {
+ /* TODO
+ * <p>This method clears the list of {@link AsyncListener} instances
+ * (if any) that were registered with the AsyncContext returned by the
+ * previous call to one of the startAsync methods, after calling each
+ * AsyncListener at its {@link AsyncListener#onStartAsync onStartAsync}
+ * method.
+ */
int timeout = (asyncTimeout > Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int) asyncTimeout;
if (timeout <= 0) {
timeout = Integer.MAX_VALUE;
@@ -3170,8 +3158,8 @@
public class AsyncContextImpl implements AsyncContext {
- protected ServletRequest request = null;
- protected ServletResponse response = null;
+ protected ServletRequest servletRequest = null;
+ protected ServletResponse servletResponse = null;
protected ServletContext servletContext = null;
protected String path = null;
@@ -3186,12 +3174,12 @@
}
public void dispatch() {
- if (request == getRequestFacade()) {
+ if (servletRequest == getRequestFacade()) {
// Get the path directly
path = getRequestPathMB().toString();
- } else if (request instanceof HttpServletRequest) {
+ } else if (servletRequest instanceof HttpServletRequest) {
// Rebuild the path
- path = ((HttpServletRequest) request).getRequestURI();
+ path = ((HttpServletRequest) servletRequest).getRequestURI();
if (servletContext != null) {
path = path.substring(servletContext.getContextPath().length());
} else {
@@ -3214,23 +3202,23 @@
}
public ServletRequest getRequest() {
- if (request != null) {
- return request;
+ if (servletRequest != null) {
+ return servletRequest;
} else {
return getRequestFacade();
}
}
public ServletResponse getResponse() {
- if (response != null) {
- return response;
+ if (servletResponse != null) {
+ return servletResponse;
} else {
return getResponseFacade();
}
}
public boolean hasOriginalRequestAndResponse() {
- return (request == getRequestFacade() && response == getResponseFacade());
+ return (servletRequest == getRequestFacade() && servletResponse == getResponseFacade());
}
public void start(Runnable runnable) {
@@ -3246,12 +3234,12 @@
ready = false;
}
- public void setRequestAndResponse(ServletRequest request, ServletResponse response) {
- if (request == null && response == null) {
+ public void setRequestAndResponse(ServletRequest servletRequest, ServletResponse servletResponse) {
+ if (servletRequest == null && response == null) {
}
- this.request = request;
- this.response = response;
+ this.servletRequest = servletRequest;
+ this.servletResponse = servletResponse;
}
public ServletContext getServletContext() {
@@ -3278,11 +3266,55 @@
ready = true;
}
- public Map<AsyncEvent, AsyncListener> getAsyncListeners() {
+ public Map<AsyncListener, AsyncListenerRegistration> getAsyncListeners() {
return asyncListeners;
}
+ public void addListener(AsyncListener listener,
+ ServletRequest servletRequest, ServletResponse servletResponse) {
+ asyncListeners.put(listener,
+ new AsyncListenerRegistration(listener, servletRequest, servletResponse));
+ }
+
+ public void addListener(AsyncListener listener) {
+ addListener(listener, getRequest(), response.getResponse());
+ }
+
+ public long getTimeout() {
+ return asyncTimeout;
+ }
+
+ public void setTimeout(long timeout) {
+ asyncTimeout = timeout;
+ }
+
}
+
+ // ------------------------------------------ RequestResponse Inner Class
+
+ public class AsyncListenerRegistration {
+ protected ServletRequest request;
+ protected ServletResponse response;
+ protected AsyncListener listener;
+ protected AsyncListenerRegistration(AsyncListener listener,
+ ServletRequest request, ServletResponse response)
+ {
+ this.listener = listener;
+ this.request = request;
+ this.response = response;
+ }
+ public ServletRequest getRequest() {
+ return request;
+ }
+ public ServletResponse getResponse() {
+ return response;
+ }
+ public AsyncListener getListener() {
+ return listener;
+ }
+ }
+
+
}
Modified: trunk/java/org/apache/catalina/connector/RequestFacade.java
===================================================================
--- trunk/java/org/apache/catalina/connector/RequestFacade.java 2009-10-07 11:59:37 UTC (rev 1184)
+++ trunk/java/org/apache/catalina/connector/RequestFacade.java 2009-10-08 10:44:14 UTC (rev 1185)
@@ -28,7 +28,6 @@
import java.util.Map;
import javax.servlet.AsyncContext;
-import javax.servlet.AsyncListener;
import javax.servlet.DispatcherType;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
@@ -942,27 +941,6 @@
}
- public void addAsyncListener(AsyncListener listener,
- ServletRequest servletRequest, ServletResponse servletResponse) {
- if (request == null) {
- throw new IllegalStateException(
- sm.getString("requestFacade.nullRequest"));
- }
-
- request.addAsyncListener(listener, servletRequest, servletResponse);
- }
-
-
- public void addAsyncListener(AsyncListener listener) {
- if (request == null) {
- throw new IllegalStateException(
- sm.getString("requestFacade.nullRequest"));
- }
-
- request.addAsyncListener(listener);
- }
-
-
public AsyncContext getAsyncContext() {
if (request == null) {
throw new IllegalStateException(
@@ -1003,26 +981,6 @@
}
- public void setAsyncTimeout(long timeout) {
- if (request == null) {
- throw new IllegalStateException(
- sm.getString("requestFacade.nullRequest"));
- }
-
- request.setAsyncTimeout(timeout);
- }
-
-
- public long getAsyncTimeout() {
- if (request == null) {
- throw new IllegalStateException(
- sm.getString("requestFacade.nullRequest"));
- }
-
- return request.getAsyncTimeout();
- }
-
-
public AsyncContext startAsync() throws IllegalStateException {
if (request == null) {
throw new IllegalStateException(
Modified: trunk/java/org/apache/catalina/core/StandardWrapperValve.java
===================================================================
--- trunk/java/org/apache/catalina/core/StandardWrapperValve.java 2009-10-07 11:59:37 UTC (rev 1184)
+++ trunk/java/org/apache/catalina/core/StandardWrapperValve.java 2009-10-08 10:44:14 UTC (rev 1185)
@@ -48,7 +48,6 @@
import java.io.IOException;
-import java.io.PrintWriter;
import java.util.Iterator;
import javax.management.MalformedObjectNameException;
@@ -58,7 +57,6 @@
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
-import javax.servlet.ServletOutputStream;
import javax.servlet.UnavailableException;
import javax.servlet.http.HttpServletResponse;
@@ -67,7 +65,7 @@
import org.apache.catalina.connector.ClientAbortException;
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
-import org.apache.catalina.connector.ResponseFacade;
+import org.apache.catalina.connector.Request.AsyncListenerRegistration;
import org.apache.catalina.util.StringManager;
import org.apache.catalina.valves.ValveBase;
import org.apache.tomcat.util.log.SystemLogHandler;
@@ -407,22 +405,27 @@
// Invoke the listeners with onComplete or onTimeout
boolean timeout = (event.getType() == EventType.TIMEOUT) ? true : false;
boolean error = (event.getType() == EventType.ERROR) ? true : false;
- Iterator<AsyncEvent> asyncEvents = asyncContext.getAsyncListeners().keySet().iterator();
- if (timeout && !asyncEvents.hasNext()) {
+ Iterator<AsyncListenerRegistration> asyncListenerRegistrations =
+ asyncContext.getAsyncListeners().values().iterator();
+ if (timeout && !asyncListenerRegistrations.hasNext()) {
// FIXME: MUST do an ERROR dispatch to the original URI and MUST set the response code to 500
}
- while (asyncEvents.hasNext()) {
- AsyncEvent asyncEvent = asyncEvents.next();
- AsyncListener asyncListener = asyncContext.getAsyncListeners().get(asyncEvent);
+ while (asyncListenerRegistrations.hasNext()) {
+ AsyncListenerRegistration asyncListenerRegistration = asyncListenerRegistrations.next();
+ AsyncListener asyncListener = asyncListenerRegistration.getListener();
try {
if (timeout) {
+ AsyncEvent asyncEvent = new AsyncEvent(asyncContext,
+ asyncListenerRegistration.getRequest(), asyncListenerRegistration.getResponse());
asyncListener.onTimeout(asyncEvent);
} else if (error) {
Throwable t = (Throwable) request.getAttribute(Globals.EXCEPTION_ATTR);
- AsyncEvent asyncEvent2 = new AsyncEvent(asyncEvent.getAsyncContext(),
- asyncEvent.getSuppliedRequest(), asyncEvent.getSuppliedResponse(), t);
- asyncListener.onError(asyncEvent2);
+ AsyncEvent asyncEvent = new AsyncEvent(asyncContext,
+ asyncListenerRegistration.getRequest(), asyncListenerRegistration.getResponse(), t);
+ asyncListener.onError(asyncEvent);
} else {
+ AsyncEvent asyncEvent = new AsyncEvent(asyncContext,
+ asyncListenerRegistration.getRequest(), asyncListenerRegistration.getResponse());
asyncListener.onComplete(asyncEvent);
}
} catch (Throwable e) {
15 years, 2 months