You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In an MP app, response headers set in an SE-style filter (that is, not a Jakarta REST filter) are lost when JaxRsService attempts to handle the request and cannot. It resets the routing which includes clearing the headers.
Steps to reproduce
Add the files below to the Helidon MP QuickStart project.
Build the project.
Run the project with the debugger, setting breakpoints:
In the lambda very near the bottom of the new Java class below.
At the code linked to above--JaxRsService#doHandle around line 251; the service has discovered that Jersey did not handle the request and it invokes routing.reset() which, among other things, clears the headers.
Access http://localhost:8080/health.
Helidon invokes the filter which sets the headers.
But JaxRsService clears those headers.
Files to add:
Add the following services file io.helidon.webserver.spi.ServerFeatureProvider to src/main/resources/META-INF/services
(There might be a way to auto-load the feature without adding config to trigger it but I didn't spend much time looking for one.)
Add this class to the MP QuickStart project:
/* * Copyright (c) 2025 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */packageio.helidon.examples.quickstart.mp;
importio.helidon.common.Weight;
importio.helidon.config.Config;
importio.helidon.http.Header;
importio.helidon.http.HeaderValues;
importio.helidon.webserver.WebServer;
importio.helidon.webserver.http.HttpFeature;
importio.helidon.webserver.http.HttpRouting;
importio.helidon.webserver.observe.health.HealthObserverConfig;
importio.helidon.webserver.spi.ServerFeature;
importio.helidon.webserver.spi.ServerFeatureProvider;
/** * Server feature to insert headers for selected responses. */@Weight(HeaderAdjustmentFeatureProvider.WEIGHT)
publicclassHeaderAdjustmentFeatureProviderimplementsServerFeatureProvider<HeaderAdjustmentFeatureProvider.HeaderAdjustmentFeature> {
staticfinaldoubleWEIGHT = 90D;
@OverridepublicStringconfigKey() {
return"header-adjustment";
}
@OverridepublicHeaderAdjustmentFeaturecreate(io.helidon.common.config.Configconfig, Stringname) {
returnnewHeaderAdjustmentFeature();
}
@Weight(WEIGHT)
publicstaticclassHeaderAdjustmentFeatureimplementsServerFeature {
privatestaticfinalHeaderX_CONTENT_TYPE_OPTIONS_NO_SNIFF = HeaderValues.create("X-Content-Type-Options", "nosniff");
publicHeaderAdjustmentFeature() {
}
@Overridepublicvoidsetup(ServerFeatureContextserverFeatureContext) {
serverFeatureContext.socket(WebServer.DEFAULT_SOCKET_NAME)
.httpRouting()
.addFeature(newHeaderAdjustmentHttpFeature(Config.global()));
}
@OverridepublicStringname() {
return"header-adjustment";
}
@OverridepublicStringtype() {
return"header-adjustment";
}
@Weight(WEIGHT)
privatestaticclassHeaderAdjustmentHttpFeatureimplementsHttpFeature {
privatefinalio.helidon.common.config.Configconfig;
privateHeaderAdjustmentHttpFeature(io.helidon.common.config.Configconfig) {
this.config = config;
}
@Overridepublicvoidsetup(HttpRouting.Builderbuilder) {
HealthObserverConfighealthObserverConfig =
HealthObserverConfig.create(config.root().get("server.features.observe.observers.health"));
builder.addFilter((chain, req, resp) -> {
if (req.path().path().endsWith(healthObserverConfig.endpoint())) {
resp.header(HeaderValues.CACHE_NO_CACHE); // Helidon will do this itself after an upcoming PR.resp.header(X_CONTENT_TYPE_OPTIONS_NO_SNIFF);
}
chain.proceed();
});
}
}
}
}
The text was updated successfully, but these errors were encountered:
Environment Details
Problem Description
In an MP app, response headers set in an SE-style filter (that is, not a Jakarta REST filter) are lost when
JaxRsService
attempts to handle the request and cannot. It resets the routing which includes clearing the headers.Steps to reproduce
Add the files below to the Helidon MP QuickStart project.
Build the project.
Run the project with the debugger, setting breakpoints:
JaxRsService#doHandle
around line 251; the service has discovered that Jersey did not handle the request and it invokesrouting.reset()
which, among other things, clears the headers.Access
http://localhost:8080/health
.Helidon invokes the filter which sets the headers.
But
JaxRsService
clears those headers.Files to add:
Add the following services file
io.helidon.webserver.spi.ServerFeatureProvider
tosrc/main/resources/META-INF/services
Add this config snippet to
application.yaml
:(There might be a way to auto-load the feature without adding config to trigger it but I didn't spend much time looking for one.)
Add this class to the MP QuickStart project:
The text was updated successfully, but these errors were encountered: