001/**
002 * Copyright 2005-2017 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 */
016package org.kuali.rice.ksb.impl.cxf.interceptors;
017
018import org.apache.cxf.interceptor.Fault;
019import org.apache.cxf.message.Message;
020import org.apache.cxf.phase.AbstractPhaseInterceptor;
021import org.apache.cxf.phase.Phase;
022
023import java.util.List;
024import java.util.Map;
025
026/**
027 * A CXF Interceptor that binds itself to the USER_PROTOCOL phase to be used on outbound
028 * messages.   The role of this interceptor is to populate outgoing protocol headers
029 * (for all intents and purposes, HTTP headers) with Kuali Rice and application version
030 * information.
031 * @see <a href="http://cxf.apache.org/docs/interceptors.html">CXF interceptors</a>
032 */
033public class ServiceCallVersioningOutInterceptor extends AbstractPhaseInterceptor<Message> {
034    /**
035     * Instantiates an ServiceCallVersioningOutInterceptor and adds it to the USER_PROTOCOL phase.
036     */
037    public ServiceCallVersioningOutInterceptor() {
038        super(Phase.USER_PROTOCOL);
039    }
040
041    /**
042     * Publishes the Kuali Rice Environment, Rice Version, Application Name and Application Version
043     * in outbound protocol headers
044     */
045    @Override
046    public void handleMessage(final Message message) throws Fault {
047        Map<String, List<String>> headers = (Map<String, List<String>>) message.get(Message.PROTOCOL_HEADERS);
048        if (headers != null) {
049            ServiceCallVersioningHelper.populateVersionHeaders(headers);
050        }
051    }
052}