@Override
	public Message<?> toMessage(Object payload, MessageHeaders header) {
		Assert.isInstanceOf(HttpRequest.class, payload);
		HttpRequest request = (HttpRequest) payload;
		ChannelBuffer content = request.getContent();
		Charset charsetToUse = null;
		boolean binary = false;
		if (content.readable()) {
			Map<String, String> messageHeaders = new HashMap<String, String>();
			for (Entry<String, String> entry : request.getHeaders()) {
				if (entry.getKey().equalsIgnoreCase("Content-Type")) {
					MediaType contentType = MediaType.parseMediaType(entry.getValue());
					charsetToUse = contentType.getCharSet();
					messageHeaders.put(MessageHeaders.CONTENT_TYPE, entry.getValue());
					binary = MediaType.APPLICATION_OCTET_STREAM.equals(contentType);
				}
				else if (!entry.getKey().toUpperCase().startsWith("ACCEPT")
						&& !entry.getKey().toUpperCase().equals("CONNECTION")) {
					messageHeaders.put(entry.getKey(), entry.getValue());
				}
			}
			messageHeaders.put("requestPath", request.getUri());
			messageHeaders.put("requestMethod", request.getMethod().toString());
			addHeaders(messageHeaders, request);
			try {
				AbstractIntegrationMessageBuilder<?> builder;
				if (binary) {
					builder = this.messageBuilderFactory.withPayload(toByteArray(content));
				}
				else {
					// ISO-8859-1 is the default http charset when not set
					charsetToUse = charsetToUse == null ? Charset.forName("ISO-8859-1") : charsetToUse;
					builder = this.messageBuilderFactory.withPayload(content.toString(charsetToUse));
				}
				builder.copyHeaders(messageHeaders);
				return builder.build();
			}
			catch (Exception ex) {
				throw new MessageConversionException("Failed to convert netty event to a Message", ex);
			}
		}
		else {
			return null;
		}
	}
Message converter (inbound only) to convert a Netty Http MessageEvent to
a Message. Returns null if the content is not readable.

@author Mark Fisher
@author Jennifer Hickey
@author Gary Russell
@author Marius Bogoevici
@author Peter Rietzler
extensions/spring-xd-extension-http/src/main/java/org/springframework/integration/x/http/NettyInboundMessageConverter.java