use of com.thoughtworks.xstream.io.xml.DomDriver in project cloudstack by apache.
the class RegionsApiUtil method makeAccountAPICall.
/**
* Makes an api call using region service end_point, api command and params
* Returns Account object on success
* @param region
* @param command
* @param params
* @return
*/
protected static RegionAccount makeAccountAPICall(Region region, String command, List<NameValuePair> params) {
try {
String url = buildUrl(buildParams(command, params), region);
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(url);
if (client.executeMethod(method) == 200) {
InputStream is = method.getResponseBodyAsStream();
// Translate response to Account object
XStream xstream = new XStream(new DomDriver());
xstream.alias("account", RegionAccount.class);
xstream.alias("user", RegionUser.class);
xstream.aliasField("id", RegionAccount.class, "uuid");
xstream.aliasField("name", RegionAccount.class, "accountName");
xstream.aliasField("accounttype", RegionAccount.class, "type");
xstream.aliasField("domainid", RegionAccount.class, "domainUuid");
xstream.aliasField("networkdomain", RegionAccount.class, "networkDomain");
xstream.aliasField("id", RegionUser.class, "uuid");
xstream.aliasField("accountId", RegionUser.class, "accountUuid");
try (ObjectInputStream in = xstream.createObjectInputStream(is)) {
return (RegionAccount) in.readObject();
} catch (IOException e) {
s_logger.error(e.getMessage());
return null;
}
} else {
return null;
}
} catch (HttpException e) {
s_logger.error(e.getMessage());
return null;
} catch (IOException e) {
s_logger.error(e.getMessage());
return null;
} catch (ClassNotFoundException e) {
s_logger.error(e.getMessage());
return null;
}
}
use of com.thoughtworks.xstream.io.xml.DomDriver in project cloudstack by apache.
the class RegionsApiUtil method makeDomainAPICall.
/**
* Makes an api call using region service end_point, api command and params
* Returns Domain object on success
* @param region
* @param command
* @param params
* @return
*/
protected static RegionDomain makeDomainAPICall(Region region, String command, List<NameValuePair> params) {
try {
String url = buildUrl(buildParams(command, params), region);
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(url);
if (client.executeMethod(method) == 200) {
InputStream is = method.getResponseBodyAsStream();
XStream xstream = new XStream(new DomDriver());
// Translate response to Domain object
xstream.alias("domain", RegionDomain.class);
xstream.aliasField("id", RegionDomain.class, "uuid");
xstream.aliasField("parentdomainid", RegionDomain.class, "parentUuid");
xstream.aliasField("networkdomain", DomainVO.class, "networkDomain");
try (ObjectInputStream in = xstream.createObjectInputStream(is)) {
return (RegionDomain) in.readObject();
} catch (IOException e) {
s_logger.error(e.getMessage());
return null;
}
} else {
return null;
}
} catch (HttpException e) {
s_logger.error(e.getMessage());
return null;
} catch (IOException e) {
s_logger.error(e.getMessage());
return null;
} catch (ClassNotFoundException e) {
s_logger.error(e.getMessage());
return null;
}
}
use of com.thoughtworks.xstream.io.xml.DomDriver in project batfish by batfish.
the class PluginConsumer method serializeToLz4Data.
/**
* Serializes the given object to the given stream, using LZ4 compression.
*/
private void serializeToLz4Data(Serializable object, OutputStream out) {
// This is a hack:
// XStream requires that its streams be closed to properly finish serialization,
// but we do not actually want to close the passed-in output stream.
out = new CloseIgnoringOutputStream(out);
try (Closer closer = Closer.create()) {
OutputStream los = closer.register(new LZ4FrameOutputStream(out));
ObjectOutputStream oos;
if (_serializeToText) {
XStream xstream = new XStream(new DomDriver("UTF-8"));
oos = closer.register(xstream.createObjectOutputStream(los));
} else {
oos = closer.register(new ObjectOutputStream(los));
}
oos.writeObject(object);
} catch (IOException e) {
throw new BatfishException("Failed to convert object to LZ4 data", e);
}
}
use of com.thoughtworks.xstream.io.xml.DomDriver in project head by mifos.
the class QuestionGroupDefinitionParserImpl method initializeXStream.
private XStream initializeXStream() {
XStream xstream = new XStream(new DomDriver("UTF-8"));
processAnnotations(xstream);
return xstream;
}
use of com.thoughtworks.xstream.io.xml.DomDriver in project intellij-plugins by JetBrains.
the class ProjectsData method serialize.
public Element serialize() {
XStream xStream = new XStream(new DomDriver());
String s = xStream.toXML(myStatus);
try {
return new SAXBuilder().build(new StringReader(s)).getRootElement();
} catch (JDOMException e) {
LOG.error(e.getMessage(), e);
} catch (IOException e) {
LOG.error(e.getMessage(), e);
}
return new Element("");
}
Aggregations