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.systest.ws.policy;
19:
20: import java.util.Collection;
21: import java.util.Iterator;
22: import java.util.logging.Logger;
23:
24: import org.apache.cxf.Bus;
25: import org.apache.cxf.endpoint.Endpoint;
26: import org.apache.cxf.helpers.CastUtils;
27: import org.apache.cxf.interceptor.Fault;
28: import org.apache.cxf.message.Message;
29: import org.apache.cxf.phase.AbstractPhaseInterceptor;
30: import org.apache.cxf.phase.Phase;
31: import org.apache.cxf.service.model.BindingOperationInfo;
32: import org.apache.cxf.service.model.EndpointInfo;
33: import org.apache.cxf.transport.http.policy.PolicyUtils;
34: import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
35: import org.apache.cxf.ws.policy.EffectivePolicy;
36: import org.apache.cxf.ws.policy.PolicyEngine;
37: import org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion;
38: import org.apache.neethi.Assertion;
39:
40: public class PolicyLoggingInterceptor extends AbstractPhaseInterceptor {
41:
42: private static final Logger LOG = Logger
43: .getLogger(PolicyLoggingInterceptor.class.getName());
44:
45: private Bus bus;
46:
47: PolicyLoggingInterceptor(boolean o) {
48: super (o ? Phase.POST_STREAM : Phase.POST_INVOKE);
49: }
50:
51: public void setBus(Bus b) {
52: bus = b;
53: }
54:
55: public void handleMessage(Message message) throws Fault {
56: EndpointInfo ei = message.getExchange().get(Endpoint.class)
57: .getEndpointInfo();
58: BindingOperationInfo boi = message.getExchange().get(
59: BindingOperationInfo.class);
60: LOG
61: .fine("Getting effective server request policy for endpoint "
62: + ei + " and binding operation " + boi);
63: EffectivePolicy ep = bus.getExtension(PolicyEngine.class)
64: .getEffectiveServerRequestPolicy(ei, boi);
65: for (Iterator it = ep.getPolicy().getAlternatives(); it
66: .hasNext();) {
67: Collection<Assertion> as = CastUtils.cast((Collection) it
68: .next(), Assertion.class);
69: LOG.fine("Checking alternative with " + as.size()
70: + " assertions.");
71: for (Assertion a : as) {
72: LOG.fine("Assertion: " + a.getClass().getName());
73: HTTPServerPolicy p = (JaxbAssertion.cast(a,
74: HTTPServerPolicy.class)).getData();
75: LOG.fine("server policy: " + PolicyUtils.toString(p));
76: }
77: }
78:
79: }
80:
81: }
|