All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.netty.channel.socket.http.package-info Maven / Gradle / Ivy

Go to download

The Netty project is an effort to provide an asynchronous event-driven network application framework and tools for rapid development of maintainable high performance and high scalability protocol servers and clients. In other words, Netty is a NIO client server framework which enables quick and easy development of network applications such as protocol servers and clients. It greatly simplifies and streamlines network programming such as TCP and UDP socket server.

There is a newer version: 4.0.0.Alpha8
Show newest version
/*
 * Copyright 2012 The Netty Project
 *
 * The Netty Project 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.
 */

/**
 * An HTTP-based client-side {@link org.jboss.netty.channel.socket.SocketChannel}
 * and its corresponding server-side Servlet implementation that make your
 * existing server application work in a firewalled network.
 *
 * 

Deploying the HTTP tunnel as a Servlet

* * First, {@link org.jboss.netty.channel.socket.http.HttpTunnelingServlet} must be * configured in a web.xml. * *
 * <?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>
 *     <!--
 *       The name of the channel, this should be a registered local channel.
 *       See LocalTransportRegister.
 *     -->
 *     <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>
 * 
* * Second, you have to bind your Netty-based server application in the same * Servlet context or shared class loader space using the local transport * (see {@link org.jboss.netty.channel.local.LocalServerChannelFactory}.) * You can use your favorite IoC framework such as JBoss Microcontainer, Guice, * and Spring to do this. The following example shows how to bind an echo * server to the endpoint specifed above (web.xml) in JBossAS 5: * *
 * <bean name="my-local-echo-server"
 *       class="org.jboss.netty.example.http.tunnel.LocalEchoServerRegistration" />
 *
 * ...
 *
 * package org.jboss.netty.example.http.tunnel;
 * ...
 *
 * public class LocalEchoServerRegistration {
 *
 *     private final ChannelFactory factory = new DefaultLocalServerChannelFactory();
 *     private volatile Channel serverChannel;
 *
 *     public void start() {
 *         ServerBootstrap serverBootstrap = new ServerBootstrap(factory);
 *         EchoHandler handler = new EchoHandler();
 *         serverBootstrap.getPipeline().addLast("handler", handler);
 *
 *         // Note that "myLocalServer" is the endpoint which was specified in web.xml.
 *         serverChannel = serverBootstrap.bind(new LocalAddress("myLocalServer"));
 *     }
 *
 *     public void stop() {
 *         serverChannel.close();
 *     }
 * }
 * 
* *

Connecting to the HTTP tunnel

* * Once the tunnel has been configured, your client-side application needs only * a couple lines of changes. * *
 * ClientBootstrap b = new ClientBootstrap(
 *         new HttpTunnelingClientSocketChannelFactory(
 *                 new NioClientSocketChannelFactory(...)));
 *
 * // Configure the pipeline (or pipeline factory) here.
 * ...
 *
 * // The host name of the HTTP server
 * b.setOption("serverName", "example.com");
 * // The path to the HTTP tunneling Servlet, which was specified in in web.xml
 * b.setOption("serverPath", "contextPath/netty-tunnel");
 * b.connect(new InetSocketAddress("example.com", 80);
 * 
* * For more configuration parameters such as HTTPS options, * refer to {@link org.jboss.netty.channel.socket.http.HttpTunnelingSocketChannelConfig}. */ package org.jboss.netty.channel.socket.http;




© 2015 - 2024 Weber Informatics LLC | Privacy Policy