Thursday, December 17, 2015

Firefox not using history in Awesome Bar search

I've been using Mozilla Firefox as my development browser of choice for some time now, and recently the latest upgrade to v43.0 was applied. However, after the upgrade completed, I noticed that, when I typed in the first few letters of a website into the awesome bar, e.g. www.goo.. it wasn't retrieving relevant results from my browsing history.

A quick google search later revealed this was not an uncommon experience, even if it hadn't happened to me before. Some suggested solutions included
  • installing the Places Maintenance add on
  • verifying that the places.sqlite file is not read only
  • deleting the places.sqlite file and starting fresh
But none of these worked for me.
On a whim I opened the configuration menu using the about:config advanced settings page and searched for "history", when I noticed that the "places.history.enabled" value was manually set to false. I don't remember making this change since the upgrade completed, and I had not experienced the issue in the previous version of Firefox, so I restored the default value - true - and restarted.

Fortunately, this change had resolved my problem, and I was able to continue my browsing experience as before!

Friday, December 04, 2015

Movember 2015

So, one month, and €105 raised in donations, later Movember is over for another year. This was my fifth time giving my time (and my upper lip!) up for the men's health foundation, and I very nearly didn't do it.
For some reason, there wasn't the same build up of excitement that was in previous years. Certainly there were less members of staff in the office where I work doing it, I'm actually pretty sure I was the only one doing it, whereas before there was upwards of 30 men all growing out their moustaches for charity.
With about a week to go in November, I got a large online donation from a friend. Larger than any other donation I had received until then, including a cash donation I had turned down for being too generous. I messaged them, and said it was too large.
What I didn't know was that their father had been diagnosed with cancer, but after surgery and recovery, was doing much better, and part of the donation was from him. So I'm glad I did Movember this year, and I'll be glad when I do it next year.
Take care of yourself.

Thursday, February 12, 2015

Lenovo Laptop Function Keys Permanently Mapped To Alternative Use

This issue was rendering my lenovo laptop unusable, I couldn't use F5 to refresh in a browser, various applications that had the function keys mapped to functionality (search, replace, etc) were useless. Finally, on a lenovo forum I found the following: https://forums.lenovo.com/t5/11e-Windows-E-and-Edge-series/Persistently-lock-function-keys/td-p/1358503 So the solution is to press the function key + ESC to reset the function keys to standard use. Panic over

Friday, January 02, 2015

I'm not having a drink, thanks

Since I was in college, I've had the habit of giving up alcohol for the month of January. At the time, it was because I had exams at the end of January, and it simply wasn't a good idea to imbibe while studying, especially coming after the Christmas/New Years period which, at the time, involved about 12 days of drinking for me. One particularly heavy year ended with me thinking I had low grade alcohol poisoning.
After finishing college, I kept the habit up, for similar reasons, after a massive amount of drinking over the fortnight, I needed a break from it to clear my system out after returning to work.
During the year, I also quit drinking for Lent. No alcohol, for 40 days and 40 nights. Again, this started in college (third year to be precise) and I kept the habit after graduating.
On more than one occasion I've thought I was drinking too much, and to me, quitting for these periods during the year meant that I was in control, not the bottle/pint glass/shot glass.
Guinness is usually my poison of choice, but I will occasionally have a Heineken. While I do enjoy a glass of whiskey or vodka, it's become rare for me to have one in the last few years, and there were only a handful of occasions when I did so in 2014.
On a normal week, outside of January or Lent, I rarely drink midweek. I drive to work, and there's a checkpoint on my route to work about two or three times a month. While I've never been stopped there (although I have been breathalysed on two other occasions) sod's law dictates that the one time I am stopped and checked will be the one time I have had a drink the night before. On an odd week over the year, I might have a drink on Friday night, but it's usually Saturday that I will go out to the pub, meet friends and drink. I rarely drink to excess, some of my friends will confess to have never seen me drunk, but often right up to my limit.
I convinced myself that this was responsible drinking, I wasn't going to drive the next morning, would have slept, eaten and recovered some way before getting behind the wheel again, and I have no responsibilities to anyone other than myself. For some reason, I rarely drink at home, be that in whatever house I was renting up until I bought my own place last year, the flat I bought, or my parents' house, it's almost always out in public. I never really understood why, but I've no inclination to drink at home.
With all that being said, over the last 18 months or so, there's been a few incidents where I was seriously concerned that the amount I do drink was having an adverse affect on myself. More than one Sunday has been described as a "write off", I've said and done things that I've regretted the next day, or whenever they've come back to me after the fog of liquor has lifted. As I get older, I've still felt rough some Mondays and even Tuesdays after a heavy night on Saturday.
So, as 2015 begins, I've resolved to stop drinking for a while. I'm not quitting, I will have a drink again before the year's end, but when my next drink will happen, I can't tell you. I've been to the Electric Picnic festival in August for the last two years, and I can see myself having a few drinks at that, but between then and now, if you want to buy me a drink, don't.
I'll worry about tomorrow when it comes, but for today, just for today, I'm not having a drink.
Thank you.

Thursday, January 01, 2015

I've been tinderized

So 2104 was the first time I really tried online dating. In no particular order. the following is my experience of dating using the app. The names of the innocent have been omitted
  • gorgeous, but felt like a sister than a romantic partner. Could have been fun but I know it wouldn't have lasted long
  • lot of fun but in the end, just not my type
  • one date, neither of us felt like it would go anywhere afterwards so we left it at that
  • great girl, intelligent, sporty, little withdrawn. I had zero experience with women like this and it showed. she ended it after the second date. Really brought me down, still feel it could have been something
  • loads in common but she ended it because we (and this is a direct quote) "don't challenge each other"
  • longest term girlfriend I've had in a long time, really knocked me back when she ended it and it hit me harder than I'm willing to admit
  • nice girl, easy to talk to but met me the same time I had a few dates with someone else, so she said she was happy to leave it at the one date we had
  • lovely girl, got on well, unfortunately lives about 15,000 miles away so we met while she was home on a short holiday
One thing I've learned is timing can be the most important part of a relationship, especially at the beginning. If both of you are not in the same headspace, romantically, it can all fall apart really easy.
Also, sometimes it's ok to be a bit of a dick, as long as she knows it's not what you're really like!

Remember - eventually you will have your last first date

Things that were true about me on 1st January 2014 that are not true on 31st December 2014

I've never done a reading at a wedding
I don't have a sister in law
I don't own the place I live in
I've never been to a gig at Leopardstown
I've never been to an open air movie screening
I've never been to Glendalough
I've never dated someone I met online
I've never been to a Six Nations game with my father

Wednesday, October 15, 2014

WinAmp on Android whipping my phone's ass

While I've tried a few different music players on the various smartphones I've owned since first buying a HTC Desire HD, I've always returned to WinAmp - a player I've used on various PCs I've owned and used since first year in college.
However, recently it refused to open, and I had to trial other players, none of which I found as good.

Fortunately it seems my plight is not unique, and at least three other users on the winamp forum had the same issue, and it has a simple solution - enable Airplane mode, then open the WinAmp app, and disable lyrics mode, then resume playback!

Thanks Spriz and habumach on the WinAmp forums for this solution - http://forums.winamp.com/showthread.php?p=3009519

Sunday, March 16, 2014

The morning after the championship before

In the aftermath of Ireland's second Six Nations win, my thoughts have turned to the World Cup in 2015. With the retirement of Brian O'Driscoll, the management are faced with the unenviable task of replacing Ireland's greatest ever player, and with a limited amount of games in which to do it before the World Cup kicks off. The forthcoming summer tour to Argentina will be the first opportunity to do so, but after a long season is not the best time to evaluate weary players.
This leaves us with the autumn internationals and the 2015 Six Nations championship to unearth a new thirteen. Is that enough gametime to adequately prepare for a World Cup?

While this season's championship has provided Brian O'Driscoll a far more fitting ending to his international career than the 2013 Lions tour, had he retired then we would already have identified this player, and he would be facing into the World Cup next year with two championships behind him, instead of one.

Although Schmidt's reign is still very much in its infancy, I have noticed one troubling statistic - his team score very few points in the second half of games against stronger opposition. Against Australia, Ireland only troubled the scoreboard with a single penalty after half time, against New Zealand we failed to register a single point in the second 40 minutes. Against England and France, we only scored 10 points after half time in both games, and only two tries. Indeed, the boys in green failed to register a score after the 55th minute in both games, while the opposition ran in 13 and 10 points, respectively.

While Jonathan Sexton finished the championship as top points scorer, the abiding memory of the final game against France was a missed conversion and penalty that, while not having an impact on the final score, brought back memories of the infamous missed penalty against the All Blacks in Aviva stadium in November which would have given Schmidt's side a win against the only team Ireland have yet to register a victory against in test rugby. These misses have again raised questions about his mettle in high pressure situations.

Compare that with England, who have a settled side, a victory over New Zealand in November, beat the Six Nations champions Ireland, and would have won the Grand Slam, were it not for a late try and conversion by the French. For these reasons, along with home advantage, I believe England are going to win the 2015 Rugby World Cup.

Thursday, February 06, 2014

Car theft

You know, if I park my car in an area known for car damage and theft, and leave valuables in the passenger seat (say my mobile phone, CDs/DVDs or a tablet) then I have to accept part of the blame when my car is broken into and my valuables stolen.
When certain choices and actions are widely known to lead to a given conclusion in a large number of circumstances, then the owner of those choices and actions really should give time and effort into rethinking them.
Read into that what you will, I just don't want my car to be broken into.

Monday, January 20, 2014

KDE Dolphin - the process for the mtp protocol died suddenly

Suddenly started getting this error in Dolphin on my kubuntu 13.10 machine when connecting my Samsung Galaxy S3 - "the process for the mtp protocol died suddenly" A quick google gave this result - https://bbs.archlinux.org/viewtopic.php?pid=1242357 - with the same error message, however the solution to disable USB debugging did not work, as it was already disabled. However, disabling developer options completely solved the problem. The only issue now is - what do I do when I'm developing an app and want to deploy it to my phone?

Tuesday, December 31, 2013

Things that were true about me on 1st January 2013 that are not true on 31st December 2013

It's never been claimed that the Lord was speaking through me
I've never seen Bloc Party, Artic Monkey, FatBoy Slim or Vann Music live
I've never been to The George
I've never been to Wembley, or climbed The Monument
I've never tried to buy a house
I've never been to Electric Picnic
I've never done yoga
I've never been live on RTE television
I'm not certified as a MongoDB developer
I've never been to a rugby league game
I've never started a parody social media account
I've never been tackled by a security guard without a reason
I've never shared a taxi with a stranger

Sunday, November 10, 2013

My first rugby league game

I went to the Rugby League World Cup game in Thomond Park, Limerick last night, Ireland lost to Australia 50-0.
It's a professional game in Australia, so their players were bigger, faster, better trained than the Irish, but you'd still expect at least one score from the boys in white*
They did get close the Australia try line a few times, but poor decision making meant it never led to a score. I've only seen bits of games on Sky Sports, never a full match, so I'm unfamiliar with the rules but the way it seemed to go to me is this:
player in possession runs at opposition, up to three players are allowed to tackle him (at least I didn't see more than three players in a tackle) and this involves wrestling him to the ground until...something happens and the ref blows. The player who took the ball into the tackle is allowed to stand up, the tackling players stand off him, and he puts the ball on the ground, stops it with his foot, and rolls it back to a teammate, and play resumes as before.
There's no lineouts, if the ball goes out of play on the sidelines, an opposition player collects the ball, and passes it from the sideline to a teammate, who touches it to his boot (think tap-and-go in rugby union) and then play resumes.
Not sure why scrums are awarded (is it for knock ons?) but a scrum only has six players on each side and appears to be uncontested, although this may have been because of Ireland's amateur status.
A try is 4 points, and a conversion is another point on top of that.
Play is 40 minutes a side, and the team with the most points at the end wins.
Honestly, if it wasn't for the unique attraction of the "World Cup" element to the occasion, I more than likely would not have attended and it's unlikely I'll be at any games in future.

*Australia played in green because they are higher ranked than Ireland, Ireland played in white.

Wednesday, September 25, 2013

SteamOS

Valve's Steam has been the de facto standard for downloadable PC gaming for some time now, and it has long been reported that they intended to move into the console gaming arena, with the "SteamBox" rumoured to be announced at a trade show/convention (E3, PAX, GDC, etc) for the past few years.

The first tentative steps have been made over the last 12 months, with Valve first releasing "big screen mode" to make the transition from PC gaming with a keyboard and mouse to console gaming with a control pad simpler. Following this came the Linux Steam client, and its steadily increasing library of games, although still lagging behind the numbers available on the Windows and Mac clients. The next big announcement came just this past week with the announcement of SteamOS, an Ubuntu-based Steam operating system that will be made available for free to hardware manufacturers, similar to Google providing the Android OS to mobile device manufacturers. However, I don't think this is going to be as big a success as Android (now the dominant mobile OS) in the gaming market.

Firstly, PC gamers are unlikely to spend money on hardware to play the games they already play on their desktop/laptop. Modern laptops can easily be connected to modern TVs with HDMI cables, and I've used a PC to play DVDs on a TV using a graphics card with a TV out port for almost a decade. A similar setup could easily be used for gaming, if you really wanted to use steam on a TV.

Secondly, console gamers are unlikely to be interested in buying another console in the near future. Sony's PlayStation 4 and MicroSoft's XBOX One are launching in November, costing 400 and 500 respectively (according to gamestop.ie). After that initial outlay plus new games, gamers are unlikely to be willing to pay for another box to sit under their TV, no matter what it offers, unless of course it is ridiculously cheap.

 Finally, and what is most important on any console, games. Steam's main rival in the downloadable gaming market is EA's controversial Origin platform. EA are unlikely to make any of their big franchises available on any Steam platform - FIFA, Madden, Modern Warfare, etc - which are among the top selling games on consoles every year. If they are not available, then gamers will simply not buy the platform. There are two more announcements to be made by Valve, the first coming this evening at 6pm GMT, which may change my opinion, but as it is, there's little to be excited about.

Friday, September 13, 2013

How to get the historical FIFA rankings for a country

FIFA, the world's football association have issued a set of international rankings once a month since August 1993 but have not made them available to developers, either through an API or downloadable files (e.g. csv, excel spreadsheet, etc).
However, it is possible to access the rankings for a country in an xml file using Firefox and the Firebug plug in.
First, open fifa.com and click on the relevant association's page, e.g. Scotland: http://www.fifa.com/associations/association=sco/index.html
When the page opens, click the "Rankings" link: http://www.fifa.com/associations/association=sco/ranking/gender=m/index.html
Right click on "Rankings Evolution" and select "Inspect element with Firebug"
The parent element of the div containing the "Rankings Evolution" text box is a div with a class type of "box". Right click on this and select "Copy HTML".
Paste the HTML into a text editor (notepad, gEdit, Kate, etc).
Search for the text "new SWFObject(" (without the quotes) and copy the first parameter, e.g. /flash/maranking/marankbrowser.swf?t1=sco&g=m&a=1&v=2&lang=e&environment=PROD
Add this to http://www.fifa.com to create the URL for the flash object: http://www.fifa.com/flash/maranking/marankbrowser.swf?t1=sco&g=m&a=1&v=2&lang=e&environment=PROD
Open a new tab and activate firebug. Click the Net tab and ensure it is enabled. Note that two requests are sent to the server, flashranking.xml and association=sco.xml. Right click on association=sco.xml and select "Copy Repsonse Body".
Open a text editor and paste in the response body. Each entry is in the format

Wednesday, September 11, 2013

Door closed for Trap

If you had said after the 1-1 draw at home to Cyprus that we would be at a World Cup play off in two years, and qualify for a tournament two years later, you'd have been laughed off the internet. Yet, that's where Trapattoni brought us.
I'm genuinely sorry to see him go, and I fear for the future of the game here with GAA in the ascendancy again, and rugby still drawing massive viewing numbers, but I have to admit it was one qualification tournament too many.

I think in time, his majority of his tenure will be remembered well.

Thanks for the memories Trapattoni, Paris, Poznan, etc,

Thursday, September 05, 2013

A farewell to boots

Since camping at all but the first Witnness events, and attending the Sunday night of the first Oxegen in 2004, it's been the better part of a decade since my last music festival (Slane isn't a festival) and, much like buses, this year I've been to two! The Longitude festival was held in Marley Park, not far from where I live and work, and the Electric Picnic celebrated it's tenth anniversary in Stradbally, Co Laois.
I wore the same work boots I had with me at Punchestown many moons ago, they were given to me as a health and safety requirement in a temporary warehouse job I took a lifetime ago, during a three week break between semesters during my Grad Dip in UL and the only positive from that job. Regrettably I had to retire my musical companions as the sole of the right boot finally conceded defeat on Sunday afternoon when it cracked, and the metal plate between it and the in sole of the boot snapped back, rendering the boot useless. They've served me well these past years, and I hope to replace them with a similar pair as soon as possible.
Among other firsts at the EP was my first yoga class. Waking early on Sunday morning (well, earlier than I had planned) and unable to regain a state of slumber, I walked first around the campsite and then on to the main concert site. Wandering around in the ealry morning, with little of the guests for company and precious few stalls open, I did feel an odd sense of serenity. While passing a tent for some local businesses in Cloughjordan, Co Tipperary, I noticed an sign for a free yoga class starting at 11, seeing as it was 10:40 or so, I resolved to try it out. The instructor began by asking was it anyone's first time, and happily I wasn't alone in making my debut. Of the class of about 30, I'd estimate there were eight others attempting this for the first time. The instructor took us through some basic breathing exercises, and then into some simple movements, before some intermediate poses, including one developed at the EP by her and a partner. While I didn't really get the breathing correct during the class, I found the movements and poses relatively easy to complete. I've been attending the local gym regularly after work and my warmup includes some similar stretches.
While the art, comedy and spoken word attractions were the big differences from the Oxegen and Witnness festivals of old, it's the little changes that struck me the most. Whereas in festivals past, facilities were kept to a minimum, there's been a mass growth in the cottage industry of offerings to festival attendees, offering everything from massages to phone recharging to ATMs (incidentally the only queue longer than the ladies toilets was for the ATMs!). Londis had a pop-up shop at the campsite in Stradbally, and the Irish Time's Ticket supplement was given away for free on each day with reviews of the previous day's events.
Ep has a reputation for being more family-friendly and I did find this the case with many young children in attendance, which did give a more relaxed atmosphere to proceedings. There were many infants as well, with one girl passing us pushing a buggy carrying a child that had not yet seen his first Christmas! One downside of this was that many remained in attendance in the main arean after the sun had passed below the horizon and night had set in. While there's nothing wrong with this in theory, in practise this meant a child could disappear without notice and be left alone in the dark, in a field with more than 30,000 people, (many of whom in were in later stages of intoxication) and with mobile phone coverage at a premium. I can only imagine what this would do to a parent.
What I had noticed at Longitude and moreso at EP was the reappearance of symbols of 60's flower child idealism, girls wearing flowers in their hair, beaded hairbands and CND-branded clothing. What troubled me was the flowers and beads were plastic and mass-manufactured, instead of real and hand woven, and clothes bearing the symbols of peace and tolerance were made and sold by fashion houses with more eyes on the bottom line than anything the icons they stood for. I wondered did these children of children of the cultural decade ,and the pivot of change that followed it, believe in what they wore, or did they just want others to think they did?
I doubt this will be my last festival, or that another nine harvests will be reaped before I attend another, but I cannot imagine myself camping again. While not unable to function without the creature comforts of home, the simple fact is that, in my fourth decade, the recovery time is longer, the stiffness less bearable and the cold night air more penetrating. C'est la vie.

Tuesday, August 27, 2013

Spring Insight on Tomcat failing to start

Spring Insight is a powerful tool to record timing data for web applications deployed on a Spring server, but can also be used on Tomcat.
However, it does require a large amount of configuration before it will run correctly on a Tomcat deployment.
One exception that caused me a large amount of grief was the descriptive java.lang.NullPointerException at java.io.File.(File.java:222) at com.springsource.insight.collection.tcserver.ltw.TomcatWeavingInsightClassLoader.readInsightConfig(TomcatWeavingInsightClassLoader.java:67) at com.springsource.insight.collection.tcserver.ltw.TomcatWeavingInsightClassLoader.start(TomcatWeavingInsightClassLoader.java:50)
  Fortunately the source code for all Spring products is available to download at http://maven.springframework.org/release/com/springsource/ I am using Insight 1.5.1.SR2, and the source for the TomcatWeavingInsightClassLoader class is in the insight-collection project at http://maven.springframework.org/release/com/springsource/insight/insight-collection-tcserver/1.5.1.SR2/insight-collection-tcserver-1.5.1.SR2-sources.jar Examining the class, on line 67 we can see the following File insightDir = new File(System.getProperty("insight.base")); So Insight is looking for the insight root directory in your deployment, which can be set at run time. To resolve the problem, add the system parameter "insight.base" to your tomcat startup with the value of the insight directory in the deployment, e.g. "-Dinsight.base=C:\tomcat\insight"

Monday, August 12, 2013

Persist timing data from Spring Insight

Spring Insight is a powerful tool for tracing time spent in various methods during the progress of a web application call. While you can export traces from the Insight UI, the resultant file is in binary format, and can only be opened with the Insight UI itself. Fortunately, there is a workaround if you want to persist the data recorded during a call.
Insight adds extra headers to the repsonse object from a call - X-TraceId and X-TraceUrl. The traceId is (unsurprisingly) the id of the compelted trace and the trace url is a link to the trace on the Insight server that is in the form "/insight/services/traces/?type=[json|xml] with json as the default.
If you enter this url into your browser, the Insight server will return the data from the call in the selected format.
If you can access the response headers programattically (e.g. in a headerless browser, or using a proxy) you will be able to access the X-TraceId and X-TraceUrl values and from there can request and persist the Insight data.

Wednesday, July 24, 2013

SalesForce.com Authorised Application using Apache HttpComponents

This article describes how to create a basic authorised application that will query the SalesForce.com API without the need for logging in to your account
  1. Register a SalesForce.com remote application
    • Create a SalesForce.com Developer account - http://developer.force.com/
    • On connection to the salesforce.com api, you must provide your password and the security token combined as a string
    • Log into your account and click App Setup(in the menu on the left) -> Create -> Apps
    • Under "Connected Apps", click New
    • Enter the Connected App Name, Connected API Name and Contact Email (note - it's recommended to not use spaces in the App and API names)
    • Under OAuth Settings. select "Enable OAuth Settings"
    • Enter the Callback URL - in an OAuth application this is the URL the application will return to after authentication, which will not be needed here, but the value cannot be blank
    • Select "Access and manage your data (api)" in the "Available OAuth Scopes" and add it to the "Selected OAuth Scopes"
    • Click Save
    • In the application description page that opens, note the Consumer Key, and Consumer Key values (you will need to click "Click to reveal" to see it)
    • In the user dashboard, click Personal Setup -> My Personal Information in the menu on the left, then Reset My Security Token.
    • Your security token will be not be displayed on screen, and will be sent to the email address associated with the salesforce.com account
      • e.g. for password "myPassword" and security token "mySecurityToken" the connection is authorised with the string "myPasswordmySecurityToken"

  2. Develop application in Eclipse
    • Create a new Java project
    • Add the following jar files:
      • From the apache http components project  - http://hc.apache.org/ - you will need the following jar files
        • httpclient
        • httpcore
    • The following code snippet will open a connection to the SalesForce API and return a JSON document
      • Replace the values in angle brackets with the appropriate values from your setup
      • String accessToken = null;
        String instanceUrl = null;
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost("https://login.salesforce.com/services/oauth2/token");
        // prepare the parameters
        ArrayList postParameters = new ArrayList();
        postParameters.add(new BasicNameValuePair("grant_type", "password"));
        postParameters.add(new BasicNameValuePair("client_id", {your application client id}));
        postParameters.add(new BasicNameValuePair("client_secret", {your application client secret}));
        postParameters.add(new BasicNameValuePair("username", {your salesforce.com username}));
        postParameters.add(new BasicNameValuePair("password", {your salesforce.com password + your salesforce.com security token}));
        // prepare the form, and set the encoding
        UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(postParameters);
        urlEncodedFormEntity.setContentEncoding("UTF-8");
        httpPost.setEntity(urlEncodedFormEntity);
        // place the right content type for the form
        httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
        // execute the request to get the tokens
        HttpResponse httpResponse = httpClient.execute(httpPost);
        int statusCode = httpResponse.getStatusLine().getStatusCode();
        if (statusCode == HttpStatus.SC_OK) {
            ObjectMapper objMapper = new ObjectMapper();
            InputStreamReader inputStreamReader = new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8");
            JsonNode rootNode = objMapper.readTree(inputStreamReader);
            accessToken = rootNode.get("access_token").asText();
            instanceUrl = rootNode.get("instance_url").asText();
        }
        System.out.println("AccessToken: " + accessToken);
        System.out.println("instanceUrl: " + instanceUrl);
  3. Query the SalesForce API
    • The instanceUrl is the salesforce.com server that all subsequent queries must be sent to, and the access token must be set as the "Authorization" header in all subsequent requests
    • One of the simplest requests is to retrieve the details for the customer accounts associated with your salesforce.com account, this list can be seen in the Account header on your dashboard
    • Use the following code snippet to request the list of accounts and store the JSON string in the accounts String object
      • URIBuilder uriBuilder = new URIBuilder(instanceUrl + "/services/data/v28.0/query");
        uriBuilder.addParameter("q", "SELECT Name, Id, BillingStreet, BillingCity, Phone, Website from Account LIMIT 100");
        String accounts = null;
        HttpGet httpGet = new HttpGet(uriBuilder.build());
        httpGet.addHeader("Authorization", "OAuth " + accessToken);
        try {
            httpResponse = httpClient.execute(httpGet);
            if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
             InputStreamReader inputStreamReader = new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8");
             accounts = objMapper.readTree(inputStreamReader).toString();
            }
        } finally {
             httpGet.releaseConnection();
         }
        System.out.println(accounts);
While these snippets will work perfectly well in a command line application, in a web application, it is prudent to persist the instance url and access token in the user's HttpSession object.

Thursday, June 20, 2013

Sending a Node.JS request module request through a proxy

all very simple really, just add the "proxy" attribute to the request call
    request({
        proxy: ':',
        url: endpointUrl ,
        method: requestMethod,
        body: requestBody
    }).pipe(res);