renamed servlets
This commit is contained in:
parent
121c88d7e2
commit
e977bbf9fe
@ -19,7 +19,7 @@
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jboss.netty.servlet;
|
||||
package org.jboss.netty.channel.socket.http;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@ -49,7 +49,7 @@ import org.jboss.netty.channel.SimpleChannelHandler;
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
@ChannelPipelineCoverage("one")
|
||||
class ServletChannelHandler extends SimpleChannelHandler {
|
||||
class HttpTunnelingChannelHandler extends SimpleChannelHandler {
|
||||
List<MessageEvent> awaitingEvents = new ArrayList<MessageEvent>();
|
||||
|
||||
private final Lock reconnectLock = new ReentrantLock();
|
||||
@ -68,7 +68,7 @@ class ServletChannelHandler extends SimpleChannelHandler {
|
||||
|
||||
private final HttpSession session;
|
||||
|
||||
public ServletChannelHandler(boolean stream, HttpSession session, long reconnectTimeout) {
|
||||
public HttpTunnelingChannelHandler(boolean stream, HttpSession session, long reconnectTimeout) {
|
||||
this.stream = stream;
|
||||
this.session = session;
|
||||
this.reconnectTimeout = reconnectTimeout;
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
* Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
|
||||
* by the @authors tag. See the copyright.txt in the distribution for a
|
||||
* full listing of individual contributors.
|
||||
*
|
||||
* This is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this software; if not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jboss.netty.channel.socket.http;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
|
||||
import org.jboss.netty.bootstrap.ClientBootstrap;
|
||||
import org.jboss.netty.channel.ChannelFactory;
|
||||
import org.jboss.netty.channel.local.LocalClientChannelFactory;
|
||||
|
||||
/**
|
||||
* A context listener that creates a client bootstrap that uses a local channel factory. The local channel factory should
|
||||
* already be registered before the contect is loaded.
|
||||
*
|
||||
* @author The Netty Project (netty-dev@lists.jboss.org)
|
||||
* @author Andy Taylor (andy.taylor@jboss.org)
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
public class HttpTunnelingContextListener implements ServletContextListener {
|
||||
|
||||
private static final long DEFAULT_RECONNECT_TIMEOUT = 5000;
|
||||
|
||||
private static final boolean DEFAULT_IS_STREAMING = true;
|
||||
|
||||
static final String SERVER_CHANNEL_PROP = "serverChannelName";
|
||||
|
||||
static final String RECONNECT_PROP = "reconnectTimeout";
|
||||
|
||||
static final String STREAMING_PROP = "streaming";
|
||||
|
||||
static final String BOOTSTRAP_PROP = "bootstrap";
|
||||
|
||||
private final ChannelFactory factory = new LocalClientChannelFactory();
|
||||
|
||||
public void contextInitialized(ServletContextEvent context) {
|
||||
context.getServletContext().setAttribute(BOOTSTRAP_PROP, new ClientBootstrap(factory));
|
||||
String timeoutParam = context.getServletContext().getInitParameter(RECONNECT_PROP);
|
||||
context.getServletContext().setAttribute(RECONNECT_PROP, timeoutParam == null?DEFAULT_RECONNECT_TIMEOUT:Long.decode(timeoutParam.trim()));
|
||||
String streaming = context.getServletContext().getInitParameter(STREAMING_PROP);
|
||||
context.getServletContext().setAttribute(STREAMING_PROP, streaming == null?DEFAULT_IS_STREAMING: Boolean.valueOf(streaming.trim()));
|
||||
String serverChannel = context.getServletContext().getInitParameter(SERVER_CHANNEL_PROP);
|
||||
context.getServletContext().setAttribute(SERVER_CHANNEL_PROP, serverChannel);
|
||||
}
|
||||
|
||||
public void contextDestroyed(ServletContextEvent context) {
|
||||
// Unused
|
||||
}
|
||||
|
||||
}
|
@ -19,7 +19,7 @@
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jboss.netty.servlet;
|
||||
package org.jboss.netty.channel.socket.http;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PushbackInputStream;
|
||||
@ -43,7 +43,7 @@ import org.jboss.netty.channel.MessageEvent;
|
||||
* @author Andy Taylor (andy.taylor@jboss.org)
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
public class NettyServlet extends HttpServlet {
|
||||
public class HttpTunnelingServlet extends HttpServlet {
|
||||
|
||||
private static final long serialVersionUID = -872309493835745385L;
|
||||
|
||||
@ -55,8 +55,8 @@ public class NettyServlet extends HttpServlet {
|
||||
HttpServletResponse response) throws IOException {
|
||||
HttpSession session = request.getSession();
|
||||
Channel channel = (Channel) session.getAttribute(CHANNEL_PROP);
|
||||
ServletChannelHandler handler =
|
||||
(ServletChannelHandler) session.getAttribute(HANDLER_PROP);
|
||||
HttpTunnelingChannelHandler handler =
|
||||
(HttpTunnelingChannelHandler) session.getAttribute(HANDLER_PROP);
|
||||
if (handler.isStreaming()) {
|
||||
streamResponse(request, response, session, handler, channel);
|
||||
} else {
|
||||
@ -67,7 +67,7 @@ public class NettyServlet extends HttpServlet {
|
||||
private void streamResponse(
|
||||
final HttpServletRequest request,
|
||||
final HttpServletResponse response, HttpSession session,
|
||||
ServletChannelHandler handler, Channel channel) throws IOException {
|
||||
HttpTunnelingChannelHandler handler, Channel channel) throws IOException {
|
||||
|
||||
response.setHeader("jsessionid", session.getId());
|
||||
response.setHeader("Content-Type", "application/octet-stream");
|
||||
@ -135,7 +135,7 @@ public class NettyServlet extends HttpServlet {
|
||||
Channel channel,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response, HttpSession session,
|
||||
ServletChannelHandler handler) throws IOException {
|
||||
HttpTunnelingChannelHandler handler) throws IOException {
|
||||
int length = request.getContentLength();
|
||||
if (length > 0) {
|
||||
byte[] bytes = new byte[length];
|
@ -19,11 +19,11 @@
|
||||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
||||
*/
|
||||
package org.jboss.netty.servlet;
|
||||
package org.jboss.netty.channel.socket.http;
|
||||
|
||||
import static org.jboss.netty.channel.Channels.*;
|
||||
import static org.jboss.netty.servlet.NettyServlet.*;
|
||||
import static org.jboss.netty.servlet.NettyServletContextListener.*;
|
||||
import static org.jboss.netty.channel.socket.http.HttpTunnelingServlet.*;
|
||||
import static org.jboss.netty.channel.socket.http.HttpTunnelingContextListener.*;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.servlet.http.HttpSessionEvent;
|
||||
@ -44,7 +44,7 @@ import org.jboss.netty.channel.local.LocalAddress;
|
||||
* @author Andy Taylor (andy.taylor@jboss.org)
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
public class NettySessionListener implements HttpSessionListener, ChannelHandler {
|
||||
public class HttpTunnelingSessionListener implements HttpSessionListener, ChannelHandler {
|
||||
|
||||
public void sessionCreated(HttpSessionEvent event) {
|
||||
HttpSession session = event.getSession();
|
||||
@ -53,12 +53,12 @@ public class NettySessionListener implements HttpSessionListener, ChannelHandler
|
||||
if(streaming) {
|
||||
session.setMaxInactiveInterval(-1);
|
||||
}
|
||||
final ServletChannelHandler handler = new ServletChannelHandler(streaming, session, (Long) session.getServletContext().getAttribute(RECONNECT_PROP));
|
||||
final HttpTunnelingChannelHandler handler = new HttpTunnelingChannelHandler(streaming, session, (Long) session.getServletContext().getAttribute(RECONNECT_PROP));
|
||||
session.setAttribute(HANDLER_PROP, handler);
|
||||
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
|
||||
public ChannelPipeline getPipeline() throws Exception {
|
||||
ChannelPipeline pipeline = pipeline();
|
||||
pipeline.addLast(NettySessionListener.class.getName(), handler);
|
||||
pipeline.addLast(HttpTunnelingSessionListener.class.getName(), handler);
|
||||
return pipeline;
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user