Example usage for javax.xml.soap SOAPEnvelope addBody

List of usage examples for javax.xml.soap SOAPEnvelope addBody

Introduction

In this page you can find the example usage for javax.xml.soap SOAPEnvelope addBody.

Prototype

public SOAPBody addBody() throws SOAPException;

Source Link

Document

Creates a SOAPBody object and sets it as the SOAPBody object for this SOAPEnvelope object.

Usage

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.//from  www  .  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 av  a2s  . c  o m*/
 * 
 * @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.//ww  w  .j  a  v a2 s  . c  o 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   www .  ja  v a2s . c o m*/
public void testRemoveAttributeByName() throws Exception {
    SOAPEnvelope envelope = saajUtil.createSOAP11Envelope();
    SOAPBody body = envelope.addBody();
    SOAPElement element = body.addChildElement(new QName("urn:test", "test"));
    element.setAttributeNS("urn:ns1", "ns1:attr1", "value");
    element.setAttributeNS("urn:ns1", "ns1:attr2", "value");
    assertTrue(element.removeAttribute(envelope.createName("attr2", "p", "urn:ns1")));
    NamedNodeMap attributes = element.getAttributes();
    assertNull(attributes.getNamedItemNS("urn:ns1", "attr2"));
}

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

@Validated
@Test/* www. j a  v  a2  s  .  c om*/
public void testAddAttributeFromNameWithNamespace() throws Exception {
    SOAPEnvelope envelope = saajUtil.createSOAP11Envelope();
    SOAPBody body = envelope.addBody();
    SOAPElement element = body.addChildElement(new QName("urn:test", "test"));
    SOAPElement retValue = element.addAttribute(envelope.createName("attr", "p", "urn:ns"), "value");
    assertSame(element, retValue);
    Attr attr = element.getAttributeNodeNS("urn:ns", "attr");
    assertEquals("urn:ns", attr.getNamespaceURI());
    assertEquals("attr", attr.getLocalName());
    assertEquals("p", attr.getPrefix());
    assertEquals("value", attr.getValue());
    Attr nsDecl = element.getAttributeNodeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "p");
    assertNotNull(nsDecl);
    assertEquals("urn:ns", nsDecl.getValue());
}

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

@Validated
@Test// ww  w.  ja v a2  s.  c o  m
public void testAddAttributeFromNameWithoutNamespace() throws Exception {
    SOAPEnvelope envelope = saajUtil.createSOAP11Envelope();
    SOAPBody body = envelope.addBody();
    SOAPElement element = body.addChildElement(new QName("urn:test", "test"));
    SOAPElement retValue = element.addAttribute(envelope.createName("attr"), "value");
    assertSame(element, retValue);
    Attr attr = element.getAttributeNodeNS(null, "attr");
    assertNull(attr.getNamespaceURI());
    String localName = attr.getLocalName();
    if (localName != null) {
        assertEquals("attr", attr.getLocalName());
    }
    assertNull(attr.getPrefix());
    assertEquals("value", attr.getValue());
}

From source file:org.jasig.portal.security.provider.saml.SAMLDelegatedAuthenticationService.java

private Document createSOAPFaultDocument(String faultString) throws SOAPException {
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage message = factory.createMessage();
    SOAPPart sp = message.getSOAPPart();
    SOAPEnvelope se = sp.getEnvelope();
    se.setPrefix(SOAP_PREFIX);/*w  w w  . ja  va  2 s  .  c  o m*/
    se.getHeader().detachNode();
    se.addHeader();
    se.getBody().detachNode();
    SOAPBody body = se.addBody();
    SOAPFault fault = body.addFault();
    Name faultCode = se.createName("Client", null, SOAPConstants.URI_NS_SOAP_ENVELOPE);
    fault.setFaultCode(faultCode);
    fault.setFaultString(faultString);
    return se.getOwnerDocument();
}

From source file:org.jbpm.bpel.integration.server.SoapHandler.java

public boolean handleResponse(MessageContext messageContext) throws JAXRPCException {
    Map parts = (Map) messageContext.getProperty(MESSAGE_PARTS_PROP);
    SOAPFaultException faultException = (SOAPFaultException) messageContext.getProperty(FAULT_EXCEPTION_PROP);

    // absence of both parts and fault means one-way operation
    if (parts == null && faultException == null)
        return true;

    String operationName = (String) messageContext.getProperty(OPERATION_NAME_PROP);
    SOAPMessage soapMessage = ((SOAPMessageContext) messageContext).getMessage();

    JbpmContext jbpmContext = integrationControl.getIntegrationServiceFactory().getJbpmConfiguration()
            .createJbpmContext();// w  w  w.ja v  a2  s .co m
    try {
        lookupEndpointMetadata(messageContext);

        SOAPEnvelope envelope = soapMessage.getSOAPPart().getEnvelope();
        // remove existing body, it might have undesirable content
        SOAPBody body = envelope.getBody();
        body.detachNode();
        // re-create body
        body = envelope.addBody();

        if (faultException == null)
            writeOutput(operationName, soapMessage, parts);
        else {
            String faultName = (String) messageContext.getProperty(FAULT_NAME_PROP);
            writeFault(operationName, soapMessage, faultName, parts, faultException);
        }
    }
    /*
     * NO need to set jbpm context as rollback only for any exception, since operations in try-block
     * only read definitions from database
     */
    catch (SOAPException e) {
        throw new JAXRPCException("could not compose outbound soap message", e);
    } finally {
        jbpmContext.close();
    }
    return true;
}