01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.interceptor;
19:
20: import java.io.IOException;
21: import java.io.InputStream;
22: import java.util.logging.Level;
23: import java.util.logging.Logger;
24:
25: import org.apache.cxf.common.logging.LogUtils;
26: import org.apache.cxf.helpers.IOUtils;
27: import org.apache.cxf.io.CachedOutputStream;
28: import org.apache.cxf.message.Message;
29: import org.apache.cxf.phase.AbstractPhaseInterceptor;
30: import org.apache.cxf.phase.Phase;
31:
32: /**
33: * A simple logging handler which outputs the bytes of the message to the
34: * Logger.
35: */
36: public class LoggingInInterceptor extends
37: AbstractPhaseInterceptor<Message> {
38:
39: private static final Logger LOG = LogUtils
40: .getL7dLogger(LoggingInInterceptor.class);
41:
42: public LoggingInInterceptor() {
43: super (Phase.RECEIVE);
44: }
45:
46: public void handleMessage(Message message) throws Fault {
47: InputStream is = message.getContent(InputStream.class);
48:
49: if (is == null) {
50: return;
51: }
52:
53: if (LOG.isLoggable(Level.INFO)) {
54: CachedOutputStream bos = new CachedOutputStream();
55: try {
56: IOUtils.copy(is, bos);
57:
58: is.close();
59: bos.close();
60:
61: LOG.info("Inbound Message\n"
62: + "--------------------------------------\n"
63: + bos.getOut().toString()
64: + "\n--------------------------------------");
65:
66: message.setContent(InputStream.class, bos
67: .getInputStream());
68:
69: } catch (IOException e) {
70: throw new Fault(e);
71: }
72: }
73: }
74:
75: }
|