Compile the project

In order to compile the class you need to add the Netty core library which is part of the JBoss AS 7 distribution.
If you are running a Maven project, then add the following dependency:


<dependency>
    <groupId>org.jboss.netty</groupId>
    <artifactId>netty</artifactId>
    <version>3.2.0.Final</version>
</dependency>
           

If you are running an Eclipse project, then simply add this JAR library:

netty jboss as 7 tutorial

Run the main class passing the required arguments- for example in order to debug JBoss' HTTP requests (running on port 8080)
you can pass the following arguments: 8888 127.0.0.1 8080
Now point your browser to 127.0.0.1:8888 and you are done!

jboss netty tutorial proxy

Proxying as text data

Proxing Hex data can be useful for debugging some kind of network protocols, however if you are simply looking for a textual view of proxied data then you need just a couple of adaptations to your code, such as converting the message to String, passing as argument the default Charset. Replace the two messageReceived methods for the inboundChannel and outboundChannel as follows:

  public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
                throws Exception {
            ChannelBuffer msg = (ChannelBuffer) e.getMessage();

            int len = msg.readUnsignedByte();
            int whichClient = msg.readUnsignedShort();
            assert len == msg.readableBytes();
            System.out.println(whichClient +" <<< " + msg.toString(Charset.defaultCharset()));

            inboundChannel.write(msg);
}
. . . .
  public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
            throws Exception {
        ChannelBuffer msg = (ChannelBuffer) e.getMessage();

        int len = msg.readUnsignedByte();
        int whichClient = msg.readUnsignedShort();
        assert len == msg.readableBytes();
        System.out.println(whichClient +" <<< " + msg.toString(Charset.defaultCharset()));

       outboundChannel.write(msg);
}

jboss netty tutorial

0
0
0
s2smodern

Related articles available on mastertheboss.com