Search in sources :

Example 1 with ObjectFactory

use of org.xipki.ca.dbtool.jaxb.ca.ObjectFactory in project xipki by xipki.

the class CaConfigurationDbExporter method export.

public void export() throws Exception {
    CAConfigurationType caconf = new CAConfigurationType();
    caconf.setVersion(VERSION);
    System.out.println("exporting CA configuration from database");
    exportCmpcontrol(caconf);
    exportResponder(caconf);
    exportEnvironment(caconf);
    exportCrlsigner(caconf);
    exportRequestor(caconf);
    exportUser(caconf);
    exportPublisher(caconf);
    exportCa(caconf);
    exportProfile(caconf);
    exportCaalias(caconf);
    exportCaHasRequestor(caconf);
    exportCaHasUser(caconf);
    exportCaHasPublisher(caconf);
    exportCaHasProfile(caconf);
    exportScep(caconf);
    JAXBElement<CAConfigurationType> root = new ObjectFactory().createCAConfiguration(caconf);
    try {
        marshaller.marshal(root, new File(baseDir, FILENAME_CA_CONFIGURATION));
    } catch (JAXBException ex) {
        throw XmlUtil.convert(ex);
    }
    System.out.println(" exported CA configuration from database");
}
Also used : CAConfigurationType(org.xipki.ca.dbtool.jaxb.ca.CAConfigurationType) ObjectFactory(org.xipki.ca.dbtool.jaxb.ca.ObjectFactory) JAXBException(javax.xml.bind.JAXBException) File(java.io.File)

Example 2 with ObjectFactory

use of org.xipki.ca.dbtool.jaxb.ca.ObjectFactory in project xipki by xipki.

the class CaCertStoreDbExporter method export.

@SuppressWarnings("unchecked")
public void export() throws Exception {
    CertStoreType certstore;
    if (resume) {
        JAXBElement<CertStoreType> root;
        try {
            root = (JAXBElement<CertStoreType>) unmarshaller.unmarshal(new File(baseDir, FILENAME_CA_CERTSTORE));
        } catch (JAXBException ex) {
            throw XmlUtil.convert(ex);
        }
        certstore = root.getValue();
        if (certstore.getVersion() > VERSION) {
            throw new InvalidInputException("could not continue with CertStore greater than " + VERSION + ": " + certstore.getVersion());
        }
    } else {
        certstore = new CertStoreType();
        certstore.setVersion(VERSION);
    }
    Exception exception = null;
    System.out.println("exporting CA certstore from database");
    try {
        if (!resume) {
            exportPublishQueue(certstore);
            exportDeltaCrlCache(certstore);
        }
        File processLogFile = new File(baseDir, DbPorter.EXPORT_PROCESS_LOG_FILENAME);
        Long idProcessedInLastProcess = null;
        CaDbEntryType typeProcessedInLastProcess = null;
        if (processLogFile.exists()) {
            byte[] content = IoUtil.read(processLogFile);
            if (content != null && content.length > 0) {
                String str = new String(content);
                int idx = str.indexOf(':');
                String typeName = str.substring(0, idx).trim();
                typeProcessedInLastProcess = CaDbEntryType.valueOf(typeName);
                idProcessedInLastProcess = Long.parseLong(str.substring(idx + 1).trim());
            }
        }
        if (CaDbEntryType.CRL == typeProcessedInLastProcess || typeProcessedInLastProcess == null) {
            exception = exportEntries(CaDbEntryType.CRL, certstore, processLogFile, idProcessedInLastProcess);
            typeProcessedInLastProcess = null;
            idProcessedInLastProcess = null;
        }
        CaDbEntryType[] types = { CaDbEntryType.CERT, CaDbEntryType.REQUEST, CaDbEntryType.REQCERT };
        for (CaDbEntryType type : types) {
            if (exception == null && (type == typeProcessedInLastProcess || typeProcessedInLastProcess == null)) {
                exception = exportEntries(type, certstore, processLogFile, idProcessedInLastProcess);
                typeProcessedInLastProcess = null;
                idProcessedInLastProcess = null;
            }
        }
        JAXBElement<CertStoreType> root = new ObjectFactory().createCertStore(certstore);
        try {
            marshaller.marshal(root, new File(baseDir + File.separator + FILENAME_CA_CERTSTORE));
        } catch (JAXBException ex) {
            throw XmlUtil.convert(ex);
        }
    } catch (Exception ex) {
        System.err.println("could not export CA certstore from database");
        exception = ex;
    }
    if (exception == null) {
        System.out.println(" exported CA certstore from database");
    } else {
        throw exception;
    }
}
Also used : InvalidInputException(org.xipki.dbtool.InvalidInputException) JAXBException(javax.xml.bind.JAXBException) DEROctetString(org.bouncycastle.asn1.DEROctetString) XMLStreamException(javax.xml.stream.XMLStreamException) DataAccessException(org.xipki.datasource.DataAccessException) JAXBException(javax.xml.bind.JAXBException) CRLException(java.security.cert.CRLException) InvalidInputException(org.xipki.dbtool.InvalidInputException) SQLException(java.sql.SQLException) IOException(java.io.IOException) ObjectFactory(org.xipki.ca.dbtool.jaxb.ca.ObjectFactory) CertStoreType(org.xipki.ca.dbtool.jaxb.ca.CertStoreType) File(java.io.File)

Aggregations

File (java.io.File)2 JAXBException (javax.xml.bind.JAXBException)2 ObjectFactory (org.xipki.ca.dbtool.jaxb.ca.ObjectFactory)2 IOException (java.io.IOException)1 CRLException (java.security.cert.CRLException)1 SQLException (java.sql.SQLException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 DEROctetString (org.bouncycastle.asn1.DEROctetString)1 CAConfigurationType (org.xipki.ca.dbtool.jaxb.ca.CAConfigurationType)1 CertStoreType (org.xipki.ca.dbtool.jaxb.ca.CertStoreType)1 DataAccessException (org.xipki.datasource.DataAccessException)1 InvalidInputException (org.xipki.dbtool.InvalidInputException)1