0

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?

henriquels
  • 518
  • 4
  • 20

2 Answers2

1

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.

Community
  • 1
  • 1
beendr
  • 654
  • 7
  • 21
  • I would like to use the struts solution, I have a question about how to continually update the video to the user, because my video server is allways sending new content because it is real time content. I have tried this: File tempVideoFile = new File("/path/temp.mp4"); FileOutputStream fos = new FileOutputStream(tempVideoFile); fos.getChannel().transferFrom(rbc, 0, 50000); Then, streaming the result to the user. But, I can't reproduce the video. – henriquels Aug 08 '16 at 14:43
  • With the idea above you can't stream video, just static files. For redirect videos you need something like a stream proxy server. I don't think struts will be an option for you in this special case. – beendr Aug 09 '16 at 05:26
0

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/.*"/>
henriquels
  • 518
  • 4
  • 20