onvif icon indicating copy to clipboard operation
onvif copied to clipboard

jaxws uses ip, instead of DNS

Open RobinGoussey opened this issue 3 years ago • 3 comments

Hi,

I am using this library, to try and connect to cameras, that are behind reverse proxies. However it seems somewhere in the code it changes the camera.localhost to the effective ip address (as in the ip of the camera, not how you connect to it), and that ip is unreachable. So the eg, I use the host https://camera.localhost, and I create an OnvifDevice, but it fails whenever I try and use a service, like media or ptz, since it somehow resolves to a.b.c.d/onvif/media_service, but this I cannot reach (reverse proxy).

Is there a way to trigger all services of Onvif device to keep using the dns instead of the ip of the interface where the camera runs?

RobinGoussey avatar Apr 02 '21 14:04 RobinGoussey

Unfortunately I dind't wrote this module, I just ported the original version under a more maintainable maven project. If you have time to dig into this I can merge your PR and release a new version

fpompermaier avatar Apr 06 '21 08:04 fpompermaier

Funny, I just solved it. I tried it before, but intellij did not seem to pick up my code changes. The library uses the xaddr the server gives it, so that being the XAddr. However this is the actual ip address of the service, and not however you reach it.

I solved it by doing this:

In OnvifDevice init, this code needs to be replaced, more specifically (for each service):

getServiceProxy((BindingProvider) media, capabilities.getMedia().getXAddr())
              .create(Media.class)
              //Add this:
getServiceProxy((BindingProvider) media, capabilities.getMedia().getXAddr().replaceFirst("http(s)?://[0-9\\.]+",this.url.toString()))
              .create(Media.class)
    if (capabilities.getMedia() != null && capabilities.getMedia().getXAddr() != null) {
      this.media = new MediaService().getMediaPort();
      this.media =
          getServiceProxy((BindingProvider) media, capabilities.getMedia().getXAddr().replaceFirst("http(s)?://[0-9\\.]+",this.url.toString()))
              .create(Media.class);
    }

    if (capabilities.getPTZ() != null && capabilities.getPTZ().getXAddr() != null) {
      this.ptz = new PtzService().getPtzPort();
      this.ptz =
          getServiceProxy((BindingProvider) ptz, capabilities.getPTZ().getXAddr().replaceFirst("http(s)?://[0-9\\.]+",this.url.toString()))
              .create(PTZ.class);
    }

    if (capabilities.getImaging() != null && capabilities.getImaging().getXAddr() != null) {
      this.imaging = new ImagingService().getImagingPort();
      this.imaging =
          getServiceProxy((BindingProvider) imaging, capabilities.getImaging().getXAddr().replaceFirst("http(s)?://[0-9\\.]+",this.url.toString()))
              .create(ImagingPort.class);
    }

    if (capabilities.getEvents() != null && capabilities.getEvents().getXAddr() != null) {
      this.events = new EventService().getEventPort();
      this.events =
          getServiceProxy((BindingProvider) events, capabilities.getEvents().getXAddr().replaceFirst("http(s)?://[0-9\\.]+",this.url.toString()))
              .create(EventPortType.class);
    }
  }

I'll look into making a pr and uploading it.

RobinGoussey avatar Apr 06 '21 08:04 RobinGoussey

That would be great!

fpompermaier avatar Apr 07 '21 07:04 fpompermaier