Struts2 - 将请求重定向到另一个应用程序 - 视频

时间:2016-08-08 13:28:55

标签: java video struts2

我有一个struts2应用程序,我需要在其中显示另一个网络应用程序中显示的视频。

这是显示视频的代码。这个IP无法在互联网上访问,只能在我的struts应用程序所在的服务器上访问。

<img src="http://<ip_from_other_server/showVideo">

我需要在struts2中执行一个操作,我可以发出请求,它将转发给其他服务器的响应。有可能吗?

2 个答案:

答案 0 :(得分:1)

除了struts解决方案,您还可以尝试设置(apache)代理,该代理会将请求重定向到您的视频服务器。有了这个,你没有那么庞大的软件堆栈。示例如下:Apache mod_proxy

但是如果你决定使用struts解决方案,这里有一些想法:

如果你愿意,我可以更详细一点。

答案 1 :(得分:0)

我可以找到解决方案。

我使用了这个项目:https://github.com/mitre/HTTP-Proxy-Servlet

有了这个,我可以将请求重定向到其他服务器。在客户端视图中,我自己的服务器正在回答请求。

在web.xml中,我提出以下内容:

<servlet>
    <servlet-name>otherServer</servlet-name>
    <servlet-class>org.mitre.dsmiley.httpproxy.URITemplateProxyServlet</servlet-class>
    <init-param>
        <param-name>targetUri</param-name>
        <param-value>http://{_ipOtherServer}:{_portOtherServer}/myAction</param-value>
    </init-param>
    <init-param>
        <param-name>log</param-name>
        <param-value>true</param-value>
    </init-param>
</servlet>
<servlet-mapping>
    <servlet-name>otherServer</servlet-name>
    <url-pattern>/otherServer/action/*</url-pattern>
</servlet-mapping>

此外,在struts.xml中,我必须排除匹配/ otherServer的所有请求。

<constant name="struts.action.excludePattern" value="/otherServer/.*"/>