Example usage for javax.xml.soap SOAPBody addChildElement

List of usage examples for javax.xml.soap SOAPBody addChildElement

Introduction

In this page you can find the example usage for javax.xml.soap SOAPBody addChildElement.

Prototype

public SOAPElement addChildElement(String localName, String prefix, String uri) throws SOAPException;

Source Link

Document

Creates a new SOAPElement object initialized with the specified local name, prefix, and URI and adds the new element to this SOAPElement object.

Usage

From source file:com.hiperium.commons.client.soap.AthenticationDispatcherTest.java

/**
 * /*from  www  . j  a va 2  s. c  om*/
 * @return
 */
public static SOAPMessage createEndSessionSOAPMessage() {
    SOAPMessage soapMessage = null;
    try {
        soapMessage = MessageFactory.newInstance().createMessage();
        SOAPPart soapPart = soapMessage.getSOAPPart();
        SOAPEnvelope soapEnvelope = soapPart.getEnvelope();

        // Add message body parameters
        SOAPBody soapBody = soapEnvelope.getBody();
        soapBody.addChildElement("endSession", "ns2", "https://sei.general.soap.web.hiperium.com/");

        // Check the input
        System.out.println("REQUEST:");
        soapMessage.writeTo(System.out);
        System.out.println();

    } catch (SOAPException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    }
    return soapMessage;
}

From source file:com.hiperium.commons.client.soap.AthenticationDispatcherTest.java

/**
 * /*from   w w  w  .j  a v  a  2 s.  c om*/
 * @return
 */
public static SOAPMessage createAuthSOAPMessage(UserCredentialDTO dto) {
    SOAPMessage soapMessage = null;
    try {
        soapMessage = MessageFactory.newInstance().createMessage();
        SOAPPart soapPart = soapMessage.getSOAPPart();
        SOAPEnvelope soapEnvelope = soapPart.getEnvelope();

        // Add message body parameters
        SOAPBody soapBody = soapEnvelope.getBody();
        SOAPElement method = soapBody.addChildElement("userAuthentication", "ns2",
                "https://sei.authentication.soap.web.hiperium.com/");
        SOAPElement argument = method.addChildElement("arg0");
        argument.addChildElement("email").addTextNode(dto.getEmail());
        argument.addChildElement("password").addTextNode(dto.getPassword());

        // Check the input
        System.out.println("REQUEST:");
        soapMessage.writeTo(System.out);
        System.out.println();

    } catch (SOAPException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    }
    return soapMessage;
}

From source file:com.hiperium.commons.client.soap.AthenticationDispatcherTest.java

/**
 * /* www  .  ja v a  2 s. c  o m*/
 * @return
 */
public static SOAPMessage createSelectHomeSOAPMessage(HomeSelectionDTO dto) {
    SOAPMessage soapMessage = null;
    try {
        soapMessage = MessageFactory.newInstance().createMessage();
        SOAPPart soapPart = soapMessage.getSOAPPart();
        SOAPEnvelope soapEnvelope = soapPart.getEnvelope();

        // Add message body parameters
        SOAPBody soapBody = soapEnvelope.getBody();
        SOAPElement method = soapBody.addChildElement("selectHome", "ns2",
                "https://sei.authentication.soap.web.hiperium.com/");
        SOAPElement argument = method.addChildElement("arg0");
        argument.addChildElement("homeId").addTextNode(dto.getHomeId().toString());
        argument.addChildElement("profileId").addTextNode(dto.getProfileId().toString());

        // Check the input
        System.out.println("REQUEST:");
        soapMessage.writeTo(System.out);
        System.out.println();

    } catch (SOAPException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    }
    return soapMessage;
}

From source file:edu.duke.cabig.c3pr.webservice.integration.StudyImportExportWebServiceTest.java

private SOAPMessage prepareRequestEnvelope(String xmlFile, String wrapperElement)
        throws SOAPException, DOMException, IOException, SAXException, ParserConfigurationException {
    MessageFactory mf = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
    SOAPMessage reqMsg = mf.createMessage();
    SOAPPart part = reqMsg.getSOAPPart();
    SOAPEnvelope env = part.getEnvelope();
    SOAPBody body = env.getBody();

    SOAPElement operation = body.addChildElement(wrapperElement, "stud", SERVICE_NS);
    operation.appendChild(env.getOwnerDocument().importNode(getSOAPBodyFromXML(xmlFile), true));
    reqMsg.saveChanges();//  w w w  .j a v a 2  s  .c om
    return reqMsg;
}

From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java

/**
 * Test that {@link SOAPElement#getAttributeValue(Name)} returns <code>null</code> if the
 * requested attribute doesn't exist.//w  w  w.j a v  a 2 s  .c o m
 * 
 * @throws Exception
 */
@Validated
@Test
public void testGetAttributeValueByNameNonExisting() throws Exception {
    SOAPEnvelope envelope = saajUtil.createSOAP11Envelope();
    SOAPBody body = envelope.addBody();
    SOAPElement element = body.addChildElement("test", "p", "urn:test");
    assertNull(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 without
 * namespace.//  w  ww .  j a va 2 s  . com
 * 
 * @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.//www .  j a v a  2s .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")));
}