Some people want to run Javalin on Android, or other small things.. Could be fun to create a minimal version of Javalin for that 馃
Prompted by https://github.com/tipsy/javalin/issues/775
Example: http://www.adam-bien.com/roller/abien/entry/a_built_in_java_httpserver
The sun server is not available on Android, so there goes that idea.
Edit: Maybe https://github.com/NanoHttpd/nanohttpd ?
Would be that a feature realted to #749 ?
No, this idea was just to make javalin work on Android.
This would however be extremely useful for running on graalvm or in a serverless architecture where less code equal to lower coldstart which in turn equal lower cost and better performance.
Could I help this somehow? @tipsy 馃檪
@richarddd this task will vary greatly based on how we scope it. If we can find a dependency free server and just do basic http (what's in the http package in javalin), I think that could be and interesting project. It would require a bit of effort to maintain though, are you up for a challenge? :slightly_smiling_face:
@tipsy sure! just tell me how I should proceed 馃憤
@richarddd Sorry about the late reply, I was traveling last week.
First of all we would have to map out what functionality this should support. I was thinking only basic verbs and exception handling. No websockets, static files, single-page-handler, etc.
Basically just a stripped down version of the JavalinServlet class.
What do you think?
@tipsy No worries, I already started working on this and got it running using com.sun.httpserver 馃檶.
However this got me thinking. It maybe would be better to make the Jetty dependencies from the "full version" optinal and abstract them away so we always leverage the servet capabilities. Then we add them back and create extension methods which uses Jerry servlet handling.
This way we could create light or even nano versions of javalin using the servlet abstraction. We could even in the future ship other flavors of Javalin with other servlet enabled servers.
What do you think? 馃檪
I already started working on this and got it running using com.sun.httpserver 馃檶.
Were you able to find the sun server as a dependency so it works on Android?
However this got me thinking. It maybe would be better to make the Jetty dependencies from the "full version" optinal and abstract them away so we always leverage the servet capabilities. Then we add them back and create extension methods which uses Jerry servlet handling.
This way we could create light or even nano versions of javalin using the servlet abstraction. We could even in the future ship other flavors of Javalin with other servlet enabled servers.
What do you think? 馃檪
That would be ideal, but it's a lot of work. Configuration and WebSockets rely directly on Jetty now, while the servlet part is independent (see https://github.com/tipsy/javalin/issues/816). I've chosen to keep this tightly coupled since it improves the developer experience better for the 99% who use Javalin with Jetty.
That gives me an idea though... If we could find a dependency free Servlet container which runs on Android, we could create a new project with Javalin as a dependency (and exclude Jetty), and just expose the functionality that would be available without Jetty 馃
Were you able to find the sun server as a dependency so it works on Android?
Nope but I wrote a really simple zero dependency socket server just to test the concept on Android and it works perfectly. I could easily make it servlet compatible
That would be ideal, but it's _a lot_ of work. Configuration and WebSockets rely directly on Jetty now, while the servlet part is independent (see #816). I've chosen to keep this tightly coupled since it improves the developer experience better for the 99% who use Javalin with Jetty.
That gives me an idea though... If we could find a dependency free Servlet container which runs on Android, we could create a new project with Javalin as a dependency (and exclude Jetty), and just expose the functionality that would be available without Jetty 馃
That would be really cool!
Btw, i don't really see the use case for running javalin on android? Why would you want that?
Nope but I wrote a really simple zero dependency socket server just to test the concept on Android and it works perfectly. I could easily make it servlet compatible
Sounds great! We can just go with that for the first version then?
Btw, i don't really see the use case for running javalin on android? Why would you want that?
It's come up 10+ times, but I'm not exactly sure if there's a very valid use case. Personally I wanted to try it once to remote control the camera and microphone (I guess lot's of people have old phones lying around).
Happy new year @richarddd, are you working on this?
Happy new year @richarddd, are you working on this?
Kind of, just have been really busy at the latest! Will pick up in a week or so :)
Cool, looking forward to it!
Any updates on this? Seeing NanoHTTPD is mostly unmaintained, I'd love to see Javalin as an alternative.
@richarddd are you still interested in working on this? The repo is multi-module now, so we could potentially create a module which doesn't use Jetty.
@richarddd are you still interested in working on this? The repo is multi-module now, so we could potentially create a module which doesn't use Jetty.
@tipsy Yes! Sorry for being so "late" to the party, I have been extremely busy (buying a house, moving, work etc, etc). It would be much easier now since its multi-module. I'll look into it :)
No problem, congratulations on the new house!
Thanks @richarddd! :+1:
You might be interested in the javalin-without-jetty module @richarddd,
You might be interested in the
javalin-without-jettymodule @richarddd,
Cool! I started looking into doing this properly but I really s**k at maven :( Gradle (or even kotlin in grade) is my build tool of choice. I someone is interested I can share my findings/experiments and I'm sure we'll figure something out.
Sorry for taking so long but I have had a few crazy months at work...
Cool! I started looking into doing this properly but I really s**k at maven :( Gradle (or even kotlin in grade) is my build tool of choice. I someone is interested I can share my findings/experiments and I'm sure we'll figure something out.
What is your maven issue?
Hi, this is just an idea, but I've been looking into a few HTTP servers for Android and probably the best option is Netty. The project is well maintained and added support for Android since a few versions ago.
NanoHTTPD looks cool, but they haven't made commits since a few years ago, so I'm not sure if the project is active, and Sun HTTP seems kind of hacky to implement.
Maybe adding support for Netty would be worth a look.
@JavierPAYTEF from my understanding, Jetty is an HTTP server and Netty is a TCP/UDP server. While Netty may be compatible with Android, Javalin is primarily an HTTP framework, so you would have to re-implement HTTP support on top of Netty. To me, it seems like the wrong tool for the job.
@oharaandrew314 with something like https://github.com/bigpuritz/netty-servlet-bridge, using netty should be pretty straightforward.
In theory Netty already implements HTTP protocol without any extra things needed. It even implements HTTP/2 and SSL.
The only thing is that needs more setup for each component to create a server and also it's a bigger library than NanoHTTP.
Check out the Snoop example here, it's pretty simple:
https://github.com/netty/netty/tree/master/example/src/main/java/io/netty/example/http
What I will say is that it's not lightweight, my APK jumped from 1MB to 21MB from adding this through using Ktor. But, I'm not sure if this is because of Netty or Ktor.
What I can confirm is that it works fine in Android SDK 25, which is the one I'm currently using, even though it throws some warnings in logcat. I think SDK 25 doesn't suport some of java.nio, but works ok all the same.
I really wanted to use Javalin because I love how clean the interface is, and loved the integration with OpenAPI, but couldn't get Jetty to work after a few days messing with multidex and desugaring :( I managed to get it to compiled but then threw errors at runtime of classes not found and such.
For all the interested folks here, Javalin actually works on Android =) The only issue I'm now facing, though, is "ClassNotFoundException: org.eclipse.jetty.websocket.server.WebSocketServerFactory" when our app is using shared system uid. We're dealing with custom ROM here, though.
And also for the interested folks, Javalin successfully maps Android device storage folder as static files
how did you make it work in android?
how did you make it work in android?
Min SDK 26 (we're building SDK 28 ROM, so I'm perfectly fine with that), slf4j-simple dependency, and that's basically it
This issue is getting nowhere, so I don't think it makes sense to keep it open anymore. If someone wants to create a PR I'd still be happy to review it though!
Most helpful comment
This issue is getting nowhere, so I don't think it makes sense to keep it open anymore. If someone wants to create a PR I'd still be happy to review it though!