Unable to create envelope from given source because the root element is not named Envelope <p>I have a SOAP request that I've tested in SoapUI. I successfully get the desired response.</p> <p>The problem in my code occurs when I'm testing whether or not the response was successful at <code>if (isSuccessResponse(soapResponse)) {</code> below:</p> <pre><code>public static void main(String[] args) throws Exception { // Establish SOAP connection SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection soapConnection = soapConnectionFactory.createConnection(); // Generate SOAP request SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), namespaceURI); // Test to see if SOAP response is available System.out.print("SOAP Response:"); System.out.println(); soapResponse.writeTo(System.out); // Close connection soapConnection.close(); if (isSuccessResponse(soapResponse)) { System.out.println("Success!"); } else { System.out.println("Fault!"); } } </code></pre> <p><strong>Success?</strong></p> <pre><code>private static boolean isSuccessResponse(SOAPMessage soapResponse) throws Exception { NodeList responseNodes = soapResponse.getSOAPBody().getElementsByTagNameNS("*", "HelpDesk_QueryList_Service"); if (responseNodes.getLength() == 1) return true; else return false; } </code></pre> <p><strong>Request:</strong> This code does in fact print out the correct request as it is identical to the working request in SoapUI. So why can't I get the related relevant information from the actual response? The printed response is the blank default response with all the of requisite headers but none of the desired information from my request:</p> <pre><code>private static SOAPMessage createSOAPRequest() throws Exception { MessageFactory messageFactory = MessageFactory.newInstance(); // Create SOAP Message SOAPMessage soapMessage = messageFactory.createMessage(); // Add request envelope, headers, and nodes from SOAP request SOAPPart soapPart = soapMessage.getSOAPPart(); // I used ? here for privacy reasons String xmlns = "?"; String username = "?"; String password = "?"; String qualification = "'?"; SOAPEnvelope envelope = soapPart.getEnvelope(); envelope.addNamespaceDeclaration("urn", xmlns); SOAPHeader soapHeader = envelope.getHeader(); SOAPElement authInfoElem = soapHeader.addChildElement("AuthenticationInfo", "urn"); createElementAndSetText(authInfoElem, "userName", username); createElementAndSetText(authInfoElem, "password", password); SOAPBody soapBody = envelope.getBody(); SOAPElement bodyElem = soapBody.addChildElement("HelpDesk_QueryList_Service", "urn"); createElementAndSetText(bodyElem, "Qualification", qualification); MimeHeaders headers = soapMessage.getMimeHeaders(); headers.addHeader("SOAPAction", xmlns + "/HelpDesk_QueryList_Service"); // Save request soapMessage.saveChanges(); // Print the request message System.out.print("SOAP Request:"); System.out.println(); soapMessage.writeTo(System.out); System.out.println(); System.out.println(); return soapMessage; } </code></pre> <p><strong>Error:</strong> I get the following error but I'm not sure why.</p> <pre><code>Lis 07, 2016 6:10:34 ODP. com.sun.xml.internal.messaging.saaj.soap.SOAPPartImpl lookForEnvelope SEVERE: SAAJ0514: Unable to create envelope from given source because the root element is not named Envelope Lis 07, 2016 6:10:34 ODP. com.sun.xml.internal.messaging.saaj.soap.EnvelopeFactory createEnvelope SEVERE: SAAJ0511: Unable to create envelope from given source Exception in thread "main" com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to create envelope from given source: at com.sun.xml.internal.messaging.saaj.soap.EnvelopeFactory.createEnvelope(EnvelopeFactory.java:117) at com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPPart1_1Impl.createEnvelopeFromSource(SOAPPart1_1Impl.java:69) at com.sun.xml.internal.messaging.saaj.soap.SOAPPartImpl.getEnvelope(SOAPPartImpl.java:128) at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.getSOAPBody(MessageImpl.java:1351) at com.xxxx.automation.remedy.RemedySOAPService.isSuccessResponse(RemedySOAPService.java:135) at com.xxxx.automation.remedy.RemedySOAPService.main(RemedySOAPService.java:52) Caused by: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to create envelope from given source because the root element is not named "Envelope" at com.sun.xml.internal.messaging.saaj.soap.SOAPPartImpl.lookForEnvelope(SOAPPartImpl.java:154) at com.sun.xml.internal.messaging.saaj.soap.SOAPPartImpl.getEnvelope(SOAPPartImpl.java:121) at com.sun.xml.internal.messaging.saaj.soap.EnvelopeFactory.createEnvelope(EnvelopeFactory.java:110) ... 5 more CAUSE: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to create envelope from given source because the root element is not named "Envelope" at com.sun.xml.internal.messaging.saaj.soap.SOAPPartImpl.lookForEnvelope(SOAPPartImpl.java:154) at com.sun.xml.internal.messaging.saaj.soap.SOAPPartImpl.getEnvelope(SOAPPartImpl.java:121) at com.sun.xml.internal.messaging.saaj.soap.EnvelopeFactory.createEnvelope(EnvelopeFactory.java:110) at com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPPart1_1Impl.createEnvelopeFromSource(SOAPPart1_1Impl.java:69) at com.sun.xml.internal.messaging.saaj.soap.SOAPPartImpl.getEnvelope(SOAPPartImpl.java:128) at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.getSOAPBody(MessageImpl.java:1351) at com.xxxx.automation.remedy.RemedySOAPService.isSuccessResponse(RemedySOAPService.java:135) at com.xxxx.automation.remedy.RemedySOAPService.main(RemedySOAPService.java :52) </code></pre> <p><strong>SOAP Response:</strong></p> <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; &lt;soapenv:Body&gt; &lt;ns0:HelpDesk_QueryList_ServiceResponse xmlns:ns0="urn:XX:XXXX:HPD_IncidentInterface_WS"&gt; &lt;ns0:getListValues&gt; &lt;ns0:Assigned_Group&gt;XXXX&lt;/ns0:Assigned_Group&gt; &lt;ns0:Assigned_Group_Shift_Name/&gt; &lt;ns0:Assigned_Support_Company&gt;XXXX&lt;/ns0:Assigned_Support_Company&gt; &lt;ns0:Assigned_Support_Organization&gt;XXXX&lt;/ns0:Assigned_Support_Organization&gt; &lt;ns0:Assignee/&gt; &lt;ns0:Categorization_Tier_1/&gt; &lt;ns0:Categorization_Tier_2/&gt; &lt;ns0:Categorization_Tier_3/&gt; &lt;ns0:City/&gt; &lt;ns0:Closure_Manufacturer/&gt; &lt;ns0:Closure_Product_Category_Tier1&gt;XXXX&lt;/ns0:Closure_Product_Category_Tier1&gt; &lt;ns0:Closure_Product_Category_Tier2&gt;XXXX&lt;/ns0:Closure_Product_Category_Tier2&gt; &lt;ns0:Closure_Product_Category_Tier3/&gt; &lt;ns0:Closure_Product_Model_Version/&gt; &lt;ns0:Closure_Product_Name/&gt; &lt;ns0:Company&gt;XXXX&lt;/ns0:Company&gt; &lt;ns0:Contact_Company&gt;XXXX&lt;/ns0:Contact_Company&gt; &lt;ns0:Contact_Sensitivity&gt;Standard&lt;/ns0:Contact_Sensitivity&gt; &lt;ns0:Country/&gt; &lt;ns0:Department&gt;XXXX&lt;/ns0:Department&gt; &lt;ns0:Summary&gt;XXXX&lt;/ns0:Summary&gt; &lt;ns0:Notes/&gt; &lt;ns0:First_Name&gt;XXXX&lt;/ns0:First_Name&gt; &lt;ns0:Impact&gt;4-Minor/Localized&lt;/ns0:Impact&gt; &lt;ns0:Incident_Number&gt;XXXX&lt;/ns0:Incident_Number&gt; &lt;ns0:Internet_E-mail&gt;XXXX&lt;/ns0:Internet_E-mail&gt; &lt;ns0:Last_Name&gt;XXXX&lt;/ns0:Last_Name&gt; &lt;ns0:Manufacturer/&gt; &lt;ns0:Organization&gt;XXXX&lt;/ns0:Organization&gt; &lt;ns0:Phone_Number&gt;XXXX&lt;/ns0:Phone_Number&gt; &lt;ns0:Priority&gt;Low&lt;/ns0:Priority&gt; &lt;ns0:Priority_Weight&gt;0&lt;/ns0:Priority_Weight&gt; &lt;ns0:Product_Categorization_Tier_1&gt;XXXX&lt;/ns0:Product_Categorization_Tier_1&gt; &lt;ns0:Product_Categorization_Tier_2&gt;XXXX&lt;/ns0:Product_Categorization_Tier_2&gt; &lt;ns0:Product_Categorization_Tier_3/&gt; &lt;ns0:Product_Model_Version/&gt; &lt;ns0:Product_Name/&gt; &lt;ns0:Region/&gt; &lt;ns0:Reported_Source xsi:nil="true"/&gt; &lt;ns0:Resolution/&gt; &lt;ns0:Resolution_Category/&gt; &lt;ns0:Resolution_Category_Tier_2/&gt; &lt;ns0:Resolution_Category_Tier_3/&gt; &lt;ns0:Service_Type&gt;User Service Restoration&lt;/ns0:Service_Type&gt; &lt;ns0:Site&gt;XXXX&lt;/ns0:Site&gt; &lt;ns0:Site_Group&gt;XXXX&lt;/ns0:Site_Group&gt; &lt;ns0:Status&gt;Cancelled&lt;/ns0:Status&gt; &lt;ns0:Status_Reason xsi:nil="true"/&gt; &lt;ns0:Urgency&gt;4-Low&lt;/ns0:Urgency&gt; &lt;ns0:VIP&gt;No&lt;/ns0:VIP&gt; &lt;ns0:ServiceCI/&gt; &lt;ns0:ServiceCI_ReconID/&gt; &lt;ns0:HPD_CI/&gt; &lt;ns0:HPD_CI_ReconID/&gt; &lt;ns0:HPD_CI_FormName/&gt; &lt;ns0:z1D_CI_FormName/&gt; &lt;ns0:Vendor_Ticket_Number xsi:nil="true"/&gt; &lt;ns0:Corporate_ID&gt;XXXX&lt;/ns0:Corporate_ID&gt; &lt;ns0:Submitter&gt;XXXX&lt;/ns0:Submitter&gt; &lt;ns0:Pending_Date xsi:nil="true"/&gt; &lt;/ns0:getListValues&gt; &lt;/ns0:HelpDesk_QueryList_ServiceResponse&gt; &lt;/soapenv:Body&gt; &lt;/soapenv:Envelope&gt; </code></pre>