Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
*/
package org.apache.camel.component.http4;

import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.apache.camel.Endpoint;
import org.apache.camel.ResolveEndpointFailedException;
import org.apache.camel.component.http4.helper.HttpHelper;
Expand Down Expand Up @@ -51,6 +46,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
* Defines the <a href="http://camel.apache.org/http4.html">HTTP4
* Component</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
*/
package org.apache.camel.component.http4;

import java.net.URI;
import java.net.URISyntaxException;

import org.apache.camel.PollingConsumer;
import org.apache.camel.Producer;
import org.apache.camel.RuntimeCamelException;
Expand All @@ -30,18 +27,18 @@
import org.apache.http.HttpHost;
import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpClient;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.DefaultedHttpContext;
import org.apache.http.protocol.HttpContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;
import java.net.URISyntaxException;

/**
* Represents a <a href="http://camel.apache.org/http.html">HTTP endpoint</a>
*
Expand All @@ -66,6 +63,7 @@ public class HttpEndpoint extends DefaultPollingEndpoint implements HeaderFilter
private boolean disableStreamCache;
private boolean transferException;
private boolean traceEnabled;
private boolean preemptiveAuth;
private String httpMethodRestrict;
private UrlRewrite urlRewrite;
private boolean clearExpiredCookies = true;
Expand Down Expand Up @@ -377,4 +375,12 @@ public CookieStore getCookieStore() {
public void setCookieStore(CookieStore cookieStore) {
this.cookieStore = cookieStore;
}

public boolean isPreemptiveAuth() {
return preemptiveAuth;
}

public void setPreemptiveAuth(boolean preemptiveAuth) {
this.preemptiveAuth = preemptiveAuth;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@
*/
package org.apache.camel.component.http4;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.camel.CamelExchangeException;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
Expand All @@ -40,31 +24,31 @@
import org.apache.camel.converter.stream.CachedOutputStream;
import org.apache.camel.impl.DefaultProducer;
import org.apache.camel.spi.HeaderFilterStrategy;
import org.apache.camel.util.ExchangeHelper;
import org.apache.camel.util.GZIPHelper;
import org.apache.camel.util.IOHelper;
import org.apache.camel.util.MessageHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.URISupport;
import org.apache.camel.util.*;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.FileEntity;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.*;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.*;

/**
* @version
*/
Expand All @@ -83,6 +67,11 @@ public HttpProducer(HttpEndpoint endpoint) {
this.transferException = endpoint.isTransferException();
}

@Override
public HttpEndpoint getEndpoint() {
return (HttpEndpoint) super.getEndpoint();
}

public void process(Exchange exchange) throws Exception {

if (getEndpoint().isClearExpiredCookies()) {
Expand All @@ -102,10 +91,17 @@ public void process(Exchange exchange) throws Exception {
if (queryString != null) {
skipRequestHeaders = URISupport.parseQuery(queryString);
}
// Need to remove the Host key as it should be not used
// Need to remove the Host key as it should be not used
exchange.getIn().getHeaders().remove("host");
}

HttpRequestBase httpRequest = createMethod(exchange);

if (getEndpoint().isPreemptiveAuth()) {
Credentials creds = ((DefaultHttpClient) httpClient).getCredentialsProvider().getCredentials(AuthScope.ANY);
httpRequest.addHeader(BasicScheme.authenticate(creds, Charset.defaultCharset().displayName(), false));
}

Message in = exchange.getIn();
String httpProtocolVersion = in.getHeader(Exchange.HTTP_PROTOCOL_VERSION, String.class);
if (httpProtocolVersion != null) {
Expand Down Expand Up @@ -177,11 +173,6 @@ public void process(Exchange exchange) throws Exception {
}
}

@Override
public HttpEndpoint getEndpoint() {
return (HttpEndpoint) super.getEndpoint();
}

protected void populateResponse(Exchange exchange, HttpRequestBase httpRequest, HttpResponse httpResponse,
Message in, HeaderFilterStrategy strategy, int responseCode) throws IOException, ClassNotFoundException {
// We just make the out message is not create when extractResponseBody throws exception
Expand Down