Skip to main content

Posts

Showing posts from 2011

Creating Calendar Based Timers in Java EE 6

Java EE 6 allows developers to create application timers that are initialized when either a Stateless Session Bean, a Singleton Bean or a Message Driven Bean are deployed to the application server. To indicate that a method on any of these beans is to be invoked on a timed basis, the method must be annotated with either the @Schedule annotation (for single timer schedules), or the @Schedules annotation (for multiple timer schedules). The code below shows a very simple Stateless Session Bean configured with 2 scheduled timers.  The first timer is configured with one schedule whereas the second is configured with 2 schedules. package com.acme.timer; import javax.ejb.Schedule; import javax.ejb.Schedules; import javax.ejb.Stateless; import javax.ejb.Timer; @Stateless public class CalendarTimer { @SuppressWarnings("unused") @Schedule(second = "*/10", minute = "*", hour = "8-17", dayOfWeek = "Mon-Fri", dayOfMonth = "*...

Using GlassFish from Eclipse

When I think of developing apps using GlassFish, I usually think of using NetBeans for the development. As you'd expect however, Oracle provides some good tooling to allow you to develop against GlassFish from within Eclipse - even to the point of installing the application server directly from within Eclipse.  So, how is this done? Installing GlassFish Server Tools Contrary to what you'd expect, to install GlassFish tooling, you don't use the Eclipse Marketplace for installation.  To install, right click within the "Servers" pane and select "New | Server" to display the "Define a New Server" dialog. On this dialog, select "Download additional server adaptors" and in the resulting dialog select "Oracle GlassFish Server Tools". After accepting the licence conditions, the GlassFish Server tools will be downloaded upon which you'll need to restart Eclipse to complete the installation. Defining a GlassFish Instanc...

Eclipse - 'Building workspace' has encountered a problem

I've got a web project that uses some 3rd party JavaScript libraries.  Unfortunately whenever Eclipse (Indigo) builds the project, it gives an error "'Building workspace' has encountered a problem". The details of the error read: Errors occurred during the build. Errors running builder 'JavaScript Validator' on project 'project'. java.lang.NullPointerException On first inspection, it looks as though the solution would be to edit the JavaScript validator preferences and make it a bit less verbose.  Unfortunately though, there doesn't seem to be any options in Eclipse to do this. One solution though appears to be to edit the project Builders (Right click on Project, select "Properties" | "Builders") and un-tick the JavaScript Validator option. When you do this, Eclipse complains that this is an advanced operation and may cause side effects, so it doesn't feel like the correct way to progress to me.  Having...

Apache Tomcat 7.0.21 Released

Apache Tomcat 7.0.21 has been released and is available for immediate download from  http://tomcat.apache.org/download-70.cgi Mark Thomas notes on the Tomcat Users list: " Apache Tomcat 7.0.21 includes security fixes, bug fixes and new features compared to version 7.0.20 including: - A fix for CVE-2011-3190 that allowed an attacker to inject requests when Tomcat was configured behind a reverse proxy using the AJP protocol. - Multiple additions and improvements to the memory leak detection/prevention features. - Improved validation of received AJP messages. Please refer to the change log for the complete list of changes: http://tomcat.apache.org/tomcat-7.0-doc/changelog.html "

Tomcat Security Issue - Authentication Bypass and Information Disclosure

A new security issue has been reported in Apache Tomcat versions 7 through 7.0.20, 6 through 6.0.33 and 5.5.0 through 5.5.33. According to the Tomcat mailing lists: "Apache Tomcat supports the AJP protocol which is used with reverse proxies to pass requests and associated data about the request from the reverse proxy to Tomcat. The AJP protocol is designed so that when a request includes a request body, an unsolicited AJP message is sent to Tomcat that includes the first part (or possibly all) of the request body. In certain circumstances, Tomcat did not process this message as a request body but as a new request. This permitted an attacker to have full control over the AJP message which allowed an attacker to (amongst other things): - insert the name of an authenticated user - insert any client IP address (potentially bypassing any client IP address filtering) - trigger the mixing of responses between users The following AJP connector implementations are not affected: org.apache....

PrimeFaces 3.0.M3 Released

Prime Technology has announced the latest milestone release of PrimeFaces .  PrimeFaces 3.0.M3 is the final milestone release with the release candiate scheduled for release in November 2011. PrimeFaces is a JSF 2 component suite featuring over 100 JSF components such as calendars, CAPTCHA, and Google Maps components.  A full showcase of components can be viewed online here . This latest milestone release adds several new components to the suite (timeline, feed reader, sheet and subtable) as well as including many other improvements.  The complete list of changes can be read in the release announcement . For more details about PrimeFaces, check out primefaces.org

Deploying a Java EE Web Application to OpenShift Express

We've just posted a new article on how to Deploy a Java EE Web Application to Open Shift Express using JBoss AS 7.  You can read the entire article here . According to jboss.org: "Express offers the fastest on-ramp to the cloud. Simply install the command-line tools, create your application and deploy to the cloud with Git. It's that easy! Express is a service that leverages a shared-hosting model with SELinux to ensure security at multiple levels."

Two New JBoss Releases - 7.0.1 and 6.1.0

The JBoss team have just released 2 new versions of the JBoss Application Server. JBoss 7.0.1, RedHat's latest Java EE 6 Web Profile certified application server includes nearly 140 resolved issues over the initial release of the product. The list of resolved issues in 7.0.1 can be found here . JBoss 6.1.0, includes almost 100 resolved issues over the initial release.  The list of resolved issues in JBoss AS 6.1.0 can be found here . Both products can be downloaded from the JBoss Community Downloads page . JBoss AS 7 is described by RedHat as " Lightning Fast " providing " efficient development as a result of fast, concurrent deployment and the ability to edit static resources without redeployment in a flexible deployment structure ".  Have you used JBoss AS 7?  What are your thoughts about it?  Log on now and leave your comments.

Apache Tomcat 7.0.20 Released

The latest release of Apache Tomcat, v7.0.20 has been released and is available for immediate download. In the release notification, Mark Thomas notes: " Apache Tomcat 7.0.20 includes bug fixes and the following new features and fixes compared to version 7.0.19: JSP files with dependencies in JARs are no longer recompiled on every access thereby improving performance. Update to version 1.1.22 of the native component of the AJP and HTTP APR/native connectors. Update to Commons Daemon 1.0.7. Converted unit tests to JUnit 4. Please refer to the change log for the complete list of changes: http://tomcat.apache.org/tomcat-7.0-doc/changelog.html Note that this version has 4 zip binaries: a generic one and three bundled with Tomcat native binaries for Windows operating systems running on different CPU architectures."

Tomcat 5.5 End of Life

The Tomcat team has announced that as of 30th September 2012 Tomcat 5.5 will be unsupported. Mark Thomas states in the Tomcat mailing lists: " This means that after 30 September 2012: - releases from the 5.5.x branch are highly unlikely - bugs affecting only the 5.5.x branch will not be addressed - security vulnerability reports will not be checked against the 5.5.x branch Three months later (i.e. after 31 December 2012) - the 5.5.x download pages will be removed - the latest 5.5.x release will be removed from the mirror system - the 5.5.x branch in svn will move from /tomcat/tc5.5.x to /tomcat/archive/tc5.5.x - the links to the 5.5.x documentation will be removed from  tomcat.apache.org - The bugzilla project for 5.5.x will be made read-only Note that all 5.5.x releases will always be available from the archive. "

Review of EJB 3.1 Cookbook by Richard M. Reese

I've just posted my review of "EJB 3.1 Cookbook" over on Develop In Java . In summary: EJB 3.1 Cookbook is an excellent resource in an EJB developer’s library. It’s not the sort of book you pick up and read from cover to cover rather a useful resource that you pick up when you think “How do I do xxx in EJB?”. With over 100 recipes this book is recommended to developers using EJB technologies. I very much liked this book and can imagine using it frequently. You can read the whole review here .

Java SE 7 Released

Oracle have today announced the immediate release of Java SE 7.  The release is on schedule as detailed on java.net . Java 7 can be downloaded from Oracle's Java site  with the JDK 7 release notes being available here . NetBeans 7 provides support for JDK 7's new features whilst, Eclipse 3.7.1 (expected in September) will add support to the Eclipse ecosystem.

JBoss AS7 Is Released

JBoss AS7 has today been released just over 6 months after the first Alpha release was made in November last year.  AS7 provides a fully Java EE 6 Web Profile certified application server. AS7 sports a vastly decreased boot time with RedHat stating a 10-fold reduction in startup time over previous versions, bringing AS7 in line with Tomcat startup times. In addition to performance increases provides with AS7, user management has also been carefully considered whilst developing the update. "Consistent and powerful management is available out of the box, including a polished, user-friendly web console, Java and HTTP APIs and a command line tool (CLI). The web console provides a clear perspective into the server runtime, while the programmatic APIs can be leveraged by tools, scripts and geeks." Full details of AS7 can be found here and AS7 can be downloaded from the Community Downloads page .

Forthcoming Book Reviews

Packt Publishing have recently released two new books of interest to Java EE developers. EJB 3.1 Cookbook and Java EE6 With NetBeans 7 both look like good reads and Packt have graciously agreed to send me a copy of each of these books for review, which I'll post on the site as soon as I've reviewed them. Thanks to Nicole for sorting this out for me.

Eclipse Indigo Released

The Eclipse Foundation has announced the immediate availability of Eclipse Indigo - Eclipse 3.7. This release follows the Eclipse tradition of the annual Eclipse Release train. This year, the key new features for the release include: EGit 1.0 release provides first-class support for Java developers using Git for source code management WindowBuilder, a world-class Eclipse-based GUI builder, is now available as an Eclipse open source project Automated functional GUI testing for Java and HTML applications is included via Jubula m2eclipse brings tight integration with Maven and the Eclipse workspace, enabling developers to work with Maven projects directly from Eclipse Mylyn 3.6 supports Hudson build monitoring directly from the Eclipse workspace Eclipse Marketplace Client now supports drag and drop installation of Eclipse-based solutions directly into Eclipse making it significantly easier to install new solutions. Several different versions of Eclipse are available including...

JBoss AS Server Configurations (all, minimal, etc.)

JBoss 5 is supplied with 5 different server configurations: minimal default all standard web When JBoss AS is started, the server configuration can be specified using the -cswitch, so for example, to start the minimal configuration, you would start JBoss as: run.bat -c minimal But what do the different configurations include? Each configuration contains a different set of services, for example clustering, which is only supported by the all configuration. The JBoss Installation and Getting Started Guide contains details of what is in each different server configuration.

VMware Introduces vFabric 5, an Integrated Application Platform for Virtual and Cloud Environments

VMWare has announced the release of VMWare vFabric Cloud Application Platform. vFabric reportedly allows developers to build cloud applications up to 50% faster with Spring that can be run on premise or in the cloud. Develop virtual and cloud applications up to 50% faster using the Spring framework and deploy them to a runtime environment that is optimized for Spring, ideally suited for virtual infrastructures and appropriate for the needs of modern applications, with the VMware vFabric Cloud Application Platform. With support for web-oriented, data-intensive and dynamic applications, vFabric is the best platform to build, run and scale modern applications on-premise or in the public cloud. Full information about vFabric can be found on VMWare's site and in the product datasheet .

How to improve your JPA Performance

James Sutherland has published a blog post  showing how to significantly increase JPA performance. In the post, he provides 11 different optimizations, such as pagination and query caching that can be applied to JPA.  The EclipseLink JPA 3.2 implementation of JPA is used throughout the post. This is a good article and well worth reading by anyone that develops database systems using JPA.

Spring 3.1.0 M2 Released

The second milestone release of Spring 3.1 has been released. The software can be obtrained from SpringSource's Maven repository (  http://maven.springframework.org/milestone ) or from the SpringSource community download page . New features in this release include: Code equivalents for Spring's XML namespaces Builder-style APIs for code-based Hibernate configuration TestContext framework support for @Configuration classes and bean definition profiles Support for injection against non-standard JavaBeans setters Support for Servlet 3 code-based configuration of Servlet container Support for Servlet 3 MultipartResolver JPA EntityManagerFactory bootstrapping without persistence.xml New HandlerMethod-based Support Classes For Annotated Controller Processing Consumes and Produces @RequestMapping Conditions Working With URI Template Variables In Controller Methods Validation For @RequestBody Method Arguments

Apache Tomcat 7.0.14 released

From the Tomcat announce list: The Apache Tomcat team announces the immediate availability of Apache Tomcat 7.0.14  Apache Tomcat 7.0.14 includes bug fixes and the following new features compared to version 7.0.12:  new StuckThreadDetectionValve to identify long running requests JAAS authentication support for the JMXRemoteLifecycleListener updated MIME type mappings to align with those of Apache httpd Please refer to the change log for the list of changes:  http://tomcat.apache.org/tomcat-7.0-doc/changelog.html  Note that this version has 4 zip binaries: a generic one and three bundled with Tomcat native binaries for Windows operating systems running on different CPU architectures.  Downloads : http://tomcat.apache.org/download-70.cgi  Migration guide from Apache Tomcat 5.5.x and 6.0.x : http://tomcat.apache.org/migration.html

Basic Java CRUD Operations with MongoDB

In this post I’d like to show how to perform basic CRUD operations against a MongoDB database using the Java driver. For this post, lets assume that we have a todo database with a collection of todo items. Each item has a task and a priority. In terms of JSON notation, an example item would look like: { "_id" : { "$oid" : "4bffb75121eec88a67ff6ec8"} , "task" : "Write Code" , "priority" : "high" } Now that we have defined what we are storing in the database, lets have a look at how we connect to Mongo. Connection to the database To connect to a MongoDB database, we would use code similar to that below. In this code you can see that we are connecting to a database called todo and getting the collection called items. In MongoDB if neither of these items exist, they will be automatically created. Mongo mongo = new Mongo(); DB db = mongo.getDB("todo"); DBCollection items = db.getColl...

Spring Framework Tooling Upgraded

SpringSource, the people behind the Spring Framework, have today released an upgrade to the SpringSource Tool Suite. Version 2.6.1 of SpringSource Tool Suite provides support for vFabric tcServer 2.5.  vFabric tcServer is described as " an enterprise version of Apache Tomcat, the widely adopted application server. Optimized for Java Spring users, with a lightweight footprint, vFabric tc Server is ideally suited for usage in modern virtual environments. " Full release notes for STS can be downloaded from here . STS can be upgraded from within the toolsuite itself if you have a previous version, or downloaded from SpringSource.com .  vFabric tcServer developer edition can be downloaded from VMWare .

Spring 3.1.M1 @Cacheable Doesn’t Evict – A Workaround

Spring 3.1 introduces a new feature to allow methods to be cached and evicted thus allowing resource heavy methods to be avoided where possible. Caching is enabled via the new @Cacheable and @CacheEvict annotations. For full details of Spring caching have a look at Costin Leau’s blog post . One example of caching would be, for example, database activity. We can apply the @Cacheable annotation to a find operation and then apply the @CacheEvict to an update / delete operation. In this sense, caching would work much like a second level cache in Hibernate or JPA. To enable caching on a find method, the method needs to be annotated with the @Cacheable annotation identifying which cache to use. Spring allows multiple caches to be defined each of which can be backed by a different caching abstraction. @Cacheable("items") public Item find(long itemId) { Item item = entityManager.find(Item.class, itemId); return item; } When it is time to invoke the find method, S...

Single Spring Application Deployment for both Local and CloudFoundry.com Servers

In my previous post I showed how it’s possible, using Spring 3.0, to deploy a database application to CloudFoundry.com and what changes are needed for a CloudFoundry.com datasource.  In this post, I’m going to show how a Spring 3.1 application can be configured at runtime to use either a local MySQL database or a CloudFoundry.com MySQL database thus allowing a single deployable Spring application to be deployed either locally or on CloudFoundry.com. Deploying a Spring application to CloudFoundry.com does not mandate the use of Spring 3.1, however Spring 3.1 makes the process much easier due to the new profile features. So, first off, we must upgrade to Spring 3.1 Upgrading to Spring 3.1 To upgrade a Spring STS application to use Spring 3.1 is an easy procedure. In the project’s pom.xml file, we first need to change the version number of Spring to 3.1.0.M1. I say it’s easy with a STS application as everything else (for example, Spring’s Milestone Maven repository) is already p...

NetBeans 7.0 Released

After nearly 6 months of beta testing, NetBeans 7.0 has been released and is now available for download from the NetBeans site. As usual, the Java SE, Java EE, C/C++ and PHP packages are available for download together with a package that contains all NetBeans modules. Additional functionality can be added to any of the base packages using the buildin Plugin Manager. NetBeans 7 provides many new features including: Language support for Java SE 7 new features (JSR 344) available with the JDK 7 developer preview. Enhanced integration with WebLogic, GlassFish and Oracle database. Enhanced support for Swing GUI development Maven 3 support HTML 5 editing support. To support NetBeans 7, a new plugin portal has also been released. The NetBeans team describe the new portal as using: " modern web technologies ; features powerful searching capabilities and improved performance ; provides an optimized user interface ; and has resolved many design drawbacks of its predecessor....

Deploying Spring Database Apps to CloudFoundry.com

Deploying Spring applications to CloudFoundry.com really is as easy as SpringSource say it is. After being approved for a Cloud Foundry beta account, the first stage is to install Cloud Foundry support into STS or Eclipse. Christian Dupuis has an excellent blog post on how to achieve this, so I won't re-iterate what he has already said. To deploy and run an application using a datasource, MySQL in my case, requires a bit more effort than deploying a standalone application, but literally very little. To deploy an application with a datasource, you must first declare which datasource to use.  In Eclipse, open up the Cloud Foundry server and press the "Add" button on the services pane. On the following screen, select a name and type for the datasource. Press the "Finish" button and the datasource is registered. After registering a datasource, you need to tell the application which datasource to use.  This is as straightforward as draggin...

Converting a Spring SimpleFormController into an @Controller

In my previous post , I showed how to convert a Spring web controller class to use the @Controller annotation. In this post, I aim to show how forms in a Spring MVC application can also be converted to using annotations. Forms in Spring are typically modelled by extending the org.springframework.web.servlet.mvc.SimpleFormController class, but using Spring annotations, they can also be simplified and defined by the @Controller annotation. Without annotations, a SimpleFormController would be defined as below as in both a Java class and as a bean in XML. import org.springframework.web.servlet.mvc.SimpleFormController   public class PriceIncreaseFormController extends SimpleFormController {       public ModelAndView onSubmit(Object command) {         // Submit the form     }           protected Object formBackingObject(HttpServletRequest request)         throws ServletException { ...

Converting a Spring Controller into a @Controller

In the Spring Web Framework, its typical to implement a Controller as a class that implements org.springframework.web.servlet.mvc.Controller, for example: public class InventoryController implements Controller { public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Handle the request here } } This class would then be defined within an application's Spring context XML file (typically appname-servlet.xml) <bean name="/home.htm" class="springapp.web.InventoryController"> ... </bean> Using Spring annotations however, its possible to remove the need to implement the org.springframework.web.servlet.mvc.controller and remove the bean definition within the XML file. To change the Controller class to use annotations, the class needs to be annotated with the @Controller and @RequestMapping annotations a...

Is NetBeans 7.0 Ready for Release?

Now that NetBeans 7 Release Candidate has been released , the NetBeans team are asking for your thoughts as to whether the software is stable for general release. The NetBeans Community Acceptance Survey  provides invaluable information to the NetBeans team about the stability and new features added into NetBeans 7. If you're using NetBeans 7 RC, please consider completing the survey.

Seam 3 Final Released

Shane Bryzak has today announced the release of Seam 3. Seam 3 is a modular collection of extensions to Java EE 6 based upon CDI which can be downloaded individually  or as a complete bundle .  Shane describes Seam 3's goal as: "to enable developers to create rich, standards-based internet applications by solving many of the challenges encountered when developing software in today's connected world." Seam 3 contains many components to help developers build web applications including components for JSF, Wicket, Security, Persistence and more.  A full list of modules and their descriptions can be found at the Seam project site . Seam 3 will work with ant Java EE 6 compatible application server such as JBoss AS or GlassFish 3.1 or by any servlet container with the Weld servlet extension.

NetBeans 7.0 Release Candidate Available

The NetBeans team has announced that NetBeans IDE 7.0 RC1 is now available for download . " NetBeans IDE 7.0 introduces language support for development to the Java SE 7 specification with the JDK 7 platform. The release also provides enhanced integration with the Oracle WebLogic server, as well as support for Oracle Database and GlassFish 3.1. Additional highlights include Maven 3 and HTML5 editing support; a new GridBagLayout designer for improved Swing GUI development; enhancements to the Java editor, and more. " The full release of NetBeans 7.0 is expected in early April.

Quick Look at EJB 3.1 on JBoss AS 6

Now that JBoss AS 6.0 has been released with full support for the Java EE 6 Web Profile, lets take a quick look at some of the new features of EJB 3.1 that are available. Three of the main features of EJB 3.1 are: EJB’s can be deployed as part of a WAR file and do not need to be is a separate EJB JAR file. EJB’s can be developed with no business interface. EJB’s can be deployed as Singletons. Let’s take a look at each of these in turn. 1. EJB’s can be deployed as part of a WAR file. Not much to look at here I’m afraid! The thing to notice is that now with NetBeans (I’m using NB 7 Beta), you can create a simple Java EE 6 Web Project and create EJB’s within the web project. If you are developing a web project, there is no longer any need for an additional JAR to deploy any EJB’s that you use. 2. EJB’s can be developed with no Business Interface Creating an EJB without a Business Interface is as simple as creating a POJO, which in fact the EJB is! In it’s simplest form,...

JBoss AS 6 Released with support for Java EE 6 Web Profile

In case you missed the announcement last week, JBoss AS 6.0 has been released for General Availability. JBoss AS 6.0 provides an fully certified implementation of the Java EE 6 Web Profile Specification ( JSR-316 ). So, what does this give to Java EE developers exactly? JBoss AS 6.0 is the latest in the line of community supported Java EE application servers. From the first milestone release to the final release of AS 6 has taken nearly a year of development and testing. JBoss AS is easy to install (simply unzip it) and run requiring only a compatible JDK to run. Configuration and management of JBoss AS can be done either via the excellent web based Administration Console , via XML file manipulation (this is particularly useful for integration with Maven or Ant) or via the command line Twiddle tool. The Java EE Web Profile was designed to provide developers with all the tools that they need to build Rich Internet Applications. The Web Profile Specification describes the profile ...