use of org.apache.camel.Endpoint in project camel by apache.
the class RouteRefPropertyPlaceholderMultipleCamelContextRefsTest method testSpringTwoCamelContextDirectEndpoint.
public void testSpringTwoCamelContextDirectEndpoint() throws Exception {
AbstractXmlApplicationContext ac = createApplicationContext();
ac.start();
CamelContext camel1 = ac.getBean("myCamel-1", CamelContext.class);
CamelContext camel2 = ac.getBean("myCamel-2", CamelContext.class);
Endpoint start1 = camel1.getEndpoint("direct:start");
Endpoint start2 = camel2.getEndpoint("direct:start");
assertNotSame(start1, start2);
MockEndpoint mock1 = camel1.getEndpoint("mock:end-1", MockEndpoint.class);
mock1.expectedBodiesReceived("Hello World");
MockEndpoint mock2 = camel2.getEndpoint("mock:end-2", MockEndpoint.class);
mock2.expectedBodiesReceived("Bye World");
camel1.createProducerTemplate().sendBody("direct:start", "Hello World");
camel2.createProducerTemplate().sendBody("direct:start", "Bye World");
mock1.assertIsSatisfied();
mock2.assertIsSatisfied();
ac.stop();
}
use of org.apache.camel.Endpoint in project camel by apache.
the class EndpointReferenceTest method testEndpointConfiguration.
public void testEndpointConfiguration() throws Exception {
Endpoint endpoint = getMandatoryBean(Endpoint.class, "endpoint1");
assertEquals("endpoint URI", "direct://start", endpoint.getEndpointUri());
DummyBean dummyBean = getMandatoryBean(DummyBean.class, "mybean");
assertNotNull("The bean should have an endpoint injected", dummyBean.getEndpoint());
assertEquals("endpoint URI", "direct://start", dummyBean.getEndpoint().getEndpointUri());
log.debug("Found dummy bean: " + dummyBean);
MockEndpoint resultEndpoint = getMockEndpoint("mock:end");
resultEndpoint.expectedBodiesReceived(body);
// now lets send a message
template.sendBody("direct:start", body);
resultEndpoint.assertIsSatisfied();
}
use of org.apache.camel.Endpoint in project camel by apache.
the class EndpointHelperTest method testLookupEndpointRegistryId.
public void testLookupEndpointRegistryId() throws Exception {
Endpoint foo = context.getEndpoint("ref:foo");
Endpoint bar = context.getEndpoint("ref:coolbar");
assertEquals("foo", EndpointHelper.lookupEndpointRegistryId(foo));
assertEquals("coolbar", EndpointHelper.lookupEndpointRegistryId(bar));
assertEquals(null, EndpointHelper.lookupEndpointRegistryId(context.getEndpoint("mock:cheese")));
}
use of org.apache.camel.Endpoint in project camel by apache.
the class UndertowComponent 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;
RestConfiguration config = configuration;
if (config == null) {
config = camelContext.getRestConfiguration("undertow", 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("undertow")) {
// 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 = "undertow:%s://%s:%s/%s?matchOnUriPrefix=true&httpMethodRestrict=%s";
} else {
url = "undertow:%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;
}
UndertowEndpoint endpoint = camelContext.getEndpoint(url, UndertowEndpoint.class);
setProperties(camelContext, endpoint, parameters);
if (!map.containsKey("undertowHttpBinding")) {
// use the rest binding, if not using a custom http binding
endpoint.setUndertowHttpBinding(new RestUndertowHttpBinding());
}
// 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.Endpoint in project camel by apache.
the class UriConfigurationTest method testHttpProxySetting.
@Test
public void testHttpProxySetting() throws Exception {
Endpoint endpoint = context.getEndpoint("twitter:search?httpProxyHost=example.com&httpProxyPort=3338&httpProxyUser=test&httpProxyPassword=pwd");
assertTrue("Endpoint not a TwitterEndpoint: " + endpoint, endpoint instanceof TwitterEndpoint);
TwitterEndpoint twitterEndpoint = (TwitterEndpoint) endpoint;
assertEquals("example.com", twitterEndpoint.getProperties().getHttpProxyHost());
assertEquals(Integer.valueOf(3338), twitterEndpoint.getProperties().getHttpProxyPort());
assertEquals("test", twitterEndpoint.getProperties().getHttpProxyUser());
assertEquals("pwd", twitterEndpoint.getProperties().getHttpProxyPassword());
}
Aggregations