Reputation: 348
I have a java application with a login-mechanism running in a tomcat. When the user clicks "logout" the application is supposed to redirect him back to the login page. So when the user clicks on "logout" the endpoint /logout is called, executes the logout-logic and then redirects the user back to the login-page.
@GET
@Path("logout")
@Produces(MediaType.TEXT_HTML)
public Response logOut(@Context HttpServletRequest request) throws URISyntaxException {
// logout logic omitted
Response.ResponseBuilder response = Response.seeOther(new URI("../jsp/login.jsp"));
return response.build();
}
When I test this on my local machine everything works fine. The relative path "../jsp/login.jsp" is transformed to http://localhost:8080/myapplication/jsp/login.jsp. On the production system however the authority part of the url is not the address of the production system but http://localhost:7080/myapplication/jsp/login.jsp.
This is why I´d like to ask how does java.net.URI resolve a relative URL? In the documentation it said that "The authority component of a hierarchical URI is, if specified, either server-based or registry-based." What does this mean? Is there a file in my tomcat where I or one of my colleagues set a wrong host or so? I appreciate all kind of advice helping me where I could start looking for the cause of this problem.
Upvotes: 0
Views: 478
Reputation: 719551
The javadoc for URI.resolve(URI)
says this:
public URI resolve(URI uri)
Resolves the given URI against this URI.
So, the answer to your question is that the servlet infrastructure is resolving "../jsp/login.jsp" against some other URI. The URI that you created in your code will be the "given URI" in the above.
Which URI is it resolving against?
Well it looks like it is the base URI for the current context.
But the bottom line is that it is not Java that decides what to resolve against. It is the webapp framework and/or Tomcat that is deciding. That's where you should be looking to find an explanation for what you are seeing.
Upvotes: 1