Java 类javax.xml.soap.SOAPBody 实例源码

项目:scribe    文件:SOAPExecutor.java   
/**
 * Constructs XPath query over the SOAP message
 * 
 * @param query XPath query
 * @param response SOAP message
 * @return XPath query
 * @throws SOAPException in case of SOAP issue
 * @throws JaxenException XPath problem
 */
public final XPath createXPath(final String query, final SOAPMessage response) throws SOAPException, JaxenException {

  /* Uses DOM to XPath mapping */
  final XPath xpath = new DOMXPath(query);

  /* Define a namespaces used in response */
  final SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
  final SOAPPart sp = response.getSOAPPart();
  final SOAPEnvelope env = sp.getEnvelope();
  final SOAPBody bdy = env.getBody();

  /* Add namespaces from SOAP envelope */
  addNamespaces(nsContext, env);

  /* Add namespaces of top body element */
  final Iterator<?> bodyElements = bdy.getChildElements();
  while (bodyElements.hasNext()) {
    SOAPElement element = (SOAPElement) bodyElements.next();
    addNamespaces(nsContext, element);
  }
  xpath.setNamespaceContext(nsContext);
  return xpath;
}
项目:xrd4j    文件:AbstractResponseDeserializer.java   
/**
 * Tries to deserialize standard SOAP error message. If a standard error
 * message is found true is returned. Otherwise false is returned.
 *
 * @param response ServiceResponse that holds the SOAPMessage
 * @return true if and only if a standard SOAP fault is found; otherwise
 * false
 * @throws SOAPException if there's a SOAP error
 */
private boolean deserializeSOAPFault(final ServiceResponse response) throws SOAPException {
    LOGGER.debug("Deserialize SOAP fault.");
    Map<String, String> fault;
    SOAPBody body = response.getSoapMessage().getSOAPBody();
    NodeList list = body.getElementsByTagNameNS("*", "Fault");
    if (list.getLength() == 1) {
        fault = SOAPHelper.nodesToMap(list.item(0).getChildNodes(), true);
        String faultCode = fault.get("FAULTCODE");
        String faultString = fault.get("FAULTSTRING");
        String faultActor = fault.get("FAULTACTOR");
        Object detail = this.deserializeFaultDetail(SOAPHelper.getNode((Node) list.item(0), "detail"));
        response.setErrorMessage(new ErrorMessage(faultCode, faultString, faultActor, detail));
        LOGGER.info("SOAP fault was succesfully deserialized.");
        return true;
    }
    LOGGER.debug("SOAP fault was not found.");
    return false;
}
项目:jdk8u-jdk    文件:SaajEmptyNamespaceTest.java   
@Test
public void testAddElementToNullNsQName() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement(new QName(null, "global-child"));
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
项目:jdk8u-jdk    文件:SaajEmptyNamespaceTest.java   
@Test
public void testAddElementToGlobalNs() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", "");
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
项目:jdk8u-jdk    文件:SaajEmptyNamespaceTest.java   
@Test
public void testAddElementToNullNs() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", null);
    childGlobalNS.addNamespaceDeclaration("", null);
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(TEST_NS, childDefaultNS.getNamespaceURI());
}
项目:jdk8u-jdk    文件:SaajEmptyNamespaceTest.java   
@Test
public void testAddElementToGlobalNsQName() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement(new QName("", "global-child"));
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(),TEST_NS);
}
项目:openjdk-jdk10    文件:SaajEmptyNamespaceTest.java   
@Test
public void testAddElementToNullNsQName() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement(new QName(null, "global-child"));
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
项目:openjdk-jdk10    文件:SaajEmptyNamespaceTest.java   
@Test
public void testAddElementToGlobalNs() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", "");
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
项目:openjdk-jdk10    文件:SaajEmptyNamespaceTest.java   
@Test
public void testAddElementToNullNs() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", null);
    childGlobalNS.addNamespaceDeclaration("", null);
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(TEST_NS, childDefaultNS.getNamespaceURI());
}
项目:openjdk-jdk10    文件:SaajEmptyNamespaceTest.java   
@Test
public void testAddElementToGlobalNsQName() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement(new QName("", "global-child"));
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(),TEST_NS);
}
项目:atf-toolbox-java    文件:WebServiceAutomationManager.java   
/**
 * createSOAPRequestMessage - create a SOAP message from an object
 *
 * @param webServiceKey
 *            key to locate the web service
 * @param request
 *            - request body content
 * @param action
 *            - SOAP Action string
 * @return SOAPMessage
 * @throws SOAPException
 *             - if there was an error creating the SOAP Connection
 * @throws JAXBException
 *             - if there was an error marshalling the SOAP Message
 */
private SOAPMessage createSOAPRequestMessage(String webServiceKey, Object request, String action) throws SOAPException, JAXBException {
    WebService service = getWebService(webServiceKey);

    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage message = factory.createMessage();
    SOAPPart soapPart = message.getSOAPPart();

    // SOAP Envelope
    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("example", service.getNamespaceURI());

    if (action != null) {
        MimeHeaders headers = message.getMimeHeaders();
        headers.addHeader("SOAPAction", service.getNamespaceURI() + "VerifyEmail");
    }

    // SOAP Body
    SOAPBody body = message.getSOAPBody();

    marshallObject(webServiceKey, request, body);

    message.saveChanges();
    return message;
}
项目:OSCAR-ConCert    文件:OSCARFAXSOAPMessage.java   
public OSCARFAXSOAPMessage(MessageFactory mf)
    throws SOAPException
{
    this.mf = mf;
    msg = mf.createMessage();
    soapPart = msg.getSOAPPart();
    envelope = soapPart.getEnvelope();
    SOAPBody body = envelope.getBody();
    SOAPElement ele = body.addChildElement(envelope.createName("OscarFax", "jaxm", "http://oscarhome.org/jaxm/oscarFax/"));
    sendingProvider = ele.addChildElement("sendingProvider");
    locationId = ele.addChildElement("locationId");
    identifier = ele.addChildElement("identifier");
    faxType = ele.addChildElement("faxType");
    coverSheet = ele.addChildElement("coverSheet");
    from = ele.addChildElement("from");
    comments = ele.addChildElement("comments");
    sendersFax = ele.addChildElement("sendersFax");
    sendersPhone = ele.addChildElement("sendersPhone");
    dateOfSending = ele.addChildElement("dateOfSending");
    recipient = ele.addChildElement("recipient");
    recipientFaxNumber = ele.addChildElement("recipientFaxNumber");
    payLoad = ele.addChildElement(envelope.createName("OscarFaxPayLoad", "jaxm", "http://oscarhome.org/jaxm/oscarFax/"));
}
项目:soap-wrapper-lambda    文件:ExampleSoapMessage.java   
public static SOAPMessage create() throws SOAPException {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage message = messageFactory.createMessage();
    SOAPPart soapPart = message.getSOAPPart();

    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("codecentric", "https://www.codecentric.de");

    SOAPBody envelopeBody = envelope.getBody();
    SOAPElement soapBodyElem = envelopeBody.addChildElement("location", "codecentric");

    SOAPElement place = soapBodyElem.addChildElement("place", "codecentric");
    place.addTextNode("Berlin");

    MimeHeaders headers = message.getMimeHeaders();
    headers.addHeader("SOAPAction", "https://www.codecentric.de/location");

    message.saveChanges();
    return message;
}
项目:rpb    文件:EventDefListAllHandler.java   
@Override
public boolean handleMessage(SOAPMessageContext context) {
    Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (!isRequest) { // only incoming messages
        try {
            SOAPMessage soapMsg = context.getMessage();
            SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
            SOAPBody soapBody = soapEnv.getBody();
            if (soapBody != null) {
                // Should have a SOAPBody and a listall response...
                NodeList nodeList = soapBody.getElementsByTagNameNS(EVENTDEF_NS, EVENTDEF_LIST_ALL_RESPONSE);
                if (nodeList.getLength() > 0) { // check for listAllResponse
                                                // tag first!
                    nodeList = soapBody.getElementsByTagNameNS(EVENTDEF_NS, EVENTDEF_ELEMENT);
                    recursiveRenamespace(nodeList); // renamespace...
                    soapMsg.saveChanges();
                }
            }
        } catch (Exception e) {
            catchMessages(e);
        }
    }
    return true;
}
项目:rpb    文件:StudyListAllHandler.java   
@Override
public boolean handleMessage(SOAPMessageContext context) {
    Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (!isRequest) { // only incoming messages
        try {
            SOAPMessage soapMsg = context.getMessage();
            SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
            SOAPBody soapBody = soapEnv.getBody();
            if (soapBody != null) {
                // Should have a SOAPBody and a listall response...
                NodeList nodeList = soapBody.getElementsByTagNameNS(STUDIES_NS, STUDY_LIST_ALL_RESPONSE);
                if (nodeList.getLength() > 0) { // check for listAllResponse
                                                // tag first!
                    nodeList = soapBody.getElementsByTagNameNS(STUDIES_NS, STUDIES_ELEMENT);
                    recursiveRenamespace(nodeList); // renamespace...
                    soapMsg.saveChanges();
                }
            }
        } catch (Exception e) {
            catchMessages(e);
        }
    }
    return true;
}
项目:hermes    文件:SOAPResponse.java   
/**
 * Adds a SOAP fault to the SOAP message of this response.
 * 
 * @param code the fault code.
 * @param actor the fault actor.
 * @param desc the fault description.
 * @return the SOAP fault which has been added to the SOAP message. null if
 *         there is no SOAP message in this response or the fault has
 *         already been added.
 * @throws SOAPException a SOAP error occurred when adding the the fault.
 */
public SOAPFault addFault(String code, String actor, String desc)
        throws SOAPException {
    SOAPMessage msg = getMessage();
    if (msg != null) {
        SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
        SOAPBody body = env.getBody();
        if (body != null && !body.hasFault()) {
            SOAPFault fault = body.addFault();
            if (code != null) {
                fault.setFaultCode(env.getElementName().getPrefix() + ":"
                        + code);
            }
            if (actor != null) {
                fault.setFaultActor(actor);
            }
            if (desc != null) {
                fault.setFaultString(desc);
            }
            return fault;
        }
    }
    return null;
}
项目:hermes    文件:SOAPSender.java   
/**
 * Add SOAP element to body with name and value.
 * 
 * @param tagName   The tag name of element to be retrieved.
 * @param tagValue  The value of the element to be added.
 * @param nsPrefix  The namespace Prefix
 * @param nsURI     The namespace URI.
 * @return          true if the creation and addition is successfully.
 * @throws SOAPException
 */
public boolean addRequestElementText(String tagName
                                    ,String tagValue
                                    ,String nsPrefix
                                    ,String nsURI) throws SOAPException{
    if (this.request == null)
        return false;       

    SOAPBody soapBody = request.getSOAPPart().getEnvelope().getBody();

    if (soapBody == null)
        return false;

    //  Create new element.
    SOAPElement newElement = SOAPUtilities.createElement(tagName, tagValue, nsPrefix, nsURI);
    soapBody.addChildElement(newElement);
    return true;
}
项目:hermes    文件:SOAPUtilities.java   
/**
 * Get a SOAP Element from the SOAPMessage (SOAPbody inside).
 * 
 * @param message   The SOAP message to be searched with.
 * @param tagname   The tag name of element to be retrieved.
 * @param nsURI     The namespace URI.
 * @param whichOne  The nth child element to be returned.
 * 
 * @return The element in the tagname specified.
 */
public static SOAPElement getElement(SOAPMessage message
                                    ,String      tagname
                                    ,String      nsURI
                                    ,int         whichOne) throws SOAPException{
    if (message == null)    // return null if the message is null.
        return null;
    // Get the soap body from the response.
    SOAPBody elementBody = message.getSOAPPart().getEnvelope().getBody();

    if (elementBody == null)    // return null if the body is null.
        return null;

    // Find all the child with the childname.           
    NodeList nl = elementBody.getElementsByTagNameNS(nsURI, tagname);
    if (nl.getLength() <= whichOne){
        return null;
    }
    return (SOAPElement) nl.item(whichOne); 
}
项目:hermes    文件:SOAPUtilities.java   
/**
 * Get a SOAP Element list from the SOAPMessage (SOAPbody inside). 
 * 
 * @param message   The SOAP message to be searched with.
 * @param tagname   The tag name of element to be retrieved.
 * @param nsURI     The namespace URI.
 * @return          list of SOAP element 
 * @throws SOAPException
 */
public static List getElementList(SOAPMessage message
                                 ,String      tagname
                                 ,String      nsURI) throws SOAPException{
    if (message == null)    // return null if the message is null.
        return null;
    // Get the soap body from the response.
    SOAPBody elementBody = message.getSOAPPart().getEnvelope().getBody();

    if (elementBody == null)    // return null if the body is null.
        return null;

    NodeList nl     = elementBody.getElementsByTagNameNS(nsURI, tagname);               
    List     list   = new Vector();

    for (int i = 0; i < nl.getLength(); i++){
        if (nl.item(i) instanceof SOAPElement){
            list.add((SOAPElement)nl.item(i));
        }
    }   
    return list;
}
项目:hermes    文件:SOAPUtilities.java   
/**
 * Count how many element with <code>tagname</code> and <code>nsURI</code>
 * is in SOAPMessage <code>message</code>.
 * 
 * @param message
 *          The SOAP message 
 * @param tagname
 *          The name of the tag to be counted.
 * @param nsURI
 *          The namespace URI of the tag.
 * @return
 *          The number of element in the SOAP message.
 * @throws SOAPException
 *          
 */
public static int countElement(SOAPMessage  message
                              ,String       tagname
                              ,String       nsURI) throws SOAPException{
    if (message == null)    // return null if the message is null.
        throw new NullPointerException("SOAP Message is null.");
    // Get the soap body from the response.
    SOAPBody elementBody = message.getSOAPPart().getEnvelope().getBody();

    if (elementBody == null)    // return null if the body is null.
        throw new NullPointerException("SOAP Body is null.");

    // Find all the child with the childname.           
    NodeList nl = elementBody.getElementsByTagNameNS(nsURI, tagname);
    return nl.getLength();  
}
项目:jdk8u_jdk    文件:SaajEmptyNamespaceTest.java   
@Test
public void testAddElementToNullNsQName() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement(new QName(null, "global-child"));
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
项目:jdk8u_jdk    文件:SaajEmptyNamespaceTest.java   
@Test
public void testAddElementToGlobalNs() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", "");
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
项目:jdk8u_jdk    文件:SaajEmptyNamespaceTest.java   
@Test
public void testAddElementToNullNs() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", null);
    childGlobalNS.addNamespaceDeclaration("", null);
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(TEST_NS, childDefaultNS.getNamespaceURI());
}
项目:jdk8u_jdk    文件:SaajEmptyNamespaceTest.java   
@Test
public void testAddElementToGlobalNsQName() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement(new QName("", "global-child"));
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(),TEST_NS);
}
项目:lookaside_java-1.8.0-openjdk    文件:SaajEmptyNamespaceTest.java   
@Test
public void testAddElementToNullNsQName() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement(new QName(null, "global-child"));
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
项目:lookaside_java-1.8.0-openjdk    文件:SaajEmptyNamespaceTest.java   
@Test
public void testAddElementToGlobalNs() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", "");
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
项目:lookaside_java-1.8.0-openjdk    文件:SaajEmptyNamespaceTest.java   
@Test
public void testAddElementToNullNs() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement("global-child", "", null);
    childGlobalNS.addNamespaceDeclaration("", null);
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(TEST_NS, childDefaultNS.getNamespaceURI());
}
项目:lookaside_java-1.8.0-openjdk    文件:SaajEmptyNamespaceTest.java   
@Test
public void testAddElementToGlobalNsQName() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();

    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement(new QName("", "global-child"));
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");

    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(),TEST_NS);
}
项目:OntologyBasedInormationExtractor    文件:AwsHandlerResolver.java   
public boolean handleMessage(SOAPMessageContext messagecontext) {
    Boolean outbound = (Boolean) messagecontext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (outbound) {
        try {
            SOAPMessage soapMessage = messagecontext.getMessage();
            SOAPBody soapBody = soapMessage.getSOAPBody();
            Node firstChild = soapBody.getFirstChild();

            String timeStamp = getTimestamp();
            String signature = getSignature(firstChild.getLocalName(), timeStamp, secretBytes);

            appendTextElement(firstChild, "Signature", signature);
            appendTextElement(firstChild, "Timestamp", timeStamp);
        } catch(SOAPException se) {
            throw new RuntimeException("SOAPException was thrown.", se);
        }
    }
    return true;
}
项目:Camel    文件:TesterBean.java   
public SOAPMessage processSOAP(Exchange exchange) {
    // Since the Camel-CXF endpoint uses a list to store the parameters
    // and bean component uses the bodyAs expression to get the value
    // we'll need to deal with the parameters ourself
    SOAPMessage soapMessage = (SOAPMessage)exchange.getIn().getBody(List.class).get(0);
    if (soapMessage == null) {
        System.out.println("Incoming null message detected...");
        return createDefaultSoapMessage("Greetings from Apache Camel!!!!", "null");
    }

    try {
        SOAPPart sp = soapMessage.getSOAPPart();
        SOAPEnvelope se = sp.getEnvelope();
        SOAPBody sb = se.getBody();
        String requestText = sb.getFirstChild().getTextContent();
        System.out.println(requestText);
        return createDefaultSoapMessage("Greetings from Apache Camel!!!!", requestText);
    } catch (Exception e) {
        e.printStackTrace();
        return createDefaultSoapMessage("Greetings from Apache Camel!!!!", e.getClass().getName());
    }
}
项目:Camel    文件:TesterBean.java   
public static SOAPMessage createDefaultSoapMessage(String responseMessage, String requestMessage) {
    try {
        SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
        SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();

        QName payloadName = new QName("http://apache.org/hello_world_soap_http/types", "greetMeResponse", "ns1");

        SOAPBodyElement payload = body.addBodyElement(payloadName);

        SOAPElement message = payload.addChildElement("responseType");

        message.addTextNode(responseMessage + " Request was  " + requestMessage);
        return soapMessage;
    } catch (SOAPException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
项目:Camel    文件:SoapTargetBean.java   
public SOAPMessage invokeSoapMessage(SOAPMessage request) {
    SOAPMessage response = null;
    try {
        SOAPBody body = request.getSOAPBody();
        Node n = body.getFirstChild();

        while (n.getNodeType() != Node.ELEMENT_NODE) {
            n = n.getNextSibling();
        }
        if (n.getLocalName().equals(sayHi.getLocalPart())) {
            response = sayHiResponse;
        } else if (n.getLocalName().equals(greetMe.getLocalPart())) {
            response = greetMeResponse;
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return response;
}
项目:jolie    文件:SoapProtocol.java   
private void setOutputEncodingStyle( SOAPEnvelope soapEnvelope, String operationName )
    throws IOException, SOAPException
{
    Port port = getWSDLPort();
    if ( port != null ) {
        BindingOperation bindingOperation = port.getBinding().getBindingOperation( operationName, null, null );
        if ( bindingOperation == null ) {
            return;
        }
        BindingOutput output = bindingOperation.getBindingOutput();
        if ( output == null ) {
            return;
        }
        for( ExtensibilityElement element : (List<ExtensibilityElement>) output.getExtensibilityElements() ) {
            if ( element instanceof javax.wsdl.extensions.soap.SOAPBody ) {
                List<String> list = ((javax.wsdl.extensions.soap.SOAPBody) element).getEncodingStyles();
                if ( list != null && list.isEmpty() == false ) {
                    soapEnvelope.setEncodingStyle( list.get( 0 ) );
                    soapEnvelope.addNamespaceDeclaration( "enc", list.get( 0 ) );
                }
            }
        }
    }
}
项目:rpb    文件:EventDefListAllHandler.java   
@Override
public boolean handleMessage(SOAPMessageContext context) {
    Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (!isRequest) { // only incoming messages
        try {
            SOAPMessage soapMsg = context.getMessage();
            SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
            SOAPBody soapBody = soapEnv.getBody();
            if (soapBody != null) {
                // Should have a SOAPBody and a listall response...
                NodeList nodeList = soapBody.getElementsByTagNameNS(EVENTDEF_NS, EVENTDEF_LIST_ALL_RESPONSE);
                if (nodeList.getLength() > 0) { // check for listAllResponse
                                                // tag first!
                    nodeList = soapBody.getElementsByTagNameNS(EVENTDEF_NS, EVENTDEF_ELEMENT);
                    recursiveRenamespace(nodeList); // renamespace...
                    soapMsg.saveChanges();
                }
            }
        } catch (Exception e) {
            catchMessages(e);
        }
    }
    return true;
}
项目:rpb    文件:StudyListAllHandler.java   
@Override
public boolean handleMessage(SOAPMessageContext context) {
    Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (!isRequest) { // only incoming messages
        try {
            SOAPMessage soapMsg = context.getMessage();
            SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
            SOAPBody soapBody = soapEnv.getBody();
            if (soapBody != null) {
                // Should have a SOAPBody and a listall response...
                NodeList nodeList = soapBody.getElementsByTagNameNS(STUDIES_NS, STUDY_LIST_ALL_RESPONSE);
                if (nodeList.getLength() > 0) { // check for listAllResponse
                                                // tag first!
                    nodeList = soapBody.getElementsByTagNameNS(STUDIES_NS, STUDIES_ELEMENT);
                    recursiveRenamespace(nodeList); // renamespace...
                    soapMsg.saveChanges();
                }
            }
        } catch (Exception e) {
            catchMessages(e);
        }
    }
    return true;
}
项目:jbossws-cxf    文件:EndpointImpl3.java   
public SOAPMessage invoke(SOAPMessage request)
{
   log.info("echo (3): " + request);
   try {
      SOAPBody sb = request.getSOAPBody();
      NodeList nl = sb.getElementsByTagName("arg0");
      if (nl.getLength() != 1) {
         throw new IllegalArgumentException("Unexpected input!");
      }
      Node ret = sb.getOwnerDocument().createElement("return");
      Node arg0 = nl.item(0);
      ret.appendChild(arg0.getFirstChild().cloneNode(true));
      Node parent = arg0.getParentNode();
      parent.removeChild(arg0);
      parent.appendChild(ret);
   } catch (Exception e) {
      throw new RuntimeException(e);
   }
   return request;
}
项目:jbossws-cxf    文件:EndpointImpl4.java   
public SOAPMessage invoke(SOAPMessage request)
{
   log.info("echo (4): " + request);
   try {
      SOAPBody sb = request.getSOAPBody();
      NodeList nl = sb.getElementsByTagName("arg0");
      if (nl.getLength() != 1) {
         throw new IllegalArgumentException("Unexpected input!");
      }
      Node ret = sb.getOwnerDocument().createElement("return");
      Node arg0 = nl.item(0);
      ret.appendChild(arg0.getFirstChild().cloneNode(true));
      Node parent = arg0.getParentNode();
      parent.removeChild(arg0);
      parent.appendChild(ret);
   } catch (Exception e) {
      throw new RuntimeException(e);
   }
   return request;
}
项目:jbossws-cxf    文件:EndpointImpl5.java   
public SOAPMessage invoke(SOAPMessage request)
{
   log.info("echo (5): " + request);
   try {
      SOAPBody sb = request.getSOAPBody();
      NodeList nl = sb.getElementsByTagName("arg0");
      if (nl.getLength() != 1) {
         throw new IllegalArgumentException("Unexpected input!");
      }
      Node ret = sb.getOwnerDocument().createElement("return");
      Node arg0 = nl.item(0);
      ret.appendChild(arg0.getFirstChild().cloneNode(true));
      Node parent = arg0.getParentNode();
      parent.removeChild(arg0);
      parent.appendChild(ret);
   } catch (Exception e) {
      throw new RuntimeException(e);
   }
   return request;
}
项目:jbossws-cxf    文件:UserHandler.java   
@Override
protected boolean handleInbound(SOAPMessageContext msgContext)
{
   log.info("handleInbound");

   try
   {
      SOAPMessage soapMessage = msgContext.getMessage();
      SOAPBody soapBody = soapMessage.getSOAPBody();

      SOAPBodyElement soapBodyElement = (SOAPBodyElement)soapBody.getChildElements().next();
      SOAPElement soapElement = (SOAPElement)soapBodyElement.getChildElements().next();
      String value = soapElement.getValue();
      soapElement.setValue(value + "|UserIn");
   }
   catch (SOAPException e)
   {
      throw  new WebServiceException(e);
   }

   return true;
}
项目:jbossws-cxf    文件:UserHandler.java   
@Override
protected boolean handleOutbound(SOAPMessageContext msgContext)
{
   log.info("handleOutbound");

   try
   {
      SOAPMessage soapMessage = msgContext.getMessage();
      SOAPBody soapBody = soapMessage.getSOAPBody();

      SOAPBodyElement soapBodyElement = (SOAPBodyElement)soapBody.getChildElements().next();
      SOAPElement soapElement = (SOAPElement)soapBodyElement.getChildElements().next();
      String value = soapElement.getValue();
      soapElement.setValue(value + "|UserOut");
   }
   catch (SOAPException e)
   {
      throw  new WebServiceException(e);
   }

   return true;
}