001: package org.objectweb.celtix.bus.bindings.soap;
002:
003: import java.util.Map;
004:
005: import javax.jws.WebParam;
006: import javax.jws.soap.SOAPBinding;
007: import javax.xml.namespace.QName;
008: import javax.xml.soap.SOAPException;
009: import javax.xml.soap.SOAPMessage;
010: import javax.xml.ws.WebServiceException;
011: import javax.xml.ws.handler.MessageContext;
012: import javax.xml.ws.handler.soap.SOAPMessageContext;
013:
014: import org.w3c.dom.Node;
015: import org.w3c.dom.NodeList;
016:
017: import org.objectweb.celtix.Bus;
018: import org.objectweb.celtix.bindings.AbstractBindingImpl;
019: import org.objectweb.celtix.bindings.AbstractServerBinding;
020: import org.objectweb.celtix.bindings.DataBindingCallback;
021: import org.objectweb.celtix.bindings.ServerBindingEndpointCallback;
022: import org.objectweb.celtix.helpers.NodeUtils;
023: import org.objectweb.celtix.helpers.WSDLHelper;
024: import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
025:
026: public class SOAPServerBinding extends AbstractServerBinding {
027:
028: protected final SOAPBindingImpl soapBinding;
029: protected final WSDLHelper helper;
030:
031: public SOAPServerBinding(Bus b, EndpointReferenceType ref,
032: ServerBindingEndpointCallback cbFactory) {
033: super (b, ref, cbFactory);
034: soapBinding = new SOAPBindingImpl(true);
035: helper = new WSDLHelper();
036: }
037:
038: public AbstractBindingImpl getBindingImpl() {
039: return soapBinding;
040: }
041:
042: public QName getOperationName(MessageContext ctx) {
043: SOAPMessageContext soapContext = SOAPMessageContext.class
044: .cast(ctx);
045: SOAPMessage msg = soapContext.getMessage();
046: Map<QName, ? extends DataBindingCallback> ops = sbeCallback
047: .getOperations();
048:
049: //attempt the simple case first....
050: Node node = null;
051: try {
052: node = NodeUtils.getChildElementNode(msg.getSOAPBody());
053: } catch (SOAPException e) {
054: return null;
055: }
056: QName firstNodeName = null;
057: if (node != null) {
058: firstNodeName = new QName(node.getNamespaceURI(), node
059: .getLocalName());
060: if (ops.containsKey(firstNodeName)) {
061: DataBindingCallback cb = ops.get(firstNodeName);
062: if (cb.getSOAPStyle() == SOAPBinding.Style.RPC) {
063: return firstNodeName;
064: }
065: }
066: }
067:
068: for (Map.Entry<QName, ? extends DataBindingCallback> entry : ops
069: .entrySet()) {
070: DataBindingCallback cb = entry.getValue();
071: if (cb.getSOAPStyle() == SOAPBinding.Style.RPC) {
072: //RPC ones should already have been found
073: continue;
074: }
075: if (cb.getSOAPParameterStyle() == SOAPBinding.ParameterStyle.BARE) {
076: //unwrapped
077: try {
078: NodeList nl = msg.getSOAPBody().getChildNodes();
079: NodeList hl = null;
080: if (msg.getSOAPHeader() != null) {
081: hl = msg.getSOAPHeader().getChildNodes();
082: }
083: if (matchParamsForDocLitBare(cb, nl, hl)) {
084: return entry.getKey();
085: }
086: } catch (SOAPException e) {
087: //ignore?
088: }
089: } else {
090: //wrapped
091: if (firstNodeName != null
092: && firstNodeName.equals(cb
093: .getRequestWrapperQName())) {
094: return entry.getKey();
095: }
096: }
097: }
098: if (firstNodeName != null && ops.containsKey(firstNodeName)) {
099: return firstNodeName;
100: }
101: //try to see if we CAN get a callback
102: if (sbeCallback.getDataBindingCallback(firstNodeName, null,
103: sbeCallback.getServiceMode()) != null) {
104: return firstNodeName;
105: }
106:
107: throw new WebServiceException("No operation matching "
108: + firstNodeName + " was found");
109: }
110:
111: public boolean matchParamsForDocLitBare(DataBindingCallback cb,
112: NodeList bodyList, NodeList headerList) {
113: if (cb.getParamsLength() == 0
114: && (bodyList == null || bodyList.getLength() == 0)
115: && (headerList == null || headerList.getLength() == 0)) {
116: return true;
117: }
118: int nodeIdx = 0;
119: boolean matchFound = false;
120: NodeList matchingList = bodyList;
121: for (int x = 0; x < cb.getParamsLength(); x++) {
122: WebParam param = cb.getWebParam(x);
123: if (null != param && param.header()) {
124: if (headerList != null) {
125: matchingList = headerList;
126: } else {
127: return matchFound;
128: }
129: }
130:
131: if (null == param || param.mode() == WebParam.Mode.OUT
132: || nodeIdx >= matchingList.getLength()) {
133: break;
134: }
135:
136: Node n = matchingList.item(nodeIdx);
137: while (n.getNodeType() != Node.ELEMENT_NODE) {
138: n = matchingList.item(++nodeIdx);
139: }
140:
141: if (n.getLocalName().equals(param.name())
142: && n.getNamespaceURI().equals(
143: param.targetNamespace())) {
144: matchFound = true;
145: ++nodeIdx;
146: } else {
147: matchFound = false;
148: break;
149: }
150: }
151:
152: return matchFound;
153: }
154:
155: public boolean isBindingCompatible(String address) {
156: return address.contains("http:");
157: }
158:
159: }
|