On Thu, May 20, 2010 at 4:14 PM,  <ningji...@apache.org> wrote:
> Author: ningjiang
> Date: Thu May 20 14:14:35 2010
> New Revision: 946640
>
> URL: http://svn.apache.org/viewvc?rev=946640&view=rev
> Log:
> CAMEL-2743 Fixed the issue of camel-http converts headers to lower case
>
> Added:
>    
> camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderTest.java
>    (with props)
> Modified:
>    
> camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
>
> Modified: 
> camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
> URL: 
> http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java?rev=946640&r1=946639&r2=946640&view=diff
> ==============================================================================
> --- 
> camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
>  (original)
> +++ 
> camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
>  Thu May 20 14:14:35 2010
> @@ -65,10 +65,10 @@ public class HttpProducer extends Defaul
>         HeaderFilterStrategy strategy = 
> getEndpoint().getHeaderFilterStrategy();
>
>         // propagate headers as HTTP headers
> -        for (String headerName : in.getHeaders().keySet()) {
> -            String headerValue = in.getHeader(headerName, String.class);
> -            if (strategy != null && 
> !strategy.applyFilterToCamelHeaders(headerName, headerValue, exchange)) {
> -                method.addRequestHeader(headerName, headerValue);
> +        for (Map.Entry<String, Object> entry : in.getHeaders().entrySet()) {
> +            String headerValue = (String) entry.getValue();

You should not cast to a String, what if the value is non string
based. You should use the Camel type converter to convert that to a
String.



> +            if (strategy != null && 
> !strategy.applyFilterToCamelHeaders(entry.getKey(), headerValue, exchange)) {
> +                method.addRequestHeader(entry.getKey(), headerValue);
>             }
>         }
>
>
> Added: 
> camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderTest.java
> URL: 
> http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderTest.java?rev=946640&view=auto
> ==============================================================================
> --- 
> camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderTest.java
>  (added)
> +++ 
> camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderTest.java
>  Thu May 20 14:14:35 2010
> @@ -0,0 +1,67 @@
> +/**
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements.  See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License.  You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +package org.apache.camel.component.jetty;
> +
> +import java.util.Map;
> +import java.util.Map.Entry;
> +
> +import org.apache.camel.Endpoint;
> +import org.apache.camel.Exchange;
> +import org.apache.camel.Processor;
> +import org.apache.camel.builder.RouteBuilder;
> +import org.apache.camel.component.jetty.JettyContentTypeTest.MyBookService;
> +import org.apache.camel.test.junit4.CamelTestSupport;
> +import org.apache.camel.util.ExchangeHelper;
> +import org.apache.camel.util.MessageHelper;
> +import org.junit.Test;
> +
> +public class HttpHeaderTest extends CamelTestSupport {
> +
> +   �...@test
> +    public void testHttpHeaders() throws Exception {
> +        String result = template.requestBody("direct:start", "hello", 
> String.class);
> +        assertEquals("Should send a right http header to the server.", "Find 
> the key!", result);
> +    }
> +
> +   �...@override
> +    protected RouteBuilder createRouteBuilder() throws Exception {
> +        return new RouteBuilder() {
> +            public void configure() throws Exception {
> +                from("direct:start").setHeader("SOAPAction", 
> constant("http://xxx.com/interfaces/ticket";))
> +                    .setHeader("Content-Type", constant("text/xml; 
> charset=utf-8"))
> +                    .to("http://localhost:9080/myapp/mytest";);
> +
> +                from("jetty:http://localhost:9080/myapp/mytest";).process(new 
> Processor() {
> +
> +                    public void process(Exchange exchange) throws Exception {
> +                        Map<String, Object> headers = 
> exchange.getIn().getHeaders();
> +                        for (Entry<String, Object> entry : 
> headers.entrySet()) {
> +                            if ("SOAPAction".equals(entry.getKey()) && 
> "http://xxx.com/interfaces/ticket".equals(entry.getValue())) {
> +                                exchange.getOut().setBody("Find the key!");
> +                                return;
> +                            }
> +                        }
> +                        exchange.getOut().setBody("Cannot find the key!");
> +                    }
> +
> +                });
> +
> +            }
> +        };
> +    }
> +
> +}
>
> Propchange: 
> camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderTest.java
> ------------------------------------------------------------------------------
>    svn:eol-style = native
>
> Propchange: 
> camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderTest.java
> ------------------------------------------------------------------------------
>    svn:keywords = Rev Date
>
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Reply via email to