Solved

interceptor redirecting to wrong url

Posted on 2014-04-02
1
266 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
ID: 39974200
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB Script to add site to Java Exception List 4 50
netstat -ano | find "8000" and taskkill /f /pid 2984 3 35
table example 4 23
expectj telnet failing 5 26
Read about why website design really matters in today's demanding market.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to dynamically set the form action using jQuery.

920 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

14 Experts available now in Live!

Get 1:1 Help Now