Tuesday 15 September 2015

java - How can I get my hands on client addresses for logging using Grizzly / Jersey? -


I am using the grizzly to serve time, Jersey application using Logbak for its logging requirements do Do not do that there is no servlet in it, I use a piece of code in this way, "fire" with fire:

  last URI Yuri = / * This is a configuration option / * this. Server = new HttpServer (); Final NetworkListener NLL = New NetworkListener ("Brown", YuriGetHost (), Yuri.portport ()); Server.addListener (nl); Last GuiceComponentProviderGcpf = New GuiceComponentProviderFactory (RC, Inje); Last HTHandler processor = ContainerFactor.CreateTurner (HTTendler, Class, RC, GCPF); This.server.getServerConfiguration (). AddHttpHandler (processor, uri.getPath ()); Server.start ();   

Now I would like to use the logback feature to create the socket address of the visible client in the log record. For this purpose I have asked about the need to replace that incoming requests (where can I put out MDC) to hook the listener for the HTTP processing and when a request for (so I can clean MDC). I just have to follow an approach, it is a container * Filter for example to hook up with the jersey, which looks like this:

  class mdcfilter Kantenrreksef filters, containers Risponsfiltr {@Override, public container request file (container request) to achieve {MDC.put (" http-client "," foo "/ * address There is no way / /); Return request; } @ Override Public Container Response Filters (ContainerQuestion Requests, Container Response Feedback) {MDC.remove ("http-client"); Return feedback; Unfortunately, a jersey does not provide info about the client  container request  (which make Cam a real surprise).  

I must have a similar interface with Grizzly, but I am unable to dig it.

For Grizzly, the related API is called. By using this, something like this happens:

  the last HTTP server server = new org.glassfish.grizzly.http.server.HttpServer (); Server.addListener (new networkist ("brown", "localhost", 8080)); Server.getServerConfiguration (). AddHttpHandler (New StaticHttpHandler ("/ var / www /", "/"); Server.getServerConfiguration (). GetMonitoringConfig () GetWebServerConfig () .addProbes (new HttpServerProbe.Adapter () {@Override public void onRequestReceiveEvent (HttpServerFilter filter, connection, request) {System.out.println (request.getRemoteAddr ()); MDC.put ( "http- client ", request.getRemoteAddr ());} @ override public void Prsurcshapuarn full (HttpServerFilter filter, connection, replies response) {MDC.remove (" http-client ");}} server Note that (START);   

Note that there may be more incidents that may be relevant, such as suspension, resume and cancel It may be handled well, especially if voting for long periods, aka whatnot ) is used. But basically it is the place to penetrate them.

No comments:

Post a Comment