Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WSDL Updates, Usernametoken authentication, multi network apdater support #7

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ bin/**
*.swp
*.swo

onvif-java/.factorypath
local.properties
.classpath
.settings/
.loadpath
.loadpath
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ This project aims to improve https://github.com/milg0/onvif-java-lib.<br>
I've tried to convice its author to use to my code but it seems we have different objectives: my goal is to create a project that focus on the funny part of the development of an ONVIF application, **keeping the interaction with the WS as simple as possible** and delege that annoying part to Apache CXF in order to not waste the developer time in writing (and MAINTAINING) code that interacts with ONVIF web services.<br>
My wish is to help other developers willing to contribute to an enterprise-level Java library for ONVIF devices.

Fork improvements (quonn77)
=============
* onvif-ws-client: WS stubs are no more part of the repository, you can simply generate them using the most updated version of the wsdl files.
Generated source files are under target/generated-sources standard maven folder.
* WSSE UsernameToken: Support for username token authentication has been added. You have to properly initiliaze UTPasswordCallback class by
providing the username, password pairs using the setAliasPassword method.
* Multi network card support. In order to avoid problem on a multinetwork environment you can specify which is the name of the network adapter to use (E.g. eth0).
You have to provide it using JVM parameter -DnetworkInterface=<network interface name> (default eth0)
Apported improvements
=============
* Project **mavenization** and **modularization** (separation between Java stubs and application) and
Expand Down
40 changes: 27 additions & 13 deletions onvif-java/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
Expand All @@ -9,6 +10,14 @@
<artifactId>onvif-java</artifactId>

<dependencies>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
Expand All @@ -24,16 +33,16 @@
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.apache.cxf.services.ws-discovery</groupId> -->
<!-- <artifactId>cxf-services-ws-discovery-api</artifactId> -->
<!-- <version>${cxf.version}</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.apache.cxf.services.ws-discovery</groupId> -->
<!-- <artifactId>cxf-services-ws-discovery-service</artifactId> -->
<!-- <version>${cxf.version}</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.apache.cxf.services.ws-discovery</groupId> -->
<!-- <artifactId>cxf-services-ws-discovery-api</artifactId> -->
<!-- <version>${cxf.version}</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.apache.cxf.services.ws-discovery</groupId> -->
<!-- <artifactId>cxf-services-ws-discovery-service</artifactId> -->
<!-- <version>${cxf.version}</version> -->
<!-- </dependency> -->

<dependency>
<groupId>org.onvif</groupId>
Expand All @@ -53,9 +62,14 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
<version>3.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-common-utilities -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-common-utilities</artifactId>
<version>2.5.11</version>
</dependency>

</dependencies>

</project>
182 changes: 131 additions & 51 deletions onvif-java/src/main/java/de/onvif/OnvifDiscovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,147 @@
import java.util.Collection;
import java.util.List;

import javax.xml.soap.SOAPException;

import org.onvif.ver10.schema.ImagingSettings20;
import org.onvif.ver10.schema.MediaUri;
import org.onvif.ver10.schema.PTZConfiguration;
import org.onvif.ver10.schema.Profile;
import org.onvif.ver10.schema.StreamSetup;
import org.onvif.ver10.schema.StreamType;
import org.onvif.ver10.schema.Transport;
import org.onvif.ver10.schema.TransportProtocol;
import org.onvif.ver10.schema.VideoSource;
import org.onvif.ver10.schema.VideoSourceConfiguration;
import org.onvif.ver10.schema.VideoSourceExtension;

//import javax.xml.ws.EndpointReference;
//
////import org.apache.cxf.ws.discovery.WSDiscoveryClient;
//import org.onvif.ver10.network.wsdl.DiscoveryService;

import de.onvif.discovery.DeviceDiscovery;
import de.onvif.soap.OnvifDevice;
import de.onvif.soap.UTPasswordCallback;

/**
* @author th
* @date 2015-06-18
*/
public class OnvifDiscovery {
public static List<URL> discoverOnvifDevices(boolean useIpv4, String... addressList) {
final ArrayList<URL> onvifPointers = new ArrayList<>();
final Collection<URL> urls = DeviceDiscovery.discoverWsDevicesAsUrls("^http$", ".*onvif.*", useIpv4, addressList);
for (URL url : urls) {
try {
onvifPointers.add(url);
}
catch (Exception e) {
e.printStackTrace();
}
}
return onvifPointers;
}

public static void main(String[] args) throws IOException {
List<URL> onvifDevices = discoverOnvifDevices(true);
// List<URL> onvifDevices = discoverOnvifDevices(true, "192.168.1.53");
if(onvifDevices.size()==0)
System.out.println("No Onvif device found");
for (URL url : onvifDevices) {
System.out.println("Device discovered: " + url.toString());
}

// cxfDiscovery();

}

// @SuppressWarnings("unused")
// private static void cxfDiscovery() throws IOException {
// //Use WS-Discovery to find references to services that implement the changeName portType
// String targetAddress = "soap.udp://192.168.1.53:3702";
// WSDiscoveryClient client = new WSDiscoveryClient();
// // Setting timeout for WS-Discovery
// client.setDefaultProbeTimeout(1000);
// // Use WS-discovery 1.0
// client.setVersion10();
// client.setSoapVersion11();
// System.out.println("Probe:" + client.getAddress());
// List<EndpointReference> references = client.probe(DiscoveryService.SERVICE);
//// List<EndpointReference> references = client.probe();
// System.out.println("The probe has been finished");
// client.close();
//
// System.out.println("Found "+references.size()+" ONVIF devices");
// //loop through all of them and have them greet me.
//// DiscoveryService service = new DiscoveryService();
// for (EndpointReference ref : references) {
//// HelloType g = service.getPort(ref, HelloType.class);
// System.out.println(ref);
// }
// }
public static List<URL> discoverOnvifDevices(boolean useIpv4, String... addressList) {
final ArrayList<URL> onvifPointers = new ArrayList<>();
final Collection<URL> urls = DeviceDiscovery.discoverWsDevicesAsUrls("^http$", ".*onvif.*", useIpv4,
addressList);
for (URL url : urls) {
try {
onvifPointers.add(url);
} catch (Exception e) {
e.printStackTrace();
}
}
return onvifPointers;
}

public static void main(String[] args) throws IOException {
// List<URL> onvifDevices = discoverOnvifDevices(true);
List<URL> onvifDevices = discoverOnvifDevices(true, "192.168.150.55");
if (onvifDevices.size() == 0)
System.out.println("No Onvif device found");
for (URL url : onvifDevices) {
System.out.println("Device discovered: " + url.toString());
}

try {

UTPasswordCallback.setAliasPassword("user", "pwd");
OnvifDevice cam = OnvifDevice.builder("192.168.150.55").username("user").password("password").build();
List<VideoSource> sources = cam.getMedia().getVideoSources();

List<Profile> profiles = cam.getMedia().getProfiles();
profiles.forEach(p -> {
System.out.println("P:" + p.getName() + " Token:" + p.getToken());
});

StreamSetup ss = new StreamSetup();
ss.setStream(StreamType.RTP_UNICAST);
Transport t = new Transport();
t.setProtocol(TransportProtocol.RTSP);
ss.setTransport(t);

String token = "profile_1_h264";
MediaUri uri = cam.getMedia().getStreamUri(ss, token);
System.out.println("URI:" + uri);
sources.forEach(vs -> {
VideoSourceExtension vse = vs.getExtension();
ImagingSettings20 imageSettings = vse != null ? vse.getImaging() : null;
System.out.println("===============================");
StringBuilder sb = new StringBuilder("VS - Token=");
sb.append(vs.getToken()).append(" frame rate=").append(vs.getFramerate());
sb.append(" Res [").append(vs.getResolution().getWidth()).append(",")
.append(vs.getResolution().getHeight()).append("]");
if (vse != null) {
sb.append(" Brightness=");
if (imageSettings != null) {
sb.append(imageSettings.getBrightness());
} else {
sb.append("NONE");
}
sb.append(" Focus=");
if (imageSettings.getFocus() != null) {
sb.append(imageSettings.getFocus().getDefaultSpeed());
} else {
sb.append("NONE");
}
sb.append(" AutoFocus=");
if (imageSettings.getFocus() != null) {
sb.append(imageSettings.getFocus().getAutoFocusMode());
} else {
sb.append("NONE");
}
} else {
sb.append(" NO VIDEO SOURCE EXTENSION!!");
}
System.out.println(sb.toString());
});
VideoSourceConfiguration vsc = cam.getMedia().getVideoSourceConfiguration("0");

System.out.println("VideoSourceConfiguration= " + vsc);

List<PTZConfiguration> ptzConfigurations = cam.getPtz().getConfigurations();
ptzConfigurations.forEach(ptzC -> {
System.out.println("PTZConfig:" + ptzC);
});
} catch (SOAPException e) {
e.printStackTrace();
}

// cxfDiscovery();

}

// @SuppressWarnings("unused")
// private static void cxfDiscovery() throws IOException {
// //Use WS-Discovery to find references to services that implement the changeName portType
// String targetAddress = "soap.udp://192.168.1.53:3702";
// WSDiscoveryClient client = new WSDiscoveryClient();
// // Setting timeout for WS-Discovery
// client.setDefaultProbeTimeout(1000);
// // Use WS-discovery 1.0
// client.setVersion10();
// client.setSoapVersion11();
// System.out.println("Probe:" + client.getAddress());
// List<EndpointReference> references = client.probe(DiscoveryService.SERVICE);
//// List<EndpointReference> references = client.probe();
// System.out.println("The probe has been finished");
// client.close();
//
// System.out.println("Found "+references.size()+" ONVIF devices");
// //loop through all of them and have them greet me.
//// DiscoveryService service = new DiscoveryService();
// for (EndpointReference ref : references) {
//// HelloType g = service.getPort(ref, HelloType.class);
// System.out.println(ref);
// }
// }
}
40 changes: 40 additions & 0 deletions onvif-java/src/main/java/de/onvif/services/IPTZListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2018 Alessio Iannone
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: The above copyright
* notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package de.onvif.services;

/**
* You have to implement and register this listener on the {@link PTZStatusService} to be notified of the PTZ Status
* retrieved from the device.
*
* @author Alessio Iannone - [email protected]
*
*/
@FunctionalInterface
public interface IPTZListener {
/**
*
* @param afov - sessadecimal degree of the AFOV value. AFOV is the Angular Field of View
* @param pan - sessadecimal degree for the panning value
* @param tilt - sessadecimal degree for the tilt value
*
*/
public void notifyPTZStatus(double afov, double pan, double tilt);
}
Loading