Search in sources :

Example 11 with DomDriver

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;
    }
}
Also used : DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) XStream(com.thoughtworks.xstream.XStream) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException) HttpMethod(org.apache.commons.httpclient.HttpMethod) ObjectInputStream(java.io.ObjectInputStream)

Example 12 with DomDriver

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;
    }
}
Also used : DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) XStream(com.thoughtworks.xstream.XStream) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException) HttpMethod(org.apache.commons.httpclient.HttpMethod) ObjectInputStream(java.io.ObjectInputStream)

Example 13 with DomDriver

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);
    }
}
Also used : Closer(com.google.common.io.Closer) BatfishException(org.batfish.common.BatfishException) DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) XStream(com.thoughtworks.xstream.XStream) LZ4FrameOutputStream(net.jpountz.lz4.LZ4FrameOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) OutputStream(java.io.OutputStream) FilterOutputStream(java.io.FilterOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) LZ4FrameOutputStream(net.jpountz.lz4.LZ4FrameOutputStream)

Example 14 with DomDriver

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;
}
Also used : DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) XStream(com.thoughtworks.xstream.XStream)

Example 15 with DomDriver

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("");
}
Also used : DomDriver(com.thoughtworks.xstream.io.xml.DomDriver) SAXBuilder(org.jdom.input.SAXBuilder) XStream(com.thoughtworks.xstream.XStream) Element(org.jdom.Element) StringReader(java.io.StringReader) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException)

Aggregations

XStream (com.thoughtworks.xstream.XStream)32 DomDriver (com.thoughtworks.xstream.io.xml.DomDriver)32 IOException (java.io.IOException)8 Gson (com.google.gson.Gson)5 File (java.io.File)5 InputStream (java.io.InputStream)5 ObjectInputStream (java.io.ObjectInputStream)5 GsonBuilder (com.google.gson.GsonBuilder)4 Binder (net.sergeych.tools.Binder)4 Yaml (org.yaml.snakeyaml.Yaml)4 HttpClient (org.apache.commons.httpclient.HttpClient)3 HttpException (org.apache.commons.httpclient.HttpException)3 HttpMethod (org.apache.commons.httpclient.HttpMethod)3 GetMethod (org.apache.commons.httpclient.methods.GetMethod)3 XStreamException (com.thoughtworks.xstream.XStreamException)2 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 BackingStoreException (java.util.prefs.BackingStoreException)2 OptionException (joptsimple.OptionException)2 BiDeserializer (net.sergeych.biserializer.BiDeserializer)2