You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ni...@apache.org on 2013/05/28 10:54:52 UTC

svn commit: r1486823 [2/3] - in /cxf/trunk/rt: ./ transports/http-netty/ transports/http-netty/netty-client/ transports/http-netty/netty-client/src/ transports/http-netty/netty-client/src/main/ transports/http-netty/netty-client/src/main/java/ transpor...

Added: cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngine.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngine.java?rev=1486823&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngine.java (added)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngine.java Tue May 28 08:54:49 2013
@@ -0,0 +1,142 @@
+/**
+ * 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.cxf.transport.http.netty.server;
+
+
+import java.net.InetSocketAddress;
+import java.net.URL;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executors;
+import org.apache.cxf.transport.HttpUriMapper;
+import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
+
+public class NettyHttpServerEngine implements ServerEngine {
+
+    /**
+     * This is the network port for which this engine is allocated.
+     */
+    private int port;
+
+    /**
+     * This is the network address for which this engine is allocated.
+     */
+    private String host;
+
+    /**
+     * This field holds the protocol for which this engine is
+     * enabled, i.e. "http" or "https".
+     */
+    private String protocol = "http";
+
+    private volatile Channel serverChannel;
+
+    private NettyHttpServletPipelineFactory servletPipeline;
+
+    private Map<String, NettyHttpContextHandler> handlerMap = new ConcurrentHashMap<String, NettyHttpContextHandler>();
+
+    public NettyHttpServerEngine(
+            String host,
+            int port) {
+        this.host = host;
+        this.port = port;
+    }
+
+    public String getProtocol() {
+        return protocol;
+    }
+
+    public void setProtocol(String protocol) {
+        this.protocol = protocol;
+    }
+
+    protected Channel startServer() {
+        // TODO Configure the server.
+        final ServerBootstrap bootstrap = new ServerBootstrap(
+                new NioServerSocketChannelFactory(Executors
+                        .newCachedThreadPool(), Executors.newCachedThreadPool()));
+
+        // Set up the event pipeline factory.
+        servletPipeline = new NettyHttpServletPipelineFactory(handlerMap);
+        bootstrap.setPipelineFactory(servletPipeline);
+        InetSocketAddress address = null;
+        if (host == null) {
+            address = new InetSocketAddress(port);
+        } else {
+            address = new InetSocketAddress(host, port);
+        }
+        // Bind and start to accept incoming connections.
+        return bootstrap.bind(address);
+    }
+
+
+    @Override
+    public void addServant(URL url, NettyHttpHandler handler) {
+        if (serverChannel == null) {
+            serverChannel = startServer();
+        }
+        // need to set the handler name for looking up
+        handler.setName(url.getPath());
+        String contextName = HttpUriMapper.getContextName(url.getPath());
+        // need to check if the NettyContext is there
+        NettyHttpContextHandler contextHandler = handlerMap.get(contextName);
+        if (contextHandler == null) {
+            contextHandler = new NettyHttpContextHandler(contextName);
+            handlerMap.put(contextName, contextHandler);
+        }
+        contextHandler.addNettyHttpHandler(handler);
+    }
+
+    @Override
+    public void removeServant(URL url) {
+        final String contextName = HttpUriMapper.getContextName(url.getPath());
+        NettyHttpContextHandler contextHandler = handlerMap.get(contextName);
+        if (contextHandler != null) {
+            contextHandler.removeNettyHttpHandler(url.getPath());
+            if (contextHandler.isEmpty()) {
+                // remove the contextHandler from handlerMap
+                handlerMap.remove(contextName);
+            }
+        }
+    }
+
+    @Override
+    public NettyHttpHandler getServant(URL url) {
+        final String contextName = HttpUriMapper.getContextName(url.getPath());
+        NettyHttpContextHandler contextHandler = handlerMap.get(contextName);
+        if (contextHandler != null) {
+            return contextHandler.getNettyHttpHandler(url.getPath());
+        } else {
+            return null;
+        }
+    }
+
+    public void shutdown() {
+        // just unbind the channel
+        if (serverChannel != null) {
+            serverChannel.close();
+        }
+        if (servletPipeline != null) {
+            servletPipeline.shutdown();
+        }
+    }
+}

Added: cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngineFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngineFactory.java?rev=1486823&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngineFactory.java (added)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngineFactory.java Tue May 28 08:54:49 2013
@@ -0,0 +1,151 @@
+/**
+ * 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.cxf.transport.http.netty.server;
+
+
+import java.io.IOException;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Logger;
+import javax.annotation.Resource;
+import org.apache.cxf.Bus;
+import org.apache.cxf.buslifecycle.BusLifeCycleListener;
+import org.apache.cxf.buslifecycle.BusLifeCycleManager;
+import org.apache.cxf.common.logging.LogUtils;
+
+public class NettyHttpServerEngineFactory implements BusLifeCycleListener {
+    private static final Logger LOG =
+            LogUtils.getL7dLogger(NettyHttpServerEngineFactory.class);
+
+    private static ConcurrentHashMap<Integer, NettyHttpServerEngine> portMap =
+            new ConcurrentHashMap<Integer, NettyHttpServerEngine>();
+
+    private Bus bus;
+
+    private BusLifeCycleManager lifeCycleManager;
+
+    public NettyHttpServerEngineFactory() {
+        // Empty
+    }
+
+    public NettyHttpServerEngineFactory(Bus b) {
+        setBus(b);
+    }
+
+    public Bus getBus() {
+        return bus;
+    }
+
+    /**
+     * This call is used to set the bus. It should only be called once.
+     *
+     * @param bus
+     */
+    @Resource(name = "cxf")
+    public final void setBus(Bus bus) {
+        assert this.bus == null || this.bus == bus;
+        this.bus = bus;
+        if (bus != null) {
+            bus.setExtension(this, NettyHttpServerEngineFactory.class);
+            lifeCycleManager = bus.getExtension(BusLifeCycleManager.class);
+            if (null != lifeCycleManager) {
+                lifeCycleManager.registerLifeCycleListener(this);
+            }
+        }
+    }
+
+    public void initComplete() {
+        // do nothing here
+    }
+
+    public void postShutdown() {
+        // shut down the Netty server in the portMap
+        // To avoid the CurrentModificationException,
+        // do not use portMap.values directly
+        NettyHttpServerEngine[] engines = portMap.values().toArray(new NettyHttpServerEngine[portMap.values().size()]);
+        for (NettyHttpServerEngine engine : engines) {
+            engine.shutdown();
+        }
+    }
+
+    public void preShutdown() {
+        // do nothing here
+        // just let server registry to call the server stop first
+    }
+
+    private static NettyHttpServerEngine getOrCreate(NettyHttpServerEngineFactory factory,
+                                                     String host,
+                                                     int port
+    ) throws IOException {
+
+        NettyHttpServerEngine ref = portMap.get(port);
+        if (ref == null) {
+            ref = new NettyHttpServerEngine(host, port);
+
+            NettyHttpServerEngine tmpRef = portMap.putIfAbsent(port, ref);
+
+            if (tmpRef != null) {
+                ref = tmpRef;
+            }
+        }
+        return ref;
+    }
+
+
+    public synchronized NettyHttpServerEngine retrieveNettyHttpServerEngine(int port) {
+        return portMap.get(port);
+    }
+
+
+    public synchronized NettyHttpServerEngine createNettyHttpServerEngine(String host, int port,
+                                                                          String protocol) throws IOException {
+        LOG.fine("Creating Jetty HTTP Server Engine for port " + port + ".");
+        NettyHttpServerEngine ref = getOrCreate(this, host, port);
+        // checking the protocol
+        if (!protocol.equals(ref.getProtocol())) {
+            throw new IOException("Protocol mismatch for port " + port + ": "
+                    + "engine's protocol is " + ref.getProtocol()
+                    + ", the url protocol is " + protocol);
+        }
+
+
+        return ref;
+    }
+
+    public synchronized NettyHttpServerEngine createNettyHttpServerEngine(int port,
+                                                                          String protocol) throws IOException {
+        return createNettyHttpServerEngine(null, port, protocol);
+    }
+
+    /**
+     * This method removes the Server Engine from the port map and stops it.
+     */
+    public static synchronized void destroyForPort(int port) {
+        NettyHttpServerEngine ref = portMap.remove(port);
+        if (ref != null) {
+            LOG.fine("Stopping Jetty HTTP Server Engine on port " + port + ".");
+            try {
+                ref.shutdown();
+            } catch (Exception e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+        }
+    }
+}

Added: cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServletHandler.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServletHandler.java?rev=1486823&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServletHandler.java (added)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServletHandler.java Tue May 28 08:54:49 2013
@@ -0,0 +1,230 @@
+/**
+ * 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.cxf.transport.http.netty.server;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.transport.http.netty.server.interceptor.NettyInterceptor;
+import org.apache.cxf.transport.http.netty.server.servlet.NettyHttpServletRequest;
+import org.apache.cxf.transport.http.netty.server.servlet.NettyServletResponse;
+import org.jboss.netty.buffer.ChannelBuffers;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelFuture;
+import org.jboss.netty.channel.ChannelFutureListener;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ChannelStateEvent;
+import org.jboss.netty.channel.ExceptionEvent;
+import org.jboss.netty.channel.MessageEvent;
+import org.jboss.netty.channel.group.ChannelGroup;
+import org.jboss.netty.handler.codec.frame.TooLongFrameException;
+import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
+import org.jboss.netty.handler.codec.http.HttpHeaders;
+import org.jboss.netty.handler.codec.http.HttpHeaders.Names;
+import org.jboss.netty.handler.codec.http.HttpRequest;
+import org.jboss.netty.handler.codec.http.HttpResponse;
+import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+import org.jboss.netty.handler.codec.http.HttpVersion;
+import org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler;
+import org.jboss.netty.handler.timeout.IdleStateEvent;
+import org.jboss.netty.util.CharsetUtil;
+
+
+public class NettyHttpServletHandler extends IdleStateAwareChannelHandler {
+    private static final Logger LOG =
+            LogUtils.getL7dLogger(NettyHttpServletHandler.class);
+    private final ChannelGroup allChannels;
+
+    private final NettyHttpServletPipelineFactory pipelineFactory;
+
+    private List<NettyInterceptor> interceptors;
+
+    //private List<String> contexts = new ArrayList<String>();
+
+    public NettyHttpServletHandler(NettyHttpServletPipelineFactory pipelineFactory) {
+        this.allChannels = pipelineFactory.getAllChannels();
+        this.pipelineFactory = pipelineFactory;
+    }
+
+    public NettyHttpServletHandler addInterceptor(
+            NettyInterceptor interceptor) {
+
+        if (this.interceptors == null) {
+            this.interceptors = new ArrayList<NettyInterceptor>();
+        }
+        this.interceptors.add(interceptor);
+        return this;
+    }
+
+    @Override
+    public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
+        throws Exception {
+        LOG.log(Level.FINE, "Opening new channel: {}", e.getChannel().getId());
+        // Agent map
+        allChannels.add(e.getChannel());
+    }
+
+    @Override
+    public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) {
+        LOG.log(Level.FINE, "Closing idle channel: {}", e.getChannel().getId());
+        e.getChannel().close();
+    }
+
+    @Override
+    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
+        throws Exception {
+
+        HttpRequest request = (HttpRequest) e.getMessage();
+        if (HttpHeaders.is100ContinueExpected(request)) {
+            e.getChannel().write(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE));
+        }
+
+        // find the nettyHttpContextHandler by lookup the request url
+        NettyHttpContextHandler nettyHttpContextHandler = pipelineFactory.getNettyHttpHandler(request.getUri());
+        if (nettyHttpContextHandler != null) {
+            handleHttpServletRequest(ctx, e, nettyHttpContextHandler);
+        } else {
+            throw new RuntimeException(
+                    "No handler found for uri: " + request.getUri());
+        }
+
+    }
+
+    protected void handleHttpServletRequest(ChannelHandlerContext ctx,
+                                            MessageEvent e, NettyHttpContextHandler nettyHttpContextHandler)
+        throws Exception {
+
+        interceptOnRequestReceived(ctx, e);
+
+        HttpRequest request = (HttpRequest) e.getMessage();
+        HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
+
+        NettyServletResponse nettyServletResponse = buildHttpServletResponse(response);
+        NettyHttpServletRequest nettyServletRequest = 
+            buildHttpServletRequest(request, nettyHttpContextHandler.getContextPath());
+
+        nettyHttpContextHandler.handle(request.getUri(), nettyServletRequest, nettyServletResponse);
+        interceptOnRequestSuccessed(ctx, e, response);
+
+        nettyServletResponse.getWriter().flush();
+
+        boolean keepAlive = HttpHeaders.isKeepAlive(request);
+
+        if (keepAlive) {
+            // Add 'Content-Length' header only for a keep-alive connection.
+            response.setHeader(Names.CONTENT_LENGTH, response.getContent()
+                    .readableBytes());
+            // Add keep alive header as per:
+            // -
+            // http://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-01.html#Connection
+            response.setHeader(Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
+        }
+
+        // write response...
+        ChannelFuture future = e.getChannel().write(response);
+
+        if (!keepAlive) {
+            future.addListener(ChannelFutureListener.CLOSE);
+        }
+
+    }
+
+
+    @Override
+    public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
+        Throwable cause = e.getCause();
+        LOG.log(Level.SEVERE, "Unexpected exception from downstream.", cause);
+
+        interceptOnRequestFailed(ctx, e);
+
+        Channel ch = e.getChannel();
+        if (cause instanceof IllegalArgumentException) {
+
+            ch.close();
+
+        } else {
+
+            if (cause instanceof TooLongFrameException) {
+                sendError(ctx, HttpResponseStatus.BAD_REQUEST);
+                return;
+            }
+
+            if (ch.isConnected()) {
+                sendError(ctx, HttpResponseStatus.INTERNAL_SERVER_ERROR);
+            }
+
+        }
+
+    }
+
+    private void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
+        HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, status);
+        response.setHeader(Names.CONTENT_TYPE, "text/plain; charset=UTF-8");
+        response.setContent(ChannelBuffers.copiedBuffer("Failure: "
+                + status.toString() + "\r\n", CharsetUtil.UTF_8));
+        ctx.getChannel().write(response).addListener(
+                ChannelFutureListener.CLOSE);
+    }
+
+    private void interceptOnRequestReceived(ChannelHandlerContext ctx,
+                                            MessageEvent e) {
+
+        if (this.interceptors != null) {
+            for (NettyInterceptor interceptor : this.interceptors) {
+                interceptor.onRequestReceived(ctx, e);
+            }
+        }
+
+    }
+
+    private void interceptOnRequestSuccessed(ChannelHandlerContext ctx,
+                                             MessageEvent e, HttpResponse response) {
+        if (this.interceptors != null) {
+            for (NettyInterceptor interceptor : this.interceptors) {
+                interceptor.onRequestSuccessed(ctx, e, response);
+            }
+        }
+
+    }
+
+    private void interceptOnRequestFailed(ChannelHandlerContext ctx,
+                                          ExceptionEvent e) {
+        if (this.interceptors != null) {
+            for (NettyInterceptor interceptor : this.interceptors) {
+                interceptor.onRequestFailed(ctx, e);
+            }
+        }
+
+    }
+
+    protected NettyServletResponse buildHttpServletResponse(
+            HttpResponse response) {
+        return new NettyServletResponse(response);
+    }
+
+    protected NettyHttpServletRequest buildHttpServletRequest(
+            HttpRequest request, String contextPath) {
+        return new NettyHttpServletRequest(request, contextPath);
+    }
+    
+}

Added: cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServletPipelineFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServletPipelineFactory.java?rev=1486823&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServletPipelineFactory.java (added)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/NettyHttpServletPipelineFactory.java Tue May 28 08:54:49 2013
@@ -0,0 +1,163 @@
+/**
+ * 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.cxf.transport.http.netty.server;
+
+import java.util.Map;
+import java.util.Set;
+import org.apache.cxf.transport.http.netty.server.interceptor.ChannelInterceptor;
+import org.apache.cxf.transport.http.netty.server.interceptor.HttpSessionInterceptor;
+import org.apache.cxf.transport.http.netty.server.session.DefaultHttpSessionStore;
+import org.apache.cxf.transport.http.netty.server.session.HttpSessionStore;
+import org.jboss.netty.channel.ChannelHandler;
+import org.jboss.netty.channel.ChannelPipeline;
+import org.jboss.netty.channel.ChannelPipelineFactory;
+import org.jboss.netty.channel.Channels;
+import org.jboss.netty.channel.group.ChannelGroup;
+import org.jboss.netty.channel.group.DefaultChannelGroup;
+import org.jboss.netty.handler.codec.http.HttpChunkAggregator;
+import org.jboss.netty.handler.codec.http.HttpContentCompressor;
+import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
+import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
+import org.jboss.netty.handler.execution.ExecutionHandler;
+import org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor;
+import org.jboss.netty.handler.timeout.IdleStateHandler;
+import org.jboss.netty.util.HashedWheelTimer;
+import org.jboss.netty.util.Timer;
+
+public class NettyHttpServletPipelineFactory implements ChannelPipelineFactory {
+
+    private final ChannelGroup allChannels = new DefaultChannelGroup();
+
+    private final HttpSessionWatchdog watchdog;
+
+    private final ChannelHandler idleStateHandler;
+
+    private final Timer timer;
+
+    // TODO we may need to configure the thread pool from outside
+    private final ExecutionHandler executionHandler =
+            new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(200, 2048576, 204857600));
+
+    private final Map<String, NettyHttpContextHandler> handlerMap;
+
+    public NettyHttpServletPipelineFactory(Map<String, NettyHttpContextHandler> handlerMap) {
+
+        this.timer = new HashedWheelTimer();
+        this.idleStateHandler = new IdleStateHandler(this.timer, 60, 30, 0);
+        this.watchdog = new HttpSessionWatchdog();
+        this.handlerMap = handlerMap;
+        new Thread(watchdog).start();
+    }
+
+
+    public Map<String, NettyHttpContextHandler> getHttpContextHandlerMap() {
+        return handlerMap;
+    }
+
+    public ChannelGroup getAllChannels() {
+        return allChannels;
+    }
+
+    public NettyHttpContextHandler getNettyHttpHandler(String url) {
+        Set<String> keySet = handlerMap.keySet();
+        for (String key : keySet) {
+            // Here just check the context path first
+            if (url.startsWith(key)) {
+                return handlerMap.get(key);
+            }
+        }
+        return null;
+    }
+
+    public void shutdown() {
+        this.watchdog.stopWatching();
+        this.timer.stop();
+        this.allChannels.close().awaitUninterruptibly();
+    }
+
+    @Override
+    public final ChannelPipeline getPipeline() throws Exception {
+        ChannelPipeline pipeline = this.getDefaulHttpChannelPipeline();
+        // need to add another executor handler for invocation the service
+        pipeline.addLast("executionHandler", executionHandler);
+        pipeline.addLast("handler", this.getServletHandler());
+        return pipeline;
+    }
+
+    protected HttpSessionStore getHttpSessionStore() {
+        return new DefaultHttpSessionStore();
+    }
+
+    protected NettyHttpServletHandler getServletHandler() {
+
+        NettyHttpServletHandler handler = new NettyHttpServletHandler(this);
+        handler.addInterceptor(new ChannelInterceptor());
+        handler.addInterceptor(new HttpSessionInterceptor(getHttpSessionStore()));
+        return handler;
+    }
+
+    protected ChannelPipeline getDefaulHttpChannelPipeline() {
+
+        // Create a default pipeline implementation.
+        ChannelPipeline pipeline = Channels.pipeline();
+
+        pipeline.addLast("decoder", new HttpRequestDecoder());
+        pipeline.addLast("aggregator", new HttpChunkAggregator(1048576));
+        pipeline.addLast("encoder", new HttpResponseEncoder());
+
+        // Remove the following line if you don't want automatic content
+        // compression.
+        pipeline.addLast("deflater", new HttpContentCompressor());
+        pipeline.addLast("idle", this.idleStateHandler);
+
+        return pipeline;
+    }
+
+    private class HttpSessionWatchdog implements Runnable {
+
+        private boolean shouldStopWatching;
+
+        @Override
+        public void run() {
+
+            while (!shouldStopWatching) {
+
+                try {
+                    HttpSessionStore store = getHttpSessionStore();
+                    if (store != null) {
+                        store.destroyInactiveSessions();
+                    }
+                    Thread.sleep(5000);
+
+                } catch (InterruptedException e) {
+                    return;
+                }
+
+            }
+
+        }
+
+        public void stopWatching() {
+            this.shouldStopWatching = true;
+        }
+
+    }
+
+}

Added: cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/ServerEngine.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/ServerEngine.java?rev=1486823&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/ServerEngine.java (added)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/ServerEngine.java Tue May 28 08:54:49 2013
@@ -0,0 +1,42 @@
+/**
+ * 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.cxf.transport.http.netty.server;
+
+import java.net.URL;
+
+public interface ServerEngine {
+
+    void addServant(URL url, NettyHttpHandler handler);
+
+    /**
+     * Remove a previously registered servant.
+     *
+     * @param url the URL the servant was registered against.
+     */
+    void removeServant(URL url);
+
+    /**
+     * Get a previously  registered servant.
+     *
+     * @param url the associated URL
+     * @return the HttpHandler if registered
+     */
+    NettyHttpHandler getServant(URL url);
+}

Added: cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/interceptor/ChannelInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/interceptor/ChannelInterceptor.java?rev=1486823&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/interceptor/ChannelInterceptor.java (added)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/interceptor/ChannelInterceptor.java Tue May 28 08:54:49 2013
@@ -0,0 +1,46 @@
+/**
+ * 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.cxf.transport.http.netty.server.interceptor;
+
+import org.apache.cxf.transport.http.netty.server.servlet.ChannelThreadLocal;
+
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ExceptionEvent;
+import org.jboss.netty.channel.MessageEvent;
+import org.jboss.netty.handler.codec.http.HttpResponse;
+
+public class ChannelInterceptor implements NettyInterceptor {
+    @Override
+    public void onRequestFailed(ChannelHandlerContext ctx, ExceptionEvent e) {
+        ChannelThreadLocal.unset();
+    }
+
+    @Override
+    public void onRequestReceived(ChannelHandlerContext ctx, MessageEvent e) {
+        ChannelThreadLocal.set(e.getChannel());
+    }
+
+    @Override
+    public void onRequestSuccessed(ChannelHandlerContext ctx, MessageEvent e,
+                                   HttpResponse response) {
+        ChannelThreadLocal.unset();
+    }
+
+}

Added: cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/interceptor/HttpSessionInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/interceptor/HttpSessionInterceptor.java?rev=1486823&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/interceptor/HttpSessionInterceptor.java (added)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/interceptor/HttpSessionInterceptor.java Tue May 28 08:54:49 2013
@@ -0,0 +1,85 @@
+/**
+ * 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.cxf.transport.http.netty.server.interceptor;
+
+import java.util.Collection;
+
+import org.apache.cxf.transport.http.netty.server.servlet.HttpSessionThreadLocal;
+import org.apache.cxf.transport.http.netty.server.servlet.NettyHttpSession;
+import org.apache.cxf.transport.http.netty.server.session.HttpSessionStore;
+import org.apache.cxf.transport.http.netty.server.util.Utils;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ExceptionEvent;
+import org.jboss.netty.channel.MessageEvent;
+import org.jboss.netty.handler.codec.http.Cookie;
+import org.jboss.netty.handler.codec.http.CookieEncoder;
+import org.jboss.netty.handler.codec.http.HttpHeaders;
+import org.jboss.netty.handler.codec.http.HttpHeaders.Names;
+import org.jboss.netty.handler.codec.http.HttpRequest;
+import org.jboss.netty.handler.codec.http.HttpResponse;
+
+public class HttpSessionInterceptor implements NettyInterceptor {
+    private boolean sessionRequestedByCookie;
+
+    public HttpSessionInterceptor(HttpSessionStore sessionStore) {
+        HttpSessionThreadLocal.setSessionStore(sessionStore);
+    }
+
+    @Override
+    public void onRequestReceived(ChannelHandlerContext ctx, MessageEvent e) {
+
+        HttpSessionThreadLocal.unset();
+
+        HttpRequest request = (HttpRequest) e.getMessage();
+        Collection<Cookie> cookies = Utils.getCookies(
+                NettyHttpSession.SESSION_ID_KEY, request);
+        if (cookies != null) {
+            for (Cookie cookie : cookies) {
+                String jsessionId = cookie.getValue();
+                NettyHttpSession s = HttpSessionThreadLocal.getSessionStore()
+                        .findSession(jsessionId);
+                if (s != null) {
+                    HttpSessionThreadLocal.set(s);
+                    this.sessionRequestedByCookie = true;
+                    break;
+                }
+            }
+        }
+    }
+
+    @Override
+    public void onRequestSuccessed(ChannelHandlerContext ctx, MessageEvent e,
+                                   HttpResponse response) {
+
+        NettyHttpSession s = HttpSessionThreadLocal.get();
+        if (s != null && !this.sessionRequestedByCookie) {
+            CookieEncoder cookieEncoder = new CookieEncoder(true);
+            cookieEncoder.addCookie(NettyHttpSession.SESSION_ID_KEY, s.getId());
+            HttpHeaders.addHeader(response, Names.SET_COOKIE, cookieEncoder.encode());
+        }
+
+    }
+
+    @Override
+    public void onRequestFailed(ChannelHandlerContext ctx, ExceptionEvent e) {
+        this.sessionRequestedByCookie = false;
+        HttpSessionThreadLocal.unset();
+    }
+}

Added: cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/interceptor/NettyInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/interceptor/NettyInterceptor.java?rev=1486823&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/interceptor/NettyInterceptor.java (added)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/interceptor/NettyInterceptor.java Tue May 28 08:54:49 2013
@@ -0,0 +1,36 @@
+/**
+ * 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.cxf.transport.http.netty.server.interceptor;
+
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ExceptionEvent;
+import org.jboss.netty.channel.MessageEvent;
+import org.jboss.netty.handler.codec.http.HttpResponse;
+
+
+public interface NettyInterceptor {
+
+    void onRequestReceived(ChannelHandlerContext ctx, MessageEvent e);
+
+    void onRequestSuccessed(ChannelHandlerContext ctx, MessageEvent e,
+                            HttpResponse response);
+
+    void onRequestFailed(ChannelHandlerContext ctx, ExceptionEvent e);
+}

Added: cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/ChannelThreadLocal.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/ChannelThreadLocal.java?rev=1486823&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/ChannelThreadLocal.java (added)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/ChannelThreadLocal.java Tue May 28 08:54:49 2013
@@ -0,0 +1,43 @@
+/**
+ * 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.cxf.transport.http.netty.server.servlet;
+
+import org.jboss.netty.channel.Channel;
+
+public final class ChannelThreadLocal {
+    public static final ThreadLocal<Channel> CHANNEL_THREAD_LOCAL
+        = new ThreadLocal<Channel>();
+    
+    private ChannelThreadLocal() {
+        // Utils class
+    }
+
+    public static void set(Channel channel) {
+        CHANNEL_THREAD_LOCAL.set(channel);
+    }
+
+    public static void unset() {
+        CHANNEL_THREAD_LOCAL.remove();
+    }
+
+    public static Channel get() {
+        return CHANNEL_THREAD_LOCAL.get();
+    }
+}

Added: cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/HttpSessionThreadLocal.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/HttpSessionThreadLocal.java?rev=1486823&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/HttpSessionThreadLocal.java (added)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/HttpSessionThreadLocal.java Tue May 28 08:54:49 2013
@@ -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.cxf.transport.http.netty.server.servlet;
+
+import org.apache.cxf.transport.http.netty.server.session.HttpSessionStore;
+
+public final class HttpSessionThreadLocal {
+    public static final ThreadLocal<NettyHttpSession> SESSION_THREAD_LOCAL = new ThreadLocal<NettyHttpSession>();
+
+    private static HttpSessionStore sessionStore;
+    
+    private HttpSessionThreadLocal() {
+        // Utils class
+    }
+
+    public static HttpSessionStore getSessionStore() {
+        return sessionStore;
+    }
+
+    public static void setSessionStore(HttpSessionStore store) {
+        sessionStore = store;
+    }
+
+    public static void set(NettyHttpSession session) {
+        SESSION_THREAD_LOCAL.set(session);
+    }
+
+    public static void unset() {
+        SESSION_THREAD_LOCAL.remove();
+    }
+
+    public static NettyHttpSession get() {
+        NettyHttpSession session = SESSION_THREAD_LOCAL.get();
+        if (session != null) {
+            session.touch();
+        }
+        return session;
+    }
+
+    public static NettyHttpSession getOrCreate() {
+        if (HttpSessionThreadLocal.get() == null) {
+            //HttpSession newSession = sessionStore.createSession();
+            // TODO need to set the sessionTimeout
+            //newSession.setMaxInactiveInterval();
+            SESSION_THREAD_LOCAL.set(sessionStore.createSession());
+        }
+        return get();
+    }
+
+}

Added: cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyHttpServletRequest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyHttpServletRequest.java?rev=1486823&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyHttpServletRequest.java (added)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyHttpServletRequest.java Tue May 28 08:54:49 2013
@@ -0,0 +1,460 @@
+/**
+ * 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.cxf.transport.http.netty.server.servlet;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.net.InetSocketAddress;
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import org.apache.cxf.transport.http.netty.server.util.Utils;
+import org.jboss.netty.handler.codec.http.CookieDecoder;
+import org.jboss.netty.handler.codec.http.HttpHeaders;
+import org.jboss.netty.handler.codec.http.HttpHeaders.Names;
+import org.jboss.netty.handler.codec.http.HttpRequest;
+import org.jboss.netty.handler.codec.http.QueryStringDecoder;
+import org.jboss.netty.handler.ssl.SslHandler;
+
+import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.COOKIE;
+
+public class NettyHttpServletRequest implements HttpServletRequest {
+
+    private static final Locale DEFAULT_LOCALE = Locale.getDefault();
+
+    private URIParser uriParser;
+
+    private HttpRequest originalRequest;
+
+    private NettyServletInputStream inputStream;
+
+    private BufferedReader reader;
+
+    private QueryStringDecoder queryStringDecoder;
+
+    private Map<String, Object> attributes;
+
+    private CookieDecoder cookieDecoder = new CookieDecoder();
+
+    private String characterEncoding;
+
+    private String contextPath;
+
+    public NettyHttpServletRequest(HttpRequest request, String contextPath) {
+        this.originalRequest = request;
+        this.contextPath = contextPath;
+        this.uriParser = new URIParser(contextPath);
+        this.inputStream = new NettyServletInputStream(request);
+        this.reader = new BufferedReader(new InputStreamReader(inputStream));
+        this.queryStringDecoder = new QueryStringDecoder(request.getUri());
+        
+    }
+
+    public HttpRequest getOriginalRequest() {
+        return originalRequest;
+    }
+
+    @Override
+    public String getContextPath() {
+        return contextPath;
+    }
+
+    @Override
+    public Cookie[] getCookies() {
+        String cookieString = this.originalRequest.getHeader(COOKIE);
+        if (cookieString != null) {
+            Set<org.jboss.netty.handler.codec.http.Cookie> cookies = cookieDecoder
+                    .decode(cookieString);
+            if (!cookies.isEmpty()) {
+                Cookie[] cookiesArray = new Cookie[cookies.size()];
+                int indx = 0;
+                for (org.jboss.netty.handler.codec.http.Cookie c : cookies) {
+                    Cookie cookie = new Cookie(c.getName(), c.getValue());
+                    cookie.setComment(c.getComment());
+                    cookie.setDomain(c.getDomain());
+                    cookie.setMaxAge(c.getMaxAge());
+                    cookie.setPath(c.getPath());
+                    cookie.setSecure(c.isSecure());
+                    cookie.setVersion(c.getVersion());
+                    cookiesArray[indx] = cookie;
+                    indx++;
+                }
+                return cookiesArray;
+
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public long getDateHeader(String name) {
+        String longVal = getHeader(name);
+        if (longVal == null) {
+            return -1;
+        }
+
+        return Long.parseLong(longVal);
+    }
+
+    @Override
+    public String getHeader(String name) {
+        return HttpHeaders.getHeader(this.originalRequest, name);
+    }
+
+    @Override
+    public Enumeration getHeaderNames() {
+        return Utils.enumeration(this.originalRequest.getHeaderNames());
+    }
+
+    @Override
+    public Enumeration getHeaders(String name) {
+        return Utils.enumeration(this.originalRequest.getHeaders(name));
+    }
+
+    @Override
+    public int getIntHeader(String name) {
+        return HttpHeaders.getIntHeader(this.originalRequest, name, -1);
+    }
+
+    @Override
+    public String getMethod() {
+        return this.originalRequest.getMethod().getName();
+    }
+
+    @Override
+    public String getQueryString() {
+        return this.uriParser.getQueryString();
+    }
+
+    @Override
+    public String getRequestURI() {
+        return this.uriParser.getRequestUri();
+    }
+
+    @Override
+    public StringBuffer getRequestURL() {
+        StringBuffer url = new StringBuffer();
+        String scheme = this.getScheme();
+        int port = this.getServerPort();
+        String urlPath = this.getRequestURI();
+
+
+        url.append(scheme); // http, https
+        url.append("://");
+        url.append(this.getServerName());
+        if (("http".equalsIgnoreCase(scheme) && port != 80)
+                || ("https".equalsIgnoreCase(scheme) && port != 443)) {
+            url.append(':');
+            url.append(this.getServerPort());
+        }
+
+        url.append(urlPath);
+        return url;
+    }
+
+    @Override
+    public int getContentLength() {
+        return (int) HttpHeaders.getContentLength(this.originalRequest, -1);
+    }
+
+    @Override
+    public String getContentType() {
+        return HttpHeaders.getHeader(this.originalRequest,
+                HttpHeaders.Names.CONTENT_TYPE);
+    }
+
+    @Override
+    public ServletInputStream getInputStream() throws IOException {
+        return this.inputStream;
+    }
+
+    @Override
+    public String getCharacterEncoding() {
+        if (characterEncoding == null) {
+            characterEncoding = Utils.getCharsetFromContentType(this.getContentType());
+        }
+        return this.characterEncoding;
+    }
+
+    @Override
+    public String getParameter(String name) {
+        String[] values = getParameterValues(name);
+        return values != null ? values[0] : null;
+    }
+
+    @Override
+    public Map getParameterMap() {
+        return this.queryStringDecoder.getParameters();
+    }
+
+    @Override
+    public Enumeration getParameterNames() {
+        return Utils.enumerationFromKeys(this.queryStringDecoder
+                .getParameters());
+    }
+
+    @Override
+    public String[] getParameterValues(String name) {
+        List<String> values = this.queryStringDecoder.getParameters().get(name);
+        if (values == null || values.isEmpty()) {
+            return null;
+        }
+        return values.toArray(new String[values.size()]);
+    }
+
+    @Override
+    public String getProtocol() {
+        return this.originalRequest.getProtocolVersion().toString();
+    }
+
+    @Override
+    public Object getAttribute(String name) {
+        if (attributes != null) {
+            return this.attributes.get(name);
+        }
+        return null;
+    }
+
+    @Override
+    public Enumeration getAttributeNames() {
+        return Utils.enumerationFromKeys(this.attributes);
+    }
+
+    @Override
+    public void removeAttribute(String name) {
+        if (this.attributes != null) {
+            this.attributes.remove(name);
+        }
+    }
+
+    @Override
+    public void setAttribute(String name, Object o) {
+        if (this.attributes == null) {
+            this.attributes = new HashMap<String, Object>();
+        }
+        this.attributes.put(name, o);
+    }
+
+    @Override
+    public BufferedReader getReader() throws IOException {
+        return this.reader;
+    }
+
+    @Override
+    public String getRequestedSessionId() {
+        // doesn't implement it yet
+        return null;
+    }
+
+    @Override
+    public HttpSession getSession() {
+        // doesn't implement it yet
+        return null;
+    }
+
+    @Override
+    public HttpSession getSession(boolean create) {
+        // doesn't implement it yet
+        return null;
+    }
+
+    @Override
+    public String getPathInfo() {
+        return this.uriParser.getPathInfo();
+    }
+
+    @Override
+    public Locale getLocale() {
+        String locale = HttpHeaders.getHeader(this.originalRequest,
+                Names.ACCEPT_LANGUAGE, DEFAULT_LOCALE.toString());
+        return new Locale(locale);
+    }
+
+    @Override
+    public String getRemoteAddr() {
+        InetSocketAddress addr = (InetSocketAddress) ChannelThreadLocal.get()
+                .getRemoteAddress();
+        return addr.getAddress().getHostAddress();
+    }
+
+    @Override
+    public String getRemoteHost() {
+        InetSocketAddress addr = (InetSocketAddress) ChannelThreadLocal.get()
+                .getRemoteAddress();
+        return addr.getHostName();
+    }
+
+    @Override
+    public int getRemotePort() {
+        InetSocketAddress addr = (InetSocketAddress) ChannelThreadLocal.get()
+                .getRemoteAddress();
+        return addr.getPort();
+    }
+
+    @Override
+    public String getServerName() {
+        InetSocketAddress addr = (InetSocketAddress) ChannelThreadLocal.get()
+                .getLocalAddress();
+        return addr.getHostName();
+    }
+
+    @Override
+    public int getServerPort() {
+        InetSocketAddress addr = (InetSocketAddress) ChannelThreadLocal.get()
+                .getLocalAddress();
+        return addr.getPort();
+    }
+
+    @Override
+    public String getServletPath() {
+        String servletPath = this.uriParser.getServletPath();
+        if ("/".equals(servletPath)) {
+            return "";
+        }
+        return servletPath;
+    }
+
+    @Override
+    public String getScheme() {
+        return this.isSecure() ? "https" : "http";
+    }
+
+    @Override
+    public boolean isSecure() {
+        return ChannelThreadLocal.get().getPipeline().get(SslHandler.class) != null;
+    }
+
+    @Override
+    public boolean isRequestedSessionIdFromCookie() {
+        return true;
+    }
+
+    @Override
+    public String getLocalAddr() {
+        InetSocketAddress addr = (InetSocketAddress) ChannelThreadLocal.get()
+                .getLocalAddress();
+        return addr.getAddress().getHostAddress();
+    }
+
+    @Override
+    public String getLocalName() {
+        return getServerName();
+    }
+
+    @Override
+    public int getLocalPort() {
+        return getServerPort();
+    }
+
+    @Override
+    public void setCharacterEncoding(String env)
+        throws UnsupportedEncodingException {
+        this.characterEncoding = env;
+    }
+
+    @Override
+    public Enumeration getLocales() {
+        Collection<Locale> locales = Utils
+                .parseAcceptLanguageHeader(HttpHeaders
+                        .getHeader(this.originalRequest,
+                                HttpHeaders.Names.ACCEPT_LANGUAGE));
+
+        if (locales == null || locales.isEmpty()) {
+            locales = new ArrayList<Locale>();
+            locales.add(Locale.getDefault());
+        }
+        return Utils.enumeration(locales);
+    }
+
+    @Override
+    public String getAuthType() {
+        throw new IllegalStateException(
+                "Method 'getAuthType' not yet implemented!");
+    }
+
+    @Override
+    public String getPathTranslated() {
+        throw new IllegalStateException(
+                "Method 'getPathTranslated' not yet implemented!");
+    }
+
+    @Override
+    public String getRemoteUser() {
+        throw new IllegalStateException(
+                "Method 'getRemoteUser' not yet implemented!");
+    }
+
+    @Override
+    public Principal getUserPrincipal() {
+        // CXF will call this method to setup user information for Authentication
+        return null;
+    }
+
+    @Override
+    public boolean isRequestedSessionIdFromURL() {
+        throw new IllegalStateException(
+                "Method 'isRequestedSessionIdFromURL' not yet implemented!");
+    }
+
+    @Override
+    public boolean isRequestedSessionIdFromUrl() {
+        throw new IllegalStateException(
+                "Method 'isRequestedSessionIdFromUrl' not yet implemented!");
+    }
+
+    @Override
+    public boolean isRequestedSessionIdValid() {
+        throw new IllegalStateException(
+                "Method 'isRequestedSessionIdValid' not yet implemented!");
+    }
+
+    @Override
+    public boolean isUserInRole(String role) {
+        throw new IllegalStateException(
+                "Method 'isUserInRole' not yet implemented!");
+    }
+
+    @Override
+    public String getRealPath(String path) {
+        throw new IllegalStateException(
+                "Method 'getRealPath' not yet implemented!");
+    }
+
+    @Override
+    public RequestDispatcher getRequestDispatcher(String path) {
+        throw new IllegalStateException(
+                "Method 'getRequestDispatcher' not yet implemented!");
+    }
+}

Added: cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyHttpSession.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyHttpSession.java?rev=1486823&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyHttpSession.java (added)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyHttpSession.java Tue May 28 08:54:49 2013
@@ -0,0 +1,169 @@
+/**
+ * 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.cxf.transport.http.netty.server.servlet;
+
+
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionBindingEvent;
+import javax.servlet.http.HttpSessionBindingListener;
+import javax.servlet.http.HttpSessionContext;
+
+import org.apache.cxf.transport.http.netty.server.util.Utils;
+
+public class NettyHttpSession implements HttpSession {
+
+    public static final String SESSION_ID_KEY = "JSESSIONID";
+
+    private String id;
+
+    private long creationTime;
+
+    private long lastAccessedTime;
+
+    private int maxInactiveInterval = -1;
+
+    private Map<String, Object> attributes;
+
+    public NettyHttpSession(String id) {
+        this.id = id;
+        this.creationTime = System.currentTimeMillis();
+        this.lastAccessedTime = this.creationTime;
+    }
+
+    @Override
+    public Object getAttribute(String name) {
+        return attributes != null ? attributes.get(name) : null;
+    }
+
+    @Override
+    public Enumeration getAttributeNames() {
+        return Utils.enumerationFromKeys(attributes);
+    }
+
+    @Override
+    public long getCreationTime() {
+        return this.creationTime;
+    }
+
+    @Override
+    public String getId() {
+        return this.id;
+    }
+
+    @Override
+    public long getLastAccessedTime() {
+        return this.lastAccessedTime;
+    }
+
+    @Override
+    public ServletContext getServletContext() {
+        // TODO do we need to support this
+        return null;
+    }
+
+    @Override
+    public HttpSessionContext getSessionContext() {
+        throw new IllegalStateException(
+                "As of Version 2.1, this method is deprecated and has no replacement.");
+    }
+
+    @Override
+    public Object getValue(String name) {
+        return getAttribute(name);
+    }
+
+    @Override
+    public String[] getValueNames() {
+        if (attributes == null) {
+            return null;
+        }
+        return attributes.keySet().toArray(
+                new String[attributes.keySet().size()]);
+    }
+
+    @Override
+    public void invalidate() {
+        if (attributes != null) {
+            attributes.clear();
+        }
+    }
+
+    @Override
+    public void putValue(String name, Object value) {
+        this.setAttribute(name, value);
+    }
+
+    @Override
+    public void removeAttribute(String name) {
+        if (attributes != null) {
+            Object value = attributes.get(name);
+            if (value instanceof HttpSessionBindingListener) {
+                ((HttpSessionBindingListener) value)
+                        .valueUnbound(new HttpSessionBindingEvent(this, name,
+                                value));
+            }
+            attributes.remove(name);
+        }
+    }
+
+    @Override
+    public void removeValue(String name) {
+        this.removeAttribute(name);
+    }
+
+    @Override
+    public void setAttribute(String name, Object value) {
+        if (attributes == null) {
+            attributes = new ConcurrentHashMap<String, Object>();
+        }
+        attributes.put(name, value);
+
+        if (value instanceof HttpSessionBindingListener) {
+            ((HttpSessionBindingListener) value)
+                    .valueBound(new HttpSessionBindingEvent(this, name, value));
+        }
+
+    }
+
+    @Override
+    public int getMaxInactiveInterval() {
+        return this.maxInactiveInterval;
+    }
+
+    @Override
+    public void setMaxInactiveInterval(int interval) {
+        this.maxInactiveInterval = interval;
+
+    }
+
+    public void touch() {
+        this.lastAccessedTime = System.currentTimeMillis();
+    }
+
+    @Override
+    public boolean isNew() {
+        throw new IllegalStateException("Method 'isNew' not yet implemented!");
+    }
+}
\ No newline at end of file

Added: cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyServletContext.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyServletContext.java?rev=1486823&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyServletContext.java (added)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyServletContext.java Tue May 28 08:54:49 2013
@@ -0,0 +1,210 @@
+/**
+ * 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.cxf.transport.http.netty.server.servlet;
+
+
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.transport.http.netty.server.util.Utils;
+
+
+public class NettyServletContext implements ServletContext {
+
+    private static final Logger LOG =
+            LogUtils.getL7dLogger(NettyServletContext.class);
+
+    private Map<String, Object> attributes;
+
+    private Map<String, String> initParameters;
+
+    private String servletContextName;
+
+    private final String contextPath;
+
+    public NettyServletContext(String contextPath) {
+        this.contextPath = contextPath;
+    }
+
+    @Override
+    public Object getAttribute(String name) {
+        return attributes != null ? attributes.get(name) : null;
+    }
+
+    @Override
+    public Enumeration getAttributeNames() {
+        return Utils.enumerationFromKeys(attributes);
+    }
+
+    @Override
+    public String getContextPath() {
+        return contextPath;
+    }
+
+    @Override
+    public int getMajorVersion() {
+        return 2;
+    }
+
+    @Override
+    public int getMinorVersion() {
+        return 4;
+    }
+
+    @Override
+    public URL getResource(String path) throws MalformedURLException {
+        return NettyServletContext.class.getResource(path);
+    }
+
+    @Override
+    public InputStream getResourceAsStream(String path) {
+        return NettyServletContext.class.getResourceAsStream(path);
+    }
+
+    @Override
+    public String getServerInfo() {
+        return "Netty Servlet";
+    }
+
+    public void addInitParameter(String name, String value) {
+        if (this.initParameters == null) {
+            this.initParameters = new HashMap<String, String>();
+        }
+        this.initParameters.put(name, value);
+    }
+
+    @Override
+    public String getInitParameter(String name) {
+        if (this.initParameters == null) {
+            return null;
+        }
+        return this.initParameters.get(name);
+    }
+
+    @Override
+    public Enumeration getInitParameterNames() {
+        return Utils.enumerationFromKeys(this.initParameters);
+    }
+
+    @Override
+    public void log(String msg) {
+        LOG.info(msg);
+    }
+
+    @Override
+    public void log(Exception exception, String msg) {
+        LOG.log(Level.SEVERE, msg, exception);
+    }
+
+    @Override
+    public void log(String message, Throwable throwable) {
+        LOG.log(Level.SEVERE, message, throwable);
+    }
+
+    @Override
+    public void removeAttribute(String name) {
+        if (this.attributes != null) {
+            this.attributes.remove(name);
+        }
+    }
+
+    @Override
+    public void setAttribute(String name, Object object) {
+        if (this.attributes == null) {
+            this.attributes = new HashMap<String, Object>();
+        }
+        this.attributes.put(name, object);
+    }
+
+    @Override
+    public String getServletContextName() {
+        return this.servletContextName;
+    }
+
+    void setServletContextName(String servletContextName) {
+        this.servletContextName = servletContextName;
+    }
+
+    @Override
+    public Servlet getServlet(String name) throws ServletException {
+        throw new IllegalStateException(
+                "Deprecated as of Java Servlet API 2.1, with no direct replacement!");
+    }
+
+    @Override
+    public Enumeration getServletNames() {
+        throw new IllegalStateException(
+                "Method 'getServletNames' deprecated as of Java Servlet API 2.0, with no replacement.");
+    }
+
+    @Override
+    public Enumeration getServlets() {
+        throw new IllegalStateException(
+                "Method 'getServlets' deprecated as of Java Servlet API 2.0, with no replacement.");
+    }
+
+    @Override
+    public ServletContext getContext(String uripath) {
+        return this;
+    }
+
+    @Override
+    public String getMimeType(String file) {
+        return Utils.getMimeType(file);
+
+    }
+
+    @Override
+    public Set getResourcePaths(String path) {
+        throw new IllegalStateException(
+                "Method 'getResourcePaths' not yet implemented!");
+    }
+
+    @Override
+    public RequestDispatcher getNamedDispatcher(String name) {
+        throw new IllegalStateException(
+                "Method 'getNamedDispatcher' not yet implemented!");
+    }
+
+    @Override
+    public String getRealPath(String path) {
+        throw new IllegalStateException(
+                "Method 'getRealPath' not yet implemented!");
+    }
+
+    @Override
+    public RequestDispatcher getRequestDispatcher(String path) {
+        throw new IllegalStateException(
+                "Method 'getRequestDispatcher' not yet implemented!");
+    }
+}

Added: cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyServletInputStream.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyServletInputStream.java?rev=1486823&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyServletInputStream.java (added)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyServletInputStream.java Tue May 28 08:54:49 2013
@@ -0,0 +1,53 @@
+/**
+ * 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.cxf.transport.http.netty.server.servlet;
+
+
+import java.io.IOException;
+import javax.servlet.ServletInputStream;
+import org.jboss.netty.buffer.ChannelBufferInputStream;
+import org.jboss.netty.handler.codec.http.HttpRequest;
+
+public class NettyServletInputStream extends ServletInputStream {
+
+    private final HttpRequest request;
+
+    private final ChannelBufferInputStream in;
+
+    public NettyServletInputStream(HttpRequest request) {
+        this.request = request;
+        this.in = new ChannelBufferInputStream(this.request.getContent());
+    }
+
+    @Override
+    public int read() throws IOException {
+        return this.in.read();
+    }
+
+    @Override
+    public int read(byte[] buf) throws IOException {
+        return this.in.read(buf);
+    }
+
+    @Override
+    public int read(byte[] buf, int offset, int len) throws IOException {
+        return this.in.read(buf, offset, len);
+    }
+}

Added: cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyServletOutputStream.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyServletOutputStream.java?rev=1486823&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyServletOutputStream.java (added)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyServletOutputStream.java Tue May 28 08:54:49 2013
@@ -0,0 +1,72 @@
+/**
+ * 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.cxf.transport.http.netty.server.servlet;
+
+import java.io.IOException;
+import javax.servlet.ServletOutputStream;
+import org.jboss.netty.buffer.ChannelBufferOutputStream;
+import org.jboss.netty.buffer.ChannelBuffers;
+import org.jboss.netty.handler.codec.http.HttpResponse;
+
+public class NettyServletOutputStream extends ServletOutputStream {
+    private HttpResponse response;
+
+    private ChannelBufferOutputStream out;
+
+    private boolean flushed;
+
+    public NettyServletOutputStream(HttpResponse response) {
+        this.response = response;
+        this.out = new ChannelBufferOutputStream(ChannelBuffers.dynamicBuffer());
+    }
+
+    @Override
+    public void write(int b) throws IOException {
+        this.out.write(b);
+    }
+
+    @Override
+    public void write(byte[] b) throws IOException {
+        this.out.write(b);
+    }
+
+    @Override
+    public void write(byte[] b, int offset, int len) throws IOException {
+        this.out.write(b, offset, len);
+    }
+
+    @Override
+    public void flush() throws IOException {
+        this.response.setContent(out.buffer());
+        this.flushed = true;
+    }
+
+    public void resetBuffer() {
+        this.out.buffer().clear();
+    }
+
+    public boolean isFlushed() {
+        return flushed;
+    }
+
+    public int getBufferSize() {
+        return this.out.buffer().capacity();
+    }
+}

Added: cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyServletResponse.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyServletResponse.java?rev=1486823&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyServletResponse.java (added)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyServletResponse.java Tue May 28 08:54:49 2013
@@ -0,0 +1,235 @@
+/**
+ * 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.cxf.transport.http.netty.server.servlet;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.Locale;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.netty.handler.codec.http.Cookie;
+import org.jboss.netty.handler.codec.http.CookieEncoder;
+import org.jboss.netty.handler.codec.http.HttpHeaders;
+import org.jboss.netty.handler.codec.http.HttpResponse;
+import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+
+import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.LOCATION;
+import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.SET_COOKIE;
+
+
+public class NettyServletResponse implements HttpServletResponse {
+
+    private HttpResponse originalResponse;
+
+    private NettyServletOutputStream outputStream;
+
+    private PrintWriter writer;
+
+    private boolean responseCommited;
+
+    public NettyServletResponse(HttpResponse response) {
+        this.originalResponse = response;
+        this.outputStream = new NettyServletOutputStream(response);
+        this.writer = new PrintWriter(this.outputStream);
+    }
+
+    public HttpResponse getOriginalResponse() {
+        return originalResponse;
+    }
+
+    public void addCookie(Cookie cookie) {
+        CookieEncoder cookieEncoder = new CookieEncoder(true);
+        cookieEncoder.addCookie(cookie.getName(), cookie.getValue());
+        HttpHeaders.addHeader(this.originalResponse, SET_COOKIE, cookieEncoder
+                .encode());
+    }
+
+    public void addDateHeader(String name, long date) {
+        HttpHeaders.addHeader(this.originalResponse, name, date);
+    }
+
+    public void addHeader(String name, String value) {
+        HttpHeaders.addHeader(this.originalResponse, name, value);
+    }
+
+    public void addIntHeader(String name, int value) {
+        HttpHeaders.addIntHeader(this.originalResponse, name, value);
+    }
+
+    @Override
+    public void addCookie(javax.servlet.http.Cookie cookie) {
+        //TODO Do we need to implement it ?
+    }
+
+    public boolean containsHeader(String name) {
+        return this.originalResponse.containsHeader(name);
+    }
+
+    public void sendError(int sc) throws IOException {
+        this.originalResponse.setStatus(HttpResponseStatus.valueOf(sc));
+    }
+
+    public void sendError(int sc, String msg) throws IOException {
+        this.originalResponse.setStatus(new HttpResponseStatus(sc, msg));
+
+    }
+
+    public void sendRedirect(String location) throws IOException {
+        setStatus(302);
+        setHeader(LOCATION, location);
+    }
+
+    public void setDateHeader(String name, long date) {
+        HttpHeaders.setHeader(this.originalResponse, name, date);
+    }
+
+    public void setHeader(String name, String value) {
+        HttpHeaders.setHeader(this.originalResponse, name, value);
+    }
+
+    public void setIntHeader(String name, int value) {
+        HttpHeaders.setIntHeader(this.originalResponse, name, value);
+
+    }
+
+    @Override
+    public ServletOutputStream getOutputStream() throws IOException {
+        return this.outputStream;
+    }
+
+    @Override
+    public PrintWriter getWriter() throws IOException {
+        return this.writer;
+    }
+
+    public void setStatus(int sc) {
+        this.originalResponse.setStatus(HttpResponseStatus.valueOf(sc));
+    }
+
+    public void setStatus(int sc, String sm) {
+        this.originalResponse.setStatus(new HttpResponseStatus(sc, sm));
+    }
+
+    @Override
+    public void setContentType(String type) {
+        HttpHeaders.setHeader(this.originalResponse,
+                HttpHeaders.Names.CONTENT_TYPE, type);
+    }
+
+    @Override
+    public void setContentLength(int len) {
+        HttpHeaders.setContentLength(this.originalResponse, len);
+    }
+
+    @Override
+    public boolean isCommitted() {
+        return this.responseCommited;
+    }
+
+    @Override
+    public void reset() {
+        if (isCommitted()) {
+            throw new IllegalStateException("Response already commited!");
+        }
+
+        this.originalResponse.clearHeaders();
+        this.resetBuffer();
+    }
+
+    @Override
+    public void resetBuffer() {
+        if (isCommitted()) {
+            throw new IllegalStateException("Response already commited!");
+        }
+        this.outputStream.resetBuffer();
+    }
+
+    @Override
+    public void flushBuffer() throws IOException {
+        this.getWriter().flush();
+        this.responseCommited = true;
+    }
+
+    @Override
+    public int getBufferSize() {
+        return this.outputStream.getBufferSize();
+    }
+
+    @Override
+    public void setBufferSize(int size) {
+        // we using always dynamic buffer for now
+    }
+
+    public String encodeRedirectURL(String url) {
+        return this.encodeURL(url);
+    }
+
+    public String encodeRedirectUrl(String url) {
+        return this.encodeURL(url);
+    }
+
+    public String encodeURL(String url) {
+        try {
+            return URLEncoder.encode(url, getCharacterEncoding());
+        } catch (UnsupportedEncodingException e) {
+            throw new RuntimeException("Error encoding url!", e);
+        }
+    }
+
+    public String encodeUrl(String url) {
+        return this.encodeRedirectURL(url);
+    }
+
+    @Override
+    public String getCharacterEncoding() {
+        throw new IllegalStateException(
+                "Method 'getCharacterEncoding' not yet implemented!");
+    }
+
+    @Override
+    public String getContentType() {
+        throw new IllegalStateException(
+                "Method 'getContentType' not yet implemented!");
+    }
+
+    @Override
+    public Locale getLocale() {
+        throw new IllegalStateException(
+                "Method 'getLocale' not yet implemented!");
+    }
+
+    @Override
+    public void setCharacterEncoding(String charset) {
+        throw new IllegalStateException(
+                "Method 'setCharacterEncoding' not yet implemented!");
+
+    }
+
+    @Override
+    public void setLocale(Locale loc) {
+        throw new IllegalStateException(
+                "Method 'setLocale' not yet implemented!");
+
+    }
+}

Added: cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/URIParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/URIParser.java?rev=1486823&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/URIParser.java (added)
+++ cxf/trunk/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/URIParser.java Tue May 28 08:54:49 2013
@@ -0,0 +1,80 @@
+/**
+ * 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.cxf.transport.http.netty.server.servlet;
+
+public class URIParser {
+
+    private String servletPath;
+
+    private String requestUri;
+
+    private String pathInfo;
+
+    private String queryString;
+
+    public URIParser(String servletPath) {
+        this.servletPath = servletPath;
+    }
+
+    public void parse(String uri) {
+
+        int indx = uri.indexOf('?');
+
+        if (!this.servletPath.startsWith("/")) {
+            this.servletPath = "/" + this.servletPath;
+        }
+
+        if (indx != -1) {
+            this.pathInfo = uri.substring(servletPath.length(), indx);
+            this.queryString = uri.substring(indx + 1);
+            this.requestUri = uri.substring(0, indx);
+        } else {
+            this.pathInfo = uri.substring(servletPath.length());
+            this.requestUri = uri;
+        }
+
+        if (this.requestUri.endsWith("/")) {
+            this.requestUri.substring(0, this.requestUri.length() - 1);
+        }
+
+        if (this.pathInfo.equals("")) {
+            this.pathInfo = null;
+        } else if (!this.pathInfo.startsWith("/")) {
+            this.pathInfo = "/" + this.pathInfo;
+        }
+    }
+
+    public String getServletPath() {
+        return servletPath;
+    }
+
+    public String getQueryString() {
+        return queryString;
+    }
+
+    public String getPathInfo() {
+        return this.pathInfo;
+    }
+
+    public String getRequestUri() {
+        return requestUri;
+    }
+
+}