View a Stack Trace from a Salesforce Web Service callout

Recently I came across a rather odd issue regarding a Web Service callout. I had generated apex classes using wsdl2apex (aka the create class from wsdl feature within Salesforce), and attempted to initiate one of the generated callouts from a sandbox. The error message I encountered was

EXCEPTION_THROWN|[103]|System.CalloutException: Web service callout failed: Unexpected element. Parser was expecting element '' but found ':HTML'

The error I expected to see was something along the lines of

The requested URL could not be retrieved, because the host name could not be resolved.

I felt if I could view the stack trace, I could get to the bottom of the issue. I could not figure out how to view the stack trace from the generated code, there was no obvious way to get at it.

From discussion with a coworker, I found out that apparently the only way to view the underlying XML and stack trace of a web service callout is to execute it from a Developer Org. Of course, you can get a limited Developer Org free from Salesforce, so testing it was no issue.

Sure enough, upon copying the code over to my Developer Org and running it, the full stack trace was clear. The actual message displayed was:

CALLOUT_RESPONSE|[103]|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The requested URL could not be retrieved</TITLE>

18:00:57.304|EXCEPTION_THROWN|[103]|System.CalloutException: Web service callout failed: Unexpected element. Parser was expecting element '' but found ':HTML'

Much easier to debug when a stack trace is available.

Conclusion: The underlying XML from a wsdl2java generated callout is only available in a Developer Org. If this oddity if documented, it’s well-hidden. Unfortunately, to view this XML from a production or sandbox org, you must copy the apex classes to a developer org and invoke accordingly.

This entry was tagged , , . Bookmark the permalink.