KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > celtix > bus > bindings > soap > SOAPServerBinding


1 package org.objectweb.celtix.bus.bindings.soap;
2
3 import java.util.Map JavaDoc;
4
5 import javax.jws.WebParam;
6 import javax.jws.soap.SOAPBinding;
7 import javax.xml.namespace.QName JavaDoc;
8 import javax.xml.soap.SOAPException JavaDoc;
9 import javax.xml.soap.SOAPMessage JavaDoc;
10 import javax.xml.ws.WebServiceException;
11 import javax.xml.ws.handler.MessageContext;
12 import javax.xml.ws.handler.soap.SOAPMessageContext;
13
14 import org.w3c.dom.Node JavaDoc;
15 import org.w3c.dom.NodeList JavaDoc;
16
17 import org.objectweb.celtix.Bus;
18 import org.objectweb.celtix.bindings.AbstractBindingImpl;
19 import org.objectweb.celtix.bindings.AbstractServerBinding;
20 import org.objectweb.celtix.bindings.DataBindingCallback;
21 import org.objectweb.celtix.bindings.ServerBindingEndpointCallback;
22 import org.objectweb.celtix.helpers.NodeUtils;
23 import org.objectweb.celtix.helpers.WSDLHelper;
24 import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
25
26 public class SOAPServerBinding extends AbstractServerBinding {
27     
28     protected final SOAPBindingImpl soapBinding;
29     protected final WSDLHelper helper;
30     
31     public SOAPServerBinding(Bus b,
32                              EndpointReferenceType ref,
33                              ServerBindingEndpointCallback cbFactory) {
34         super(b, ref, cbFactory);
35         soapBinding = new SOAPBindingImpl(true);
36         helper = new WSDLHelper();
37     }
38     
39     public AbstractBindingImpl getBindingImpl() {
40         return soapBinding;
41     }
42     public QName JavaDoc getOperationName(MessageContext ctx) {
43         SOAPMessageContext soapContext = SOAPMessageContext.class.cast(ctx);
44         SOAPMessage JavaDoc msg = soapContext.getMessage();
45         Map JavaDoc<QName JavaDoc, ? extends DataBindingCallback> ops = sbeCallback.getOperations();
46
47
48         
49         //attempt the simple case first....
50
Node JavaDoc node = null;
51         try {
52             node = NodeUtils.getChildElementNode(msg.getSOAPBody());
53         } catch (SOAPException JavaDoc e) {
54             return null;
55         }
56         QName JavaDoc firstNodeName = null;
57         if (node != null) {
58             firstNodeName = new QName JavaDoc(node.getNamespaceURI(), node.getLocalName());
59             if (ops.containsKey(firstNodeName)) {
60                 DataBindingCallback cb = ops.get(firstNodeName);
61                 if (cb.getSOAPStyle() == SOAPBinding.Style.RPC) {
62                     return firstNodeName;
63                 }
64             }
65         }
66
67         for (Map.Entry JavaDoc<QName JavaDoc, ? extends DataBindingCallback> entry : ops.entrySet()) {
68             DataBindingCallback cb = entry.getValue();
69             if (cb.getSOAPStyle() == SOAPBinding.Style.RPC) {
70                 //RPC ones should already have been found
71
continue;
72             }
73             if (cb.getSOAPParameterStyle() == SOAPBinding.ParameterStyle.BARE) {
74                 //unwrapped
75
try {
76                     NodeList JavaDoc nl = msg.getSOAPBody().getChildNodes();
77                     NodeList JavaDoc hl = null;
78                     if (msg.getSOAPHeader() != null) {
79                         hl = msg.getSOAPHeader().getChildNodes();
80                     }
81                     if (matchParamsForDocLitBare(cb, nl, hl)) {
82                         return entry.getKey();
83                     }
84                 } catch (SOAPException JavaDoc e) {
85                     //ignore?
86
}
87             } else {
88                 //wrapped
89
if (firstNodeName != null
90                     && firstNodeName.equals(cb.getRequestWrapperQName())) {
91                     return entry.getKey();
92                 }
93             }
94         }
95         if (firstNodeName != null
96             && ops.containsKey(firstNodeName)) {
97             return firstNodeName;
98         }
99         //try to see if we CAN get a callback
100
if (sbeCallback.getDataBindingCallback(firstNodeName, null,
101                                                sbeCallback.getServiceMode()) != null) {
102             return firstNodeName;
103         }
104         
105         throw new WebServiceException("No operation matching " + firstNodeName + " was found");
106     }
107     
108     public boolean matchParamsForDocLitBare(DataBindingCallback cb,
109                                             NodeList JavaDoc bodyList,
110                                             NodeList JavaDoc headerList) {
111         if (cb.getParamsLength() == 0
112             && (bodyList == null || bodyList.getLength() == 0)
113             && (headerList == null || headerList.getLength() == 0)) {
114             return true;
115         }
116         int nodeIdx = 0;
117         boolean matchFound = false;
118         NodeList JavaDoc matchingList = bodyList;
119         for (int x = 0; x < cb.getParamsLength(); x++) {
120             WebParam param = cb.getWebParam(x);
121             if (null != param && param.header()) {
122                 if (headerList != null) {
123                     matchingList = headerList;
124                 } else {
125                     return matchFound;
126                 }
127             }
128             
129             if (null == param
130                 || param.mode() == WebParam.Mode.OUT
131                 || nodeIdx >= matchingList.getLength()) {
132                 break;
133             }
134             
135             Node JavaDoc n = matchingList.item(nodeIdx);
136             while (n.getNodeType() != Node.ELEMENT_NODE) {
137                 n = matchingList.item(++nodeIdx);
138             }
139             
140             if (n.getLocalName().equals(param.name())
141                 && n.getNamespaceURI().equals(param.targetNamespace())) {
142                 matchFound = true;
143                 ++nodeIdx;
144             } else {
145                 matchFound = false;
146                 break;
147             }
148         }
149
150         return matchFound;
151     }
152
153     public boolean isBindingCompatible(String JavaDoc address) {
154         return address.contains("http:");
155     }
156
157
158 }
159
Popular Tags