Search in sources :

Example 6 with SimpleXMLParserDocument

use of com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocument in project BiglyBT by BiglySoftware.

the class UPnPImpl method performSOAPRequest.

public SimpleXMLParserDocument performSOAPRequest(UPnPService service, String soap_action, String request) throws SimpleXMLParserDocumentException, UPnPException, IOException {
    SimpleXMLParserDocument res;
    if (service.getDirectInvocations() || forceDirect()) {
        res = performSOAPRequest(service, soap_action, request, false);
    } else {
        try {
            res = performSOAPRequest(service, soap_action, request, true);
            http_calls_ok++;
        } catch (IOException e) {
            res = performSOAPRequest(service, soap_action, request, false);
            direct_calls_ok++;
            if (direct_calls_ok == 1) {
                log("Invocation via http connection failed (" + e.getMessage() + ") but socket connection succeeded");
            }
        }
    }
    return (res);
}
Also used : SimpleXMLParserDocument(com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocument)

Example 7 with SimpleXMLParserDocument

use of com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocument in project BiglyBT by BiglySoftware.

the class UPnPStateVariableImpl method getValue.

@Override
public String getValue() throws UPnPException {
    try {
        String soap_action = "urn:schemas-upnp-org:control-1-0#QueryStateVariable";
        String request = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + "<s:Body>";
        request += "<u:QueryStateVariable xmlns:u=\"urn:schemas-upnp-org:control-1-0\">" + "<u:varName>" + name + "</u:varName>" + "</u:QueryStateVariable>";
        request += "</s:Body>" + "</s:Envelope>";
        SimpleXMLParserDocument resp_doc = ((UPnPDeviceImpl) service.getDevice()).getUPnP().performSOAPRequest(service, soap_action, request);
        SimpleXMLParserDocumentNode body = resp_doc.getChild("Body");
        SimpleXMLParserDocumentNode fault = body.getChild("Fault");
        if (fault != null) {
            throw (new UPnPException("Invoke fails - fault reported: " + fault.getValue()));
        }
        SimpleXMLParserDocumentNode resp_node = body.getChild("QueryStateVariableResponse");
        if (resp_node == null) {
            throw (new UPnPException("Invoke fails - response missing: " + body.getValue()));
        }
        SimpleXMLParserDocumentNode value_node = resp_node.getChild("return");
        return (value_node.getValue());
    } catch (Throwable e) {
        if (e instanceof UPnPException) {
            throw ((UPnPException) e);
        }
        throw (new UPnPException("Invoke fails", e));
    }
}
Also used : SimpleXMLParserDocument(com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocument) SimpleXMLParserDocumentNode(com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode) UPnPException(com.biglybt.net.upnp.UPnPException)

Example 8 with SimpleXMLParserDocument

use of com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocument 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.BIGLYBT_NAME + "\"; mn=\"" + client_name + "\"; mv=\"" + Constants.BIGLYBT_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));
    }
}
Also used : SimpleXMLParserDocument(com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocument) UPnPMSException(com.biglybt.net.upnpms.UPnPMSException) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) ResourceDownloaderFactoryImpl(com.biglybt.pifimpl.local.utils.resourcedownloader.ResourceDownloaderFactoryImpl)

Example 9 with SimpleXMLParserDocument

use of com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocument 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));
    }
}
Also used : SimpleXMLParserDocument(com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocument) ArrayList(java.util.ArrayList) UPnPMSException(com.biglybt.net.upnpms.UPnPMSException) SimpleXMLParserDocumentNode(com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode) URL(java.net.URL)

Aggregations

SimpleXMLParserDocument (com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocument)9 SimpleXMLParserDocumentNode (com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentNode)3 UPnPException (com.biglybt.net.upnp.UPnPException)2 UPnPMSException (com.biglybt.net.upnpms.UPnPMSException)2 ResourceDownloader (com.biglybt.pif.utils.resourcedownloader.ResourceDownloader)2 SimpleXMLParserDocumentException (com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocumentException)2 TOTorrent (com.biglybt.core.torrent.TOTorrent)1 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)1 UPnPActionArgument (com.biglybt.net.upnp.UPnPActionArgument)1 UPnPService (com.biglybt.net.upnp.UPnPService)1 UPnPDeviceImpl (com.biglybt.net.upnp.impl.device.UPnPDeviceImpl)1 ResourceDownloaderFactory (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderFactory)1 ResourceDownloaderFactoryImpl (com.biglybt.pifimpl.local.utils.resourcedownloader.ResourceDownloaderFactoryImpl)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1