Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
61stAirhacksQ&A.md

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

Also checkout recent episode:

60th airhacks.tv

Please keep the questions Java EE-stic. Means: as short and as concise as only possible. Feel free to ask several, shorter questions.

@nkengasongatem

This comment has been minimized.

Copy link

nkengasongatem commented Mar 16, 2019

Hi Adam, I am working on project which uses JS at the frontend and Jakarta EE at the backend. I would like to persist submitted form data containing a picture, and save this picture as blob (despite the shortcomings) in a MySQL database. I tried the method below but JSONB fails during deserialization of the 'candidatePicture' field.

 var file = URL.createObjectURL(document.getElementById("candidatePicture").files[0]);
         fetch(file).then(response => {
            response.blob().then(photo => {

             const reader = new FileReader();

            // Start reading the blob as text.
            reader.readAsText(photo);
            
            // This fires after the blob has been read/loaded.
            reader.addEventListener('loadend', (e) => {
                
                const text = e.srcElement.result;
                var ballotData = $("#addBallotForm").serializeArray();
                var ballot = {
                    "candidateName": ballotData[0].value,
                    "positionName": ballotData[1].value,
                    "candidateNIC": ballotData[2].value,
                    "partyname": ballotData[3].value,
                    "candidateSlogan": ballotData[4].value,
                    "candidatePicture": text,
                    "actionPlan": ""
                };
                console.log(JSON.stringify(ballot));

                $.ajax({
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    crossDomain: true,
                    type: "POST",
                    enctype: 'application/json',
                    processData: false, // Important! prevent jQuery from transforming the data into a query string 
                    cache: false,
                    url: url,
                    data: JSON.stringify(ballot)
                }).done((data, textStatus, jqXHR) => {
                    if (jqXHR.status === 200) {
                        swal("The ballot has been succesfully created!", {icon: "success"})
                                .then((confirm) => {
                                    if (confirm) {
                                        table.ajax.reload();
                                        clearAddBallotModal(); // clear the form
                                        $("#addBallotModal").click(); // close the modal
                                        displayBallots(); // redisplay the ballots
                                    }
                                });
                    } else {
                        swal("Oops! Invalid ballot Input", {icon: "warning"});
                    }
                }).fail((jqXHR, textStatus, errorThrown) => {
                    swal("Error! An error occured!", {icon: "error"});
                });

            });

        });
    });

In my netbeans 8.2 console i get:
Severe: javax.ws.rs.ProcessingException: Error deserializing object from entity stream. javax.ws.rs.ProcessingException: Error deserializing object from entity stream.

This is my resource endpoint method:

  @POST
    @Path("{ipaddress}/{electionid}")
    @ApiOperation(value = "Create new ballot item", notes = "This can only be done by logged in users.")
    @ApiResponses(value = {
    @ApiResponse(code = 400, message = "Invalid ballot item Input"),
    @ApiResponse(code = 200, message = "Ballot item created")})
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public Response add(
        @ApiParam(value = "The ipaddress of the ballot item to be created", required = true) @PathParam("ipaddress") String ip,
        @ApiParam(value = "The election's id", required = true) @PathParam("electionid") String electionid,
        @ApiParam(value = "The ballot item that needs to be added", required = true) BallotItem newBallot) {

    Election election = electionService.find(Long.parseLong(electionid));
    newBallot.setElectionID(election);
    ballotsService.create(newBallot); 
    return Response.ok(newBallot).build();
 }

Please how can i get this to work? Thanks in advance

@AdamBien

This comment has been minimized.

Copy link
Owner Author

AdamBien commented Mar 20, 2019

Thoughts on quarkus.io

@g-mccarthy

This comment has been minimized.

Copy link

g-mccarthy commented Mar 26, 2019

Hi Adam,
Really enjoy your videos and advice.
I am wondering if you could explain the reasons why a team would/should choose a single page application rather than a request response model, benefits/drawbacks etc. I think that single page apps with some js framework such as react/angular/vue etc are the default choice at the moment for lots of applications/teams but this decision is not based on any sound analysis/thought. Interested in your thoughts on this.

Thank you,
Glen.

@viktorcitaku

This comment has been minimized.

Copy link

viktorcitaku commented Mar 26, 2019

Hi Adam,

  1. I want to know if there is a way which is more elegant than JCA to read from TCP Socket Connection?

  2. Let's say we have two Payara (or any JEE Server) instances where we have two apps deployed and to communicate with each other they use JMS. Now should I have a third instance of Payara Server to play the role of a Message Broker or what would be the JEE-stic way?

  3. How would you manage Transactions between Microservices in JEE?

Thanks in advance.

@jessefarinacci

This comment has been minimized.

Copy link

jessefarinacci commented Mar 27, 2019

Which do you endorse and why: Flyway vs Liquibase vs SomethingElse

@kret11

This comment has been minimized.

Copy link

kret11 commented Mar 27, 2019

Not exactly JEE question but still wondering how to model database and Entity objects for REST backend serving multilingual data. Thanks

@Tunjidir

This comment has been minimized.

Copy link

Tunjidir commented Mar 29, 2019

Hi Adam, I hope you are well? Please what is your take on using synchronized in a Singleton Bean with BEAN managed concurrency type assuming that i want a method to perform some asynchronous requests? do i opt in for Locks?

Secondly, I get confused a lot with system tests and integration test, recently i was in a project where arquillian was being used to build a war file, with it's dependencies, a container managed application server was started and system tests were being ran as Integration test. I get confused all over again. Please could you give a very simple, layman's definition of integration test and maybe an example of what an integration test might look like without using arquillian. Oh? and in the case of using arquillian to build a war file and start an application server, does that pass as a system test or an integration test? are integration tests a variant of system tests or vice versa?

How do you handle shared entity classes between two microservices handled by different teams? Say i was making a request to another microservice to return an entity class? Does every microservice keep a shared copy of the entity class or do you just use JsonObjects and build the entity class from the JsonObjects?

i am new to bce structuring and i have a question about that. say i have a blog application i'm building. do i have a component post with a bce structure and another component comment with another bce structure, mind you, the comment entity has a manyToOne relationship with a post entity. with this am i still minimizing coupling and maximizing cohesion? what package would a web filter reside in? Control? or do you just drop it in the application layer since it filters all the requests?

I've been looking at adding a datasource url to a docker image. i pretty much understand that but then how does it work behind the scene, supposing i have a localdb running. does docker connect the datasource url with my local db. will request to fetch some data from the database fail if the local db is not running. sorry if this sounds dumb, i am just exploring javaEE with cloud and all it's wonderful features. thanks

@tnaskret

This comment has been minimized.

Copy link

tnaskret commented Apr 1, 2019

Hello,
I'm new to open liberty and MicroProfile. How to upload files using MicroProfile 2.1(jaxrs-2.1) on open liberty? Do i need to add extra dependencies?
I'm waiting for a new video course on MicroProfile :-)
Bests,
Tomasz

@franden

This comment has been minimized.

Copy link

franden commented Apr 1, 2019

Hello Adam,
currently we are trying to establish continuous static code checks with SonarQube in our Java EE 7 (JBoss EAP 7.0) application. In many cases we use CDI with field Injection, without explicit defined constructor. Now we have SonarQube finding that marks all our projects as "buggy", because of this rule: Constructor injection should be used instead of field injection. If we now try to use constructor injection, the CDI container (WELD) complain on startup that the modified beans have no "non-private constructor with no parameters". According to the CDI 1.1 spec the CDI beans must have non-private constructor with no parameters. But such constructor wouldn't make sense in our application, except the requirement of CDI spec. That would mean, that the SonarQube can not be applied for CDI.

  • What is your preferred approach for "CDI constructor injection VS field injection (VS setter injection)"?
  • Do you also use SonarQube in your Projects?
    • If yes, how do you deal with the rule RSPEC-3306?
@AlbozDroid

This comment has been minimized.

Copy link

AlbozDroid commented Apr 1, 2019

Hi Adam,

I have some questions around multi-war projects:

  1. Do you deploy one war per JEE App Server? or multiple wars in the same app server?.
  2. Do you deploy more than one JEE Application Server in the same physical server (or virtual machine)?
  3. In multi war projects how do you handle Authentication?. Do you have a separate dedicated war for Authentication and every other war delegates to that one? For example all other wars intercept all requests, call the authentication wars to check whether the credentials (username/pass, cookie, Bearer) are valid or not?
  4. What do you use for service discovery? How do your wars find each other.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.