001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.ws.policy;
019:
020: import org.apache.cxf.Bus;
021: import org.apache.cxf.interceptor.Fault;
022: import org.apache.cxf.message.Exchange;
023: import org.apache.cxf.message.Message;
024: import org.apache.cxf.phase.AbstractPhaseInterceptor;
025: import org.apache.cxf.service.model.BindingFaultInfo;
026: import org.apache.cxf.service.model.BindingOperationInfo;
027: import org.apache.cxf.transport.Conduit;
028: import org.apache.cxf.transport.Destination;
029:
030: /**
031: *
032: */
033: public abstract class AbstractPolicyInterceptor extends
034: AbstractPhaseInterceptor<Message> {
035:
036: protected Bus bus;
037:
038: public AbstractPolicyInterceptor(String phase) {
039: super (phase);
040: }
041:
042: public AbstractPolicyInterceptor(String id, String phase) {
043: super (id, phase);
044: }
045:
046: public void setBus(Bus b) {
047: bus = b;
048: }
049:
050: public Bus getBus() {
051: return bus;
052: }
053:
054: public void handleMessage(Message message) throws Fault {
055: try {
056: handle(message);
057: } catch (PolicyException ex) {
058: throw new Fault(ex);
059: }
060: }
061:
062: protected void getTransportAssertions(Message message) {
063: Exchange ex = message.getExchange();
064: Assertor assertor = null;
065: Conduit conduit = ex.getConduit(message);
066: if (conduit instanceof Assertor) {
067: assertor = (Assertor) conduit;
068: } else {
069: Destination destination = ex.getDestination();
070: if (destination instanceof Assertor) {
071: assertor = (Assertor) destination;
072: }
073: }
074: if (null != assertor) {
075: assertor.assertMessage(message);
076: }
077: }
078:
079: protected BindingFaultInfo getBindingFaultInfo(Message msg,
080: Exception ex, BindingOperationInfo boi) {
081: BindingFaultInfo bfi = msg.get(BindingFaultInfo.class);
082: if (null == bfi) {
083: Throwable cause = ex.getCause();
084: if (null == cause) {
085: return null;
086: }
087: for (BindingFaultInfo b : boi.getFaults()) {
088: Class<?> faultClass = b.getFaultInfo().getProperty(
089: Class.class.getName(), Class.class);
090: if (faultClass.isAssignableFrom(cause.getClass())) {
091: bfi = b;
092: msg.put(BindingFaultInfo.class, bfi);
093: break;
094: }
095: }
096: if (null == bfi && null != boi.getWrappedOperation()) {
097: for (BindingFaultInfo b : boi.getWrappedOperation()
098: .getFaults()) {
099: Class<?> faultClass = b.getFaultInfo().getProperty(
100: Class.class.getName(), Class.class);
101: if (faultClass.isAssignableFrom(cause.getClass())) {
102: bfi = b;
103: msg.put(BindingFaultInfo.class, bfi);
104: break;
105: }
106: }
107: }
108: }
109: return bfi;
110: }
111:
112: protected abstract void handle(Message message)
113: throws PolicyException;
114:
115: }
|