diff --git a/src/us/mn/state/dot/tms/server/comm/onvifptz/DOMUtils.java b/src/us/mn/state/dot/tms/server/comm/onvifptz/DOMUtils.java index b6bb6b14d..b5744c499 100644 --- a/src/us/mn/state/dot/tms/server/comm/onvifptz/DOMUtils.java +++ b/src/us/mn/state/dot/tms/server/comm/onvifptz/DOMUtils.java @@ -57,7 +57,7 @@ public static String getString(Node n) { public static Document getDocument(String s) { Document doc = null; try { - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + DocumentBuilder db = DocumentBuilderFactory.newNSInstance().newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(s)); doc = db.parse(is); diff --git a/src/us/mn/state/dot/tms/server/comm/onvifptz/DeviceService.java b/src/us/mn/state/dot/tms/server/comm/onvifptz/DeviceService.java index 40441d64c..072b49650 100644 --- a/src/us/mn/state/dot/tms/server/comm/onvifptz/DeviceService.java +++ b/src/us/mn/state/dot/tms/server/comm/onvifptz/DeviceService.java @@ -15,6 +15,7 @@ package us.mn.state.dot.tms.server.comm.onvifptz; import javax.xml.parsers.ParserConfigurationException; +import org.w3c.dom.NodeList; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -56,6 +57,39 @@ public String getServices() { return sendRequestDocument(doc); } + /** Gets a service address by its namespace */ + public String getServiceAddr(String namespace) { + String servicesRes = getServices(); + Document servicesDoc = DOMUtils.getDocument(servicesRes); + + NodeList services = servicesDoc.getElementsByTagNameNS("*", "Service"); + for (int i = 0; i < services.getLength(); i++) { + Element service = (Element) services.item(i); + Element ns = (Element) service.getElementsByTagNameNS("*", "Namespace").item(0); + + if (ns.getTextContent().equalsIgnoreCase(namespace)) { + Element addr = (Element) service.getElementsByTagNameNS("*", "XAddr").item(0); + return addr.getTextContent(); + } + } + return null; + } + + /** Get the PTZ binding address */ + public String getPTZBinding() { + return getServiceAddr("http://www.onvif.org/ver20/ptz/wsdl"); + } + + /** Get the media binding address */ + public String getMediaBinding() { + return getServiceAddr("http://www.onvif.org/ver10/media/wsdl"); + } + + /** Get the imaging binding address */ + public String getImagingBinding() { + return getServiceAddr("http://www.onvif.org/ver20/imaging/wsdl"); + } + /** Document builder function for GetScopes */ public Document getScopesDocument() { Document doc = getBaseDocument(); diff --git a/src/us/mn/state/dot/tms/server/comm/onvifptz/OnvifProp.java b/src/us/mn/state/dot/tms/server/comm/onvifptz/OnvifProp.java index f737e9b14..9474dec6e 100644 --- a/src/us/mn/state/dot/tms/server/comm/onvifptz/OnvifProp.java +++ b/src/us/mn/state/dot/tms/server/comm/onvifptz/OnvifProp.java @@ -70,12 +70,11 @@ public String sendSoap() { return "No cmd specified"; } - // create each service - // TODO: generalize service paths? (device service specified by ONVIF standard) + // create each service (device service binding specified by ONVIF standard) DeviceService dev = DeviceService.getDeviceService(url + "/onvif/device_service", user, pass); - PTZService ptz = PTZService.getPTZService(url + ":80/onvif/ptz", user, pass); - MediaService media = MediaService.getMediaService(url + ":80/onvif/media", user, pass); - ImagingService img = ImagingService.getImagingService(url + ":80/onvif/imaging", user, pass); + PTZService ptz = PTZService.getPTZService(dev.getPTZBinding(), user, pass); + MediaService media = MediaService.getMediaService(dev.getMediaBinding(), user, pass); + ImagingService img = ImagingService.getImagingService(dev.getImagingBinding(), user, pass); String mediaProfile = null, videoSource = null; int mediaWidth = 0, videoWidth = 0; // to find maximum values