use of javax.xml.bind.Unmarshaller in project libresonic by Libresonic.
the class SonosService method getUsername.
private String getUsername() {
MessageContext messageContext = context.getMessageContext();
if (messageContext == null || !(messageContext instanceof WrappedMessageContext)) {
LOG.error("Message context is null or not an instance of WrappedMessageContext.");
return null;
}
Message message = ((WrappedMessageContext) messageContext).getWrappedMessage();
List<Header> headers = CastUtils.cast((List<?>) message.get(Header.HEADER_LIST));
if (headers != null) {
for (Header h : headers) {
Object o = h.getObject();
// Unwrap the node using JAXB
if (o instanceof Node) {
JAXBContext jaxbContext;
try {
// TODO: Check performance
jaxbContext = new JAXBDataBinding(Credentials.class).getContext();
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
o = unmarshaller.unmarshal((Node) o);
} catch (JAXBException e) {
// failed to get the credentials object from the headers
LOG.error("JAXB error trying to unwrap credentials", e);
}
}
if (o instanceof Credentials) {
Credentials c = (Credentials) o;
// Note: We're using the username as session ID.
String username = c.getSessionId();
if (username == null) {
LOG.debug("No session id in credentials object, get from login");
username = c.getLogin().getUsername();
}
return username;
} else {
LOG.error("No credentials object");
}
}
} else {
LOG.error("No headers found");
}
return null;
}
use of javax.xml.bind.Unmarshaller in project ORCID-Source by ORCID.
the class OrcidValidationJaxbContextResolver method getContext.
@Override
public Unmarshaller getContext(Class<?> type) {
try {
String apiVersion = getApiVersion();
String schemaFilenamePrefix = getSchemaFilenamePrefix(type, apiVersion);
Unmarshaller unmarshaller = getJAXBContext(apiVersion).createUnmarshaller();
// the controller
if (OrcidMessage.class.equals(type) || org.orcid.jaxb.model.record_rc3.WorkBulk.class.equals(type) || org.orcid.jaxb.model.record_rc4.WorkBulk.class.equals(type) || org.orcid.jaxb.model.record_v2.WorkBulk.class.equals(type)) {
return unmarshaller;
}
if (schemaFilenamePrefix != null) {
Schema schema = getSchema(schemaFilenamePrefix, apiVersion);
unmarshaller.setSchema(schema);
unmarshaller.setEventHandler(new OrcidValidationHandler());
}
return unmarshaller;
} catch (JAXBException e) {
throw new WebApplicationException(getResponse(e));
} catch (SAXException e) {
throw new WebApplicationException(getResponse(e));
}
}
use of javax.xml.bind.Unmarshaller in project ORCID-Source by ORCID.
the class JaxbOrcidMessageUtil method getPublicOrcidMessage.
public static OrcidMessage getPublicOrcidMessage() throws JAXBException {
JAXBContext context = JAXBContext.newInstance(PACKAGE);
Unmarshaller unmarshaller = context.createUnmarshaller();
return (OrcidMessage) unmarshaller.unmarshal(JaxbOrcidMessageUtil.class.getResourceAsStream(ORCID_PUBLIC_FULL_XML));
}
use of javax.xml.bind.Unmarshaller in project ORCID-Source by ORCID.
the class MemberV1Test method unmarshallFromPath.
public OrcidMessage unmarshallFromPath(String path) throws Exception {
try (Reader reader = new InputStreamReader(getClass().getResourceAsStream(path))) {
JAXBContext context = JAXBContext.newInstance(OrcidProfile.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
return (OrcidMessage) unmarshaller.unmarshal(reader);
} catch (Exception e) {
throw new RuntimeException("Error reading file from classpath", e);
}
}
use of javax.xml.bind.Unmarshaller in project ORCID-Source by ORCID.
the class NotificationsTest method unmarshall.
public NotificationPermission unmarshall(Reader reader) {
try {
JAXBContext context = JAXBContext.newInstance(NotificationPermission.class.getPackage().getName());
Unmarshaller unmarshaller = context.createUnmarshaller();
return (NotificationPermission) unmarshaller.unmarshal(reader);
} catch (JAXBException e) {
throw new RuntimeException("Unable to unmarshall orcid message" + e);
}
}
Aggregations