use of com.thoughtworks.xstream.XStream 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.XStream in project audit4j-core by audit4j.
the class XMLConfigProvider method generateConfig.
/**
* {@inheritDoc}
*/
@Override
public void generateConfig(T config, String filePath) throws ConfigurationException {
XStream xstream = new XStream(new StaxDriver());
xstream.alias("configuration", clazz);
BufferedOutputStream stdout = null;
try {
stdout = new BufferedOutputStream(new FileOutputStream(filePath));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
xstream.marshal(config, new PrettyPrintWriter(new OutputStreamWriter(stdout)));
}
use of com.thoughtworks.xstream.XStream in project ignite by apache.
the class IgniteNodeRunner method readCfgFromFileAndDeleteFile.
/**
* Reads configuration from given file and delete the file after.
*
* @param fileName File name.
* @return Readed configuration.
* @throws IOException If failed.
* @see #storeToFile(IgniteConfiguration, boolean)
* @throws IgniteCheckedException On error.
*/
private static IgniteConfiguration readCfgFromFileAndDeleteFile(String fileName) throws IOException, IgniteCheckedException {
try (BufferedReader cfgReader = new BufferedReader(new FileReader(fileName))) {
IgniteConfiguration cfg = (IgniteConfiguration) new XStream().fromXML(cfgReader);
if (cfg.getMarshaller() == null) {
Marshaller marsh = IgniteTestResources.getMarshaller();
cfg.setMarshaller(marsh);
}
X.println("Configured marshaller class: " + cfg.getMarshaller().getClass().getName());
if (cfg.getDiscoverySpi() == null) {
TcpDiscoverySpi disco = new TcpDiscoverySpi();
disco.setIpFinder(GridCacheAbstractFullApiSelfTest.LOCAL_IP_FINDER);
cfg.setDiscoverySpi(disco);
}
return cfg;
} finally {
new File(fileName).delete();
}
}
use of com.thoughtworks.xstream.XStream in project drools by kiegroup.
the class XmlBifParser method loadBif.
public static Bif loadBif(URL url) {
XStream xstream = createTrustingXStream();
initXStream(xstream);
Bif bif = (Bif) xstream.fromXML(url);
return bif;
}
use of com.thoughtworks.xstream.XStream in project drools by kiegroup.
the class XmlBifParser method loadBif.
public static Bif loadBif(Resource resource, KnowledgeBuilderErrors errors) {
InputStream is = null;
try {
is = resource.getInputStream();
} catch (IOException e) {
errors.add(new ParserError(resource, "Exception opening Stream:\n" + e.toString(), 0, 0));
return null;
}
try {
String encoding = resource instanceof InternalResource ? ((InternalResource) resource).getEncoding() : null;
XStream xstream = encoding != null ? createTrustingXStream(new DomDriver(encoding)) : createTrustingXStream();
initXStream(xstream);
Bif bif = (Bif) xstream.fromXML(is);
return bif;
} catch (Exception e) {
errors.add(new BayesNetworkAssemblerError(resource, "Unable to parse opening Stream:\n" + e.toString()));
return null;
}
}
Aggregations