List of usage examples for javax.xml.soap SOAPElement setAttributeNS
public void setAttributeNS(String namespaceURI, String qualifiedName, String value) throws DOMException;
From source file:edu.unc.lib.dl.services.TripleStoreManagerMulgaraImpl.java
private String sendTQL(String query) { log.info(query);/*from ww w. j ava 2s .c o m*/ String result = null; try { // First create the connection SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance(); SOAPConnection connection = soapConnFactory.createConnection(); // Next, create the actual message MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage message = messageFactory.createMessage(); message.getMimeHeaders().setHeader("SOAPAction", "itqlbean:executeQueryToString"); SOAPBody soapBody = message.getSOAPPart().getEnvelope().getBody(); soapBody.addNamespaceDeclaration("xsd", JDOMNamespaceUtil.XSD_NS.getURI()); soapBody.addNamespaceDeclaration("xsi", JDOMNamespaceUtil.XSI_NS.getURI()); soapBody.addNamespaceDeclaration("itqlbean", this.getItqlEndpointURL()); SOAPElement eqts = soapBody.addChildElement("executeQueryToString", "itqlbean"); SOAPElement queryStr = eqts.addChildElement("queryString", "itqlbean"); queryStr.setAttributeNS(JDOMNamespaceUtil.XSI_NS.getURI(), "xsi:type", "xsd:string"); CDATASection queryCDATA = message.getSOAPPart().createCDATASection(query); queryStr.appendChild(queryCDATA); message.saveChanges(); SOAPMessage reply = connection.call(message, this.getItqlEndpointURL()); if (reply.getSOAPBody().hasFault()) { reportSOAPFault(reply); if (log.isDebugEnabled()) { // log the full soap body response DOMBuilder builder = new DOMBuilder(); org.jdom.Document jdomDoc = builder.build(reply.getSOAPBody().getOwnerDocument()); log.info(new XMLOutputter().outputString(jdomDoc)); } } else { NodeList nl = reply.getSOAPPart().getEnvelope().getBody().getElementsByTagNameNS("*", "executeQueryToStringReturn"); if (nl.getLength() > 0) { result = nl.item(0).getTextContent(); } log.debug(result); } } catch (SOAPException e) { throw new Error("Cannot query triple store at " + this.getItqlEndpointURL(), e); } return result; }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test/*from w ww . ja v a 2s. com*/ public void testRemoveNamespaceDeclaration() throws SOAPException { SOAPElement element = saajUtil.createSOAPElement(null, "test", null); element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:p", "urn:ns"); assertTrue(element.removeNamespaceDeclaration("p")); assertEquals(0, element.getAttributes().getLength()); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test/*from www. ja v a 2 s . c o m*/ public void testRemoveAttributeByQNameNonExisting() throws Exception { SOAPElement element = saajUtil.createSOAPElement(null, "test", null); element.setAttributeNS("urn:ns1", "ns1:attr", "value"); assertFalse(element.removeAttribute(new QName("urn:ns2", "test"))); NamedNodeMap attributes = element.getAttributes(); assertEquals(1, attributes.getLength()); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
/** * Test the behavior of {@link SOAPElement#getAttributeValue(Name)} for an attribute without * namespace.//from w w w . j av a2 s . c om * * @throws Exception */ @Validated @Test public void testGetAttributeValueByNameWithoutNamespace() throws Exception { SOAPEnvelope envelope = saajUtil.createSOAP11Envelope(); SOAPBody body = envelope.addBody(); SOAPElement element = body.addChildElement("test", "p", "urn:test"); element.setAttributeNS(null, "attr", "value"); assertEquals("value", element.getAttributeValue(envelope.createName("attr"))); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
/** * Test the behavior of {@link SOAPElement#getAttributeValue(Name)} for an attribute with * namespace. In particular, check that the prefix is not considered when matching attribute * names.//from w ww . jav a 2 s . co m * * @throws Exception */ @Validated @Test public void testGetAttributeValueByNameWithNamespace() throws Exception { SOAPEnvelope envelope = saajUtil.createSOAP11Envelope(); SOAPBody body = envelope.addBody(); SOAPElement element = body.addChildElement("test", "p", "urn:test"); element.setAttributeNS("urn:test", "p:attr", "value"); assertEquals("value", element.getAttributeValue(envelope.createName("attr", "", "urn:test"))); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test//from ww w. j ava2 s .com public void testRemoveAttributeByQNameWithNamespace() throws Exception { SOAPElement element = saajUtil.createSOAPElement(null, "test", null); element.setAttributeNS("urn:ns1", "ns1:attr", "value"); element.setAttributeNS("urn:ns2", "ns2:attr", "value"); assertTrue(element.removeAttribute(new QName("urn:ns1", "attr"))); NamedNodeMap attributes = element.getAttributes(); assertEquals(1, attributes.getLength()); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
/** * Tests the behavior of {@link SOAPElement#removeAttribute(QName)} for an attribute created * with {@link Element#setAttributeNS(String, String, String)}, but without namespace. * /*from w ww.j av a 2 s . c o m*/ * @throws Exception */ @Validated @Test public void testRemoveAttributeByQNameWithoutNamespace1() throws Exception { SOAPElement element = saajUtil.createSOAPElement(null, "test", null); element.setAttributeNS("urn:ns1", "ns1:attr", "value"); element.setAttributeNS(null, "attr", "value"); assertTrue(element.removeAttribute(new QName("attr"))); NamedNodeMap attributes = element.getAttributes(); assertEquals(1, attributes.getLength()); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
/** * Tests the behavior of {@link SOAPElement#removeAttribute(QName)} for an attribute created * with {@link Element#setAttribute(String, String)}. * /* w w w. ja v a2 s . c o m*/ * @throws Exception */ @Validated @Test public void testRemoveAttributeByQNameWithoutNamespace2() throws Exception { SOAPElement element = saajUtil.createSOAPElement(null, "test", null); element.setAttributeNS("urn:ns1", "ns1:attr", "value"); element.setAttribute("attr", "value"); assertTrue(element.removeAttribute(new QName("attr"))); NamedNodeMap attributes = element.getAttributes(); assertEquals(1, attributes.getLength()); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test//from www .j a v 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
/** * Test the behavior of {@link SOAPElement#getAttributeValue(QName)} for an attribute without * namespace./*from w w w . j a va2s. c om*/ * * @throws Exception */ @Validated @Test public void testGetAttributeValueByQNameWithoutNamespace() throws Exception { SOAPElement element = saajUtil.createSOAPElement("urn:test", "test", "p"); element.setAttributeNS(null, "attr", "value"); assertEquals("value", element.getAttributeValue(new QName("attr"))); }