Search code examples
javagoogle-app-enginegoogle-cloud-endpoints

Getting raw HTTP Data (Headers, Cookies, etc) in Google Cloud Endpoints


I am wondering if it is possible to collect raw HTTP data in a Cloud Endpoint. I can't seem to find anything in Google's documentation, but App Engine's Twitter told me that it was (https://twitter.com/app_engine/status/305747445017624576). If so, can I please have syntax for it? I am aware that the API for GCE is still in its early stages, and any help would be greatly appreciated.


Solution

  • Add an HttpServletRequest parameter to your endpoint method, e.g.

    @ApiMethod
    public MyResponse getResponse( HttpServletRequest req, @Named("infoId") String infoId ) {
        // Use 'req' as you would in a servlet, e.g.
        String ipAddress = req.getRemoteAddr();
        ...
    }