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.rm;
019:
020: import java.util.Collection;
021: import java.util.logging.Level;
022: import java.util.logging.Logger;
023:
024: import org.apache.cxf.Bus;
025: import org.apache.cxf.binding.Binding;
026: import org.apache.cxf.common.logging.LogUtils;
027: import org.apache.cxf.endpoint.Endpoint;
028: import org.apache.cxf.interceptor.Fault;
029: import org.apache.cxf.message.Message;
030: import org.apache.cxf.phase.AbstractPhaseInterceptor;
031: import org.apache.cxf.phase.Phase;
032: import org.apache.cxf.ws.policy.AssertionInfo;
033: import org.apache.cxf.ws.policy.AssertionInfoMap;
034:
035: /**
036: * Interceptor responsible for implementing exchange of RM protocol messages,
037: * aggregating RM metadata in the application message and processing of
038: * RM metadata contained in incoming application messages.
039: * The same interceptor can be used on multiple endpoints.
040: *
041: */
042: public abstract class AbstractRMInterceptor<T extends Message> extends
043: AbstractPhaseInterceptor<T> {
044:
045: private static final Logger LOG = LogUtils
046: .getL7dLogger(AbstractRMInterceptor.class);
047: private RMManager manager;
048: private Bus bus;
049:
050: protected AbstractRMInterceptor() {
051: super (Phase.PRE_LOGICAL);
052: }
053:
054: public RMManager getManager() {
055: if (null == manager) {
056: return bus.getExtension(RMManager.class);
057: }
058: return manager;
059: }
060:
061: public void setManager(RMManager m) {
062: manager = m;
063: }
064:
065: public Bus getBus() {
066: return bus;
067: }
068:
069: public void setBus(Bus bus) {
070: this .bus = bus;
071: }
072:
073: // Interceptor interface
074:
075: public void handleMessage(Message msg) throws Fault {
076:
077: try {
078: handle(msg);
079: } catch (SequenceFault sf) {
080:
081: // log the fault as it may not be reported back to the client
082:
083: Endpoint e = msg.getExchange().get(Endpoint.class);
084: Binding b = null;
085: if (null != e) {
086: b = e.getBinding();
087: }
088: if (null != b) {
089: RMManager m = getManager();
090: LOG.fine("Manager: " + m);
091: BindingFaultFactory bff = m.getBindingFaultFactory(b);
092: Fault f = bff.createFault(sf);
093: LogUtils.log(LOG, Level.SEVERE, "SEQ_FAULT_MSG", bff
094: .toString(f));
095: throw f;
096: }
097: throw new Fault(sf);
098: } catch (RMException ex) {
099: throw new Fault(ex);
100: }
101: }
102:
103: /**
104: * Asserts all RMAssertion assertions for the current message, regardless their attributes
105: * (if there is more thsn one we have ensured that they are all supported by considering
106: * e.g. the minimum acknowledgment interval).
107: * @param message the current message
108: */
109: void assertReliability(Message message) {
110: AssertionInfoMap aim = message.get(AssertionInfoMap.class);
111: if (null == aim) {
112: return;
113:
114: }
115: Collection<AssertionInfo> ais = aim.get(RMConstants
116: .getRMAssertionQName());
117: if (null == ais || ais.size() == 0) {
118: return;
119: }
120:
121: for (AssertionInfo ai : ais) {
122: ai.setAsserted(true);
123: }
124: }
125:
126: protected abstract void handle(Message message)
127: throws SequenceFault, RMException;
128:
129: }
|