6

Good morning. I've been beating my head against this for the past 24 hours.

The following three links are:

  1. RestClient class - https://gist.github.com/2a2dd1e1b227dac24e80
  2. RestClient Testclass - https://gist.github.com/ad45ab59ac1f9f1a251f
  3. HttpCalloutMock provider - https://gist.github.com/b71ef196ebd2114e6d4e

In any given dev org (that I've tried), and in the sandbox org these tests run without error, and demonstrate 100% test coverage of the test class. (whether thats a good thing is not at play here please). However, if I try to push this code to production I receive the following errors:

enter image description here

Furthermore, this is all the debug log information I can find. Nothing shows in the dev console, nothing shows in the debug logs. If I deploy via a change set I get marginally more information -- in that I get line numbers on which the errors occur.

enter image description here

Interesting, to me at least, is that the errors all seem to occur on HTTP Success codes (200) statuses.

I have seen the very similar seeming issue here: https://stackoverflow.com/questions/14833509/exception-when-deploying-a-httpcalloutmock

but there does not seem to be clear indications on when/what or if that issue was overcome. Additionally, I have retraced my code, and verified that, for instance the failure on line 51 does indeed invoke the get convenience method, which invokes the full constructor, which creates a request, and finally invokes the .send() method.

I am at a complete loss here, and any help would be greatly appreciated. Even if it's just to hit me upside the head and tell me where to look to see more detailed logs...

Update I have narrowed this down pretty specifically.

If you attempt to push a test that utilizes the above linked HttpCalloutMock Provider with a return code of 200, and a body, that test will fail. Specifically, the body will not be returned from the mock object to the rest class and hence to the test. Either not returning a body (and why would you want to do that on a success test?) or changing the response code allow this to run.

Do any of my fellow force.com Apex nerds (represent!) see anything wrong with that HttpCalloutMock class? I'm hours away from offering an SE bounty -- but I will start the beer @ df (for appropriately aged peeps) bounty right now.

3 pints.

And yes, I have a case open with SF. I am starting to get that sick-to-your-stomach-guess-who's-got-two-thumbs-and-found-a-platform-bug feeling.

7
  • 1
    What releases are your sandboxes and your production orgs on? Spring '13 or Summer '13?
    – Mark Pond
    May 21 '13 at 17:46
  • both spring 13.
    – Kevin P
    May 21 '13 at 21:34
  • 1
    I have specifically narrowed this down to the Mock provider class, the response code 200, and a production setting. It is as if the production system will not properly set the body of a response with the response code 200. Platform bug?
    – Kevin P
    May 21 '13 at 21:35
  • Do you have a support case opened for this yet? I think it may be your best bet at finding the solution.
    – Mark Pond
    May 22 '13 at 6:15
  • Of course. No joy yet.
    – Kevin P
    May 22 '13 at 18:36
2

Try removing the exception handler in the RestClient constructor. I suspect that you're getting an exception there, and as a result this.responseBody is left as null. It will be easier to debug that exception than the NullPointer.

I'm thinking that web callouts aren't allowed in constructors, or maybe just certain constructors (like a controller for a Visualforce page), but I could be wrong. You may need to rework your class so the constructor just sets everything up, and then a method call (like get() or post()) does the actual work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.