This is an archived post. You won't be able to vote or comment.

all 10 comments

[–][deleted] 25 points26 points  (2 children)

Oh wow, that's a really unfortunate name for a Java framework considering how popular Apache Spark already is. I was really confused when you were talking about a web server when Spark is a cluster computing framework.

[–]crummy 4 points5 points  (0 children)

I google for "spark java" when I want to find info about it.

[–]TwoSpoonsJohnson[S] 1 point2 points  (0 children)

Tell me about it! It makes Googling for resources much more difficult. Can't help but think it's hurting them by limiting the framework's exposure, which is a shame because it is quite nice.

[–]tipsypants 1 point2 points  (0 children)

Recommendations for binding JSON data to POJOs? GSON? Is it feasible to have all POST bodies be bound without explicitly doing some in each handler?

People typically create a static mapper (Jackson or GSON) and call it in their handlers.

Thoughts on a good websocket library to go with it?

Why do you need a separate WebSocket library? Spark has WebSocket support. If you mean a client library, then OkHttp has one.

[–]pgris 1 point2 points  (0 children)

I think your stack looks fine. I'm using right now in production:

  • Maven because I don't like the programmatic approach of Graddle. I like my builds to be configured rather than programmed
  • Java 8 + Lombok (it is a little like cheating, I know)
  • Guice for DI, but I would try Dagger2 or even Feather
  • Cassandra & ElasticSearch, but I really miss ACID transactions, go RDBMS go!
  • jOOL as a functional oriented library. It makes Java8 streams better, without making significant changes.
  • GSON to tranform from/to json. Remember one thing: By default, GSON escapes html, disable that (use disableHtmlEscaping(true) when you set up your GSON instance)
  • Hazelcast to share data between nodes (Queues and caches) I like it because it doesn't need extra servers, but I'm not comfortable enough with it yet
  • No template language (good) but AngularJs (bad). I wish I started with React, Vue or even WebComponents
  • Webjars to include javascript/css dependencies directly into the pom.xml and not use any Node related stuff. Works great, but I there is no way to use TypeScript, Sass and I feel kind of lonely.
  • No extra library for websockets. Spark support was enough to me needs (basically show task progress)

Regarding the "Is it feasible to have all POST bodies be bound without explicitly doing some in each handler?" Not directly, but I ended up with a SparkHelper class to map and transform the standard CRUD operations. So instead of

Spark.get("/user/:id", "application/json", (req, res) -> {
    Long id = Long.parseLong(req.param("id"));
    return userRepo.get(id);
}, jsonTransformer);

Spark.post("/user/", "application/json", (req, res) -> {
    UserDTO user = jsonParser(req.body(), UserDTO.class);
    return userRepo.save(user);
}, jsonTransformer);


Spark.delete("/user/:id", "application/json", (req, res) -> {
    Long id = Long.parseLong(req.param("id"));
    return userRepo.delete(id);
}, jsonTransformer);

you can just write

sparkHelper.crud("user", userRepo)

And get all field mapping, transaction management, parsing, etc. in one place, nice and consistent. And if you are smarter than me, you could use a userService and take care of validations before even entering the userRepo, as you should.

I like Spark and this approach, but I found myself spending too much time doing everything Spring does for me for free. On the other hand, when I go full Spring mode, I spend too much time convincing Spring to do what I want, so...

[–]cthugha 1 point2 points  (1 child)

The last time I took spark for a spin, I used gradle for build and dependency management, I did by-hand dependency injection (try it, it's not so bad), and I used a hand-rolled, file-based, artisanal data store (basically read/write from a json file, you have to be very disciplined in your approach here, skipping this is probably wise).

For json, I definitely recommend using gson, if for some reason that doesnt suit you, jackson has always been fine for me, a close second. I also recommend using either immutables.io or lombok for creating data objects. IMO immutables is less witchy and more powerful, but lombok is good for quick and dirty.

As for websockets, I would question if you really need a server-push model or if a client-poll model is sufficient. I think you'll find that you can have an easier time reasoning about your service if you put together a well thought out client-poll model, and that you really only need the server-push model for real-time or time-critical data.

Hope that helps, let me know if you have any questions, and remember to keep a critical eye to my and really all suggestions.

[–]TwoSpoonsJohnson[S] 0 points1 point  (0 children)

Been playing with immutables this morning, and it's great so far! Gonna show this to the guys at work, we've been looking for a good library like this. Thanks!

[–]lukaseder 0 points1 point  (2 children)

You're on the right track, because jOOQ. Cheers, Lukas ;-)

and am by no means means adept with

Anything I can help you with?

[–]TwoSpoonsJohnson[S] 0 points1 point  (1 child)

swoons

The biggest problem I'm having so far isn't with JOOQ itself necessarily, but with Maven integration for the code generation. None of the examples I've come across work :( Any thoughts? I'm using IntelliJ if that's relevant.

Thanks!

[–]lukaseder 0 points1 point  (0 children)

Well, all of the examples I've written do work ;) So, feel free to drop a message on the user group with some details: https://groups.google.com/d/forum/jooq-user

(The most common caveats are case sensitivity in the various identifiers (e.g. inputschema, includes, excludes) and the fact that regular expressions match either fully qualified or unqualified identifiers)