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 java.util.Collection;
021: import java.util.List;
022: import java.util.logging.Level;
023: import java.util.logging.Logger;
024:
025: import org.apache.cxf.common.logging.LogUtils;
026: import org.apache.cxf.endpoint.Endpoint;
027: import org.apache.cxf.interceptor.Interceptor;
028: import org.apache.cxf.message.Exchange;
029: import org.apache.cxf.message.Message;
030: import org.apache.cxf.message.MessageUtils;
031: import org.apache.cxf.phase.Phase;
032: import org.apache.cxf.service.model.BindingFaultInfo;
033: import org.apache.cxf.service.model.BindingOperationInfo;
034: import org.apache.cxf.service.model.EndpointInfo;
035: import org.apache.cxf.transport.Destination;
036: import org.apache.neethi.Assertion;
037:
038: /**
039: *
040: */
041: public class ServerPolicyOutFaultInterceptor extends
042: AbstractPolicyInterceptor {
043:
044: private static final Logger LOG = LogUtils
045: .getL7dLogger(ServerPolicyOutFaultInterceptor.class);
046:
047: public ServerPolicyOutFaultInterceptor() {
048: super (PolicyConstants.SERVER_POLICY_OUT_FAULT_INTERCEPTOR_ID,
049: Phase.SETUP);
050: }
051:
052: protected void handle(Message msg) {
053: if (MessageUtils.isRequestor(msg)) {
054: LOG.fine("Is a requestor.");
055: return;
056: }
057:
058: Exchange exchange = msg.getExchange();
059: assert null != exchange;
060:
061: BindingOperationInfo boi = exchange
062: .get(BindingOperationInfo.class);
063: if (null == boi) {
064: LOG.fine("No binding operation info.");
065: return;
066: }
067:
068: Endpoint e = exchange.get(Endpoint.class);
069: if (null == e) {
070: LOG.fine("No endpoint.");
071: return;
072: }
073: EndpointInfo ei = e.getEndpointInfo();
074:
075: PolicyEngine pe = bus.getExtension(PolicyEngine.class);
076: if (null == pe) {
077: return;
078: }
079:
080: Destination destination = exchange.getDestination();
081:
082: Exception ex = exchange.get(Exception.class);
083: assert null != ex;
084:
085: BindingFaultInfo bfi = getBindingFaultInfo(msg, ex, boi);
086: if (null == bfi) {
087: LOG.fine("No binding fault info.");
088: return;
089: }
090:
091: EffectivePolicy effectivePolicy = pe
092: .getEffectiveServerFaultPolicy(ei, bfi, destination);
093:
094: List<Interceptor> interceptors = effectivePolicy
095: .getInterceptors();
096: for (Interceptor oi : interceptors) {
097: msg.getInterceptorChain().add(oi);
098: LOG.log(Level.INFO, "Added interceptor of type {0}", oi
099: .getClass().getSimpleName());
100: }
101:
102: // insert assertions of the chosen alternative into the message
103:
104: Collection<Assertion> assertions = effectivePolicy
105: .getChosenAlternative();
106: if (null != assertions) {
107: msg.put(AssertionInfoMap.class, new AssertionInfoMap(
108: assertions));
109: }
110: }
111: }
|