01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.ws.policy;
19:
20: import java.util.Collection;
21: import java.util.List;
22: import java.util.logging.Level;
23: import java.util.logging.Logger;
24:
25: import org.apache.cxf.common.logging.LogUtils;
26: import org.apache.cxf.endpoint.Endpoint;
27: import org.apache.cxf.interceptor.Interceptor;
28: import org.apache.cxf.message.Exchange;
29: import org.apache.cxf.message.Message;
30: import org.apache.cxf.message.MessageUtils;
31: import org.apache.cxf.phase.Phase;
32: import org.apache.cxf.service.model.EndpointInfo;
33: import org.apache.cxf.transport.Conduit;
34: import org.apache.neethi.Assertion;
35:
36: /**
37: *
38: */
39: public class ClientPolicyInFaultInterceptor extends
40: AbstractPolicyInterceptor {
41:
42: private static final Logger LOG = LogUtils
43: .getL7dLogger(ClientPolicyInFaultInterceptor.class);
44:
45: public ClientPolicyInFaultInterceptor() {
46: super (PolicyConstants.CLIENT_POLICY_IN_FAULT_INTERCEPTOR_ID,
47: Phase.RECEIVE);
48: }
49:
50: protected void handle(Message msg) {
51: if (!MessageUtils.isRequestor(msg)) {
52: LOG.fine("Not a requestor.");
53: return;
54: }
55:
56: Exchange exchange = msg.getExchange();
57: assert null != exchange;
58:
59: Endpoint e = exchange.get(Endpoint.class);
60: if (null == e) {
61: LOG.fine("No endpoint.");
62: return;
63: }
64: EndpointInfo ei = e.getEndpointInfo();
65:
66: PolicyEngine pe = bus.getExtension(PolicyEngine.class);
67: if (null == pe) {
68: return;
69: }
70:
71: Conduit conduit = exchange.getConduit(msg);
72: LOG.fine("conduit: " + conduit);
73:
74: // We do not know the underlying message type yet - so we pre-emptively add interceptors
75: // that can deal with all faults returned to this client endpoint.
76:
77: EndpointPolicy ep = pe.getClientEndpointPolicy(ei, conduit);
78: LOG.fine("ep: " + ep);
79:
80: List<Interceptor> faultInterceptors = ep.getFaultInterceptors();
81: LOG.fine("faultInterceptors: " + faultInterceptors);
82: for (Interceptor i : faultInterceptors) {
83: msg.getInterceptorChain().add(i);
84: LOG.log(Level.INFO, "Added interceptor of type {0}", i
85: .getClass().getSimpleName());
86: }
87:
88: // insert assertions of endpoint's fault vocabulary into message
89:
90: Collection<Assertion> assertions = ep.getFaultVocabulary();
91: if (null != assertions) {
92: msg.put(AssertionInfoMap.class, new AssertionInfoMap(
93: assertions));
94: }
95: }
96: }
|