Redirect url failed

Hi,
We have a solution. We can launch this solution via “http://host/servoy-webclient/solutions/solution/app”. But we want to access this solution by using a short url, like http://host/testapp, and then POST this to a servlet to redirect it to “http://host/servoy-webclient/solutions/solution/app”. What we have done are:

  1. add servlet and mapping in web.xml; the url pattern in the mapping is “/testapp”;
  2. wrote a servlet class and copy the servlet jar file to “http://host/servoy_home/application_server/server/webapps/ROOT/WEB-INF/lib/”;

In the servlet class we do redirect in the method “service(HttpServletRequest req, HttpServletResponse resp)”:

RequestDispatcher dispatcher =  req.getRequestDispatcher("/servoy-webclient/solutions/solution/app");
dispatcher.forward(req, resp);

It failed after it redirected because the url was changed to “http://host/?x=…” while it should be “http://host/servoy-webclient/?x=…” if we launch the solution directly.

Then we made a change to the servlet to ask it to return “/servoy-webclient” when redirecting. This time the url looks right and the login page showed up but other problems came: it cannot find the javascript files needed by servoy because all of them just have a relative path to /webapps/ROOT. If we launch solutions directly then those javascript files will be found in “/servoy-webclient/resources/…”; if redirecting then it went to “/host/resources/…” to look for them and broken. There are other resources referred in servoy using absolution path and they don’t have problem.

How can we fix this issue?

Thanks,

dont do the redirect like that on the server (requestdispatch)

Just redirect through the client. So send a http redirect so that the browser does the redirect for you

Thank you.

Johan,

jcompagner:
dont do the redirect like that on the server (requestdispatch)

Just redirect through the client. So send a http redirect so that the browser does the redirect for you

Unfortunately there’s a problem with sending a redirect back to the client. If a 302 or 303 redirect code is sent the second request will be made as a GET request which won’t always work (it won’t work in the case where the parameters being passed in exceed the maximum URL length). The only way I’m aware of to redirect and keep it as a POST is to use a 307 redirect code. The problem here is the HTTP spec says:

If the 307 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change the conditions under which the request was issued.

This means the user will be prompted before redirecting which makes it a bad user experience.

Corey

if you just redirect like what you do then wicket things that all request are coming from that location
so it will generate a relative urls to the link you specify so then all the links should work through that.

so if wicket gets

/yyy/xxxx

then al the urls will be generated with a relative path so it will be

/yyy/WICKETSTUFF

this works this way because of proxies so that real proxies like apache are working correctly.

if you want to have your own url then you have to map your own servlet/filter after /servoy-webclient/
so something like

/servoy-webclient/mything.

then all the urls will be correct.

jcompagner:
if you want to have your own url then you have to map your own servlet/filter after /servoy-webclient/
so something like

/servoy-webclient/mything.

then all the urls will be correct.

I tested it using /servoy-webclient/test as url pattern. Servlet caught it but still couldn’t forward to the right url because the forwarded url was:

http://host:8090/?x=........

which should be

http://host:8090/servoy-webclient/?x=........

and the generated relative path was relative to “http://host:8090/” not “http://host:8090/servoy-webclient/”.

thats weird, dont know why that happens then

so
/servoy-webclient/test
and
/test

are exactly the same? I wouldnt expect that.

what happens if you do

/servoy-webclient/test/
and
/test/

I got the same redirected url like “http://host/?x=…” for both “/servoy-webclient/test” and “/test”.

and when you add another / at the end?

I got the same redirected url with “/servoy-webclient/test/” and “/test/” as before.

then i dont know what really happens under water
i would expect that that would have worked.
But somehow the request doesnt have the right stuff that wicket can work with.

Hi, :)

I am also looking to redirect a small URL to my actual URL.
any suggestion :?:

Thanks in advance.