001 /**
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.ksb.impl.cxf.interceptors;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.apache.log4j.Logger;
020 import org.kuali.rice.core.api.config.property.Config;
021 import org.kuali.rice.core.api.config.property.ConfigContext;
022
023 import java.util.Collections;
024 import java.util.List;
025 import java.util.Map;
026
027 /**
028 * Helps populate service call protocol headers with Rice version information.
029 */
030 public class ServiceCallVersioningHelper {
031 private static final Logger LOG = Logger.getLogger(ServiceCallVersioningOutInterceptor.class);
032
033 public static final String KUALI_RICE_ENVIRONMENT_HEADER = "X-Kuali-Env";
034 public static final String KUALI_RICE_VERSION_HEADER = "X-Kuali-Rice-Ver";
035 public static final String KUALI_APP_NAME_HEADER = "X-Kuali-App-Name";
036 public static final String KUALI_APP_VERSION_HEADER = "X-Kuali-App-Ver";
037
038 private ServiceCallVersioningHelper() { /* static utility class */ }
039
040 /**
041 * Populates protocol headers represented by a map of list of strings with Kuali/Rice
042 * versioning information, including Rice environment and version, and Rice application
043 * name and version.
044 * @param headers the protocol headers. let's be honest, they are just HTTP headers.
045 */
046 public static void populateVersionHeaders(Map<String, List<String>> headers) {
047 Config config = ConfigContext.getCurrentContextConfig();
048 if (config == null) {
049 LOG.error("No configuration context found when handling outbound message");
050 // commented for the sake of tests
051 // assert config != null : "No configuration context found when handling outbound message";
052 return;
053 }
054
055 String riceEnvironment = config.getEnvironment();
056 assert StringUtils.isNotBlank(riceEnvironment) : "Rice environment should never be blank";
057 if (StringUtils.isNotBlank(riceEnvironment)) {
058 headers.put(KUALI_RICE_ENVIRONMENT_HEADER, Collections.singletonList(riceEnvironment));
059 }
060
061 String riceVersion = config.getRiceVersion();
062 assert StringUtils.isNotBlank(riceVersion) : "Rice version should never be blank";
063 if (StringUtils.isNotBlank(riceVersion)) {
064 headers.put(KUALI_RICE_VERSION_HEADER, Collections.singletonList(riceVersion));
065 }
066
067 String appName = config.getApplicationName();
068 if (StringUtils.isNotBlank(appName)) {
069 headers.put(KUALI_APP_NAME_HEADER, Collections.singletonList(appName));
070 }
071
072 String appVersion = config.getApplicationVersion();
073 if (StringUtils.isNotBlank(appVersion)) {
074 headers.put(KUALI_APP_VERSION_HEADER, Collections.singletonList(appVersion));
075 }
076 }
077 }