当前位置: 首页>>代码示例>>Java>>正文


Java SOAPHeaderElement.detachNode方法代码示例

本文整理汇总了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));
        
	}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:60,代码来源:SOAPHeadersAdapterTests.java

示例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));
        
	}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:60,代码来源:SOAPHeadersAdapterTests.java


注:本文中的javax.xml.soap.SOAPHeaderElement.detachNode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。