1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.ihe.ws.cxf.payload;
17
18 import org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor;
19 import org.apache.cxf.message.Message;
20 import org.apache.cxf.phase.AbstractPhaseInterceptor;
21 import org.apache.cxf.phase.Phase;
22 import org.openehealth.ipf.commons.ihe.ws.utils.SoapUtils;
23 import static org.openehealth.ipf.commons.ihe.ws.cxf.payload.StringPayloadHolder.PayloadType.SOAP_BODY;
24
25
26
27
28
29
30
31
32 public class OutPayloadExtractorInterceptor extends AbstractPhaseInterceptor<Message> {
33
34
35
36
37
38
39 public static final String PAYLOAD_COLLECTING_DEACTIVATION_ENABLED =
40 OutPayloadExtractorInterceptor.class.getName() + ".collecting.deactivation.enabled";
41
42
43 public OutPayloadExtractorInterceptor() {
44 super(Phase.PRE_PROTOCOL_ENDING);
45 addAfter(SAAJOutInterceptor.SAAJOutEndingInterceptor.class.getName());
46 }
47
48
49 @Override
50 public void handleMessage(Message message) {
51 if (isGET(message)) {
52 return;
53 }
54
55 WrappedOutputStream wrapper = OutStreamSubstituteInterceptor.getStreamWrapper(message);
56 if (! Boolean.FALSE.equals(message.getContextualProperty(PAYLOAD_COLLECTING_DEACTIVATION_ENABLED))) {
57 wrapper.deactivate();
58 }
59
60 String soapEnvelope = wrapper.getCollectedPayload();
61 String payload = SoapUtils.extractSoapBody(soapEnvelope);
62 StringPayloadHolder payloadHolder = new StringPayloadHolder();
63 payloadHolder.put(SOAP_BODY, payload);
64 message.setContent(StringPayloadHolder.class, payloadHolder);
65 }
66 }