Search in sources :

Example 61 with JAXBException

use of javax.xml.bind.JAXBException in project ORCID-Source by ORCID.

the class OrcidClientGroup method unmarshall.

public static OrcidClientGroup unmarshall(InputStream input) {
    try {
        JAXBContext context = JAXBContext.newInstance(OrcidClientGroup.class.getPackage().getName());
        Unmarshaller unmarshaller = context.createUnmarshaller();
        return (OrcidClientGroup) unmarshaller.unmarshal(input);
    } catch (JAXBException e) {
        // XXX Should be more specific exception
        throw new RuntimeException("Unable to unmarshall client group" + e);
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 62 with JAXBException

use of javax.xml.bind.JAXBException in project ORCID-Source by ORCID.

the class RecordUtil method convertToString.

/**
     * @param args
     */
public static String convertToString(Object obj) {
    try {
        JAXBContext context = JAXBContext.newInstance(obj.getClass());
        StringWriter writer = new StringWriter();
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(obj, writer);
        return writer.toString();
    } catch (JAXBException e) {
        return ("Unable to unmarshal because: " + e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext)

Example 63 with JAXBException

use of javax.xml.bind.JAXBException in project ORCID-Source by ORCID.

the class OrcidMessage method unmarshall.

public static OrcidMessage unmarshall(Reader reader) {
    try {
        JAXBContext context = JAXBContext.newInstance(OrcidMessage.class.getPackage().getName());
        Unmarshaller unmarshaller = context.createUnmarshaller();
        return (OrcidMessage) unmarshaller.unmarshal(reader);
    } catch (JAXBException e) {
        // XXX Should be more specific exception
        throw new RuntimeException("Unable to unmarshall orcid message" + e);
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 64 with JAXBException

use of javax.xml.bind.JAXBException in project ORCID-Source by ORCID.

the class S3MessageProcessor method update_1_2_API.

private void update_1_2_API(String orcid) {
    if (is12IndexingEnabled) {
        try {
            OrcidMessage profile = orcid12ApiClient.fetchPublicProfile(orcid);
            // Update API 1.2
            if (profile != null) {
                s3Updater.updateS3(orcid, profile);
                recordStatusManager.markAsSent(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
            }
        } catch (LockedRecordException | DeprecatedRecordException e) {
            try {
                if (e instanceof LockedRecordException) {
                    LOG.error("Record " + orcid + " is locked");
                    exceptionHandler.handle12LockedRecordException(orcid, ((LockedRecordException) e).getOrcidMessage());
                } else {
                    LOG.error("Record " + orcid + " is deprecated");
                    exceptionHandler.handle12DeprecatedRecordException(orcid, ((DeprecatedRecordException) e).getOrcidDeprecated());
                }
                recordStatusManager.markAsSent(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
            } catch (JsonProcessingException | AmazonClientException | JAXBException e1) {
                LOG.error("Unable to handle LockedRecordException for record " + orcid, e1);
                recordStatusManager.markAsFailed(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
            }
        } catch (Exception e) {
            // something else went wrong fetching record from ORCID and
            // threw a
            // runtime exception
            LOG.error("Unable to fetch record " + orcid + " for 1.2 API");
            LOG.error(e.getMessage(), e);
            recordStatusManager.markAsFailed(orcid, AvailableBroker.DUMP_STATUS_1_2_API);
        }
    }
}
Also used : LockedRecordException(org.orcid.listener.exception.LockedRecordException) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) LockedRecordException(org.orcid.listener.exception.LockedRecordException) DeprecatedRecordException(org.orcid.listener.exception.DeprecatedRecordException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JAXBException(javax.xml.bind.JAXBException) AmazonClientException(com.amazonaws.AmazonClientException)

Example 65 with JAXBException

use of javax.xml.bind.JAXBException in project ORCID-Source by ORCID.

the class ValidateV2_1SamplesTest method unmarshall.

private Object unmarshall(Reader reader, Class<?> type, String schemaPath) throws SAXException, URISyntaxException {
    try {
        JAXBContext context = JAXBContext.newInstance(type);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        if (schemaPath != null) {
            SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            Schema schema = sf.newSchema(new File(getClass().getResource(schemaPath).toURI()));
            unmarshaller.setSchema(schema);
        }
        return unmarshaller.unmarshal(reader);
    } catch (JAXBException e) {
        throw new RuntimeException("Unable to unmarshall orcid message" + e);
    }
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) Schema(javax.xml.validation.Schema) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File)

Aggregations

JAXBException (javax.xml.bind.JAXBException)402 JAXBContext (javax.xml.bind.JAXBContext)126 IOException (java.io.IOException)93 Unmarshaller (javax.xml.bind.Unmarshaller)91 Marshaller (javax.xml.bind.Marshaller)69 ArrayList (java.util.ArrayList)38 StringWriter (java.io.StringWriter)35 List (java.util.List)35 Map (java.util.Map)33 SAXException (org.xml.sax.SAXException)32 File (java.io.File)29 InputStream (java.io.InputStream)29 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)28 HashSet (java.util.HashSet)28 JAXBElement (javax.xml.bind.JAXBElement)24 XMLStreamException (javax.xml.stream.XMLStreamException)23 SAML2MetaException (com.sun.identity.saml2.meta.SAML2MetaException)22 StringReader (java.io.StringReader)21 HashMap (java.util.HashMap)21 SAML2MetaManager (com.sun.identity.saml2.meta.SAML2MetaManager)20