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()));
}
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());
}
}
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;
}
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;
}
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;
}
Aggregations