Browse Source

DispatcherPortlet throws custom NoHandlerFoundException instead of misleading UnavailableException (SPR-7542)

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3684 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Juergen Hoeller 16 years ago
parent
commit
a0c93b7e91
  1. 9
      org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/DispatcherPortlet.java
  2. 53
      org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/NoHandlerFoundException.java
  3. 4
      org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/mvc/PortletWrappingController.java
  4. 8
      org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerAdapter.java

9
org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/DispatcherPortlet.java

@ -39,7 +39,6 @@ import javax.portlet.RenderResponse; @@ -39,7 +39,6 @@ import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import javax.portlet.StateAwareResponse;
import javax.portlet.UnavailableException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -51,6 +50,7 @@ import org.springframework.context.ApplicationContext; @@ -51,6 +50,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.core.OrderComparator;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.core.style.StylerUtils;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartException;
@ -988,14 +988,13 @@ public class DispatcherPortlet extends FrameworkPortlet { @@ -988,14 +988,13 @@ public class DispatcherPortlet extends FrameworkPortlet {
*/
protected void noHandlerFound(PortletRequest request, PortletResponse response) throws Exception {
if (pageNotFoundLogger.isWarnEnabled()) {
pageNotFoundLogger.warn("No mapping found for current request " +
pageNotFoundLogger.warn("No handler found for current request " +
"in DispatcherPortlet with name '" + getPortletName() +
"', mode '" + request.getPortletMode() +
"', phase '" + request.getAttribute(PortletRequest.LIFECYCLE_PHASE) +
"', session '" + request.getRequestedSessionId() +
"', user '" + getUsernameForRequest(request) + "'");
"', parameters " + StylerUtils.style(request.getParameterMap()));
}
throw new UnavailableException("No handler found for request");
throw new NoHandlerFoundException("No handler found for portlet request", request);
}
/**

53
org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/NoHandlerFoundException.java

@ -0,0 +1,53 @@ @@ -0,0 +1,53 @@
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed 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.springframework.web.portlet;
import javax.portlet.PortletException;
import javax.portlet.PortletRequest;
import org.springframework.core.style.StylerUtils;
/**
* Exception to be thrown if DispatcherPortlet is unable to determine
* a corresponding handler for an incoming portlet request.
*
* @author Juergen Hoeller
* @since 3.0.5
*/
public class NoHandlerFoundException extends PortletException {
/**
* Constructor for NoHandlerFoundException.
* @param msg the detail message
*/
public NoHandlerFoundException(String msg) {
super(msg);
}
/**
* Constructor for NoHandlerFoundException.
* @param msg the detail message
* @param request the current portlet request,
* for further context to be included in the exception message
*/
public NoHandlerFoundException(String msg, PortletRequest request) {
super(msg + ": mode '" + request.getPortletMode() +
"', phase '" + request.getAttribute(PortletRequest.LIFECYCLE_PHASE) +
"', parameters " + StylerUtils.style(request.getParameterMap()));
}
}

4
org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/mvc/PortletWrappingController.java

@ -37,7 +37,6 @@ import javax.portlet.RenderResponse; @@ -37,7 +37,6 @@ import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import javax.portlet.ResourceServingPortlet;
import javax.portlet.UnavailableException;
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
@ -45,6 +44,7 @@ import org.springframework.beans.factory.BeanNameAware; @@ -45,6 +44,7 @@ import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.web.portlet.ModelAndView;
import org.springframework.web.portlet.NoHandlerFoundException;
import org.springframework.web.portlet.context.PortletConfigAware;
import org.springframework.web.portlet.context.PortletContextAware;
import org.springframework.web.portlet.util.PortletUtils;
@ -190,7 +190,7 @@ public class PortletWrappingController extends AbstractController @@ -190,7 +190,7 @@ public class PortletWrappingController extends AbstractController
ResourceRequest request, ResourceResponse response) throws Exception {
if (!(this.portletInstance instanceof ResourceServingPortlet)) {
throw new UnavailableException("Cannot handle resource request - target portlet [" +
throw new NoHandlerFoundException("Cannot handle resource request - target portlet [" +
this.portletInstance.getClass() + " does not implement ResourceServingPortlet");
}
ResourceServingPortlet resourcePortlet = (ResourceServingPortlet) this.portletInstance;

8
org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerAdapter.java

@ -48,7 +48,6 @@ import javax.portlet.RenderResponse; @@ -48,7 +48,6 @@ import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import javax.portlet.StateAwareResponse;
import javax.portlet.UnavailableException;
import javax.portlet.WindowState;
import javax.servlet.http.Cookie;
@ -62,7 +61,6 @@ import org.springframework.core.LocalVariableTableParameterNameDiscoverer; @@ -62,7 +61,6 @@ import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.core.Ordered;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.style.StylerUtils;
import org.springframework.ui.ExtendedModelMap;
import org.springframework.ui.Model;
import org.springframework.util.Assert;
@ -88,6 +86,7 @@ import org.springframework.web.context.request.RequestScope; @@ -88,6 +86,7 @@ import org.springframework.web.context.request.RequestScope;
import org.springframework.web.multipart.MultipartRequest;
import org.springframework.web.portlet.HandlerAdapter;
import org.springframework.web.portlet.ModelAndView;
import org.springframework.web.portlet.NoHandlerFoundException;
import org.springframework.web.portlet.bind.MissingPortletRequestParameterException;
import org.springframework.web.portlet.bind.PortletRequestDataBinder;
import org.springframework.web.portlet.bind.annotation.ActionMapping;
@ -505,10 +504,7 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator @@ -505,10 +504,7 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator
}
}
else {
throw new UnavailableException(
"No matching handler method found for portlet request: mode '" + request.getPortletMode() +
"', phase '" + request.getAttribute(PortletRequest.LIFECYCLE_PHASE) +
"', parameters " + StylerUtils.style(request.getParameterMap()));
throw new NoHandlerFoundException("No matching handler method found for portlet request", request);
}
}

Loading…
Cancel
Save