You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2009/05/14 09:41:39 UTC
svn commit: r774672 - in /camel/branches/camel-1.x: ./
components/camel-http/src/main/java/org/apache/camel/component/http/
components/camel-http/src/main/java/org/apache/camel/component/http/helper/
Author: ningjiang
Date: Thu May 14 07:41:38 2009
New Revision: 774672
URL: http://svn.apache.org/viewvc?rev=774672&view=rev
Log:
Merged revisions 774658-774659 via svnmerge from
https://svn.apache.org/repos/asf/camel/trunk
........
r774658 | ningjiang | 2009-05-14 14:46:16 +0800 (Thu, 14 May 2009) | 1 line
CAMEL-1609 Better fixing the issue of Content type setting for HTTP producer
........
r774659 | ningjiang | 2009-05-14 14:53:45 +0800 (Thu, 14 May 2009) | 1 line
CAMEL-1609 removed the duplicated code from HttpMessage
........
Modified:
camel/branches/camel-1.x/ (props changed)
camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpHeaderFilterStrategy.java
camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java
camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java
camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java
Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu May 14 07:41:38 2009
@@ -1 +1 @@
-/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752418,752751-752755,752764-752773,752956,753087,753101,753175,755136,755487,756313,756348,756870,756939,757636,757693,757743,757865,758539,758563,758600,758617,758692,758990,759362,759453,759887,759931,760003,760890,760909,760937,761194,761536,761583,761607,762047,762633,762650,762935,763095,763484,763551,765154,765686,765729,765743,765824,766016,766289,766584,766588,766590,766602,766673,767403,767824,768342,769239,769346,769368,769434,770172,770906,771303,773193,773446,773781,774192,774383
+/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752418,752751-752755,752764-752773,752956,753087,753101,753175,755136,755487,756313,756348,756870,756939,757636,757693,757743,757865,758539,758563,758600,758617,758692,758990,759362,759453,759887,759931,760003,760890,760909,760937,761194,761536,761583,761607,762047,762633,762650,762935,763095,763484,763551,765154,765686,765729,765743,765824,766016,766289,766584,766588,766590,766602,766673,767403,767824,768342,769239,769346,769368,769434,770172,770906,771303,773193,773446,773781,774192,774383,774658-774659
Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java?rev=774672&r1=774671&r2=774672&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java (original)
+++ camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java Thu May 14 07:41:38 2009
@@ -17,12 +17,11 @@
package org.apache.camel.component.http;
import java.io.ByteArrayOutputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
import java.io.PrintWriter;
-import java.util.zip.GZIPOutputStream;
+import java.util.Enumeration;
+import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
@@ -52,7 +51,36 @@
public void readRequest(HttpServletRequest request, HttpMessage message) {
// lets force a parse of the body and headers
message.getBody();
- message.getHeaders();
+ // populate the headers from the request
+ Map<String, Object> headers = message.getHeaders();
+
+ //apply the headerFilterStrategy
+ Enumeration names = request.getHeaderNames();
+ while (names.hasMoreElements()) {
+ String name = (String)names.nextElement();
+ Object value = request.getHeader(name);
+ if (headerFilterStrategy != null
+ && !headerFilterStrategy.applyFilterToExternalHeaders(name, value)) {
+ headers.put(name, value);
+ }
+ }
+
+ //if the request method is Get, we also populate the http request parameters
+ if (request.getMethod().equalsIgnoreCase("GET")) {
+ names = request.getParameterNames();
+ while (names.hasMoreElements()) {
+ String name = (String)names.nextElement();
+ Object value = request.getParameter(name);
+ if (headerFilterStrategy != null
+ && !headerFilterStrategy.applyFilterToExternalHeaders(name, value)) {
+ headers.put(name, value);
+ }
+ }
+ }
+
+ // store the method and query and other info in headers
+ headers.put(HttpMethods.HTTP_METHOD, request.getMethod());
+ headers.put(HttpProducer.QUERY, request.getQueryString());
}
public void writeResponse(HttpExchange exchange, HttpServletResponse response) throws IOException {
Modified: camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpHeaderFilterStrategy.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpHeaderFilterStrategy.java?rev=774672&r1=774671&r2=774672&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpHeaderFilterStrategy.java (original)
+++ camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpHeaderFilterStrategy.java Thu May 14 07:41:38 2009
@@ -29,7 +29,8 @@
}
protected void initialize() {
- getOutFilter().add("content-length");
+ getOutFilter().add("content-length");
+ getOutFilter().add("content-type");
getOutFilter().add(HttpMethods.HTTP_METHOD.toLowerCase());
getOutFilter().add(HttpProducer.QUERY);
getOutFilter().add(HttpProducer.HTTP_RESPONSE_CODE.toLowerCase());
Modified: camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java?rev=774672&r1=774671&r2=774672&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java (original)
+++ camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpMessage.java Thu May 14 07:41:38 2009
@@ -56,30 +56,5 @@
} catch (IOException e) {
throw new RuntimeCamelException(e);
}
- }
-
- @Override
- protected void populateInitialHeaders(Map<String, Object> map) {
- // populate the http request headers
- Enumeration names = request.getHeaderNames();
- while (names.hasMoreElements()) {
- String name = (String)names.nextElement();
- Object value = request.getHeader(name);
- map.put(name, value);
- }
-
- //if the request method is Get, we also populate the http request parameters
- if (request.getMethod().equalsIgnoreCase("GET")) {
- names = request.getParameterNames();
- while (names.hasMoreElements()) {
- String name = (String)names.nextElement();
- Object value = request.getParameter(name);
- map.put(name, value);
- }
- }
-
- // store the method and query as well
- map.put(HttpMethods.HTTP_METHOD, request.getMethod());
- map.put(HttpProducer.QUERY, request.getQueryString());
- }
+ }
}
Modified: camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java?rev=774672&r1=774671&r2=774672&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java (original)
+++ camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java Thu May 14 07:41:38 2009
@@ -33,6 +33,8 @@
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.MessageHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
@@ -209,6 +211,9 @@
}
if (methodToUse.isEntityEnclosing()) {
((EntityEnclosingMethod)method).setRequestEntity(requestEntity);
+ if (requestEntity.getContentType() == null) {
+ LOG.warn("Missing the ContentType in the request entity for the URI " + uri + ". The method is " + method);
+ }
}
return method;
@@ -225,13 +230,14 @@
if (in.getBody() == null) {
return null;
}
+
try {
return in.getBody(RequestEntity.class);
} catch (NoTypeConversionAvailableException ex) {
try {
String data = in.getBody(String.class);
if (data != null) {
- String contentType = in.getHeader("Content-Type", String.class);
+ String contentType = ExchangeHelper.getContentType(exchange);
String charset = exchange.getProperty(Exchange.CHARSET_NAME, String.class);
return new StringRequestEntity(data, contentType, charset);
} else {
@@ -241,7 +247,7 @@
} catch (UnsupportedEncodingException e) {
throw new RuntimeCamelException(e);
}
- }
+ }
}
public HttpClient getHttpClient() {
Modified: camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java?rev=774672&r1=774671&r2=774672&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java (original)
+++ camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/RequestEntityConverter.java Thu May 14 07:41:38 2009
@@ -29,6 +29,7 @@
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.component.http.helper.GZIPHelper;
+import org.apache.camel.util.ExchangeHelper;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.RequestEntity;
@@ -45,36 +46,38 @@
@Converter
public RequestEntity toRequestEntity(ByteBuffer buffer, Exchange exchange) throws Exception {
return new InputStreamRequestEntity(
- GZIPHelper.toGZIPInputStreamIfRequested(
- (String) exchange.getIn().getHeader(GZIPHelper.CONTENT_ENCODING),
- buffer.array()));
- }
+ GZIPHelper.toGZIPInputStreamIfRequested(
+ exchange.getIn().getHeader(GZIPHelper.CONTENT_ENCODING, String.class),
+ buffer.array()), ExchangeHelper.getContentType(exchange));
+ }
@Converter
public RequestEntity toRequestEntity(byte[] array, Exchange exchange) throws Exception {
return new InputStreamRequestEntity(
- GZIPHelper.toGZIPInputStreamIfRequested(
- (String) exchange.getIn().getHeader(GZIPHelper.CONTENT_ENCODING),
- array));
- }
+ GZIPHelper.toGZIPInputStreamIfRequested(
+ exchange.getIn().getHeader(GZIPHelper.CONTENT_ENCODING, String.class),
+ array), ExchangeHelper.getContentType(exchange));
+ }
@Converter
public RequestEntity toRequestEntity(InputStream inStream, Exchange exchange) throws Exception {
return new InputStreamRequestEntity(
- GZIPHelper.getGZIPWrappedInputStream(
- (String) exchange.getIn().getHeader(GZIPHelper.CONTENT_ENCODING),
- inStream));
- }
-
+ GZIPHelper.getGZIPWrappedInputStream(
+ exchange.getIn().getHeader(GZIPHelper.CONTENT_ENCODING, String.class),
+ inStream), ExchangeHelper.getContentType(exchange));
+ }
@Converter
public RequestEntity toRequestEntity(String str, Exchange exchange) throws Exception {
- return new InputStreamRequestEntity(
- GZIPHelper.toGZIPInputStreamIfRequested(
- (String) exchange.getIn().getHeader(GZIPHelper.CONTENT_ENCODING),
- str.getBytes()));
- }
-
-
+ if (GZIPHelper.containsGzip(exchange.getIn().getHeader(GZIPHelper.CONTENT_ENCODING, String.class))) {
+ return new InputStreamRequestEntity(
+ GZIPHelper.toGZIPInputStreamIfRequested(
+ exchange.getIn().getHeader(GZIPHelper.CONTENT_ENCODING, String.class),
+ str.getBytes()), ExchangeHelper.getContentType(exchange));
+ } else {
+ // will use the default StringRequestEntity
+ return null;
+ }
+ }
}
Modified: camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java?rev=774672&r1=774671&r2=774672&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java (original)
+++ camel/branches/camel-1.x/components/camel-http/src/main/java/org/apache/camel/component/http/helper/GZIPHelper.java Thu May 14 07:41:38 2009
@@ -124,7 +124,7 @@
return compressed;
}
- private static boolean containsGzip(String str) {
+ public static boolean containsGzip(String str) {
return str != null && str.toLowerCase().indexOf(GZIP) >= 0;
}