String scheme = "http";
String host = "";
int port = 0;
// if no explicit port/host configured, then use port from rest configuration
RestConfiguration config = getCamelContext().getRestConfiguration();
if (config.getComponent() == null || config.getComponent().equals("jetty")) {
if (config.getScheme() != null) {
scheme = config.getScheme();
}
if (config.getHost() != null) {
host = config.getHost();
}
int num = config.getPort();
if (num > 0) {
port = num;
}
}
// if no explicit hostname set then resolve the hostname
if (ObjectHelper.isEmpty(host)) {
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 != null && (config.getComponent() == null || config.getComponent().equals("jetty"))) {
// setup endpoint options
if (config.getEndpointProperties() != null && !config.getEndpointProperties().isEmpty()) {
map.putAll(config.getEndpointProperties());
}
}
String query = URISupport.createQueryString(map);
String url = "jetty:%s://%s:%s/%s?httpMethodRestrict=%s";
// must use upper case for restrict
String restrict = verb.toUpperCase(Locale.US);
// get the endpoint
url = String.format(url, scheme, host, port, path, restrict);
if (!query.isEmpty()) {
url = url + "&" + query;
}
JettyHttpEndpoint endpoint = camelContext.getEndpoint(url, JettyHttpEndpoint.class);
setProperties(endpoint, parameters);
// disable this filter as we want to use ours
endpoint.setEnableMultipartFilter(false);
// use the rest binding
endpoint.setBinding(new JettyRestHttpBinding());
// configure consumer properties
Consumer consumer = endpoint.createConsumer(processor);
if (config != null && config.getConsumerProperties() != null && !config.getConsumerProperties().isEmpty()) {
setProperties(consumer, config.getConsumerProperties());
}
return consumer;
}