function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
atraveratraver 

Premature end of file error when sending outbound message

I have an integration utilizing Salesforce's "Outbound Messaging" functionality. When rule's criteria is met, a message is sent to an endpoint (a Java servlet) configured in my application. This endpoint takes the incoming SOAP request from Salesforce, processes its body and performs the desired action in my application. The HTTP response from my application is a SOAP document with a "notificationsResponse" element. However, as far as Salesforce is concerned, the outbound message workflow is not complete. In the "Outbound Messaging Delivery Status" screen in Salesforce, my message shows up as still being in the queue with a delivery failure reason of "org.xml.sax.SAXParseException: Premature end of file."

 

Looking for information on the outbound messaging functionality, I've come across the outbound messaging document, the outbound messaging WSDL document as well as various blogs talking about similar issues, but I haven't been able to come up with a workable solution. Some questions, then:

 

 

  1. Should my servlet be sending the SOAP document immediately as its HTTP response, or should it send an asynchronous SOAP response (i.e., through an entirely new HTTP request)?
  2. Is the notificationsResponse a red herring? Am I receiving the SAXParseException because of another problem? 
  3. Should I also be sending some kind of response to the original SOAP request to immediately tell Salesforce that I got the request and everything's OK? I've tried two different responses for the doPost() method in my endpoint servlet: (a) a void method, so no response is being sent, and (b) a method that returns a string representing the notificationsResponse object.
Part of me thinks this exception will linger until I sent a new SOAP request from my application to Salesforce with a notificationsResponse object, but it seems kinda weird that it would show up as an exception in the logs until I send that. I'd imagine there's some kind of "Things are OK, you'll be getting a notificationsResponse soon" response I can send, but maybe not? Maybe this exception just lingers until the final notificationsResponse SOAP call is sent to Salesforce?
I feel like I'm just blabbering at this point. Any help would be appreciated!

 

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

you're on the right track. 

(a) what does SUCCESS_RESPONSE look like ?

(b) you almost certainly need to close or at least flush your OutputStreamWriter.

All Answers

SuperfellSuperfell

Your servlet should send a http/soap response (as a response to the inbound http request) as per the schema in the WSDL when you've processed the message. Best place to start is with a wire capture of the request/response from your servlet. (soapscope, wireshark, etc)

atraveratraver

Thanks for the response, Simon. So you're saying I'm doing it correctly by returning my SOAP document as the immediate response from my servlet's doPost() method? For example:

 

 

public void doPost(HttpServletRequest request, HttpServletResponse response) {
  // Take the SOAP request and process it
  // [snip]

  // Send the response, immediately
  response.setContentType("text/xml");
  OutputStreamWriter writer = new OutputStreamWriter(response.getOutputStream());
  writer.write(SUCCESS_RESPONSE);
}

 

Or should I be sending an entirely separate, new SOAP request back to Salesforce with the notificationsResponse object? Because what I pasted into the code area above is what I'm currently doing, and I'm receiving the exception.

 

SuperfellSuperfell

you're on the right track. 

(a) what does SUCCESS_RESPONSE look like ?

(b) you almost certainly need to close or at least flush your OutputStreamWriter.

This was selected as the best answer
atraveratraver

You're probably right about the OutputStreamWriter; I'll try that and see. The value of SUCCESS_RESPONSE is this:

 

 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <notificationsResponse xmlns="http://soap.sforce.com/2005/09/outbound">
      <Ack>true</Ack>
    </notificationsResponse>
  </soapenv:Body>
</soapenv:Envelope>
             

 

 

atraveratraver

You were absolutely right, Simon. I needed to flush my OutputStreamWriter, and the response was successfully sent back to Salesforce. The outbound messaging queue is once again empty!