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 | 0 | public class PrettyLoggingFeature extends LoggingFeature |
26 | |
{ |
27 | |
@Override |
28 | |
protected void initializeProvider(InterceptorProvider provider, Bus bus) |
29 | |
{ |
30 | 0 | provider.getInInterceptors().add(new PrettyLoggingInInterceptor(getLimit())); |
31 | 0 | provider.getOutInterceptors().add(new PrettyLoggingOutInterceptor(getLimit())); |
32 | 0 | } |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
protected static String formatXmlPayload(String originalLogString) |
40 | |
{ |
41 | 0 | String[] lines = originalLogString.split("\n"); |
42 | |
|
43 | |
|
44 | 0 | int payloadLine = -1; |
45 | 0 | for (int i=0; i<lines.length; ++i) |
46 | |
{ |
47 | 0 | if (lines[i].startsWith("Payload: ")) |
48 | |
{ |
49 | 0 | payloadLine = i; |
50 | 0 | break; |
51 | |
} |
52 | |
} |
53 | 0 | if (payloadLine == -1) |
54 | |
{ |
55 | 0 | System.err.println("Could not find a line which begins with 'Payload: '"); |
56 | 0 | return originalLogString; |
57 | |
} |
58 | |
|
59 | |
|
60 | 0 | String payload = lines[payloadLine]; |
61 | 0 | String xml = StringUtils.substringAfter(payload, "Payload: "); |
62 | 0 | XmlPrettyPrinter pp = new XmlPrettyPrinter(); |
63 | |
try |
64 | |
{ |
65 | 0 | xml = (String) pp.transform(xml); |
66 | |
} |
67 | 0 | catch (MuleException e) |
68 | |
{ |
69 | 0 | System.err.println(e.getMessage()); |
70 | 0 | } |
71 | |
|
72 | |
|
73 | 0 | lines[payloadLine] = "Payload: \n" + xml; |
74 | 0 | return StringUtils.join(lines, "\n"); |
75 | |
} |
76 | |
} |