private Element parseMetadata( @NotNull String systemId, @NotNull ServiceDescriptor serviceDescriptor) { List<? extends Source> mexWsdls = serviceDescriptor.getWSDLs(); List<? extends Source> mexSchemas = serviceDescriptor.getSchemas(); Document root = null; for (Source src : mexWsdls) { if (src instanceof DOMSource) { Node n = ((DOMSource) src).getNode(); Document doc; if (n.getNodeType() == Node.ELEMENT_NODE && n.getOwnerDocument() == null) { doc = DOMUtil.createDom(); doc.importNode(n, true); } else { doc = n.getOwnerDocument(); } // Element e = (n.getNodeType() == Node.ELEMENT_NODE)?(Element)n: // DOMUtil.getFirstElementChild(n); if (root == null) { // check if its main wsdl, then set it to root NodeList nl = doc.getDocumentElement().getElementsByTagNameNS(WSDLConstants.NS_WSDL, "service"); if (nl.getLength() > 0) { root = doc; rootWSDL = src.getSystemId(); } } NodeList nl = doc.getDocumentElement().getElementsByTagNameNS(WSDLConstants.NS_WSDL, "import"); for (int i = 0; i < nl.getLength(); i++) { Element imp = (Element) nl.item(i); String loc = imp.getAttribute("location"); if (loc != null) { if (!externalReferences.contains(loc)) externalReferences.add(loc); } } if (core.keySet().contains(systemId)) core.remove(systemId); core.put(src.getSystemId(), doc); resolvedCache.put(systemId, doc.getDocumentURI()); isMexMetadata = true; } // TODO:handle SAXSource // TODO:handler StreamSource } for (Source src : mexSchemas) { if (src instanceof DOMSource) { Node n = ((DOMSource) src).getNode(); Element e = (n.getNodeType() == Node.ELEMENT_NODE) ? (Element) n : DOMUtil.getFirstElementChild(n); inlinedSchemaElements.add(e); } // TODO:handle SAXSource // TODO:handler StreamSource } return root.getDocumentElement(); }
SOAP12Fault(CodeType code, ReasonType reason, String node, String role, Element detailObject) { this.code = code; this.reason = reason; this.node = node; this.role = role; if (detailObject != null) { if (detailObject.getNamespaceURI().equals(ns) && detailObject.getLocalName().equals("Detail")) { detail = new DetailType(); for (Element detailEntry : DOMUtil.getChildElements(detailObject)) { detail.getDetails().add(detailEntry); } } else { detail = new DetailType(detailObject); } } }
/** * Determines the target node of the "bindings" element by using the inherited target node, then * put the result into the "result" map. */ private void buildTargetNodeMap( Element bindings, Node inheritedTarget, Map<Element, Node> result) { // start by the inherited target Node target = inheritedTarget; validate(bindings); // validate this node // look for @wsdlLocation if (isTopLevelBinding(bindings)) { String wsdlLocation; if (bindings.getAttributeNode("wsdlLocation") != null) { wsdlLocation = bindings.getAttribute("wsdlLocation"); try { // absolutize this URI. // TODO: use the URI class // TODO: honor xml:base wsdlLocation = new URL(new URL(forest.getSystemId(bindings.getOwnerDocument())), wsdlLocation) .toExternalForm(); } catch (MalformedURLException e) { wsdlLocation = JAXWSUtils.absolutize(JAXWSUtils.getFileOrURLName(wsdlLocation)); } } else { // the node does not have wsdlLocation = forest.getFirstRootDocument(); } target = forest.get(wsdlLocation); if (target == null) { reportError( bindings, WsdlMessages.INTERNALIZER_INCORRECT_SCHEMA_REFERENCE( wsdlLocation, EditDistance.findNearest(wsdlLocation, forest.listSystemIDs()))); return; // abort processing this <JAXWS:bindings> } } // if the target node is xs:schema, declare the jaxb version on it as latter on it will be // required by the inlined schema bindings Element element = DOMUtil.getFirstElementChild(target); if (element != null && element.getNamespaceURI().equals(Constants.NS_WSDL) && element.getLocalName().equals("definitions")) { // get all schema elements Element type = DOMUtils.getFirstChildElement(element, Constants.NS_WSDL, "types"); if (type != null) { for (Element schemaElement : DOMUtils.getChildElements(type, Constants.NS_XSD, "schema")) { if (!schemaElement.hasAttributeNS(Constants.NS_XMLNS, "jaxb")) { schemaElement.setAttributeNS( Constants.NS_XMLNS, "xmlns:jaxb", JAXWSBindingsConstants.NS_JAXB_BINDINGS); } // add jaxb:bindings version info. Lets put it to 1.0, may need to change latter if (!schemaElement.hasAttributeNS(JAXWSBindingsConstants.NS_JAXB_BINDINGS, "version")) { schemaElement.setAttributeNS( JAXWSBindingsConstants.NS_JAXB_BINDINGS, "jaxb:version", JAXWSBindingsConstants.JAXB_BINDING_VERSION); } } } } boolean hasNode = true; if ((isJAXWSBindings(bindings) || isJAXBBindings(bindings)) && bindings.getAttributeNode("node") != null) { target = evaluateXPathNode( bindings, target, bindings.getAttribute("node"), new NamespaceContextImpl(bindings)); } else if (isJAXWSBindings(bindings) && (bindings.getAttributeNode("node") == null) && !isTopLevelBinding(bindings)) { hasNode = false; } else if (isGlobalBinding(bindings) && !isWSDLDefinition(target) && isTopLevelBinding(bindings.getParentNode())) { target = getWSDLDefintionNode(bindings, target); } // if target is null it means the xpath evaluation has some problem, // just return if (target == null) return; // update the result map if (hasNode) result.put(bindings, target); // look for child <JAXWS:bindings> and process them recursively Element[] children = getChildElements(bindings); for (Element child : children) buildTargetNodeMap(child, target, result); }
private static void writeW3CMetaData( StreamWriterBufferCreator writer, QName service, QName port, QName portType, List<Element> metadata, String wsdlAddress) throws XMLStreamException { writer.writeStartElement( AddressingVersion.W3C.getPrefix(), W3CAddressingConstants.WSA_METADATA_NAME, AddressingVersion.W3C.nsUri); writer.writeNamespace(AddressingVersion.W3C.getWsdlPrefix(), AddressingVersion.W3C.wsdlNsUri); // Write Interface info if (portType != null) { writer.writeStartElement( AddressingVersion.W3C.getWsdlPrefix(), W3CAddressingConstants.WSAW_INTERFACENAME_NAME, AddressingVersion.W3C.wsdlNsUri); String portTypePrefix = portType.getPrefix(); if (portTypePrefix == null || portTypePrefix.equals("")) { // TODO check prefix again portTypePrefix = "wsns"; } writer.writeNamespace(portTypePrefix, portType.getNamespaceURI()); writer.writeCharacters(portTypePrefix + ":" + portType.getLocalPart()); writer.writeEndElement(); } if (service != null) { // Write service and Port info if (!(service.getNamespaceURI().equals("") || service.getLocalPart().equals(""))) { writer.writeStartElement( AddressingVersion.W3C.getWsdlPrefix(), W3CAddressingConstants.WSAW_SERVICENAME_NAME, AddressingVersion.W3C.wsdlNsUri); String servicePrefix = service.getPrefix(); if (servicePrefix == null || servicePrefix.equals("")) { // TODO check prefix again servicePrefix = "wsns"; } writer.writeNamespace(servicePrefix, service.getNamespaceURI()); if (port != null) { writer.writeAttribute(W3CAddressingConstants.WSAW_ENDPOINTNAME_NAME, port.getLocalPart()); } writer.writeCharacters(servicePrefix + ":" + service.getLocalPart()); writer.writeEndElement(); } } // Inline the wsdl if (wsdlAddress != null) { writeWsdl(writer, service, wsdlAddress); } // Add the extra metadata Elements if (metadata != null) for (Element e : metadata) { DOMUtil.serializeNode(e, writer); } writer.writeEndElement(); }
private static XMLStreamBuffer createBufferFromData( AddressingVersion version, String address, List<Element> referenceParameters, QName service, QName port, QName portType, List<Element> metadata, String wsdlAddress) { StreamWriterBufferCreator writer = new StreamWriterBufferCreator(); try { writer.writeStartDocument(); writer.writeStartElement(version.getPrefix(), "EndpointReference", version.nsUri); writer.writeNamespace(version.getPrefix(), version.nsUri); writer.writeStartElement(version.getPrefix(), "Address", version.nsUri); writer.writeCharacters(address); writer.writeEndElement(); if (referenceParameters != null) { writer.writeStartElement(version.getPrefix(), "ReferenceParameters", version.nsUri); for (Element e : referenceParameters) DOMUtil.serializeNode(e, writer); writer.writeEndElement(); } switch (version) { case W3C: writeW3CMetaData(writer, service, port, portType, metadata, wsdlAddress); break; case MEMBER: writeMSMetaData(writer, service, port, portType, metadata); if (wsdlAddress != null) { // Inline the wsdl as extensibility element // Write mex:Metadata wrapper writer.writeStartElement( MemberSubmissionAddressingConstants.MEX_METADATA.getPrefix(), MemberSubmissionAddressingConstants.MEX_METADATA.getLocalPart(), MemberSubmissionAddressingConstants.MEX_METADATA.getNamespaceURI()); writer.writeStartElement( MemberSubmissionAddressingConstants.MEX_METADATA_SECTION.getPrefix(), MemberSubmissionAddressingConstants.MEX_METADATA_SECTION.getLocalPart(), MemberSubmissionAddressingConstants.MEX_METADATA_SECTION.getNamespaceURI()); writer.writeAttribute( MemberSubmissionAddressingConstants.MEX_METADATA_DIALECT_ATTRIBUTE, MemberSubmissionAddressingConstants.MEX_METADATA_DIALECT_VALUE); writeWsdl(writer, service, wsdlAddress); writer.writeEndElement(); writer.writeEndElement(); } break; } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); return writer.getXMLStreamBuffer(); } catch (XMLStreamException e) { throw new WebServiceException(e); } }