cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Taucher <stefan.tauche...@gmail.com>
Subject LoggingOutInterceptor problem getting message id
Date Mon, 22 Dec 2014 15:22:58 GMT
We want to log the Request/Response to an ELK-Stack an therefor building
custom IN/OUT LoggingInterceptors.

The InInterceptor works flawlessly but the Out is making some problems.

Here are my 2 problems:

First of all i never get a massage id (which is essentual for our logging
system)
and the secound thing is that the first Response is never logged!

Here is the code

public class GelfLoggingOutInterceptor extends LoggingOutInterceptor
implements CachedOutputStreamCallback {

  private String payload;

  public GelfLoggingOutInterceptor() {
    super(Phase.WRITE);
  }

  @Override
  public void handleMessage(Message message) throws Fault {
    super.handleMessage(message);
    Logger logger_file =
LoggerFactory.getLogger(GelfLoggingOutInterceptor.class);
    try
    {
      Logger logger_gelf = LoggerFactory.getLogger("GELFAPPENDER");

      OutputStream os = message.getContent(OutputStream.class);
      CacheAndWriteOutputStream cwos = new CacheAndWriteOutputStream(os);
      message.setContent(OutputStream.class, cwos);

      cwos.registerCallback(this);

      String id = (String) message.get(Message);
      Integer responseCode = (Integer) message.get(Message.RESPONSE_CODE);
      String encoding = (String) message.get(Message.ENCODING);
      String contenttype = (String) message.get(Message.CONTENT_TYPE);
      Object headers = message.get(Message.PROTOCOL_HEADERS);

      MDC.put("ID", id);
      if (responseCode != null)
        MDC.put("ResponseCode", responseCode);
      MDC.put("Encoding", encoding);
      MDC.put("Content-Type", contenttype);
      if (headers != null)
        MDC.put("Header", headers);
      MDC.put("Message-Type", "Outbound");

      logger_gelf.info(payload);
    }

    catch (Exception ex)
    {
      ex.printStackTrace();
      StringBuilder sb = new StringBuilder();
      sb.append("Error at writing the gelf log ");
      sb.append(ex.getMessage());
      logger_file.warn(sb.toString());
    }
  }

  @Override
  protected void writePayload(StringBuilder builder, CachedOutputStream
cos, String encoding, String contentType) throws Exception {
    super.writePayload(builder, cos, encoding, contentType);

  }

  @Override
  public void onClose(CachedOutputStream cos) {
    {
      try
      {
        if (cos != null)
        {
          payload = IOUtils.toString(cos.getInputStream());
        }

      } catch (Exception e)
      {
        e.printStackTrace();
      }
    }

  }

  @Override
  public void onFlush(CachedOutputStream arg0) {
  }

}


Can anybody please help me!

Thanks for reading! :D

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message