Whe control point try to get XML that describes Service, there is a problem in ControlRequest::setRequestHost(Service)
at the following lines:
String urlBase =
service.getRootDevice().getURLBase();
if (urlBase != null && 0 < urlBase.length()){
try {
URL url = new URL(urlBase);
String basePath = url.getPath();
int baseLen = basePath.length();
if (0 < baseLen) {
if (1 < baseLen || (basePath.charAt(0) != '/'))
ctrlURL = basePath + ctrlURL;
}
}catch (MalformedURLException e) {}
}
the above code is correct only if the ctrlURL is a relative path. But the UPnP Specification said that the baseURL and evne the ctrlURL may be URI. In particular I had trouble with a ctrlURL that is a AbsolutePath instead of a RelativePath
The device that I'm speaking about is the BinaryLight that come with the Siemens UPnP SDK. It's XML have either a URLBase and a absoulte path as controlURL.
<URLBase>http://<ip>/<path1>/</URLBase>
<controlURL>/<path1>/<path2></URLBase>
So, your fix thr problem with the example that you wrote and looking at UPnP Spercification it's valid
To solve either my problem you have to add
String urlBase = service.getRootDevice().getURLBase();
if ((HTTP.isAbsoluteURL(ctrlURL) == false)&&(ctrlURL.charAt(0) != '/')) {
if (urlBase != null && 0 < urlBase.length()){
try {
URL url = new URL(urlBase);
String basePath = url.getPath();
int baseLen = basePath.length();
if (0 < baseLen) {
if (1 < baseLen || (basePath.charAt(0) != '/'))
ctrlURL = basePath + ctrlURL;
}
}
catch (MalformedURLException e) {}
}
}
P.S.: In my previus post the solution for contrlURL didn't call a method so my previous code should be
String ctrlURL = service.getControlURL();
URL ctrlFullURL = null;
try {
ctrlFullURL = new URL(ctrlURL);
String host = ctrlFullURL.getHost();
int port = ctrlFullURL.getPort();
if(port == -1) port = ctrlFullURL.getDefaultPort();
setURI(ctrlURL, true);
setHost(host,port);
setRequestHost(host);
setRequestPort(port);
return;
} catch (MalformedURLException ignored) {}
if(ctrlURL.length>0 && ctrlURL.charAt(0) != '/'){
/*
Here is the code of Thomas Schulz (2004/03/20)
*/
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Whe control point try to get XML that describes Service, there is a problem in ControlRequest::setRequestHost(Service)
at the following lines:
String urlBase =
service.getRootDevice().getURLBase();
if (urlBase != null && 0 < urlBase.length()){
try {
URL url = new URL(urlBase);
String basePath = url.getPath();
int baseLen = basePath.length();
if (0 < baseLen) {
if (1 < baseLen || (basePath.charAt(0) != '/'))
ctrlURL = basePath + ctrlURL;
}
}catch (MalformedURLException e) {}
}
the above code is correct only if the ctrlURL is a relative path. But the UPnP Specification said that the baseURL and evne the ctrlURL may be URI. In particular I had trouble with a ctrlURL that is a AbsolutePath instead of a RelativePath
The solution (only for AbsolutePath) may be:
String urlBase =
service.getRootDevice().getURLBase();
if (urlBase != null && 0 < urlBase.length()){
try {
URL url = new URL(urlBase);
String basePath = url.getPath();
int baseLen = basePath.length();
if(ctrlURL.charAt(0)!='/' && 0 < baseLen) {
if (1 < baseLen || (basePath.charAt(0) != '/'))
ctrlURL = basePath + ctrlURL;
}
}catch (MalformedURLException e) {}
}
A complete solution for URI may be:
String ctrlURL = service.getControlURL();
URL ctrlFullURL = null;
try {
ctrlFullURL = new URL(ctrlURL);
String host = ctrlFullURL.getHost();
int port = ctrlFullURL.getPort();
if(port == -1) port = ctrlFullURL.getDefaultPort();
setHost(host,port);
setRequestHost(host);
setRequestPort(port);
return;
} catch (MalformedURLException ignored) {}
<follow the old code with patch for Absolute ctrlURL>
Hi Stefano,
Does your device has both the URLBase and the absolute path as the following ?
<URLBase>http://xxx.xxx.xxx.xxx./....</URLBase>
<controlURL>http://xxx.xxx.xxx.xxx./....</controlURL>
Could the following code fix your problem ?
String urlBase = service.getRootDevice().getURLBase();
if (HTTP.isAbsoluteURL(ctrlURL) == false) {
if (urlBase != null && 0 < urlBase.length()){
try {
URL url = new URL(urlBase);
String basePath = url.getPath();
int baseLen = basePath.length();
if (0 < baseLen) {
if (1 < baseLen || (basePath.charAt(0) != '/'))
ctrlURL = basePath + ctrlURL;
}
}
catch (MalformedURLException e) {}
}
}
The device that I'm speaking about is the BinaryLight that come with the Siemens UPnP SDK. It's XML have either a URLBase and a absoulte path as controlURL.
<URLBase>http://<ip>/<path1>/</URLBase>
<controlURL>/<path1>/<path2></URLBase>
So, your fix thr problem with the example that you wrote and looking at UPnP Spercification it's valid
To solve either my problem you have to add
String urlBase = service.getRootDevice().getURLBase();
if ((HTTP.isAbsoluteURL(ctrlURL) == false)&&(ctrlURL.charAt(0) != '/')) {
if (urlBase != null && 0 < urlBase.length()){
try {
URL url = new URL(urlBase);
String basePath = url.getPath();
int baseLen = basePath.length();
if (0 < baseLen) {
if (1 < baseLen || (basePath.charAt(0) != '/'))
ctrlURL = basePath + ctrlURL;
}
}
catch (MalformedURLException e) {}
}
}
P.S.: In my previus post the solution for contrlURL didn't call a method so my previous code should be
String ctrlURL = service.getControlURL();
URL ctrlFullURL = null;
try {
ctrlFullURL = new URL(ctrlURL);
String host = ctrlFullURL.getHost();
int port = ctrlFullURL.getPort();
if(port == -1) port = ctrlFullURL.getDefaultPort();
setURI(ctrlURL, true);
setHost(host,port);
setRequestHost(host);
setRequestPort(port);
return;
} catch (MalformedURLException ignored) {}
if(ctrlURL.length>0 && ctrlURL.charAt(0) != '/'){
/*
Here is the code of Thomas Schulz (2004/03/20)
*/
}
Hi Stefano,
Thanks for many suggestions :-)
Wheren could I get the sample, BinaryLight ?
I got the C++ and Java SDK of v1.01 today, but I couldn't only the TestDevice.
><URLBase>http://<ip>/<path1>/</URLBase>
><controlURL>/<path1>/<path2></URLBase>
Umm ... It is a complex case.
I checked your problem using Siemens Java SDK v1.01 for UPnP. However, It seems that the latest version has no URLBase.
Intel's NMPR recommends the URLBase is blank. It might be changed for the NMPR
Thanks for any advices :-)