本文整理匯總了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();
}
}