Java Lobby Announcements

Subscribe to Java Lobby Announcements feed
Recent posts in Java on DZone.com
Updated: 3 hours 17 min ago

Architecting a Testable Web Service in Spark Framework

Thu, 2017-07-06 12:01
Background of the Spark and REST Web App Testing

I’m writing a REST web app to help me manage my online training courses. I’m building it iteratively and using TDD and trying to architect it to be easily testable at multiple layers in the architectural stack.

Previously, with RestMud, I had to pull it apart to make it more testable after the fact, and I’m trying to avoid that now. I’m using the Spark Java Framework to build the app because it is very simple and lightweight, and I can package the whole application into a standalone jar for running anywhere that a JVM exists with minimal installation requirements on the user. Which means I can also use this for training.

Categories: Java

Reactive Spring 5 and Application Design Impact

Thu, 2017-07-06 08:01

The 5th version of Spring Framework brings Reactive Programming support. In the same time, trying to put reactivity into practice brings a number of new challenges. I want to share my learnings what are the new rules of reactive design and how they can influence Spring-based applications development. This post assumes the reader has already a prior knowledge of the new features in Spring 5 and Reactor Project.

Functional Programming

An unavoidable impact of Reactive Programming with Spring 5 is shifting towards functional transformations. When non-blocking implementations, such as Spring’s WebClient or Spring Data’s reactive repositories, are used, we have to deal with reactive data types: Mono and Flux. To stay non-blocking, the result of the queries can be only accessed through functional transformations.

Categories: Java

Spring Boot Web Test Slicing

Wed, 2017-07-05 23:01

Spring Boot introduced, if you'll recall, test slicing a while back, and it has taken me some time to get my head around it and explore some of its nuances.

Background

The main reason to use this feature is to reduce boilerplate. Consider a controller that looks like this, just for variety written using Kotlin.

Categories: Java

Microservices and Spring Cloud Config Server

Wed, 2017-07-05 19:01

With microservices, we create a central config server where all configurable parameters of micro-services are written version controlled. The benefit of a central config server is that if we change a property for a microservice, it can reflect that on the fly without redeploying the microservice.

Before the microservices era, we created a properties files where we maintained our configurable parameters so that if we changed the parameter values or added or deleted a parameter, we generally needed to restart the application container. Moreover, think about the environments. Often, we have Development, Staging, and Prod, and each has separate URL for different services like JMS, JNDI, etc. Also, if the environment changes, we need to pick right properties file. For instance, for development, we need to load the development property file. Spring provides the Profile concept where, based on the passing profile, Spring loads the appropriate environment's properties.

Categories: Java

Java 9 Modular Development (Part 1)

Wed, 2017-07-05 13:01

Modularity is a way of writing and implementing a program as a number of unique modules. It avoids monolithic design, and it helps in reducing a system's complexity, minimizing coupling, and a few other features.

Java 9 modularity has been a big project of around 5 years of work that will change a lot of what we do today.

Categories: Java

AutoWiring Spring Beans Into Classes Not Managed by Spring

Wed, 2017-07-05 10:01

In my previous article JPA Auditing: Persisting Audit Logs Automatically using EntityListeners, I discussed how we can use Spring Data JPA automate auditing and automatically create audit logs or history records and update CreatedBy, CreatedDate, LastModifiedBy, LastModifiedDate properties.

So in order to save history records for our File entity, we were trying to autowire EntityManager inside our FileEntityListener class before we learned that we could not do that.

Categories: Java

Java Command-Line Interfaces (Part 5): JewelCli

Wed, 2017-07-05 07:01

After looking at command-line processing in Java with Apache Commons CLIargs4jjbock, and Commandline in previous posts, I turn attention in this post to using JewelCli to accomplish similar processing of command-line arguments in Java.

Several Java command-line processing libraries use annotations to define the command-line options. Three of the four libraries covered in this series of posts so far use annotations and so does JewelCli. JewelCli is unique among the libraries I've covered so far because its annotations are applied on a Java interface rather than on a Java class or class's constructs. The next code listing demonstrates how to use annotations on a Java interface to implement the "definition" stage of command-line parsing with JewelCli.

Categories: Java

Are Java 8 Streams Truly Lazy? Not Completely!

Tue, 2017-07-04 20:01

In a recent article, I’ve shown that programmers should always apply a filter first, map later strategy with streams. The example I made there was this one:

hugeCollection .stream() .limit(2) .map(e -> superExpensiveMapping(e)) .collect(Collectors.toList());


Categories: Java

What's New in Spring Framework 5?

Tue, 2017-07-04 12:01

Spring Framework 5.0 is the first major release of the Spring Framework since version 4 was released in December of 2013. Juergen Hoeller, Spring Framework project lead, announced the release of the first Spring Framework 5.0 milestone (5.0 M1) on July 28, 2016.

Now, almsot a year later, we are looking forward to Release Candidate 3 (RC3) to be released on July 18, 2017. This is expected to be the final release on the roadmap to the first GA (General Availability) release of Spring Framework 5.0.

Categories: Java

Authentication Using Actions in Play Framework

Tue, 2017-07-04 07:31

Actions plays an important role in Play Framework, the requests received by a Play application are handled by an Action. Action composition is an incredibly powerful way to enhance or restrict controller behaviour. In Play Framework controllers consist of methods that create Action objects to handle the incoming requests.

A play.api.mvc.Action is basically a (play.api.mvc.Request => play.api.mvc.Result) function that handles a request and generates a result to be sent to the client. 

Categories: Java

Pages