Skip to content

Commit

Permalink
Merged revisions 1176787 via svnmerge from
Browse files Browse the repository at this point in the history
https://svn.apache.org/repos/asf/camel/branches/camel-2.8.x

................
  r1176787 | ningjiang | 2011-09-28 16:58:44 +0800 (Wed, 28 Sep 2011) | 13 lines
  
  Merged revisions 1176781-1176782 via svnmerge from 
  https://svn.apache.org/repos/asf/camel/trunk
  
  ........
    r1176781 | ningjiang | 2011-09-28 16:23:35 +0800 (Wed, 28 Sep 2011) | 1 line
    
    CAMEL-4497 HttpPollingConsumer Get URL should support the property place holders as HttpProducer does
  ........
    r1176782 | ningjiang | 2011-09-28 16:27:15 +0800 (Wed, 28 Sep 2011) | 1 line
    
    CAMEL-4489, CAMEL-4497 fixed the camel-http4 proxy url issue
  ........
................


git-svn-id: https://svn.apache.org/repos/asf/camel/branches/camel-2.7.x@1176792 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
WillemJiang committed Sep 28, 2011
1 parent 6b6951e commit 651ad86
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
Expand Up @@ -58,7 +58,7 @@ public Exchange receiveNoWait() {

protected Exchange doReceive(int timeout) {
Exchange exchange = endpoint.createExchange();
HttpMethod method = createMethod();
HttpMethod method = createMethod(exchange);

// set optional timeout in millis
if (timeout > 0) {
Expand Down Expand Up @@ -111,8 +111,8 @@ public void setHttpClient(HttpClient httpClient) {

// Implementation methods
//-------------------------------------------------------------------------
protected HttpMethod createMethod() {
String uri = endpoint.getEndpointUri();
protected HttpMethod createMethod(Exchange exchange) {
String uri = HttpHelper.createURL(exchange, endpoint);
return new GetMethod(uri);
}

Expand Down
Expand Up @@ -177,7 +177,15 @@ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Obje
HttpClientConfigurer configurer = createHttpClientConfigurer(parameters);
URI endpointUri = URISupport.createRemainingURI(new URI(addressUri), CastUtils.cast(httpClientParameters));
// 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(addressUri), CastUtils.cast(parameters));
// The httpUri should be start with http or https
String httpUriAddress = addressUri;
if (addressUri.startsWith("http4")) {
httpUriAddress = "http" + addressUri.substring(5);
}
if (addressUri.startsWith("https4")) {
httpUriAddress = "https" + addressUri.substring(6);
}
URI httpUri = URISupport.createRemainingURI(new URI(httpUriAddress), CastUtils.cast(parameters));

// validate http uri that end-user did not duplicate the http part that can be a common error
String part = httpUri.getSchemeSpecificPart();
Expand Down
Expand Up @@ -62,7 +62,7 @@ public Exchange receiveNoWait() {

protected Exchange doReceive(int timeout) {
Exchange exchange = endpoint.createExchange();
HttpRequestBase method = createMethod();
HttpRequestBase method = createMethod(exchange);

// set optional timeout in millis
if (timeout > 0) {
Expand Down Expand Up @@ -125,8 +125,8 @@ public void setHttpClient(HttpClient httpClient) {
// Implementation methods
//-------------------------------------------------------------------------

protected HttpRequestBase createMethod() {
String uri = endpoint.getEndpointUri();
protected HttpRequestBase createMethod(Exchange exchange) {
String uri = HttpHelper.createURL(exchange, endpoint);
return new HttpGet(uri);
}

Expand Down
Expand Up @@ -289,13 +289,7 @@ protected HttpRequestBase createMethod(Exchange exchange) throws URISyntaxExcept
+ ". If you are forwarding/bridging http endpoints, then enable the bridgeEndpoint option on the endpoint: " + getEndpoint());
}

// Changed the schema to http4 to normal http by default
String schema = "http";
if (uri.getScheme().equals("https4")) {
schema = "https";
}

StringBuilder builder = new StringBuilder(schema).append("://").append(uri.getHost());
StringBuilder builder = new StringBuilder(uri.getScheme()).append("://").append(uri.getHost());

if (uri.getPort() != -1) {
builder.append(":").append(uri.getPort());
Expand Down
Expand Up @@ -182,6 +182,15 @@ public void process(Exchange exchange) throws Exception {

assertExchange(exchange);
}

public void httpGetPullEndpointWithProxyAndWithUser() {
proxy.register("*", new ProxyAuthenticationValidationHandler("GET", null, null, getExpectedContent(), user, password));

Exchange exchange = consumer.receive("http4://" + getHostName() + ":" + getPort() + "?proxyAuthHost="
+ getProxyHost() + "&proxyAuthPort=" + getProxyPort() + "&proxyAuthUsername=camel&proxyAuthPassword=password");

assertExchange(exchange);
}

private String getProxyHost() {
return proxy.getServiceAddress().getHostName();
Expand All @@ -194,7 +203,12 @@ private int getProxyPort() {
class RequestProxyBasicAuth implements HttpRequestInterceptor {
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
String auth = null;


String requestLine = request.getRequestLine().toString();
// assert we set a write GET URI
if (requestLine.contains("http4://localhost")) {
throw new HttpException("Get a wrong proxy GET url");
}
Header h = request.getFirstHeader(AUTH.PROXY_AUTH_RESP);
if (h != null) {
String s = h.getValue();
Expand Down

0 comments on commit 651ad86

Please sign in to comment.