use of org.apache.camel.Endpoint in project camel by apache.
the class WebsocketComponent method createEndpoint.
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
// TODO cmueller: remove the "sslContextParametersRef" look up in Camel 3.0
SSLContextParameters sslContextParameters = resolveAndRemoveReferenceParameter(parameters, "sslContextParametersRef", SSLContextParameters.class);
if (sslContextParameters == null) {
sslContextParameters = resolveAndRemoveReferenceParameter(parameters, "sslContextParameters", SSLContextParameters.class);
}
Boolean enableJmx = getAndRemoveParameter(parameters, "enableJmx", Boolean.class);
String staticResources = getAndRemoveParameter(parameters, "staticResources", String.class);
int port = extractPortNumber(remaining);
String host = extractHostName(remaining);
WebsocketEndpoint endpoint = new WebsocketEndpoint(this, uri, remaining, parameters);
if (enableJmx != null) {
endpoint.setEnableJmx(enableJmx);
} else {
endpoint.setEnableJmx(isEnableJmx());
}
// prefer to use endpoint configured over component configured
if (sslContextParameters == null) {
// fallback to component configured
sslContextParameters = getSslContextParameters();
}
if (sslContextParameters != null) {
endpoint.setSslContextParameters(sslContextParameters);
}
// prefer to use endpoint configured over component configured
if (staticResources == null) {
// fallback to component configured
staticResources = getStaticResources();
}
if (staticResources != null) {
endpoint.setStaticResources(staticResources);
}
endpoint.setSslContextParameters(sslContextParameters);
endpoint.setPort(port);
endpoint.setHost(host);
setProperties(endpoint, parameters);
return endpoint;
}
use of org.apache.camel.Endpoint in project camel by apache.
the class ZipkinTracer method doStart.
@Override
protected void doStart() throws Exception {
ObjectHelper.notNull(camelContext, "CamelContext", this);
camelContext.getManagementStrategy().addEventNotifier(eventNotifier);
if (!camelContext.getRoutePolicyFactories().contains(this)) {
camelContext.addRoutePolicyFactory(this);
}
if (spanCollector == null) {
if (hostName != null && port > 0) {
LOG.info("Configuring Zipkin ScribeSpanCollector using host: {} and port: {}", hostName, port);
spanCollector = new ScribeSpanCollector(hostName, port);
} else {
// is there a zipkin service setup as ENV variable to auto register a scribe span collector
String host = new ServiceHostPropertiesFunction().apply(ZIPKIN_COLLECTOR_THRIFT_SERVICE);
String port = new ServicePortPropertiesFunction().apply(ZIPKIN_COLLECTOR_THRIFT_SERVICE);
if (ObjectHelper.isNotEmpty(host) && ObjectHelper.isNotEmpty(port)) {
LOG.info("Auto-configuring Zipkin ScribeSpanCollector using host: {} and port: {}", host, port);
int num = camelContext.getTypeConverter().mandatoryConvertTo(Integer.class, port);
spanCollector = new ScribeSpanCollector(host, num);
}
}
}
if (spanCollector == null) {
// Try to lookup the span collector from the registry if only one instance is present
Set<SpanCollector> collectors = camelContext.getRegistry().findByType(SpanCollector.class);
if (collectors.size() == 1) {
spanCollector = collectors.iterator().next();
}
}
ObjectHelper.notNull(spanCollector, "SpanCollector", this);
if (clientServiceMappings.isEmpty() && serverServiceMappings.isEmpty()) {
LOG.warn("No service name(s) has been mapped in clientServiceMappings or serverServiceMappings. Camel will fallback and use endpoint uris as service names.");
useFallbackServiceNames = true;
}
// create braves mapped per service name
for (Map.Entry<String, String> entry : clientServiceMappings.entrySet()) {
String pattern = entry.getKey();
String serviceName = entry.getValue();
createBraveForService(pattern, serviceName);
}
for (Map.Entry<String, String> entry : serverServiceMappings.entrySet()) {
String pattern = entry.getKey();
String serviceName = entry.getValue();
createBraveForService(pattern, serviceName);
}
ServiceHelper.startServices(spanCollector, eventNotifier);
}
use of org.apache.camel.Endpoint in project camel by apache.
the class YammerComponent method createEndpoint.
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
// by default use config for each endpoint; use from component level if one has been explicitly set
YammerConfiguration endpointConfig = getConfig();
if (endpointConfig == null) {
endpointConfig = new YammerConfiguration();
}
// set options from component
endpointConfig.setConsumerKey(consumerKey);
endpointConfig.setConsumerSecret(consumerSecret);
endpointConfig.setAccessToken(accessToken);
endpointConfig.setFunction(remaining);
endpointConfig.setFunctionType(YammerFunctionType.fromUri(remaining));
// and then override from parameters
setProperties(endpointConfig, parameters);
Endpoint endpoint = new YammerEndpoint(uri, this, endpointConfig);
setProperties(endpoint, parameters);
return endpoint;
}
use of org.apache.camel.Endpoint in project camel by apache.
the class YammerComponentTestSupport method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
InputStream is = getClass().getResourceAsStream(jsonFile());
setMessages(context.getTypeConverter().convertTo(String.class, is));
yammerComponent = context.getComponent("yammer", YammerComponent.class);
Collection<Endpoint> endpoints = context.getEndpoints();
for (Endpoint endpoint : endpoints) {
if (endpoint instanceof YammerEndpoint) {
((YammerEndpoint) endpoint).getConfig().setRequestor(new TestApiRequestor(getMessages()));
}
}
}
use of org.apache.camel.Endpoint in project camel by apache.
the class CamelClientEndpoint method main.
// START SNIPPET: e1
public static void main(final String[] args) throws Exception {
System.out.println("Notice this client requires that the CamelServer is already running!");
AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml");
CamelContext camel = context.getBean("camel-client", CamelContext.class);
// get the endpoint from the camel context
Endpoint endpoint = camel.getEndpoint("jms:queue:numbers");
// create the exchange used for the communication
// we use the in out pattern for a synchronized exchange where we expect a response
Exchange exchange = endpoint.createExchange(ExchangePattern.InOut);
// set the input on the in body
// must be correct type to match the expected type of an Integer object
exchange.getIn().setBody(11);
// to send the exchange we need an producer to do it for us
Producer producer = endpoint.createProducer();
// start the producer so it can operate
producer.start();
// let the producer process the exchange where it does all the work in this oneline of code
System.out.println("Invoking the multiply with 11");
producer.process(exchange);
// get the response from the out body and cast it to an integer
int response = exchange.getOut().getBody(Integer.class);
System.out.println("... the result is: " + response);
// stopping the JMS producer has the side effect of the "ReplyTo Queue" being properly
// closed, making this client not to try any further reads for the replies from the server
producer.stop();
// we're done so let's properly close the application context
IOHelper.close(context);
}
Aggregations