View Javadoc
1   /*
2    * Copyright 2012 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.openehealth.ipf.commons.ihe.ws.cxf.payload;
17  
18  import lombok.experimental.Delegate;
19  import org.apache.cxf.binding.soap.SoapMessage;
20  import org.apache.cxf.interceptor.AttachmentOutInterceptor;
21  import org.apache.cxf.message.Message;
22  import org.apache.cxf.phase.Phase;
23  import org.apache.cxf.phase.PhaseInterceptor;
24  import org.openehealth.ipf.commons.ihe.core.payload.ExpressionResolver;
25  import org.openehealth.ipf.commons.ihe.core.payload.SpringExpressionResolver;
26  import org.openehealth.ipf.commons.ihe.ws.cxf.AbstractSafeInterceptor;
27  
28  import java.util.Arrays;
29  import java.util.Collection;
30  
31  /**
32   * CXF interceptor which stores outgoing HTTP payload
33   * into files with user-defined name patterns.
34   * <p>
35   * Members of {@link WsPayloadLoggerBase} are mixed into this class.
36   *
37   * @author Dmytro Rud
38   */
39  public class OutPayloadLoggerInterceptor extends AbstractSafeInterceptor {
40      @Delegate private final WsPayloadLoggerBase base = new WsPayloadLoggerBase();
41  
42      public OutPayloadLoggerInterceptor(String fileNamePattern) {
43          this(new SpringExpressionResolver(fileNamePattern));
44      }
45  
46      /**
47       * Instantiation, explicitly using a ExpressionResolver instance
48       *
49       * @param resolver ExpressionResolver instance
50       * @since 3.1
51       */
52      public OutPayloadLoggerInterceptor(ExpressionResolver resolver) {
53          super(Phase.PRE_STREAM_ENDING);
54          addAfter(AttachmentOutInterceptor.AttachmentOutEndingInterceptor.class.getName());
55          setExpressionResolver(resolver);
56      }
57  
58      @Override
59      public Collection<PhaseInterceptor<? extends Message>> getAdditionalInterceptors() {
60          return Arrays.asList(
61                  new DisablePayloadCollectingDeactivationInterceptor(),
62                  new OutStreamSubstituteInterceptor());
63      }
64  
65  
66      @Override
67      public void process(SoapMessage message) {
68          if (canProcess()) {
69              logPayload(message);
70          }
71      }
72  
73  }