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
Solved

interceptor redirecting to wrong url

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

809 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