-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTP Server runtime based on Java built-in HTTP Server #893
Conversation
|
||
void writeBody(HttpExchange exchange, byte[] body) throws IOException { | ||
if (body.length > 0) { | ||
OutputStream outputStream = exchange.getResponseBody(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do the buffering to byte[] and not just directly write to the response body stream?
*/ | ||
@Experimental | ||
@Internal | ||
class HttpExchangeHttpServletRequest implements HttpServletRequest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't it be easier to implement Micronaut's HTTP request interface instead of trying to create a servlet bridge?
http-server/src/main/java/io/micronaut/servlet/http/server/HttpExchangeHttpServletRequest.java
Outdated
Show resolved
Hide resolved
http-server/src/main/java/io/micronaut/servlet/http/server/HttpExchangeHttpServletRequest.java
Outdated
Show resolved
Hide resolved
http-server/src/main/java/io/micronaut/servlet/http/server/HttpExchangeHttpServletResponse.java
Outdated
Show resolved
Hide resolved
http-server/src/main/java/io/micronaut/servlet/http/server/HttpExchangeHttpServletResponse.java
Outdated
Show resolved
Hide resolved
http-server/src/main/java/io/micronaut/servlet/http/server/HttpExchangeServletInputStream.java
Outdated
Show resolved
Hide resolved
http-server/src/main/java/io/micronaut/servlet/http/server/HttpExchangeHttpServletResponse.java
Outdated
Show resolved
Hide resolved
test-suite-http-server-tck to test-suite-http-server-tck-jdk add jdk suffix
|
Micronaut HTTP Server Module
This pull request adds a HTTP Server implementation based on the Java built-in HTTP Server. To use it, users need to add the following dependency:
io.micronaut.servlet:micronaut-http-server
.For users, it would probably be best to use something more battled tested like netty or any of the servlet implementations as their runtime. Still, it is pretty cool to be able to have a Micronaut application with both a server and a client based on the built-in Java HTTP server and HTTP client while keeping your Micronaut Application with the same Micronaut APIs.
Micronaut HTTP Server Module Implementation.
To power it, I created a new module that depends on
servlet-engine
. It leverages the APIServletHttpHandler<HttpServletRequest, HttpServletResponse>
to implement acom.sun.net.httpserver.HttpHandler
.I created implementations of
HttpServletRequest
andHttpServletResponse
to interact withcom.sun.net.httpserver.HttpExchange
. Although, I have left many methods withthrow new UnsupportedOperationException("Not implemented");
, the TCK passes fully but for one test which fails for every other Servlet implementation.Consuming Java built-in HTTP Server runtime in function test modules
I have created hooks so that the serverless test modules (gcp , azure, and aws) can be powered by the built-in Java http server runtime without relying on
servlet-runtime
. Instead, they will provide their own implementation ofHttpHandler
based on the function and they will exposes the function`s application context as the server application context.The following draft PR shows the implementation in the AWS module:
micronaut-projects/micronaut-aws#2315
This will allow us to stop relying on Jetty 11, which has an opened CVE, in all those modules.
Files Moves
QueryStringDecoder
I copied
QueryStringDecoder
fromhttp-poja-common
and packageio.micronaut.http.poja.util.QueryStringDecoder
intoservlet-core
and packageio.micronaut.servlet.http.utils
. I have deprecated from removalio.micronaut.http.poja.util.QueryStringDecoder
Server Classes
I have copied the server classes (
ServletServerFactory
,ServletStaticResourceConfiguration
, andAbstractServletServer
) fromserver-runtime
intoserver-core
. I have deprecated, for removal, these classes in theserver-runtime
module.Event Publication
AbstractServletServer
publishes onlyServerShutDown
if there is a bean of typeApplicationEventPublisher<ServerShutdownEvent>
ServerStartupEvent
which publishesServiceReadyEvent
.