use of javax.xml.bind.JAXBException in project midpoint by Evolveum.
the class JaxbTestUtil method compareElement.
@SuppressWarnings("unchecked")
private boolean compareElement(Object a, Object b) {
if (a == b) {
return true;
}
if (a == null && b == null) {
return true;
}
if (a == null || b == null) {
return false;
}
Document doc = null;
Element ae = null;
Element be = null;
if (a instanceof Element) {
ae = (Element) a;
} else if (a instanceof JAXBElement) {
if (doc == null) {
doc = DOMUtil.getDocument();
}
try {
ae = marshalElementToDom((JAXBElement) a, doc);
} catch (JAXBException e) {
throw new IllegalStateException("Failed to marshall element " + a, e);
}
} else {
throw new IllegalArgumentException("Got unexpected type " + a.getClass().getName() + ": " + a);
}
if (b instanceof Element) {
be = (Element) b;
} else if (a instanceof JAXBElement) {
if (doc == null) {
doc = DOMUtil.getDocument();
}
try {
be = marshalElementToDom((JAXBElement) a, doc);
} catch (JAXBException e) {
throw new IllegalStateException("Failed to marshall element " + b, e);
}
} else {
throw new IllegalArgumentException("Got unexpected type " + b.getClass().getName() + ": " + b);
}
return DOMUtil.compareElement(ae, be, true);
}
use of javax.xml.bind.JAXBException in project midpoint by Evolveum.
the class JaxbTestUtil method initialize.
public void initialize() {
StringBuilder sb = new StringBuilder();
Iterator<Package> iterator = getSchemaRegistry().getCompileTimePackages().iterator();
while (iterator.hasNext()) {
Package jaxbPackage = iterator.next();
sb.append(jaxbPackage.getName());
if (iterator.hasNext()) {
sb.append(":");
}
}
String jaxbPaths = sb.toString();
if (jaxbPaths.isEmpty()) {
LOGGER.debug("No JAXB paths, skipping creation of JAXB context");
} else {
try {
context = JAXBContext.newInstance(jaxbPaths);
} catch (JAXBException ex) {
throw new SystemException("Couldn't create JAXBContext for: " + jaxbPaths, ex);
}
}
}
use of javax.xml.bind.JAXBException in project midpoint by Evolveum.
the class ModelWebService method doExecuteScripts.
private ExecuteScriptsResponseType doExecuteScripts(List<JAXBElement<?>> scriptsToExecute, ExecuteScriptsOptionsType options, Task task, OperationResult result) {
ExecuteScriptsResponseType response = new ExecuteScriptsResponseType();
ScriptOutputsType outputs = new ScriptOutputsType();
response.setOutputs(outputs);
try {
for (JAXBElement<?> script : scriptsToExecute) {
Object scriptValue = script.getValue();
if (!(scriptValue instanceof ScriptingExpressionType)) {
throw new SchemaException("Expected that scripts will be of type ScriptingExpressionType, but it was " + scriptValue.getClass().getName());
}
ScriptExecutionResult executionResult = scriptingService.evaluateExpression((ScriptingExpressionType) script.getValue(), task, result);
SingleScriptOutputType output = new SingleScriptOutputType();
outputs.getOutput().add(output);
output.setTextOutput(executionResult.getConsoleOutput());
if (options == null || options.getOutputFormat() == null || options.getOutputFormat() == OutputFormatType.XML) {
output.setDataOutput(prepareXmlData(executionResult.getDataOutput(), null));
} else {
// temporarily we send serialized XML in the case of MSL output
PipelineDataType jaxbOutput = prepareXmlData(executionResult.getDataOutput(), null);
output.setMslData(prismContext.xmlSerializer().serializeAnyData(jaxbOutput, SchemaConstants.C_VALUE));
}
}
result.computeStatusIfUnknown();
} catch (ScriptExecutionException | JAXBException | SchemaException | RuntimeException | SecurityViolationException e) {
result.recordFatalError(e.getMessage(), e);
LoggingUtils.logException(LOGGER, "Exception while executing script", e);
}
result.summarize();
response.setResult(result.createOperationResultType());
return response;
}
use of javax.xml.bind.JAXBException 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.JAXBException in project ORCID-Source by ORCID.
the class OrcidMarshallerContextResolver method getContext.
@Override
public Marshaller getContext(Class<?> type) {
try {
context = JAXBContext.newInstance(type);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
return new OrcidMarshallerWrapper(marshaller);
} catch (JAXBException e) {
logger.error("Cannot create new marshaller", e);
throw new WebApplicationException(getResponse(e));
}
}
Aggregations