Author: thomas.heute(a)jboss.com
Date: 2008-10-07 06:22:17 -0400 (Tue, 07 Oct 2008)
New Revision: 12041
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/classic/OtherResponseHandler.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/command/view/ViewContextCommand.java
Log:
JBPORTAL-2178: NPE when requesting dashboard as unauthenticated user
Don't NPE but returns a 500 error
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/classic/OtherResponseHandler.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/classic/OtherResponseHandler.java 2008-10-07
09:06:48 UTC (rev 12040)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/classic/OtherResponseHandler.java 2008-10-07
10:22:17 UTC (rev 12041)
@@ -175,7 +175,7 @@
log.error("An error occured", cause);
}
- return HTTPResponse.sendError();
+ return HTTPResponse.sendError(errorResponse.getMessage());
}
else if (controllerResponse instanceof UnavailableResourceResponse)
{
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java 2008-10-07
09:06:48 UTC (rev 12040)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java 2008-10-07
10:22:17 UTC (rev 12041)
@@ -124,27 +124,49 @@
public static HTTPResponse sendForbidden()
{
- return sendStatus(HttpServletResponse.SC_FORBIDDEN);
+ return sendStatus(HttpServletResponse.SC_FORBIDDEN, null);
}
public static HTTPResponse sendNotFound()
{
- return sendStatus(HttpServletResponse.SC_NOT_FOUND);
+ return sendStatus(HttpServletResponse.SC_NOT_FOUND, null);
}
public static HTTPResponse sendError()
{
- return sendStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ return sendStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null);
}
- private static HTTPResponse sendStatus(final int statusCode)
+ public static HTTPResponse sendForbidden(String message)
{
+ return sendStatus(HttpServletResponse.SC_FORBIDDEN, message);
+ }
+
+ public static HTTPResponse sendNotFound(String message)
+ {
+ return sendStatus(HttpServletResponse.SC_NOT_FOUND, message);
+ }
+
+ public static HTTPResponse sendError(String message)
+ {
+ return sendStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
+ }
+
+ private static HTTPResponse sendStatus(final int statusCode, final String message)
+ {
return new HTTPResponse()
{
public void sendResponse(ServerInvocationContext ctx) throws IOException
{
HttpServletResponse resp = ctx.getClientResponse();
- resp.sendError(statusCode);
+ if (message == null)
+ {
+ resp.sendError(statusCode);
+ }
+ else
+ {
+ resp.sendError(statusCode, message);
+ }
}
};
}
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/command/view/ViewContextCommand.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/command/view/ViewContextCommand.java 2008-10-07
09:06:48 UTC (rev 12040)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/command/view/ViewContextCommand.java 2008-10-07
10:22:17 UTC (rev 12041)
@@ -26,6 +26,8 @@
import org.jboss.portal.core.controller.ControllerResponse;
import org.jboss.portal.core.controller.command.info.CommandInfo;
import org.jboss.portal.core.controller.command.info.ViewCommandInfo;
+import org.jboss.portal.core.controller.command.response.ErrorResponse;
+import org.jboss.portal.core.controller.command.response.UnavailableResourceResponse;
import org.jboss.portal.core.model.portal.Page;
import org.jboss.portal.core.model.portal.Portal;
import org.jboss.portal.core.model.portal.PortalObjectId;
@@ -58,9 +60,22 @@
if (isDashboard())
{
User user = context.getUser();
+
+ if (user == null)
+ {
+ return new ErrorResponse("No authenticated user", false);
+ }
+
Portal portal =
context.getController().getCustomizationManager().getDashboard(user);
- Page page = portal.getDefaultPage();
- return new UpdatePageResponse(page.getId());
+ if (portal != null)
+ {
+ Page page = portal.getDefaultPage();
+ return new UpdatePageResponse(page.getId());
+ }
+ else
+ {
+ return new UnavailableResourceResponse("Dashboard for user:" +
user.getUserName() + " can't be found" , false);
+ }
}
else
{
Show replies by date