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