當前位置: 首頁>>代碼示例>>Java>>正文


Java SOAPBody.addAttribute方法代碼示例

本文整理匯總了Java中javax.xml.soap.SOAPBody.addAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java SOAPBody.addAttribute方法的具體用法?Java SOAPBody.addAttribute怎麽用?Java SOAPBody.addAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.xml.soap.SOAPBody的用法示例。


在下文中一共展示了SOAPBody.addAttribute方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testRemoveAttribute2

import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
@Validated @Test
public void testRemoveAttribute2() throws Exception {
    SOAPMessage msg = MessageFactory.newInstance().createMessage();
    SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
    SOAPBody body = envelope.getBody();

    QName name = new QName("MyAttr1");
    String value = "MyValue1";
    body.addAttribute(name, value);
    boolean b = body.removeAttribute(name);
    assertTrue(b);

    b = body.removeAttribute(name);
    if (b) {
        //removeAttribute() did not return false
        fail();
    }
    //getAttributeValue should return null
    assertNull(body.getAttributeValue(name));
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:21,代碼來源:SOAPElementTest.java

示例2: testRemoveAttributeName

import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
@Validated @Test
public void testRemoveAttributeName() throws Exception {
    SOAPMessage msg = MessageFactory.newInstance().createMessage();
    SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
    SOAPBody body = envelope.getBody();

    Name name = envelope.createName("MyAttr1");
    String value = "MyValue1";
    body.addAttribute(name, value);
    boolean b = body.removeAttribute(name);
    assertTrue(b);

    b = body.removeAttribute(name);
    assertTrue(!b);

    String s = body.getAttributeValue(name);
    assertNull(s);
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:19,代碼來源:SOAPElementTest.java

示例3: _testRemoveAttributeQName

import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
public void _testRemoveAttributeQName() throws Exception {
    SOAPMessage msg =
            MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
    SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
    SOAPBody body = envelope.getBody();

    QName name = new QName("MyAttr1");
    String value = "MyValue1";
    body.addAttribute(name, value);
    boolean b = body.removeAttribute(name);
    assertTrue(b);
    b = body.removeAttribute(name);
    assertTrue(!b);

    assertNull(body.getAttributeValue(name));
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:17,代碼來源:SOAPElementTest.java

示例4: testAttributes

import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
@Validated @Test
public void testAttributes() throws Exception {
    SOAPEnvelope envelope = getSOAPEnvelope();
    SOAPBody body = envelope.getBody();

    Name name1 = envelope.createName("MyAttr1");
    String value1 = "MyValue1";

    Name name2 = envelope.createName("MyAttr2");
    String value2 = "MyValue2";

    Name name3 = envelope.createName("MyAttr3");
    String value3 = "MyValue3";

    body.addAttribute(name1, value1);
    body.addAttribute(name2, value2);
    body.addAttribute(name3, value3);

    Iterator iterator = body.getAllAttributes();
    assertTrue(getIteratorCount(iterator) == 3);
    iterator = body.getAllAttributes();

    boolean foundName1 = false;
    boolean foundName2 = false;
    boolean foundName3 = false;
    while (iterator.hasNext()) {
        Name name = (Name)iterator.next();
        if (name.equals(name1)) {
            foundName1 = true;
            assertEquals(value1, body.getAttributeValue(name));
        } else if (name.equals(name2)) {
            foundName2 = true;
            assertEquals(value2, body.getAttributeValue(name));
        } else if (name.equals(name3)) {
            foundName3 = true;
            assertEquals(value3, body.getAttributeValue(name));
        }
    }
    assertTrue(foundName1 && foundName2 && foundName3);
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:41,代碼來源:SOAPEnvelopeTest.java

示例5: testAttributes2

import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
@Validated @Test
public void testAttributes2() throws Exception {
    SOAPEnvelope envelope = getSOAPEnvelope();
    SOAPBody body = envelope.getBody();

    Name name1 = envelope.createName("MyAttr1", "att", "http://test.com/Attr");
    String value1 = "MyValue1";

    Name name2 = envelope.createName("MyAttr2");
    String value2 = "MyValue2";

    Name name3 = envelope.createName("MyAttr3");
    String value3 = "MyValue3";

    body.addAttribute(name1, value1);
    body.addAttribute(name2, value2);
    body.addAttribute(name3, value3);

    Iterator iterator = body.getAllAttributes();
    assertTrue(getIteratorCount(iterator) == 3);
    iterator = body.getAllAttributes();

    boolean foundName1 = false;
    boolean foundName2 = false;
    boolean foundName3 = false;
    while (iterator.hasNext()) {
        Name name = (Name)iterator.next();
        if (name.equals(name1)) {
            foundName1 = true;
            assertEquals(value1, body.getAttributeValue(name));
        } else if (name.equals(name2)) {
            foundName2 = true;
            assertEquals(value2, body.getAttributeValue(name));
        } else if (name.equals(name3)) {
            foundName3 = true;
            assertEquals(value3, body.getAttributeValue(name));
        }
    }
    assertTrue(foundName1 && foundName2 && foundName3);
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:41,代碼來源:SOAPEnvelopeTest.java

示例6: testAttributes3

import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
@Validated @Test
public void testAttributes3() throws Exception {
    SOAPEnvelope envelope = getSOAPEnvelope();
    SOAPBody body = envelope.getBody();

    Name name1 = envelope.createName("MyAttr1", "att", "http://test.com/Attr");
    String value1 = "MyValue1";

    Name name2 = envelope.createName("MyAttr2", "att", "http://test.com/Attr");
    String value2 = "MyValue2";

    Name name3 = envelope.createName("MyAttr3", "att", "http://test.com/Attr");
    String value3 = "MyValue3";

    body.addAttribute(name1, value1);
    body.addAttribute(name2, value2);
    body.addAttribute(name3, value3);

    Iterator iterator = body.getAllAttributes();
    assertTrue(getIteratorCount(iterator) == 3);
    iterator = body.getAllAttributes();

    boolean foundName1 = false;
    boolean foundName2 = false;
    boolean foundName3 = false;
    while (iterator.hasNext()) {
        Name name = (Name)iterator.next();
        if (name.equals(name1)) {
            foundName1 = true;
            assertEquals(value1, body.getAttributeValue(name));
        } else if (name.equals(name2)) {
            foundName2 = true;
            assertEquals(value2, body.getAttributeValue(name));
        } else if (name.equals(name3)) {
            foundName3 = true;
            assertEquals(value3, body.getAttributeValue(name));
        }
    }
    assertTrue(foundName1 && foundName2 && foundName3);
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:41,代碼來源:SOAPEnvelopeTest.java

示例7: testRemoveAttribute

import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
@Validated @Test
public void testRemoveAttribute() throws Exception {
    SOAPMessage msg = MessageFactory.newInstance().createMessage();
    SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
    SOAPBody body = envelope.getBody();
    Name name = envelope.createName("MyAttr1");
    String value = "MyValue1";
    body.addAttribute(name, value);
    boolean b = body.removeAttribute(name);
    assertTrue("removeAttribute() did not return true", b);
    b = body.removeAttribute(name);
    assertFalse("removeAttribute() did not return false", b);
    assertNull(body.getAttributeValue(name));
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:15,代碼來源:SOAPElementTest.java

示例8: testAddAttribute

import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
@Validated @Test
public void testAddAttribute() {
    try {
        MessageFactory fact = MessageFactory.newInstance();
        SOAPMessage message = fact.createMessage();
        SOAPBody soapBody = message.getSOAPBody();
        QName qname = new QName("http://test.apache.org/", "Child1", "ch");
        String value = "MyValue1";
        soapBody.addAttribute(qname, value);
        message.saveChanges();

    } catch (Exception e) {
        fail("Unexpected Exception : " + e);
    }
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:16,代碼來源:SOAPBodyTest.java

示例9: testAddAttribute2

import javax.xml.soap.SOAPBody; //導入方法依賴的package包/類
@Validated @Test
public void testAddAttribute2() {
    try {
        MessageFactory fact = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
        SOAPMessage message = fact.createMessage();
        SOAPBody soapBody = message.getSOAPBody();
        QName qname = new QName("http://test.apache.org/", "Child1", "ch");
        String value = "MyValue1";
        soapBody.addAttribute(qname, value);
        message.saveChanges();
    } catch (Exception e) {
        fail("Unexpected Exception : " + e);
    }
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:15,代碼來源:SOAPBodyTest.java


注:本文中的javax.xml.soap.SOAPBody.addAttribute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。