users@grizzly.java.net

can't figure out ClientIP (request.remoteAddr())

From: Xasima Xirohata <xasima_at_gmail.com>
Date: Tue, 4 Dec 2007 11:16:55 +0200

Hello. How to figure out the Client IP (or client ip behind proxy) using
standalone grizzly (with no glassfish installed) .

I've tried the following code and this returns NULL in request.remoteAddr
(); I've tried to test the code both from local and remote computer.

I have the grizzly-http-webserver-1.6.1/http-1.6.1.jar, lib/framework-
1.6.1.jar, lib/http-utils-1.6.1.jar, lib/rcm-1.6.1.jar in classpath.

I've tried the restlet project with grizzly connector before and bump into
the same situation. While jetty has returned user ip, grizzly does nothing.
Please, point me what i need to change in code to figure out the user ip
even user is located behind the proxy.



---------------------------------------------------------------------------------------------------
import java.net.HttpURLConnection;

import com.sun.grizzly.http.SelectorThread;
import com.sun.grizzly.tcp.Adapter;
import com.sun.grizzly.tcp.OutputBuffer;
import com.sun.grizzly.tcp.Request ;
import com.sun.grizzly.tcp.Response;
import com.sun.grizzly.util.buf.ByteChunk;
public class Agregator implements Adapter {




    private static ByteChunk chunk = new ByteChunk();


    public static void main(String[] args) {
        SelectorThread st = new SelectorThread();
        int port = 8080;
        st.setPort(port);
        st.setAdapter(new Agregator());
        try {
            st.initEndpoint();
            st.startEndpoint();
        } catch (Exception e) {
          System.out.println("Exception in SelectorThread: " + e);
        } finally {
            if (st.isRunning()) {
                st.stopEndpoint();
            }
        }
    }


    public void service(Request request, Response response) throws Exception
{
         //Look here
        System.out.println(request.remoteAddr());
        if (request.method().toString().equalsIgnoreCase("GET")) {
            response.setStatus(HttpURLConnection.HTTP_OK);
            response.finish();
        }
    }

    public void afterService(Request request, Response response)
            throws Exception {
        request.recycle();
        response.recycle();
    }

    public void fireAdapterEvent(String string, Object object) {
    }

}
---------------------------------------------------------------------------------------------------




-- 
Best regards,
    ~ Xasima Xirohata ~