Coming Up for Air

Can I Use Dropwizard for This?

I’ve been toying with using DropWizard as my…​ deployment platform for a personal project, but I need/want JAX-RS 2 and CDI, which is a problem for the the stable DW. There is a branch that is migrating to JAX-RS 2 (and Jersey 2.9), and it sort of works, but trying a simple injection is causing a failure I can’t quite figure out:

Caused by: A MultiException has 1 exceptions.  They are:
1. org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at Injectee(requiredType=SayHelloService,parent=HelloWorldResource,qualifiers={}),position=-1,optional=false,self=false,unqualified=null,288169102)

    at org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:74)
    at org.jvnet.hk2.internal.Utilities.justInject(Utilities.java:838)
    at org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:890)
    at org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:880)
    at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:517)
    at org.glassfish.jersey.server.ApplicationHandler.access$500(ApplicationHandler.java:163)
    at org.glassfish.jersey.server.ApplicationHandler$3.run(ApplicationHandler.java:323)
    at org.glassfish.jersey.internal.Errors$2.call(Errors.java:289)
    at org.glassfish.jersey.internal.Errors$2.call(Errors.java:286)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:286)
    at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:320)
    at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:285)
    at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:310)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:170)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:358)
    at javax.servlet.GenericServlet.init(GenericServlet.java:244)
    at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:540)
    ... 36 more
Caused by: org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at Injectee(requiredType=SayHelloService,parent=HelloWorldResource,qualifiers={}),position=-1,optional=false,self=false,unqualified=null,288169102)
    ... 55 more

If I create the Weld runtime and request the beans specifically, I get to good objects (instances of both A and B, with B having an injected instance of A), but once I tell DW to fire things, the app dies:

1
2
3
4
5
6
7
8
9
10
11
12
        Weld weld = new Weld();
        WeldContainer container = weld.initialize();
        container.instance().select(SayHelloService.class).get();
        SayHelloService service = WeldContext.INSTANCE.getBean(SayHelloService.class);
        final HelloWorldResource resource = container.instance().select(HelloWorldResource.class).get();
        resource.setTemplate(configuration.getTemplate());
        resource.setDefaultName(configuration.getDefaultName());

        final TemplateHealthCheck healthCheck
                = new TemplateHealthCheck(configuration.getTemplate());
        environment.healthChecks().register("template", healthCheck);
        environment.jersey().register(resource);

It seems, then, my deployment environment will be, at least for now, a Java EE app server. They’re small enough these days that it really shouldn’t matter. I was just curious to see if DW might be viable for me, and it appears that the answer is "not yet".

I’ll check back later.

LiveJournal Export

I have a personal LiveJournal blog that I’d like to migrate to Awestruct. Unfortunately, LiveJournal’s export tool is really limited, allowing the export of only one month at a time. There are tools to work around that, but the only ones I’ve seen require Windows, which rules me out. In typical geek fashion, then, I wrote my own tool, ljexport, a very quick-and-dirty JavaFX 8 application. All this does is export each month to its own file. Once you have the data, you’re on your own. :)

JavaFX and Maven

I’ve been tinkering with a couple of different JavaFX projects for a while now. Due to other commitments, they’ve been largely ignored recently, but I made some time this weekend to return to them. Since I last looked at them, Java 8, and, thus, JavaFX 8, have been release, so I decided to see how the tooling in NetBeans has changed to stay apace with the development of the libraries. While there are certainly updates, it seems new projects are still built using Ant. Yuck. :P I knew Adam Bien had a Maven archetype for his igniter.fx project, so I took a look to see what that POM does to support JavaFX. As it turns out, it’s pretty simple. For those interested, I have extracted here the basic POM:

14 NetBeans Web Development Tips in 7 Minutes

Recently, Geertjan Wielenga, Principal Product Manager in the Oracle Developer Tools group, posted a video on his blog showing "14 NetBeans Web Development Tips in 7 Minutes", which showed off several nice tips for the IDE (#1 and #5 are my favorites). If you’re like me, sometimes you don’t have (or don’t want to make) time to watch a video, so I thought I’d make a table of contents for the video, with links to relevant portion of it for those that would like to read the list and watch only the parts that interest them.

File Uploads with JAX-RS 2

If you search for how to upload a file to a JAX-RS 2 endpoint, most suggestions will point you to implementation-specific approaches. While that works, it defeats one of the purposes of a spec: portability. There are some posts out there that will point you in the right direction, though. What I’ll do here, then, is present a clear, portable solution to the problem.

Book Review: 50 Android Hacks

Cover50 Android Hacks by Carl Sessa is, as you may have deduced from the title, a collection of 50 tips and tricks to help Android developers of all skill levels handle a variety of problems. For the most part, I found the book very helpful. Before I get to that, I have a minor quibble: I’m not sure "hacks" was the best choice of words. I understand the marketing aspect of it, but when I hear "hack", I think of a piece of code I’m embarrassed to share with someone else, of something I’d prefer to hide. These "hacks" seem anything but. Clean, clear, efficient, something to be proud of. It’s a minor quibble, of course, but there it is. :)

The book itself is pretty easily laid out. If you’ve read a "cookbook", then you should be comfortable and familiar with the basic layout. Each chapter is a different tip, which range from the "easy" (e.g., centering text in a view) to the more advanced (e.g., using the SyncAdapter). The topics covered include layouts, animations, build tools and more.

I read this, appropriately enough, using the Kindle App on my Android tablet, and the experience was very good. I’ve read several programming books on my tablet, and they usually have issues with unreadable source code, large blanks due to content flow issues, etc. Some of this is affected, of course, by the font size and is fixable, but I saw none of those issues here. All of the source, both XML and Java, were neatly formatted and readable, with no odd, jarring line wrap issues. The graphics were crisp and readable, and the pages were neat and clean.

This is a great book, especially for beginning to intermediate Android developers, but I’d wager that there’s something here for just about everyone.

CLI Libraries Compared

I recently ran across a couple of pretty cool libraries for creating command-line tools: Airline from the Airlift project, and crest from Tomitribe. Having spent the last few years working on administration for GlassFish, this is an area near and dear to my heart, so I thought I’d cobble together a quick example using each to see how usable they are.

Integrating Bitbucket and Jenkins

If you’re like me, you have your source code hosted in a hosted environment (such as Bitbucket), but you have a local continuous integration server (such as Jenkins). It would be really nice if you could have Jenkins build your project every time you commit, but without the heavy requirement of polling your repo. In this post, I’ll show you how to integrate the two to do just that.

Android Lifecycles

I’ve been getting a number of bug reports from my app Cub Tracker that had me stumped. I was getting NullPointerExceptions where I shouldn’t be. After some digging, I think I finally found the culprit: device rotation. While rotating the device does, indeed, trigger the error, it goes deeper than that. My problem is that the app doesn’t correctly save the state of the view, which becomes problematic when, for example, the device is rotated. In trying to fix that, I discovered I don’t understand the Android lifecycle as well as I should, so I set out to fix that.

Merry Christmas

As is my custom, I want to thank all of my readers, especially those who have joined the discussion, and wish you all a merry Christmas. In all the hustle of the season, it is my hope and prayer that the joy and peace brought to us in the person of Jesus Christ will be an ever-present blessing in your lives.

Import Maven Artifacts to Ceylon Repos

In trying to come up to speed on Ceylon, I’ve run into some issues with module import dependencies. I’m pretty sure they’re all pilot error, but it was suggested that I import the jars into the Ceylon repository and specify the dependencies between the modules. This would, effectively, be functionally the same as the <dependencies> element in the Maven POM. In classic geek, over-engineer-the-solution fashion, I cobbled together this shell script. It could be more elegant, but it seems to work, and it was much simpler than a Java implementation using the Maven APIs. :)

Ceylon: a First, Quick Take

Last week at Devoxx, Red Hat announced the release of Ceylon 1.0, "a modern, modular, statically typed programming language for the Java and JavaScript virtual machines." A fan of learning languages, I started taking the tour. In no particular order, and without any lengthy rumination, here are my initial thoughts on the language.

Awestruct NetBeans Plugin

Several weeks ago, I posted blurb about a JavaFX project I had cobbled together, DoctorFX. It is an effort to build a semi-graphical editor for Asciidoc, but it is, currently, very basic. I had some spare time last week, so I decided to add some features to it. As I thought about what needed to be added and what that would require, I thought that, perhaps, an architectural change was warranted. With some time and an itch, I pulled out the sledge hammer and out came a NetBeans plugin. This plugin though, does more than Asciidoc: it offers full(-ish) support for the Awestruct framework.

There are a lot of features I’d like to add still, but, currently it supports only basic project loading and editing. It technically has code to preview Asciidoc files, though I’m having issues getting the rendered page from displaying. (In case you want to take a crack at it, that code is here.) I’d also like to add preview support for Slim and Haml, but that may have to wait a bit.

If you’d like to lend a hand to the effort, you can find the current source on Bitbucket.

This is, of course, a bit heavier than DoctorFX, but most of my work with Asciidoc is, currently, in the context of Awestruct, so this fits my needs better, and it was fun dipping my toes into the NetBeans Platform API. :)

Gradle Tip: Better Test Debugging

In a recent post, I showed how to attach a debugger to tests run from the command line via Gradle. While it worked, it turns out that it’s a bit over kill. Try this instead:

1
2
3
4
5
6
7
8
9
$ gradle -Dtest.debug test
:compileJava
:processResources UP-TO-DATE
:classes
:compileTestJava
:processTestResources
:testClasses
:test
Listening for transport dt_socket at address: 5005

Attach your debugger to port 5005, and off you go. No need to modify your build. Kudos to the NetBeans debugger output for helping me find that. ;)

Gradle Tip: Running a Single Test

Using Maven, to run a single test (class), you would issue mvn -Dtest=MyTest. Gradle has similar functionality (gradle -Dtest.single=MyTest), though it seems to be much more powerful. You can get all the details here.

Quotes

Sample quote

Quote source