soapformatter.java
来自「ejb3 java session bean」· Java 代码 · 共 708 行 · 第 1/2 页
JAVA
708 行
*/ if (!SoapBindConstants.LITERAL_USE.equals(soapBindBody.getUse())) { throw new SOAPException("binding must use value 'literal' for attribute " + "'use' in all soapbind:body elements: " + binding); } /* * BP 1.2 R2717: An rpc-literal binding MUST have the namespace attribute specified, the value * of which MUST be an absolute URI, on contained soapbind:body elements */ String operationNamespaceUri = soapBindBody.getNamespaceURI(); if (operationNamespaceUri == null) { throw new SOAPException("rpc binding must have the namespace attribute " + "specified on contained soapbind:body elements: " + binding); } // get operation wrapper Operation operation = bindOperation.getOperation(); SOAPElement operationWrapper = SoapUtil.getElement(body, operationNamespaceUri, direction.getRpcWrapperLocalName(operation)); /* * WSDL 1.1 section 2.4.6: Note that [the parameterOrder attribute] serves as a "hint" and may * safely be ignored by those not concerned with RPC signatures. * * BPEL is not concerned with RPC signatures, so ignore parameterOrder */ List partNames = soapBindBody.getParts(); List wsdlParts = getWsdlParts(partNames, direction.getMessageDefinition(operation)); // fill in parts for (int i = 0, n = wsdlParts.size(); i < n; i++) { Part wsdlPart = (Part) wsdlParts.get(i); /* * BP 1.2 R2203: An rpc-literal binding MUST refer, in its soapbind:body element(s), only to * wsdl:part element(s) that have been defined using the type attribute */ if (wsdlPart.getTypeName() == null) { throw new SOAPException("rpc binding must refer, in its soapbind:body " + "elements, only to wsdl:part elements defined using attribute 'type': " + binding); } // create part String partName = wsdlPart.getName(); Element part = XmlUtil.createElement(partName); parts.put(partName, part); SOAPElement accessor = SoapUtil.getElement(operationWrapper, partName); /* * BPEL-243 - XML Schema Part 1 Second Edition, section 2.6.2: An element may be valid * without content if it has the attribute xsi:nil with the value true */ Boolean nil = DatatypeUtil.parseBoolean(accessor.getAttributeNS( BpelConstants.NS_XML_SCHEMA_INSTANCE, BpelConstants.ATTR_NIL)); if (nil != Boolean.TRUE) { // copy accessor inside operation wrapper to part SoapUtil.copy(part, accessor); } else { /* * XML Schema Part 1 Second Edition, section 2.6.2: An element so labeled must be empty, but * can carry attributes if permitted by the corresponding complex type */ SoapUtil.copyAttributes(part, accessor); // copies xsi:nil as well // do not copy child nodes } } } protected void readDocumentBody(BindingOperation bindOperation, javax.xml.soap.SOAPBody body, Map parts, MessageDirection direction) throws SOAPException { // obtain soapbind:body element SOAPBody soapBindBody = direction.getBodyDescription(bindOperation); /* * BP 1.2 R2706: A wsdl:binding MUST use the value of "literal" for the use attribute in all * soapbind:body elements */ if (!SoapBindConstants.LITERAL_USE.equals(soapBindBody.getUse())) { throw new SOAPException("binding must use value 'literal' for attribute " + "'use' in all soapbind:body elements: " + binding); } /* * BP 1.2 R2716: A document-literal binding MUST NOT have the namespace attribute specified on * contained soapbind:body elements */ if (soapBindBody.getNamespaceURI() != null) { throw new SOAPException("document binding must not have attribute " + "'namespace' specified on contained soapbind:body elements: " + binding); } /* * WSDL 1.1 section 2.4.6: Note that [the parameterOrder attribute] serves as a "hint" and may * safely be ignored by those not concerned with RPC signatures. * * BPEL is not concerned with RPC signatures, so ignore parameterOrder */ List partNames = soapBindBody.getParts(); Message message = direction.getMessageDefinition(bindOperation.getOperation()); if (partNames == null) { /* * BP 1.2 R2210: If a document-literal binding does not specify the parts attribute on a * soapbind:body element, the corresponding abstract wsdl:message MUST define zero or one * wsdl:parts */ if (message.getParts().size() > 1) { throw new SOAPException("if a document binding does not specify " + "attribute 'parts' on a soapbind:body element, the corresponding " + "wsdl:message must define zero or one wsdl:parts: " + binding); } } else if (partNames.size() > 1) { /* * BP 1.2 R2201: A document-literal binding MUST, in each of its soapbind:body element(s), * have at most one part listed in the parts attribute, if the parts attribute is specified */ throw new SOAPException("document binding must, in its soapbind:body " + "elements, have at most one part listed in attribute 'parts': " + binding); } List wsdlParts = getWsdlParts(partNames, message); /* * BP 1.2 section 4.4.1: For document-literal bindings, the Profile requires that at most one * part, abstractly defined with the element attribute, be serialized into the soap:Body * element. */ assert wsdlParts.size() <= 1 : wsdlParts.size(); if (wsdlParts.size() == 1) { Part wsdlPart = (Part) wsdlParts.get(0); /* * BP 1.2 R2204: A document-literal binding MUST refer, in each of its soapbind:body * element(s), only to wsdl:part element(s) that have been defined using the element * attribute. */ QName elementName = wsdlPart.getElementName(); if (elementName == null) { throw new SOAPException("document binding must refer, in its " + "soapbind:body elements, only to wsdl:part elements defined " + "using attribute 'element': " + binding); } // create part Element part = XmlUtil.createElement(elementName); parts.put(wsdlPart.getName(), part); /* * BP 1.2 R2712: A document-literal binding MUST be serialized as an ENVELOPE with a soap:Body * whose child element is an instance of the global element declaration referenced by the * corresponding wsdl:message part */ SOAPElement element = SoapUtil.getElement(body, elementName); if (element == null) { throw new SOAPException("document binding must be serialized as an " + "envelope with a soap:Body whose child element is an instance " + "of the element declaration referenced by the corresponding " + "wsdl:message part: " + binding); } /* * BPEL-243 - XML Schema Part 1 Second Edition, section 2.6.2: An element may be valid * without content if it has the attribute xsi:nil with the value true */ Boolean nil = DatatypeUtil.parseBoolean(element.getAttributeNS( BpelConstants.NS_XML_SCHEMA_INSTANCE, BpelConstants.ATTR_NIL)); if (nil != Boolean.TRUE) { // copy element inside env:Body to part SoapUtil.copy(part, element); } else { /* * XML Schema Part 1 Second Edition, section 2.6.2: An element so labeled must be empty, but * can carry attributes if permitted by the corresponding complex type */ SoapUtil.copyAttributes(part, element); // copies xsi:nil as well // do not copy child nodes } } } public void writeFault(String operation, SOAPMessage message, String fault, Map parts, QName code, String reason) throws SOAPException { SOAPElement faultElem = faultFormat.addFault(message.getSOAPBody()); faultFormat.setCode(faultElem, code); faultFormat.setReason(faultElem, reason); if (fault == null) return; // no fault detail BindingOperation bindOperation = binding.getBindingOperation(operation, null, null); BindingFault bindFault = bindOperation.getBindingFault(fault); if (bindFault == null) throw new SOAPException("fault '" + fault + "' not found: " + binding); // obtain soapbind:fault element SOAPFault soapBindFault = (SOAPFault) WsdlUtil.getExtension( bindFault.getExtensibilityElements(), SOAPConstants.Q_ELEM_SOAP_FAULT); /* * BP 1.2 R2721: A wsdl:binding MUST have the name attribute specified on all contained * soapbind:fault elements */ if (soapBindFault.getName() == null) { throw new SOAPException("a wsdl:binding must have attribute 'name' " + "specified on all contained soapbind:fault elements: " + binding); } /* * BP 1.2 R2754: the value of the name attribute on a soapbind:fault element MUST match the * value of the name attribute on its parent wsdl:fault element. */ if (!soapBindFault.getName().equals(fault)) { throw new SOAPException("value of attribute 'name' on a " + "soapbind:fault element must match the value of attribute " + "'name' on its parent wsdl:fault element: " + binding); } /* * BP 1.2 R2706: A wsdl:binding MUST use the value of "literal" for the use attribute in all * soapbind:fault elements */ if (!SoapBindConstants.LITERAL_USE.equals(soapBindFault.getUse())) { throw new SOAPException("binding must use value 'literal' for attribute " + "'use' in all soapbind:fault elements: " + binding); } /* * BP 1.2 R2716: A document-literal binding MUST NOT have the namespace attribute specified on * contained soapbind:fault elements */ if (soapBindFault.getNamespaceURI() != null) { throw new SOAPException("document binding must not have attribute " + "'namespace' specified on contained soapbind:fault elements: " + binding); } /* * WSDL 1.1 section 3.6: The fault message MUST have a single part */ Fault wsdlFault = bindOperation.getOperation().getFault(fault); Map wsdlParts = wsdlFault.getMessage().getParts(); if (wsdlParts.size() != 1) throw new SOAPException("fault messages must have a single part: " + binding); /* * BP 1.2 R2205: A wsdl:binding MUST refer, in each of its soapbind:fault elements, only to * wsdl:part element(s) that have been defined using the element attribute */ Part wsdlPart = (Part) wsdlParts.values().iterator().next(); QName elementName = wsdlPart.getElementName(); if (elementName == null) { throw new SOAPException("binding must refer, in each of its " + "soapbind:fault elements, only to wsdl:parts that have been " + "defined using attribute 'element': " + binding); } /* * WSDL 1.1 section 3.6: The soapbind:fault element specifies the contents of the SOAP Fault * detail element */ Element part = (Element) parts.get(wsdlPart.getName()); if (!XmlUtil.nodeNameEquals(part, elementName)) { throw new SOAPException("soapbind:fault element does not match the " + "given contents: " + binding); } faultFormat.addDetail(faultElem, parts); } public Fault readFault(String operation, SOAPMessage message, Map parts) throws SOAPException { SOAPElement faultElem = faultFormat.getFault(message.getSOAPBody()); SOAPElement detail = faultFormat.getDetail(faultElem); if (detail == null) throw new SOAPException("soap fault does not include a detail element"); BindingOperation bindOperation = binding.getBindingOperation(operation, null, null); // look for a wsdl fault which matches detail content for (Iterator i = bindOperation.getOperation().getFaults().values().iterator(); i.hasNext();) { Fault wsdlFault = (Fault) i.next(); // obtain definition of part which appears inside detail Map wsdlParts = wsdlFault.getMessage().getParts(); if (wsdlParts.size() != 1) throw new SOAPException("multiple parts not supported in fault"); /* * BP 1.2 R2205: A wsdl:binding MUST refer, in each of its soapbind:fault elements, only to * wsdl:part element(s) that have been defined using the element attribute */ Part wsdlPart = (Part) wsdlParts.values().iterator().next(); QName elementName = wsdlPart.getElementName(); if (elementName == null) { throw new SOAPException("binding must refer, in each of its " + "soapbind:fault elements, only to wsdl:part elements that have " + "been defined using attribute 'element': " + binding); } // obtain element inside detail SOAPElement element = SoapUtil.getElement(detail, elementName); if (element == null) continue; // this is not the wsdl:fault we are looking for // obtain soapbind:fault element String faultName = wsdlFault.getName(); BindingFault bindFault = bindOperation.getBindingFault(faultName); SOAPFault soapBindFault = (SOAPFault) WsdlUtil.getExtension( bindFault.getExtensibilityElements(), SOAPConstants.Q_ELEM_SOAP_FAULT); /* * BP 1.2 R2721: A wsdl:binding MUST have the name attribute specified on all contained * soapbind:fault elements */ if (soapBindFault.getName() == null) { throw new SOAPException("binding must have attribute 'name' " + "specified on all contained soapbind:fault elements: " + binding); } /* * BP 1.2 R2754: the value of the name attribute on a soapbind:fault element MUST match the * value of the name attribute on its parent wsdl:fault element. */ if (!soapBindFault.getName().equals(faultName)) { throw new SOAPException("value of attribute 'name' on a " + "soapbind:fault element must match the value of attribute " + "'name' on its parent wsdl:fault element: " + binding); } /* * BP 1.2 R2706: A wsdl:binding MUST use the value of "literal" for the use attribute in all * soapbind:fault elements */ if (!SoapBindConstants.LITERAL_USE.equals(soapBindFault.getUse())) { throw new SOAPException("binding must use value 'literal' for " + "attribute 'use' in all soapbind:fault elements: " + binding); } // create part Element part = XmlUtil.createElement(elementName); parts.put(wsdlPart.getName(), part); // copy element inside detail to part SoapUtil.copy(part, element); return wsdlFault; } throw new SOAPException("no wsdl fault matches the detail element content"); } public boolean hasFault(SOAPMessage message) throws SOAPException { return faultFormat.hasFault(message); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?