Adam Bien's Weblog

More Questions Than Ever: The 16th Airhacks Live Questions And Answers

Questions for the 16th airhacks.tv at July, 6th 2015 at 6.PM. CET: http://www.ustream.tv/channel/adambien (no reqistrations, no obligations, just ask questions and watch :-)):

  1. Do you see JavaScript frameworks in your work yet? Do you see MVVM becoming popular? [Michael K.]

  2. You mentioned in an earlier video the BCE package structure. For business-cases, this is really straight forward and a good structure.

    But there are many concerns, which does not really fit in this structure (sort of cross-concern), and because of this I have the question: Where to put the following concerns/classes:

    ResourceLocator (für REST-SubResources) bzw. AbstractResources

    (for functionality, which every resource needs (like @Context definitions))

    DateUtil? / MailService?

    AbstractEntity

    ApplicationConfiguration/JaxRSConfig

    REST-Adapter/Interceptoren/Filter/Mapper

    Tracing mit LoggerExposer?

    ValidationController / Validation-Annotations (which do not belong

    to a concrete domain-object, but is rather used for any validation) [Ulrich C.]

  3. Is it ok to use DTO in a REST-method for request/response-payload?

    I would argue, that the DTO for the REST-method would separate the domain from a technical interface (REST). In addition, there is the possibility to version the interface (DTO) independently from the domain objects. Furthermore, there are some properties, which needs to be send via REST-interface, which are not needed in the domain objects. [Ulrich C.]

  4. I’m 21 years old , and i’m at 3rd year studying Computer Science. At the moment i’m creating some apps in Java and more specially in Android , i like the server side applications too.

    What i have seen so far is that Java is very powerful but we must always look at future.

    By that i mean C# with mono-project.com you can write the truly write once run everywhere that Java tried to offer.

    So i’m asking the Java guru if i should change to C# ?

    Also one more question , for next month’s Q&A : How annotations are useful ? Explain few of them.

    Thanks in advance and sorry for your time. [Giorgos]

  5. I have long been a fan of JDO and welcomed JPA. Using annotations it is very easy to persist objects. However, there are very few examples to be found about how to persist third-party objects (assuming said objects provide getters and setters that will not change). I am thinking that using a wrapper around the objects would be one way to go, but I would like to hear how you would approach this. An example would be great, too. [Eddy]

  6. Which cdi annotations are available in jsp? I want to use conversations coped to design wizard form. TY @8indaas

  7. Where would you put interceptors ?

    By definition they are “cross-cutting”.

    In the project I am currently doing I have the boundary, control and entity packages for each business “component”. Because of the cross-cutting nature of interceptors I created a fourth package currently named “interceptors”. I know ! That’s technical like “ejb” and “jsf” ! I thought about putting it in a control package. But the control package of which business component ? Just choosing at random a component seems contrary to the “cross-cutting” nature of interceptors. It would also introduce unwanted dependencies at the component
    level. Your insight on this would be much appreciated.

    Ronald

  8. could you please show how to Unit-test a boundary utilizing other @Stateless and @Inject (CDI) objects? What exactly do i need to test it fastly without having Arquillian in place?A simple example would be very helpful. Karsten

  9. Is there a way to have dynamic finders in JPA like Grails or Rails? Any plans to include this feature on the new MVC framework? Antonio

  10. What’s your reaction to this post from Juergen Hoeller: http://spring.io/blog/2015/06/04/happy-second-birthday-java-ee–7-how-is-it-going-in-production Remko

  11. This one might be a little off topic but I figured its worth a try asking. How do you go about setting up a datasource in wildfly that talks to a mysql server via ssl. I have the mysql server’s cert as well as a client key/cert combo. Brett

  12. I have question related to cooperation with JavaScript in one war. I would like to make a simple app using AngularJS but the structure of this project not directly match to the maven project so I found that I can use yeoman-maven-plugin and everything started work fine but then maven build takes too much time. I think that my approach is a little bit too much complicated :) So can you tell me how you do this, I will be grateful. Sebastian

  13. I have one more question. How to test two microservices where one communicates with the second.via REST. Exactly I wonder which interfaces should I mocked. Right now (we don’t have exactly microesrvices :)) I test both applications separately. Is it enough? Someone can for example change interface - I know that this is a strange reason but can happen :) Sebastian

  14. Question 1 : is it possible build web application MVC1 ( ozark ) with JAVAEE7 ? is it enough matured currently for large scale web application ?

    Question 2 : in JPA based app. I am facing some problem in

    em.mergeI().—————— transaction related problem.

    to overcome this problem i am use em.createNativeQuery (“update into”).

    please give comments : is it recommend write way ?

    Question 3 : what is the best practice primary key generation for large scale financial application ? (for jpa)

    a) auto-increment / not auto-increment ?

    b) table / sequence strategy ?

    Question 4 : how to do audit in JPA ? masumcse1

  15. Could you suggest how to organize CI process with jenkins and docker. I have a set of the java ee apps and for each of them I configured docker. So, I want to use jenkins to run integration tests and then rebuild image and rerun container for each application.

    As I understood the most straightforward way is to use separate VM for CI with preinstalled docker and jenkins on localhost. So, Jenkins tracks changes, updates source, then runs IT via maven and then reruns containers on localhost.

    But docker has official image for jenkins and I remember that you use it. If you run jenkins in docker container, how do you organize access to parent host for running IT, rerunning containers with apps? Or do you use docker in docker approach? Here is an example https://github.com/jpetazzo/dind Or maybe another way …. I’m really confused :) Andrii

  16. Can you provide an example of how to send text to cell phone from web application? Some sites provide an authorization code to cell phone as part of authentication. Patrick

  17. When using bce and jsf where do you place your backing beans? team4rk

Any questions left? Write a comment, edit: https://gist.github.com/AdamBien/ee8565840092cc7f39ab or ask live: https://twitter.com/AdamBien.

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

From javax.json.JsonObject To byte[] And Back

Enjoy self-explanatory, Java EE 7 code :-):


import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonReader;
import javax.json.JsonWriter;

//...
   JsonObject deserialize(byte[] content) throws IOException {
        try (ByteArrayInputStream bais = new ByteArrayInputStream(content);
             JsonReader reader = Json.createReader(bais)) {
            return reader.readObject();
        }
    }

  byte[] serialize(JsonObject object) throws IOException {
        try (ByteArrayOutputStream oos = new ByteArrayOutputStream(); 
		     JsonWriter writer = Json.createWriter(oos)) {
            writer.writeObject(object);
            writer.close();
            oos.flush();
            return oos.toByteArray();
        }
    }


//...

    @Test
    public void reserialize() throws IOException {
        JsonObject expected = Json.createObjectBuilder().
                add("name", "duke").
                build();
        byte[] serialized = serialize(expected);
        JsonObject actual = deserialize(serialized);
        assertNotSame(actual, expected);
        assertThat(actual, is(expected));
    }

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

Trouble-Free Shopping with youstice.com And Java EE 7

Interview with Matyas Bene, an airhacks.com alumni and developer at youstice.com:

What is youstice.com?

Youstice is a company and cloud-solution that helps resolve customer complaints and make shopping trouble-free. With Youstice , companies can seamlessly communicate and handle customer complaints within a matter of minutes. Similarly, disgruntled customers can get prompt assistance with their issues and save valuable time with the possibility to escalate their complaints to a neutral 3rd party for an independent decision.

Which technologies is youstice.com using on the backend?

The solution consists of 3 pillars:

  • the application itself - developed in a proprietary JVM-based, full-stack development and runtime platform, running on Tomcat,
  • the integration gateway (API) - facilitating the communication between 3rd party SW and the application, developed in J2EE,
  • plugins into various e-shop platforms and other points of entry - utilizing various technologies including PHP, Java, C# and others - as needed

You decided to use JAX-RS 2.0 / Java EE to implement the API, why?

First, we needed to be platform-independent, hence JAVA and the JVM. Choosing J2EE as our framework was a no-brainer for several reason:

  • all the components are already integrated (no wasted time by fiddling with the integration of 3rd party libraries),
  • is well-established and has a solution to the most pressing issues that a developer would encounter in an enterprise or even in the wild-wild world of cloud solutions, and
  • is open, versatile and future-proof,
  • is lean to run and quick to develop.
To give credit where credit is due, Adam Bien (and his videos about "Lean J2EE" on youtube) played a big role in changing my opinion on J2EE a couple of years ago.

How many developers are working on the API?

It was a one-man project since the beginning.

What about the performance?

Development performance is remarkable. We estimated it to 5MD (net effort) to get on feature-parity with the old-version, which we delivered (excluding translations, bug-fixing and tuning). Runtime performance has also improved. Rewriting the API to J2EE helped us to increase the number of requests handled per second three-fold on the same hardware, and, at the same time, eliminate the occasional drop-outs. This migration also opened up possibilities and functionalities that were not available before, or would have required a considerable amount of extra-code.

What is your experience with Java EE so far?

Still learning it, of course. The more I learn about and work with Java EE 7, the more I realize the level of development (and also runtime) efficiency it offers. That said, I guess it's still too easy and tempting not to follow the rules (TM) and end up with >X (=your time here) minutes of compilation times, sending development efficiency to the rock-bottom. So it either requires a really stubborn adamancy in sticking to the rules (TM) or considerable level of expertise.

I'd also like to note, that the number of quality materials specific for Java EE 6/7 is very limited. There are plenty of gems in the platform (especially in conjunction with JDK8) that are either well-hidden or difficult to understand/combine properly at first, yet are huge time-savers for the knowledgeable. A big thank you goes to you, Adam for doing your best to fill this gap. The blogs, Q&A sessions and the trainings are worth gold. So far every session I attended resulted in hundreds of lines deleted, dependencies dropped, features increased, builds simplified.

Which tools, servers, IDEs, external libraries are you using?

IDE is NetBeans. Previously it was Eclipse, but I haven't seen it since my first airhacks session in Munich. As a matter of fact, it was easy to convince my colleagues to switch as well. We utilize Jenkins, SonarQube and Jacoco for the quality cycle. The application server we use is Payara. Important 3rd party libs include querydsl, jersey and jackson. Lately, we introduced porcupine to fight back-pressure and swagger to document our API. However, the overall trend is to shrink the .war size. Currently it's half the size it was 6 months ago. It's partly Payara's advantage (ships many commonly used jars, like jackson) and partly our internal effort to get rid of external dependencies. We even consider dropping jackson in spite of the performance advantages.

You attended the airhacks.com workshops in Munich. Do you had the opportunity to chat with other attendees? What was the most interesting project?

Knowledge sharing between participants is something I especially enjoyed during the last 'micro-services' sessions. The attendants were all seasoned professionals who've brought their lessons learned from past projects. It was very interesting to see how certain challenges pop up in almost every organization (and the different solutions or attempts) as well as learn about the rare cases. Out of the projects I've learned about, the most interesting one for me was tipi.camp - AFAIK they were running glassfish on an embedded raspberry.pi device to monitor showers in camps.

Any resources, links (shameless plugs) you would like to share with us?

Partly mentioned above: Payara, QueryDSL, Orient DB, Swagger, AuthenticRoast and of course Youstice. Just because I think they're great.

Matyas, 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

Java WebSockets Client

JSR-356 comprises both: client and server endpoints.

This screencast demonstrates how to connect to a (Java EE 7) server from a plain Java client using the RI (tyrus):

Also checkout: hellsockets.

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

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

Mapping CSV Files To POJOs With Enhydrator

Enhydrator is slim, Apache licensed, Java 8 ETL (Extract, Transform, Load) library. In the 3rd episode I'm going to explain how to map rows from any source into POJOs (4 mins, 30 secs):

Also checkout Enhydrator in Action (Part 1), Type Conversions and Filtering With Nashorn (Part 2) and: https://github.com/AdamBien/enhydrator.

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 Client Rulz v0.0.2 released

The JAX-RS client rulz project was released with a single feature--the URI can be resolved using the Java's system properties:


JAXRSClientProvider.buildWithURI([SYSTEM-PROPERTY-KEY], [DEFAULT-IF-NOT-FOUND]);

Use:

<dependency>
	<groupId>com.airhacks.rulz</groupId>
	<artifactId>jaxrsclient</artifactId>
	<version>[RECENT_VERSION]</version>
	<scope>test</scope>
</dependency>

to setup rulz for your integration tests.

Usage example:


    @Rule
    public JAXRSClientProvider provider = JAXRSClientProvider.buildWithURI("java-site","http://www.java.com");

    @Test
    public void pingJava() {
        Client client = provider.client();
        assertNotNull(client);
        WebTarget target = provider.target();
        assertNotNull(target);
    }


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

One-liner: Extracting Long Statistics From A Collection of POJOs

From a collection of objects representing method calls:


public class MethodCall {

    private String methodName;
    private int duration;

    public MethodCall(String methodName, int duration) {
        this.methodName = methodName;
        this.duration = duration;
    }

    public String getMethodName() {
        return methodName;
    }

    public int getDuration() {
        return duration;
    }
}

useful statistics data can be extracted with Collectors.summarizingLong:


import java.util.ArrayList;
import java.util.LongSummaryStatistics;
import java.util.stream.Collectors;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import org.junit.Before;
import org.junit.Test;

public class LongSummaryStatisticsTest {

    private ArrayList<MethodCall> calls;

    @Before
    public void provideTestData() {
        this.calls = new ArrayList<>();
        calls.add(new MethodCall("save", 90));
        calls.add(new MethodCall("find", 10));
        calls.add(new MethodCall("delete", 2));

    }

    @Test
    public void computeStatistics() {

        LongSummaryStatistics statistics = this.calls.stream().
                collect(Collectors.summarizingLong(MethodCall::getDuration));

        assertThat(statistics.getCount(), is(3l));
        assertThat(statistics.getMin(), is(2l));
        assertThat(statistics.getMax(), is(90l));
        assertThat(statistics.getAverage(), is(34d));
        assertThat(statistics.getSum(), is(102l));
    }

}


The code above was extracted from "Effective Java EE" online course (coming soon), the second part of the Java EE Bootstrap at 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

Writing POJOs To XML--Without Annotations

With the utility classes introduced in JDK 1.4 XMLEncoder and XMLDecoder you can serialize and deserialize POJOs with property accessors (aka JavaBeans) with some caveats:

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

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

The Difference Between SOA and Microservices Architectures

SOA was not about SOAP and microservices are not about REST.

In theory there is no difference. The SOA definition could be also applied to microservices architecture as well:

"Services are unassociated, loosely coupled units of functionality that are self-contained. Each service implements at least one action, such as submitting an online application for an account, retrieving an online bank statement or modifying an online booking or airline ticket order." [SOA definition from wikipedia]

Also a microservice architecture could be challenged (often killed) with the same questions as a SOA.

In practice SOA was applied to expose, reuse and expose business services at enterprise level. Microservice architectures are used to structure individual applications. Because it is easier to control a single application than a whole enterprise, microservices are less ambitious and more pragmatic.

See you at Java EE Workshops at MUC Airport, particularly at the Java EE Architectures workshop!


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

With POJOs To XML And Back With JAXB

JAXB comes out-of-the-box with JDK and makes it trivial to write and read POJOs from XML:

The entire enhydrator configuration (Pipeline) is persisted with JAXB.

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