users@grizzly.java.net

Re: [Jersey] How to Get Remote IP address in JAX/RS with Grizzly

From: Sebastien Dionne <survivant00_at_gmail.com>
Date: Tue, 16 Feb 2010 18:58:33 -0500

does that can do the job ?


controller = new Controller();
        TCPSelectorHandler tcpSelectorHandler = new TCPSelectorHandler(){
            public SelectableChannel acceptWithoutRegistration(SelectionKey
key) throws IOException {
                ServerSocketChannel server = (ServerSocketChannel)
key.channel();
                SocketChannel channel = server.accept();

                if (isAddressBanned(channel.socket().getInetAddress())) {
                        if(s_logger.isDebugEnabled()){
                            s_logger.debug("This IP [" +
channel.socket().getInetAddress() + "] is banned, the connection will be
close");
                        }
                        closeChannel(channel);
                        return null;
                }

                return channel;
            }
        };


private boolean isAddressBanned(InetAddress address){

        if(address==null){
            return false;
        }

        return bannedMap.containsKey(address.getHostAddress());
    }



2010/2/16 Paul Sandoz <Paul.Sandoz_at_sun.com>

> Hi Gary,
>
> On Feb 16, 2010, at 7:51 PM, Gary Murphy wrote:
>
> I would like to get the remote IP address of the JAX-RS client for
>> logging purposes. I understand that I can inject an HttpServletRequest
>> if I am running in a servlet container, but I am using the Grizzly
>> server embedded in my application container.
>>
>> I looked through the Grizzly documentation and can't quite determine
>> what class I need to implement (ProtocolHandler, perhaps?) and how to
>> attach it to the Grizzly pipeline created for me by the Jersey
>> integration with Grizzly.
>>
>> I would prefer a lower-level technique so I can integrate it in my
>> application framework instead of injecting into each resource.
>>
>>
> Hmm... cross posting to the Grizzly users list.
>
> If there is a way to get the client IP address from the low-level Grizzly
> request i can add a method to HttpRequestContext so that it is supported in
> a platform independent way.
>
> Paul.
>
>
> Thanks.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>
>


-- 
-------------
A+
Sébastien.
Vous pouvez me suivre sur Twitter / You can follow me on Twitter :
http://twitter.com/survivant