Category Archives: java

Log your miles and community runs: Java EE 7 Real World Experience

miles2run-logo

miles2run.org is an easy way to track your running activities and share with friends and families. Day-based or distance-based goals can be created and then tracked. It also allows to create community run goals and have multiple runners participate and track their activities towards that goal. You can also find out local runners and connect with them.

The project was started to help track running activities for #JavaOneStreak. The goal was to run at least a mile every day all the way until JavaOne and use this website to track the runs. There are tons of sophisticated applications and websites that allow you to track running activity. Most of them provide integration with your GPS watch, phone GPS, and other fancy features. Some of them even allow creating a group but none of them is based on Java :-)

The application is hosted as a website and built using HTML5 and Java EE 7. The landing page provides a summary of total runners, their city/country, miles, and hours logged so far.

miles2run-landingpage

The website can be viewed on a desktop, tablet, or a cell phone. The runners can login to the website using common social brokers such as Facebook, Google, and Twitter.

Any body can click on “Community Runs” on the top-right corner to see what all group runs have been created so far. These can only be created by an administrator. The group run page for JavaOne shows how many runners have joined this run and other statistics.

miles2run-javaone-mainpage

Each runner is presented with a dashboard showing how much distance they’ve run so far and total/completed/remaining/missed days.

miles2run-javaone-dashboard1

A visual representation of the progress and a heat map of the activity calendar is shown:

miles2run-javaone-dashboard2

A line chart of mileage over the days is shown:

miles2run-javaone-dashboard3

And then a summary of activities over the past months is shown as well:

miles2run-javaone-dashboard4

Runners also have the opportunity to follow other runners and track their activities.

Here is a conceptual view of the application:

miles2run-architecture

And here is a technology view of the application:

miles2run-tech

Here is a brief description of the technology stack:

  • Presentation
    • Thymeleaf template engine views rendered by JAX-RS
    • Social brokering using native APIs for Facebook, Google, Twitter
  • Middle Tier
    • @Stateless EJB for all transactional JPA interactions, @Asynchronous for posting status to social networks
    • JAX-RS for exposing REST endpoints. ContainerRequestFilter and ContainerResponseFilter for security for cross-cutting concerns like authentication, injecting profile, and CORS.
    • Bean Validation constraints in JAX-RS resources.
    • Bean discovery mode=”all”
  • Backend
    • CDI producers for creating EntityManagers and other configuration objects like Redis connection pool objects or MongoDB configuration object. All NoSQL services are created @ApplicationScoped.
    • Using native drivers for Redis and MongoDB. Jedis is being used for Redis and MongoDB Java driver is used for MongoDB. CDI services wrap these driver API and expose business functionalities that other layers could use.
    • JPA + Bean Validation. Database scripts are generated from JPA model, added to source control, manually applied to the database. Using @Index and Entity Graph.
    • Servlets are used for callback URLs for social brokers.
    • Error pages are configured using <error-page>.
    • MySQL is used for all business entities like Activity, Goal, User Profile etc. Redis is used for storing counters and timeline data. MongoDB is used for location-based user recommendations and follower/following recommendations.

Technologies from outside the platform:

  • JavaScript
    • D3.js and C3.js for visually appealing graphs
    • AngularJS for views
    • Cal Heatmap for calendar heatmap
    • jQuery
  • Google Geocoding API to convert Location Text to latitude and longitude
  • Jadira usertype for storing dates in UTC
  • Joda-Time for working with dates
  • Thymeleaf was used instead of JavaServer Faces because:
    • Allows JAX-RS to be used as an MVC framework to render server side HTML pages and exposing REST services.
    • This application is a Single Page application built using AngularJS. So, we needed a lightweight approach to render server side pages. JAX-RS along with Thyemleaf render the main HTML 5 page and then we use AngularJS to render different partials/views on that page. For example, the main home page is rendered by JAX-RS and Thymeleaf. When you work with different sections of this page all of them are part of a SPA managed by AngualarJS.
    • Thymeleaf documents are valid HTML 5 documents so you can work with them offline for static prototyping.
  • Redis is used for storing all the counters like number of runners, cities, counters specific to goal like total distance covered in a goal etc. To avoid lots of read/write from the database, an an in-memory database is used so all the write and read operations are very performant. Redis counters are atomic, which means there are no concurrency issues associated with it. INCR andINCRBY Redis operations are used to update counters.
  • MongoDB is used for location data.

Toolset

  • JDK 8
  • IntelliJ 13.1 with Maven
  • Wildfly 8.1.0.Final – Development was done using a local WildFly instance and then pushed to scalable WildFly instances on OpenShift for deployment. HA Proxy is used as the load balancer.The advantage of working with OpenShift is that there is no OpenShift specific code in your application. So, it’s the same application that work locally that is deployed to test and production environment. You just have to use environment variables to abstract out environment specific configuration.
  • Github

Planned updates

  • Use Jenkins for Continuous Integration and manage deployments
  • JPA 2.1 converter instead of Jadira
  • Keycloak instead of native social broker
  • Opensource the application

Wish list for Java EE 8

  • Integration with OAuth providers
  • A real MVC framework with support for pluggable template engines
  • Seamless working with NoSQL databases

Download WildFly 8.1 today, learn the technology by reading/trying Java EE 7 samples, browse through Java EE 7 resources.

Or if you want to be on the bleeding edge, check out WildFly 9.0.

Many thanks to Shekhar Gulati (@shekhargulati) for authoring the application and providing all the answers!

Are you using Java EE 7 and WildFly to deploy your projects ? Would love to feature you here! Send me an email or leave a comment on the blog.

Java EE 7, JBoss, WildFly, Devoxx4Kids, and Parties at JavaOne 2014

JavaOne 2014 is about a week away, although some of festivities will start next Friday! This is going to be my 16th JavaOne in as many years and I’ve really enjoyed participating in each one of them. As always, there is great content lined up with rockstar speakers. This conference is a confluence of movers and shakers in the Java world and provides plenty of opportunities to engage with them. This is going to be my first year as Red Hatter and looking forward to catching up with friends and colleagues.

And in case you are wondering, and care about it, here are my engagements for that week:

Saturday, Sep 27

Devoxx4Kids Day
7pm – 11:30pm: NetBeans Party

Sunday, Sep 28

8am – 9:30am, Java Champions Brunch
7pm – 8:30pm: Duke Choice Awards
8pm – 11pm: Java EE Appreciation Event

Monday, Sep 29

8:30am – 10:30am Java EE 7 Soup to Nuts Tutorial [TUT1952]
11:30pm – 12:30pm Meet the Experts on Java EE and HTML5 Enterprise Application Development
1:30pm – 2:00pm Java EE 7 Essentials book signing at O’Reilly Booth

Tuesday, Sep 30

8:30am – 10:30am: Devoxx4Kids for Parents Tutorial [TUT1878]
12:30pm – 1:30pm: Lessons learned from real-life Java EE 7 Deployments [CON2450]
2:30pm – 4pm: Java EE Hackergarten
6pm – 9pm: Oracle Authors Appreciation Party
7pm – 9pm: JavaOne IGNITE
7pm – 10pm: PartyOne
7pm – 9:30: Java Champions Social
8pm – 8:45pm: Technology Evangelists Gathering [BOF12166]

Wednesday, Oct 1

1pm – 1:30pm: Book signing on Java EE and HTML5 Enterprise Application Development book (OOW bookstore in Moscone South, Upper Hall Lobby)
4pm – 6:30pm: #JavaOneStreak meetup, Hilton San Francisco Union Square, Sutter

Thursday, Oct 2

11:50: Broadening JCP Program Participation [CON9775]

I’ll also be running my own “hallway track” and so feel free to meet there. Of course, you can catch me at Red Hat booth as well!

There are lots of Red Hat speakers and sessions at the conference as well. And if you are not able to attend a Red Hat session then you can check out the mini-sessions in the exhibit hall.

See ya there!

Java EE 6 Sample, with HTML5, jQuery, Hybrid mobile: aka Ticket Monster (Tech Tip #44)

Java EE 7 was released last year, Java EE 8 preparations have already started, so what tempts me to write a blog about Java EE 6 ?

A few reasons …

  • Even though Java EE 5 was the first version where some of the specs were updated to simplify the platform, Java EE 6 is where higher productivity became the primary focus and kicked into high gear.
  • All commercially available application servers are still Java EE 6 compliant.
  • Java EE 7 is pretty cool and provide an awesome bunch of new technologies like WebSocket, Batch, JSON, and Concurrency. But customers are still sticking around with older version of the platform because these applications, servers, and environments cannot change overnight.

So if you are looking for a real-world Java EE 6 sample application that:

  • Use Eclipse for building a Java EE 6 application
  • Build persistence layer with JPA2 and Bean Validation
  • Build business services with JAX-RS
  • Building the User Interface with HTML5
  • Building Administration UI with JBoss Forge
  • Building statistics dashboard using HTML5 and JavaScript
  • Hybrid mobile version of the app using Apache Cordova

In addition, it also shows:

  • Deploy your application on a local instance or a remote instance running in OpenShift
  • Run tests against your JBoss instance

Ticket Monster is your ultimate source. It not only shows how the key Java EE 6 technologies can be used together but also integrate jQuery, HTML5, and mobile version of the application as well.

The video below gives a quick preview of the application:

An instance of Ticket Monster can be previewed at ticketmonster-jdf.rhcloud.com or timo-milestogo.rhcloud.com.

So how do you get started ?

  1. Download Ticket Monster 2.6.0 (with tutorials). Corresponding source code is at github.com/jboss-developer/ticket-monster/tree/2.6.0.Final-with-tutorials.
  2. Set up Red Hat Maven repositories as explained here. If you don’t care reading through the instructions, overwrite .m2/settings.xml with this settings.xml.
  3. Build the WAR of your application
  4. To run on local JBoss instance:
    • Download JBoss EAP 6.3
    • Unzip and start as
    • Deploy the application as

      This will also build the application again.

      The application is now accessible at localhost:8080/ticket-monster.

  5. To run on JBoss instance in OpenShift
    • Create a JBoss EAP 6 application in OpenShift
    • Add PostgreSQL cartridge for this application
    • Create an archive as

      This will use the installed PostgreSQL cartridge for persistence.

    • Clone the git workspace from OpenShift

      The actual git url will be specific to your application.

    • Copy generated WAR file to git workspace and rename to ROOT.war

    • Remove existing source and pom.xml from git workspace, add WAR, and push

    • Access the application at htp://<appname-domainname>.rhcloud.com.The following video shows the steps for running TicketMonster on OpenShift:

Ask your questions about Ticket Monster at .
Enjoy!

Java EE 7 Javadocs Download, Online, Tutorial, Samples (Tech Tip #42)

I was surprised when Google could not find Java EE 7 Javadocs download link clearly on the first page. StackOverflow was helpful here again, but even that was the last link on first page.

Now, I do know the location and can find my ways around. But this needs to be simplified and made more accessible for developers around the world.

So here are some usual Java EE 7 references:

  • Java EE 7 Javadocs Download Full Platform (bit.ly/ee7-javadocs), Web Profile
  • Java EE 7 Javadocs Online
  • Java EE 7 Tutorial
  • Java EE 7 Whitepaper
  • Java EE 7 Samples

Javadocs can also be installed on Dash as explained in Antonio’s blog.

And as usual, you can download WildFly or GlassFish to get started with Java EE 7!

Enjoy!

Adding Java EE 7 Batch Addon to JBoss Forge ? – Part 5 (Tech Tip #38)

This is the fifth part (part 1part 2, part 3, part 4) of a multi-part video series where Lincoln Baxter (@lincolnthree) and I are interactively building a Forge addon to add Java EE 7 Batch functionality.

Part 1 showed how to get started with creating an addon, add relevant POM dependencies, build and install the addon using Forge shell, add a new command batch-new-jobxml, and add --reader--processor--writer parameters to the newly added command.

Part 2 showed how to identify classes for each CLI parameter that already honor the contract required by the Batch specification.

Part 3 showed how parameters can be made required, created templates for reader, processor, and writer, validated the specified parameters.

Part 4 added a new test for the command and showed how Forge can be used in debug mode.

This part shows:

  • Fix a bug reported by a community member
  • Started work another issue to make processor validation optional

Enjoy!

As always, the evolving source code is available at github.com/javaee-samples/forge-addons. The debugging will continue in the next episode.

Defaults in Java EE 7 (Tech Tip #37)

Java EE 7 platform added a few new specifications to the platform:

  • Java API for WebSocket 1.0
  • Batch Applications for Java 1.0
  • Java API for JSON Processing 1.0
  • Concurrency Utilities for Java EE 1.0

This is highlighted in the pancake diagram shown below:

javaee7-pancake

Several of the existing specifications were updated to fill the gaps and provide a more cohesive platform. Some small, but rather significant additions, were made to the platform to provide defaults for different features. These defaults would lower the bar for application developers to build Java EE applications.

Lets take a look at them.

  • Default CDI: Java EE 6 required “beans.xml” in an archive to enable CDI. This was mostly a marker file. So you could bundle a completely empty “beans.xml” in the archive and that would enable injection. Of course, you could specify a lot of other elements in this file such as interceptors, decorators, alternative but the basic dependency injection was enabled by just the mere inclusion of this file.This was one of the biggest source of confusion of why beans were not getting injected in a Java EE 7 archive, and was asked on several forums and other channels.

    Java EE 7 made that “beans.xml” optional and provided a default behavior. Now if this file is not bundled, all CDI-scoped beans are available for injection. So any bean with an explicitly specified scope is available for injection. Scopes defined by the CDI specification are listed at docs.oracle.com/javaee/7/api/javax/enterprise/context/package-summary.html. Specifically, here are the scopes defined by CDI:

    • @ApplicationScoped
    • @ConversationScoped
    • @Dependent
    • @NormalScope
    • @RequestScoped
    • @SessionScoped

    In addition, two new scopes are introduced in Java EE 7:

    • @FlowScoped
    • @TransactionScoped

    So, any bean with these scopes will be available for injection, in other beans only, without the presence of “beans.xml”.

    Check it out in action at github.com/javaee-samples/javaee7-samples/tree/master/cdi/nobeans-xml.

  • Default data source: A Java EE runtime, a.k.a application server, requires to package a database with it. If you are building a Java EE application, you likely will need some sort of data store or RBDMS to store the data. So this makes perfect sense.For example, WildFly bundles in-memory H2 database.Now, you can certainly use another JDBC-compliant database but bundling a database makes it convenient to start with. However, in order to get started, Java EE 6 still required to create JDBC resources in an application server-specific way. This would mean understanding app server-specific tools.

    Java EE 7 simplified it by providing a default data source with a pre-defined JNDI name.This mean you can inject a data source as:

    Also, your persistence.xml can look like:

    Note, no <jta-data-source>.

    In both of these circumstances, a default data source with JNDI name java:comp/DefaultDataSource is bound to your application-server specific JDBC resource.

    The exact data source in WildFly can be verified using jboss-cli script as:

    Check it out in action at github.com/javaee-samples/javaee7-samples/tree/master/jpa/default-datasource.

  • Create JMS connection factory, queues, and topics: An application using JMS topics and queues in Java EE 6 would require a deployment script to create Connection Factory and Queues/Topics. These would again be done in an application server-specific way.Java EE 7 provide annotations @JMSConnectionFactoryDefinition and @JMSConnectionFactoryDefinitions that are read by the Java EE 7 runtime and ensures that the ConnectionFactory specified by these annotations is provisioned in the operational environment.

    Similarly, @JMSDestinationDefinition and @JMSDestinationDefinitions can be used to create Topics/Queues as part of application deployment.So no more deployment scripts, just include annotation in your code ?

    Check it out in action at github.com/javaee-samples/javaee7-samples/tree/master/jms/send-receive.

  • Default JMS connection factory: Just like default data source, a default JMS resource allows you to avoid creating a JMSConnectionFactory in an appserver-specific way to deploy the application using JMS resources.Injection of a JMS Producer or Consumer in Java EE 6 required to get an instance of application-managed or container-managed JMSConnectionFactory. This factory had to be manually created in an application-server specific way.Providing a default JMSConnectionFactory simplifies this step further.

    JMS 2.0 also introduced JMSContext as entry point to the simplified API, and it can be injected simply as:

    Not specifying a ConnectionFactory means the default one will be used. And it has the JNDI name of jms/DefaultJMSConnectionFactory.

    The JNDI name may be mapped to the appserver-specific JMS provider. For example, in case of WildFly it is defined as:

    Check it out in action at github.com/javaee-samples/javaee7-samples/tree/master/jms/send-receive.

  • Default executors: Concurrency Utilities for Java EE introduced four different managed objects:
    • ManagedExecutorService
    • ScheduledManagedExecutorService
    • ContextService
    • ManagedThreadFactory

    These objects allow user to create application threads that are managed by the Java EE server runtime. Once again, a default and pre-configured managed object, with a well-defined JNDI name, is made available for each one of them.

    This allows a user to inject a ManagedExecutorService as:

    instead of:

    Default ManagedExecutorService in WildFly can be found as:

    Similarly other default managed objects can be found.

    Check out different executors in action at github.com/javaee-samples/javaee7-samples/tree/master/concurrency.

With so many simplifications, why would you not like to use Java EE 7 platform ?

And WildFly is a fantastic application server too :-)

Download WildFly now, and get started!

Schedule Java EE 7 Batch Jobs (Tech Tip #36)

Java EE 7 added the capability to perform Batch jobs in a standard way using JSR 352.

This code fragment is the Job Specification Language defined as XML, a.k.a. Job XML. It defines a canonical job, with a single step, using item-oriented or chunk-oriented processing. A chunk can have a reader, optional processor, and a writer. Each of these elements are identified using the corresponding elements in the Job XML, and are CDI beans packaged in the archive.

This job can be easily started using:

A typical question asked in different forums and conferences is how to schedule these jobs in a Java EE runtime. Batch 1.0 API itself does not offer anything to be schedule these jobs. However Java EE platform offers three different ways to schedule these jobs:

  1. Use the @javax.ejb.Schedule annotation in an EJB.
    Here is a sample code that will trigger the execution of batch job at 11:59:59 PM every day.

    Of course, you can change the parameters of @Schedule to start the batch job at the desired time.
  2. Use ManagedScheduledExecutorService using javax.enterprise.concurrent.Trigger as shown:

    Call runJob to initiate job execution and cancelJob to terminate job execution. In this case, a new job is started a day later than the previous task. And its not started until previous one is terminated. You will need more error checks for proper execution.

    MyJob is very trivial:

    Of course, you can automatically schedule it by calling this code in @PostConstruct.

  3. A slight variation of second technique allows to run the job after a fixed delay as shown:

    The first task is executed 2 hours after the runJob2 method is called. And then with a 3 hours delay between subsequent execution.

This support is available to you within the Java EE platform. In addition, you can also invoke BatchRuntime.getJobOperator().start("myJob", new Properties()); from any of your Quartz-scheduled methods as well.

You can try all of this on WildFly.

And there are a ton of Java EE 7 samples at github.com/javaee-samples/javaee7-samples.

This particular sample is available at github.com/javaee-samples/javaee7-samples/tree/master/batch/scheduling.

How are you scheduling your Batch jobs ?

Testable Java EE 7 Maven Archetype, using Arquillian (Tech Tip #34)

There is a Maven archetype to create Java EE 7 application:

It generates a simple “pom.xml” with Java EE 7 API <dependency>. It does the job to get started with building the application. But how do you test this app ?

Of course, you write unit and integration tests. But how do you run these tests, especially in a container-independent manner ?

That’s where Arquillian comes in!

Arquillian guides explain how to write real tests, but you still need to figure out Maven dependencies, create profiles, figure out container dependencies, and more. That’s still too much work :)

Meet a new Maven archetype that generates a Java EE 7 app, with profiles pre-configured for WildFly and GlassFish.

The four profiles are:

  1. wildfly-remote-arquillian
  2. wildfly-managed-arquillian
  3. glassfish-remote-arquillian
  4. glassfish-embedded-arquillian

The first profile is the most natural to start with. It requires to download WildFly 8.1, unzip and start using ./bin/standalone.sh. Then you can run the test as:

to see the result as:

This is useful if tests need to be executed multiple times on the same WildFly instance.

The second profile is the easiest to start with, and does not require any manual downloading. Using the profile downloads WildFly (8.0.0 at this time) to Maven repository, installs it in the “target” directory, starts the server, deploys the WAR file, runs the test, and stops the server.

“glassfish-remote-arquillian” profile is like “wildfly-remote-arquillian” where an instance of GlassFish is started externally and tests are run in the usual manner. This profile does not work at this moment because of ARQ-1596.

“glassfish-embedded-arquillian” is like “wildfly-managed-arquillian” where GlassFish container is downloaded transparently using the Maven dependencies, starts the container, deploys the app, runs the test, and stops the container.

Archetype source code is at: github.com/javaee-samples/javaee7-archetypes/tree/master/javaee7-archetype and the archetype is published at search.maven.org/#search%7Cga%7C1%7Cjavaee7-arquillian-archetype.

Many thanks to @aslakknutsen for publishing this archetype!

A complete working sample can be checked out from github.com/arun-gupta/wildfly-samples/tree/master/arquillian.

Let us know if you find this useful and how would you use it.

Java EE 7 Hands-on Lab on WildFly and OpenShift (Tech Tip #33)

Thanks to @dmueller for inspiring this blog entry and @FarahJuma for keeping WildFly cartridge continuously updated!

Java EE 7 hands-on lab has been delivered at several conferences, meetups, Java User Groups, and other venues around the world. It provides instructions for a typical 3-tier application using several technologies in the Java EE 7 platform, such as WebSocket 1.0 (JSR 356), Batch Applications (JSR 352), JSON-P 1.0 (JSR 353), JAX-RS 2.0 (JSR 339), JMS 2.0 (JSR 343), CDI 1.1 (JSR 346), JPA 2.1 (JSR 338), and many more. The self-paced instructions allows the attendees to learn the design patterns in Java EE 7, and be productive right away.

This lab can be built using NetBeans, JBoss Tools/Eclipse, or IntelliJ. The deployment can be done on WildFly or GlassFish.

Do you want to get a taste of the application without trying out all the steps ? You can download the solution and deploy on application server of your choice.

Don’t have time for downloading and installing your application server ? OpenShift is your answer!

OpenShift provides an open source hybrid cloud application platform by Red Hat. It enables polyglot applications to be deployed on a public, private, and a hybrid cloud very easily. It provides an extensible cartridge-based architecture that allows a wide range of functionality such as frameworks, databases, monitoring services, or connectors to external backends to be easily added. WildFly cartridge allows you to start a WildFly instance in OpenShift Online.

This Tech Tip shows how to deploy Java EE 7 hands-on lab solution easily on WildFly cartridge on OpenShift.

  1. Register for a free OpenShift account.
  2. Login to OpenShift Console.
  3. Create a new WildFly application using the quickstart. Take the defaults, or change the name to whatever you want, and click on “Create Application”. The following page is shown:techtip33-app-created-credsThe default application page looks like:techtip33-wildfly-default-output
  4. Clone the workspace using the credentials shown for your application.
  5. Delete the generated “src” directory and copy the “src” from solution.
  6. Commit and push the changes to restart the cartridge:

Refreshing the page at javaee7lab-milestogo.rhcloud.com now shows the application deployed successfully:

techtip33-javaee7lab-default-output

Simple, isn’t it ?

Try it and let us know your feedback!

Tech Tip #21 also talks about how to get started with WildFly in OpenShift and JBoss Developer Studio.

 

DeltaSpike 1.0 – Extend #JavaEE beyond #JavaEE (Tech Tip #32)

Do you want @Transactional and @TransactionScoped-like features introduced in Java EE 7 in JBoss EAP 6.x or any other Java EE 6 compliant application server ?

Need a CDI scope for window/tab for a JSF application ?

Simplified JPA Criteria API ?

How about boot and shutdown CDI container in a Java SE application ?

Simplified annotation-based security in Java EE ?

This is not a wish list for Java EE 8, but is possible today using DeltaSpike. All of this is possible by using the power of CDI portable extensions to unleash the power of a Java EE application server beyond what is defined in the existing specifications.

deltaspike-logo

DeltaSpike consist of a number of portable CDI extensions that provide useful features for Java application developers.

What are CDI portable extensions ?

CDI portable extensions extend the functionality of the container using an Service Provider Interface (SPI). A portable extension may integrate with the container by:

  • Providing its own beans, interceptors, and decorators to the container
  • Injecting dependencies into its own objects using the dependency injection service
  • Providing a contextual implementation for a custom scope
  • Augmenting or overriding the annotation-based metadata with metadata from some other source

DeltaSpike also ensure true portability! They are tested on different CDI implementations like JBoss Weld and Apache OpenWebBeans, and also on different Java EE servers like Apache Tomcat and TomEE, JBoss AS7, WildFly 8, Oracle GlassFish 3.1+ and 4.x+, IBM WebSphere 8.x, Oracle WebLogic Server 12c, Jetty, and others.

DeltaSpike has a core API and Impl module. The extensions themselves are available in different modules:

  • Security: Intercept and check security
  • Java Persistence API: @Transactional, @TransactionScoped, Extended persistence context, and more
  • Java Server Faces: Multi-window handling, New scopes, Type-safe view configs
  • Bean Validation: Add CDI support in Bean Validation
  • Servlet: Injection of common Servlet objects, propagation of Servlet events to the CDI event bus
  • Data: provides enhanced JPA experience with declarative queries, reducing boilerplate to a minimum.
  • Test Control: Allows to write CDI based tests easily
  • Scheduler: Simple integration with Quartz v2 (per default) or any other scheduler which supports cron-expressions for job-classes.
  • Container Control: Allows to boot and shutdown the CDI container in SE applications, control the life-cycle of the built-in contexts of the CDI container

You may realize that some of the functionality is already available in Java EE 7 so this would certainly be lot more relevant to Java EE 6 compliant application server. But there are still several features that can be used in Java EE 7 compliant app servers, like WildFly. And then it has the potential to be the playground for new features that are being discussed in Java EE 8!

Getting started is easy if you are using Maven. Add core and impl <dependency>s to “pom.xml”:

And then configure one of the modules as explained here.

Complete documentation for all the modules is available here.

One of the frequently needed features is accessing ServletRequest in a CDI bean. With DeltaSpike, this can be easily achieved using the following annotation:

A complete sample showcasing this functionality is available at github.com/arun-gupta/wildfly-samples/tree/master/deltaspike.

DeltaSpike 1.0 was recently announced and the complete list of JIRA tickets fixed is here.

There are usual ways to connect with the team:

Let us know what would you like to see in DeltaSpike!

Java EE BoF at DevoxxUK Notes

2014-06-12 19.45.54

The usual Java EE BoF at DevoxxUK was another chance for community members to meet and discuss the past, present, and future of Java EE. The gathering happened on the first anniversary of Java EE 7 and so allowed us to focus on what happened in the past year and start focusing on what’s expected from Java EE 8.

Here are some notes:

  • Meetup started with the usual pet peeve of no official Java EE logo. @Java_EE is the “official” twitter handle which tweets about technology, compliant application servers, and competitive analysis that favor Oracle ;) This handle has an image but there were personal opinions about its usage, with no clear consensus or statement from JCP or Oracle, on whether this is the official logo of Java EE as well.
  • Another constant running pet peeve is how the information around Java EE is scattered in different websites. There is official Java EE 7 tutorial by Oracle and 200+ samples/tests (with 33 contributors from the community), and Adam Bien’s samples. These are good for somebody who has a basic understanding of the technology already. But there is nothing for a newbie to Java EE. No single website that shows Java EE design patterns, how the technology has evolved over the years, comparison with Spring, why choose one over another, different application servers and their compliance level, relevance of production support in an open source world, tool set, and the list goes on. Antonio Goncalves (@agoncal) raised the point that if somebody registers javaee.io, then would Oracle send their lawyers after the person who registered the domain ? David Delabassee (@delabassee) mentioned that there might be some announcement to that effect at JavaOne, so wait and watch.
  • Antonio talked about how Java EE platform consists of a profile, and a profile can consists of multiple specs. He proposed a further granularity where a spec could be divided into multiple parts, such as CDI could be divided into core, injection, interceptors, etc. Different specs (existing or new) can then define what pieces of the spec they depend upon. This does rely upon modular platform. As we know, modularity is not coming to Java SE in the near future. So if this needs to be achieved then Java EE platform will have to define some mechanism of its own. David Blevins (@dblevins) particularly brought a good point that just because CDI is a good specification, that should not mean that everything should be added to CDI and make it a bloatware. We need to protect JSRs that are good and keep them light.
  • Nigel Deakin announced that JMS 2.x is getting planned. Some of the key focus there is to simplify Message Driven Beans, leverage connectors (this is David Blevins’s favorite topic ;), and allow messaging dispatching using JAX-RS-fashioned APIs. It was highly recommended that no new bean type should be introduced. Nigel is looking for supporters of the JSR.
  • David also mentioned that JAX-RS.next and Servlet.next are getting planned as part of Java EE 8. There is a already a flurry of activity on MVC support in JAX-RS. Similarly should support for Server-Sent Events be included in JAX-RS, or outside it ? There was as a suggestion that JAX-RS should expose an SPI and other specs should be able to leverage that SPI to add features to JAX-RS, instead of making it part of the core spec itself.
  • Anatole (@atsticks) talked briefly about the Configuration JSR which should likely be filed before Java EE 8 as well.
  • There was interest on having an embedded Java EE server. The user should be able to deploy the WAR file and the runtime should be able to detect dependencies and load the right set of containers.
  • There was still no urgency to provide a standards-based PaaS platform. However even though JSR 88 is formally deprecated but there were discussions about bringing a Devops-style API. This was also discussed during JavaOne 2013 as well.
  • Another constant pet peeves is the different styles of Logging API. There is no standard API in Java EE to log and each application server picks their favorite framework. This makes the job of application developer challenging.
  • JMX 2 might be revised as part of Java EE 8. There was a brief discussion on exposing JMX beans as REST endpoints.
  • There was also discussion around that there should be a separate Java Community Process track at JavaOne. This would provide beginner to advanced sessions on JCP, and hopefully encourage more members to join JCP and contribute.

Please leave a comment on the blog for any updates.

Configuration JSR in Java EE 8 – What should be covered ?

GeeCON 2014 was very inspiring! A really greet feeling from the Polish Java community, awesome bunch of organizers (Andrej (@ags313), Adam (@maneo), Konrad (ktosopl), Adrian (@adrno), rest of the gang is just super nice), great technical content, courteous and helpful volunteers, lots of socializing space/opportunities, and most importantly fun! This was my second GeeCON and would love to go back there next year.

During speakers’ dinner, Anatole (@atsticks) and I were talking about the Configuration JSR (scheduled to be part of Java EE 8) and he shared the proposal. Instead of reading the proposal, I decided to put my thoughts down first so as not to be tainted by it. So this blog describe the use cases that I think this JSR should address. This by no means is a comprehensive list, or in any particular priority order. It is solely intended as input to the JSR and Expert Group based upon Anatole’s request, Laird Nelson (@chuggid) is the other spec lead on this.

Here goes the list …

  1. Application-wide configuration may be provided using XML-based configuration (application.xml ?), Annotations, and a programmatic Java API. A graphical web-based tool may simplify generation of these artifacts as well.
  2. One of the primary concerns during devops is the ability to take the same WAR file from development, to testing, and finally to production. Unzipping the archive and bundling a different deployment descriptor to point to different databases/servers is used as a workaround, but not recommended. If configuration is specified using a XML configuration file, then there should be the ability to specify configuration for all of these stages. Each stage could point to a different JMS destination, JNDI reference for data source, port numbers, etc.For example:

    In addition, a mechanism to trigger a particular stage would need to be defined. An external configuration tool that can trigger a particular environment may be one way to achieve this. Relying upon environment variables does is not a good idea.

    Custom stages should be permitted as this would allow to target different environments for stress, performance, regression, integration, and different sorts of testing.

    All of this, of course, would work for Java EE components only.

  3. Configuration may not be restricted to only Java EE components. It may include the max amount of memory that the application could use on the server, whether high availability is enabled or not, min/max number of servers in a cluster, etc. This would require to specify the configuration outside of Java EE context.
  4. Stages may inherit from other stages. This would allow a production environment to point to the test database rather easily. In this case, inheritance rules would need to be defined.
  5. Application configuration may be specified exclusively outside the application. This could be done using the graphical tool, and stored in a persistent store. This would allow a system administrator to easily pick a particular configuration.
  6. Reasonable defaults should be defined for the entire application, such as more logging/debugging during development stage. This will allow containers to spit out more detailed and useful information during different stages. For example, JSF displays an error message on XHTML page, even if there is no place holder for it, during development phase but hides it during the production stage.
  7. A mechanism to store all the configuration information in a variety of persistent stores would be useful. One of the common ways could be “application.xml” as a file, typically bundled in the archive itself. Storing this information in a relational database could be useful as well. This would allow developers to focus on application configuration during development, possibly using annotations or “application.xml”. And then retrieve a testing/production configuration from a database when targeting those stages.
  8. An archive would typically have a “persistence.xml” and a “web.xml”. Explicit rules on how the values defined in those individual files are overridden by application-wide configuration needs to be defined. These rules would need to be defined amongst the different ways configuration is enabled, for example “application.xml” overriding the values set by annotations.
  9. Going a step further, it may be relevant to even provide a standard schema on how this information is persisted. Vendors may provide their extensions to it, but at least a basic schema would ensure some level of portability.A development database bundled with the application server would work during development stage. But typically a more enterprise and reliable database would be used during production. So one more step further, a standard way to connect to these databases would be useful.
  10. A typical EAR file may look like:

    The scope of how/where an annotation is defined needs to be clearly specified. Whether “application.xml” can be defined in a JAR file bundled in WEB-INF/lib in an EAR file ?

    If so, what are the overriding rules ?

    Can it only be specified on the top-level archive ?

    What happens if there is a conflict ?

  11. JSR 236 did not specify how different managed objects can be configured, and this is a gap in the existing specification. If JSR 236.next is not being planned or not planning to address it during Java EE 8 timeframe, then this JSR should attempt to address that.
  12. Different application servers have their own means to deploy multiple versions of an application. This allows multiple versions to be deployed but only one version to be enabled at a given time. It would be nice if application versioning can be addressed by this JSR.
  13. Pre/post hooks for deployment, and other stages, should be made available. These can be used by sysadmins to provision resources required during deployment/runtime.
  14. CDI events for different stages may be generated. This would allow different parties to listen, and react to them.
  15. A Java EE 8 application may not need any deployment descriptors of the past. Bundling either just this “application.xml”, or specifying the configuration information externally should be enough.
  16. Reload of configuration information should be possible, without deploying the archive.
  17. A REST schema of all the configuration information handled by the JSR will really simplify how vendors can easily build custom tools on it.
  18. Other frameworks like Ruby-on-Rails and Grails allow application-wide configuration and we should learn from them, and adopt their best practices.

Now that my own thoughts are listed here, here are some additional ones after reading the proposal …

  1. There is no mention in the JSR for an XML-based deployment descriptor. Even though non-Java EE components will be specified outside the scope of Java EE, but I think having a descriptor to specify the configuration for Java EE components is useful.
  2. +1 on not defining a new archive format and Anatole has explained it well in the blog.
  3. I strongly prefer the second approach integrate this new functionality with all existing JSRs as that keeps the approach simple, and scalable to any future specs as well. This JSR should define an overall framework, and how other JSRs would specify the configuration. Individual component JSRs then should leverage that and define the exact configuration points. Ideally, each component specification should have an explicit chapter dedicated for configuration.
  4. KISSing is good and I like the proposed simplistic approach of using a Map to store all this information.

What do do you think should be the scope of this JSR ?

Added a calendar reminder to revisit this blog in a year, and another one in +1 year, and see how many of these points actually make it in the spec.

PicketLink: Simplified Security and Identity Management for Java

picketlink_logo_600x

PicketLink is an umbrella project for security and identity management for Java Applications. It provides:

  • Java EE Application Security
    • Authentication API
    • Authorization and Permission API
    • Session Based Identity
    • Fully Integrated With CDI
  • Identity Management
    • Built-in Identity Stores for Databases and LDAP
    • Supports Java EE and Java SE Platform
    • Rich and Extensible API
    • Multi-Tenancy
    • Ideal for Cloud and SaaS applications
  • Federation
    • SAML (v2.0 and v1.1)
    • OAuth2
    • XACML v2
    • OpenID
    • WS-Trust based Security Token Server (STS)
  • Social Login
    • Facebook Connect
    • Twitter Login
    • Google+ Login
  • Mobile Applications Security
  • REST Applications Security

Want to learn all about PicketLink ? Look at deep dive sessions part 1 and part 2.

Peter Skopek (@pskopek) works on the PicketLink team at Red Hat and gave a presentation at London JBUG a few days ago. The slides and the video recording are now available:

Lot more information at picketlink.org.

Getting Started with WildFly in OpenShift and JBoss Developer Studio (Tech Tip #21)

[Republishing from http://wildfly.org/news/2014/04/25/Getting-Started-WildFly-OpenShift/]

OpenShift provides an open source hybrid cloud application platform by Red Hat. It enables polyglot applications to be deployed on a public, private, and a hybrid cloud very easily. It provides an extensible cartridge-based architecture that allows a wide range of functionality such as frameworks, databases, monitoring services, or connectors to external backends to be easily added. WildFly cartridge allows you to start a WildFly instance in OpenShift Online.

JBoss Developer Studio provide comprehensive tooling around Java EE, HTML5, Mobile, and many other technologies needed for modern web application development. The latest 7.1.1 release provide support for Eclipse Kepler SR2, the latest Eclipse release.

This blog contains a video tutorial that explains how to get started with WildFly in OpenShift and JBoss Developer Studio. Specifically, it shows:

  • Create an OpenShift application using WildFly cartridge
  • Access the WildFly administration console using port forwarding
  • Import the created application in JBoss Developer Studio
  • Make changes to the application and view them in the deployed application
  • Add a simple Java EE 7 component to the application

Enjoy!

WildFly 8 Launch Presentations in 40+ JUGs in 6 continents

40+ Java User Groups from 6 continents have participated in WildFly 8 Launch so far, and a few more are still lined up. This has truly been a global participation so far, and truly reflects the spirit of Java community.

Several of these were delivered virtually primarily using G+ hangout, and then some in person during the travel by WildFly team. Lots of interesting conversations and feedback from developers all around the world, many thanks for that!

Enjoy a collage of the pictures captured so far …

wildfly8-40jugs-apr25

And a complete album available on facebook.com/wildfly

Post by WildFly.

Is your JUG interested in learning all the cool features of WildFly ? Just drop a comment on this blog or ping at @WildFlyAs.

#WeAreOpen