1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.cxf.feature;
12
13 import org.mule.api.MuleException;
14 import org.mule.module.xml.transformer.XmlPrettyPrinter;
15 import org.mule.util.StringUtils;
16
17 import org.apache.cxf.Bus;
18 import org.apache.cxf.feature.LoggingFeature;
19 import org.apache.cxf.interceptor.InterceptorProvider;
20
21
22
23
24
25 public class PrettyLoggingFeature extends LoggingFeature
26 {
27 @Override
28 protected void initializeProvider(InterceptorProvider provider, Bus bus)
29 {
30 provider.getInInterceptors().add(new PrettyLoggingInInterceptor(getLimit()));
31 provider.getOutInterceptors().add(new PrettyLoggingOutInterceptor(getLimit()));
32 }
33
34
35
36
37
38
39 protected static String formatXmlPayload(String originalLogString)
40 {
41 String[] lines = originalLogString.split("\n");
42
43
44 int payloadLine = -1;
45 for (int i=0; i<lines.length; ++i)
46 {
47 if (lines[i].startsWith("Payload: "))
48 {
49 payloadLine = i;
50 break;
51 }
52 }
53 if (payloadLine == -1)
54 {
55 System.err.println("Could not find a line which begins with 'Payload: '");
56 return originalLogString;
57 }
58
59
60 String payload = lines[payloadLine];
61 String xml = StringUtils.substringAfter(payload, "Payload: ");
62 XmlPrettyPrinter pp = new XmlPrettyPrinter();
63 try
64 {
65 xml = (String) pp.transform(xml);
66 }
67 catch (MuleException e)
68 {
69 System.err.println(e.getMessage());
70 }
71
72
73 lines[payloadLine] = "Payload: \n" + xml;
74 return StringUtils.join(lines, "\n");
75 }
76 }