Solved

interceptor redirecting to wrong url

Posted on 2014-04-02
1
275 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

726 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