use of com.biglybt.net.upnpms.UPnPMSException in project BiglyBT by BiglySoftware.
the class UPNPMSBrowserImpl method getXML.
private SimpleXMLParserDocument getXML(URL url, String soap_action, String post_data) throws UPnPMSException {
ResourceDownloader rd = new ResourceDownloaderFactoryImpl().create(url, post_data);
try {
rd.setProperty("URL_Connection", "Keep-Alive");
rd.setProperty("URL_Read_Timeout", 10 * 60 * 1000);
rd.setProperty("URL_Connect_Timeout", 5 * 60 * 1000);
rd.setProperty("URL_SOAPAction", "\"" + soap_action + "\"");
rd.setProperty("URL_X-AV-Client-Info", "av=1.0; cn=\"" + Constants.AZUREUS_NAME + "\"; mn=\"" + client_name + "\"; mv=\"" + Constants.AZUREUS_VERSION + "\"");
rd.setProperty("URL_Content-Type", "text/xml; charset=\"utf-8\"");
SimpleXMLParserDocument doc = SimpleXMLParserDocumentFactory.create(url, rd.download());
return (doc);
} catch (Throwable e) {
throw (new UPnPMSException("XML RPC failed", e));
}
}
use of com.biglybt.net.upnpms.UPnPMSException in project BiglyBT by BiglySoftware.
the class UPNPMSBrowserImpl method getContainerContents.
protected List<SimpleXMLParserDocumentNode> getContainerContents(String id) throws UPnPMSException {
try {
List<SimpleXMLParserDocumentNode> results = new ArrayList<>();
int starting_index = 0;
while (true) {
String NL = "\r\n";
String soap_action = "urn:schemas-upnp-org:service:ContentDirectory:1#Browse";
String request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + NL + "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + NL + "<s:Body>" + NL + "<u:Browse xmlns:u=\"urn:schemas-upnp-org:service:ContentDirectory:1\">" + NL + "<ObjectID>" + id + "</ObjectID>" + NL + "<BrowseFlag>BrowseDirectChildren</BrowseFlag>" + NL + "<Filter>dc:date,res@protocolInfo,res@size</Filter>" + NL + "<StartingIndex>" + starting_index + "</StartingIndex>" + NL + "<RequestedCount>256</RequestedCount>" + NL + "<SortCriteria></SortCriteria>" + NL + "</u:Browse>" + NL + "</s:Body>" + NL + "</s:Envelope>";
SimpleXMLParserDocument doc = null;
UPnPMSException last_error = null;
for (URL endpoint : new ArrayList<>(endpoints)) {
try {
doc = getXML(endpoint, soap_action, request);
setPreferredEndpoint(endpoint);
break;
} catch (UPnPMSException e) {
last_error = e;
}
}
if (doc == null) {
throw (last_error);
}
SimpleXMLParserDocumentNode body = doc.getChild("Body");
SimpleXMLParserDocumentNode response = body.getChild("BrowseResponse");
SimpleXMLParserDocumentNode didl_result = response.getChild("Result");
String didl_str = didl_result.getValue();
SimpleXMLParserDocument didle_doc = SimpleXMLParserDocumentFactory.create(didl_str);
results.add(didle_doc);
int num_returned = Integer.parseInt(response.getChild("NumberReturned").getValue());
if (num_returned <= 0) {
break;
}
starting_index += num_returned;
int total_matches = Integer.parseInt(response.getChild("TotalMatches").getValue());
if (starting_index >= total_matches) {
break;
}
}
return (results);
} catch (UPnPMSException e) {
throw (e);
} catch (Throwable e) {
throw (new UPnPMSException("Failed to read container", e));
}
}
Aggregations