Adam Bien's Weblog

MVC, Models and Java EE 8

The Model-View-Controller (MVC 1.0) Specification (JSR-371) enables unmanaged POJOs to be used as models:

You will find an executable example at: https://github.com/AdamBien/javaee8-mvc-sample.

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting


Classic Java EE 7 Workshops: Bootstrap, Effective and Architectures, July, 13th-15th
Online workshop: Java EE 7 Bootstrap

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

beans.xml and JAXRSConfiguration: javaee7-essentials-archetype v1.3 released

The version 1.3 javaee7-essentials-archetype comes with two features:

  1. beans.xml for Java EE 7 and bean-discovery-mode="all" is created
  2. JAXRSConfiguration class mapped to the "resources" path enables JAX-RS

Create a project directly from the IDE (in NetBeans: New Project -> Maven -> Project From Archetype. Choose com.airhacks as groupId in the search box).

Or use the CLI:


mvn archetype:generate -Dfilter=com.airhacks:javaee7-essentials-archetype

If you like to stay lean without beans.xml and JAXRSConfiguration, choose the version v1.2.

The archetype's source is available at: https://github.com/AdamBien/javaee7-essentials-archetype. The project can be also directly cloned from: https://github.com/AdamBien/javaee-essentials-pom

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting


Classic Java EE 7 Workshops: Bootstrap, Effective and Architectures, July, 13th-15th
Online workshop: Java EE 7 Bootstrap

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Auto-Creating JMS Destinations With JMS 2.0 and Java EE 7

Java EE 7 and JMS 2.0 introduced the @JMSDestinationDefinitions annotation which allows automatic creation of JMS resources at deployment time:


import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.jms.JMSDestinationDefinition;
import javax.jms.JMSDestinationDefinitions;

@JMSDestinationDefinitions(
        value = {
            @JMSDestinationDefinition(
                    name = "java:/queue/duke-queue",
                    interfaceName = "javax.jms.Queue",
                    destinationName = "duke"
            ),
            @JMSDestinationDefinition(
                    name = "java:/topic/duke-topic",
                    interfaceName = "javax.jms.Topic",
                    destinationName = "duke-topic"
            )
        }
)
@Startup
@Singleton
public class Initializer {
     
    @Resource(lookup = "java:/queue/duke-queue")
    private Queue queue;      
    
    @Produces
    public Queue expose() {
        return this.queue;
    }
}

The conveniently created JMS destination (Queue or Topic) can be immediately exposed to dependency injection with the CDI @Produces annotation.

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting


Classic Java EE 7 Workshops: Bootstrap, Effective and Architectures, July, 13th-15th
Online workshop: Java EE 7 Bootstrap

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Playing With Model View Controller MVC (JSR-371) from Java EE 8

Playing with JSR-371 MVC (Reference Implementation) ozark scheduled to ship with Java EE 8.

See also executable example: https://github.com/AdamBien/javaee8-mvc-sample

See also other screencasts at: http://tv.adam-bien.com or subscribe to http://www.youtube.com/user/bienadam.


Classic Java EE 7 Workshops: Bootstrap, Effective and Architectures, July, 13th-15th
Online workshop: Java EE 7 Bootstrap

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

An Interview With the Killerfish--Payara

Q: C2B2 already provided commercial support for GlassFish, what is the idea behind www.payara.co?

Payara is a new initiative for C2B2. Previously we provided operational support and consultancy for customers using GlassFish in production. With Payara we are going a completely different direction. We are using the upstream open source GlassFish code base as our core to build a new application server, Payara.

We are looking to build new capabilities into Payara Server and recently we’ve added in JSR107 and data grid capabilities by incorporating Hazelcast. I did a webinar on this with Hazelcast last month: http://www.payara.co/javaee_applications_supercharged_ldquo_using_jc. We are also investigating new deployment scenarios for cloud and micro services environments through Payara Micro; and we aim to connect with the wider DevOps ecosystem through integrations with tools like Chef, Puppet, Ansible, Docker and Kubernetes.

Q: Have you got any feedback from Oracle about your Payara activities?

We have had no official feedback from Oracle. A number of our employees have signed the Contributor Licensing Agreement with Oracle and so can now submit fixes back to the upstream GlassFish team.  A number of these have been incorporated into the current GlassFish nightly builds. Informally, we’ve had support and encouragement from some of the engineers of the upstream GlassFish projects and in the spirit of open source they are keen for us to contribute.

Q: I've been watching Payara since JavaOne 2014 and the github account is very active. What triggers the activity?

People are using Payara and GlassFish and see that we are active, so they are reporting bugs and suggest lots of new ideas for new things they would like to see. This drives the list of things we want to add into each release. Payara is released quarterly and all development is carried out in the open on GitHub, which generates all the activity. We also see people raising questions, suggestions and issues on Twitter, StackOverflow, Facebook etc. The community has been really active and the interest is definitely growing – we’re really happy about it and we encourage all Payara and GlassFish users to get involved in the discussion!

Q: Does the community participate in Payara Development?

Absolutely! A number of people have signed the CLA and submitted pull requests for bug fixes and changes, which have been incorporated in the latest Payara release. New ideas from the community are also forming the basis of the enhancements and Payara Micro is a direct result of ideas from the community of how they would like to run their Java EE applications. We are completely open to community contributions and ideas. To be honest, we can’t think of everything ourselves, so we are very keen to get other people’s cool ideas to implement. GitHub is the central place to participate but people can ask questions on Twitter and other social media platforms, or even come along to one of the Java EE & GlassFishUser Group sessions in London (more info http://www.meetup.com/GlassFish-User-Group/).

Q:How many GlassFish users are switching to Payara? Can you give us any rough ideas?

There are a number of people we are aware of who are planning to or have already switched to Payara, including some very well know companies. We have been pleasantly surprised at how quickly the level of interest has grown and the speed at which some organisations are planning to switch. The level of interest and demand is growing and this spurs us on to make Payara better and better.

Q:How hard was the implementation of Payara Micro Edition?

To be honest, it was pretty easy to get the initial release of Payara Micro out. Not a lot of people know, but GlassFish has had an embedded edition for a long time. We’ve built on GlassFish embedded and our new Hazelcast integration to produce our first version of Payara Micro. A lot of the work we did was packaging GlassFish embedded in such a way that we could get more JavaEE capabilities and to get full web session clustering. The new Hazelcast integration gave us Dynamic Clustering which is fundamental to Payara Micro.

For us, Payara Micro marks the beginning of development in new ways of deploying JavaEE applications in radically new topologies. I’ve recently written an overview of Payara Micro which can be found on our blog: http://www.payara.co/introducing_payara_micro. We have a lot of cool ideas for taking Payara Micro in an exciting direction so stay tuned.

Q:Do you know any cool projects using Payara?

We are aware of projects using or planning to use Payara in many different cool ways e.g. for SAAS, Point of Sale, Intranet and Microservices. You should hear more about this in the near future as we are already gathering some success stories to publish on our website soon. Also, if you continue to blog about cool projects like the recent dreamIT one, I’m sure we’ll hear more on your blog ;-)

Q:What is your opinion about Java EE? Is it productive? How many of your customers are using it?

Is JavaEE productive? Absolutely! You can create applications in very few lines of code using a standard IDE like NetBeans with zero IDE setup. Producing a standard war file which can then be run on the command line with java –jar payara-micro.jar –deploy your.war. What could be more productive? You don’t need complex dependency management, complex installations or weird XML configuration files any more. I’ve got a talk at NetBeans Day in London on the 29th of May which will build and run a simple JavaEE application in 45 minutes: https://blog.idrsolutions.com/2015/03/netbeans-day-uk-friday-29th-may-2015/

Q:What are the features of the current release?

The latest release added Payara Micro; a small footprint version of Payara that requires no pre-installation and can run war files from the command line. Saying that, Payara Micro supports applications that use Java EE web profile apis along with JBatch, Concurrency and JCache. It also auto-clusters to give full web session replication across multiple Payara Micro instances.

From core GlassFish we’ve replaced the Shoal based clustering with Hazelcast as an embedded Data Grid which gives us JCache support and dynamic clustering capabilities. We’ve extended the range of JBatch persistence providers by adding support for MySQL, Oracle and DB2. Along with numerous critical bug fixes and upgrades to a lot of the underlying components like Jersey, Tyrus and Grizzly etc.

Q:What are the next cool features we can expect on Payara?

We are focusing on a number of areas.

Payara Micro is going to morph and grow into a fundamentally different way of installing and managing Java EE applications. Targeted at dynamic cloud environments and large scale installations. Our long-term goal is to make 1000 Payara Micro instances manageable from a single console on the cloud. We are looking at how RTS games present a lot of information to a user on the status of their units as a model for building a new management console for the cloud.

We have a focus on manageability and are starting to build in transaction tracing and fault finding capabilities to identify problems and make the operator aware of them as they happen so you don’t have to dig around to work out what went wrong.

Finally we are also focusing on integrating with the rest of the DevOps ecosystem with tooling around Payara for Chef, Docker, Maven etc.

Q: How expensive is the commercial support? Where is the pricelist?

Our commercial support is simply based on the number of Payara servers you are running rather than cpus, cores or power factors. We have priced commercial support in 3 tiers starting from $1,500 per server per annum for the most basic support, which we hope is set at a level that even small shops can get support. Our Enterprise support which provides full 24/7 screen sharing assistance runs to $5,000 per server per annum. We’ve also added unlimited options for organisations looking to run Payara everywhere without having to keep track of the numbers of servers they run. Of course there is also open source support on GitHub on a best endeavours basis. However we want to encourage people to buy commercial support as all the money that people spend with us on support is being reinvested into cool new Payara features. You can get the full pricelist with a feature breakdown on http://www.payara.fish/support  

Steve, thank you for the interview!


Classic Java EE 7 Workshops: Bootstrap, Effective and Architectures, July, 13th-15th
Online workshop: Java EE 7 Bootstrap

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

From Devoxx 2014: Pico Services with Java EE 7 on Java 8 and Docker

My presentation about (pico|micro|femto)services on Java EE from Devoxx 2014.

Watch on Parleys.com

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting


Classic Java EE 7 Workshops: Bootstrap, Effective and Architectures, July, 13th-15th
Online workshop: Java EE 7 Bootstrap

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

JAX-RS: Get swagger.json For Free!

JAX-RS analyzer maven plugin examines JAX-RS resources in your Java EE project and generates the swagger.json definition. There are no runtime dependencies, additional annotations or configuration required, you only have to include the plugin to your maven build and then mvn clean install your project:


<plugin>
	<groupId>com.sebastian-daschner</groupId>
	<artifactId>jaxrs-analyzer-maven-plugin</artifactId>
	<version>0.3</version>
	<executions>
		<execution>
			<goals>
				<goal>analyze-jaxrs</goal>
			</goals>
			<configuration>
				<!-- Available backends, defaults to plaintext -->
				<!-- <backend>plaintext</backend> -->
				<backend>swagger</backend>
			</configuration>
		</execution>
	</executions>
</plugin>


The recent release (swaggerina) of headlands ships with swagger-ui with the spec generated by the JAX-RS analyzer plugin. A drop-in WAR is also available.

Big thanks to Sebastian Daschner, an airhacks alumni, for this time-saver. I think you should star the repo: https://github.com/sdaschner/jaxrs-analyzer :-).

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting


Classic Java EE 7 Workshops: Bootstrap, Effective and Architectures, July, 13th-15th
Online workshop: Java EE 7 Bootstrap

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Proposed schedule for JDK 9

2015-12-10  Feature Complete
2016-02-04  All Tests Run
2016-02-25  Rampdown Start
2016-04-21  Zero Bug Bounce
2016-06-16  Rampdown Phase 2
2016-07-21  Final Release Candidate
2016-09-22  General Availability

See origin mail.


Classic Java EE 7 Workshops: Bootstrap, Effective and Architectures, July, 13th-15th
Online workshop: Java EE 7 Bootstrap

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Multiple JAX-RS URIs in One WAR

To deploy multiple JAX-RS applications with different URIs in one WAR you will have to create one javax.ws.rs.core.Application subclass per such an application (or use web.xml for this purpose). Obviously the in Java EE ubiquitous Convention over Configuration (or Configuration by Exception) cannot work any more: you will have to explicitly configure resources in each subclass by overriding the method getClasses or getSingletons:


@Path("first")
public class FirstResource {
    @GET
    public String first() {
        return "first";
    }
}


@ApplicationPath("one")
public class JAXRSConfigurationOne extends Application {
    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> resources = new HashSet<>();
        resources.add(FirstResource.class);
        return resources;
    }
}


@Path("second")
public class SecondResource {
    @GET
    public String first() {
        return "second";
    }
}


@ApplicationPath("two")
public class JAXRSConfigurationTwo extends Application {
    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> resources = new HashSet<>();
        resources.add(SecondResource.class);
        return resources;
    }
}

Both JAX-RS applications become accessible through distinct URIs: http://localhost:8080/multiple-roots/one/first and http://localhost:8080/multiple-roots/two/second

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting


Classic Java EE 7 Workshops: Bootstrap, Effective and Architectures, July, 13th-15th
Online workshop: Java EE 7 Bootstrap

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

Java EE 8 MVC (JSR-371) Example

Java EE 8 comes with a lean Model View Controller (MVC) specification for action based web frameworks JSR-371. The PDF document is 33 pages lean and pragmatic.

Project ozark.java.net is the reference implementation and it already works well on GlassFish 4.1 daily build.

To get a feeling for the spec I implemented a simplistic example based on the ECB idea:


package com.airhacks.time.presentation;

import com.airhacks.time.business.clock.boundary.AtomClock;
import com.oracle.ozark.core.Models;
import javax.inject.Inject;
import javax.mvc.Controller;
import javax.ws.rs.GET;
import javax.ws.rs.Path;


@Controller
@Path("time")
public class TimeController {

    @Inject
    Models models;

    @Inject
    AtomClock clock;

    @GET
    public String now() {
        this.models.put("time", new Time(clock.currentTime()));
        return "/time.jsp";
    }

}

The whole project with WAR and sources was pushed to github.com/AdamBien/javaee8-mvc-sample/

I also introduced the MVC sample in the 14th airhacks Q&A broadcast

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting


Classic Java EE 7 Workshops: Bootstrap, Effective and Architectures, July, 13th-15th
Online workshop: Java EE 7 Bootstrap

Newsletter: airhacksnews.com

A book about rethinking Java EE Patterns

realworldpatterns.com
...the last 150 posts
...the last 10 comments
License