2

I have several pages that have the same master template, which contains the header with a log out button. When I try to log out from all pages it works correctly except for one - the one which has request parameters in its URL.

After logout (session invalidation), I'm redirecting back to the login page as follows:

return "/login.xhtml?faces-redirect=true";

When I press logout on URLs like this,

http://localhost:8080/WPA_MOVIEDATABASE/app/index.xhtml

then the redirect works fine and I end up in:

http://localhost:8080/WPA_MOVIEDATABASE/login.xhtml

However, when I press logout on URLs with a request parameter like this,

http://localhost:8080/WPA_MOVIEDATABASE/app/movie.xhtml?id=135

then I'm redirected back to the same URL without the query string:

http://localhost:8080/WPA_MOVIEDATABASE/app/movie.xhtml

Am I doing the redirecting wrong or is this the normal behivour for these kind of URLs?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Kuba Spatny
  • 26,618
  • 9
  • 40
  • 63
  • Are you implying that `http://localhost:8080/WPA_MOVIEDATABASE/app/movie.xhtml?id=135` doesn't give a 404 when you open it directly by entering/copypasting that URL in browser's address bar, instead of being redirected to it? – BalusC Nov 29 '13 at 19:57
  • @BalusC enter that page work fine, but when I try to log out from that page I get 404. – Kuba Spatny Nov 29 '13 at 19:58
  • @BalusC I edited the question, hopefully the problem will be more clear now. – Kuba Spatny Nov 29 '13 at 20:01
  • Much better, indeed! What's the resulting URL of the redirect? (as you see in browser's address bar). Is it the same in both cases? – BalusC Nov 29 '13 at 20:04
  • @BalusC When it correctly redirects: `http://localhost:8080/WPA_MOVIEDATABASE/login.xhtml` but for the 404 it just strips the parameter `http://localhost:8080/WPA_MOVIEDATABASE/app/movie.xhtml` – Kuba Spatny Nov 29 '13 at 20:06
  • Well, you must have a custom/3rd-party `NavigationHandler` or `ViewHandler` somewhere. This is not the default behavior. By the way, curious that exactly the same URL without a query string gives 404. That must be explicitly programmed (or wrongly configured). – BalusC Nov 29 '13 at 20:06
  • As far as I know I am not using any of that. But also (my mistake) the error is not 404 but 500, but still due to the fact that it's being redirected to `/app/movie.xhtml` – Kuba Spatny Nov 29 '13 at 20:19
  • Okay, a 500 is indeed more likely to happen (although this indicates a bug in the bean associated with your movie page, but that aside). Coming back to the concrete problem, have you checked the HTTP traffic monitor? Is there only one redirect, or are there maybe two redirects because the login page itself for some reason decided to redirect back to movie page? (by the way: I edited and improved the question, the 404/500 actually isn't relevant anymore) – BalusC Nov 29 '13 at 20:22
  • @BalusC Thank you for your help! I really did find problem in the HTTP Server Monitor. – Kuba Spatny Nov 29 '13 at 21:13

1 Answers1

0

In the HTTP Server Monitor I found out that after pressing the logout button, there was first a POST request to

http://localhost:8080/WPA_MOVIEDATABASE/app/movie.xhtml

and then would follow a GET request to

http://localhost:8080/WPA_MOVIEDATABASE/login.xhtml.

At that moment I knew the problem was in the log out button..

I was using:

<h:form>
   <h:commandLink value="Log out" action="#{userBB.logout}"/>
</h:form>

Changing the code to the following resolved the problem:

<h:button value="LOG OUT" outcome="#{userBB.logout()}" />


A million thanks to BalusC whose tips led me to discovering the true problem!

Kuba Spatny
  • 26,618
  • 9
  • 40
  • 63
  • 1
    Hm, is your problem really solved? The HTTP traffic looks fine. Your "solution" just instantly executes logout method during opening the page. – BalusC Nov 29 '13 at 21:15
  • @BalusC The two request would be triggered after pressing the logout button. Now after I press the button there's only the GET request for `/WPA_MOVIEDATABASE/login.xhtml` – Kuba Spatny Nov 29 '13 at 21:19
  • 1
    Your initial code that's using a command component is the right one to handle logout. The new code is as though you've put a plain `#{userBB.logout()}` in your view, so that's definitely not the cause of the problem and not the solution to it. – skuntsel Nov 29 '13 at 21:24
  • @skuntsel well using the command component is followed by POST request to `WPA_MOVIEDATABASE/app/movie.xhtml` without the parameter which then triggers the 500. However I don't think this problem would be present after the pages would be filtered for not logged user.. I am actually trying to validate the url preRender as said here http://stackoverflow.com/questions/15068446/jsf-throw-404-error-if-get-parameter-is-omitted but it doesn't seem to work if the parameters are completely ommited – Kuba Spatny Nov 29 '13 at 21:36
  • So the problem seems to be the missed parameters when the link is clicked. By default it should have made the POST request to the url with parameters. Can you try h:commandButton instead of h:commandLink (it might be some configuration/coding error which caused the commandLink js to screw up the parameters)? – Andrey Dec 01 '13 at 11:00
  • @Andrey commandButton produces the same problem, I returned to using commandLink, I just had to ensure that field movie != null in a getter method - which frankly I dont understand, how it could be null when I have preRender validation to check for that null.. – Kuba Spatny Dec 01 '13 at 11:22