Real World Java EE Night Hacks--Dissecting the Business Tier Book and Project

The book Real World Java EE Night Hacks--Dissecting the Business Tier is available as softcover (print), Kindle (worldwide) hardware, kindle software reader (Win, Mac, Android, BlackBerry iPhone and iPad) and Adobe Digital Editions eBook (epub)
Real World Java EE Night Hacks dissects a plain vanilla Java EE 6 application "x-ray". It measures the traffic and statistics of this blog and comes with Roller 4 integration - just look at the right area to see it in action. With this post x-ray will the first time measure the popularity of itself :-). Real World Java EE Night Hacks includes coverage of:

  • A brief introduction into the core principles of Java EE 6 (EJB 3.1, CDI, JPA, JTA,Dependency Injection, Convention over Configuration, interceptors, transactions, REST) using real world code
  • Unit and integration testing of Java EE 6 applications using JUnit and ScalaTest
  • Using interceptors for performance measuring and monitoring
  • Creating mocks with Mockito for EJB 3.1, CDI, JPA, and JAX-RS
  • Developing embedded integration tests with Arquillian
  • Productive use of JAX-RS, Contexts and Dependency Injection, EJB 3.1, and JPA
  • RESTful services and REST clients with Java EE 6
  • Convention over Configuration with Java EE 6
  • Effective component configuration with CDI and Convention over Configuration
  • Plug-in implementation with CDI
  • Transactional pub/sub without JMS based on CDI and EJB 3.1
  • Continuous integration with Maven 3, Mercurial/Git, and Hudson/Jenkins
  • Implementing configurable timers and asynchronous batch processing
  • Eventual consistency and high-performance deferred writes with Java EE 6
  • Real-time client and server monitoring with JMX and REST
  • Functional testing with FitNesse
  • Performing stress and load tests
  • Simplest possible, but maintainable, Java EE 6 design and architecture
Special thanks to James Gosling, (nighthacks.com) for the foreword:

"Most books for software developers are horizontal slices through some piece of the technological landscape. "X for Dummies" or "Everything you need to know about X." Breadth and lots of toy examples. This book takes a largely orthogonal approach, taking a vertical slice through a stack of technologies to get something very real done. Adam takes as his organizing principle one real Java EE application that is not a toy, and goes through it, almost line-by-line explaining what it does, and why. In many ways, it feels like John Lions', Lions' classic Commentary on UNIX 6th Edition.

One of the problems that people often have when they start looking at Java is that they get overwhelmed by the vast expanse of facilities available. Most of the APIs have the interesting property that the solution to any task tends to be pretty simple. The complexity is in finding that simple path. Adam's book shows a path to a solution for the problem he was trying to solve. You can treat it as an inspiration to find your own simple path to whatever problem you have at hand, and guidance on how various pieces fit together "
Real World Java EE Night Hacks - Dissecting the Business Tier will benefit experienced developers and architects interested in code, not PowerPoint slides :-).

I will cover the topics in subsequent posts - so the content of the book will become more technical again :-). The source code was pushed into the GIT-repository: http://java.net/projects/x-ray

All samples were tested with Glassfish v3 - v3.1, developed with Netbeans 7 and IntelliJ, built with Maven 3 / Hudson, managed by Mercurial / GIT, unit tested with JUnit / Scala Test, mocked with Mockito, functional tested with fitnesse, and quality-measured with SonarSource.

Comments:

Linked your book at http://java-abwaschbar.blogspot.com/2011/05/new-javaee-book-by-adam-bien-available.html.

Posted by Frederik Mortensen on May 01, 2011 at 01:29 PM CEST #

Congrats...just bought the book.
Really like your style ,very concise on concrete problems,not the bla bla and 700 pages that nobody really reads all...
For reading it on Ubuntu, it was tough...lucky I have a virtual box with xp...Please do something related to this...if i would have known I was rather bought the soft cover version.
Cheers
Cristian

Posted by Cristian on May 01, 2011 at 02:02 PM CEST #

@Cristian,

thanks! I'm not sure, whether I would be able to do something about ubuntu. I'm using lulu's infrastructure - its the only possibility right now.

Glad you like it!

thanks!,

adam

Posted by Adam Bien on May 01, 2011 at 02:24 PM CEST #

@Frederic,

thanks for linking!,

adam

Posted by Adam Bien on May 01, 2011 at 02:24 PM CEST #

bought it and am looking forward to read it :)

Posted by roman on May 01, 2011 at 07:09 PM CEST #

I think i'm going to pick this up...

Adam, just curious, what are you doing for employment besides writing books and speaking? Sounds like you're living the dream

Posted by Jonathan Fisher on May 01, 2011 at 10:45 PM CEST #

Just tried to buy your book, but the "PDF Ebook" is really the adobe reader format, so not viewable as a plain PDF, and locked to the reader on a particular machine.
Sorry that's one sale lost.

Posted by Mike Mormando on May 01, 2011 at 11:33 PM CEST #

I'd like to buy this book, but I need to be sure I'll be able to read it on my iPad. does anybody was able to read this DRMed file on an iPad. thanks.

Posted by Antoine SABOT-DURAND on May 02, 2011 at 12:25 AM CEST #

Answering myself to my comment. The book (epub or pdf) can be read on iPad or iPhone with the free app "Bluefire Reader" : http://itunes.apple.com/app/bluefire-reader/id394275498?mt=8#
Bought the book in ePub and start reading it on my iPad : looks great. Thanks Adam

Posted by Antoine SABOT-DURAND on May 02, 2011 at 01:18 AM CEST #

@Antoine,

thanks! I did exactly the same to try that on iPhone. The free app: http://itunes.apple.com/de/app/bluefire-reader/id394275498?mt=8 works!

Also installed the free Adobe Digital Editions - similar to the Kindle Reader.

AND: the book is also in the queue to be available at the iBookStore,

thanks!,

adam

Posted by Adam Bien on May 02, 2011 at 03:23 AM CEST #

Hi Adam, is lulu.com the only option to by the book?

Posted by Christian on May 02, 2011 at 12:52 PM CEST #

@Christian,

amazon, bookstores, kindle, iBook store should follow soon.

Thanks for your interest!,

adam

Posted by Adam Bien on May 02, 2011 at 03:45 PM CEST #

A bit of topic...
Just a question about your books. Which software do you use to write them (Openoffice, Word, Latex...)?

Posted by Pedro Maria on May 03, 2011 at 12:05 AM CEST #

Adam - Bought the book. Would like to download the source code and view it in my Java IDE (Eclipse).

I'm not familiar with git and don't have git installed.

Is there another way I can get the source code?

Thank You,

Posted by Bruce on May 06, 2011 at 06:43 PM CEST #

@Bruce,

Eclipse?! :-)

http://www.eclipse.org/egit/
http://wiki.eclipse.org/EGit/User_Guide/Remote

works?

thanks for buying!,

adam

Posted by Adam Bien on May 06, 2011 at 06:55 PM CEST #

Hi,

I just bought the book as eBook and discovered afterwards that I need this obscure, unhandy, old-style Adobe DRM software to read it. Impossible to print, to safe locally (afaik), neither it's displayed without clipping errors by the Adobe software.

Obviously, it's my fault since I didn't check the supported formats. Still I'm very disappointed and sorry that the book will not be part of my library. :(

I recommend to not to buy the ebook version, go for the paper version instead.

Best regards,
TC
(This message because you asked for feedback in your thankyou message :) )

Posted by TC on May 08, 2011 at 07:07 PM CEST #

@TC,

I published the first as softcover first and got several requests regarding an eBook. Adobe Digital Editions software doesn't feel natively on Mac (I guess it is an Air application), bluefire reader is a lot better on iPad or iPhone.

The kindle reader (software) is the best. I read already ~50 kindle books on iPhone and Kindle and it rocks.

I also prefer a softcover...:-)

Sorry for that! -> I'm looking forward to your opinion about the content :-).

thanks!

adam

Posted by Adam Bien on May 09, 2011 at 12:35 AM CEST #

Hi Adam,

Congratulations on the book. I haven't gone through the book, so some of my questions may be answered as I go through it.

But I notice in the samples that you are using Arquillian for the EJB integration tests and in particular with embedded glassfish e.g. LoggerProducerIT test. However, the EJB being tested doesn't hit the database and I assume the reason is that Arquillian deployable container doesn't support PersistenceContext (see 12.8 of Arquillian Ref guide). So my question is why use it when most EJBs in practice are going to access some db via the EntityManager.

Also, when I ran the tests (via maven) for x-ray-services, only a single test was executed. Is this correct?

Also, what's with the '~' in x-ray~git, the name of the git project?

Posted by Simon on May 09, 2011 at 06:21 AM CEST #

@Simon,

thanks for buying it!

"However, the EJB being tested doesn't hit the database and I assume the reason is that Arquillian deployable container doesn't support PersistenceContext (see 12.8 of Arquillian Ref guide). So my question is why use it when most EJBs in practice are going to access some db via the EntityManager."

I only used arquillian for 2 killer testing use cases - Configuration and Logger injection. I had to deploy helper classes to make testing easier. I will cover that in subsequent posts.

I mocked out the EM or used a created instance in an integration test for all other use cases. See chapter: "Unit Test Is Not Integration Test".

"Also, when I ran the tests (via maven) for x-ray-services, only a single test was executed. Is this correct?"

This is strange...It works in my case.

"Also, what's with the '~' in x-ray~git, the name of the git project?"

The name of the repo is x-ray. By cloning it the ~git is appended. Similarly to mercurial,

thanks for your feedback!,

adam

Posted by Adam Bien on May 09, 2011 at 02:08 PM CEST #

Hi Adam,

Re EJB Tests: I see now. Thanks. Mocking the EntityManager makes sense and using Scala to write unit tests is a great idea which I will adopt.

I have been torturing myself these last few weeks trying to get my EJB unit/integration tests working. I have been successful with using the embedded glassfish container as per your post [1] and others: [2], [3]. But they are slow and I have to run them in a suite which instantiates a single instance of the EJB container - previously I was starting and stopping the instance per test class. However, now there is the problem of having to truncate the contents of the in memory db and I solved that. Then I moved onto testing authorisation and soon as I added @RolesAllowed annotation I was faced with a whole new branch of problems. I had to add a file realm to my "test" container installation and programmatically login. I followed this approach [4], but with not using Open EJB, and not only did this not work, it also broke my existing tests. And that's when I gave up and concluded that my goal of EJB integration tests was not feasible and I put it on the back burner.

So your book has appeared at a good time.

Re x-ray-services tests: This is what Maven produces:

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.abien.xray.business.useragent.entity.UserAgentTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.065 sec

And I know there are more tests than this...

Cheers,
Simon

[1] http://www.adam-bien.com/roller/abien/entry/embedding_ejb_3_1_container
[2] http://www.blackbit.be/2010/02/17/jpa-unit-testing-with-the-glassfish-3-embedded-ejb-container/
[3] http://ctpjava.blogspot.com/2009/10/unit-testing-ejbs-and-jpa-with.html
[4] http://openejb.apache.org/3.0/testing-security-example.html

Posted by Simon on May 10, 2011 at 06:29 AM CEST #

Hi Simon,

"Mocking the EntityManager makes sense and using Scala to write unit tests is a great idea which I will adopt."

I used Scala for testing just because of "fun" (Night Hacks are Night Hacks :-)). I don't know whether it was a very good idea - the compilation and execution is a lot slower comparing it to a usual Java JUnit 4. For that reason I use in my "commercial" projects JUnit 4 + mockito for unit testing.

thanks!,

adam

Posted by Adam Bien on May 11, 2011 at 12:16 AM CEST #

Hi,

The book looks promising, but I will not buy this stupid Adobe Digital Editions format.
Why not build a PDF version with my name on every page (that's how Pragmatic Programmer, InformIT, and Mannings are doing their protection)?

Posted by Thomas on May 13, 2011 at 04:23 AM CEST #

@Thomas,

I do not like Adobe Digital Editions format either. A PDF with reader's name would be a perfect solution. Unfortunately it isn't supported by lulu.com right now. I will suggest that - then I will offer that channel as well.

I really like kindle hardware and software readers (iPad, iPhone, Android, Mac, PC ...). I read already ~50 books and it works great. Kindle even synchronizes your reading progress across all devices / readers.

Night hacks is also available on kindle (amazon.de, amazon.com, amazon.uk worldwide):

http://www.amazon.com/World-Night-Hacks-Dissecting-Business-ebook/dp/B004Z20A3G/ref=sr_1_1?ie=UTF8&m=A12MGAGPLUJEQK&s=books&qid=1305273994&sr=8-1

...and print: http://www.lulu.com/product/paperback/real-world-java-ee-night-hacks-dissecting-the-business-tier/15591446

thanks and sorry,

adam

Posted by Adam Bien on May 13, 2011 at 01:12 PM CEST #

I've just bought the book and currently reading it...In the HttpRequestRESTInterceptor, I noticed the worstXrayPerformance variable is not protected vs multithreads accesses. Shouldn't you need to add the volatile keyword to it in order to limit the risk of losing updates on it? Enjoy the reading BTW.

Posted by Franck Garcia on May 15, 2011 at 07:04 PM CEST #

@Franck,

an interesting case. The spec says:

"For a servlet not hosted in a distributed environment (the default), the servlet container must use only one instance per servlet declaration. However, for a servlet implementing the SingleThreadModel interface, the servlet container may instantiate multiple instances to handle a heavy request load and serialize requests to a particular instance."

Since we cannot rely on the configuration of the host-servlet, we have to make it volatile. A very good catch. Thanks! I pushed the fix with credits. Check out the repo...

thanks for buying and reading - a review is highly appreciated :-).

adam

Posted by Adam Bien on May 15, 2011 at 11:28 PM CEST #

Hi Adam,
I do think that the content is more important than a fancy layout, especially since you publish it yourself. But still - does it have to look so terrible?
Your book is nice to read regarding the way you write, but it's not nice at all to look at while doing so, especially when trying to read the code parts, which are terribly formatted.
So my suggestion for the next book (which I probably buy as well): Invest at least a little bit of time and effort into a decent layout.
Cheers, Alex

Posted by Alex on May 20, 2011 at 07:19 PM CEST #

@Alex,

and I thought this book was already perfectly formatted :-). Thanks for you opinion regarding the content!

Do you read the ePub or print version?

thanks,

adam

Posted by Adam Bien on May 21, 2011 at 01:27 AM CEST #

@Adam,
I'm reading the print version.
Well, especially the code is hard to read due to the random line breaks - here it would have been better to explicitely format the code for the given number of characters by the page width and check if it's clearly readable.
Alex

Posted by Alex on May 24, 2011 at 05:44 PM CEST #

@Alex,

I already thought about shortening the method/field names to improve formatting, but then you could miss the link between the described code and http://java.net/projects/x-ray

It is a common problem - 16:9 book format would work lot better :-)

thanks for the feedback!,

adam

Posted by Adam Bien on May 25, 2011 at 03:36 PM CEST #

I sorry for asking this small help... but I could not fix it even after half a day (shame)... trying to build the x-ray application through maven x-ray-assembly >mvn clean package keeps giving arquillian dependency error tried all versions but no success please help... it is a new system where I don't have old repositories... help would be appreciated... Thanks... aNash

Posted by Nash Adam on December 15, 2011 at 12:20 PM CET #

Really a nice and useful post for java student..I'm persuing MCA..so its useful for me ..Thank You Very Much

Posted by Programming Pad on January 20, 2013 at 02:19 AM CET #

Hi Adam, will you release soon another book on the topic?

I would like to buy this one, but if in short terms you will come out with a new one I will expect for it!

Posted by Paolo on December 15, 2015 at 05:04 PM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments
License