Search in sources :

Example 16 with JaxbHelper

use of org.platformlayer.xml.JaxbHelper in project platformlayer by platformlayer.

the class ModelClass method build.

public static <T extends ItemBase> ModelClass<T> build(ServiceProvider serviceProvider, Class<T> clazz) {
    JaxbHelper jaxbHelper = JaxbHelper.get(clazz);
    ItemType itemType = new ItemType(JaxbHelper.getXmlElementName(clazz));
    return new ModelClass<T>(serviceProvider, clazz, itemType);
}
Also used : ItemType(org.platformlayer.ids.ItemType) JaxbHelper(org.platformlayer.xml.JaxbHelper)

Example 17 with JaxbHelper

use of org.platformlayer.xml.JaxbHelper in project platformlayer by platformlayer.

the class JdbcManagedItemRepository method serialize.

byte[] serialize(ItemBase item, CryptoKey itemSecret) {
    // Remove fields that are stored in other columns
    // TODO: Is this the best way to do this?
    // We use JAXB to avoid requiring everything to implement Serializable
    ItemBase mutableItem = CloneHelpers.cloneViaJaxb(item);
    mutableItem.tags = null;
    mutableItem.key = null;
    mutableItem.version = 0;
    mutableItem.state = null;
    JaxbHelper jaxbHelper = JaxbHelper.get(item.getClass());
    StringWriter writer = new StringWriter();
    try {
        Marshaller marshaller = jaxbHelper.createMarshaller();
        // OpsSecretEncryptionStrategy strategy = new OpsSecretEncryptionStrategy(itemSecret);
        // strategy.setAdapter(marshaller);
        marshaller.marshal(mutableItem, writer);
    } catch (JAXBException e) {
        throw new IllegalArgumentException("Could not serialize data", e);
    }
    String xml = writer.toString();
    byte[] ciphertext = FathomdbCrypto.encrypt(itemSecret, Utf8.getBytes(xml));
    return ciphertext;
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) ItemBase(org.platformlayer.core.model.ItemBase) JAXBException(javax.xml.bind.JAXBException) JaxbHelper(org.platformlayer.xml.JaxbHelper)

Example 18 with JaxbHelper

use of org.platformlayer.xml.JaxbHelper in project platformlayer by platformlayer.

the class PlatformLayerTestContext method getItem.

public <T extends ItemBase> T getItem(String id, Class<T> itemClass) throws OpsException, IOException {
    TypedPlatformLayerClient client = getTypedClient();
    JaxbHelper jaxbHelper = PlatformLayerClientBase.toJaxbHelper(itemClass, new Class[] {});
    PlatformLayerKey key = PlatformLayerClientBase.toKey(jaxbHelper, new ManagedItemId(id), itemClass, client.listServices(true));
    return client.getItem(key, itemClass);
}
Also used : TypedPlatformLayerClient(org.platformlayer.TypedPlatformLayerClient) JaxbHelper(org.platformlayer.xml.JaxbHelper) PlatformLayerKey(org.platformlayer.core.model.PlatformLayerKey) ManagedItemId(org.platformlayer.ids.ManagedItemId)

Example 19 with JaxbHelper

use of org.platformlayer.xml.JaxbHelper in project platformlayer by platformlayer.

the class OpenstackBackupContext method writeDescriptor.

@Override
public void writeDescriptor() throws OpsException {
    String path = getBackupId() + ".backup.xml";
    JaxbHelper jaxb = JaxbHelper.get(BackupData.class);
    String xml;
    try {
        xml = jaxb.marshal(data, true);
    } catch (JAXBException e) {
        throw new OpsException("Error serializing metadata", e);
    }
    byte[] data = Utf8.getBytes(xml);
    try {
        getStorageClient().putObject(containerName, path, data);
    } catch (OpenstackException e) {
        throw new OpsException("Error uploading metadata", e);
    } catch (IOException e) {
        throw new OpsException("Error uploading metadata", e);
    }
}
Also used : OpsException(org.platformlayer.ops.OpsException) JAXBException(javax.xml.bind.JAXBException) JaxbHelper(org.platformlayer.xml.JaxbHelper) IOException(java.io.IOException) OpenstackException(org.openstack.client.OpenstackException)

Aggregations

JaxbHelper (org.platformlayer.xml.JaxbHelper)19 JAXBException (javax.xml.bind.JAXBException)8 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)6 IOException (java.io.IOException)4 UnmarshalException (javax.xml.bind.UnmarshalException)3 UntypedItem (org.platformlayer.common.UntypedItem)3 OpsException (org.platformlayer.ops.OpsException)3 StringReader (java.io.StringReader)2 ItemBase (org.platformlayer.core.model.ItemBase)2 ItemType (org.platformlayer.ids.ItemType)2 ManagedItemId (org.platformlayer.ids.ManagedItemId)2 ServiceType (org.platformlayer.ids.ServiceType)2 ServiceProvider (org.platformlayer.xaas.services.ServiceProvider)2 Document (org.w3c.dom.Document)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 StringWriter (java.io.StringWriter)1 ConnectException (java.net.ConnectException)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 Consumes (javax.ws.rs.Consumes)1