0

I have this two controller from two separate projects lets name them:

  • project1.controller1
  • project2.controller1

Obviously these are two Spring controllers from different projects.What I want is to make project1.controller1 a gateway all request will be sent here. And will process the request if it will go to project2.controller1 or a new controller.

Some pseudoCode:

@Controller
public class someClassFromProject1{

   @RequestMapping(value="/controller1", method=RequestMethod.POST)
   public String smsCatcher(String target, HttpServletRequest request,
        HttpServletResponse response){
           //some processing, converting request to string, etc
           if("someStringThatIsPartOfTheRequest".equals("someString"))
            //carry request and forward it to project2.controller1
           else
            //go to another external controller
         }

    }

And in project2.controller 1 will look something like this:

@Controller
public class someClassFromProject2{

   @RequestMapping(value="/controller1", method=RequestMethod.POST)
   public String smsCatcher(String target, HttpServletRequest request,
        HttpServletResponse response){
          //processing
   }
  }

I've already tried return "forward:/someUrl"; and return "redirect:someUrl";. It didn't work and it didn't reach project2.controller1. So any ideas on this one?

Edit: Forgot to add this one, different project means different WAR but deployed on the same sever. And the request should be carried over from project1.controller1 to project2.controller1 because I'm gonna process the request there.

Thanks!

3 Answers3

0

You need to use redirect instead of forward.

Alexandre Jacob
  • 2,993
  • 3
  • 26
  • 36
0

The protocol is required if the host is different to that of the current host

return "redirect:http://www.yahoo.com";

Have a look at the redirect: prefix section from Spring Web MVC framework also check this

A logical view name such as redirect:/myapp/some/resource will redirect relative to the current Servlet context, while a name such as redirect:http://myhost.com/some/arbitrary/path will redirect to an absolute URL.

Community
  • 1
  • 1
karim mohsen
  • 2,164
  • 1
  • 15
  • 19
0

Figured it out but then it's kind of messy, I've used HttpClient to Post my Request to the URL. It also carried the request along with the forwarding. Anyway, thanks for all the help guys. Thanks :)