public void handleMessage(Message message) throws Fault {
   final OutputStream os = message.getContent(OutputStream.class);
   final Writer iowriter = message.getContent(Writer.class);
   if (os == null && iowriter == null) {
     return;
   }
   Logger logger = getMessageLogger(message);
   if (logger.isLoggable(Level.INFO) || writer != null) {
     // Write the output while caching it for the log message
     boolean hasLogged = message.containsKey(LOG_SETUP);
     if (!hasLogged) {
       message.put(LOG_SETUP, Boolean.TRUE);
       if (os != null) {
         final CacheAndWriteOutputStream newOut = new CacheAndWriteOutputStream(os);
         if (threshold > 0) {
           newOut.setThreshold(threshold);
         }
         if (limit > 0) {
           newOut.setCacheLimit(limit);
         }
         message.setContent(OutputStream.class, newOut);
         newOut.registerCallback(new LoggingCallback(logger, message, os));
       } else {
         message.setContent(Writer.class, new LogWriter(logger, message, iowriter));
       }
     }
   }
 }
Exemple #2
0
 private OutputStream createCachingOut(
     Message message, final OutputStream os, CachedOutputStreamCallback callback) {
   final CacheAndWriteOutputStream newOut = new CacheAndWriteOutputStream(os);
   if (threshold > 0) {
     newOut.setThreshold(threshold);
   }
   if (limit > 0) {
     newOut.setCacheLimit(limit);
   }
   newOut.registerCallback(callback);
   return newOut;
 }
  /** @param message */
  @Override
  public void handleMessage(SoapMessage message) throws Fault {
    long l = LOG.logStart();

    final OutputStream os = message.getContent(OutputStream.class);
    boolean isRequestor = MessageUtils.isRequestor(message);
    if (os == null) {
      LOG.logWarn("Could not log message because it not contains OutputStream!", null);
      return;
    }
    // create store file
    File fStore;
    if (isRequestor) {
      MSHOutMail rq = SoapUtils.getMSHOutMail(message);
      fStore = EBMSLogUtils.getOutboundFileName(true, rq.getId(), null);
    } else {
      // get base from input log file
      String base =
          (String) message.getExchange().get(EBMSConstants.EBMS_CP_BASE_LOG_SOAP_MESSAGE_FILE);
      fStore = EBMSLogUtils.getOutboundFileName(false, null, base);
    }

    LOG.log("Out " + (isRequestor ? "request" : "response") + " stored to:" + fStore.getName());
    message
        .getExchange()
        .put(
            EBMSConstants.EBMS_CP_BASE_LOG_SOAP_MESSAGE_FILE, EBMSLogUtils.getBaseFileName(fStore));
    message.getExchange().put(EBMSConstants.EBMS_CP_OUT_LOG_SOAP_MESSAGE_FILE, fStore);

    //  create FileOutputStream to log request
    FileOutputStream fos;
    try {
      fos = new FileOutputStream(fStore);
    } catch (FileNotFoundException ex) {
      String errmsg =
          "Could not log outbound message to file: '" + fStore.getAbsolutePath() + "'! ";
      LOG.logError(l, errmsg, ex);
      return;
    }

    // create  CacheAndWriteOutputStream
    final CacheAndWriteOutputStream newOut = new CacheAndWriteOutputStream(os);

    message.setContent(OutputStream.class, newOut);
    newOut.registerCallback(new LoggingCallback(fos, message, os, fStore));

    LOG.logEnd(l);
  }