Skip to content

Instantly share code, notes, and snippets.

@AdamBien
Last active April 11, 2016 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamBien/9a8ad5beec52199f1d13 to your computer and use it in GitHub Desktop.
Save AdamBien/9a8ad5beec52199f1d13 to your computer and use it in GitHub Desktop.
25thAirhacksQ&A.md

Ask questions and see you at 11th April at 6.PM. CET: http://www.ustream.tv/channel/adambien Also see archives: airhacks.tv

  1. Java EE 8 News
  2. 2 years of airhacks.tv celebration (now really 2 years)
  3. Do you think NetBeans is still a good IDE for JEE, Java, HTML, SPA, etc, development in 2016? I'm currently faced with a number of developers who seem to love IntelliJ, but I'd love a free alternative for some of our projects. We're currently using Eclipse (and STS), but that platform doesn't agree with me which is why I'm considering NetBeans. I know I should just make up my own mind about this, but I appreciate your work a lot and would love to hear your opinion.
  4. How to access the "other side" with afterburner.fx?:
@Service
public class Receiver {
    private long counter = 0;
    
    @PostConstruct
    public void init() {
        System.out.println("Receiver.init()");
    }
 
    @RabbitListener(queues = "hello")
    public void receiveMessage(Message message) {
     String s = new String(message.getBody());
//     msgRepository.save(new Msg(null, s));
     
        Platform.runLater(() -> {
         counter++;
         System.out.println("Received <" + s + ">" + counter);
         //I want to print this log to JavaFx Label
        });
    }
}
@abhirockzz
Copy link

Hello Adam!

I have a few questions revolving around the EJB vs CDI topic (things I have picked up from Java EE EG discussions)

The underlying themes for JavaEE.future (Java EE 8/9) seem to be the following

  • Moving from multiple Java EE component models to a one based on CDI
  • Modernising the implementations of the EJB features using CDI based model

Questions

  • EJB component model predates CDI. Was this unification considered during Java EE 6 when CDI was first introduced as a part of the platform? (The fact is that Java EE 6 enhanced the EJB spec itself)
  • What is the benefit of extracting EJB features (pooling, concurrency, scheduling etc.) into separate specifications and then implementing them through CDI (maybe extensions) ? What do we stand to gain - Performance, efficiency (if yes, this is an implementation specific detail)? Why not just continue to use @Stateless/@Singleton/@stateful and get everything all at once ?
  • Assuming that both CDI and EJB continue to co-exist, what’s wrong with having two models (except of course the learning curve) ? (again) What do we stand to lose ?
  • Assuming CDI will rule the roost, will EJB as a spec be deprecated ? Is that safe ?

Cheers!
Abhishek

@vonix2000
Copy link

Hi Adam,

I have a few questions.

  1. BCE pattern
    In your last show I saw that you used controls from boundaries of another business component. I thought that classes inside control package are not exposed to other business components. Is boundary only for external usage? If I only have JAX-RS access, would I only place the REST endpoint there?
  2. AsyncResponse for CRUD
    If I have simple CRUD operations via REST, which usually take less than a second: does it make sense to use @Suspended AsyncResponse with a dedicated ManagedExecutorService to gain more robustness? Is there any best practice?
  3. Best practice for long JavaEE tasks
    Is there a good pattern how to manage long running tasks (several minutes) in JavaEE via REST? So far I immediately return 201 with an id (for client long polling) and start the task asynchronously, which returns a Future. To manage the tasks (monitor status, cancel, ...) I keep a reference of all Future results in a ConcurrentHashMap inside a @Singleton EJB. Is there any better (leaner) approach to achieve that?
  4. ES2015 vs Typescript
    I plan to develop a new web application and wanted to use Angular 2 right away. First I wanted to write it with ES2015, but then I saw that Angular 2 itself is written in Typescript. What would you recommend to use?

Regards,
Simon

@suikast42
Copy link

Hi Adam,
I am thinhink about to broke our monolithic (Plain Old :-D ) Java EE architecture down to microservices. The biggest thing what I am thinking about ist the transaction management across micro service calls. REST ist stateless EJB remooting doesn't support transaction through the system boundary. Have you any suggestions ?

@sharpedavid
Copy link

Hi Adam,

Is JMX still useful now? Will it be useful in the future?

I learned about JMX (Java Management Extensions) only a couple of weeks ago. You have a few old blog posts (5+ years) that reference JMX. Most recently you posted about "JSR 373: JavaTM EE Management API 2.0" which mentions that "The expert group should also consider whether the existing MEJB and JMX APIs should be designated as Proposed Optional".

On the surface JMX seems useful for monitoring and configuration, but when I think about it I don't know if I should bother learning it when I have REST instead. I can't think of anything JMX does that REST can't do better.

p.s. I found some current projects and libraries that are using JMX for things like https://jolokia.org/, http://hawt.io/, and https://dropwizard.github.io/metrics/3.1.0/getting-started/#reporting-via-jmx, but overall very few references to JMX in the Java community.

@dwamara
Copy link

dwamara commented Mar 16, 2016

HI Adam,

long time since I last posted a question here and more longer time since I last visit the airhacks in MUC,
I am architecturing and will have to implement a platform for a client that needs a lot of asynchronous calls. At the moment (unless the requirements changes), it looks like this and as for client's requirements it should be all microserviced (!):

  1. a method let's say "callFromMain" in a class MainCallingClass should make a first call to a service A that should return a List of values, said aList
  2. aList should then be used as parameter for services B, C, D and E. As they are all independent from one another and to spare time, the calls to B, C, D and E should not be sequential but asynchronous, and they all belong to different microservices parts (they will be in separate war files).
  3. at the end, the results from B, C, D and E (all results are also List) should be under certain conditions aggregated in MainCallingClass to make a final List that will be the end result.

How should such a bunch of asynchronous calls should be implemented so that it works really as it should? Needless to say, it is possible that the client in the future adds more services to the list B, C, D and E, thing which is not yet clear at the moment but as I know the client and how he works with his requirements, it is 95% possible.

I hope it was clearly enough explained,

Regards,
Daniel

@matafe
Copy link

matafe commented Mar 16, 2016

Hi Adam,

Do you how how to implement or any existent product or standard using JAX-RS for "Retrieving a Partial Response" like the Youtube API (https://developers.google.com/youtube/2.0/developers_guide_protocol_partial#Fields_Formatting_Rules) or Facebook?

The basic idea is when my rest client request for some server resource... I want to customize witch data it should retrieve from server (I do not want to bring all the entity attributes). I.E. Fetch the person by id (bring id and name), fetch the person by id (bring id, name and addresses),...

Regards,
Mauricio

@sharpedavid
Copy link

I was listening to one of the recent Airhacks and I think you mentioned that you rarely put business logic in Entities. I dug up these old blog posts of yours:

These are almost 10 years old, so I understand your thinking should change. I'm just bringing these up for comparison.

I've read your description of ECB/BCE, and looking at Lightfish I see no business logic in the Escalation entity. On the other hand, in javaee-bce-archetype you have a small amount of business logic in Registration.

It seems like good object-oriented design to put business logic in our business objects. Do you have some updated advice on this?

I think I'm not alone in feeling that thin entities and EJBs pull us away from object-oriented design. EJBs aren't objects, and if our entities are thin, they're anemic objects. I don't think object-oriented design is some Ultimate Paradigm that is only productive when we strictly adhere to it, but to me it just seems like a good idea for business objects to "own" their business logic.

@matafe
Copy link

matafe commented Mar 16, 2016

Just a note: I was taking a look at you project "doit", did you try to deploy on wildfly (8,9,10)? I think there is a problem with CDI and JPA (EntityListener).
Caused by: org.jboss.weld.exceptions.IllegalArgumentException: WELD-001456: Argument resolvedBean must not be null
Regards.

@robertBrem
Copy link

Hi Adam
I really like your show and that you take time for us!

  • I adopted your way of building JavaEE applications with Docker. If I understand it correctly you do a docker build on every push. For the system tests the build happen in your own docker registry, so that your server can pull and run the new container. Or do you have a hook for Jenkins that checks out the Dockerfile and build it on the server. Do you even use a docker registry or is there no need for it?
  • Do you use the same war for your system tests that get deployed in production later? If you need a bearer token (from keycloak) to access the services, how do you handle that? Security in system tests in general.
  • I try to use CorrelationID for my services. I used the ContainerRequestFilter and the ContainerResponseFilter. DemoProject. The filters are very neat. What I don't like is the call from another service:
    @GET
    public void getOrders(@Suspended AsyncResponse response, @Context HttpHeaders httpHeaders) {
        CompletableFuture
                .supplyAsync(this::getOrders, mes)
                .thenApply(new Function<String, String>() {
                    @Override
                    public String apply(String message) {
                        List<String> requestHeader = httpHeaders.getRequestHeader(CorrelationIDRequestFilter.CORRELATION_ID_KEY);
                        String paymentResponse = paymentTarget
                                .request()
                                .header(CorrelationIDRequestFilter.CORRELATION_ID_KEY, requestHeader.get(0))
                                .get(String.class);
                        return message + " with payments: " + paymentResponse;
                    }
                })
                .thenAccept(response::resume);
    }

It is working but I don't want do that for every call. Is there a better way to implement correlation ids in Java EE?

@viktorcitaku
Copy link

Hi Adam,

  • How would you manage in architectural aspect a huge system, would you stick with "just WARs" or probably you would choose EARs (WARs + JARs) instead? (I saw this http://www.adam-bien.com/roller/abien/entry/beans_with_both_views_local and in the examples you were using @Remote and @Local)
  • Do you think the new MVC action based specification is a bit late in Java EE 8, since now most of projects go with RESTful services?

And I have a request, where can I find videos from you, regarding JEE, FX, etc. (So far I searched and watched on YouTube), and another thing or question is, why you don't live stream on YouTube?

Best regards :-)

@iokhahon
Copy link

Hi Adam,
I am coding a JAX-RS resource class with several sub resource classes.
In your video "A little REST with JAX-RS 2.0 and JavaEE 7" you instantiated your sub resources like this :-

@get
@path("{first}-{last}")
public Developer developer(@PathParm("first") String first, @PathParm("last") String last) {
return new Developer(last, last);
}

Another similar example from another video :-
@context
ResourceContext rc;

@path("/chickens")
public ChickenResource chickenResource() :
return rc.initResource(new ChickenResource());
}

The problem is that these sub resource classes are instantiated with new, so CDI does not manage them.
Therefore, if these sub resource classes need instances of other control or entity classe(s) they cannot use @Inject.

One possible solution is to @Inject into the "parent" resource class instances of all the possible classes the sub resource classes might need, then pass references to them on the various constructors :-

@Inject
DeveloperStuff ds;

@Inject
ChickenStuff cs;

@Inject
DeveloperStuff ds;

@path("{first}-{last}")
public Developer developer(@PathParm("first") String first, @PathParm("last") String last) {
return new Developer(ds, last, last);
}

@path("/chickens")
public ChickenResource chickenResource() :
return rc.initResource(new ChickenResource(cs));
}

This seems highly inefficient since for a given request not all the possible instances are going to be required.
Is there is a way of deferring the instantiation or ChickenStuff and DeveloperStuff until we need them on the appropriate @path methods perhaps by using a scope?
Or, is another approach for @ChickenStuff and @developerstuff to use @produces which might somehow work around the fact CDI has disowned classes instantiated with new?

You insight would be greatly appreciated, keep up the great work, your Airhacks are very inspirational.
Mike

@enji7
Copy link

enji7 commented Apr 1, 2016

Hi Adam,

  • Other Java sources: Which other Java-related blogs / screencasts / periodicals can you recommend?
  • Screencast software: Which software do you use for recording your screencasts?
  • Reliable checkpoints in Java EE 7 Batch Processing (JSR 352): It appears that it is not specified how checkpoints are persisted by the application server. Hence, checkpoint data can be lost (e.g., due to a hard drive failure on the application server's machine). When the batch writes data to a database, checkpoint data must instead be written to the database using a custom implementation (which is unfortunate). Can you confirm this?
  • Asynchronous processing of client requests: What is the benefit of freeing the initially processing thread by passing over to another (asynchronous) thread instead? Does it make a difference if the pool for the initially processing threads is exhausted, or the pool for the async threads? One advantage I could think of is that separate pools allow us to define separate max counts for different parts of the application: If one function X of the application is currently overloaded, the application is still capable of serving requests to other functions.

Thanks & happy hacking,
Nenad

@gbourant
Copy link

gbourant commented Apr 3, 2016

Hey Adam,

  • Security
    I'm moving a PHP spaggeti Project into a JavaEE one, exposing REST Services.
    To secure the API i'm using Keycloak.
    Could you recommend me any other parts where i have to shield the App (except the exposed API)?
  • I had a class like the following
@Stateless
public class A {
@Inject
Clazz C;
}

after i implemented it with this way and Injection stopped working , to make it work i used @Local instead of @stateless , why it didn't work?

@Local
public class A implements B{
@Inject
Clazz C;
}
  • I want to share common fields and beheivor at all entities , how to achive something like the following ? (JPA doesn't save the extened fields).If possible the extended fields to be on the same table.
@Entity
public class A extends EntityLogger {
 @Id
 @GeneratedValue
 private Long ID;
 private String Name;
}

public class EntityLogger {

    @Temporal(TemporalType.TIMESTAMP)
    Date created;

    @Temporal(TemporalType.TIMESTAMP)
    Date updated;

    @PrePersist
    public void created() {
        created = new Date();
    }

    @PreUpdate
    public void updated() {
        updated = new Date();
    }
}

Thanks.

@masumcse1
Copy link

I have need a sample project that are build on java ee 7 with following criteria
JSF2.2 + Rest + Service (EJB/cdi) + JPA + any db

*** crud JSF2.2 with Rest client

@masumcse1
Copy link

i want to learn SAML with JAVA EE and implement my personal project .
SAML with java ee
please give me a idea how to do this one ?

@acll19
Copy link

acll19 commented Apr 7, 2016

When I face a new project, can I think of it in a microservice architecture way from the beginning, or it is just for "refactoring" a monolithic application?

@Chilis92
Copy link

Hi Adam,

I'm using JMS and i have one web application that works as a producer and I have another web application (Consumer) with an MDB, my MDB is implementing MessageListener interface so I'm getting the messages in the console properly. The problem is that I'm not able to send those messages to my JSF page. I tried to create an stateless EJB to get the messages and then send them to the JSF page but it does't work. So do you know if there is a way to call like a JSF back bean from MDB to display message on the view?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment