use of org.apache.camel.spi.DataFormat in project camel by apache.
the class OsgiDataFormatResolverTest method testOsgiResolverFindDataFormatFallbackTest.
@Test
public void testOsgiResolverFindDataFormatFallbackTest() throws Exception {
SimpleRegistry registry = new SimpleRegistry();
registry.put("allstar-dataformat", new SampleDataFormat(true));
CamelContext camelContext = new DefaultCamelContext(registry);
OsgiDataFormatResolver resolver = new OsgiDataFormatResolver(getBundleContext());
DataFormat dataformat = resolver.resolveDataFormat("allstar", camelContext);
assertNotNull("We should find the super dataformat", dataformat);
assertTrue("We should get the super dataformat here", dataformat instanceof SampleDataFormat);
}
use of org.apache.camel.spi.DataFormat in project camel by apache.
the class OsgiDataFormatResolverTest method testOsgiResolverFindLanguageDoubleFallbackTest.
@Test
public void testOsgiResolverFindLanguageDoubleFallbackTest() throws Exception {
SimpleRegistry registry = new SimpleRegistry();
registry.put("allstar", new SampleDataFormat(false));
registry.put("allstar-dataformat", new SampleDataFormat(true));
CamelContext camelContext = new DefaultCamelContext(registry);
OsgiDataFormatResolver resolver = new OsgiDataFormatResolver(getBundleContext());
DataFormat dataformat = resolver.resolveDataFormat("allstar", camelContext);
assertNotNull("We should find the super dataformat", dataformat);
assertTrue("We should get the super dataformat here", dataformat instanceof SampleDataFormat);
assertFalse("We should NOT find the fallback dataformat", ((SampleDataFormat) dataformat).isFallback());
}
use of org.apache.camel.spi.DataFormat in project camel by apache.
the class DozerProducer method resolveMarshaller.
/**
* Find and configure an unmarshaller for the specified data format.
*/
private synchronized MarshalProcessor resolveMarshaller(Exchange exchange, String dataFormatId) throws Exception {
if (marshaller == null) {
DataFormat dataFormat = DataFormatDefinition.getDataFormat(exchange.getUnitOfWork().getRouteContext(), null, dataFormatId);
if (dataFormat == null) {
throw new Exception("Unable to resolve data format for marshalling: " + dataFormatId);
}
// Wrap the data format in a processor and start/configure it.
// Stop/shutdown is handled when the corresponding methods are
// called on this producer.
marshaller = new MarshalProcessor(dataFormat);
marshaller.setCamelContext(exchange.getContext());
marshaller.start();
}
return marshaller;
}
use of org.apache.camel.spi.DataFormat in project camel by apache.
the class DozerProducer method resolveUnmarshaller.
/**
* Find and configure an unmarshaller for the specified data format.
*/
private synchronized UnmarshalProcessor resolveUnmarshaller(Exchange exchange, String dataFormatId) throws Exception {
if (unmarshaller == null) {
DataFormat dataFormat = DataFormatDefinition.getDataFormat(exchange.getUnitOfWork().getRouteContext(), null, dataFormatId);
if (dataFormat == null) {
throw new Exception("Unable to resolve data format for unmarshalling: " + dataFormatId);
}
// Wrap the data format in a processor and start/configure it.
// Stop/shutdown is handled when the corresponding methods are
// called on this producer.
unmarshaller = new UnmarshalProcessor(dataFormat);
unmarshaller.setCamelContext(exchange.getContext());
unmarshaller.start();
}
return unmarshaller;
}
use of org.apache.camel.spi.DataFormat in project camel by apache.
the class DataFormatComponent method createEndpoint.
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
String name = ObjectHelper.before(remaining, ":");
// try to lookup data format in the registry or create it from resource
DataFormat df = getCamelContext().resolveDataFormat(name);
if (df == null) {
// if not, try to find a factory in the registry
df = getCamelContext().createDataFormat(name);
}
if (df == null) {
throw new IllegalArgumentException("Cannot find data format with name: " + name);
}
String operation = ObjectHelper.after(remaining, ":");
if (!"marshal".equals(operation) && !"unmarshal".equals(operation)) {
throw new IllegalArgumentException("Operation must be either marshal or unmarshal, was: " + operation);
}
// set reference properties first as they use # syntax that fools the regular properties setter
EndpointHelper.setReferenceProperties(getCamelContext(), df, parameters);
EndpointHelper.setProperties(getCamelContext(), df, parameters);
DataFormatEndpoint endpoint = new DataFormatEndpoint(uri, this, df);
endpoint.setOperation(operation);
setProperties(endpoint, parameters);
return endpoint;
}
Aggregations