0

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 Answers1

0

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

https://foo:password@example.com

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.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
André Schild
  • 4,592
  • 5
  • 28
  • 42
  • Oh okay, didn't know that microsoft disabled this. Tried to pass the login already, but you're right -> not really a clean and safe solution. Thanks for your help. – unhappy Jun 08 '15 at 16:57