将请求转发到新控制器 [英] Forwarding request to a new controller

查看:32
本文介绍了将请求转发到新控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有来自两个不同项目的这两个控制器让我们命名它们:

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

  • project1.controller1
  • project2.controller1

显然这是来自不同项目的两个 Spring 控制器.我想要的是将 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.

一些伪代码:

@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
         }

    }

在 project2.controller 1 中看起来像这样:

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
   }
  }

我已经尝试过 return "forward:/someUrl";return "redirect:someUrl";.它没有工作,也没有到达 project2.controller1.那么对此有什么想法吗?

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?

忘记添加这个了,不同的项目意味着不同的WAR但部署在同一台服务器上.请求应该从 project1.controller1 转移到 project2.controller1 因为我要在那里处理请求.

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.

谢谢!

推荐答案

想通了,但后来有点乱,我使用 HttpClient 将我的请求发布到 URL.它还携带请求和转发.无论如何,感谢所有帮助人.谢谢:)

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 :)

这篇关于将请求转发到新控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆