List of usage examples for javax.xml.soap SOAPElement getPrefix
public String getPrefix();
null
if it is unspecified. From source file:be.agiv.security.handler.WSTrustHandler.java
private void handleOutboundMessage(SOAPMessageContext context) throws SOAPException { if (null == this.secondaryParametersNodeList) { return;/* w ww. j a v a 2 s .c o m*/ } SOAPMessage soapMessage = context.getMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); SOAPBody soapBody = soapMessage.getSOAPBody(); NodeList nodeList = soapBody.getElementsByTagNameNS(WSConstants.WSTRUST_NAMESPACE, "RequestSecurityToken"); if (0 == nodeList.getLength()) { return; } SOAPElement requestSecurityTokenElement = (SOAPElement) nodeList.item(0); String prefix = requestSecurityTokenElement.getPrefix(); SOAPElement secondaryParametersElement = requestSecurityTokenElement.addChildElement("SecondaryParameters", prefix); for (int idx = 0; idx < this.secondaryParametersNodeList.getLength(); idx++) { Node node = this.secondaryParametersNodeList.item(idx); Node importedNode = soapPart.importNode(node, true); secondaryParametersElement.appendChild(importedNode); } }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test//ww w . ja va 2s .c o m public void testAddChildElementFromLocalNameAndPrefix() throws Exception { SOAPElement element = saajUtil.createSOAPElement(null, "test", null); element.addNamespaceDeclaration("p", "urn:test"); SOAPElement child = element.addChildElement("child", "p"); assertEquals("urn:test", child.getNamespaceURI()); assertEquals("p", child.getPrefix()); assertEquals("child", child.getLocalName()); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test/*from ww w. jav a2 s. com*/ public void testAddChildElementWithDeclaredNamespace() throws Exception { SOAPElement element = saajUtil.createSOAPElement(null, "test", null); element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:p", "urn:ns"); SOAPElement child = element.addChildElement("test", "p", "urn:ns"); assertEquals("urn:ns", child.getNamespaceURI()); assertEquals("p", child.getPrefix()); assertEquals("test", child.getLocalName()); assertEquals(0, child.getAttributes().getLength()); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test/*from w ww . ja v a 2 s. c o m*/ public void testAddChildElementWithUndeclaredNamespace() throws Exception { SOAPElement element = saajUtil.createSOAPElement(null, "test", null); SOAPElement child = element.addChildElement("test", "p", "urn:ns"); assertEquals("urn:ns", child.getNamespaceURI()); assertEquals("p", child.getPrefix()); assertEquals("test", child.getLocalName()); Attr nsDecl = child.getAttributeNodeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "p"); assertNotNull(nsDecl); assertEquals("urn:ns", nsDecl.getValue()); }
From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java
private void addAttributes(SOAPMessage responseMessage, SOAPEnvelope soapEnvelope, Context context, NamedNodeMap attributes, SOAPElement soapElement) throws SOAPException { SOAPElement soapMethodResponseElement = (SOAPElement) soapEnvelope.getBody().getFirstChild(); String targetNamespace = soapMethodResponseElement.getNamespaceURI(); String prefix = soapMethodResponseElement.getPrefix(); int len = attributes.getLength(); Attr attribute;//from w w w. ja v a 2s. c o m for (int i = 0; i < len; i++) { attribute = (Attr) attributes.item(i); String attributeName = attribute.getName(); String attributeValue = attribute.getNodeValue(); String attributeNsUri = attribute.getNamespaceURI(); String attributePrefix = getPrefix(context.projectName, attributeNsUri); XmlSchemaAttribute xmlSchemaAttribute = getXmlSchemaAttributeByName(context.projectName, attributeName); boolean isGlobal = xmlSchemaAttribute != null; if (isGlobal) { attributeNsUri = xmlSchemaAttribute.getQName().getNamespaceURI(); attributePrefix = getPrefix(context.projectName, attributeNsUri); } if (XsdForm.qualified == context.project.getSchemaElementForm() || isGlobal) { if (attributePrefix == null) { soapElement.addAttribute(soapEnvelope.createName(attributeName, prefix, targetNamespace), attributeValue); } else { soapElement.addAttribute( soapEnvelope.createName(attributeName, attributePrefix, attributeNsUri), attributeValue); } } else { soapElement.addAttribute(soapEnvelope.createName(attributeName), attributeValue); } } }
From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java
private void addElement(SOAPMessage responseMessage, SOAPEnvelope soapEnvelope, Context context, Element elementToAdd, SOAPElement soapElement) throws SOAPException { SOAPElement soapMethodResponseElement = (SOAPElement) soapEnvelope.getBody().getFirstChild(); String targetNamespace = soapMethodResponseElement.getNamespaceURI(); String prefix = soapMethodResponseElement.getPrefix(); String nodeType = elementToAdd.getAttribute("type"); SOAPElement childSoapElement = soapElement; boolean elementAdded = true; boolean bTable = false; if (nodeType.equals("table")) { bTable = true;// ww w . j a v a 2 s . c o m /*childSoapElement = soapElement.addChildElement("ArrayOf" + context.transactionName + "_" + tableName + "_Row", ""); if (!context.httpServletRequest.getServletPath().endsWith(".wsl")) { childSoapElement.addAttribute(soapEnvelope.createName("xsi:type"), "soapenc:Array"); }*/ childSoapElement = soapElement.addChildElement(elementToAdd.getNodeName()); } else if (nodeType.equals("row")) { /*String elementType = context.transactionName + "_" + tableName + "_Row"; childSoapElement = soapElement.addChildElement(elementType, "");*/ childSoapElement = soapElement.addChildElement(elementToAdd.getNodeName()); } else if (nodeType.equals("attachment")) { childSoapElement = soapElement.addChildElement(elementToAdd.getNodeName()); if (context.requestedObject instanceof AbstractHttpTransaction) { AttachmentDetails attachment = AttachmentManager.getAttachment(elementToAdd); if (attachment != null) { byte[] raw = attachment.getData(); if (raw != null) childSoapElement.addTextNode(Base64.encodeBase64String(raw)); } /* DON'T WORK YET *\ AttachmentPart ap = responseMessage.createAttachmentPart(new ByteArrayInputStream(raw), elementToAdd.getAttribute("content-type")); ap.setContentId(key); ap.setContentLocation(elementToAdd.getAttribute("url")); responseMessage.addAttachmentPart(ap); \* DON'T WORK YET */ } } else { String elementNodeName = elementToAdd.getNodeName(); String elementNodeNsUri = elementToAdd.getNamespaceURI(); String elementNodePrefix = getPrefix(context.projectName, elementNodeNsUri); XmlSchemaElement xmlSchemaElement = getXmlSchemaElementByName(context.projectName, elementNodeName); boolean isGlobal = xmlSchemaElement != null; if (isGlobal) { elementNodeNsUri = xmlSchemaElement.getQName().getNamespaceURI(); elementNodePrefix = getPrefix(context.projectName, elementNodeNsUri); } // ignore original SOAP message response elements // if ((elementNodeName.toUpperCase().indexOf("SOAP-ENV:") != -1) || ((elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("SOAP-ENV:") != -1)) || // (elementNodeName.toUpperCase().indexOf("SOAPENV:") != -1) || ((elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("SOAPENV:") != -1)) || // (elementNodeName.toUpperCase().indexOf("NS0:") != -1) || ((elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("NS0:") != -1))) { // elementAdded = false; // } if ("http://schemas.xmlsoap.org/soap/envelope/".equals(elementToAdd.getNamespaceURI()) || "http://schemas.xmlsoap.org/soap/envelope/" .equals(elementToAdd.getParentNode().getNamespaceURI()) || elementToAdd.getParentNode().getNodeName().toUpperCase().indexOf("NS0:") != -1 || elementNodeName.toUpperCase().indexOf("NS0:") != -1) { elementAdded = false; } else { if (XsdForm.qualified == context.project.getSchemaElementForm() || isGlobal) { if (elementNodePrefix == null) { childSoapElement = soapElement .addChildElement(soapEnvelope.createName(elementNodeName, prefix, targetNamespace)); } else { childSoapElement = soapElement.addChildElement( soapEnvelope.createName(elementNodeName, elementNodePrefix, elementNodeNsUri)); } } else { childSoapElement = soapElement.addChildElement(elementNodeName); } } } if (elementAdded && elementToAdd.hasAttributes()) { addAttributes(responseMessage, soapEnvelope, context, elementToAdd.getAttributes(), childSoapElement); } if (elementToAdd.hasChildNodes()) { NodeList childNodes = elementToAdd.getChildNodes(); int len = childNodes.getLength(); if (bTable) { /*if (!context.httpServletRequest.getServletPath().endsWith(".wsl")) { childSoapElement.addAttribute(soapEnvelope.createName("soapenc:arrayType"), context.projectName+"_ns:" + context.transactionName + "_" + tableName + "_Row[" + (len - 1) + "]"); }*/ } org.w3c.dom.Node node; Element childElement; for (int i = 0; i < len; i++) { node = childNodes.item(i); switch (node.getNodeType()) { case org.w3c.dom.Node.ELEMENT_NODE: childElement = (Element) node; addElement(responseMessage, soapEnvelope, context, childElement, childSoapElement); break; case org.w3c.dom.Node.CDATA_SECTION_NODE: case org.w3c.dom.Node.TEXT_NODE: String text = node.getNodeValue(); text = (text == null) ? "" : text; childSoapElement.addTextNode(text); break; default: break; } } /*org.w3c.dom.Node node; Element childElement; for (int i = 0 ; i < len ; i++) { node = childNodes.item(i); if (node instanceof Element) { childElement = (Element) node; addElement(responseMessage, soapEnvelope, context, childElement, childSoapElement); } else if (node instanceof CDATASection) { Node textNode = XMLUtils.findChildNode(elementToAdd, org.w3c.dom.Node.CDATA_SECTION_NODE); String text = textNode.getNodeValue(); if (text == null) { text = ""; } childSoapElement.addTextNode(text); } else { Node textNode = XMLUtils.findChildNode(elementToAdd, org.w3c.dom.Node.TEXT_NODE); if (textNode != null) { String text = textNode.getNodeValue(); if (text == null) { text = ""; } childSoapElement.addTextNode(text); } } }*/ } }
From source file:org.apache.axis2.jaxws.message.util.impl.SAAJConverterImpl.java
/** * update the tag data of the SOAPElement * * @param NameCreator nc//w w w . j a v a2 s. c o m * @param element SOAPElement * @param reader XMLStreamReader whose cursor is at START_ELEMENT */ protected void updateTagData(NameCreator nc, SOAPElement element, XMLStreamReader reader, boolean newElement) throws SOAPException { String prefix = reader.getPrefix(); prefix = (prefix == null) ? "" : prefix; // Make sure the prefix is correct if (prefix.length() > 0 && !element.getPrefix().equals(prefix)) { // Due to a bug in Axiom DOM or in the reader...not sure where yet, // there may be a non-null prefix and no namespace String ns = reader.getNamespaceURI(); if (ns != null && ns.length() != 0) { element.setPrefix(prefix); } } if (!newElement) { // Add the namespace declarations from the reader for the missing namespaces int size = reader.getNamespaceCount(); for (int i = 0; i < size; i++) { String pre = reader.getNamespacePrefix(i); String ns = reader.getNamespaceURI(i); if ((pre != null && pre.length() > 0) && (ns == null || ns.length() == 0)) { if (log.isDebugEnabled()) { log.debug("The prefix is (" + pre + ") but there is no namespace. " + "This erroneous declaration is skipped."); } } else { String existingNS = element.getNamespaceURI(pre); if (!ns.equals(existingNS)) { element.removeNamespaceDeclaration(pre); // Is it necessary to remove the existing prefix/ns element.addNamespaceDeclaration(pre, ns); } } } } else { // Add the namespace declarations from the reader int size = reader.getNamespaceCount(); for (int i = 0; i < size; i++) { String newPrefix = reader.getNamespacePrefix(i); String newNS = reader.getNamespaceURI(i); if ((newPrefix != null && newPrefix.length() > 0) && (newNS == null || newNS.length() == 0)) { // Due to a bug in Axiom DOM or the reader, I have // seen cases where the prefix is non-null but there is not // namespace. Example: prefix is axis2ns3 and namespace is null. // This is an error..log, tolerate and continue if (log.isDebugEnabled()) { log.debug("The prefix is (" + newPrefix + ") but there is no namespace. " + "This erroneous declaration is skipped."); } } else { element.addNamespaceDeclaration(newPrefix, newNS); } } } addAttributes(nc, element, reader); return; }
From source file:org.apache.axis2.saaj.SOAPFactoryTest.java
@Validated @Test//w w w . ja v a 2 s. c o m public void testCreateElement2() { try { SOAPFactory sf = SOAPFactory.newInstance(); //SOAPFactory sf = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); if (sf == null) { fail("could not create SOAPFactory object"); } log.info("Create a DOMElement"); DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dbfactory.newDocumentBuilder(); Document document = builder.newDocument(); Element de = document.createElementNS("http://MyNamespace.org/", "MyTag"); //Calling SOAPFactory.createElement(org.w3c.dom.Element) SOAPElement se = sf.createElement(de); if (!de.getNodeName().equals(se.getNodeName()) || !de.getNamespaceURI().equals(se.getNamespaceURI())) { //Node names are not equal fail("Got: <URI=" + se.getNamespaceURI() + ", PREFIX=" + se.getPrefix() + ", NAME=" + se.getNodeName() + ">" + "Expected: <URI=" + de.getNamespaceURI() + ", PREFIX=" + de.getPrefix() + ", NAME=" + de.getNodeName() + ">"); } } catch (Exception e) { fail("Exception: " + e); } }
From source file:org.apache.axis2.saaj.SOAPFactoryTest.java
@Validated @Test/* ww w .j a v a 2 s .c o m*/ public void testCreateElement4() { try { SOAPFactory sf = SOAPFactory.newInstance(); if (sf == null) { fail("createElementTest6() could not create SOAPFactory object"); } QName qname = new QName("http://MyNamespace.org/", "MyTag"); SOAPElement se1 = sf.createElement(qname); //Create second SOAPElement from first SOAPElement SOAPElement se2 = sf.createElement(se1); //commented to support jdk 1.4 build // if(!se1.isEqualNode(se2) && !se1.isSameNode(se2)) { // fail("The SOAPElement's are not equal and not the same (unexpected)"); // } if (!se1.getNodeName().equals(se2.getNodeName()) || !se1.getNamespaceURI().equals(se2.getNamespaceURI())) { fail("Got: <URI=" + se1.getNamespaceURI() + ", PREFIX=" + se1.getPrefix() + ", NAME=" + se1.getNodeName() + ">" + "Expected: <URI=" + se2.getNamespaceURI() + ", PREFIX=" + se2.getPrefix() + ", NAME=" + se2.getNodeName() + ">"); } } catch (Exception e) { fail(); } }
From source file:org.jbpm.bpel.integration.soap.SoapUtil.java
public static void ensureOwnNamespaceDeclared(SOAPElement elem) throws SOAPException { ensureNamespaceDeclared(elem, elem.getNamespaceURI(), elem.getPrefix()); }