Get resource path from full url | Community
Skip to main content
New Participant
November 28, 2015
Solved

Get resource path from full url

  • November 28, 2015
  • 3 replies
  • 2972 views

Hi All,

I am implementing login component in which I want to support goto parameter for example

https://myDomain/login.html?goto=https://myDomain/securePage.html.

I am able to get the redirect path in my servlet from the query parameter but from query parameter how do i get the resource path? I was hoping resolve method might come handy but it does not seem to work :(. Anything more elegant that string manipulation to solve this problem?

final String gotoPath = xssApi.filterHTML(request.getParameter(gotoParam)); if (StringUtils.isNotEmpty(gotoPath)) { final Resource gotoPathResource = request.getResourceResolver().resolve(gotoPath); if (null != gotoPathResource && null != gotoPathResource.adaptTo(Page.class)) { response.sendRedirect(gotoPath); return; } }

Above code is giving resource as non existent

Thanks!

Shehjad

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Shehjadkhan

I have changed code to below to make it work.

final String gotoPath = xssApi.filterHTML(request.getParameter(gotoParam)); final URI gotoUri = new URI(gotoPath, false); if (StringUtils.isNotEmpty(gotoPath)) { final Resource gotoPathResource = request.getResourceResolver().resolve(gotoUri.getPath()); if (null != gotoPathResource && null != gotoPathResource.adaptTo(Page.class)) { response.sendRedirect(gotoPath); return; } } redirect(request, response, redirectPath);

3 replies

ShehjadkhanAuthorAccepted solution
New Participant
November 28, 2015

I have changed code to below to make it work.

final String gotoPath = xssApi.filterHTML(request.getParameter(gotoParam)); final URI gotoUri = new URI(gotoPath, false); if (StringUtils.isNotEmpty(gotoPath)) { final Resource gotoPathResource = request.getResourceResolver().resolve(gotoUri.getPath()); if (null != gotoPathResource && null != gotoPathResource.adaptTo(Page.class)) { response.sendRedirect(gotoPath); return; } } redirect(request, response, redirectPath);
New Participant
November 28, 2015

Asling Thanks for your reply, yes i understand i can do some string manipulation but I don't find that be a elegant way :)

Yes we have mapping to map short urls as you mentioned in your comment

New Participant
November 28, 2015

I'm assuming that you have some rewriting going on to handle the URL without /content/<path>/, so, you could simply take your go to parameter, strip out the https://<domain> and use what is left over (minus the .html)

So, https://www.mydomain.com/mypage.html would become "mypage", you know the content path, so prepend it and the string becomes /content/<path>/mypage and then get the resource.