Skip to content

Commit

Permalink
Document access log support and annotation support better (#715)
Browse files Browse the repository at this point in the history
  • Loading branch information
graemerocher authored May 29, 2024
1 parent 435f54d commit 2c42107
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.micronaut.servlet.jetty

import io.micronaut.context.annotation.Property
import io.micronaut.http.client.HttpClient
import io.micronaut.http.client.annotation.Client
import io.micronaut.test.extensions.spock.annotation.MicronautTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.micronaut.servlet.jetty;

// tag::class[]
import io.micronaut.context.annotation.Factory;
import io.micronaut.core.annotation.Order;
import io.micronaut.core.order.Ordered;
Expand All @@ -12,11 +13,13 @@
import jakarta.servlet.ServletResponse;
import java.io.IOException;

@Factory
@Factory // <1>
public class MyFilterFactory {

@ServletFilterBean(filterName = "another", value = {"/extra-filter/*", "/extra-servlet/*"})
@Order(Ordered.HIGHEST_PRECEDENCE)
@ServletFilterBean(
filterName = "another", // <2>
value = {"/extra-filter/*", "${my.filter.mapping}"}) // <3>
@Order(Ordered.HIGHEST_PRECEDENCE) // <4>
Filter myOtherFilter() {
return new GenericFilter() {
@Override
Expand All @@ -27,3 +30,4 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
};
}
}
// end::class[]
3 changes: 3 additions & 0 deletions http-server-jetty/src/test/resources/application-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
micronaut:
security:
enabled: false
my:
filter:
mapping: /extra-servlet/*
13 changes: 13 additions & 0 deletions src/main/docs/guide/jetty.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,16 @@ include::http-server-jetty/src/test/java/io/micronaut/servlet/jetty/docs/JettySe
include::http-server-jetty/src/test/java/io/micronaut/servlet/jetty/docs/JettyServerCustomizer.java[tags=class, indent=0]
----

=== Access Log Configuration

To configure the https://eclipse.dev/jetty/documentation/jetty-11/programming-guide/index.html#pg-server-http-request-logging[Jetty Access Log]:

.Jetty Access Log Configuration
[configuration]
----
micronaut.server.jetty.access-log.enabled: true
micronaut.server.jetty.access-log.filename: /tmp/access.log
micronaut.server.jetty.access-log.retain-days: 10
micronaut.server.jetty.access-log.pattern: >
%{client}a - %u %t "%r" %s %O
----
12 changes: 12 additions & 0 deletions src/main/docs/guide/servletAnnotation.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ In addition, you can use the following annotations on methods of https://docs.mi

* ann:servlet.api.annotation.ServletBean[] - Equivalent of https://jakarta.ee/specifications/servlet/5.0/apidocs/jakarta/servlet/annotation/webservlet[@WebServlet] but can be applied to a method of a factory to Register a new servlet.
* ann:servlet.api.annotation.ServletFilterBean[] - Equivalent of https://jakarta.ee/specifications/servlet/5.0/apidocs/jakarta/servlet/annotation/webfilter[@WebFilter] but can be applied to a method of a factory to Register a new filter.
The following example adds a new Servlet filter with the highest precedence:

.Adding a Filter with a Factory
snippet::io.micronaut.servlet.jetty.MyFilterFactory[tags="class", indent=0, project="http-server-jetty"]

<1> A `@Factory` bean is defined
<2> The ann:servlet.api.annotation.ServletFilterBean[] annotation is used and a filter name defined
<3> 1 or more mappings are defined. Note these can be resolved from property placeholder configuration if necessary.
<4> The order of the filter is defined.

NOTE: Servlet Filters are not to be confused with https://docs.micronaut.io/latest/guide/#filters[Micronaut filters]. Servlet Filters always run before the Micronaut Servlet which in turn runs the Micronaut Filters hence it is not possible to place a Servlet Filter after Micronaut Filters.
11 changes: 11 additions & 0 deletions src/main/docs/guide/tomcat.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,14 @@ include::http-server-tomcat/src/test/java/io/micronaut/servlet/tomcat/docs/Tomca
include::http-server-tomcat/src/test/java/io/micronaut/servlet/tomcat/docs/TomcatServerCustomizer.java[tags=class, indent=0]
----

=== Access Log Configuration

To configure the https://tomcat.apache.org/tomcat-10.1-doc/config/valve.html#Access_Logging[Tomcat Access Log]:

.Tomcat Access Log Configuration
[configuration]
----
micronaut.server.tomcat.access-log.enabled: true,
micronaut.server.tomcat.access-log.pattern: combined
micronaut.server.tomcat.access-log.directory: /var/logs
----
11 changes: 11 additions & 0 deletions src/main/docs/guide/undertow.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,14 @@ include::http-server-undertow/src/test/java/io/micronaut/servlet/undertow/docs/U
include::http-server-undertow/src/test/java/io/micronaut/servlet/undertow/docs/UndertowServerCustomizer.java[tags=class, indent=0]
----

=== Access Log Configuration

To configure the https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.3/html/configuration_guide/configuring_the_web_server_undertow#access_logging[Undertow Access Log]:

.Undertow Access Log Configuration
[configuration]
----
micronaut.server.undertow.access-log.enabled: true,
micronaut.server.undertow.access-log.pattern: combined
micronaut.server.undertow.access-log.output-directory: /var/logs
----

0 comments on commit 2c42107

Please sign in to comment.