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.systest.ws.addressing;
019:
020: import java.util.ArrayList;
021: import java.util.HashMap;
022: import java.util.List;
023: import java.util.Map;
024:
025: import org.apache.cxf.message.Message;
026: import org.apache.cxf.phase.AbstractPhaseInterceptor;
027: import org.apache.cxf.phase.Phase;
028: import org.apache.cxf.ws.addressing.AddressingPropertiesImpl;
029: import org.apache.cxf.ws.addressing.ContextUtils;
030: import org.apache.cxf.ws.addressing.Names;
031:
032: import static org.apache.cxf.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_INBOUND;
033: import static org.apache.cxf.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_OUTBOUND;
034:
035: /**
036: * Verifies presence of MAPs in the context.
037: */
038: public class MAPVerifier extends AbstractPhaseInterceptor<Message> {
039: VerificationCache verificationCache;
040: List<String> expectedExposedAs = new ArrayList<String>();
041: private Map<String, Object> mapProperties;
042:
043: public MAPVerifier() {
044: super (Phase.POST_LOGICAL);
045: mapProperties = new HashMap<String, Object>();
046: mapProperties.put(MAPTest.INBOUND_KEY,
047: CLIENT_ADDRESSING_PROPERTIES_INBOUND);
048: mapProperties.put(MAPTest.OUTBOUND_KEY,
049: CLIENT_ADDRESSING_PROPERTIES_OUTBOUND);
050: }
051:
052: public void handleMessage(Message message) {
053: verify(message);
054: }
055:
056: public void handleFault(Message message) {
057: verify(message);
058: }
059:
060: private void verify(Message message) {
061: boolean isOutbound = ContextUtils.isOutbound(message);
062: String mapProperty = (String) mapProperties
063: .get(isOutbound ? MAPTest.OUTBOUND_KEY
064: : MAPTest.INBOUND_KEY);
065: AddressingPropertiesImpl maps = (AddressingPropertiesImpl) message
066: .get(mapProperty);
067: if (ContextUtils.isRequestor(message)) {
068: if (isOutbound) {
069: String exposeAs = getExpectedExposeAs(false);
070: if (exposeAs != null) {
071: maps.exposeAs(exposeAs);
072: }
073: } else {
074: String exposeAs = getExpectedExposeAs(true);
075: String expected = exposeAs != null ? exposeAs
076: : Names.WSA_NAMESPACE_NAME;
077: if (maps.getNamespaceURI() != expected) {
078: verificationCache.put("Incoming version mismatch"
079: + " expected: " + expected + " got: "
080: + maps.getNamespaceURI());
081: }
082: exposeAs = null;
083: }
084: }
085: verificationCache.put(MAPTest.verifyMAPs(maps, this ));
086: }
087:
088: private String getExpectedExposeAs(boolean remove) {
089: int size = expectedExposedAs.size();
090: return size == 0 ? null : remove ? expectedExposedAs
091: .remove(size - 1) : expectedExposedAs.get(size - 1);
092: }
093:
094: public void setVerificationCache(VerificationCache cache) {
095: verificationCache = cache;
096: }
097:
098: public void addToExpectedExposedAs(String str) {
099: expectedExposedAs.add(str);
100: }
101: }
|