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.Destination;
34: import org.apache.neethi.Assertion;
35:
36: /**
37: *
38: */
39: public class ServerPolicyInInterceptor extends
40: AbstractPolicyInterceptor {
41:
42: private static final Logger LOG = LogUtils
43: .getL7dLogger(ServerPolicyInInterceptor.class);
44:
45: public ServerPolicyInInterceptor() {
46: super (PolicyConstants.SERVER_POLICY_IN_INTERCEPTOR_ID,
47: Phase.RECEIVE);
48: }
49:
50: protected void handle(Message msg) {
51: if (MessageUtils.isRequestor(msg)) {
52: LOG.fine("Is 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: Destination destination = exchange.getDestination();
72:
73: // We do not know the underlying message type yet - so we pre-emptively add interceptors
74: // that can deal with any messages to this endpoint
75:
76: EndpointPolicy ep = pe.getServerEndpointPolicy(ei, destination);
77:
78: List<Interceptor> interceptors = ep.getInterceptors();
79: for (Interceptor i : interceptors) {
80: msg.getInterceptorChain().add(i);
81: LOG.log(Level.INFO, "Added interceptor of type {0}", i
82: .getClass().getSimpleName());
83: }
84:
85: // insert assertions of endpoint's vocabulary into message
86:
87: Collection<Assertion> assertions = ep.getVocabulary();
88: if (null != assertions) {
89: msg.put(AssertionInfoMap.class, new AssertionInfoMap(
90: assertions));
91: }
92: }
93: }
|