本文整理汇总了Java中javax.xml.soap.SOAPHeaderElement.detachNode方法的典型用法代码示例。如果您正苦于以下问题:Java SOAPHeaderElement.detachNode方法的具体用法?Java SOAPHeaderElement.detachNode怎么用?Java SOAPHeaderElement.detachNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.soap.SOAPHeaderElement
的用法示例。
在下文中一共展示了SOAPHeaderElement.detachNode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAddRemoveAsSOAPMessage
import javax.xml.soap.SOAPHeaderElement; //导入方法依赖的package包/类
public void testAddRemoveAsSOAPMessage() throws Exception {
MessageContext messageContext = getMessageContext();
SOAPHeadersAdapter.install(messageContext);
SOAPFactory sf = SOAPFactory.newInstance();
// QName used here should match the key for the list set on the requestCtx
SOAPElement e1 = sf.createElement(ACOH1_HEADER_QNAME);
e1.addTextNode(CONTENT_STRING1);
String acoh1 = e1.toString();
// QName used here should match the key for the list set on the requestCtx
SOAPElement e2 = sf.createElement(ACOH1_HEADER_QNAME);
e2.addTextNode(CONTENT_STRING2);
String acoh2 = e2.toString();
List<String> acoh1ContentList = new ArrayList<String>();
acoh1ContentList.add(acoh1);
acoh1ContentList.add(acoh2);
SOAPHeadersAdapter adapter = (SOAPHeadersAdapter)messageContext.getProperty(Constants.JAXWS_OUTBOUND_SOAP_HEADERS);
adapter.put(ACOH1_HEADER_QNAME, acoh1ContentList);
// get message object and convert to SOAPMessage
SOAPMessage soapMessage = messageContext.getMessage().getAsSOAPMessage();
// confirm headers are there
SOAPHeader soapHeader = soapMessage.getSOAPHeader();
Iterator<SOAPHeaderElement> it = soapHeader.getChildElements();
// TODO: not sure if the order of the header additions is or should be preserved.
// in other words, this test may be a little too strict.
SOAPHeaderElement headerElem1 = it.next();
SOAPHeaderElement headerElem2 = it.next();
// should only be two header elements, so...
assertFalse(it.hasNext());
assertTrue(headerElem1.toString().equals(acoh1));
assertTrue(headerElem2.toString().equals(acoh2));
// now that we've done a toString() on the header elements, they've been parsed and
// processed by the underlying OM implementation... let's remove one by way of SOAP
// API, then let's make sure we can still get and manipulate the headers via the
// SOAPHeadersAdapter
// TODO: removeChild gives an exception
//soapHeader.removeChild(headerElem1);
headerElem1.detachNode();
// one is removed, make sure the SOAPHeadersAdapter reflects the change
List<String> contentListAfterSOAPRemoval = adapter.get(ACOH1_HEADER_QNAME);
assertTrue(contentListAfterSOAPRemoval.size() == 1);
// remember we removed headerElem1, so we expect acoh2 to still exist
assertTrue(contentListAfterSOAPRemoval.get(0).equals(acoh2));
}
示例2: testAddRemoveAsSOAPEnvelope
import javax.xml.soap.SOAPHeaderElement; //导入方法依赖的package包/类
public void testAddRemoveAsSOAPEnvelope() throws Exception {
MessageContext messageContext = getMessageContext();
SOAPHeadersAdapter.install(messageContext);
SOAPFactory sf = SOAPFactory.newInstance();
// QName used here should match the key for the list set on the requestCtx
SOAPElement e1 = sf.createElement(ACOH1_HEADER_QNAME);
e1.addTextNode(CONTENT_STRING1);
String acoh1 = e1.toString();
// QName used here should match the key for the list set on the requestCtx
SOAPElement e2 = sf.createElement(ACOH1_HEADER_QNAME);
e2.addTextNode(CONTENT_STRING2);
String acoh2 = e2.toString();
List<String> acoh1ContentList = new ArrayList<String>();
acoh1ContentList.add(acoh1);
acoh1ContentList.add(acoh2);
SOAPHeadersAdapter adapter = (SOAPHeadersAdapter)messageContext.getProperty(Constants.JAXWS_OUTBOUND_SOAP_HEADERS);
adapter.put(ACOH1_HEADER_QNAME, acoh1ContentList);
// get message object and convert to SOAPEnvelope
SOAPEnvelope soapEnvelope = messageContext.getMessage().getAsSOAPEnvelope();
// confirm headers are there
SOAPHeader soapHeader = soapEnvelope.getHeader();
Iterator<SOAPHeaderElement> it = soapHeader.getChildElements();
// TODO: not sure if the order of the header additions is or should be preserved.
// in other words, this test may be a little too strict.
SOAPHeaderElement headerElem1 = it.next();
SOAPHeaderElement headerElem2 = it.next();
// should only be two header elements, so...
assertFalse(it.hasNext());
assertTrue(headerElem1.toString().equals(acoh1));
assertTrue(headerElem2.toString().equals(acoh2));
// now that we've done a toString() on the header elements, they've been parsed and
// processed by the underlying OM implementation... let's remove one by way of SOAP
// API, then let's make sure we can still get and manipulate the headers via the
// SOAPHeadersAdapter
// TODO: removeChild gives an exception
//soapHeader.removeChild(headerElem1);
headerElem1.detachNode();
// one is removed, make sure the SOAPHeadersAdapter reflects the change
List<String> contentListAfterSOAPRemoval = adapter.get(ACOH1_HEADER_QNAME);
assertTrue(contentListAfterSOAPRemoval.size() == 1);
// remember we removed headerElem1, so we expect acoh2 to still exist
assertTrue(contentListAfterSOAPRemoval.get(0).equals(acoh2));
}