Skip to content

Question: How to get access to original HttpServletRequest from zalando HttpRequest #2080

@metalpalo

Description

@metalpalo

We have implemented custom sink for logbook logging(version 2.13.0):

@Bean
Sink customizedLogbookSink(HttpLogFormatter formatter, HttpLogWriter writer) {
    return new CustomSink(formatter, writer);
  }

Within this class is is possibe to get HttpRequest from zalando library but we want to have get original HttpServletRequest which is wrapped in 3rd level via delegate method.

Is possible to simply get this class if exists and get access to its attributes? For this moment when debuging it following code works for me but it can depend in concrete release or configuration:

if (request instanceof ForwardingHttpRequest) {//FilteredHttpRequest
        HttpRequest delegate1 = ((ForwardingHttpRequest) request).delegate();

        if (delegate1 instanceof ForwardingHttpRequest) {//CachingHttpRequest
          HttpRequest delegate2 = ((ForwardingHttpRequest) delegate1).delegate();

          if (delegate2 instanceof HttpServletRequest) {//RemoteRequest
            HttpServletRequest servletRequest = ((HttpServletRequest) delegate2);
            Object attribute = servletRequest.getAttribute("importantAttributeKey");
            System.out.println(attribute);
          }
        }
      }

thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions