users@glassfish.java.net

Re: Obtaining LoginException

From: <Jan.Luehe_at_Sun.COM>
Date: Thu, 02 Aug 2007 18:51:23 -0700

Shevland, Joe wrote:

>>The error information is exposed to a JSP error page via the
>>page context's ErrorData variable, which is populated from
>>the following servlet request attributes:
>>
>> javax.servlet.error.exception
>> javax.servlet.error.status_code
>> javax.servlet.error.request_uri
>> javax.servlet.error.servlet_name
>>
>>In your JSP error page, you may access this information
>>conveniently via the Expression Language, as follows:
>>
>> ${pageContext.errorData.throwable}
>> ${pageContext.errorData.statusCode}
>> ${pageContext.errorData.requestURI}
>> ${pageContext.errorData.servletName}
>>
>>
>>Jan
>>
>>
>
>Thanks Jan, looks perfect, although I'm seeing an NPE when I try; I
>wasn't sure about the need for isErrorPage="true" in the error page, but
>I've tried with and without. With, the generated servlet code NPE's at:
>
>
>response.setStatus(((Integer)request.getAttribute("javax.servlet.error.s
>tatus_code")).intValue());
>
>with the stack trace:
>
> at
>com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWork
>erThread.java:106)
>Caused by: java.lang.NullPointerException
> at
>org.apache.jsp.login.login_005ferror_jsp._jspService(login_005ferror_jsp
>..java:26)
> at
>org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:93)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
> at
>org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.ja
>va:373)
> ... 35 more
>
>using:
>
> <login-config>
> <auth-method>FORM</auth-method>
> <realm-name>custom_realm</realm-name>
> <form-login-config>
> <form-login-page>/login/login.jsp</form-login-page>
> <form-error-page>/login/login_error.jsp</form-error-page>
> </form-login-config>
> </login-config>
>
>And without the stack trace is altered a little, but still NPE's when
>accessing pageContext.getErrorData(). Might be something I'm not
>configuring correctly (version is v2 b50g).
>
>

OK, I see what's going on.

The servlet spec differentiates between error pages declared via
<error-page>, and error pages applicable to FORM authentication,
which are declared via <form-error-page>.

The error related servlet request attributes mentioned earlier are
exposed only to the former type of error pages, not the latter,
causing the NPE you were seeing.

If you think about it, this makes sense: While error pages declared
via <error-page> receive the request via RequestDispatcher.forward()
(meaning any error-related request attributes added to the request
prior to the dispatch will be visible to them), the same does not
necessarily hold true for error pages declared via <form-error-page>,
which should receive the request via an HTTP redirect,
meaning any error attributes stored on the request prior to the
redirect will be lost.

See

  https://glassfish.dev.java.net/issues/show_bug.cgi?id=3374
  ("FORM authenticator should issue a redirect (instead of a request
   dispatch "forward") to the login page")

for why a <form-login-page> resource (and also <form-error-page>,
since the same resource may be used for both purposes) should receive
the request via an HTTP redirect as opposed to a
RequestDispatcher.forward() operation. We fixed the above issue only
very recently in GlassFish v2 (as of build 57).

I know this is subtle, but I hope it still makes sense to you.

Let me know if you have any questions.


Jan


>Regards
>Joe
>
>This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>
>