View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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.kuali.rice.ksb.impl.cxf.interceptors;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.apache.log4j.Logger;
20  import org.kuali.rice.core.api.config.property.Config;
21  import org.kuali.rice.core.api.config.property.ConfigContext;
22  
23  import java.util.Collections;
24  import java.util.List;
25  import java.util.Map;
26  
27  /**
28   * Helps populate service call protocol headers with Rice version information.
29   */
30  public class ServiceCallVersioningHelper {
31      private static final Logger LOG = Logger.getLogger(ServiceCallVersioningOutInterceptor.class);
32  
33      public static final String KUALI_RICE_ENVIRONMENT_HEADER = "X-Kuali-Env";
34      public static final String KUALI_RICE_VERSION_HEADER = "X-Kuali-Rice-Ver";
35      public static final String KUALI_APP_NAME_HEADER = "X-Kuali-App-Name";
36      public static final String KUALI_APP_VERSION_HEADER = "X-Kuali-App-Ver";
37  
38      private ServiceCallVersioningHelper() { /* static utility class */ }
39  
40      /**
41       * Populates protocol headers represented by a map of list of strings with Kuali/Rice
42       * versioning information, including Rice environment and version, and Rice application
43       * name and version.
44       * @param headers the protocol headers. let's be honest, they are just HTTP headers.
45       */
46      public static void populateVersionHeaders(Map<String, List<String>> headers) {
47          Config config = ConfigContext.getCurrentContextConfig();
48          if (config == null) {
49              LOG.error("No configuration context found when handling outbound message");
50              // commented for the sake of tests
51              // assert config != null : "No configuration context found when handling outbound message";
52              return;
53          }
54  
55          String riceEnvironment = config.getEnvironment();
56          assert StringUtils.isNotBlank(riceEnvironment) : "Rice environment should never be blank";
57          if (StringUtils.isNotBlank(riceEnvironment)) {
58              headers.put(KUALI_RICE_ENVIRONMENT_HEADER, Collections.singletonList(riceEnvironment));
59          }
60  
61          String riceVersion = config.getRiceVersion();
62          assert StringUtils.isNotBlank(riceVersion) : "Rice version should never be blank";
63          if (StringUtils.isNotBlank(riceVersion)) {
64              headers.put(KUALI_RICE_VERSION_HEADER, Collections.singletonList(riceVersion));
65          }
66  
67          String appName = config.getApplicationName();
68           if (StringUtils.isNotBlank(appName)) {
69              headers.put(KUALI_APP_NAME_HEADER, Collections.singletonList(appName));
70          }
71  
72          String appVersion = config.getApplicationVersion();
73           if (StringUtils.isNotBlank(appVersion)) {
74              headers.put(KUALI_APP_VERSION_HEADER, Collections.singletonList(appVersion));
75          }
76      }
77  }