use of org.apache.camel.converter.jaxb.JaxbDataFormat in project camel by apache.
the class JaxbDataFormatAutoConfiguration method configureJaxbDataFormatFactory.
@Bean(name = "jaxb-dataformat-factory")
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(JaxbDataFormat.class)
public DataFormatFactory configureJaxbDataFormatFactory(final CamelContext camelContext, final JaxbDataFormatConfiguration configuration) {
return new DataFormatFactory() {
public DataFormat newInstance() {
JaxbDataFormat dataformat = new JaxbDataFormat();
if (CamelContextAware.class.isAssignableFrom(JaxbDataFormat.class)) {
CamelContextAware contextAware = CamelContextAware.class.cast(dataformat);
if (contextAware != null) {
contextAware.setCamelContext(camelContext);
}
}
try {
Map<String, Object> parameters = new HashMap<>();
IntrospectionSupport.getProperties(configuration, parameters, null, false);
IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), dataformat, parameters);
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
return dataformat;
}
};
}
use of org.apache.camel.converter.jaxb.JaxbDataFormat in project camel by apache.
the class JmsJaxbTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
errorHandler(deadLetterChannel("jms:queue:error").redeliveryDelay(0));
onException(InvalidOrderException.class).maximumRedeliveries(0).handled(true).to("jms:queue:invalid");
DataFormat jaxb = new JaxbDataFormat("org.apache.camel.itest.jms");
from("jms:queue:in").unmarshal(jaxb).choice().when().method(JmsJaxbTest.class, "isWine").to("jms:queue:wine").otherwise().throwException(new InvalidOrderException("We only like wine")).end();
from("jms:queue:wine").to("mock:wine");
from("jms:queue:error").to("mock:error");
from("jms:queue:invalid").to("mock:invalid");
}
};
}
use of org.apache.camel.converter.jaxb.JaxbDataFormat in project camel by apache.
the class RestSwaggerComponentTest method createRouteBuilder.
@Override
protected RoutesBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
final JAXBContext jaxbContext = JAXBContext.newInstance(Pet.class);
final JaxbDataFormat jaxb = new JaxbDataFormat(jaxbContext);
jaxb.setJaxbProviderProperties(Collections.singletonMap(Marshaller.JAXB_FORMATTED_OUTPUT, false));
from("direct:getPetById").to("petStore:getPetById").unmarshal(jaxb);
from("direct:addPet").marshal(jaxb).to("petStore:addPet").unmarshal(jaxb);
}
};
}
use of org.apache.camel.converter.jaxb.JaxbDataFormat in project camel by apache.
the class JaxbDataFormatMustBeJAXBElementTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
JaxbDataFormat jaxb = new JaxbDataFormat(JAXBContext.newInstance(Foo.class));
jaxb.setPrettyPrint(false);
jaxb.setMustBeJAXBElement(false);
from("direct:start").marshal(jaxb).to("log:xml", "mock:result");
JaxbDataFormat jaxb2 = new JaxbDataFormat(JAXBContext.newInstance(Foo.class));
jaxb2.setPrettyPrint(false);
jaxb2.setMustBeJAXBElement(true);
from("direct:start2").marshal(jaxb2).to("log:xml", "mock:result2");
}
};
}
use of org.apache.camel.converter.jaxb.JaxbDataFormat in project camel by apache.
the class CamelJaxbTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
JaxbDataFormat dataFormat = new JaxbDataFormat("org.apache.camel.foo.bar");
dataFormat.setSchemaLocation("person.xsd");
dataFormat.setIgnoreJAXBElement(false);
JaxbDataFormat filterEnabledFormat = new JaxbDataFormat("org.apache.camel.foo.bar");
filterEnabledFormat.setFilterNonXmlChars(true);
JaxbDataFormat customWriterFormat = new JaxbDataFormat("org.apache.camel.foo.bar");
customWriterFormat.setXmlStreamWriterWrapper(new TestXmlStreamWriter());
JaxbDataFormat customWriterAndFilterFormat = new JaxbDataFormat("org.apache.camel.foo.bar");
customWriterAndFilterFormat.setFilterNonXmlChars(true);
customWriterAndFilterFormat.setXmlStreamWriterWrapper(new TestXmlStreamWriter());
from("direct:getJAXBElementValue").unmarshal(new JaxbDataFormat("org.apache.camel.foo.bar")).to("mock:result");
from("direct:getJAXBElement").unmarshal(dataFormat).to("mock:result");
from("direct:unmarshalFilteringEnabled").unmarshal(filterEnabledFormat).to("mock:result");
from("direct:marshal").marshal(dataFormat).to("mock:result");
from("direct:marshalFilteringEnabled").marshal(filterEnabledFormat).to("mock:result");
from("direct:marshalCustomWriter").marshal(customWriterFormat).to("mock:result");
from("direct:marshalCustomWriterAndFiltering").marshal(customWriterAndFilterFormat).to("mock:result");
from("direct:unmarshall").unmarshal().jaxb(PersonType.class.getPackage().getName()).to("mock:result");
}
};
}
Aggregations