Play Authenticate No Context

Hopefully this saves someone a little time.  Starting with a working project that had play authenticate fully integrated and  all of its controller methods fixed to work with 2.4.4/2.4.6 injected routes, I deleted everything but the bare metal code to create an entire application template for future projects.  When trying to pull up the home page, I was getting a runtime error from the Application.java controller on construction saying that it could not be injected because there was no http context available.  By removing code from the main page, i quickly determined that the error was coming from the authentication references.  I checked the old application again and everything critical to authentication seemed to be there.  To make a much longer than it should have been story short, the problem was simply that I had not defined an index.html.scala template.  I was using a template named “home” but did not realize that authenticate needed this.  Exactly why would require digging that I don’t care to do, however, in researching the problem, i noticed that in the Global class where I would expect context initialization to happen, the index template was referenced.  So, I added it back with a simple forward to my home page as so

<meta http-equiv=”refresh” content=”0; url=@routes.Application.home” />

and that was all it took.   Anyone interested in this working, starter application please let me know as I will be happy to share it or whatever i’m using for a play starting point at the time.  I am not sure if play authenticate has been updated to be compatible with 2.4.x play yet so this may save  you quite a bit of work.  Hope this helps someone 🙂

Dominion is Over After 2 Seasons

It sucks. Syfy has cancelled Dominion after only 2 season. I was just catching up on season 2 and found this release

Dominion Cancelled

which really sucks.  Well, I don’t usually get upset about stuff like this, however, this was actually a really good show.  Just like I am only noticing this a few months after the news hit, I expect people to realize what they have lost much too late.  This series, loosely based upon the movie Legion (which was really cool itself) was just coming in to its own towards the end of season 2.  That is, incidentally, where I am.  It sucks knowing that this story is over in just a couple more episodes.  For anyone that has not caught this series yet, please check out the 2 seasons that were filmed.  It is worth your time.  It has a great plot dealing with a battle between angels and humans on earth sometime in the future.  Hopefully I am not one of the only people upset about this and syfy will revisit the concept in the future (like firefly the movie) Ugh, just saw they cancelled defiance too.  wtf.  Childhoods end, the 3 part series based on the Arthur C Clarke book is also a winner, but as a 3 part series, is over and can’t be cancelled.  I will really miss this show.

 

Trivago. Bait and Switch??? What the hell is wrong with this company?

In my post earlier today I was criticizing Trivago’s use of fake competitive sites in order to show a price differential in their listings. This is questionable to the point of being strange. Now, I am completely convinced of what type of company this is. About an hour after this last post, I was out on weather.com and of course, since I don’t have it blocked, the ads that pop up on the side are targeted to my most recent cookies. Trivago pays weather.com to fill up the side of my forecast with hotel listings featuring ridiculously low prices. The two I clicked on were like 30$ and 32$ a night. I don’t need a hotel. I just wanted to see what the deal was with a $30 room. I mean, how bad would a place have to be to only charge 30$ a night. Upon clicking on these ads, i am taken right back to the beautifully css’ed trivago site only to find out that both of these hotels are now charging well over 100$ a night. This is not a timing thing. This is not an expired offer. This is Trivago being a really really sucky company. Before, I might, just might have given them a chance when hotel shopping. At this point, I could care less about saving money if it involves dealing with these fucktards.

Trivago and Amoma???

As if the Trivago commercials weren’t annoying enough, I’ve found yet another reason to question this perfectly css’ed sight. Really, I am very impressed by the developers use of client side elements and reactive design. Their marketing though is down right insulting in some cases. For example, they use the old trick of showing a high price, and their price, which is much lower to create urgency in the buyer. “Look! This is such a good deal!” To get the high price they show, without much explanation of how this is picked, they grab a high price from one of the sites that they work with and compare it to the lowest price from amongst their list of partners. Well, apparently there was not enough differentiation in prices between legitimate sites to create the urgency their marketing department wanted. So, what do they do? They create another site, Amoma.com, which also lists hotel deals (claiming to have low prices) but whose deals are often suspiciously above the market rate. Then, whenever they cannot find a legitimate difference in prices when comparing legitimate sites, they always have a high price leader to turn to. The Trivago list is full of entries where a high Amoma.com price is displayed with a line through it directly followed by a reasonable price from a leading hotel room reseller. From what I can tell there is very little difference between the major players in this business. Expedia, Priceline and Travelocity all pretty much have the same rates regardless of whether it is a hotel room, car or flight you are looking for. Why even bother going to another site that has to set up a fake travel site in order to justify it’s existence. Just my 2 cents.

Play Framework JavascriptRouter Connecting to a Java Controller

Just wanted to go over some of the basics of making use of the

javascriptrouter javascript routing capability in the Play Framework

.  I won’t go in to any major detail but instead will give examples of the minimal setup in Play necessary to get this working.  With this functionality, you can access back end data through your Java controller from a page without a page refresh.  While there are several ways of doing this, wrapping things with Play provides a simple, consistent path with powerful implications.

First, add a route for javascript routing to use and a route for the method that will be called in the routes file:


GET /assets/js/routes controllers.Application.jsRoutes()

GET /cities/:id controllers.Application.getCities(id: Long)

In this, I am passing a simple integer parameter to the getCities method in my Application controller.

Now, in your template, add this script to expose this route

<script src="@controllers.routes.Application.jsRoutes()" type="text/javascript"></script>

You will probably want to throw this in to your main template. This is the one that holds your basic page layout, headers, footers, standard menu items etc. This way it will be available in all of the other templates that include the main template.

In your controller, set up a method to handle javascript routes and a method corresponding to the getCities(int) call

public Result getCities(Long id) {
System.out.println("in getCities in the Application controller");
System.out.println("The id passed in is " + Long.toString(id));
return ok();
}


public Result jsRoutes()
{
response().setContentType("text/javascript");
return ok(Routes.javascriptRouter("appRoutes", //appRoutes will be the JS object available in our view
routes.javascript.Application.getCities()));
}

I’m not doing anything here or passing anything back. Once you have this working, it is up to you what you want to return to the call from javascript. This method simply displays the id passed in to show that it is being called.

Finally, in the template you wish to fetch data for, add the code to make your call through the router from javascript. In this example I am simply passing in a parameter of 1 and showing the returned string data in an alert box. In the provided java method, nothing is returned. You will want to do something real in your method and pass back something useful.


appRoutes.controllers.Application.getCities(1).ajax({success : function(data) {alert(data);});

A reworked and more useful example of the controller method here sends back a set of json formated key value pairs.

public Result getCities(Long id) {
Map cities = City.options(id);
Gson gson = new GsonBuilder().create();
String json = gson.toJson(cities);
return ok(json);
}

That’s all there is to it! Now that you have the page talking to the controller, you can do most anything you might normally handle with a submit and page refresh without sending back a whole page. For example, as I may be preparing to in this case, load up a list of cities in a dropdown based on a selected state (onchange event) in another dropdown. The documentation I’ve seen on this is mostly geared towards those writing their controller in Scala too. Play has very good support for Java and will hopefully continue to allow both Java and Scala controllers in the future. It is currently my favorite way of putting Java to use on the web. If the 3.x versions of Play become even more Scalified, that is, the option of writing model and controller code in Java rather than Scala goes away, I will abandon Play and try something else. Basically I am saying, if I have to program everything in Scala, I would just as soon make the move to NodeJS. I am using Play specifically because of the cool way it handles routing web requests to Java code. The Scala you have to use in templating is fairly simple. I’ve even developed a few little Scala tricks I’ve become fond of in my template code. However, I’m not at all interested in developing complex application logic in Scala or javascript for that matter. Scratch the NodeJS comment. I’ll just skip the framework all together and create REST stuff by hand. For now though, the Play framework has been a great addition to my web application strategy. This javascript routing stuff is an example of just how slick it is as a framework for modern web applications.

For more information, check out this article which goes in to a little more detail on javascriptrouters in play with java controller code

 

Donald Trump on Jimmy Kimmel Don’t Be A Loser

I’ve been following the presidential race fairly closely and it looks like we may just get a president that doesn’t suck this time. Check out this poem from the Donald Trump interview on Jimmy Kimmel last night. This is funny as hell.

Winners aren’t losers. They’re winners like me.
A loser’s a loser. Which one will you be?
Winners do deals and winners get rich.
While sad little losers just sit there and bitch.
This lobster’s a loser. Throw him in the pot.
I like a lobster who doesn’t get caught.
Now, here are some frogs I do not like at all.
We must kick these frogs out and then build a wall.
Oh the places you’ll go, on your yacht and your plane.
With your suits from Milan and your wives from Ukraine.
Oh the buildings you’ll build, oh the wealth you’ll amass.
Oh the people around you all kissing your ass.
There are two kinds of people. Which one will you be?
A loser like them, or a winner like me?

Do I think he will be an effective president? Yes I do. We really need this. It is hard to believe I am living in a country that might choose a candidate like Hillary Clinton over someone like Trump. We have to get out there and prevent this. If not for any other reason, do it for the entertainment value.

Trouble With Your BlueTooth Speaker in Ubuntu 14.04 LTS

When I first got my portable bluetooth speaker, the Sony SRS X-5 (pictured on the left) it’s connection to Ubuntu was fairly automatic, as it should be. I would push the bluetooth discover button on the top of the unit, Ubuntu would see it and pair without much trouble. At some point a few months ago, this stopped working as it had. I could still get it to connect but it took a lot of playing around, removing it and adding it back, before I would actually get it working and set up A2D2(high fidelity playback). Not sure what was actually going on but I found out how to fix it. If you are using Ubuntu 14.04 or Mint Linux or similar, simply turning bluetooth on and off and similarly cycling your speaker’s bluetooth will no longer work. What does is the following. First, open a terminal window (ctrl-alt-t) and enter this at the command prompt:

sudo pactl load-module module-bluetooth-discover

Enter your password if prompted. Your linux bluetooth module should now be restarted. Open sound settings, push whatever button you have to on your device to search for a connection, and your bluetooth speaker should now show up in your list of output devices. You will likely have a combo box with a couple of choices of modes. Select “High Fidelity”(A2D2) and test it out. If you are still in telephony mode, or for whatever reason something is not right, you may not see left and right options to test. In this case, click on the bluetooth icon in your menu bar and select devices. If you don’t have a devices option, install the bluetooth device manager. You can find this in the Ubuntu Software Center or apt-get it. If you see you your speaker in the device manager, remove it and then add it back. This should work just fine but will not usually unless you have reloaded the whole module as instructed above. Now you should be able to go back to sound settings and configure your speaker for A2D2 High Fidelity output in stereo. Test it all out and set your volume. You are ready to go! Hope this helps.

On a side note, I would like to mention that I really do love the SRS X-5. The Bose mini, pictured on the right, doesn’t even come close. It is strange to me that they get compared so often. I guess this is because they are in the same price range. In terms of audio performance, the Sony beats the Bose by a wide margin.
srsx5
I am normally critical of Bose bass capability. It sounds, for lack of a better word, “flappy” to me across their entire range of products. I am not sure why this is, and of course I can not argue that their speakers do perform a lot better on average than many of their competitors, however, in this particular case, the Sony is the clear winner. The SRS x-5 is not a bass monster but does handle most music quite well given its size and price. It is important to keep it plugged in as when running on battery, the woofer output is cut in half. It’s bass is more of a mid-bass and it shines in the case of music that is most dependent upon this range and up. If you listen to hip hop or the like and enjoy your music loud, this speaker will not make you happy. Nor should the Bose for that matter, yet many such listeners will probably side with it for name alone. For my tastes, I am very impressed with the x-5’s performance when compared against other sub-200$ bluetooth competitors. While portable, this is not a take anywhere speaker. So, if you are headed to the beach to jam out, you may want to choose something else. For moderate volume, at home listening, or in my case, something to have with you in the hotel room when travelling for work, the Sony does a great job making up for that stereo you miss. I even found it’s audio enhancement mode, a concept I would normally skip with most products, actually does sound good and effectively improve the device’s sound stage. If you don’t already have several of these gadgets, now that you have your Ubuntu bluetooth speaker connectivity issue resolved, I would suggest grabbing one of these. It is well worth the retail, but if you wait a little, you may find it refurbished on Woot! for 80-90$ as I’ve seen it lately.

The Web and the Decline of the Middle Man

At one time, it was pretty standard for a real estate agent to be involved with every sale of real property in the US.  When the market boomed a few years back, more people than ever jumped in to grab their share of this easy money.  You can’t sell your house, building or lot without an agent and when it sells, that agent is entitled to 6-10% of the sale price.  How did this system evolve?  Is selling your property really that complicated as to require a consultant who ends up “earning” 10k, 20k, 50k or more.  How much could this person actually be worth when to become an agent all that is required is reading one little book or taking a short course over a few weekends and then passing a basic competency exam?  Apparently the public has finally given these questions the attention they deserve and the market has changed.  For decades, the real estate business has thrived based on it’s control of information.  While most of the actual complexity of handling a real estate transaction is dealt with by a lawyer, the brokers and agents have maintained their position in this deal by the guarding their information.  In every state, an agency would maintain a book containing property listings, the MLS.  This book was only available to licensed brokers.  Furthermore, rules and regulations were lobbied in to place by this and other agent supported associations to secure their role in property transactions with the argument that they somehow protected the consumer.  While not all of reasons agents and their strict code of ethics were imposed upon this market were bad, the price paid for such services and protection was clearly outlandish.  Now, access to lists of property for sale are easy to come by, thanks to the internet.  So is information on how to manage a real estate transaction.  The real estate industry now finds itself on shaky ground and commissions have fallen drastically.

The same has happened in the car business.  Web sites such as truecar are working to provide consumers with the information they need to make better buying choices.  The car salesman used to play an important role in the typical new or used car purchase.  Now, anyone with the internet can walk in to this type of transaction knowing almost everything needed to make a good choice without the help of a highly paid car consultant.

Quite a few other industries are experiencing similar evolutions.  Almost any job with the title of agent, salesman or broker is either going away or adapting to much higher expectations and lower margins.  Some are going away all together.  When was the last time you called your stock broker?  Personally I think this is great.  Not only am I fond of economic efficiency and perfecting markets, but in times like these, it is becoming critical for the nations economic survival.

In all of this, one would expect the business of staffing, recruitment, job placement to be dwindling to nothing.  Of all of the “agent” style businesses, this is arguably the most questionable in terms of value to the consumer.  How does someone secure an income of 100k, 200k or more simply by running a few searches and making a few calls?  Why has internet availability of information on the job market not totally eradicated this line of work?  Clearly this industry is hanging on some how as year after year tech search firms, staffing firms and the like report 10s of millions in revenue with no end in site.  The current job market is arguably in worse shape than the housing market.  Why does this tax on employment still exist at all?  Are recruiters providing value that other agents and brokers in other industries were not?  Either the answer to this question is yes, or something else, something far less palatable, far less redeeming, far less defendable is happening.