Author: bdekruijff at gmail.com
Date: Tue Feb 8 14:09:27 2011
New Revision: 767
Log:
AMDATU-292 prevent a NPE resulting in a 500 when no dispatcher is available
Modified:
branches/amdatu-dispatcher/amdatu-web/rest-wink/src/main/java/org/amdatu/web/rest/wink/service/WinkServletFilter.java
Modified:
branches/amdatu-dispatcher/amdatu-web/rest-wink/src/main/java/org/amdatu/web/rest/wink/service/WinkServletFilter.java
==============================================================================
---
branches/amdatu-dispatcher/amdatu-web/rest-wink/src/main/java/org/amdatu/web/rest/wink/service/WinkServletFilter.java
(original)
+++
branches/amdatu-dispatcher/amdatu-web/rest-wink/src/main/java/org/amdatu/web/rest/wink/service/WinkServletFilter.java
Tue Feb 8 14:09:27 2011
@@ -26,6 +26,7 @@
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
/**
* The Wink servlet filter has only one purpose; getting rid of the double
path occurrence in the URLs of the
@@ -38,8 +39,9 @@
* The easitest way to fix this issue, without the need to override many Wink
classes, is to associate a servlet
* filter with /rest/users which just forwrds the request internally to
/rest/users/users. This
* is exactly what this filter does.
+ *
* @author ivol
- *
+ *
*/
public class WinkServletFilter implements Filter {
// URL from which requests must be dispatched
@@ -51,6 +53,7 @@
/**
* Instantiates a new Wink servlet filter with the purpose of removing the
double occurrence of the
* Path in the URL of the REST service.
+ *
* @param from The desired URL of the REST service
* @param to The actual URL of the REST services
*/
@@ -59,7 +62,8 @@
m_dispatchTo = to;
}
- public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
+ public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException,
+ ServletException {
String path = ((HttpServletRequest) request).getRequestURI();
// To prevent endless recursion we verify that the path doesn't start
with our target path. There is one
@@ -69,8 +73,14 @@
if (path.startsWith(m_dispatchFrom) && !path.startsWith(m_dispatchTo))
{
String targetPath = path.replace(m_dispatchFrom, m_dispatchTo);
RequestDispatcher dispatcher =
request.getRequestDispatcher(targetPath);
- dispatcher.forward(request, response);
- } else {
+ if (dispatcher == null) {
+ ((HttpServletResponse)
response).sendError(HttpServletResponse.SC_NOT_FOUND);
+ }
+ else {
+ dispatcher.forward(request, response);
+ }
+ }
+ else {
chain.doFilter(request, response);
}
}