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.BindingOperationInfo;
033: import org.apache.cxf.service.model.EndpointInfo;
034: import org.apache.cxf.transport.Conduit;
035: import org.apache.neethi.Assertion;
036:
037: /**
038: *
039: */
040: public class ClientPolicyOutInterceptor extends
041: AbstractPolicyInterceptor {
042:
043: private static final Logger LOG = LogUtils
044: .getL7dLogger(ClientPolicyOutInterceptor.class);
045:
046: public ClientPolicyOutInterceptor() {
047: super (PolicyConstants.CLIENT_POLICY_OUT_INTERCEPTOR_ID,
048: Phase.SETUP);
049: }
050:
051: protected void handle(Message msg) {
052: if (!MessageUtils.isRequestor(msg)) {
053: LOG.fine("Not a requestor.");
054: return;
055: }
056:
057: Exchange exchange = msg.getExchange();
058: assert null != exchange;
059:
060: BindingOperationInfo boi = exchange
061: .get(BindingOperationInfo.class);
062: if (null == boi) {
063: LOG.fine("No binding operation info.");
064: return;
065: }
066:
067: Endpoint e = exchange.get(Endpoint.class);
068: if (null == e) {
069: LOG.fine("No endpoint.");
070: return;
071: }
072: EndpointInfo ei = e.getEndpointInfo();
073:
074: PolicyEngine pe = bus.getExtension(PolicyEngine.class);
075: if (null == pe) {
076: return;
077: }
078:
079: Conduit conduit = exchange.getConduit(msg);
080:
081: // add the required interceptors
082:
083: EffectivePolicy effectivePolicy = pe
084: .getEffectiveClientRequestPolicy(ei, boi, conduit);
085: msg.put(EffectivePolicy.class, effectivePolicy);
086: PolicyUtils
087: .logPolicy(LOG, Level.FINEST,
088: "Using effective policy: ", effectivePolicy
089: .getPolicy());
090:
091: List<Interceptor> interceptors = effectivePolicy
092: .getInterceptors();
093: for (Interceptor i : interceptors) {
094: msg.getInterceptorChain().add(i);
095: LOG.log(Level.INFO, "Added interceptor of type {0}", i
096: .getClass().getSimpleName());
097: }
098:
099: // insert assertions of the chosen alternative into the message
100:
101: Collection<Assertion> assertions = effectivePolicy
102: .getChosenAlternative();
103: if (null != assertions) {
104: if (LOG.isLoggable(Level.FINEST)) {
105: StringBuffer buf = new StringBuffer();
106: buf.append("Chosen alternative: ");
107: String nl = System.getProperty("line.separator");
108: buf.append(nl);
109: for (Assertion a : assertions) {
110: PolicyUtils.printPolicyComponent(a, buf, 1);
111: }
112: LOG.finest(buf.toString());
113: }
114: msg.put(AssertionInfoMap.class, new AssertionInfoMap(
115: assertions));
116: }
117: }
118: }
|