本文整理汇总了Java中org.apache.camel.dataformat.xmljson.XmlJsonDataFormat类的典型用法代码示例。如果您正苦于以下问题:Java XmlJsonDataFormat类的具体用法?Java XmlJsonDataFormat怎么用?Java XmlJsonDataFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XmlJsonDataFormat类属于org.apache.camel.dataformat.xmljson包,在下文中一共展示了XmlJsonDataFormat类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureXmlJsonDataFormat
import org.apache.camel.dataformat.xmljson.XmlJsonDataFormat; //导入依赖的package包/类
@Bean
@ConditionalOnClass(CamelContext.class)
@ConditionalOnMissingBean(XmlJsonDataFormat.class)
public XmlJsonDataFormat configureXmlJsonDataFormat(
CamelContext camelContext,
XmlJsonDataFormatConfiguration configuration) throws Exception {
XmlJsonDataFormat dataformat = new XmlJsonDataFormat();
if (dataformat instanceof CamelContextAware) {
((CamelContextAware) dataformat).setCamelContext(camelContext);
}
Map<String, Object> parameters = new HashMap<>();
IntrospectionSupport.getProperties(configuration, parameters, null,
false);
IntrospectionSupport.setProperties(camelContext,
camelContext.getTypeConverter(), dataformat, parameters);
return dataformat;
}
示例2: configure
import org.apache.camel.dataformat.xmljson.XmlJsonDataFormat; //导入依赖的package包/类
@Override
public void configure() throws Exception {
from("direct:marshal")
.marshal().xmljson()
.to("mock:marshalResult");
from("direct:unmarshal")
.unmarshal().xmljson()
.to("mock:unmarshalResult");
XmlJsonDataFormat xmlJsonFormat = new XmlJsonDataFormat();
xmlJsonFormat.setRootName("bookstore");
xmlJsonFormat.setElementName("book");
xmlJsonFormat.setExpandableProperties(Arrays.asList("author", "author"));
from("direct:unmarshalBookstore")
.unmarshal(xmlJsonFormat)
.to("mock:unmarshalBookstoreResult");
}
示例3: configure
import org.apache.camel.dataformat.xmljson.XmlJsonDataFormat; //导入依赖的package包/类
@Override
public void configure() throws Exception {
final DataFormat bindy = new BindyCsvDataFormat(org.camelcookbook.transformation.csv.model.BookModel.class);
final DataFormat jaxb = new JaxbDataFormat("org.camelcookbook.transformation.myschema");
final XmlJsonDataFormat xmlJsonFormat = new XmlJsonDataFormat();
xmlJsonFormat.setRootName("bookstore");
xmlJsonFormat.setElementName("book");
xmlJsonFormat.setExpandableProperties(Arrays.asList("author", "author"));
from("direct:start")
.choice()
.when(header(Exchange.FILE_NAME).endsWith(".csv"))
.unmarshal(bindy)
.bean(MyNormalizer.class, "bookModelToJaxb")
.to("mock:csv")
.when(header(Exchange.FILE_NAME).endsWith(".json"))
.unmarshal(xmlJsonFormat)
.to("mock:json")
.when(header(Exchange.FILE_NAME).endsWith(".xml"))
.unmarshal(jaxb)
.to("mock:xml")
.otherwise()
.to("mock:unknown")
.stop()
.end()
.to("mock:normalized");
}
示例4: testMarshalAndUnmarshal
import org.apache.camel.dataformat.xmljson.XmlJsonDataFormat; //导入依赖的package包/类
@Test
public void testMarshalAndUnmarshal() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
XmlJsonDataFormat format = new XmlJsonDataFormat();
from("direct:marshal").marshal(format).to("mock:json");
from("direct:unmarshal").unmarshal(format).to("mock:xml");
}
});
camelctx.start();
try {
MockEndpoint mockJSON = camelctx.getEndpoint("mock:json", MockEndpoint.class);
mockJSON.expectedMessageCount(1);
mockJSON.expectedHeaderReceived(Exchange.CONTENT_TYPE, "application/json");
mockJSON.message(0).body().isInstanceOf(byte[].class);
MockEndpoint mockXML = camelctx.getEndpoint("mock:xml", MockEndpoint.class);
mockXML.expectedMessageCount(1);
mockXML.expectedHeaderReceived(Exchange.CONTENT_TYPE, "application/xml");
mockXML.message(0).body().isInstanceOf(String.class);
InputStream inStream = getClass().getResourceAsStream("/xmljson/testMessage1.xml");
String in = camelctx.getTypeConverter().convertTo(String.class, inStream);
ProducerTemplate template = camelctx.createProducerTemplate();
Object json = template.requestBody("direct:marshal", in);
String jsonString = camelctx.getTypeConverter().convertTo(String.class, json);
String expString = "{'a':'1','b':'2','c':{'a':'c.a.1','b':'c.b.2'},'d':['a','b','c'],'e':['1','2','3'],'f':'true','g':[]}";
Assert.assertEquals(expString, jsonString.replace('"', '\''));
template.sendBody("direct:unmarshal", jsonString);
mockJSON.assertIsSatisfied();
mockXML.assertIsSatisfied();
} finally {
camelctx.stop();
}
}