use of org.apache.camel.Consumer in project camel by apache.
the class WebsocketEndpointTest method testCreateConsumer.
/**
* Test method for {@link org.apache.camel.component.websocket.WebsocketEndpoint#createConsumer(org.apache.camel.Processor)} .
*/
@Test
public void testCreateConsumer() throws Exception {
Consumer consumer = websocketEndpoint.createConsumer(processor);
component.connect((WebsocketProducerConsumer) consumer);
assertNotNull(consumer);
assertEquals(WebsocketConsumer.class, consumer.getClass());
InOrder inOrder = inOrder(component, processor);
ArgumentCaptor<NodeSynchronization> synchronizationCaptor = ArgumentCaptor.forClass(NodeSynchronization.class);
ArgumentCaptor<WebsocketConsumer> consumerCaptor = ArgumentCaptor.forClass(WebsocketConsumer.class);
inOrder.verify(component, times(1)).addServlet(synchronizationCaptor.capture(), consumerCaptor.capture(), eq(REMAINING));
inOrder.verifyNoMoreInteractions();
assertEquals(DefaultNodeSynchronization.class, synchronizationCaptor.getValue().getClass());
assertEquals(consumer, consumerCaptor.getValue());
}
use of org.apache.camel.Consumer in project camel by apache.
the class NettyEndpoint method createConsumer.
public Consumer createConsumer(Processor processor) throws Exception {
Consumer answer = new NettyConsumer(this, processor, configuration);
configureConsumer(answer);
return answer;
}
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("netty4-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("netty4-http")) {
// setup endpoint options
if (config.getEndpointProperties() != null && !config.getEndpointProperties().isEmpty()) {
map.putAll(config.getEndpointProperties());
}
}
// allow HTTP Options as we want to handle CORS in rest-dsl
boolean cors = config.isEnableCORS();
String query = URISupport.createQueryString(map);
String url;
if (api) {
url = "netty4-http:%s://%s:%s/%s?matchOnUriPrefix=true&httpMethodRestrict=%s";
} else {
url = "netty4-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 NettyEndpoint method createConsumer.
public Consumer createConsumer(Processor processor) throws Exception {
Consumer answer = new NettyConsumer(this, processor, configuration);
configureConsumer(answer);
return answer;
}
use of org.apache.camel.Consumer in project camel by apache.
the class OpenShiftEndpoint method createConsumer.
@Override
public Consumer createConsumer(Processor processor) throws Exception {
ObjectHelper.notEmpty(clientId, "clientId", this);
ObjectHelper.notEmpty(username, "username", this);
ObjectHelper.notEmpty(password, "password", this);
Consumer consumer = new OpenShiftConsumer(this, processor);
configureConsumer(consumer);
return consumer;
}
Aggregations