1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.opensaml.ws.message.handler;
18
19 import org.opensaml.ws.message.MessageContext;
20 import org.opensaml.ws.message.encoder.BaseMessageEncoder;
21 import org.opensaml.ws.message.encoder.MessageEncodingException;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25
26
27
28 public abstract class BaseHandlerChainAwareMessageEncoder extends BaseMessageEncoder implements HandlerChainAware {
29
30
31 private final Logger log = LoggerFactory.getLogger(BaseHandlerChainAwareMessageEncoder.class);
32
33
34 protected void doEncode(MessageContext messageContext) throws MessageEncodingException {
35 prepareMessageContext(messageContext);
36
37 processOutboundHandlerChain(messageContext);
38
39 encodeToTransport(messageContext);
40 }
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 protected abstract void prepareMessageContext(MessageContext messageContext) throws MessageEncodingException;
60
61
62
63
64
65
66
67
68 protected abstract void encodeToTransport(MessageContext messageContext) throws MessageEncodingException;
69
70
71
72
73
74
75
76 protected void processOutboundHandlerChain(MessageContext messageContext) throws MessageEncodingException {
77 HandlerChainResolver outboundHandlerChainResolver = messageContext.getOutboundHandlerChainResolver();
78 if (outboundHandlerChainResolver != null) {
79 log.debug("Invoking outbound handler chain on message context");
80 try {
81 for (HandlerChain outboundHandlerChain : outboundHandlerChainResolver.resolve(messageContext)) {
82 if (outboundHandlerChain != null) {
83 invokeHandlerChain(outboundHandlerChain, messageContext);
84 }
85 }
86 } catch (HandlerException e) {
87 log.error("Encountered HandlerException when encoding message: {}", e.getMessage());
88 throw new MessageEncodingException("Handler exception while encoding message", e);
89 }
90 }
91 }
92
93
94
95
96
97
98
99
100
101 protected void invokeHandlerChain(HandlerChain handlerChain, MessageContext messageContext)
102 throws HandlerException {
103 if (handlerChain != null && messageContext != null) {
104 handlerChain.invoke(messageContext);
105 }
106 }
107
108 }