Skip to content

Commit

Permalink
Add flag to make ThreadNameFilter optional (dropwizard#2014)
Browse files Browse the repository at this point in the history
Include a flag enableThreadNameFilter in AbstractServerFactory to allow
disabling of the ThreadNameFilter's installation. Existing default behavior
is preserved.

Fixes dropwizard#2013.
  • Loading branch information
markelliot authored and Anders Jansson committed Sep 20, 2018
1 parent ec3c62f commit 3c89ca2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/source/manual/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ rootPath ``/*``
the JAX-RS resources will be served.
registerDefaultExceptionMappers true Whether or not the default Jersey ExceptionMappers should be registered.
Set this to false if you want to register your own.
enableThreadNameFilter true Whether or not to apply the ``ThreadNameFilter`` that adjusts thread names to include the request method and request URI.
=================================== =============================================== =============================================================================


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@
* The URL pattern relative to {@code applicationContextPath} from which the JAX-RS resources will be served.
* </td>
* </tr>
* <tr>
* <td>{@code enableThreadNameFilter}</td>
* <td>true</td>
* <td>
* Whether or not to apply the {@code ThreadNameFilter} that adjusts thread names to include the request
* method and request URI.
* </td>
* </tr>
* </table>
*
* @see DefaultServerFactory
Expand Down Expand Up @@ -255,6 +263,8 @@ public abstract class AbstractServerFactory implements ServerFactory {

private Optional<String> jerseyRootPath = Optional.empty();

private boolean enableThreadNameFilter = true;

@JsonIgnore
@ValidationMethod(message = "must have a smaller minThreads than maxThreads")
public boolean isThreadPoolSizedCorrectly() {
Expand Down Expand Up @@ -461,6 +471,16 @@ public void setJerseyRootPath(String jerseyRootPath) {
this.jerseyRootPath = Optional.ofNullable(jerseyRootPath);
}

@JsonProperty
public boolean getEnableThreadNameFilter() {
return enableThreadNameFilter;
}

@JsonProperty
public void setEnableThreadNameFilter(boolean enableThreadNameFilter) {
this.enableThreadNameFilter = enableThreadNameFilter;
}

protected Handler createAdminServlet(Server server,
MutableServletContextHandler handler,
MetricRegistry metrics,
Expand Down Expand Up @@ -495,7 +515,9 @@ protected Handler createAppServlet(Server server,
configureSessionsAndSecurity(handler, server);
handler.addFilter(AllowedMethodsFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST))
.setInitParameter(AllowedMethodsFilter.ALLOWED_METHODS_PARAM, Joiner.on(',').join(allowedMethods));
handler.addFilter(ThreadNameFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
if (enableThreadNameFilter) {
handler.addFilter(ThreadNameFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
}
serverPush.addFilter(handler);
if (jerseyContainer != null) {
jerseyRootPath.ifPresent(jersey::setUrlPattern);
Expand Down

0 comments on commit 3c89ca2

Please sign in to comment.