use of org.apache.camel.spi.DataFormat in project camel by apache.
the class HL7ByteArrayRouteTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
// START SNIPPET: e1
DataFormat hl7 = new HL7DataFormat();
// we setup or HL7 listener on port 8888 (using the hl7codec) and in sync mode so we can return a response
from("mina2:tcp://127.0.0.1:" + getPort() + "?sync=true&codec=#hl7codec").unmarshal(hl7).choice().when(header("CamelHL7TriggerEvent").isEqualTo("A19")).bean("hl7service", "handleA19").to("mock:a19").when(header("CamelHL7TriggerEvent").isEqualTo("A01")).to("mock:a01").bean("hl7service", "handleA01").to("mock:a19").otherwise().to("mock:unknown").end().marshal(hl7);
// END SNIPPET: e1
}
};
}
use of org.apache.camel.spi.DataFormat in project camel by apache.
the class DataFormatDataSetTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
DataFormat jaxb = new JaxbDataFormat("org.apache.camel.example");
// use 5 concurrent threads to do marshalling
from("dataset:beer").marshal(jaxb).to("dataset:beer");
}
};
}
use of org.apache.camel.spi.DataFormat in project camel by apache.
the class DefaultManagementLifecycleStrategy method getManagedObjectForService.
@SuppressWarnings("unchecked")
private Object getManagedObjectForService(CamelContext context, Service service, Route route) {
// skip channel, UoW and dont double wrap instrumentation
if (service instanceof Channel || service instanceof UnitOfWork || service instanceof InstrumentationProcessor) {
return null;
}
// skip non managed services
if (service instanceof NonManagedService) {
return null;
}
Object answer = null;
if (service instanceof ManagementAware) {
return ((ManagementAware<Service>) service).getManagedObject(service);
} else if (service instanceof Tracer) {
// special for tracer
Tracer tracer = (Tracer) service;
ManagedTracer mt = managedTracers.get(tracer);
if (mt == null) {
mt = new ManagedTracer(context, tracer);
mt.init(getManagementStrategy());
managedTracers.put(tracer, mt);
}
return mt;
} else if (service instanceof BacklogTracer) {
// special for backlog tracer
BacklogTracer backlogTracer = (BacklogTracer) service;
ManagedBacklogTracer mt = managedBacklogTracers.get(backlogTracer);
if (mt == null) {
mt = new ManagedBacklogTracer(context, backlogTracer);
mt.init(getManagementStrategy());
managedBacklogTracers.put(backlogTracer, mt);
}
return mt;
} else if (service instanceof BacklogDebugger) {
// special for backlog debugger
BacklogDebugger backlogDebugger = (BacklogDebugger) service;
ManagedBacklogDebugger md = managedBacklogDebuggers.get(backlogDebugger);
if (md == null) {
md = new ManagedBacklogDebugger(context, backlogDebugger);
md.init(getManagementStrategy());
managedBacklogDebuggers.put(backlogDebugger, md);
}
return md;
} else if (service instanceof DataFormat) {
answer = getManagementObjectStrategy().getManagedObjectForDataFormat(context, (DataFormat) service);
} else if (service instanceof Producer) {
answer = getManagementObjectStrategy().getManagedObjectForProducer(context, (Producer) service);
} else if (service instanceof Consumer) {
answer = getManagementObjectStrategy().getManagedObjectForConsumer(context, (Consumer) service);
} else if (service instanceof Processor) {
// special for processors as we need to do some extra work
return getManagedObjectForProcessor(context, (Processor) service, route);
} else if (service instanceof ThrottlingInflightRoutePolicy) {
answer = new ManagedThrottlingInflightRoutePolicy(context, (ThrottlingInflightRoutePolicy) service);
} else if (service instanceof ThrottlingExceptionRoutePolicy) {
answer = new ManagedThrottlingExceptionRoutePolicy(context, (ThrottlingExceptionRoutePolicy) service);
} else if (service instanceof ConsumerCache) {
answer = new ManagedConsumerCache(context, (ConsumerCache) service);
} else if (service instanceof ProducerCache) {
answer = new ManagedProducerCache(context, (ProducerCache) service);
} else if (service instanceof DefaultEndpointRegistry) {
answer = new ManagedEndpointRegistry(context, (DefaultEndpointRegistry) service);
} else if (service instanceof TypeConverterRegistry) {
answer = new ManagedTypeConverterRegistry(context, (TypeConverterRegistry) service);
} else if (service instanceof RestRegistry) {
answer = new ManagedRestRegistry(context, (RestRegistry) service);
} else if (service instanceof InflightRepository) {
answer = new ManagedInflightRepository(context, (InflightRepository) service);
} else if (service instanceof AsyncProcessorAwaitManager) {
answer = new ManagedAsyncProcessorAwaitManager(context, (AsyncProcessorAwaitManager) service);
} else if (service instanceof RuntimeEndpointRegistry) {
answer = new ManagedRuntimeEndpointRegistry(context, (RuntimeEndpointRegistry) service);
} else if (service instanceof StreamCachingStrategy) {
answer = new ManagedStreamCachingStrategy(context, (StreamCachingStrategy) service);
} else if (service instanceof EventNotifier) {
answer = getManagementObjectStrategy().getManagedObjectForEventNotifier(context, (EventNotifier) service);
} else if (service instanceof TransformerRegistry) {
answer = new ManagedTransformerRegistry(context, (TransformerRegistry) service);
} else if (service instanceof ValidatorRegistry) {
answer = new ManagedValidatorRegistry(context, (ValidatorRegistry) service);
} else if (service instanceof RuntimeCamelCatalog) {
answer = new ManagedRuntimeCamelCatalog(context, (RuntimeCamelCatalog) service);
} else if (service != null) {
// fallback as generic service
answer = getManagementObjectStrategy().getManagedObjectForService(context, service);
}
if (answer != null && answer instanceof ManagedService) {
ManagedService ms = (ManagedService) answer;
ms.setRoute(route);
ms.init(getManagementStrategy());
}
return answer;
}
use of org.apache.camel.spi.DataFormat in project camel by apache.
the class OsgiDataFormatResolver method createDataFormat.
public DataFormat createDataFormat(String name, CamelContext context) {
DataFormat dataFormat = null;
// lookup in registry first
DataFormatFactory dataFormatFactory = ResolverHelper.lookupDataFormatFactoryInRegistryWithFallback(context, name);
if (dataFormatFactory != null) {
dataFormat = dataFormatFactory.newInstance();
}
if (dataFormat == null) {
dataFormat = getDataFormat(name, context, true);
}
return dataFormat;
}
use of org.apache.camel.spi.DataFormat in project camel by apache.
the class DataFormatDefinition method getDataFormat.
/**
* Factory method to create the data format
*
* @param routeContext route context
* @param type the data format type
* @param ref reference to lookup for a data format
* @return the data format or null if not possible to create
*/
public static DataFormat getDataFormat(RouteContext routeContext, DataFormatDefinition type, String ref) {
if (type == null) {
ObjectHelper.notNull(ref, "ref or type");
// try to let resolver see if it can resolve it, its not always possible
type = routeContext.getCamelContext().resolveDataFormatDefinition(ref);
if (type != null) {
return type.getDataFormat(routeContext);
}
DataFormat dataFormat = routeContext.getCamelContext().resolveDataFormat(ref);
if (dataFormat == null) {
throw new IllegalArgumentException("Cannot find data format in registry with ref: " + ref);
}
return dataFormat;
} else {
return type.getDataFormat(routeContext);
}
}
Aggregations