1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.ihe.ws;
17
18 import java.util.List;
19
20 import org.apache.cxf.interceptor.Interceptor;
21 import org.apache.cxf.interceptor.InterceptorProvider;
22 import org.apache.cxf.message.Exchange;
23 import org.apache.cxf.message.Message;
24
25
26
27
28
29 abstract public class InterceptorUtils {
30
31 private InterceptorUtils() {
32 throw new IllegalStateException("Cannot instantiate utility class");
33 }
34
35
36 public static void copyInterceptorsFromProvider(
37 InterceptorProvider source,
38 InterceptorProvider target)
39 {
40 if (source != null) {
41 copyInterceptorsFromList(source.getInInterceptors(),
42 target.getInInterceptors());
43 copyInterceptorsFromList(source.getInFaultInterceptors(),
44 target.getInFaultInterceptors());
45 copyInterceptorsFromList(source.getOutInterceptors(),
46 target.getOutInterceptors());
47 copyInterceptorsFromList(source.getOutFaultInterceptors(),
48 target.getOutFaultInterceptors());
49 }
50 }
51
52 private static void copyInterceptorsFromList(
53 List<Interceptor<? extends Message>> source,
54 List<Interceptor<? extends Message>> target)
55 {
56 if (source != null) {
57 target.addAll(source);
58 }
59 }
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 public static <T> T findContextualProperty(Message message, String propertyName) {
76 Exchange exchange = message.getExchange();
77 Message[] messages = new Message[] {
78 message,
79 exchange.getInMessage(),
80 exchange.getOutMessage(),
81 exchange.getInFaultMessage(),
82 exchange.getOutFaultMessage()
83 };
84
85 for (Message m : messages) {
86 if (m != null) {
87 T t = (T) m.getContextualProperty(propertyName);
88 if (t != null) {
89 return t;
90 }
91 }
92 }
93 return null;
94 }
95
96 }