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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Xasima Xirohata
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 ~
Reply | Threaded
Open this post in threaded view
|

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

Alan Williamson
You need to tell Grizzly you want to read this information

in your service method put in:

   req.action(ActionCode.ACTION_REQ_HOST_ADDR_ATTRIBUTE, null);

[don't fool me for a Grizzly expert, this question i asked just last
week and Jeanfrancois contribued the answer]

:)

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

--
Alan Williamson
  "a wiki -and- a blog" @ http://www.Blog-City.com/

  b: http://alan.blog-city.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

charlie hunt-3
Alan,

You may not be a Grizzly expert, but you are quickly becoming one. ;-)

Thanks for jumping in and helping with questions.

charlie ...

Alan Williamson wrote:

> You need to tell Grizzly you want to read this information
>
> in your service method put in:
>
>   req.action(ActionCode.ACTION_REQ_HOST_ADDR_ATTRIBUTE, null);    
>
> [don't fool me for a Grizzly expert, this question i asked just last
> week and Jeanfrancois contribued the answer]
>
> :)
>
> Xasima Xirohata wrote:
>> Hello. How to figure out the Client IP (or client ip behind proxy)
>> using standalone grizzly (with no glassfish installed) .
>

--

Charlie Hunt
Java Performance Engineer

<http://java.sun.com/docs/performance/>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]