use of javax.xml.bind.JAXBContext in project midpoint by Evolveum.
the class DescriptorLoader method loadData.
public void loadData(MidPointApplication application) {
LOGGER.debug("Loading data from descriptor files.");
try (InputStream baseInput = application.getServletContext().getResourceAsStream(baseFileName);
InputStream customInput = application.getServletContext().getResourceAsStream(customFileName)) {
if (baseInput == null) {
LOGGER.error("Couldn't find " + baseFileName + " file, can't load application menu and other stuff.");
}
JAXBContext context = JAXBContext.newInstance(ObjectFactory.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
JAXBElement<DescriptorType> element = (JAXBElement) unmarshaller.unmarshal(baseInput);
DescriptorType descriptor = element.getValue();
LOGGER.debug("Loading menu bar from " + baseFileName + " .");
DescriptorType customDescriptor = null;
if (customInput != null) {
element = (JAXBElement) unmarshaller.unmarshal(customInput);
customDescriptor = element.getValue();
}
scanPackagesForPages(descriptor.getPackagesToScan(), application);
if (customDescriptor != null) {
scanPackagesForPages(customDescriptor.getPackagesToScan(), application);
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("loaded:\n{}", debugDump(1));
}
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't process application descriptor", ex);
}
}
use of javax.xml.bind.JAXBContext 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.JAXBContext in project midpoint by Evolveum.
the class AbstractTestForExchangeConnector method unmarshallResource.
protected static <T> T unmarshallResource(String path) throws JAXBException, FileNotFoundException {
JAXBContext jc = ModelClientUtil.instantiateJaxbContext();
Unmarshaller unmarshaller = jc.createUnmarshaller();
InputStream is = null;
JAXBElement<T> element = null;
try {
is = AbstractTestForExchangeConnector.class.getClassLoader().getResourceAsStream(path);
if (is == null) {
throw new FileNotFoundException("System resource " + path + " was not found");
}
element = (JAXBElement<T>) unmarshaller.unmarshal(is);
} finally {
if (is != null) {
IOUtils.closeQuietly(is);
}
}
if (element == null) {
return null;
}
return element.getValue();
}
use of javax.xml.bind.JAXBContext in project uPortal by Jasig.
the class GsaSearchTest method test.
@Test
public void test() throws JAXBException, IOException {
Resource resource = applicationContext.getResource("classpath:/org/apereo/portal/portlets/search/gsa/gsa1.xml");
JAXBContext jc = JAXBContext.newInstance(GsaResults.class);
Unmarshaller u = jc.createUnmarshaller();
GsaResults result = (GsaResults) u.unmarshal(resource.getInputStream());
assert result.getSpellingSuggestion().size() == 1;
}
use of javax.xml.bind.JAXBContext in project uPortal by Jasig.
the class GsaSearchTest method test2.
@Test
public void test2() throws JAXBException, IOException {
Resource resource = applicationContext.getResource("classpath:/org/apereo/portal/portlets/search/gsa/gsa2.xml");
JAXBContext jc = JAXBContext.newInstance(GsaResults.class);
Unmarshaller u = jc.createUnmarshaller();
GsaResults result = (GsaResults) u.unmarshal(resource.getInputStream());
assert result.getDirectoryLinks().size() == 2;
}
Aggregations