use of org.apache.camel.Consumer in project camel by apache.
the class JmsSimpleRequestCustomReplyToTest method testRequetCustomReplyTo.
@Test
public void testRequetCustomReplyTo() throws Exception {
// use another thread to send the late reply to simulate that we do it later, not
// from the original route anyway
Thread sender = new Thread(new SendLateReply());
sender.start();
MockEndpoint result = getMockEndpoint("mock:result");
result.expectedMessageCount(1);
Exchange out = template.request("activemq:queue:hello", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.setPattern(ExchangePattern.InOnly);
exchange.getIn().setHeader("MyReplyQeueue", "foo");
exchange.getIn().setBody("Hello World");
}
});
result.assertIsSatisfied();
assertNotNull(out);
assertFalse(out.hasOut());
// get the reply from the special reply queue
Endpoint end = context.getEndpoint(componentName + ":" + myReplyTo);
final Consumer consumer = end.createConsumer(new Processor() {
public void process(Exchange exchange) throws Exception {
assertEquals("Late reply", exchange.getIn().getBody());
latch.countDown();
}
});
// reset latch
latch = new CountDownLatch(1);
consumer.start();
latch.await();
consumer.stop();
}
use of org.apache.camel.Consumer in project camel by apache.
the class SparkEndpoint method createConsumer.
@Override
public Consumer createConsumer(Processor processor) throws Exception {
CamelSparkRoute route = new CamelSparkRoute(this, processor);
Consumer consumer = new SparkConsumer(this, processor, route);
configureConsumer(consumer);
return consumer;
}
use of org.apache.camel.Consumer in project camel by apache.
the class MllpEndpoint method createConsumer.
public Consumer createConsumer(Processor processor) throws Exception {
LOG.trace("({}).createConsumer(processor)", this.getEndpointKey());
Consumer consumer = new MllpTcpServerConsumer(this, processor);
configureConsumer(consumer);
return consumer;
}
use of org.apache.camel.Consumer in project camel by apache.
the class NettyHttpComponent method doCreateConsumer.
Consumer doCreateConsumer(CamelContext camelContext, Processor processor, String verb, String basePath, String uriTemplate, String consumes, String produces, RestConfiguration configuration, Map<String, Object> parameters, boolean api) throws Exception {
String path = basePath;
if (uriTemplate != null) {
// make sure to avoid double slashes
if (uriTemplate.startsWith("/")) {
path = path + uriTemplate;
} else {
path = path + "/" + uriTemplate;
}
}
path = FileUtil.stripLeadingSeparator(path);
String scheme = "http";
String host = "";
int port = 0;
// if no explicit port/host configured, then use port from rest configuration
RestConfiguration config = configuration;
if (config == null) {
config = camelContext.getRestConfiguration("netty-http", true);
}
if (config.getScheme() != null) {
scheme = config.getScheme();
}
if (config.getHost() != null) {
host = config.getHost();
}
int num = config.getPort();
if (num > 0) {
port = num;
}
// prefix path with context-path if configured in rest-dsl configuration
String contextPath = config.getContextPath();
if (ObjectHelper.isNotEmpty(contextPath)) {
contextPath = FileUtil.stripTrailingSeparator(contextPath);
contextPath = FileUtil.stripLeadingSeparator(contextPath);
if (ObjectHelper.isNotEmpty(contextPath)) {
path = contextPath + "/" + path;
}
}
// if no explicit hostname set then resolve the hostname
if (ObjectHelper.isEmpty(host)) {
if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.allLocalIp) {
host = "0.0.0.0";
} else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localHostName) {
host = HostUtils.getLocalHostName();
} else if (config.getRestHostNameResolver() == RestConfiguration.RestHostNameResolver.localIp) {
host = HostUtils.getLocalIp();
}
}
Map<String, Object> map = new HashMap<String, Object>();
// build query string, and append any endpoint configuration properties
if (config.getComponent() == null || config.getComponent().equals("netty-http")) {
// setup endpoint options
if (config.getEndpointProperties() != null && !config.getEndpointProperties().isEmpty()) {
map.putAll(config.getEndpointProperties());
}
}
boolean cors = config.isEnableCORS();
if (cors) {
// allow HTTP Options as we want to handle CORS in rest-dsl
map.put("optionsEnabled", "true");
}
String query = URISupport.createQueryString(map);
String url;
if (api) {
url = "netty-http:%s://%s:%s/%s?matchOnUriPrefix=true&httpMethodRestrict=%s";
} else {
url = "netty-http:%s://%s:%s/%s?httpMethodRestrict=%s";
}
// must use upper case for restrict
String restrict = verb.toUpperCase(Locale.US);
if (cors) {
restrict += ",OPTIONS";
}
// get the endpoint
url = String.format(url, scheme, host, port, path, restrict);
if (!query.isEmpty()) {
url = url + "&" + query;
}
NettyHttpEndpoint endpoint = camelContext.getEndpoint(url, NettyHttpEndpoint.class);
setProperties(camelContext, endpoint, parameters);
// configure consumer properties
Consumer consumer = endpoint.createConsumer(processor);
if (config.getConsumerProperties() != null && !config.getConsumerProperties().isEmpty()) {
setProperties(camelContext, consumer, config.getConsumerProperties());
}
return consumer;
}
use of org.apache.camel.Consumer in project camel by apache.
the class ServletComponent method doCreateConsumer.
Consumer doCreateConsumer(CamelContext camelContext, Processor processor, String verb, String basePath, String uriTemplate, String consumes, String produces, RestConfiguration configuration, Map<String, Object> parameters, boolean api) throws Exception {
String path = basePath;
if (uriTemplate != null) {
// make sure to avoid double slashes
if (uriTemplate.startsWith("/")) {
path = path + uriTemplate;
} else {
path = path + "/" + uriTemplate;
}
}
path = FileUtil.stripLeadingSeparator(path);
// if no explicit port/host configured, then use port from rest configuration
RestConfiguration config = configuration;
if (config == null) {
config = camelContext.getRestConfiguration("servlet", true);
}
Map<String, Object> map = new HashMap<String, Object>();
// build query string, and append any endpoint configuration properties
if (config.getComponent() == null || config.getComponent().equals("servlet")) {
// setup endpoint options
if (config.getEndpointProperties() != null && !config.getEndpointProperties().isEmpty()) {
map.putAll(config.getEndpointProperties());
}
}
boolean cors = config.isEnableCORS();
if (cors) {
// allow HTTP Options as we want to handle CORS in rest-dsl
map.put("optionsEnabled", "true");
}
// do not append with context-path as the servlet path should be without context-path
String query = URISupport.createQueryString(map);
String url;
if (api) {
url = "servlet:///%s?matchOnUriPrefix=true&httpMethodRestrict=%s";
} else {
url = "servlet:///%s?httpMethodRestrict=%s";
}
// must use upper case for restrict
String restrict = verb.toUpperCase(Locale.US);
if (cors) {
restrict += ",OPTIONS";
}
// get the endpoint
url = String.format(url, path, restrict);
if (!query.isEmpty()) {
url = url + "&" + query;
}
ServletEndpoint endpoint = camelContext.getEndpoint(url, ServletEndpoint.class);
setProperties(camelContext, endpoint, parameters);
if (!map.containsKey("httpBindingRef")) {
// use the rest binding, if not using a custom http binding
HttpBinding binding = new ServletRestHttpBinding();
binding.setHeaderFilterStrategy(endpoint.getHeaderFilterStrategy());
binding.setTransferException(endpoint.isTransferException());
binding.setEagerCheckContentAvailable(endpoint.isEagerCheckContentAvailable());
endpoint.setHttpBinding(binding);
}
// configure consumer properties
Consumer consumer = endpoint.createConsumer(processor);
if (config.getConsumerProperties() != null && !config.getConsumerProperties().isEmpty()) {
setProperties(camelContext, consumer, config.getConsumerProperties());
}
return consumer;
}
Aggregations