alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Apache CXF example source code file (AbstractPhaseInterceptor.java)

This example Apache CXF source code file (AbstractPhaseInterceptor.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Apache CXF tags/keywords

abstractphaseinterceptor, abstractphaseinterceptor, get, message, phaseinterceptor, set, set, sortedarrayset, sortedarrayset, string, string, util

The Apache CXF AbstractPhaseInterceptor.java source code

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.cxf.phase;

import java.util.Collection;
import java.util.Set;

import javax.xml.stream.XMLStreamReader;

import org.apache.cxf.common.util.SortedArraySet;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageUtils;

/**
 * Provides a starting point implementation for a interceptors that 
 * participate in phased message processing. Developers should extend from 
 * this class when implementing custom interceptors.
 * Developers need to provide an implementation for handleMessage() and 
 * can overide the handleFault() implementation. They should not overide 
 * the other methods.
 */
public abstract class AbstractPhaseInterceptor<T extends Message> implements PhaseInterceptor {
    private final String id;
    private final String phase;
    private final Set<String> before = new SortedArraySet();
    private final Set<String> after = new SortedArraySet();

    /**
     * Instantiates the interceptor to live in a specified phase. The 
     * interceptor's id will be set to the name of the implementing class.
     *
     * @param phase the interceptor's phase
     */
    public AbstractPhaseInterceptor(String phase) {
        this(null, phase, false);
    }

    /**
     * Instantiates the interceptor with a specified id.
     *
     * @param i the interceptor's id
     * @param p the interceptor's phase
     */
    public AbstractPhaseInterceptor(String i, String p) {
        this(i, p, false);
    }

    /**
     * Instantiates the interceptor and specifies if it gets a system 
     * determined unique id. If <code>uniqueId is set to true the 
     * interceptor's id will be determined by the runtime. If 
     * <code>uniqueId is set to false, the implementing class' name 
     * is used as the id.
     *
     * @param p the interceptor's phase
     * @param uniqueId
     */
    public AbstractPhaseInterceptor(String phase, boolean uniqueId) {
        this(null, phase, uniqueId);
    }

    /**
     * Instantiates the interceptor with a specified id or with a system 
     * determined unique id. The specified id will be used unless 
     * <code>uniqueId is set to true.
     *
     * @param i the interceptor's id
     * @param p the interceptor's phase
     * @param uniqueId
     */
    public AbstractPhaseInterceptor(String i, String p, boolean uniqueId) {
        if (i == null) {
            i = getClass().getName();
        }
        if (uniqueId) {
            i += System.identityHashCode(this);
        }
        id = i;
        phase = p;
    }
    
    /**
     * Specifies that the current interceptor needs to be added to the 
     * interceptor chain before the specified collection of interceptors. 
     * This method replaces any existing list with the provided list.
     * 
     * @param i a collection of interceptor ids
     */
    public void setBefore(Collection<String> i) {
        before.clear();
        before.addAll(i);
    }

    /**
     * Specifies that the current interceptor needs to be added to the 
     * interceptor chain after the specified collection of interceptors.
     * This method replaces any existing list with the provided list.
     * 
     * @param i a collection of interceptor ids
     */
    public void setAfter(Collection<String> i) {
        after.clear();
        after.addAll(i);
    }

    /**
     * Specifies that the current interceptor needs to be added to the 
     * interceptor chain before the specified collection of interceptors.
     * 
     * @param i a collection of interceptor ids
     */
    public void addBefore(Collection<String> i) {
        before.addAll(i);
    }

    /**
     * Specifies that the current interceptor needs to be added to the 
     * interceptor chain after the specified collection of interceptors.
     * 
     * @param i a collection of interceptor ids
     */
    public void addAfter(Collection<String> i) {
        after.addAll(i);
    }
    
    /**
     * Specifies that the current interceptor needs to be added to the 
     * interceptor chain before the specified interceptor.
     * 
     * @param i an interceptor id
     */
    public void addBefore(String i) {
        before.add(i);
    }

    /**
     * Specifies that the current interceptor needs to be added to the 
     * interceptor chain after the specified interceptor.
     * 
     * @param i an interceptor id
     */
    public void addAfter(String i) {
        after.add(i);
    }


    public final Set<String> getAfter() {
        return after;
    }

    public final Set<String> getBefore() {
        return before;
    }

    public final String getId() {
        return id;
    }

    public final String getPhase() {
        return phase;
    }


    public void handleFault(T message) {
    }

    public boolean isGET(T message) {
        String method = (String)message.get(Message.HTTP_REQUEST_METHOD);
        return "GET".equals(method) && message.getContent(XMLStreamReader.class) == null;
    }
    
    /**
     * Determine if current messaging role is that of requestor.
     * 
     * @param message the current Message
     * @return true if the current messaging role is that of requestor
     */
    protected boolean isRequestor(T message) {
        return MessageUtils.isRequestor(message);
    }  

}

Other Apache CXF examples (source code examples)

Here is a short list of links related to this Apache CXF AbstractPhaseInterceptor.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.