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 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 jmeter by apache.
the class TemplateManager method initXStream.
private XStream initXStream() {
XStream xstream = new XStream(new DomDriver() {
/**
* Create the DocumentBuilderFactory instance.
* See https://blog.compass-security.com/2012/08/secure-xml-parser-configuration/
* See https://github.com/x-stream/xstream/issues/25
* @return the new instance
*/
@Override
protected DocumentBuilderFactory createDocumentBuilderFactory() {
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
} catch (ParserConfigurationException e) {
throw new StreamException(e);
}
factory.setExpandEntityReferences(false);
return factory;
}
});
xstream.alias("template", Template.class);
xstream.alias("templates", Templates.class);
xstream.useAttributeFor(Template.class, "isTestPlan");
// templates i
xstream.addImplicitMap(Templates.class, // $NON-NLS-1$
"templates", Template.class, // $NON-NLS-1$
"name");
return xstream;
}
use of com.thoughtworks.xstream.XStream in project jmeter by apache.
the class ObjectMessageRenderer method getValueFromText.
/**
* Try to load an object via XStream from XML text, so that it can be used as body
* for a JMS message.
* An {@link IllegalStateException} will be thrown if transforming the XML to an object fails.
*
* @param xmlMessage String containing XML text as input for the transformation
* @return Serialized object instance
*/
@Override
public Serializable getValueFromText(final String xmlMessage) {
Serializable readObject = null;
try {
XStream xstream = new XStream();
readObject = (Serializable) xstream.fromXML(xmlMessage, readObject);
} catch (Exception e) {
throw new IllegalStateException("Unable to load object instance from text", e);
}
return readObject;
}
use of com.thoughtworks.xstream.XStream in project maven-plugins by apache.
the class EvaluateMojo method getXStream.
/**
* @return lazy loading xstream object.
*/
private XStream getXStream() {
if (xstream == null) {
xstream = new XStream();
addAlias(xstream);
// handle Properties a la Maven
xstream.registerConverter(new PropertiesConverter() {
/** {@inheritDoc} */
public boolean canConvert(@SuppressWarnings("rawtypes") Class type) {
return Properties.class == type;
}
/** {@inheritDoc} */
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
Properties properties = (Properties) source;
// sort
Map<?, ?> map = new TreeMap<Object, Object>(properties);
for (Map.Entry<?, ?> entry : map.entrySet()) {
writer.startNode(entry.getKey().toString());
writer.setValue(entry.getValue().toString());
writer.endNode();
}
}
});
}
return xstream;
}
Aggregations