本文整理汇总了Java中org.apache.camel.util.URISupport.createQueryString方法的典型用法代码示例。如果您正苦于以下问题:Java URISupport.createQueryString方法的具体用法?Java URISupport.createQueryString怎么用?Java URISupport.createQueryString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.camel.util.URISupport
的用法示例。
在下文中一共展示了URISupport.createQueryString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: afterConfiguration
import org.apache.camel.util.URISupport; //导入方法依赖的package包/类
@Override
protected void afterConfiguration(String uri, String remaining, Endpoint endpoint, Map<String, Object> parameters) throws Exception {
RssEndpoint rss = (RssEndpoint) endpoint;
if (rss.getFeedUri() != null) {
// already set so do not change it
return;
}
// recreate feed uri after we have configured the endpoint so we can use the left over parameters
// for the http feed
String feedUri;
if (!parameters.isEmpty()) {
Map<String, Object> options = new LinkedHashMap<String, Object>(parameters);
String query = URISupport.createQueryString(options);
feedUri = remaining + "?" + query;
} else {
feedUri = remaining;
}
rss.setFeedUri(feedUri);
}
示例2: asRouteApiDefinition
import org.apache.camel.util.URISupport; //导入方法依赖的package包/类
/**
* Transforms the rest api configuration into a {@link org.apache.camel.model.RouteDefinition} which
* Camel routing engine uses to service the rest api docs.
*/
public static RouteDefinition asRouteApiDefinition(CamelContext camelContext, RestConfiguration configuration) {
RouteDefinition answer = new RouteDefinition();
// create the from endpoint uri which is using the rest-api component
String from = "rest-api:" + configuration.getApiContextPath();
// append options
Map<String, Object> options = new HashMap<String, Object>();
String routeId = configuration.getApiContextRouteId();
if (routeId == null) {
routeId = answer.idOrCreate(camelContext.getNodeIdFactory());
}
options.put("routeId", routeId);
if (configuration.getComponent() != null && !configuration.getComponent().isEmpty()) {
options.put("componentName", configuration.getComponent());
}
if (configuration.getApiContextIdPattern() != null) {
options.put("contextIdPattern", configuration.getApiContextIdPattern());
}
if (!options.isEmpty()) {
String query;
try {
query = URISupport.createQueryString(options);
} catch (URISyntaxException e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
from = from + "?" + query;
}
// we use the same uri as the producer (so we have a little route for the rest api)
String to = from;
answer.fromRest(from);
answer.id(routeId);
answer.to(to);
return answer;
}
示例3: createEndpoint
import org.apache.camel.util.URISupport; //导入方法依赖的package包/类
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters)
throws Exception {
String childUri = remaining;
// we need to apply the params here
if (parameters != null && parameters.size() > 0) {
childUri = childUri + "?" + URISupport.createQueryString(parameters);
}
// need to clean the parameters to avoid default component verify parameter complain
parameters.clear();
Endpoint childEndpoint = context.getEndpoint(childUri);
return new MyEndpoint(uri, childEndpoint);
}
示例4: createEndpoint
import org.apache.camel.util.URISupport; //导入方法依赖的package包/类
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
String remainingRaw = URISupport.extractRemainderPath(new URI(uri), true);
RestletEndpoint result = new RestletEndpoint(this, remainingRaw);
if (synchronous != null) {
result.setSynchronous(synchronous);
}
result.setDisableStreamCache(isDisableStreamCache());
setEndpointHeaderFilterStrategy(result);
setProperties(result, parameters);
// set the endpoint uri according to the parameter
result.updateEndpointUri();
// construct URI so we can use it to get the splitted information
URI u = new URI(remainingRaw);
String protocol = u.getScheme();
String uriPattern = u.getRawPath();
if (parameters.size() > 0) {
uriPattern = uriPattern + "?" + URISupport.createQueryString(parameters);
}
int port = 0;
String host = u.getHost();
if (u.getPort() > 0) {
port = u.getPort();
} else {
port = this.port;
}
result.setProtocol(protocol);
result.setUriPattern(uriPattern);
result.setHost(host);
if (port > 0) {
result.setPort(port);
}
return result;
}
示例5: createConsumer
import org.apache.camel.util.URISupport; //导入方法依赖的package包/类
@Override
public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String basePath, String uriTemplate,
String consumes, String produces, Map<String, Object> parameters) 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 = 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(endpoint));
// configure consumer properties
Consumer consumer = endpoint.createConsumer(processor);
if (config != null && config.getConsumerProperties() != null && !config.getConsumerProperties().isEmpty()) {
setProperties(consumer, config.getConsumerProperties());
}
return consumer;
}
示例6: doCreateConsumer
import org.apache.camel.util.URISupport; //导入方法依赖的package包/类
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;
}
示例7: createConsumer
import org.apache.camel.util.URISupport; //导入方法依赖的package包/类
@Override
public Consumer createConsumer(CamelContext camelContext,
Processor processor,
String verb,
String basePath,
String uriTemplate,
String consumes,
String produces,
RestConfiguration configuration,
Map<String, Object> parameters) throws Exception {
RestConfiguration config = configuration;
if (config == null) {
config = getCamelContext().getRestConfiguration("coap", true);
}
String host = config.getHost();
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>();
// 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 = (config.getScheme() == null ? "coap" : config.getScheme()) + "://" + host;
if (config.getPort() != -1) {
url += ":" + config.getPort();
}
String restrict = verb.toUpperCase(Locale.US);
if (cors) {
restrict += ",OPTIONS";
}
if (uriTemplate == null) {
uriTemplate = "";
}
url += basePath + uriTemplate + "?coapMethod=" + restrict;
if (!query.isEmpty()) {
url += "&" + query;
}
CoAPEndpoint endpoint = camelContext.getEndpoint(url, CoAPEndpoint.class);
setProperties(endpoint, parameters);
// configure consumer properties
Consumer consumer = endpoint.createConsumer(processor);
if (config.getConsumerProperties() != null && !config.getConsumerProperties().isEmpty()) {
setProperties(consumer, config.getConsumerProperties());
}
return consumer;
}
示例8: doCreateConsumer
import org.apache.camel.util.URISupport; //导入方法依赖的package包/类
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);
RestConfiguration config = configuration;
if (config == null) {
config = camelContext.getRestConfiguration("spark-rest", true);
}
Map<String, Object> map = new HashMap<String, Object>();
if (consumes != null) {
map.put("accept", consumes);
}
// setup endpoint options
if (config.getEndpointProperties() != null && !config.getEndpointProperties().isEmpty()) {
map.putAll(config.getEndpointProperties());
}
if (ObjectHelper.isNotEmpty(path)) {
// spark-rest uses :name syntax instead of {name} so we need to replace those
Matcher matcher = pattern.matcher(path);
path = matcher.replaceAll(":$1");
}
// 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;
}
}
String url;
if (api) {
url = "spark-rest:%s:%s?matchOnUriPrefix=true";
} else {
url = "spark-rest:%s:%s";
}
url = String.format(url, verb, path);
String query = URISupport.createQueryString(map);
if (!query.isEmpty()) {
url = url + "?" + query;
}
// get the endpoint
SparkEndpoint endpoint = camelContext.getEndpoint(url, SparkEndpoint.class);
setProperties(camelContext, endpoint, parameters);
// configure consumer properties
Consumer consumer = endpoint.createConsumer(processor);
if (config.isEnableCORS()) {
// if CORS is enabled then configure that on the spark consumer
if (config.getConsumerProperties() == null) {
config.setConsumerProperties(new HashMap<String, Object>());
}
config.getConsumerProperties().put("enableCors", true);
}
if (config.getConsumerProperties() != null && !config.getConsumerProperties().isEmpty()) {
setProperties(camelContext, consumer, config.getConsumerProperties());
}
return consumer;
}