Java 类org.apache.camel.util.UnsafeUriCharactersEncoder 实例源码

项目:Camel    文件:NettyHttpHelper.java   
/**
 * Creates the URI to invoke.
 *
 * @param exchange the exchange
 * @param url      the url to invoke
 * @param endpoint the endpoint
 * @return the URI to invoke
 */
public static URI createURI(Exchange exchange, String url, NettyHttpEndpoint endpoint) throws URISyntaxException {
    URI uri = new URI(url);
    // is a query string provided in the endpoint URI or in a header
    // (header overrules endpoint, raw query header overrules query header)
    String queryString = exchange.getIn().getHeader(Exchange.HTTP_RAW_QUERY, String.class);
    if (queryString == null) {
        queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
    }
    if (queryString == null) {
        // use raw as we encode just below
        queryString = uri.getRawQuery();
    }
    if (queryString != null) {
        // need to encode query string
        queryString = UnsafeUriCharactersEncoder.encodeHttpURI(queryString);
        uri = URISupport.createURIWithQuery(uri, queryString);
    }
    return uri;
}
项目:Camel    文件:HttpServerMultiplexChannelHandler.java   
private static String pathAsKey(String path) {
    // cater for default path
    if (path == null || path.equals("/")) {
        path = "";
    }

    // strip out query parameters
    int idx = path.indexOf('?');
    if (idx > -1) {
        path = path.substring(0, idx);
    }

    // strip of ending /
    if (path.endsWith("/")) {
        path = path.substring(0, path.length() - 1);
    }

    return UnsafeUriCharactersEncoder.encodeHttpURI(path);
}
项目:Camel    文件:NettyHttpComponent.java   
@Override
protected NettyConfiguration parseConfiguration(NettyConfiguration configuration, String remaining, Map<String, Object> parameters) throws Exception {
    // ensure uri is encoded to be valid
    String safe = UnsafeUriCharactersEncoder.encodeHttpURI(remaining);
    URI uri = new URI(safe);
    configuration.parseURI(uri, parameters, this, "http", "https");

    // force using tcp as the underlying transport
    configuration.setProtocol("tcp");
    configuration.setTextline(false);

    if (configuration instanceof NettyHttpConfiguration) {
        ((NettyHttpConfiguration) configuration).setPath(uri.getPath());
    }

    return configuration;
}
项目:Camel    文件:ExecEndpointTest.java   
@Test
@DirtiesContext
public void testCreateEndpointComposite2() throws Exception {
    String workingDir = "/workingdir";
    String outFile = "target/outfile.xml";
    long timeout = 10000;
    StringBuilder builder = new StringBuilder();
    builder.append("exec:executable.exe").append("?workingDir=" + workingDir).append("&timeout=" + timeout);
    builder.append("&outFile=" + outFile);
    builder.append("&commandExecutor=#customExecutor&binding=#customBinding");

    ExecEndpoint e = createExecEndpoint(UnsafeUriCharactersEncoder.encode(builder.toString()));
    assertEquals(workingDir, e.getWorkingDir());
    assertEquals(timeout, e.getTimeout());
    assertEquals(outFile, e.getOutFile());
    assertSame(customBinding, e.getBinding());
    assertSame(customExecutor, e.getCommandExecutor());
}
项目:Camel    文件:HttpHelper.java   
/**
 * Creates the URI to invoke.
 *
 * @param exchange the exchange
 * @param url      the url to invoke
 * @param endpoint the endpoint
 * @return the URI to invoke
 */
public static URI createURI(Exchange exchange, String url, HttpCommonEndpoint endpoint) throws URISyntaxException {
    URI uri = new URI(url);
    // is a query string provided in the endpoint URI or in a header
    // (header overrules endpoint, raw query header overrules query header)
    String queryString = exchange.getIn().getHeader(Exchange.HTTP_RAW_QUERY, String.class);
    if (queryString == null) {
        queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
    }
    if (queryString == null) {
        queryString = endpoint.getHttpUri().getRawQuery();
    }
    // We should use the query string from the HTTP_URI header
    if (queryString == null) {
        queryString = uri.getRawQuery();
    }
    if (queryString != null) {
        // need to encode query string
        queryString = UnsafeUriCharactersEncoder.encodeHttpURI(queryString);
        uri = URISupport.createURIWithQuery(uri, queryString);
    }
    return uri;
}
项目:Camel    文件:NettyHttpHelper.java   
/**
 * Creates the URI to invoke.
 *
 * @param exchange the exchange
 * @param url      the url to invoke
 * @param endpoint the endpoint
 * @return the URI to invoke
 */
public static URI createURI(Exchange exchange, String url, NettyHttpEndpoint endpoint) throws URISyntaxException {
    URI uri = new URI(url);
    // is a query string provided in the endpoint URI or in a header
    // (header overrules endpoint, raw query header overrules query header)
    String queryString = exchange.getIn().getHeader(Exchange.HTTP_RAW_QUERY, String.class);
    if (queryString == null) {
        queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
    }
    if (queryString == null) {
        // use raw as we encode just below
        queryString = uri.getRawQuery();
    }
    if (queryString != null) {
        // need to encode query string
        queryString = UnsafeUriCharactersEncoder.encodeHttpURI(queryString);
        uri = URISupport.createURIWithQuery(uri, queryString);
    }
    return uri;
}
项目:Camel    文件:HttpServerMultiplexChannelHandler.java   
private static String pathAsKey(String path) {
    // cater for default path
    if (path == null || path.equals("/")) {
        path = "";
    }

    // strip out query parameters
    int idx = path.indexOf('?');
    if (idx > -1) {
        path = path.substring(0, idx);
    }

    // strip of ending /
    if (path.endsWith("/")) {
        path = path.substring(0, path.length() - 1);
    }

    return UnsafeUriCharactersEncoder.encodeHttpURI(path);
}
项目:Camel    文件:NettyHttpComponent.java   
@Override
protected NettyConfiguration parseConfiguration(NettyConfiguration configuration, String remaining, Map<String, Object> parameters) throws Exception {
    // ensure uri is encoded to be valid
    String safe = UnsafeUriCharactersEncoder.encodeHttpURI(remaining);
    URI uri = new URI(safe);
    configuration.parseURI(uri, parameters, this, "http", "https");

    // force using tcp as the underlying transport
    configuration.setProtocol("tcp");
    configuration.setTextline(false);

    if (configuration instanceof NettyHttpConfiguration) {
        ((NettyHttpConfiguration) configuration).setPath(uri.getPath());
    }
    return configuration;
}
项目:Camel    文件:UndertowHelper.java   
/**
 * Creates the URI to invoke.
 *
 * @param exchange the exchange
 * @param url      the url to invoke
 * @param endpoint the endpoint
 * @return the URI to invoke
 */
public static URI createURI(Exchange exchange, String url, UndertowEndpoint endpoint) throws URISyntaxException {
    URI uri = new URI(url);
    // is a query string provided in the endpoint URI or in a header (header overrules endpoint)
    String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
    if (queryString == null) {
        queryString = endpoint.getHttpURI().getRawQuery();
    }
    // We should user the query string from the HTTP_URI header
    if (queryString == null) {
        queryString = uri.getRawQuery();
    }
    if (queryString != null) {
        // need to encode query string
        queryString = UnsafeUriCharactersEncoder.encodeHttpURI(queryString);
        uri = URISupport.createURIWithQuery(uri, queryString);
    }
    return uri;
}
项目:Camel    文件:AhcHelper.java   
/**
 * Creates the URI to invoke.
 *
 * @param exchange the exchange
 * @param url      the url to invoke
 * @param endpoint the endpoint
 * @return the URI to invoke
 */
public static URI createURI(Exchange exchange, String url, AhcEndpoint endpoint) throws URISyntaxException {
    URI uri = new URI(url);
    // is a query string provided in the endpoint URI or in a header (header overrules endpoint)
    String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
    if (queryString == null) {
        queryString = endpoint.getHttpUri().getRawQuery();
    }
    // We should user the query string from the HTTP_URI header
    if (queryString == null) {
        queryString = uri.getQuery();
    }
    if (queryString != null) {
        // need to encode query string
        queryString = UnsafeUriCharactersEncoder.encodeHttpURI(queryString);
        uri = URISupport.createURIWithQuery(uri, queryString);
    }
    return uri;
}
项目:switchyard    文件:V1BaseCamelBindingModel.java   
protected final void traverseConfiguration(List<Configuration> parent, QueryString queryString,
    String ... excludes) {

    if (parent.size() != 0) {
        List<String> excludeParameters = new ArrayList<String>(Arrays.asList(excludes));

        // ignore additional URI parameters
        excludeParameters.add(AdditionalUriParametersModel.ADDITIONAL_URI_PARAMETERS);

        traverseConfigurationInternal(parent, queryString, excludeParameters);

        // add additional URI parameters
        final AdditionalUriParametersModel additionalParametersModel = getAdditionalUriParameters();
        if (additionalParametersModel != null) {
            for (ParameterModel parameter : additionalParametersModel.getParameters()) {
                if (parameter == null || parameter.getName() == null || excludeParameters.contains(parameter.getName())) {
                    continue;
                }
                queryString.add(parameter.getName(), UnsafeUriCharactersEncoder.encode(parameter.getValue()));
                excludeParameters.add(parameter.getName());
            }
        }
    }
}
项目:switchyard    文件:V1BaseCamelBindingModel.java   
private void traverseConfigurationInternal(List<Configuration> parent, QueryString queryString,
        List<String> excludes) {

    if (parent.size() != 0) {
        Iterator<Configuration> parentIterator = parent.iterator();
        while (parentIterator.hasNext()) {
            Configuration child = parentIterator.next();

            if (child == null || child.getName() == null || excludes.contains(child.getName())) {
                continue;
            }

            if (child.getChildren().size() == 0) {
                queryString.add(child.getName(), UnsafeUriCharactersEncoder.encode(child.getValue()));
                excludes.add(child.getName());
            } else {
                traverseConfigurationInternal(child.getChildren(), queryString, excludes);
            }
        }
    }
}
项目:Camel    文件:DefaultComponent.java   
@Deprecated
protected String preProcessUri(String uri) {
    // Give components a chance to preprocess URIs and migrate to URI syntax that discourages invalid URIs
    // (see CAMEL-4425)
    // check URI string to the unsafe URI characters
    String encodedUri = UnsafeUriCharactersEncoder.encode(uri);
    if (!encodedUri.equals(uri)) {
        // uri supplied is not really valid
        // we just don't want to log the password setting here
        LOG.warn("Supplied URI '{}' contains unsafe characters, please check encoding", URISupport.sanitizeUri(uri));
    }
    return encodedUri;
}
项目:Camel    文件:DefaultEndpointConfiguration.java   
public void setURI(String uri) {
    try {
        String encoded = UnsafeUriCharactersEncoder.encode(uri);
        setURI(new URI(encoded));
    } catch (URISyntaxException e) {
        throw new RuntimeCamelException("Cannot parse uri: " + uri, e);
    }
}
项目:Camel    文件:ExecEndpointTest.java   
@Test
@DirtiesContext
public void testCreateEndpointWithArgs2() throws Exception {
    String args = "arg1 \"arg2 \" arg3";
    ExecEndpoint e = createExecEndpoint("exec:test?args=" + UnsafeUriCharactersEncoder.encode(args));
    assertEquals(args, e.getArgs());
}
项目:Camel    文件:ExecEndpointTest.java   
@Test
@DirtiesContext
public void testCreateEndpointEscapedWorkingDir() throws Exception {
    String cmd = "temp.exe";
    String dir = "\"c:/program files/wokr/temp\"";
    String uri = "exec:" + cmd + "?workingDir=" + dir;

    ExecEndpoint endpoint = createExecEndpoint(UnsafeUriCharactersEncoder.encode(uri));
    assertEquals(cmd, endpoint.getExecutable());
    assertNull(endpoint.getArgs());

    assertEquals(dir, endpoint.getWorkingDir());
}
项目:Camel    文件:ExecEndpointTest.java   
@Test
@DirtiesContext
public void testCreateEndpointEscapedCommand() throws Exception {
    String executable = "C:/Program Files/test/text.exe";
    String uri = "exec:" + executable;

    ExecEndpoint endpoint = createExecEndpoint(UnsafeUriCharactersEncoder.encode(uri));

    assertNull(endpoint.getArgs());
    assertNull(endpoint.getWorkingDir());

    assertEquals(executable, endpoint.getExecutable());
}
项目:Camel    文件:ExecEndpointTest.java   
@Test
@DirtiesContext
public void testCreateEndpointComposite() throws Exception {
    String workingDir = "/workingdir";
    String argsEscaped = "arg1 arg2 \"arg 3\"";
    long timeout = 10000L;

    String uri = "exec:executable.exe?workingDir=" + workingDir + "&timeout=" + timeout + "&args=" + argsEscaped;
    ExecEndpoint e = createExecEndpoint(UnsafeUriCharactersEncoder.encode(uri));
    assertEquals(workingDir, e.getWorkingDir());
    assertEquals(argsEscaped, e.getArgs());
    assertEquals(timeout, e.getTimeout());
}
项目:Camel    文件:HttpHelper.java   
/**
 * Creates the HttpMethod to use to call the remote server, often either its GET or POST.
 *
 * @param exchange  the exchange
 * @return the created method
 * @throws URISyntaxException
 */
public static HttpMethods createMethod(Exchange exchange, HttpCommonEndpoint endpoint, boolean hasPayload) throws URISyntaxException {
    // is a query string provided in the endpoint URI or in a header (header overrules endpoint)
    String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
    // We need also check the HTTP_URI header query part
    String uriString = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
    // resolve placeholders in uriString
    try {
        uriString = exchange.getContext().resolvePropertyPlaceholders(uriString);
    } catch (Exception e) {
        throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uriString, exchange, e);
    }
    if (uriString != null) {
        // in case the URI string contains unsafe characters
        uriString = UnsafeUriCharactersEncoder.encodeHttpURI(uriString);
        URI uri = new URI(uriString);
        queryString = uri.getQuery();
    }
    if (queryString == null) {
        queryString = endpoint.getHttpUri().getRawQuery();
    }

    // compute what method to use either GET or POST
    HttpMethods answer;
    HttpMethods m = exchange.getIn().getHeader(Exchange.HTTP_METHOD, HttpMethods.class);
    if (m != null) {
        // always use what end-user provides in a header
        answer = m;
    } else if (queryString != null) {
        // if a query string is provided then use GET
        answer = HttpMethods.GET;
    } else {
        // fallback to POST if we have payload, otherwise GET
        answer = hasPayload ? HttpMethods.POST : HttpMethods.GET;
    }

    return answer;
}
项目:Camel    文件:HttpMethodHelper.java   
/**
 * Creates the HttpMethod to use to call the remote server, often either its GET or POST.
 *
 * @param exchange the exchange
 * @return the created method
 * @throws URISyntaxException 
 */
public static HttpMethods createMethod(Exchange exchange, HttpEndpoint endpoint, boolean hasPayload) throws URISyntaxException {
    // is a query string provided in the endpoint URI or in a header (header
    // overrules endpoint)
    String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
    // We need also check the HTTP_URI header query part
    String uriString = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
    // resolve placeholders in uriString
    try {
        uriString = exchange.getContext().resolvePropertyPlaceholders(uriString);
    } catch (Exception e) {
        throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uriString, exchange, e);
    }
    if (uriString != null) {
        // in case the URI string contains unsafe characters
        uriString = UnsafeUriCharactersEncoder.encodeHttpURI(uriString);
        URI uri = new URI(uriString);
        queryString = uri.getQuery();
    }
    if (queryString == null) {
        queryString = endpoint.getHttpUri().getRawQuery();
    }

    // compute what method to use either GET or POST
    HttpMethods answer;
    HttpMethods m = exchange.getIn().getHeader(Exchange.HTTP_METHOD, HttpMethods.class);
    if (m != null) {
        // always use what end-user provides in a header
        answer = m;
    } else if (queryString != null) {
        // if a query string is provided then use GET
        answer = HttpMethods.GET;
    } else {
        // fallback to POST if we have payload, otherwise GET
        answer = hasPayload ? HttpMethods.POST : HttpMethods.GET;
    }

    return answer;
}
项目:Camel    文件:JmsEndpoint.java   
public JmsEndpoint(String uri, JmsComponent component, String destinationName, boolean pubSubDomain, JmsConfiguration configuration) {
    super(UnsafeUriCharactersEncoder.encode(uri), component);
    this.configuration = configuration;
    this.destinationName = destinationName;
    this.pubSubDomain = pubSubDomain;
    if (pubSubDomain) {
        this.destinationType = "topic";
    } else {
        this.destinationType = "queue";
    }
}
项目:Camel    文件:JmsEndpoint.java   
@SuppressWarnings("deprecation")
public JmsEndpoint(String endpointUri, JmsBinding binding, JmsConfiguration configuration, String destinationName, boolean pubSubDomain) {
    super(UnsafeUriCharactersEncoder.encode(endpointUri));
    this.binding = binding;
    this.configuration = configuration;
    this.destinationName = destinationName;
    this.pubSubDomain = pubSubDomain;
    if (pubSubDomain) {
        this.destinationType = "topic";
    } else {
        this.destinationType = "queue";
    }
}
项目:Camel    文件:JmsEndpoint.java   
public JmsEndpoint(String endpointUri, String destinationName, boolean pubSubDomain) {
    this(UnsafeUriCharactersEncoder.encode(endpointUri), null, new JmsConfiguration(), destinationName, pubSubDomain);
    this.binding = new JmsBinding(this);
    if (pubSubDomain) {
        this.destinationType = "topic";
    } else {
        this.destinationType = "queue";
    }
}
项目:Camel    文件:IrcConfiguration.java   
private static void addQueryParameter(StringBuilder sb, String key, Object value) {
    sb.append(sb.length() == 0 ? "" : "&");
    sb.append(key);
    if (value != null) {
        String s = value.toString();
        sb.append(s.isEmpty() ? "" : "=" + UnsafeUriCharactersEncoder.encode(s));
    }
}
项目:Camel    文件:CamelContinuationServlet.java   
private void updateHttpPath(Exchange exchange, String contextPath) {
    String httpPath = (String) exchange.getIn().getHeader(Exchange.HTTP_PATH);
    // encode context path in case it contains unsafe chars, because HTTP_PATH isn't decoded at this moment
    String encodedContextPath = UnsafeUriCharactersEncoder.encodeHttpURI(contextPath);

    // here we just remove the CamelServletContextPath part from the HTTP_PATH
    if (contextPath != null && httpPath.startsWith(encodedContextPath)) {
        exchange.getIn().setHeader(Exchange.HTTP_PATH, httpPath.substring(encodedContextPath.length()));
    }
}
项目:Camel    文件:UndertowComponent.java   
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    URI uriHttpUriAddress = new URI(UnsafeUriCharactersEncoder.encodeHttpURI(remaining));
    URI endpointUri = URISupport.createRemainingURI(uriHttpUriAddress, parameters);

    // any additional channel options
    Map<String, Object> options = IntrospectionSupport.extractProperties(parameters, "option.");

    // create the endpoint first
    UndertowEndpoint endpoint = createEndpointInstance(endpointUri, this);
    // set options from component
    endpoint.setSslContextParameters(sslContextParameters);
    endpoint.setUndertowHttpBinding(undertowHttpBinding);
    // set options from parameters
    setProperties(endpoint, parameters);
    if (options != null) {
        endpoint.setOptions(options);
    }

    // then re-create the http uri with the remaining parameters which the endpoint did not use
    URI httpUri = URISupport.createRemainingURI(
        new URI(uriHttpUriAddress.getScheme(),
            uriHttpUriAddress.getUserInfo(),
            uriHttpUriAddress.getHost(),
            uriHttpUriAddress.getPort(),
            uriHttpUriAddress.getPath(),
            uriHttpUriAddress.getQuery(),
            uriHttpUriAddress.getFragment()),
        parameters);
    endpoint.setHttpURI(httpUri);

    return endpoint;
}
项目:Camel    文件:UndertowHelper.java   
/**
 * Creates the URL to invoke.
 *
 * @param exchange the exchange
 * @param endpoint the endpoint
 * @return the URL to invoke
 */
public static String createURL(Exchange exchange, UndertowEndpoint endpoint) {
    String uri = uri = endpoint.getHttpURI().toASCIIString();

    // resolve placeholders in uri
    try {
        uri = exchange.getContext().resolvePropertyPlaceholders(uri);
    } catch (Exception e) {
        throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uri, exchange, e);
    }

    // append HTTP_PATH to HTTP_URI if it is provided in the header
    String path = exchange.getIn().getHeader(Exchange.HTTP_PATH, String.class);
    // NOW the HTTP_PATH is just related path, we don't need to trim it
    if (path != null) {
        if (path.startsWith("/")) {
            path = path.substring(1);
        }
        if (path.length() > 0) {
            // make sure that there is exactly one "/" between HTTP_URI and
            // HTTP_PATH
            if (!uri.endsWith("/")) {
                uri = uri + "/";
            }
            uri = uri.concat(path);
        }
    }

    // ensure uri is encoded to be valid
    uri = UnsafeUriCharactersEncoder.encodeHttpURI(uri);

    return uri;
}
项目:switchyard    文件:V2CamelMqttBindingModel.java   
@Override
public URI getComponentURI() {
    Configuration modelConfiguration = getModelConfiguration();
    List<Configuration> children = modelConfiguration.getChildren();

    String baseUri = MQTT + "://" + getName();

    QueryString queryStr = new QueryString();
    traverseConfiguration(children, queryStr, NAME);

    return URI.create(UnsafeUriCharactersEncoder.encode(baseUri + queryStr.toString()));
}
项目:switchyard    文件:V1CamelJpaBindingModel.java   
@Override
public URI getComponentURI() {
    Configuration modelConfiguration = getModelConfiguration();
    List<Configuration> children = modelConfiguration.getChildren();

    String baseUri = JPA + "://" + getEntityClassName();

    QueryString queryStr = new QueryString();
    traverseConfiguration(children, queryStr, ENTITY_CLASS_NAME);

    return URI.create(baseUri + UnsafeUriCharactersEncoder.encode(queryStr.toString()));
}
项目:switchyard    文件:V1CamelSqlBindingModel.java   
@Override
public URI getComponentURI() {
    Configuration modelConfiguration = getModelConfiguration();
    List<Configuration> children = modelConfiguration.getChildren();
    String baseUri = SQL + "://" + getQuery();
    QueryString queryStr = new QueryString();
    queryStr.add("consumer.delay", getPeriod());
    queryStr.add("consumer.initialDelay", getInitialDelay());
    traverseConfiguration(children, queryStr, QUERY);
    return URI.create(UnsafeUriCharactersEncoder.encode(baseUri + queryStr.toString()));
}
项目:switchyard    文件:V1CamelQuartzBindingModel.java   
@Override
public URI getComponentURI() {
    Configuration modelConfiguration = getModelConfiguration();
    List<Configuration> children = modelConfiguration.getChildren();

    String baseUri = QUARTZ + "://" + getTimerName();

    QueryString queryStr = new QueryString();
    traverseConfiguration(children, queryStr, NAME);

    return URI.create(UnsafeUriCharactersEncoder.encode(baseUri + queryStr.toString()));
}
项目:switchyard    文件:V2CamelQuartzBindingModel.java   
@Override
public URI getComponentURI() {
    Configuration modelConfiguration = getModelConfiguration();
    List<Configuration> children = modelConfiguration.getChildren();

    String baseUri = QUARTZ + "://" + getTimerName();

    QueryString queryStr = new QueryString();
    traverseConfiguration(children, queryStr, NAME);

    return URI.create(UnsafeUriCharactersEncoder.encode(baseUri + queryStr.toString()));
}
项目:Camel    文件:NettyHttpHelper.java   
/**
 * Creates the URL to invoke.
 *
 * @param exchange the exchange
 * @param endpoint the endpoint
 * @return the URL to invoke
 */
public static String createURL(Exchange exchange, NettyHttpEndpoint endpoint) throws URISyntaxException {
    String uri = endpoint.getEndpointUri();

    // resolve placeholders in uri
    try {
        uri = exchange.getContext().resolvePropertyPlaceholders(uri);
    } catch (Exception e) {
        throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uri, exchange, e);
    }

    // append HTTP_PATH to HTTP_URI if it is provided in the header
    String path = exchange.getIn().getHeader(Exchange.HTTP_PATH, String.class);
    // NOW the HTTP_PATH is just related path, we don't need to trim it
    if (path != null) {
        if (path.startsWith("/")) {
            path = path.substring(1);
        }

        if (path.length() > 0) {
            // inject the dynamic path before the query params, if there are any
            int idx = uri.indexOf("?");

            // if there are no query params
            if (idx == -1) {
                // make sure that there is exactly one "/" between HTTP_URI and HTTP_PATH
                uri = uri.endsWith("/") ? uri : uri + "/";
                uri = uri.concat(path);
            } else {
                // there are query params, so inject the relative path in the right place
                String base = uri.substring(0, idx);
                base = base.endsWith("/") ? base : base + "/";
                base = base.concat(path);
                uri = base.concat(uri.substring(idx));
            }
        }
    }

    // ensure uri is encoded to be valid
    uri = UnsafeUriCharactersEncoder.encodeHttpURI(uri);

    return uri;
}
项目:Camel    文件:CxfEndpoint.java   
protected void updateEndpointUri(String endpointUri) {
    super.setEndpointUri(UnsafeUriCharactersEncoder.encodeHttpURI(endpointUri));
}
项目:Camel    文件:CxfEndpoint.java   
/**
 * The service publish address.
 */
public void setAddress(String address) {
    super.setEndpointUri(UnsafeUriCharactersEncoder.encodeHttpURI(address));
    this.address = address;
}
项目:Camel    文件:ServletComponent.java   
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    // must extract well known parameters before we create the endpoint
    Boolean throwExceptionOnFailure = getAndRemoveParameter(parameters, "throwExceptionOnFailure", Boolean.class);
    Boolean transferException = getAndRemoveParameter(parameters, "transferException", Boolean.class);
    Boolean bridgeEndpoint = getAndRemoveParameter(parameters, "bridgeEndpoint", Boolean.class);
    HttpBinding binding = resolveAndRemoveReferenceParameter(parameters, "httpBinding", HttpBinding.class);
    Boolean matchOnUriPrefix = getAndRemoveParameter(parameters, "matchOnUriPrefix", Boolean.class);
    String servletName = getAndRemoveParameter(parameters, "servletName", String.class, getServletName());
    String httpMethodRestrict = getAndRemoveParameter(parameters, "httpMethodRestrict", String.class);
    HeaderFilterStrategy headerFilterStrategy = resolveAndRemoveReferenceParameter(parameters, "headerFilterStrategy", HeaderFilterStrategy.class);
    Boolean async = getAndRemoveParameter(parameters, "async", Boolean.class);

    if (lenientContextPath()) {
        // the uri must have a leading slash for the context-path matching to work with servlet, and it can be something people
        // forget to add and then the servlet consumer cannot match the context-path as would have been expected
        String scheme = ObjectHelper.before(uri, ":");
        String after = ObjectHelper.after(uri, ":");
        // rebuild uri to have exactly one leading slash
        while (after.startsWith("/")) {
            after = after.substring(1);
        }
        after = "/" + after;
        uri = scheme + ":" + after;
    }

    // restructure uri to be based on the parameters left as we dont want to include the Camel internal options
    URI httpUri = URISupport.createRemainingURI(new URI(UnsafeUriCharactersEncoder.encodeHttpURI(uri)), parameters);

    ServletEndpoint endpoint = createServletEndpoint(uri, this, httpUri);
    endpoint.setServletName(servletName);
    if (async != null) {
        endpoint.setAsync(async);
    }
    if (headerFilterStrategy != null) {
        endpoint.setHeaderFilterStrategy(headerFilterStrategy);
    } else {
        setEndpointHeaderFilterStrategy(endpoint);
    }

    // prefer to use endpoint configured over component configured
    if (binding == null) {
        // fallback to component configured
        binding = getHttpBinding();
    }
    if (binding != null) {
        endpoint.setBinding(binding);
    }
    // should we use an exception for failed error codes?
    if (throwExceptionOnFailure != null) {
        endpoint.setThrowExceptionOnFailure(throwExceptionOnFailure);
    }
    // should we transfer exception as serialized object
    if (transferException != null) {
        endpoint.setTransferException(transferException);
    }
    if (bridgeEndpoint != null) {
        endpoint.setBridgeEndpoint(bridgeEndpoint);
    }
    if (matchOnUriPrefix != null) {
        endpoint.setMatchOnUriPrefix(matchOnUriPrefix);
    }
    if (httpMethodRestrict != null) {
        endpoint.setHttpMethodRestrict(httpMethodRestrict);
    }

    setProperties(endpoint, parameters);
    return endpoint;
}
项目:Camel    文件:HttpHelper.java   
/**
 * Creates the URL to invoke.
 *
 * @param exchange the exchange
 * @param endpoint the endpoint
 * @return the URL to invoke
 */
public static String createURL(Exchange exchange, HttpCommonEndpoint endpoint) {
    String uri = null;
    if (!(endpoint.isBridgeEndpoint())) {
        uri = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
    }
    if (uri == null) {
        uri = endpoint.getHttpUri().toASCIIString();
    }

    // resolve placeholders in uri
    try {
        uri = exchange.getContext().resolvePropertyPlaceholders(uri);
    } catch (Exception e) {
        throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uri, exchange, e);
    }

    // append HTTP_PATH to HTTP_URI if it is provided in the header
    String path = exchange.getIn().getHeader(Exchange.HTTP_PATH, String.class);
    // NOW the HTTP_PATH is just related path, we don't need to trim it
    if (path != null) {
        if (path.length() > 1 && path.startsWith("/")) {
            path = path.substring(1);
        }
        if (path.length() > 0) {
            // inject the dynamic path before the query params, if there are any
            int idx = uri.indexOf("?");

            // if there are no query params
            if (idx == -1) {
                // make sure that there is exactly one "/" between HTTP_URI and HTTP_PATH
                uri = uri.endsWith("/") || path.startsWith("/") ? uri : uri + "/";
                uri = uri.concat(path);
            } else {
                // there are query params, so inject the relative path in the right place
                String base = uri.substring(0, idx);
                base = base.endsWith("/") ? base : base + "/";
                base = base.concat(path);
                uri = base.concat(uri.substring(idx));
            }
        }
    }

    // ensure uri is encoded to be valid
    uri = UnsafeUriCharactersEncoder.encodeHttpURI(uri);

    return uri;
}
项目:Camel    文件:JmsEndpoint.java   
/**
 * Creates a pub-sub endpoint with the given destination
 */
public JmsEndpoint(String endpointUri, String destinationName) {
    this(UnsafeUriCharactersEncoder.encode(endpointUri), destinationName, true);
}
项目:Camel    文件:NettyHttpHelper.java   
/**
 * Creates the URL to invoke.
 *
 * @param exchange the exchange
 * @param endpoint the endpoint
 * @return the URL to invoke
 */
public static String createURL(Exchange exchange, NettyHttpEndpoint endpoint) throws URISyntaxException {
    String uri = endpoint.getEndpointUri();

    // resolve placeholders in uri
    try {
        uri = exchange.getContext().resolvePropertyPlaceholders(uri);
    } catch (Exception e) {
        throw new RuntimeExchangeException("Cannot resolve property placeholders with uri: " + uri, exchange, e);
    }

    // append HTTP_PATH to HTTP_URI if it is provided in the header
    String path = exchange.getIn().getHeader(Exchange.HTTP_PATH, String.class);
    // NOW the HTTP_PATH is just related path, we don't need to trim it
    if (path != null) {
        if (path.startsWith("/")) {
            path = path.substring(1);
        }

        if (path.length() > 0) {
            // inject the dynamic path before the query params, if there are any
            int idx = uri.indexOf("?");

            // if there are no query params
            if (idx == -1) {
                // make sure that there is exactly one "/" between HTTP_URI and HTTP_PATH
                uri = uri.endsWith("/") ? uri : uri + "/";
                uri = uri.concat(path);
            } else {
                // there are query params, so inject the relative path in the right place
                String base = uri.substring(0, idx);
                base = base.endsWith("/") ? base : base + "/";
                base = base.concat(path);
                uri = base.concat(uri.substring(idx));
            }
        }
    }

    // ensure uri is encoded to be valid
    uri = UnsafeUriCharactersEncoder.encodeHttpURI(uri);

    return uri;
}
项目:Camel    文件:IrcEndpoint.java   
public IrcEndpoint(String endpointUri, IrcComponent component, IrcConfiguration configuration) {
    super(UnsafeUriCharactersEncoder.encode(endpointUri), component);
    this.component = component;
    this.configuration = configuration;
}