use of javax.xml.bind.JAXBContext in project opennms by OpenNMS.
the class ValidatingMessageBodyReader method readFrom.
@Override
public T readFrom(final Class<T> clazz, final Type type, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, String> parameters, final InputStream stream) throws IOException, WebApplicationException {
LOG.debug("readFrom: {}/{}/{}", clazz.getSimpleName(), type, mediaType);
JAXBContext jaxbContext = null;
final ContextResolver<JAXBContext> resolver = providers.getContextResolver(JAXBContext.class, mediaType);
try {
if (resolver != null) {
jaxbContext = resolver.getContext(clazz);
}
if (jaxbContext == null) {
jaxbContext = JAXBContext.newInstance(clazz);
}
return JaxbUtils.unmarshal(clazz, new InputSource(stream), jaxbContext);
} catch (final JAXBException e) {
LOG.warn("An error occurred while unmarshaling a {} object", clazz.getSimpleName(), e);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of javax.xml.bind.JAXBContext in project ORCID-Source by ORCID.
the class JpaJaxbEducationAdapterTest method getEducation.
private Education getEducation(boolean full) throws JAXBException {
JAXBContext context = JAXBContext.newInstance(new Class[] { Education.class });
Unmarshaller unmarshaller = context.createUnmarshaller();
String name = "/record_2.0/samples/read_samples/education-2.0.xml";
if (full) {
name = "/record_2.0/samples/read_samples/education-full-2.0.xml";
}
InputStream inputStream = getClass().getResourceAsStream(name);
return (Education) unmarshaller.unmarshal(inputStream);
}
use of javax.xml.bind.JAXBContext in project ORCID-Source by ORCID.
the class TestXmlValidity method before.
@Before
public void before() throws JAXBException {
JAXBContext context = JAXBContext.newInstance(OrcidMessage.class);
unmarshaller = context.createUnmarshaller();
}
use of javax.xml.bind.JAXBContext in project ORCID-Source by ORCID.
the class ConvertVrc3ToVrc4Test method upgradeAddressesToVrc3Test.
@Test
public void upgradeAddressesToVrc3Test() throws JAXBException {
JAXBContext jaxbContext1 = JAXBContext.newInstance(Addresses.class);
JAXBContext jaxbContext2 = JAXBContext.newInstance(org.orcid.jaxb.model.record_rc4.Addresses.class);
Unmarshaller jaxbUnmarshaller = jaxbContext1.createUnmarshaller();
InputStream rc3Stream = ConvertVrc3ToVrc4Test.class.getClassLoader().getResourceAsStream("test-addresses-2.0_rc3.xml");
InputStream rc4Stream = ConvertVrc3ToVrc4Test.class.getClassLoader().getResourceAsStream("test-addresses-2.0_rc4.xml");
Addresses rc4Element = (Addresses) jaxbUnmarshaller.unmarshal(rc3Stream);
jaxbUnmarshaller = jaxbContext2.createUnmarshaller();
org.orcid.jaxb.model.record_rc4.Addresses rc4Element1 = (org.orcid.jaxb.model.record_rc4.Addresses) jaxbUnmarshaller.unmarshal(rc4Stream);
V2Convertible result = versionConverterV2_0_rc3ToV2_0_rc4.upgrade(new V2Convertible(rc4Element, "v2_rc3"));
org.orcid.jaxb.model.record_rc4.Addresses rc4Element2 = (org.orcid.jaxb.model.record_rc4.Addresses) result.getObjectToConvert();
assertEquals(rc4Element1, rc4Element2);
}
use of javax.xml.bind.JAXBContext in project ORCID-Source by ORCID.
the class ConvertVrc3ToVrc4Test method upgradePeerReviewsToVrc3Test.
@Test
public void upgradePeerReviewsToVrc3Test() throws JAXBException {
JAXBContext jaxbContext1 = JAXBContext.newInstance(PeerReviews.class);
JAXBContext jaxbContext2 = JAXBContext.newInstance(org.orcid.jaxb.model.record.summary_rc4.PeerReviews.class);
Unmarshaller jaxbUnmarshaller = jaxbContext1.createUnmarshaller();
InputStream rc3Stream = ConvertVrc3ToVrc4Test.class.getClassLoader().getResourceAsStream("test-peer-reviews-2.0_rc3.xml");
InputStream rc4Stream = ConvertVrc3ToVrc4Test.class.getClassLoader().getResourceAsStream("test-peer-reviews-2.0_rc4.xml");
PeerReviews rc4PeerReviews = (PeerReviews) jaxbUnmarshaller.unmarshal(rc3Stream);
jaxbUnmarshaller = jaxbContext2.createUnmarshaller();
org.orcid.jaxb.model.record.summary_rc4.PeerReviews rc4PeerReviews1 = (org.orcid.jaxb.model.record.summary_rc4.PeerReviews) jaxbUnmarshaller.unmarshal(rc4Stream);
V2Convertible result = versionConverterV2_0_rc3ToV2_0_rc4.upgrade(new V2Convertible(rc4PeerReviews, "v2_rc3"));
org.orcid.jaxb.model.record.summary_rc4.PeerReviews rc4PeerReviews2 = (org.orcid.jaxb.model.record.summary_rc4.PeerReviews) result.getObjectToConvert();
assertEquals(rc4PeerReviews1, rc4PeerReviews2);
}
Aggregations