Adam Bien's Weblog
Hacking Bookstore in a Bookstore ...with Java EE 6 - FREE JUG Session
Already looking forward to the JUG session in Hamburg. This time I will try to implement interactively a bookshop with Java EE 6,
without any wizards, code generations, templates and other unfair stuff :-).
Because JUGs are fun - I will try to show as many Java EE 6 features as possible, and so probably over-engineer
the application a bit. I promised that several times already - but now its time to proof the "lightweightness" of Java EE 6 in the IDE and not only on slides.
I would introduce at least REST, JSF 2, CDI (JSR-330 and JSR-299), JPA, Bean Validation, EJB 3.1, Mocks, Unit Tests probably Maven (depends on the internet connection). Please prepare some heretical questions, or ideas.
See you at the bookstore "Lehmanns", 8 pm. They should also have some of "Real World Java EE Patterns - Rethinking Best Practices" books.
Posted at 12:50AM Aug 30, 2010 by Adam Bien in Real World Java EE Patterns - Rethinking Best Practices | Comments[0]
[my tweets]
Rss My book: Real World Java EE - Rethinking Best Practices
Mail Of The Week: What I Can And Cannot Do With Java EE 6
Got an interesting email with questions regarding Java EE restrictions. Some answers:
>"I have installed Glassfish 3.0.1 and am using NetBeans 6.9.1 for implementing stuff"Congrats - you saved about 5h :-).
- I have a web service running on Glassfish. What can I do now to access an RMI based server? Can I do this:
HelloWorldRMI hdl = (HelloWorldRMI) Naming.lookup("rmi://localhost:2000/HelloWorldRMI");
String helloString = hdl.sayHello("WS");
Yes you can. It works perfectly with all servers I know. This is what I do with greenfire.dev.java.net to access the native driver. - Can I also open a socket from the same web service to another C++ based server?
You can open client sockets, but not server sockets. I did it in the past with JBoss, Glassfish and WLS. The spec is a bit fluffy here. - Can I write something to a file?
It will work on most application servers, but it isn't compliant. It is also problematic regarding consistency and concurrency.
You could write a JCA connector for transactional file access. It is easier, than you may think. I wrote a JCA-File connector in my book Real World Java EE Patterns - Rethinking Best Practices See page 181 - Generic JCA connector. My transactional example is comprised of ...4 classes and one XML file. - Can I create my own classloader and load classes through there?
It will mostly work, but is not compliant."...Allowing the enterprise bean to access information about other classes and to access the classes in a manner that is normally disallowed by the Java programming language could compromise security..." - Can I dynamically create classes like this:
MyClass myClass = (MyClass) Class.forName("...my.MyClass").newInstance();
String returnString = myClass.sayHello(className);
This is perfect - except obtaining EJBs and CDI managed beans that way :-)
Posted at 11:33AM Aug 18, 2010 by Adam Bien in Real World Java EE Patterns - Rethinking Best Practices | Comments[6]
[my tweets]
Rss My book: Real World Java EE - Rethinking Best Practices
What Is The Value Of A Software Architect?
(My) definition of the architect's role: "Software Architect is someone who is able to break down customers (=product owners, sponsors etc.) vision in more or less fine grained software artifacts"
I prefer the term "vision" over requirements, because most of the time requirements happen to be unstable and the customer actually unsure.
An architect should also immediately inform the customer about the impacts of his functional and non-functional requirements. Pro-active consulting in the definition phase about
the consequences of high availability, modularization, distribution, security etc. is crucial and safes real money. The architect should be especially well experienced with possible problems and side-effects.
Posted at 12:57PM Aug 12, 2010 by Adam Bien in Real World Java EE Patterns - Rethinking Best Practices | Comments[7]
[my tweets]
Rss My book: Real World Java EE - Rethinking Best Practices
JUGs, Un-Workshops, No-Slides Sessions, Interactive Hackings ...with Java EE 6 (the lightweight stuff)
- JUG Darmstadt: Stop Talking, Start Hacking "Session" in Darmstadt (24.08.2010)
- Java EE 6 Patterns, or one week Real World Java EE 6 in Hamburg (30.08-03.09.2010) - some places left - will take place
- I promised a talk at the JUG HH in between 30.08.-02.09.2010 - but the JUG guys seems to be on vacations. If you have another ideas for a JUG freestyle session in Hamburg in this period - let me know. In worst case we could occupy StarBucks :-)
- ch-open Workshop:Its Not A Trick - It's Java EE 6. Live - from installation to deployment There were > 24 registrations several weeks back. Looking forward to this one. I will use only few slides and a lot my keyboard. It will be an interactive hacking workshop.
- SIG Java: Java EE 6 from the IDE perspective, 09.09 in Munich
- JBoss OneDayTalk:Lightweight, Lean and Productive with Java EE 6, 01.10.2010 in Munich
- JavaOne in San Francisco, 19.09-23.09.2010: S313248 Creating Lightweight Applications with Nothing but Vanilla Java EE 6, S313250 JavaFX Script: The Java Patterns Killer, S313278 Java EE 6 Panel: What Do We Do Now?, S314243 Hacking Heating Systems with Java EE 6, JavaFX, and Scripting
- End 2 End Java EE 6 in Munich (20.10-22.10.2010) - we will build together a fullstack application. Furthermore I will try to answer as many questions, and solve as many problems as possible. In the last workshops we eliminated several millions lines of J2EE code, just during the breaks :-)
- Workshop: Xtreme Productivity with Java EE 6 in Munich, 04.11-05.11.2010 We will concentrate on productivity and "clean code" with Java EE 6. The aim of the workshop is rethinking of existing patterns and best practices and align them with Java EE 6
Posted at 06:52PM Aug 04, 2010 by Adam Bien in Real World Java EE Patterns - Rethinking Best Practices | Comments[4]
[my tweets]
Rss My book: Real World Java EE - Rethinking Best Practices
Why stateful and local anti-facades are KISS
The Gateway exposes rich and persistent domain objects directly to the presentation logic. Because the domain objects are well encapsulated already - it is rather an advantage, than a shortcoming. Because of simplicity and built-in aspects, an EJB 3.1 happens to be the simplest and leanest candidate for a Gateway implementation.
Why local (to JSF 2, Wicket or a Fat Client)?- Rich domain objects (JPA 2) contain business logic per definition. A call to method can change the state not only of the target entity, but of the whole connected graph. In the local case the EntityManager will correctly recognize the changes and compute deltas (change sets) and persist all changes at the end of the transaction. In remote case you will have to implement the same functionality - what is actually duplication.
- In local case you don't have to care about lazy loading. The entities gets just loaded on demand.
- In complex scenarios the data synchronization between layers becomes a challenge. If you keep you entities managed between requests, there is nothing left to do. You can even bind them directly to the UI - and it will still work.
- For every request you will have to build the domain graph again and again. This is not only complex, but it does not necessarily scale better, than a stateful solution
Before you start prematurely "improving" the scalability and start with bloated applications, it is more reasonable to concentrate on the core business logic and stress test continually the application. In some cases a stateful architecture wont't scale. In this case you will have to provide the synchronization, delta-computation afterwards - with demand documented with stress test results. [See Gateway, page 101 in "Real World Java EE Patterns Rethinking Best Practices" book for more in-depth discussion]
Posted at 12:49PM Aug 02, 2010 by Adam Bien in Real World Java EE Patterns - Rethinking Best Practices | Comments[1]
[my tweets]
Rss My book: Real World Java EE - Rethinking Best Practices
A Day In Paris (JUG) With Java EE 6
Back from JUG Paris. It was almost a conference (~200 attendees). It was my first time in Paris -> I really like the city. Although I was said to got some competition by the football world championships, the room was packed.I predicted France to become the football world champion (I'm a true football expert :-)) - the attendees liked my expertise in this area.
I started with slides and ended in the IDE. What I really enjoyed - was the amount of good questions (from AOP, to SmallTalk). The situation escalated in the breaks, where some attendees asked me several questions at the same time concurrently. These questions were the best. In the last part I build a JUG Management System with CDI, EJB 3, JPA, REST (JSON+XML), a bit security, Servlets and in the last two minutes I introduced JSF 2. Because of time, I started to answer questions in the IDE :-).After the session we spend about 2 hours in restaurant and another 2 hours in a bar - still discussing Java EE, Clustering, Failover, scalability, private / public Clouds Java, even JINI. We discussed 98% Java and 2% private stuff (like the relation of a freelancer to vacations :-)). Paris JUG is really well organized - and all participant seem to have lots of fun. Really enjoyed that. Already looking forward to SophiaConf in Nice. What also interesting - there is a female group of Java Hackers in Paris. This could be the beginning of a female Java Champions division as well.
Posted at 02:20PM Jul 08, 2010 by Adam Bien in Events | Comments[9]
[my tweets]
Rss My book: Real World Java EE - Rethinking Best Practices
Java FX CSS Reference Available
The appearance of UI-Controls in Java FX can be either configured programmatically, or with CSS. See this comprehensive CSS reference. Hopefully it will be distributed with the official SDK doc in the next release...
Its a kind of "Convention Over Configuration" again :-).
Posted at 11:11AM Jun 25, 2010 by Adam Bien in RIA / Java FX | Comments[0]
[my tweets]
Rss My book: Real World Java EE - Rethinking Best Practices
EJB 3.1 + Hessian = (Almost) Perfect Binary Remoting
EJB 3.1 + REST are perfect combo for HTTP and resource style programming. REST is not very well suited for the exposure of already existing interfaces. The RPC-misuse of REST will result in hard to understand and so to maintain code.
With hessian it is very easy to expose existing Java-interfaces with almost no overhead. Hessian is also extremely (better than IIOP and far better than SOAP) fast and scalable. The size of the whole hessian library (hessian-4.0.7.jar) is smaller than 400 kB and so compatible with the "Kilobyte Deployment" style of Java EE 6 programming and deployment.
To expose an existing EJB 3.1 with hessian:
@Stateless
public class CurrentTime {
public long nanos(){
return System.nanoTime();
}
}
You will need an interface:
public interface TimeService {
public long nanos();
}
...and hessian-specific implementation of the endpoint:
public class HessianTimeEndpoint extends HessianServlet implements TimeService{
@EJB
CurrentTime currentTime;
@Override
public long nanos() {
return currentTime.nanos();
}
}
The hessian enpoint is an servlet - so the dependency injection works here without any XML configuration. You can just inject your no-interface EJB 3.1 view bean into the servlet.
The client side is also very lean. You only need a two lines of code to get a reference tot he proxy:
public class HessianTimeEndpointTest {
private TimeService timeService;
@Before
public void initProxy() throws MalformedURLException {
String url = "http://localhost:8080/EJB31AndHessian/TimeService";
HessianProxyFactory factory = new HessianProxyFactory();
this.timeService = (TimeService) factory.create(TimeService.class,url);
assertNotNull(timeService);
}
@Test
public void nanos() {
long nanos = this.timeService.nanos();
assertTrue(nanos>0);
System.out.println("Nanos: " + nanos);
}
}
HessianServlet inherits from GenericServlet and not from HttpServlet. This is a shame, because you will have to use a web.xml deployment descriptor, instead of a single annotation @WebServlet:
<web-app >
<servlet>
<servlet-name>TimeService</servlet-name>
<servlet-class>com.abien.patterns.business.sf.hessian.HessianTimeEndpoint</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TimeService</servlet-name>
<url-pattern>/TimeService</url-pattern>
</servlet-mapping>
</web-app>
You will find the executable project (tested with Netbeans 6.9 and Glassfish v3.0.1) in: http://kenai.com/projects/javaee-patterns/ [project name:
EJB3AndHessian].
The whole WAR (EJB 3, Servlet, web.xml and the hessian "framework") is 393 kB. 385 kB hessian, and 7 kB EJB + Servlet :-)
The initial deployment of the WAR with EJBs took:
INFO: Portable JNDI names for EJB CurrentTime : [java:global/EJB31AndHessian/CurrentTime!com.abien.patterns.business.sf.CurrentTime, java:global/EJB31AndHessian/CurrentTime]
INFO: Loading application EJB31AndHessian at /EJB31AndHessian
INFO: EJB31AndHessian was successfully deployed in 807 milliseconds.
Don't worry: the subsequent deployments are substantially faster :-):
INFO: Portable JNDI names for EJB CurrentTime : [java:global/EJB31AndHessian/CurrentTime!com.abien.patterns.business.sf.CurrentTime, java:global/EJB31AndHessian/CurrentTime]
INFO: Loading application EJB31AndHessian at /EJB31AndHessian
INFO: EJB31AndHessian was successfully deployed in 568 milliseconds.
[See also Service Facade pattern, page 69"Real World Java EE Patterns - Rethinking Best Practices]
Posted at 02:59PM Jun 21, 2010 by Adam Bien in Real World Java EE Patterns - Rethinking Best Practices | Comments[14]
[my tweets]
Rss My book: Real World Java EE - Rethinking Best Practices
A French And Free Java EE 6 Week - Some Slides, More Code
The free Java EE 6 events in the week of 05.07-09.07.2010 will start at July the 6th in Paris. I will give a (hopefully openspace-like / interactive) presentation with the title Lightweight Killer Apps with Nothing But Vanilla Java EE 6.
In the same week I will give a releated presentation Java EE 6 - Leaner Than POJOs in Nice.Java EE 6 is so lightweight - that it may look overly complicated on slides. For that reason I will spend the majority of the time in the IDE. Hope it is o.k.
Thanks for the invitation (and sorry for the rollbacks in the past)! I guess I'm the only speaker with a truly french last name - but without any capability of speaking french :-).
Posted at 02:25PM Jun 14, 2010 by Adam Bien in Events | Comments[7]
[my tweets]
Rss My book: Real World Java EE - Rethinking Best Practices
How Popular Is Actually Java EE 6?
I'm back from the JAX 2010 - one of the biggest european Java conferences. There was lot more interests in Java EE 6, than expected:
- The "Simpler? - Is Impossible - Java EE 6" Workshop was fully booked - with 75 reservations. The actual number of attendees was approx. 100-150. Even the repetition at the very last day was well attended (12-20 attendees I had far more attendees at the end, than at the beginning :-)).
- The "60 Minutes With Java EE 6" talk was also well attended - it took place in one of the biggest rooms (the keynote room).
- We got a table with the topic "Weightless Beans" for the open space part of the conference. Because of the number of attendees, we had expand to the next table near us - and had a lot of fun and nice conversations about Java EE 6 (EJB, CDI, JPA) and the craziest errors in production.
- Java EE 6 trainings are almost sold out. I increased the max-number of attendees to 20.
- We asked the audience after our (Peter Rossbach, a Tomcat-Committer and me) Tomcat + openEJB session, who would be interested in a Tomcat+EJB distribution. More than half attendees were interested.
- Several conference attendees reported me that they are in the process of migration to Java EE 6 ...from Java EE 5
JAX was really nice conference with great food and interesting topics. Already looking forward to W-JAX! Thanks for attending the workshops, sessions - your feedback is highly appreciated.
Posted at 09:23PM May 08, 2010 by Adam Bien in Real World Java EE Patterns - Rethinking Best Practices | Comments[12]
[my tweets]
Rss My book: Real World Java EE - Rethinking Best Practices

