?
Solved

interceptor redirecting to wrong url

Posted on 2014-04-02
1
Medium Priority
?
280 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 36

Accepted Solution

by:
mccarl earned 2000 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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
This video teaches viewers about errors in exception handling.
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.
Suggested Courses

770 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