Search in sources :

Example 66 with Marshaller

use of javax.xml.bind.Marshaller in project phoenix by apache.

the class XMLConfigParser method writeDataModel.

// TODO Remove static calls
@SuppressWarnings("unused")
public static void writeDataModel(DataModel data, OutputStream output) throws JAXBException {
    // create JAXB context and initializing Marshaller
    JAXBContext jaxbContext = JAXBContext.newInstance(DataModel.class);
    Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
    // for getting nice formatted output
    jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    // Writing to console
    jaxbMarshaller.marshal(data, output);
}
Also used : Marshaller(javax.xml.bind.Marshaller) JAXBContext(javax.xml.bind.JAXBContext)

Example 67 with Marshaller

use of javax.xml.bind.Marshaller in project karaf by apache.

the class JaxbUtil method marshal.

public static void marshal(Features features, Writer out) throws JAXBException {
    Marshaller marshaller = FEATURES_CONTEXT.createMarshaller();
    marshaller.setProperty("jaxb.formatted.output", true);
    marshaller.marshal(features, out);
}
Also used : Marshaller(javax.xml.bind.Marshaller)

Example 68 with Marshaller

use of javax.xml.bind.Marshaller in project cloudstack by apache.

the class SecurityGroupHttpClient method call.

public SecurityGroupRuleAnswer call(String agentIp, SecurityGroupRulesCmd cmd) {
    PostMethod post = new PostMethod(String.format("http://%s:%s", agentIp, getPort()));
    try {
        SecurityGroupVmRuleSet rset = new SecurityGroupVmRuleSet();
        rset.getEgressRules().addAll(generateRules(cmd.getEgressRuleSet()));
        rset.getIngressRules().addAll(generateRules(cmd.getIngressRuleSet()));
        rset.setVmName(cmd.getVmName());
        rset.setVmIp(cmd.getGuestIp());
        rset.setVmMac(cmd.getGuestMac());
        rset.setVmId(cmd.getVmId());
        rset.setSignature(cmd.getSignature());
        rset.setSequenceNumber(cmd.getSeqNum());
        Marshaller marshaller = context.createMarshaller();
        StringWriter writer = new StringWriter();
        marshaller.marshal(rset, writer);
        String xmlContents = writer.toString();
        logger.debug(xmlContents);
        post.addRequestHeader("command", "set_rules");
        StringRequestEntity entity = new StringRequestEntity(xmlContents);
        post.setRequestEntity(entity);
        if (httpClient.executeMethod(post) != 200) {
            return new SecurityGroupRuleAnswer(cmd, false, post.getResponseBodyAsString());
        } else {
            return new SecurityGroupRuleAnswer(cmd);
        }
    } catch (Exception e) {
        return new SecurityGroupRuleAnswer(cmd, false, e.getMessage());
    } finally {
        if (post != null) {
            post.releaseConnection();
        }
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) StringWriter(java.io.StringWriter) PostMethod(org.apache.commons.httpclient.methods.PostMethod) SecurityGroupVmRuleSet(com.cloud.baremetal.networkservice.schema.SecurityGroupVmRuleSet) SecurityGroupRuleAnswer(com.cloud.agent.api.SecurityGroupRuleAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SocketTimeoutException(java.net.SocketTimeoutException)

Example 69 with Marshaller

use of javax.xml.bind.Marshaller in project asterixdb by apache.

the class TestHelper method writeConfigurations.

public static void writeConfigurations(AsterixConfiguration ac, String fileName) throws FileNotFoundException, IOException, JAXBException {
    File configFile = new File(fileName);
    if (!configFile.exists()) {
        configFile.getParentFile().mkdirs();
        configFile.createNewFile();
    } else {
        configFile.delete();
    }
    try (FileOutputStream os = new FileOutputStream(fileName)) {
        JAXBContext ctx = JAXBContext.newInstance(AsterixConfiguration.class);
        Marshaller marshaller = ctx.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(ac, os);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) FileOutputStream(java.io.FileOutputStream) JAXBContext(javax.xml.bind.JAXBContext) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 70 with Marshaller

use of javax.xml.bind.Marshaller in project asterixdb by apache.

the class Utils method writeYarnClusterConfig.

public static void writeYarnClusterConfig(String path, Cluster cl) throws YarnException {
    try {
        File f = new File(path);
        JAXBContext configCtx = JAXBContext.newInstance(Cluster.class);
        Marshaller marhsaller = configCtx.createMarshaller();
        marhsaller.marshal(cl, f);
    } catch (JAXBException e) {
        throw new YarnException(e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) File(java.io.File) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Aggregations

Marshaller (javax.xml.bind.Marshaller)280 JAXBContext (javax.xml.bind.JAXBContext)162 JAXBException (javax.xml.bind.JAXBException)100 StringWriter (java.io.StringWriter)82 Test (org.junit.Test)33 JAXBElement (javax.xml.bind.JAXBElement)32 ByteArrayOutputStream (java.io.ByteArrayOutputStream)31 File (java.io.File)29 Unmarshaller (javax.xml.bind.Unmarshaller)21 IOException (java.io.IOException)20 FileOutputStream (java.io.FileOutputStream)19 ByteArrayInputStream (java.io.ByteArrayInputStream)15 QName (javax.xml.namespace.QName)14 Element (org.w3c.dom.Element)14 HashMap (java.util.HashMap)12 Writer (java.io.Writer)11 Document (org.w3c.dom.Document)11 InputStream (java.io.InputStream)7 OutputStream (java.io.OutputStream)7 ArrayList (java.util.ArrayList)7