Search in sources :

Example 1 with XmlRpcClientException

use of org.apache.xmlrpc.client.XmlRpcClientException in project camel by apache.

the class XmlRpcDataFormat method unmarshalResponse.

protected Object unmarshalResponse(Exchange exchange, InputStream stream) throws Exception {
    InputSource isource = new InputSource(stream);
    XMLReader xr = newXMLReader();
    XmlRpcResponseParser xp;
    try {
        xp = new XmlRpcResponseParser(xmlRpcStreamRequestConfig, typeFactory);
        xr.setContentHandler(xp);
        xr.parse(isource);
    } catch (SAXException e) {
        throw new XmlRpcClientException("Failed to parse server's response: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new XmlRpcClientException("Failed to read server's response: " + e.getMessage(), e);
    }
    if (xp.isSuccess()) {
        return xp.getResult();
    }
    Throwable t = xp.getErrorCause();
    if (t == null) {
        throw new XmlRpcException(xp.getErrorCode(), xp.getErrorMessage());
    }
    if (t instanceof XmlRpcException) {
        throw (XmlRpcException) t;
    }
    if (t instanceof RuntimeException) {
        throw (RuntimeException) t;
    }
    throw new XmlRpcException(xp.getErrorCode(), xp.getErrorMessage(), t);
}
Also used : InputSource(org.xml.sax.InputSource) XmlRpcClientException(org.apache.xmlrpc.client.XmlRpcClientException) IOException(java.io.IOException) XMLReader(org.xml.sax.XMLReader) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XmlRpcResponseParser(org.apache.xmlrpc.parser.XmlRpcResponseParser) SAXException(org.xml.sax.SAXException)

Example 2 with XmlRpcClientException

use of org.apache.xmlrpc.client.XmlRpcClientException in project camel by apache.

the class XmlRpcDataFormat method unmarshalRequest.

protected Object unmarshalRequest(Exchange exchange, InputStream stream) throws Exception {
    InputSource isource = new InputSource(stream);
    XMLReader xr = newXMLReader();
    XmlRpcRequestParser xp;
    try {
        xp = new XmlRpcRequestParser(xmlRpcStreamRequestConfig, typeFactory);
        xr.setContentHandler(xp);
        xr.parse(isource);
    } catch (SAXException e) {
        throw new XmlRpcClientException("Failed to parse server's response: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new XmlRpcClientException("Failed to read server's response: " + e.getMessage(), e);
    }
    return new XmlRpcRequestImpl(xp.getMethodName(), xp.getParams());
}
Also used : XmlRpcRequestParser(org.apache.xmlrpc.parser.XmlRpcRequestParser) InputSource(org.xml.sax.InputSource) XmlRpcRequestImpl(org.apache.camel.component.xmlrpc.XmlRpcRequestImpl) XmlRpcClientException(org.apache.xmlrpc.client.XmlRpcClientException) IOException(java.io.IOException) XMLReader(org.xml.sax.XMLReader) SAXException(org.xml.sax.SAXException)

Aggregations

IOException (java.io.IOException)2 XmlRpcClientException (org.apache.xmlrpc.client.XmlRpcClientException)2 InputSource (org.xml.sax.InputSource)2 SAXException (org.xml.sax.SAXException)2 XMLReader (org.xml.sax.XMLReader)2 XmlRpcRequestImpl (org.apache.camel.component.xmlrpc.XmlRpcRequestImpl)1 XmlRpcException (org.apache.xmlrpc.XmlRpcException)1 XmlRpcRequestParser (org.apache.xmlrpc.parser.XmlRpcRequestParser)1 XmlRpcResponseParser (org.apache.xmlrpc.parser.XmlRpcResponseParser)1