Author: davsclaus
Date: Tue Apr 30 09:28:58 2013
New Revision: 1477519
URL: http://svn.apache.org/r1477519
Log:
CAMEL-6327: More work on new camel-netty-http component.
Added:
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHeaderFilterStrategy.java
Modified:
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerChannelHandler.java
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpBinding.java
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConverter.java
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java
Modified:
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java?rev=1477519&r1=1477518&r2=1477519&view=diff
==============================================================================
---
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
(original)
+++
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/DefaultHttpBinding.java
Tue Apr 30 09:28:58 2013
@@ -268,7 +268,7 @@ public class DefaultHttpBinding implemen
}
// set the content type in the response.
String contentType = MessageHelper.getContentType(message);
- if (MessageHelper.getContentType(message) != null) {
+ if (contentType != null) {
response.setContentType(contentType);
}
Modified:
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java?rev=1477519&r1=1477518&r2=1477519&view=diff
==============================================================================
---
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
(original)
+++
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultNettyHttpBinding.java
Tue Apr 30 09:28:58 2013
@@ -16,10 +16,17 @@
*/
package org.apache.camel.component.netty.http;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
+import org.apache.camel.TypeConverter;
+import org.apache.camel.spi.HeaderFilterStrategy;
+import org.apache.camel.util.MessageHelper;
+import org.apache.camel.util.ObjectHelper;
+import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
import org.jboss.netty.handler.codec.http.HttpHeaders;
@@ -33,20 +40,38 @@ import org.jboss.netty.handler.codec.htt
*/
public class DefaultNettyHttpBinding implements NettyHttpBinding {
+ private HeaderFilterStrategy headerFilterStrategy;
+
+ public DefaultNettyHttpBinding() {
+ }
+
+ public DefaultNettyHttpBinding(HeaderFilterStrategy headerFilterStrategy) {
+ this.headerFilterStrategy = headerFilterStrategy;
+ }
+
@Override
- public Message toCamelMessage(HttpRequest request, Exchange exchange) {
+ public Message toCamelMessage(HttpRequest request, Exchange exchange)
throws Exception {
NettyHttpMessage answer = new NettyHttpMessage(request);
answer.setHeader(Exchange.HTTP_METHOD, request.getMethod().getName());
answer.setHeader(Exchange.HTTP_URI, request.getUri());
+ // populate the headers from the request
+ Map<String, Object> headers = answer.getHeaders();
+
for (String name : request.getHeaderNames()) {
+ // mapping the content-type
+ if (name.toLowerCase().equals("content-type")) {
+ name = Exchange.CONTENT_TYPE;
+ }
+ // add the headers one by one, and use the header filter strategy
List<String> values = request.getHeaders(name);
- if (values.size() == 1) {
- // flatten the list and store as single value
- answer.setHeader(name, values.get(0));
- } else {
- // if multiple values store them as list
- answer.setHeader(name, values);
+ Iterator<?> it = ObjectHelper.createIterator(values);
+ while (it.hasNext()) {
+ Object extracted = it.next();
+ if (headerFilterStrategy != null
+ &&
!headerFilterStrategy.applyFilterToExternalHeaders(name, extracted, exchange)) {
+ NettyHttpHelper.appendHeader(headers, name, extracted);
+ }
}
}
@@ -56,23 +81,70 @@ public class DefaultNettyHttpBinding imp
}
@Override
- public HttpResponse fromCamelMessage(Message msg) {
+ public HttpResponse fromCamelMessage(Message message) throws Exception {
// the status code is default 200, but a header can override that
- Integer code = msg.getHeader(Exchange.HTTP_RESPONSE_CODE, 200,
Integer.class);
+ Integer code = message.getHeader(Exchange.HTTP_RESPONSE_CODE, 200,
Integer.class);
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1,
HttpResponseStatus.valueOf(code));
- byte[] data = msg.getBody(byte[].class);
- if (data != null) {
- response.setContent(ChannelBuffers.copiedBuffer(data));
- response.setHeader(HttpHeaders.Names.CONTENT_LENGTH,
response.getContent().readableBytes());
+ TypeConverter tc =
message.getExchange().getContext().getTypeConverter();
+
+ // append headers
+ // must use entrySet to ensure case of keys is preserved
+ for (Map.Entry<String, Object> entry :
message.getHeaders().entrySet()) {
+ String key = entry.getKey();
+ Object value = entry.getValue();
+ // use an iterator as there can be multiple values. (must not use
a delimiter)
+ final Iterator<?> it = ObjectHelper.createIterator(value, null);
+ while (it.hasNext()) {
+ String headerValue = tc.convertTo(String.class, it.next());
+ if (headerValue != null && headerFilterStrategy != null
+ &&
!headerFilterStrategy.applyFilterToCamelHeaders(key, headerValue,
message.getExchange())) {
+ response.addHeader(key, headerValue);
+ }
+ }
}
- // map Camel headers to http (use header filter)
- String contentType = msg.getHeader(Exchange.CONTENT_TYPE, "text/plain;
charset=UTF-8", String.class);
- response.setHeader(HttpHeaders.Names.CONTENT_TYPE, contentType);
+ Object body = message.getBody();
+ if (body != null) {
+ // support bodies as native Netty
+ ChannelBuffer buffer;
+ if (body instanceof ChannelBuffer) {
+ buffer = (ChannelBuffer) body;
+ } else {
+ // try to convert to buffer first
+ buffer = message.getBody(ChannelBuffer.class);
+ if (buffer == null) {
+ // fallback to byte array as last resort
+ byte[] data = message.getMandatoryBody(byte[].class);
+ buffer = ChannelBuffers.copiedBuffer(data);
+ }
+ }
+ if (buffer != null) {
+ response.setContent(buffer);
+ response.setHeader(HttpHeaders.Names.CONTENT_LENGTH,
buffer.readableBytes());
+ }
+ }
+
+ // set the content type in the response.
+ String contentType = MessageHelper.getContentType(message);
+ if (contentType != null) {
+ response.setHeader(HttpHeaders.Names.CONTENT_TYPE, contentType);
+ }
+
+ // TODO: keep alive should be something we can control
response.setHeader(HttpHeaders.Names.CONNECTION,
HttpHeaders.Values.CLOSE);
return response;
}
+
+ @Override
+ public HeaderFilterStrategy getHeaderFilterStrategy() {
+ return headerFilterStrategy;
+ }
+
+ @Override
+ public void setHeaderFilterStrategy(HeaderFilterStrategy
headerFilterStrategy) {
+ this.headerFilterStrategy = headerFilterStrategy;
+ }
}
Modified:
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerChannelHandler.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerChannelHandler.java?rev=1477519&r1=1477518&r2=1477519&view=diff
==============================================================================
---
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerChannelHandler.java
(original)
+++
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerChannelHandler.java
Tue Apr 30 09:28:58 2013
@@ -99,7 +99,7 @@ public class HttpServerChannelHandler ex
}
@Override
- protected Object getResponseBody(Exchange exchange) {
+ protected Object getResponseBody(Exchange exchange) throws Exception {
// use the binding
if (exchange.hasOut()) {
return
consumer.getEndpoint().getNettyHttpBinding().fromCamelMessage(exchange.getOut());
Modified:
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpBinding.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpBinding.java?rev=1477519&r1=1477518&r2=1477519&view=diff
==============================================================================
---
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpBinding.java
(original)
+++
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpBinding.java
Tue Apr 30 09:28:58 2013
@@ -18,6 +18,7 @@ package org.apache.camel.component.netty
import org.apache.camel.Exchange;
import org.apache.camel.Message;
+import org.apache.camel.spi.HeaderFilterStrategy;
import org.jboss.netty.handler.codec.http.HttpRequest;
import org.jboss.netty.handler.codec.http.HttpResponse;
@@ -32,14 +33,31 @@ public interface NettyHttpBinding {
* @param request the netty http request
* @param exchange the exchange that should contain the returned message.
* @return the message to store on the given exchange
+ * @throws Exception is thrown if error during binding
*/
- Message toCamelMessage(HttpRequest request, Exchange exchange);
+ Message toCamelMessage(HttpRequest request, Exchange exchange) throws
Exception;
/**
* Binds from Camel {@link Message} to Netty {@link HttpResponse}.
*
- * @param msg the Camel message
+ * @param message the Camel message
* @return the http response
+ * @throws Exception is thrown if error during binding
*/
- HttpResponse fromCamelMessage(Message msg);
+ HttpResponse fromCamelMessage(Message message) throws Exception;
+
+ /**
+ * Gets the header filter strategy
+ *
+ * @return the strategy
+ */
+ HeaderFilterStrategy getHeaderFilterStrategy();
+
+ /**
+ * Sets the header filter strategy to use.
+ *
+ * @param headerFilterStrategy the custom strategy
+ */
+ void setHeaderFilterStrategy(HeaderFilterStrategy headerFilterStrategy);
+
}
Modified:
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java?rev=1477519&r1=1477518&r2=1477519&view=diff
==============================================================================
---
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
(original)
+++
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpComponent.java
Tue Apr 30 09:28:58 2013
@@ -22,21 +22,25 @@ import java.util.Map;
import org.apache.camel.Endpoint;
import org.apache.camel.component.netty.NettyComponent;
import org.apache.camel.component.netty.NettyConfiguration;
+import org.apache.camel.spi.HeaderFilterStrategy;
+import org.apache.camel.spi.HeaderFilterStrategyAware;
-public class NettyHttpComponent extends NettyComponent {
+public class NettyHttpComponent extends NettyComponent implements
HeaderFilterStrategyAware {
private NettyHttpBinding nettyHttpBinding;
+ private HeaderFilterStrategy headerFilterStrategy;
public NettyHttpComponent() {
- // use the http configuration
+ // use the http configuration and filter strategy
setConfiguration(new NettyHttpConfiguration());
+ setHeaderFilterStrategy(new NettyHttpHeaderFilterStrategy());
+ setNettyHttpBinding(new
DefaultNettyHttpBinding(getHeaderFilterStrategy()));
}
// TODO: allow to turn mapMessage=true|false
// TODO: netty http producer
// TODO: make it easy to turn chunked on|off
// TODO: make it easy to turn compression on|off
- // TODO: use HeaderFilterStrategy to filter headers
// TODO: add logging
@Override
@@ -53,10 +57,17 @@ public class NettyHttpComponent extends
// validate config
config.validateConfiguration();
- NettyHttpEndpoint nettyEndpoint = new NettyHttpEndpoint(remaining,
this, config);
- nettyEndpoint.setTimer(getTimer());
- setProperties(nettyEndpoint.getConfiguration(), parameters);
- return nettyEndpoint;
+ NettyHttpEndpoint answer = new NettyHttpEndpoint(remaining, this,
config);
+ answer.setTimer(getTimer());
+ setProperties(answer.getConfiguration(), parameters);
+ // set component options on endpoint as defaults
+ if (answer.getNettyHttpBinding() == null) {
+ answer.setNettyHttpBinding(getNettyHttpBinding());
+ }
+ if (answer.getHeaderFilterStrategy() == null) {
+ answer.setHeaderFilterStrategy(getHeaderFilterStrategy());
+ }
+ return answer;
}
@Override
@@ -77,4 +88,12 @@ public class NettyHttpComponent extends
public void setNettyHttpBinding(NettyHttpBinding nettyHttpBinding) {
this.nettyHttpBinding = nettyHttpBinding;
}
+
+ public HeaderFilterStrategy getHeaderFilterStrategy() {
+ return headerFilterStrategy;
+ }
+
+ public void setHeaderFilterStrategy(HeaderFilterStrategy
headerFilterStrategy) {
+ this.headerFilterStrategy = headerFilterStrategy;
+ }
}
Modified:
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java?rev=1477519&r1=1477518&r2=1477519&view=diff
==============================================================================
---
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
(original)
+++
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpEndpoint.java
Tue Apr 30 09:28:58 2013
@@ -23,21 +23,20 @@ import org.apache.camel.Processor;
import org.apache.camel.component.netty.NettyConfiguration;
import org.apache.camel.component.netty.NettyConstants;
import org.apache.camel.component.netty.NettyEndpoint;
+import org.apache.camel.spi.HeaderFilterStrategy;
+import org.apache.camel.spi.HeaderFilterStrategyAware;
+import org.apache.camel.util.ObjectHelper;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.handler.codec.http.HttpRequest;
-public class NettyHttpEndpoint extends NettyEndpoint {
+public class NettyHttpEndpoint extends NettyEndpoint implements
HeaderFilterStrategyAware {
private NettyHttpBinding nettyHttpBinding;
+ private HeaderFilterStrategy headerFilterStrategy;
public NettyHttpEndpoint(String endpointUri, NettyHttpComponent component,
NettyConfiguration configuration) {
super(endpointUri, component, configuration);
- this.nettyHttpBinding = component.getNettyHttpBinding();
- // ensure a default binding is created if not configured on component
- if (this.nettyHttpBinding == null) {
- this.nettyHttpBinding = new DefaultNettyHttpBinding();
- }
}
@Override
@@ -48,7 +47,7 @@ public class NettyHttpEndpoint extends N
}
@Override
- public Exchange createExchange(ChannelHandlerContext ctx, MessageEvent
messageEvent) {
+ public Exchange createExchange(ChannelHandlerContext ctx, MessageEvent
messageEvent) throws Exception {
Exchange exchange = createExchange();
// use the http binding
@@ -76,4 +75,20 @@ public class NettyHttpEndpoint extends N
public void setNettyHttpBinding(NettyHttpBinding nettyHttpBinding) {
this.nettyHttpBinding = nettyHttpBinding;
}
+
+ public HeaderFilterStrategy getHeaderFilterStrategy() {
+ return headerFilterStrategy;
+ }
+
+ public void setHeaderFilterStrategy(HeaderFilterStrategy
headerFilterStrategy) {
+ this.headerFilterStrategy = headerFilterStrategy;
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+
+ ObjectHelper.notNull(nettyHttpBinding, "nettyHttpBinding", this);
+ ObjectHelper.notNull(headerFilterStrategy, "headerFilterStrategy",
this);
+ }
}
Added:
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHeaderFilterStrategy.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHeaderFilterStrategy.java?rev=1477519&view=auto
==============================================================================
---
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHeaderFilterStrategy.java
(added)
+++
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHeaderFilterStrategy.java
Tue Apr 30 09:28:58 2013
@@ -0,0 +1,52 @@
+/**
+ * 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.netty.http;
+
+import org.apache.camel.impl.DefaultHeaderFilterStrategy;
+import org.apache.camel.spi.HeaderFilterStrategy;
+
+/**
+ * Default Netty {@link HeaderFilterStrategy} used when binding with {@link
NettyHttpBinding}.
+ */
+public class NettyHttpHeaderFilterStrategy extends DefaultHeaderFilterStrategy
{
+
+ public NettyHttpHeaderFilterStrategy() {
+ initialize();
+ }
+
+ protected void initialize() {
+ getOutFilter().add("content-length");
+ getOutFilter().add("content-type");
+ // Add the filter for the Generic Message header
+ // http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.5
+ getOutFilter().add("cache-control");
+ getOutFilter().add("connection");
+ getOutFilter().add("date");
+ getOutFilter().add("pragma");
+ getOutFilter().add("trailer");
+ getOutFilter().add("transfer-encoding");
+ getOutFilter().add("upgrade");
+ getOutFilter().add("via");
+ getOutFilter().add("warning");
+
+ setLowerCase(true);
+
+ // filter headers begin with "Camel" or "org.apache.camel"
+ // must ignore case for Http based transports
+
setOutFilterPattern("(?i)(Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*");
+ }
+}
Modified:
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java?rev=1477519&r1=1477518&r2=1477519&view=diff
==============================================================================
---
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java
(original)
+++
camel/trunk/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java
Tue Apr 30 09:28:58 2013
@@ -16,6 +16,10 @@
*/
package org.apache.camel.component.netty.http;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
import org.apache.camel.Exchange;
import org.apache.camel.converter.IOConverter;
@@ -39,4 +43,32 @@ public final class NettyHttpHelper {
}
}
+ /**
+ * Appends the key/value to the headers.
+ * <p/>
+ * This implementation supports keys with multiple values. In such
situations the value
+ * will be a {@link java.util.List} that contains the multiple values.
+ *
+ * @param headers headers
+ * @param key the key
+ * @param value the value
+ */
+ @SuppressWarnings("unchecked")
+ public static void appendHeader(Map<String, Object> headers, String key,
Object value) {
+ if (headers.containsKey(key)) {
+ Object existing = headers.get(key);
+ List<Object> list;
+ if (existing instanceof List) {
+ list = (List<Object>) existing;
+ } else {
+ list = new ArrayList<Object>();
+ list.add(existing);
+ }
+ list.add(value);
+ value = list;
+ }
+
+ headers.put(key, value);
+ }
+
}
Modified:
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConverter.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConverter.java?rev=1477519&r1=1477518&r2=1477519&view=diff
==============================================================================
---
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConverter.java
(original)
+++
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyConverter.java
Tue Apr 30 09:28:58 2013
@@ -25,7 +25,7 @@ import org.apache.camel.Converter;
import org.apache.camel.Exchange;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBufferInputStream;
-import org.jboss.netty.buffer.DynamicChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
/**
* A set of converter methods for working with Netty types
@@ -67,8 +67,20 @@ public final class NettyConverter {
@Converter
public static ChannelBuffer toByteBuffer(byte[] bytes) {
- ChannelBuffer buf = new DynamicChannelBuffer(bytes.length);
+ ChannelBuffer buf = ChannelBuffers.dynamicBuffer(bytes.length);
buf.writeBytes(bytes);
return buf;
}
+
+ @Converter
+ public static ChannelBuffer toByteBuffer(String s, Exchange exchange) {
+ byte[] bytes;
+ if (exchange != null) {
+ // use type converter as it can handle encoding set on the Exchange
+ bytes =
exchange.getContext().getTypeConverter().convertTo(byte[].class, exchange, s);
+ } else {
+ bytes = s.getBytes();
+ }
+ return toByteBuffer(bytes);
+ }
}
Modified:
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java?rev=1477519&r1=1477518&r2=1477519&view=diff
==============================================================================
---
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java
(original)
+++
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/NettyEndpoint.java
Tue Apr 30 09:28:58 2013
@@ -51,7 +51,7 @@ public class NettyEndpoint extends Defau
}
}
- public Exchange createExchange(ChannelHandlerContext ctx, MessageEvent
messageEvent) {
+ public Exchange createExchange(ChannelHandlerContext ctx, MessageEvent
messageEvent) throws Exception {
Exchange exchange = createExchange();
exchange.getIn().setHeader(NettyConstants.NETTY_CHANNEL_HANDLER_CONTEXT, ctx);
exchange.getIn().setHeader(NettyConstants.NETTY_MESSAGE_EVENT,
messageEvent);
Modified:
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java?rev=1477519&r1=1477518&r2=1477519&view=diff
==============================================================================
---
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java
(original)
+++
camel/trunk/components/camel-netty/src/main/java/org/apache/camel/component/netty/handlers/ServerChannelHandler.java
Tue Apr 30 09:28:58 2013
@@ -174,8 +174,9 @@ public class ServerChannelHandler extend
*
* @param exchange the exchange
* @return the object to use as response
+ * @throws Exception is thrown if error getting the response body
*/
- protected Object getResponseBody(Exchange exchange) {
+ protected Object getResponseBody(Exchange exchange) throws Exception {
if (exchange.hasOut()) {
return NettyPayloadHelper.getOut(consumer.getEndpoint(), exchange);
} else {