henriquels
henriquels

Reputation: 546

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?

Upvotes: 0

Views: 579

Answers (2)

henriquels
henriquels

Reputation: 546

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/.*"/>

Upvotes: 0

beendr
beendr

Reputation: 654

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.

Upvotes: 1

Related Questions