View Javadoc
1   /*
2    * Copyright 2009 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;
17  
18  import org.slf4j.Logger;
19  import org.slf4j.LoggerFactory;
20  import org.apache.cxf.binding.soap.SoapMessage;
21  import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
22  import org.apache.cxf.message.Message;
23  
24  /**
25   * CXF interceptor which logs all errors instead of 
26   * letting them break the processing flow.
27   * @author Dmytro Rud
28   */
29  abstract public class AbstractSafeInterceptor extends AbstractSoapInterceptor {
30      private static final transient Logger LOG = LoggerFactory.getLogger(AbstractSafeInterceptor.class);
31  
32      /**
33       * Constructs the interceptor.
34       * @param phase
35       *          the phase in which the interceptor is run.
36       */
37      protected AbstractSafeInterceptor(String phase) {
38          super(phase);
39      }
40      
41      /**
42       * Performs the actual work, being called from {@link #handleMessage(Message)}.   
43       * 
44       * @param message
45       *          CXF message to process.
46       * @throws Exception
47       *          any exception that occurred when processing the message.
48       */
49      abstract protected void process(SoapMessage message) throws Exception;
50      
51      /**
52       * Calls {@link #process(org.apache.cxf.binding.soap.SoapMessage)}
53       * and "forwards" all exceptions to the error log.
54       * 
55       * @param message CXF message to process.
56       */
57      @Override
58      public final void handleMessage(SoapMessage message) {
59          try {
60              process(message);
61          } catch(Exception e) {
62              LOG.error(e.getMessage(), e);
63          }
64      }
65  
66  }