use of org.apache.xmlrpc.XmlRpcException 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);
}
use of org.apache.xmlrpc.XmlRpcException in project camel by apache.
the class XmlRpcDataFormat method getXMLWriter.
protected XMLWriter getXMLWriter(Exchange exchange, OutputStream outputStream) throws XmlRpcException {
XMLWriter writer = new CharSetXMLWriter();
String encoding = IOHelper.getCharsetName(exchange);
writer.setEncoding(encoding);
writer.setIndenting(false);
writer.setFlushing(true);
try {
writer.setWriter(new BufferedWriter(new OutputStreamWriter(outputStream, encoding)));
} catch (UnsupportedEncodingException e) {
throw new XmlRpcException("Unsupported encoding: " + encoding, e);
}
return writer;
}
use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.
the class OvmResourceBase method execute.
protected Answer execute(PrepareOCFS2NodesCommand cmd) {
List<Ternary<Integer, String, String>> nodes = cmd.getNodes();
StringBuffer params = new StringBuffer();
for (Ternary<Integer, String, String> node : nodes) {
String param = String.format("%1$s:%2$s:%3$s", node.first(), node.second(), node.third());
params.append(param);
params.append(";");
}
try {
OvmStoragePool.prepareOCFS2Nodes(_conn, cmd.getClusterName(), params.toString());
return new Answer(cmd, true, "Success");
} catch (XmlRpcException e) {
s_logger.debug("OCFS2 prepare nodes failed", e);
return new Answer(cmd, false, e.getMessage());
}
}
use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.
the class Connection method callTimeoutInSec.
public Object callTimeoutInSec(String method, List<?> params, int timeout, boolean debug) throws XmlRpcException {
TimingOutCallback callback = new TimingOutCallback(timeout * 1000);
if (debug) {
LOGGER.debug("Call Ovm3 agent " + hostName + "(" + hostIp + "): " + method + " with " + params);
}
long startTime = System.currentTimeMillis();
try {
/* returns actual xml */
XmlRpcClientRequestImpl req = new XmlRpcClientRequestImpl(xmlClient.getClientConfig(), method, params);
xmlClient.executeAsync(req, callback);
return callback.waitForResponse();
} catch (TimingOutCallback.TimeoutException e) {
LOGGER.info("Timeout: ", e);
throw new XmlRpcException(e.getMessage());
} catch (XmlRpcException e) {
LOGGER.info("XML RPC Exception occured: ", e);
throw e;
} catch (RuntimeException e) {
LOGGER.info("Runtime Exception: ", e);
throw new XmlRpcException(e.getMessage());
} catch (Throwable e) {
LOGGER.error("Holy crap batman!: ", e);
throw new XmlRpcException(e.getMessage(), e);
} finally {
long endTime = System.currentTimeMillis();
/* in seconds */
float during = (endTime - startTime) / (float) 1000;
LOGGER.debug("Ovm3 call " + method + " finished in " + during + " secs, on " + hostIp + ":" + hostPort);
}
}
use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.
the class OvmResourceBase method execute.
@Override
public StopAnswer execute(StopCommand cmd) {
String vmName = cmd.getVmName();
try {
OvmVm.Details vm = null;
try {
vm = OvmVm.getDetails(_conn, vmName);
} catch (XmlRpcException e) {
s_logger.debug("Unable to get details of vm: " + vmName + ", treating it as stopped", e);
return new StopAnswer(cmd, "success", true);
}
deleteAllNetworkRulesForVm(vmName);
OvmVm.stop(_conn, vmName);
cleanup(vm);
return new StopAnswer(cmd, "success", true);
} catch (Exception e) {
s_logger.debug("Stop " + vmName + "failed", e);
return new StopAnswer(cmd, e.getMessage(), false);
}
}
Aggregations