We have a system that consumes webservice in SAP. Due to the complexity of webservice structure that SF is invoking in SAP, we use the tool wsdl2apex to generate stub classes. Basically, the connectivity is like this:
SF ==> APIgee ==> Siteminder ==> SAP
The system needs a few enhancements particularly in logging. The goal is to have comprehensive log, to easily pinpoint the culprit when failure happens. The main reason why this enhancement conceived is that there were some webservice/network/middleware-related issues and we really had a hard time tracing that.
When we had those issues, the log only says:
Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found ':HTML'
The error message above is same error when we had authentication error, gateway timeout, SAP unavailability, or any siteminder error, which is being relayed to APIgee, the point where SF connects. The errors actually would have different HTTP headers and messages in the body, but I don't know how to get the content/body and headers using wsdl2apex (or WebServiceCallout) approach.
- How do I extract/generate the XML SOAP envelope being sent to webservice from the stub classes generated by wsdl2apex?
- How do I extract/generate the raw data returned by the webservice from the stub classes generated by wsdl2apex?
- How do I get the HTTP headers returned by the webservice from the stub classes generated by wsdl2apex?
NOTE: when the call was a success, outputHttpHeaders_x contains HTTP headers. However, when there's an error, i.e. 400, 401, 404, 40x, outputHttpHeaders_x is not getting populated. Though a SOAPUI simulation clearly shows there were headers returned.
Please don't tell me to use HTTPRequest instead. I am not in the position to revamp the current code, and I don't have the time and budget to do that. Also, we have a very complex webservice and wsdl2apex tools is really handy to generate all the stubs for such complex webservice.