Search in sources :

Example 1 with JAXBException

use of javax.xml.bind.JAXBException in project camel by apache.

the class CxfMessageHeadersRelayTest method validateReturnedOutOfBandHeaderWithInsertion.

protected static void validateReturnedOutOfBandHeaderWithInsertion(Map<String, Object> responseContext, boolean expect) {
    List<OutofBandHeader> hdrToTest = new ArrayList<OutofBandHeader>();
    List<Header> oobHdr = CastUtils.cast((List<?>) responseContext.get(Header.HEADER_LIST));
    if (!expect) {
        if (oobHdr == null || (oobHdr != null && oobHdr.size() == 0)) {
            return;
        }
        fail("Should have got *no* out-of-band headers, but some were found");
    }
    if (oobHdr == null) {
        fail("Should have got List of out-of-band headers");
    }
    assertTrue("HeaderHolder list expected to conain 2 object received " + oobHdr.size(), oobHdr.size() == 2);
    for (Header hdr1 : oobHdr) {
        if (hdr1.getObject() instanceof Node) {
            try {
                JAXBElement<?> job = (JAXBElement<?>) JAXBContext.newInstance(org.apache.cxf.outofband.header.ObjectFactory.class).createUnmarshaller().unmarshal((Node) hdr1.getObject());
                hdrToTest.add((OutofBandHeader) job.getValue());
            } catch (JAXBException ex) {
                ex.printStackTrace();
            }
        }
    }
    assertTrue("out-of-band header should not be null", hdrToTest.size() > 0);
    assertTrue("Expected out-of-band Header name testOobReturnHeaderName recevied :" + hdrToTest.get(0).getName(), "testOobReturnHeaderName".equals(hdrToTest.get(0).getName()));
    assertTrue("Expected out-of-band Header value testOobReturnHeaderValue recevied :" + hdrToTest.get(0).getValue(), "testOobReturnHeaderValue".equals(hdrToTest.get(0).getValue()));
    assertTrue("Expected out-of-band Header attribute testReturnHdrAttribute recevied :" + hdrToTest.get(0).getHdrAttribute(), "testReturnHdrAttribute".equals(hdrToTest.get(0).getHdrAttribute()));
    assertTrue("Expected out-of-band Header name New_testOobHeader recevied :" + hdrToTest.get(1).getName(), "New_testOobHeader".equals(hdrToTest.get(1).getName()));
    assertTrue("Expected out-of-band Header value New_testOobHeaderValue recevied :" + hdrToTest.get(1).getValue(), "New_testOobHeaderValue".equals(hdrToTest.get(1).getValue()));
    assertTrue("Expected out-of-band Header attribute testHdrAttribute recevied :" + hdrToTest.get(1).getHdrAttribute(), "testHdrAttribute".equals(hdrToTest.get(1).getHdrAttribute()));
}
Also used : SoapHeader(org.apache.cxf.binding.soap.SoapHeader) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) Header(org.apache.cxf.headers.Header) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) JAXBElement(javax.xml.bind.JAXBElement)

Example 2 with JAXBException

use of javax.xml.bind.JAXBException in project camel by apache.

the class HeaderTesterWithInsertionImpl method verifyHeader.

private void verifyHeader(Object hdr, String headerName, String headerValue) {
    if (hdr instanceof Header && ((Header) hdr).getObject() instanceof Node) {
        Header hdr1 = (Header) hdr;
        try {
            JAXBElement<?> job = (JAXBElement<?>) JAXBContext.newInstance(org.apache.cxf.outofband.header.ObjectFactory.class).createUnmarshaller().unmarshal((Node) hdr1.getObject());
            OutofBandHeader ob = (OutofBandHeader) job.getValue();
            if (!headerName.equals(ob.getName())) {
                throw new RuntimeException("test failed expected name ' + headerName + ' but found '" + ob.getName() + "'");
            }
            if (!headerValue.equals(ob.getValue())) {
                throw new RuntimeException("test failed expected name ' + headerValue + ' but found '" + ob.getValue() + "'");
            }
        } catch (JAXBException ex) {
            throw new RuntimeException("test failed", ex);
        }
    } else {
        throw new RuntimeException("test failed. Unexpected type " + hdr.getClass());
    }
}
Also used : OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) Header(org.apache.cxf.headers.Header) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) JAXBElement(javax.xml.bind.JAXBElement)

Example 3 with JAXBException

use of javax.xml.bind.JAXBException in project camel by apache.

the class CamelNamespaceHandler method parseSecureRandomParametersNode.

private Metadata parseSecureRandomParametersNode(Element element, ParserContext context) {
    LOG.trace("Parsing SecureRandomParameters {}", element);
    // now parse the key store parameters with JAXB
    Binder<Node> binder;
    try {
        binder = getJaxbContext().createBinder();
    } catch (JAXBException e) {
        throw new ComponentDefinitionException("Failed to create the JAXB binder : " + e, e);
    }
    Object value = parseUsingJaxb(element, context, binder);
    if (!(value instanceof SecureRandomParametersFactoryBean)) {
        throw new ComponentDefinitionException("Expected an instance of " + SecureRandomParametersFactoryBean.class);
    }
    SecureRandomParametersFactoryBean srfb = (SecureRandomParametersFactoryBean) value;
    String id = srfb.getId();
    MutablePassThroughMetadata factory = context.createMetadata(MutablePassThroughMetadata.class);
    factory.setId(".camelBlueprint.passThrough." + id);
    factory.setObject(new PassThroughCallable<Object>(srfb));
    MutableBeanMetadata factory2 = context.createMetadata(MutableBeanMetadata.class);
    factory2.setId(".camelBlueprint.factory." + id);
    factory2.setFactoryComponent(factory);
    factory2.setFactoryMethod("call");
    factory2.setInitMethod("afterPropertiesSet");
    factory2.setDestroyMethod("destroy");
    factory2.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
    MutableBeanMetadata ctx = context.createMetadata(MutableBeanMetadata.class);
    ctx.setId(id);
    ctx.setRuntimeClass(SecureRandomParameters.class);
    ctx.setFactoryComponent(factory2);
    ctx.setFactoryMethod("getObject");
    // must be lazy as we want CamelContext to be activated first
    ctx.setActivation(ACTIVATION_LAZY);
    LOG.trace("Parsing SecureRandomParameters done, returning {}", ctx);
    return ctx;
}
Also used : MutablePassThroughMetadata(org.apache.aries.blueprint.mutable.MutablePassThroughMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) ExpressionNode(org.apache.camel.model.ExpressionNode) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) SecureRandomParametersFactoryBean(org.apache.camel.util.blueprint.SecureRandomParametersFactoryBean)

Example 4 with JAXBException

use of javax.xml.bind.JAXBException in project camel by apache.

the class CamelNamespaceHandler method parseSSLContextParametersNode.

private Metadata parseSSLContextParametersNode(Element element, ParserContext context) {
    LOG.trace("Parsing SSLContextParameters {}", element);
    // now parse the key store parameters with JAXB
    Binder<Node> binder;
    try {
        binder = getJaxbContext().createBinder();
    } catch (JAXBException e) {
        throw new ComponentDefinitionException("Failed to create the JAXB binder : " + e, e);
    }
    Object value = parseUsingJaxb(element, context, binder);
    if (!(value instanceof SSLContextParametersFactoryBean)) {
        throw new ComponentDefinitionException("Expected an instance of " + SSLContextParametersFactoryBean.class);
    }
    SSLContextParametersFactoryBean scpfb = (SSLContextParametersFactoryBean) value;
    String id = scpfb.getId();
    MutablePassThroughMetadata factory = context.createMetadata(MutablePassThroughMetadata.class);
    factory.setId(".camelBlueprint.passThrough." + id);
    factory.setObject(new PassThroughCallable<Object>(scpfb));
    MutableBeanMetadata factory2 = context.createMetadata(MutableBeanMetadata.class);
    factory2.setId(".camelBlueprint.factory." + id);
    factory2.setFactoryComponent(factory);
    factory2.setFactoryMethod("call");
    factory2.setInitMethod("afterPropertiesSet");
    factory2.setDestroyMethod("destroy");
    factory2.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
    MutableBeanMetadata ctx = context.createMetadata(MutableBeanMetadata.class);
    ctx.setId(id);
    ctx.setRuntimeClass(SSLContextParameters.class);
    ctx.setFactoryComponent(factory2);
    ctx.setFactoryMethod("getObject");
    // must be lazy as we want CamelContext to be activated first
    ctx.setActivation(ACTIVATION_LAZY);
    LOG.trace("Parsing SSLContextParameters done, returning {}", ctx);
    return ctx;
}
Also used : MutablePassThroughMetadata(org.apache.aries.blueprint.mutable.MutablePassThroughMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) ExpressionNode(org.apache.camel.model.ExpressionNode) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) SSLContextParametersFactoryBean(org.apache.camel.util.blueprint.SSLContextParametersFactoryBean)

Example 5 with JAXBException

use of javax.xml.bind.JAXBException in project camel by apache.

the class CamelNamespaceHandler method parseEndpointNode.

private Metadata parseEndpointNode(Element element, ParserContext context) {
    LOG.trace("Parsing Endpoint {}", element);
    // now parse the rests with JAXB
    Binder<Node> binder;
    try {
        binder = getJaxbContext().createBinder();
    } catch (JAXBException e) {
        throw new ComponentDefinitionException("Failed to create the JAXB binder : " + e, e);
    }
    Object value = parseUsingJaxb(element, context, binder);
    if (!(value instanceof CamelEndpointFactoryBean)) {
        throw new ComponentDefinitionException("Expected an instance of " + CamelEndpointFactoryBean.class);
    }
    CamelEndpointFactoryBean rcfb = (CamelEndpointFactoryBean) value;
    String id = rcfb.getId();
    MutablePassThroughMetadata factory = context.createMetadata(MutablePassThroughMetadata.class);
    factory.setId(".camelBlueprint.passThrough." + id);
    factory.setObject(new PassThroughCallable<Object>(rcfb));
    MutableBeanMetadata factory2 = context.createMetadata(MutableBeanMetadata.class);
    factory2.setId(".camelBlueprint.factory." + id);
    factory2.setFactoryComponent(factory);
    factory2.setFactoryMethod("call");
    factory2.setInitMethod("afterPropertiesSet");
    factory2.setDestroyMethod("destroy");
    factory2.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
    MutableBeanMetadata ctx = context.createMetadata(MutableBeanMetadata.class);
    ctx.setId(id);
    ctx.setRuntimeClass(Endpoint.class);
    ctx.setFactoryComponent(factory2);
    ctx.setFactoryMethod("getObject");
    // must be lazy as we want CamelContext to be activated first
    ctx.setActivation(ACTIVATION_LAZY);
    LOG.trace("Parsing endpoint done, returning {}", element, ctx);
    return ctx;
}
Also used : MutablePassThroughMetadata(org.apache.aries.blueprint.mutable.MutablePassThroughMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) ExpressionNode(org.apache.camel.model.ExpressionNode) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) CamelEndpointFactoryBean(org.apache.camel.blueprint.CamelEndpointFactoryBean)

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