Configuring Netty HTTP

200 views
Skip to first unread message

huzhiwu

unread,
May 24, 2012, 11:05:31 PM5/24/12
to netty
Dear organizations:
           My English is very poor. I'm sorry, excuse me. I would like to ask a question that how to Configuring netty servlet.
There has very litter information for that.
           
 I'm want to configuring a Netty servlet transport for use with Tomcat.
  Here's an example web.xml describing a web application that uses the servlet:  
 
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
         version="2.4">
       
   
  <servlet>
   <servlet-name>NettyTunnelingServlet</servlet-name>
     <servlet-class>org.jboss.netty.channel.socket.http.HttpTunnelingServlet</servlet-class>
    <init-param>
     <param-name>endpoint</param-name>
      <param-value>local:myLocalServer</param-value>
    </init-param>
<load-on-startup>1</load-on-startup>
  </servlet>
 
  <servlet-mapping>
       <servlet-name>NettyTunnelingServlet</servlet-name>
       <url-pattern>/netty-tunnel</url-pattern>
  </servlet-mapping>
   
</web-app>
 
part of client java code
 
 // Configure the client.
        ClientBootstrap bootstrap = new ClientBootstrap(
//         new HttpTunnelingClientSocketChannelFactory(
         new NioClientSocketChannelFactory(
                        Executors.newCachedThreadPool(),
                        Executors.newCachedThreadPool()));
 
        // Set up the event pipeline factory.
        bootstrap.setPipelineFactory(new HttpClientPipelineFactory(ssl));
 
        // The host name of the HTTP server
        bootstrap.setOption("serverName", host);//host="localhost"
        // The path to the HTTP tunneling Servlet, which was specified in in web.xml
        bootstrap.setOption("serverPath", "contextPath/netty-tunnel");
        
        
        // Start the connection attempt.
        ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));
 
        // Wait until the connection attempt succeeds or fails.
        Channel channel = future.awaitUninterruptibly().getChannel();
        if (!future.isSuccess()) {
            future.getCause().printStackTrace();
            bootstrap.releaseExternalResources();
            return;
        }
    
     server java code:
   
public class LocalEchoServerRegistration {
 
    private final ChannelFactory factory = new DefaultLocalServerChannelFactory();
    private volatile Channel serverChannel;
 
    public void start() {
        ServerBootstrap serverBootstrap = new ServerBootstrap(factory);
        serverBootstrap.getPipeline().addLast("handler", new HttpResponseHandler());
 
        // Note that "myLocalServer" is the endpoint which was specified in web.xml.
        serverChannel = serverBootstrap.bind(new LocalAddress("myLocalServer"));
    }
 
    public void stop() {
        serverChannel.close();
    }
}
 
but now can not communicate the server .
I'm want to communicate to netty servlet by client or IE Browser(Firefox Browser),
Can you give to the available and detailed java code, Thank you!

 
          
 
 

huzhiwu
Reply all
Reply to author
Forward
0 new messages