Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
45thAirhacksQ&A.md

dempile commented Nov 8, 2017

Hi Adam,
Have you tryed Beanshell and how do you compare it to a Groovy, Scala, or newly Kotlin ?
Can Kotlin be used in a JEE Application, if yes in which part of the application it's more useful.
What's the best solution to create reports instead of JasperReport ?

taysay commented Nov 12, 2017

Hi Adam,

Please how to you handle RESTful header custom parameters behind an apache httpd service. Apache seems to drop none standard parameters on the http header. Thank you so much.

afrunt commented Nov 12, 2017

Hi Adam!
I was inspired by your videos about the java ee and now I want to remember, how to live without tons of dependencies.
The last question is, how could I achieve switching between two persistence units like so

public abstract class DAO<ET, KT, DT extends DAO<ET, KT, DT>> implements WithEntityManager {
    @PersistenceContext(name = "corePU")
    private EntityManager em;

    @PersistenceContext(name = "odsPU")
    private EntityManager odsEm;

    private boolean ods;

    private DT odsInstance;

    //obsolete datasource
    public DT ods(){
        //should return the new managed bean of the same DAO type, but with ods==true to choose the odsPU instead of corePU
    }

    @Override
    public EntityManager getEntityManager() {
        if (ods) {
            return odsEm;
        } else {
            return em;
        }
    }
}

@Stateless
public class PaymentDAO extends DAO<Payment, Long, PaymentDAO> {
    public PaymentDAO() {
        super(Payment.class, Long.class);
    }
}

@Named
@Path("/payment")
@Produces("application/json")
@Consumes("application/json")
public class PaymentResource {
    @Inject
    private Logger logger;

    @Inject
    private PaymentDAO paymentDAO;

    @GET
    @Path("/{id}")
    public Payment payment(@PathParam("id") long id) {
        //should be able to work this way
        //payment from core DS
        Payment payment = paymentDAO.find(id);
        //payment from ODS
        Payment paymentOds = paymentDAO.ods().find(id);
        return payment;
    }
}

I did it before with Spring, where I was able to create such instances on the fly if they doesn't exist (using applicationContext and beanFactory). What should I do with CDI to achieve the same, I mean, how to create the identical bean with toggled flag and different qualifier and return it? The actual problem is to use the same xxxDAO contract with different datasources without additional parameters in methods definitions. DAO's are stateless, so I don't able to just toggle those flag.

I found some solution, that looks like below. Is it right to do it this way? It works, but maybe there is some other good approach to do the same.

public <T> T ods() {
        if (odsInstance != null) {
            return odsInstance;
        }

        odsInstance = new Unmanaged<>(getClass())
                .newInstance()
                .produce()
                .inject()
                .postConstruct()
                .get()
                .setOds(true);
        
        return odsInstance;
}

Thanks !

Owner

AdamBien commented Nov 13, 2017

@AdamBien what do you think about using @kotlin in pair with java in JEE project just like @springframework did ?

— omar Alvarez (@denpile) November 13, 2017

Hi Adam,

a small observation about conversation
about frameworks/technology in teams,...:

I‘ve noticed that there is a tend to more/growing intrinsic motivated „discussions“ rather than talking about the technology judicious (Dunning-Kruger-Effect) in teams, ...

For example: „We have to use this framework. Google uses it. It is so great“

Beside of the fact that correlation and causality have been flipped by this statement it ends sometimes the discussion because for the person it is no more relevant what others say,...

Your experience with deadlocked conversations?

Greetings from Munich

Hi Adam,

  1. Do JPA Implementations like EclipseLink, Hibernate, etc use JDBC internally?
  2. Do JPA implementations use an internal cache which then is synchronised with DB later?
  3. Why do we need Connection Pools (DB Connection) in application servers? (Can each web applicaiton connect to DB as we could do in Java SE?)

Thanks a lot! (I hope you do not forget any of my questions)

Hi Adam

How do you decide the optimum Amazon AWS instance type and how do you combine this with Glassfish configuration for optimum performance.

Thanks!

Hi Adam, another question.

How do I upgrade a Glassfish application without losing availability?

MougLee commented Nov 26, 2017

Hi Adam, first, thank you for all the good information you are providing :)

I am playing with Java EE 8 security API and I wanted to create a JWTAuthenticationMechanism by extending the HttpAuthenticationMechanism class.

@Override
    public AuthenticationStatus validateRequest(HttpServletRequest request, HttpServletResponse response, HttpMessageContext context) {
        LoginRequest loginRequest = null;
        String token = extractToken(context);
        if (isLoginRequest(request) && (loginRequest = parseLoginRequest(request, context)) != null) {
            return tryLogIn(loginRequest, context);
        } else if (token != null) {
            return validateToken(token, context);
        } else if (context.isProtected()) {
            // if there are no credentials and the resource is protected, we response with unauthorized status
            return context.responseUnauthorized();
        }
        // there are no credentials AND the resource is not protected -> instruct the container to "do nothing"
        return context.doNothing();
    }
  1. The problem is that when I return a context.responseUnauthorized();, I get HTML code in response with status 500 and javax.ejb.AccessLocalException: Client not authorized for this invocation error. I would prefer to get a json response.
    What is the best way to handle this?
  • throwing an exception that extends WebApplicationException that returns the json response instead?
  • using an ExceptionMapper for javax.ejb.AccessLocalException (this is probably a bad idea if you have anything else than just REST API)?
  • something else? :)
  1. Let's say my code exposes REST API and has a "jsf app" and I want to use two different authentication mechanisms (JWT and Form based or Certificate based). What is the best way to achieve that?

Thanks! :)

Hello Adam ,

I totally agree with your perception about front end js apps.(just use the platform).

I even made a simple Single Page App based on WebComponents and even added route capabilities.

But at one point of time you will need more complex components like tables , etc etc.

How do you deal with that ?

Thank you!

swhp commented Nov 27, 2017

Hello Adam,

I am watching your screen cast about Java EE, Docker, and Cloud such as Openshift, Amazon, etc.
I have better understanding how to deploy Java EE on the cloud with Docker, but I'm still not understand how you handle the database connection? Did you also deploy the database inside Docker container or you're using Cloud Relational Database? Would you share your experience that elaborate Java EE and relational database on Cloud?

Thank you!

VAGGELIS commented Nov 27, 2017

Hi Adam,
Congratulations for the good work. I'd like to ask a question about a specific requirement i have in my project.
How can i have a transaction writing/updating to two different databases the same data? I whould like all the data to be persisted into two dbs syncrhonously. Should i look for XA Transaction? Any suggestion? (i'm using wildfly 8 and mysql).

Vaggelis

Hi Adam,

You already gave a kinda political answer to a similar question last month. But as you asked me on Twitter, to ask again, so I do:

How do you feel with the fact that the Java world does not have a solution for PWA with offline focus?

I think this is the toughest target environment for a Java developer as there is no official solution.


Let me add some more detail:

By your opinion, what's the Java way to implement a PWA with focus on heavy offline functionality and mobile devices?

Here some potential solutions:

a. for the programming language part:

  1. Transpilers (either of Java source- or bytecode)
    like GWT, JSweet, TeaVM or CheerpJ,
    none of them official nor enterprise traction though.
  2. Using JavaScript or, if sensible for the concrete application,
    any of it's derivants like TypeScript,
    thus, leaving the Java world.

b. for the GUI part:

  1. JavaFX ports to the browser (currently it just renders JavaFX
    on a server to be displayed in a browser, but an offline
    solution was announced).
  2. Using vanilla JavaScript DOM or JavaScript frameworks like
    React, Angular, Vue etc.

Where there is still no solution for the combination a1+b2 or the other way around, as far as I know.

For the case of answer 2 of either part: Isn't that kinda giving up Java?
Remember: I was talking about PWA with heavy offline functionality.
To me it seems, the Java world has no answer for this.

Thanks!
... Michael

t-shaguy commented Dec 4, 2017

Dear Adam,

Thank you very much for all the wonderful work. Please I have a question relating to @suspended AsyncResponse response in Jax RS, now
I have my Restful Service call a MicroService implemented with JAX RS,

so I have this .

@post
@path("balance")
@jwttokenneeded // for JWT
public void doBalance(@suspended AsyncResponse, String reqtestStr)
{
Supplier balanceRequest = () -> baltarget.request().post(Entity.text(requestStr));
CompletableFuture.supplyAsync(balanceRequest, enquiry)// implementing bulkheads pattern @thanks to Adam Bien
.handle(this::doHandleResponse)
.thenAccept(response::resume).get(); // blocks
}

now balanceRequest returns the response object, I want a situation where I can manipulate the Response message (status and all that so I can propergate the response from balanceRequest to the caller , what happens now is the caller always gets the http status code 200. But my intention is to be able to control and define the http status and other components in the response.
Thank you

Nurudeen commented Dec 5, 2017

Hi Adam ,
I am trying to encrypt form data "user name and password field " before sending to browser .
The form is in a jsp page posting the parameter to a servlet . I want to encrypt the form fields before calling the servlet class because these details always appear as plain text before reaching the application server .
I have https on my URL but these details still shows as plain text in the body of the request when users tries to login .

tobciu commented Dec 5, 2017

Hi Adam,
in JavaEE8 how can i convert LocalDateTime to a json string so i can parse/use it in javascript?
Is there a posibility now to define a converter such as the AttributeConverter from JPA 2.1?
Thank you :-)

dawuzi commented Dec 5, 2017

Hi Adam,

I have noticed that a connection timeout exception when using JAX-WS on wildfly (10.1.0.Final in my case) has an javax.ejb.EJBTransactionRolledbackException as one of the underlying causing exception in the stacktrace. It then marks the current transaction as Rolled back even when the exception is caught and handled. The issue is that further actions executed afterwards which requires a valid transaction (especially database actions using JPA like create and update) would throw an exception saying that the current transaction has been rolled back.

I currently use a work around by invoking further actions using a method marked with the attribute @transactionattribute(TransactionAttributeType.REQUIRES_NEW) so it they can be executed with a valid new transaction. However, I believe there has to be a way to make the connection timeout exception from the JAX-WS not roll back the current transaction especially when the exception was properly handled with a try and catch block.

GADNT commented Dec 6, 2017

Hi Adam

In java 9 we have https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/CompletableFuture.html#orTimeout-long-java.util.concurrent.TimeUnit method that permit to us to wait an amount of time and get the result in a non-blocking way beside the https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html#get-long-java.util.concurrent.TimeUnit- method in java 8 that block for result(if I understood it correctly).

If we want the behavior that java 9 method have , what might be the alternative for java8 ?

another subject:
How do you choose the type of the database in your projects? Relational database vs document database

Finally 👍 for you effort during this year and the knowledge's(cool stories) you spread to us.

Thank you
Gabriel

DKLEEE commented Dec 6, 2017

Hi Adam,

what is your prefered way for connecting a Desktop Application (Eclipse RCP as "thin"client) with a JavaEE Server for back end?
Is Remote EJB still a thing, should we go with REST to maybe switch sometime to Web, WSDL?
Any best practices?

Thanks

kgampe5 commented Dec 6, 2017

Hi Adam,

assuming we have several JEE microservices running in different containers. Could be 4 services or 8, depends on whatever. Each microservice would provide standard information like "current internal status of service running in container" through a REST service.

Now, i want to build an overall status application (may be a single JEE app) which shows the status of all running microservices or provides an "action call" e.g. refresh something in a "known" microservice.

How would you technically implement the "register myself (microservice) to status app" feature in JEE which enables the status app to provide information or action calls of/to each microservice without knowing them by configuration? How do i ensure that only microservices are listed which are online?

regards
Karsten

newk5 commented Dec 6, 2017

Hello Adam,

I've recently found out about your youtube channel and your blogs, and those have been very helpful, thank you for all the work you've put into it. I have 2 questions I'd like to make

1- In a JSF JavaEE7 application running on payara, is there a way to know through some sort of event/callback/listener when the user's session expires? I'm using JAAS-Based authentication on the payara server using a JDBCRealm. When the user logs in, the session object is stored in a CDI Session-scoped bean.

2- What's your opinion on using vert.x instead of javaee for a microservices based application? Do you think it's a worthy alternative compared to javaee? I'm trying to decide which one to use and the whole ecosystem around JavaEE and its maturity attracts me more than vert.x, however vert.x seems to be more scalable. I've tested scalability using JMeter for a vert.x and a JAX-RS based webapp and saw that vert.x was able to reach double the throughput of javaee and use less resources (I've also tested with @suspended asyncResponse). JAX-RS and JavaEE7 microservices are still a bit new to me so I'm not sure if there's a better way to configure my JAX-RS app to be more scalable and unfortunately I could not find many vertx vs javaee comparisons online.

Thank you and greetings from Portugal!

Nurudeen commented Dec 6, 2017

Hello Adam ,
I often have below error message when my applications runs , what could possibly be the cause of the error ?

[#|2017-12-06T13:37:26.769+0100|WARNING|oracle-glassfish3.1.2|javax.enterprise.resource.corba.ORBUtil|_ThreadID=602223;_ThreadName=Thread-2;|IOP00410025: Write of message exceeded TCP timeout : max wait time = 6,000 ms, total time spent blocked, waiting to write = 7,280 ms.
org.omg.CORBA.COMM_FAILURE: WARNING: IOP00410025: Write of message exceeded TCP timeout : max wait time = 6,000 ms, total time spent blocked, waiting to write = 7,280 ms. vmcid: OMG minor code: 25 completed: No

Kindly advice for a possible solution .

Hi Adam.
What would you prefer for a Server push implementation: websocket or SSE? Are These Protocols suitable for long living client to server Connections?

Thank you and Best regards from Hamburg.

Bastian

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