Solved

interceptor redirecting to wrong url

Posted on 2014-04-02
1
265 Views
Last Modified: 2014-04-14
Hi,

I am hitting the following url :
http://flight.yatra.com/air-search/int2/trigger?CHD=0&flexi=0&noOfSegments=1&origin=DEL&type=O&class_=Economy&ADT=1&destination=BOM&flight_depart_date=19/04/2014&price=0&viewName=normal&INF=0&tenant=international&class=Economy

I have written an interceptor in which prehandle has the following lines :

String redirectUrl = request.getServerName()+request.getContextPath()+"/dom2/trigger?"+request.getQueryString();
				response.sendRedirect(redirectUrl);
				return false;

Open in new window


I wanted to modify int2 to dom2 in the original url.

Although the redirectUrl is building fine. But when running the code it gives an error
and the url i see is the following :

http://flight.yatra.com:8080/air-search/int2/flight.yatra.com/air-search/dom2/trigger?CHD=0&flexi=0&noOfSegments=1&origin=DEL&type=O&class_=Economy&ADT=1&destination=BOM&flight_depart_date=19/04/2014&price=0&viewName=normal&INF=0&tenant=international&class=Economy

This is not same as the redirectUrl.
How do i achieve this ?

Thanks
0
Comment
Question by:Rohit Bajaj
1 Comment
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
Comment Utility
The string that you are building will NOT have a leading / and so (as per the Javadoc for HttpServletResponse.sendRedirect) the servlet container will resolve the relative URL as relative to the path in the original request. Since the original request is targeting the "trigger" resource in the "/air-search/int2/" path the string that you have built gets appended to that path, hence you get the resolved URL as you are seeing.

If you note also in that Javadoc, you can append a leading / to the URL to make the servlet container resolve it relative to the containers root, so the below should work for you...
	String redirectUrl = request.getContextPath()+"/dom2/trigger?"+request.getQueryString();
	response.sendRedirect(redirectUrl);
	return false;

Open in new window

(Note: that getContextPath() returns a String that already has the leading / so that is why the above will resolve correctly.)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now