Coming Up for Air

2015

November

  • Kotlin and CDI

    If you’ve been following my blog, you’ve probably noticed that I’ve been spending a lot of time with Kotlin of late. (For the curious, I really like it so far, but I haven’t done just a whole lot with it.) I’ve experimented with writing simple JSF and JAX-RS apps in it, largely to see if I can make it work. With those hurdles cleared, I’m trying something a bit more ambitious: a complete (if basic) Java EE application, written completely in Kotlin. Because I’m a sucker for a bad joke, I’ve dubbed the project KotlinEE. I’m not quite ready to walk through that application yet, but I what I would like to discuss now is an issue I ran into trying to get CDI working with Kotlin.

2014

August

  • 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.

2012

July

  • Writing Pluggable Java EE Applications, The Explanation

    I recently posted the slides and the source code from the presentation I gave at JAXConf San Francisco. While that’s helpful for those who were in my session, it’s probably less so for those who weren’t. What I’ll do in this post, then, is discuss the slides and code in detail, skipping over the introductory slides, and getting right to the heart of the matter.

  • Writing Pluggable Java EE Applications
    jaxlogo

    I just finished giving my session at JAXConf San Francisco 2012, "Writing Plugged-In Java EE Apps". I think it went pretty well, though I guess I’ll find out how it really went when the reviews come in. :) Either way, I had a great time. As promised, here is a tar ball that includes the code we looked at during the session, as well as the accompanying slides. Hopefully I’ll be able to get this code put in a proper public repository (such as java.net or GitHub, or both) soon. For now, feel free to play with the code. Fix bugs. Extend it. Whatever comes to mind. :) If you make changes or use it in something, I’d love to hear about it. Thanks to all who attended!

February

  • CDI @OKCJUG

    I had the opportunity today to present an introduction to CDI at the Oklahoma City Java Users Group. It was a smaller crowd, but they had great questions nonetheless. After a rough start in a workspace that wasn’t quite as clean as it should have been, I think the went fairly well. I had a good time at least. : )

    Thanks to all those that came out and asked questions during and after. If you’d like to play with the code (WARNING: for those of that weren’t there, these examples are 100% creativity free :), you can download the project here.

  • CDI @OKCJUG

    I had the opportunity today to present an introduction to CDI at the Oklahoma City Java Users Group. It was a smaller crowd, but they had great questions nonetheless. After a rough start in a workspace that wasn’t quite as clean as it should have been, I think the went fairly well. I had a good time at least. : )

    Thanks to all those that came out and asked questions during and after. If you’d like to play with the code (WARNING: for those of that weren’t there, these examples are 100% creativity free :), you can download the project here.

My Links

Quotes

Sample quote

Quote source

Publications