Release 0.4: https://github.com/kmcdonald11/Send2SP
This release was all about cookies and Java connection objects. Best part? Completely self taught. I’ll try and go over what I’ve learned as best I can since it’s still new to me – and it’s possible I have the wrong idea.
Part of this bug/enhancement was to connect to a website through the tool for the program, and be able to interact with a server. This is something I’ve touched on before in other languages, and it wasn’t too difficult. Java, on the other hand, was all new to me with it’s connection objects. My experience with Java in the past has been mainly graphical, so switching to something like this was a bit of a challenge.
In order to get as far as I did on this release, I had to piece together a few guides. These were the most useful, from least to greatest:
I’d encourage you to go check out the GitHub link above and head into the “src” folder to see (note that the spacing/alignment that you see in GitHub is super messy – and not something I’d do. Not sure why it shows up like that). In short, you choose the tool option (I named it Send2SP) from the menu. It pops up with a confirmation box, asking if you’d like to send your current code to sketchpad.cc. You accept, and are prompted to enter your login credentials.
Then comes the tricky part. Cookies. I posted a photo of what I’ve got, with some easy to read debug info:
First line, “set cookie,” is run /after/ you’ve requested the headers from Sketchpad’s url, and received the cookie information. That cookie info that’s taken from the url is saved in my code (variable named cookie, how clever). The “set cookie” that you see happens after you take that saved cookie, and pass it back up to the server through the connection object to let it know that we’re still the same person/user. It was a check to see what exactly I was relaying back at the server.
The second line was a sanity check. You’ll notice in the console below, you can see that the webpage I was getting back was telling me I didn’t have cookies enabled. I added in the “get cookie” to run after I sent my own cookie to the server, and wanted to make sure I was sending the same thing as what I expected.
Also, good to note that in Java, the responses from using the connection objects are the actual html page. I printed our my responses to console, and that explains why you see some divs and things down there. It’s webpage that’s being sent back.
Because of this, I didn’t get any further. I don’t understand why it wouldn’t be recognizing my cookies. My only guess is that as I’m originally requesting the header information from the website, a total of 7 different key/value pairs come back. The part that confuses me is that the key for each of those 7 values remains the same “ES”. The values aren’t even all different from each other. Sometimes two cookies are sent back, exact same key/value pairs, and maximum of 3 in a row. One would think that if they all have the same key – it’s really only one cookie.. right? Again, this cookie stuff is completely new to me, so I’m not sure. Having multiple key/value responses all using the same key would lead me to make a logical conclusion that it’s really only one cookie.
Over the past few weeks, I have been in emailing Ari, the man behind Sketchpad, back and forth about this API information. I haven’t been on IRC too often because I don’t see much fit for myself. I’m not sure if this IDE has it’s own IRC chat – but lurking around Processing.js didn’t relate to me at all. My communication has been email based due to the fact that this API information I needed for Sketchpad isn’t anywhere on the web for the public.
While this tool isn’t completed, I’m still really keen on finishing it. I feel like I’ve made that commitment, and I do want to get it done. I want to contribute. I couldn’t just walk away from it now and have this effort be wasted, haha. Over the winter, I’m hoping to have some Java/cookie guidance and help to get this little part figured out. Once I can make that connection work – the rest is easy. It’s all app flow. I was looking forward to reformatting my computer over the winter break, but I’m gonna put it on hold because I really don’t want to try and have to set up that ANT thing again in Eclipse.
I totally forgot to bring this up, but feel it’s important since I spent a good 1-2h trying to solve it. So in my searches of trying to understand connection/cookie stuff in Java, I came across this library: http://hc.apache.org/httpclient-3.x/
I did get it compiling with ANT, and had some test code for it. Problem was that I couldn’t launch Processing’s IDE with the new tool/library. I kept getting some error every time I tried to run the program when it had the tool in it’s compile path. I was able to initialize/call a few things from the library, but once I reached a certain point, it would no longer run with the IDE. If it worked – it would’ve been a huge help because that library looked awesome and had a lot of recommendations.