繁体   English   中英

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

[英]Struts2 - redirect request to another application - video

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

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

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

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

除了struts解决方案之外,您还可以尝试设置一个(apache)代理,它将请求重定向到您的视频服务器。 这样一来,您就不必拥有庞大的软件堆栈。 示例如下: Apache mod_proxy

但是,如果您决定使用struts解决方案,请注意以下几点:

  • 创建一个可能连接到视频服务器的操作,也许使用FileOutputStream这样的答案: 使用java下载文件
  • 使用该文件(在某个位置保存的临时文件),为其打开一个流,并在您的<img href="mypicture"> -Action中对其进行粉碎,例如: Struts2 ServletResponseAware或此处的Struts流结果

如果您愿意,我可以提供更多详细信息。

我可以找到解决方案。

我使用了这个项目: 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/.*"/>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM