01: package org.objectweb.celtix.systest.ws.addressing;
02:
03: import java.util.ArrayList;
04: import java.util.HashMap;
05: import java.util.List;
06: import java.util.Map;
07:
08: import javax.xml.ws.handler.LogicalHandler;
09: import javax.xml.ws.handler.LogicalMessageContext;
10: import javax.xml.ws.handler.MessageContext;
11:
12: import org.objectweb.celtix.bus.ws.addressing.AddressingPropertiesImpl;
13: import org.objectweb.celtix.bus.ws.addressing.ContextUtils;
14: import org.objectweb.celtix.bus.ws.addressing.Names;
15: import static org.objectweb.celtix.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_INBOUND;
16: import static org.objectweb.celtix.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_OUTBOUND;
17:
18: /**
19: * Verifies presence of MAPs in the context.
20: */
21: public class MAPVerifier implements
22: LogicalHandler<LogicalMessageContext> {
23: VerificationCache verificationCache;
24: List<String> expectedExposedAs = new ArrayList<String>();
25: private Map<String, Object> mapProperties;
26:
27: public MAPVerifier() {
28: mapProperties = new HashMap<String, Object>();
29: mapProperties.put(MAPTest.INBOUND_KEY,
30: CLIENT_ADDRESSING_PROPERTIES_INBOUND);
31: mapProperties.put(MAPTest.OUTBOUND_KEY,
32: CLIENT_ADDRESSING_PROPERTIES_OUTBOUND);
33: }
34:
35: public void init(Map<String, Object> params) {
36: if (params != null && params.size() > 0) {
37: mapProperties = params;
38: }
39: }
40:
41: public boolean handleMessage(LogicalMessageContext context) {
42: verify(context);
43: return true;
44: }
45:
46: public boolean handleFault(LogicalMessageContext context) {
47: verify(context);
48: return true;
49: }
50:
51: public void close(MessageContext context) {
52: }
53:
54: public void destroy() {
55: }
56:
57: private void verify(LogicalMessageContext context) {
58: boolean isOutbound = ContextUtils.isOutbound(context);
59: String mapProperty = (String) mapProperties
60: .get(isOutbound ? MAPTest.OUTBOUND_KEY
61: : MAPTest.INBOUND_KEY);
62: AddressingPropertiesImpl maps = (AddressingPropertiesImpl) context
63: .get(mapProperty);
64: if (ContextUtils.isRequestor(context)) {
65: if (isOutbound) {
66: String exposeAs = getExpectedExposeAs(false);
67: if (exposeAs != null) {
68: maps.exposeAs(exposeAs);
69: }
70: } else {
71: String exposeAs = getExpectedExposeAs(true);
72: String expected = exposeAs != null ? exposeAs
73: : Names.WSA_NAMESPACE_NAME;
74: if (maps.getNamespaceURI() != expected) {
75: verificationCache.put("Incoming version mismatch"
76: + " expected: " + expected + " got: "
77: + maps.getNamespaceURI());
78: }
79: exposeAs = null;
80: }
81: }
82: verificationCache.put(MAPTest.verifyMAPs(maps, this ));
83: }
84:
85: private String getExpectedExposeAs(boolean remove) {
86: int size = expectedExposedAs.size();
87: return size == 0 ? null : remove ? expectedExposedAs
88: .remove(size - 1) : expectedExposedAs.get(size - 1);
89: }
90:
91: public void setVerificationCache(VerificationCache cache) {
92: verificationCache = cache;
93: }
94:
95: public void addToExpectedExposedAs(String str) {
96: expectedExposedAs.add(str);
97: }
98: }
|