简体   繁体   English

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

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

I have a struts2 application and I need to show inside it a video that is being showed in another web app. 我有一个struts2应用程序,我需要在其中显示正在另一个Web应用程序中显示的视频。

This is the code that shows the video. 这是显示视频的代码。 This IP is not accessible in the internet, just on the server where my struts app is located. 该IP在Internet上无法访问,只能在我的struts应用程序所在的服务器上访问。

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

I need an action in struts2 that I can make a request and it will forward to the response from the other server. 我需要在struts2中执行一个可以发出请求的操作,该操作将转发到其他服务器的响应。 Is it possible? 可能吗?

Besides the struts solution you could try to setup a (apache) proxy, which will redirect the request to your video server. 除了struts解决方案之外,您还可以尝试设置一个(apache)代理,它将请求重定向到您的视频服务器。 With that you don't have that huge software stack. 这样一来,您就不必拥有庞大的软件堆栈。 Examples are here: Apache mod_proxy 示例如下: Apache mod_proxy

But if you decide to use the struts solution, here some ideas: 但是,如果您决定使用struts解决方案,请注意以下几点:

If you want, I can get a little bit more in detail. 如果您愿意,我可以提供更多详细信息。

I could find a solution. 我可以找到解决方案。

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

With that, I could redirect the requests to the other server. 这样,我可以将请求重定向到其他服务器。 In the client view, my own server is answering the request. 在客户端视图中,我自己的服务器正在应答请求。

In the web.xml, I put the following: 在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>

Also, in struts.xml I had to exclude all the requests that matched /otherServer. 另外,在struts.xml中,我必须排除所有与/ otherServer匹配的请求。

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

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

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