简体   繁体   中英

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.

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.

<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. Is it possible?

Besides the struts solution you could try to setup a (apache) proxy, which will redirect the request to your video server. With that you don't have that huge software stack. Examples are here: Apache mod_proxy

But if you decide to use the struts solution, here some ideas:

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

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:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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