Search in sources :

Example 51 with JAXBException

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);
}
Also used : JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) JAXBException(javax.xml.bind.JAXBException) JAXBElement(javax.xml.bind.JAXBElement) Document(org.w3c.dom.Document)

Example 52 with JAXBException

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);
        }
    }
}
Also used : SystemException(com.evolveum.midpoint.util.exception.SystemException) JAXBException(javax.xml.bind.JAXBException)

Example 53 with JAXBException

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;
}
Also used : JAXBException(javax.xml.bind.JAXBException) ScriptingExpressionType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ScriptingExpressionType) ExecuteScriptsResponseType(com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteScriptsResponseType) PrismObject(com.evolveum.midpoint.prism.PrismObject) PipelineDataType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.PipelineDataType)

Example 54 with JAXBException

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;
}
Also used : Message(org.apache.cxf.message.Message) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) Header(org.apache.cxf.headers.Header) WrappedMessageContext(org.apache.cxf.jaxws.context.WrappedMessageContext) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) MessageContext(javax.xml.ws.handler.MessageContext) WrappedMessageContext(org.apache.cxf.jaxws.context.WrappedMessageContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 55 with JAXBException

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));
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) WebApplicationException(javax.ws.rs.WebApplicationException) JAXBException(javax.xml.bind.JAXBException)

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