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.Destination;
035: import org.apache.neethi.Assertion;
036:
037: /**
038: *
039: */
040: public class ServerPolicyOutInterceptor extends
041: AbstractPolicyInterceptor {
042:
043: private static final Logger LOG = LogUtils
044: .getL7dLogger(ServerPolicyOutInterceptor.class);
045:
046: public ServerPolicyOutInterceptor() {
047: super (PolicyConstants.SERVER_POLICY_OUT_INTERCEPTOR_ID,
048: Phase.SETUP);
049: }
050:
051: protected void handle(Message msg) {
052: if (MessageUtils.isRequestor(msg)) {
053: LOG.fine("Is 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: Destination destination = exchange.getDestination();
080: EffectivePolicy effectivePolicy = pe
081: .getEffectiveServerResponsePolicy(ei, boi, destination);
082: msg.put(EffectivePolicy.class, effectivePolicy);
083:
084: List<Interceptor> interceptors = effectivePolicy
085: .getInterceptors();
086: for (Interceptor oi : interceptors) {
087: msg.getInterceptorChain().add(oi);
088: LOG.log(Level.INFO, "Added interceptor of type {0}", oi
089: .getClass().getSimpleName());
090: }
091:
092: // insert assertions of the chosen alternative into the message
093:
094: Collection<Assertion> assertions = effectivePolicy
095: .getChosenAlternative();
096: if (null != assertions) {
097: msg.put(AssertionInfoMap.class, new AssertionInfoMap(
098: assertions));
099: }
100: }
101: }
|