How to display MJPEG-stream in Vaadin (Java)?

733 views Asked by At

I`m looking for a way to display a MJPEG-stream (from ip cam) in my vaadin application.

My problem is the necessary authentication to start the stream.

Really easy solution to simply get the stream:

String url = "...urlgoeshere/video.mjpg";

Image image = new Image();
image.setSource(new ExternalResource(url));
content.addComponent(image);

It works like a charm if I allow anonymous connections to the camera, but thats not really my goal.

I tried to authenticate with:

Authenticator.setDefault(new MyAuthenticator(username, password));

but it doesn`t affect the request.

If I manually set up a request like:

String url = "...urlgoeshere/video.mjpg";

Authenticator.setDefault(new MyAuthenticator("username", "password"));

URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET"); 

the authentication works, but this way I have to handle all the images by myself.

Are there any better ways to display a stream which requires authentication?

1

There are 1 answers

1
André Schild On

I think you should be able to use the username & password in the URL of the external resource.

https://foo:[email protected]

But this depends on the protocol the webcam uses for authentification, and you will also have the username and password "visible" in the html / javascript of your application.

And one more note: Microsoft did disable this some time ago, so if your users are using IE, this won't work.