FHIR Chat · Plain server WAR configuration · implementers

Stream: implementers

Topic: Plain server WAR configuration


view this post on Zulip Théo Matussière (May 12 2020 at 09:01):

Hi all,
First of all a big thanks for the HAPI library, looks very cool! I'm part of a health company and leading the effort on being FHIR-ready.
Our stack is Kotlin, with Gradle, and I've had no problems coding a few providers so far.
However I am at a loss when it comes to booting up the server, I'm very new to servlets in general, so I took inspiration from https://github.com/FirelyTeam/fhirstarters/tree/master/java/hapi-fhirstarters-rest-server-skeleton and created a matching minimal "src/main/webapp/web.xml" file.
I installed tomcat locally and pulled the appropriate dependencies, following from the Kotlin guide to servlets: https://kotlinlang.org/docs/tutorials/httpservlets.html
The war plugin indeed offers a "war" task, but it doesn't seem to do much - I'm sure I'm missing something but I can't figure out what Googling around, the war plugin help page (https://docs.gradle.org/current/userguide/war_plugin.html) outlines how to configure the task but I couldn't get it to do anything so far.
Big thanks for any hints,
Théo

view this post on Zulip James Agnew (May 12 2020 at 09:31):

If you haven't already, you need to update your POM packaging to "war" as well: https://github.com/FirelyTeam/fhirstarters/blob/master/java/hapi-fhirstarters-rest-server-skeleton/pom.xml#L7

view this post on Zulip Théo Matussière (May 12 2020 at 10:07):

there aren't POM files in a gradle project though, I assumed the gradle equivalent configuration to be the one described here https://kotlinlang.org/docs/tutorials/httpservlets.html with the war plugin, maybe this isn't enough?

view this post on Zulip James Agnew (May 12 2020 at 12:05):

Ah sorry, missed the fact that you are using Gradle. Unfortunately I have no experience building WARs with Gradle..

view this post on Zulip Théo Matussière (May 12 2020 at 13:11):

Do you know of someone who would?

view this post on Zulip James Agnew (May 12 2020 at 13:13):

Hmm.. @Jens Villadsen possibly?

view this post on Zulip Théo Matussière (May 12 2020 at 13:15):

Excellent, thanks a lot! Can we expect them to see this conversation or should I try to reach out directly?

view this post on Zulip James Agnew (May 12 2020 at 14:14):

Jens is pretty active on here, i'm sure he'll see it.

view this post on Zulip Jens Villadsen (May 12 2020 at 20:58):

@Théo Matussière You do not need to compile it down to a war, in order to run the HAPI FHIR server. You can easily embed it into an application with an embedded HTTP server, like eg. spring boot which works fine in kotlin, AFAIK. Now, some questions:
1) Do you really need to pack it into a war?
2) Have you had a look at eg. https://guides.gradle.org/building-java-web-applications/#add_a_gradle_build_file?

view this post on Zulip Théo Matussière (May 13 2020 at 08:13):

hi @Jens Villadsen thanks a lot for the pointers
1) I'm new enough to servlets to have no opinion on this, reading through guides and tutorials I thought I picked up that this was necessary - I'd gladly go for something simpler.
2) I did, that translates into this diff for me:
Screenshot-2020-05-13-at-10.03.22.png
So I guess all in all I misunderstood the need for tomcat, will look into spring boot. In my setting if I could run it with ktor that would be ideal, do you know if that is feasible?

view this post on Zulip Jens Villadsen (May 13 2020 at 08:55):

Have a look at https://kotlinlang.org/docs/tutorials/httpservlets.html / https://github.com/Kotlin/kotlin-examples/tree/master/tutorials/servlet-web-applications and https://github.com/hapifhir/hapi-fhir-jpaserver-starter/blob/master/src/main/java/ca/uhn/fhir/jpa/starter/JpaRestfulServer.java

  • and eg. annotate your JpaRestfulServer with
@WebServlet(
        name = "FhirServlet",
        urlPatterns = "/" + CONTEXT_PATH + "/*"
        )

 class JpaRestfulServer : RestfulServer {
...
}

that should get you going ;)

view this post on Zulip Théo Matussière (May 13 2020 at 17:58):

Indeed! I'm getting a servlet to run, but alas it doesn't seem to have registered the HAPI service. Followed the kotlin tutorial which uses gretty with jetty as a backend, whereas the hapi example uses spring, is there a known incompatibility with jetty that means I should use the spring framework? no strong preference either way.
uploading a few code screens in order to give you more context, maybe I'm just missing something...
thanks again for the attention!
Screenshot-2020-05-13-at-19.56.03.png Screenshot-2020-05-13-at-19.55.39.png Screenshot-2020-05-13-at-19.55.35.png

view this post on Zulip Jens Villadsen (May 14 2020 at 07:45):

HAPI uses spring as IoC

view this post on Zulip Jens Villadsen (May 14 2020 at 07:48):

you can use tomcat, undertow, jetty and a lot of other containers with spring

view this post on Zulip Jens Villadsen (May 14 2020 at 07:52):

You could have a look at this (old) example of combining webservlet with gretty: https://github.com/akhikhl/example-uploadr

view this post on Zulip Théo Matussière (May 14 2020 at 08:20):

I'm not seeing differences in either the gradle file or the server registration part though.

view this post on Zulip Théo Matussière (May 14 2020 at 08:41):

Hah ok I found it, it was the loadOnStartup thing that was missing, with @WebServlet(name = "FhirServlet", value = ["/fhir/*"], loadOnStartup = 1) it indeed runs the server

view this post on Zulip Théo Matussière (May 14 2020 at 08:42):

big thanks @Jens Villadsen !


Last updated: Apr 12 2022 at 19:14 UTC