Notes on Mobile
Thanks for nothing…

Well that was a total waste of a morning. Long story short was that I wanted to be able to create documents in a Domino database, but not require a form to do it. Naturally I created an agent that my HTML form could post to. All was going well, but I decided that I also wanted to be able to attach an image as well as some simple form fields. So, after a little more work, my agent reading the ‘multipart/form-data’ with the help of the Apache commons fileupload library. That itself was a bit of a trick since all the examples assume you are using it in a servlet context. There is a way however, to use the agent’s DocumentContext document instead of the HTTPRequest object. All this was working fantastic… only when I started looking at the attachments I created did I discover a huge(!!!) problem. My images were corrupt. At first I though maybe I didn’t have something set right with the Apache code, but alas, after wasting an entire morning, it turns out Domino was to blame. On top of that, it apparently has been a problem for a long time and is still, broken on 8.5.2.

What is happening is that when Domino writes the binary data coming from the HTTP request to the DocumenContext document, it converts the contents to LMBCS and thus totally messes up my binary POST data. There is nothing I can do to get access to the original data, short of writing a actual servlet - which probably won’t work anyway.

ARRGGG!!!!!

Fine. Lesson learned. Domino is not a good HTTP server. Ya I know there are easier ways to do this with forms and file upload controls and what not but that’s not the point though. This stuff should work.

JSON bug….

OK… this project isn’t as easy as it was yesterday…. So in the process of creating the contacts page I found a bug in the JSON output for my view. It really wasn’t easy to find either… 

I started as I normally do by creating the basic page template and JS code that I have done for the past two pages. I ran into a problem when my getJSON call wasn’t returning any results (the success callback wasn’t being called). I took the URL and pasted into a browser and every looked fine. The server was the same, so no cross domain issues. No errors on the server console. ACL was the same as the other database…. what was going on!

Reading though the doc on JQuery.getJSON I found this note:

Important: As of jQuery 1.4, if the JSON file contains a syntax error, the request will usually fail silently. Avoid frequent hand-editing of JSON data for this reason. JSON is a data-interchange format with syntax rules that are stricter than those of JavaScript’s object literal notation. For example, all strings represented in JSON, whether they are properties or values, must be enclosed in double-quotes. For details on the JSON format, see http://json.org/.

Hmmm….. could this be my problem? I went back to the output I got from the browser window and pasted it into a JSON validator and sure enough there was a problem.

Parse error on line 77:
...               "0": "Teamstudio CIAO\! C
-----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['

So it looks as if Domino is trying to escape a the ‘!’ character when it shouldn’t be. This won’t fly with the JSON.parse call that JQuery.getJSON uses.

CRAP!

I have to say, I seem to run into this way too often with Notes and Domino. There are so many useful features that are just not robust enough to use. Even worse is most of the bugs you find are not easily worked around and you never seem to find them until you are a week into a project. It is extremely frustrating!

I have a few alternatives that I can explore so unless anyone has any ideas how to fix this, I think I’m gonna ditch the views and switch to an agent. I think that even though the agent is more work, there are a lot of cool possibilities that it offers that wouldn’t have been possible with just a view. Though, I really did like the simplicity and ease of reuse the views offered…. they just don’t do what they advertise.