You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2017/04/27 11:42:01 UTC
svn commit: r1792868 - in
/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal:
dispatch/ handler/ runtime/
Author: cziegeler
Date: Thu Apr 27 11:42:01 2017
New Revision: 1792868
URL: http://svn.apache.org/viewvc?rev=1792868&view=rev
Log:
FELIX-5296 : Implement Http Whiteboard Service Updates (RFC 223)
Modified:
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/MultipartConfig.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/RequestDispatcherImpl.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandler.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/AbstractInfo.java
felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletInfo.java
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java?rev=1792868&r1=1792867&r2=1792868&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java Thu Apr 27 11:42:01 2017
@@ -89,16 +89,16 @@ public final class Dispatcher
// invoke preprocessors and then dispatching
mgr.invokePreprocessors(req, res, new Preprocessor() {
-
+
@Override
- public void init(final FilterConfig filterConfig) throws ServletException
+ public void init(final FilterConfig filterConfig) throws ServletException
{
- // nothing to do
+ // nothing to do
}
-
+
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
- throws IOException, ServletException
+ throws IOException, ServletException
{
final HttpServletRequest req = (HttpServletRequest)request;
final HttpServletResponse res = (HttpServletResponse)response;
@@ -133,7 +133,7 @@ public final class Dispatcher
final HttpServletRequest wrappedRequest = new ServletRequestWrapper(req, servletContext, requestInfo, null,
pr.handler.getContextServiceId(),
pr.handler.getServletInfo().isAsyncSupported(),
- pr.handler.getServletInfo().getMultipartConfig());
+ pr.handler.getMultipartConfig());
final FilterHandler[] filterHandlers = handlerRegistry.getFilters(pr, req.getDispatcherType(), pr.requestURI);
try
@@ -161,13 +161,13 @@ public final class Dispatcher
servletContext.getServletRequestListener().requestDestroyed(new ServletRequestEvent(servletContext, wrappedRequest));
}
} }
-
+
@Override
- public void destroy()
+ public void destroy()
{
// nothing to do
}
- });
+ });
}
}
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/MultipartConfig.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/MultipartConfig.java?rev=1792868&r1=1792867&r2=1792868&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/MultipartConfig.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/MultipartConfig.java Thu Apr 27 11:42:01 2017
@@ -22,7 +22,7 @@ public final class MultipartConfig
{
public static final MultipartConfig DEFAULT_CONFIG = new MultipartConfig(null, null, -1, -1);
- private static final String TEMP_DIR = System.getProperty("java.io.tmpdir");
+ public static final MultipartConfig INVALID_CONFIG = new MultipartConfig(null, null, -1, -1);
/**
* Specifies the multipart threshold
@@ -57,14 +57,7 @@ public final class MultipartConfig
{
this.multipartThreshold = DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD;
}
- if ( location != null )
- {
- this.multipartLocation = location;
- }
- else
- {
- this.multipartLocation = TEMP_DIR;
- }
+ this.multipartLocation = location;
if ( maxFileSize > 0 || maxFileSize == -1 ) {
this.multipartMaxFileSize = maxFileSize;
}
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/RequestDispatcherImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/RequestDispatcherImpl.java?rev=1792868&r1=1792867&r2=1792868&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/RequestDispatcherImpl.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/RequestDispatcherImpl.java Thu Apr 27 11:42:01 2017
@@ -66,7 +66,7 @@ public final class RequestDispatcherImpl
DispatcherType.FORWARD,
this.resolution.handler.getContextServiceId(),
this.resolution.handler.getServletInfo().isAsyncSupported(),
- this.resolution.handler.getServletInfo().getMultipartConfig());
+ this.resolution.handler.getMultipartConfig());
final String requestURI = UriUtils.concat(this.requestInfo.servletPath, this.requestInfo.pathInfo);
final FilterHandler[] filterHandlers = this.resolution.handlerRegistry.getFilterHandlers(this.resolution.handler, DispatcherType.FORWARD, requestURI);
@@ -103,7 +103,7 @@ public final class RequestDispatcherImpl
DispatcherType.INCLUDE,
this.resolution.handler.getContextServiceId(),
this.resolution.handler.getServletInfo().isAsyncSupported(),
- this.resolution.handler.getServletInfo().getMultipartConfig());
+ this.resolution.handler.getMultipartConfig());
final String requestURI = UriUtils.concat(this.requestInfo.servletPath, this.requestInfo.pathInfo);
final FilterHandler[] filterHandlers = this.resolution.handlerRegistry.getFilterHandlers(this.resolution.handler, DispatcherType.INCLUDE, requestURI);
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandler.java?rev=1792868&r1=1792867&r2=1792868&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandler.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandler.java Thu Apr 27 11:42:01 2017
@@ -16,6 +16,7 @@
*/
package org.apache.felix.http.base.internal.handler;
+import java.io.File;
import java.io.IOException;
import javax.servlet.Servlet;
@@ -24,6 +25,7 @@ import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.apache.felix.http.base.internal.context.ExtServletContext;
+import org.apache.felix.http.base.internal.dispatch.MultipartConfig;
import org.apache.felix.http.base.internal.logger.SystemLogger;
import org.apache.felix.http.base.internal.runtime.ServletInfo;
import org.osgi.service.http.runtime.dto.DTOConstants;
@@ -34,6 +36,10 @@ import org.osgi.service.http.runtime.dto
*/
public abstract class ServletHandler implements Comparable<ServletHandler>
{
+ private static final String TEMP_DIR = System.getProperty("java.io.tmpdir");
+
+ private static final String JAVA_SERVLET_TEMP_DIR_PROP = "javax.servlet.content.tempdir";
+
private final long contextServiceId;
private final ServletInfo servletInfo;
@@ -44,6 +50,8 @@ public abstract class ServletHandler imp
protected volatile int useCount;
+ private final MultipartConfig mpConfig;
+
public ServletHandler(final long contextServiceId,
final ExtServletContext context,
final ServletInfo servletInfo)
@@ -51,6 +59,25 @@ public abstract class ServletHandler imp
this.contextServiceId = contextServiceId;
this.context = context;
this.servletInfo = servletInfo;
+ final MultipartConfig origConfig = servletInfo.getMultipartConfig();
+ String location = origConfig.multipartLocation;
+ if ( location == null ) {
+ final Object obj = context.getAttribute(JAVA_SERVLET_TEMP_DIR_PROP);
+ if ( obj != null ) {
+ if ( obj instanceof File ) {
+ location = ((File)obj).getAbsolutePath();
+ } else {
+ location = obj.toString();
+ }
+ }
+ }
+ if ( location == null ) {
+ location = TEMP_DIR;
+ }
+ this.mpConfig = new MultipartConfig(origConfig.multipartThreshold,
+ location,
+ origConfig.multipartMaxFileSize,
+ origConfig.multipartMaxRequestSize);
}
@Override
@@ -189,4 +216,8 @@ public abstract class ServletHandler imp
return servletInfo.equals(other.servletInfo);
}
+ public MultipartConfig getMultipartConfig()
+ {
+ return mpConfig;
+ }
}
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/AbstractInfo.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/AbstractInfo.java?rev=1792868&r1=1792867&r2=1792868&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/AbstractInfo.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/AbstractInfo.java Thu Apr 27 11:42:01 2017
@@ -164,34 +164,6 @@ public abstract class AbstractInfo<T> im
return false;
}
- protected Integer getIntProperty(ServiceReference<T> ref, String key)
- {
- Object value = ref.getProperty(key);
- if (value instanceof String)
- {
- return Integer.valueOf((String) value);
- }
- else if (value instanceof Number)
- {
- return ((Number) value).intValue();
- }
- return null;
- }
-
- protected long getLongProperty(ServiceReference<T> ref, String key)
- {
- Object value = ref.getProperty(key);
- if (value instanceof String)
- {
- return Long.valueOf((String) value);
- }
- else if (value instanceof Number)
- {
- return ((Number) value).longValue();
- }
- return -1;
- }
-
/**
* Get the init parameters.
*/
Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletInfo.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletInfo.java?rev=1792868&r1=1792867&r2=1792868&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletInfo.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletInfo.java Thu Apr 27 11:42:01 2017
@@ -89,10 +89,19 @@ public class ServletInfo extends Whitebo
this.asyncSupported = getBooleanProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED);
if ( getBooleanProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_MULTIPART_ENABLED) )
{
- this.multipartConfig = new MultipartConfig(getIntProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_MULTIPART_FILESIZETHRESHOLD),
- getStringProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_MULTIPART_LOCATION),
- getLongProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_MULTIPART_MAXFILESIZE),
- getLongProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_MULTIPART_MAXREQUESTSIZE));
+ MultipartConfig cfg = null;
+ try
+ {
+ cfg = new MultipartConfig(getIntProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_MULTIPART_FILESIZETHRESHOLD),
+ getStringProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_MULTIPART_LOCATION),
+ getLongProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_MULTIPART_MAXFILESIZE),
+ getLongProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_MULTIPART_MAXREQUESTSIZE));
+ }
+ catch (final IllegalArgumentException iae)
+ {
+ cfg = MultipartConfig.INVALID_CONFIG;
+ }
+ this.multipartConfig = cfg;
}
else
{
@@ -117,6 +126,42 @@ public class ServletInfo extends Whitebo
this.prefix = resource.getPrefix();
}
+ private Integer getIntProperty(final ServiceReference<Servlet> ref, final String key)
+ {
+ final Object value = ref.getProperty(key);
+ if (value instanceof String)
+ {
+ return Integer.valueOf((String) value);
+ }
+ else if (value instanceof Number)
+ {
+ return ((Number) value).intValue();
+ }
+ else if ( value != null )
+ {
+ throw new IllegalArgumentException();
+ }
+ return null;
+ }
+
+ private long getLongProperty(final ServiceReference<Servlet> ref, final String key)
+ {
+ final Object value = ref.getProperty(key);
+ if (value instanceof String)
+ {
+ return Long.valueOf((String) value);
+ }
+ else if (value instanceof Number)
+ {
+ return ((Number) value).longValue();
+ }
+ else if ( value != null )
+ {
+ throw new IllegalArgumentException();
+ }
+ return -1;
+ }
+
@SuppressWarnings("rawtypes")
private static ServiceReference getRef(ServiceReference ref)
{
@@ -144,7 +189,9 @@ public class ServletInfo extends Whitebo
@Override
public boolean isValid()
{
- boolean valid = super.isValid() && !(isEmpty(this.patterns) && isEmpty(this.errorPage) && isEmpty(this.name));
+ boolean valid = super.isValid()
+ && !(isEmpty(this.patterns) && isEmpty(this.errorPage) && isEmpty(this.name))
+ && this.multipartConfig != MultipartConfig.INVALID_CONFIG;
if ( valid )
{
if ( this.patterns != null )