Skip to content

Commit de39965

Browse files
committed
update to dropwizard 5.0-rc.4;
remove admin context identification in logs (because it doesn't work anymore)
1 parent 29d9b61 commit de39965

6 files changed

Lines changed: 6 additions & 50 deletions

File tree

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
* Update to dropwizard 5 (requires java 17)
2-
* [admin-rest]
3-
- Add identifyAdminContextInRequestLogs bundle option to highlight admin requests in logs
42

53
### 7.2.1 (2025-05-12)
64
* Fix NoClassDefFoundError on guicey startup due to junit classes leak into core (#428)

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ wrapper {
1919
description = 'Dropwizard guice integration'
2020

2121
ext {
22-
dropwizard = '5.0.0-rc.3'
22+
dropwizard = '5.0.0-rc.4'
2323
guice = '7.0.0'
2424
hk2 = '3.0.6'
2525
spockJunit5 = '1.2.0'

guicey-admin-rest/src/main/java/ru/vyarus/guicey/admin/AdminRestBundle.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public class AdminRestBundle extends UniqueGuiceyBundle {
3434
private final Logger logger = LoggerFactory.getLogger(AdminRestBundle.class);
3535

3636
private final String path;
37-
private boolean identifyAdminContext;
3837

3938
/**
4039
* Admin rest will be mapped on the same path as main rest if rest mapping is different from '/*'.
@@ -54,28 +53,6 @@ public AdminRestBundle(final String path) {
5453
this.path = path;
5554
}
5655

57-
/**
58-
* Shortcut for {@code identifyAdminPathsInRequestLogs(true)}.
59-
*
60-
* @return bundle instance
61-
*/
62-
public AdminRestBundle identifyAdminContextInRequestLogs() {
63-
return identifyAdminContextInRequestLogs(true);
64-
}
65-
66-
/**
67-
* As admin rest just redirects to main context rest, then all admin rest calls would be logged. It might
68-
* be hard to identify admin calls in such logs (if rest contexts are the same and resources used from both
69-
* contexts). When enabled, " (ADMIN REST)" string is appended for loggable request uri.
70-
*
71-
* @param identifyAdminPathsInRequestLogs true to identify admin calls in request logs
72-
* @return bundle instance
73-
*/
74-
public AdminRestBundle identifyAdminContextInRequestLogs(final boolean identifyAdminPathsInRequestLogs) {
75-
this.identifyAdminContext = identifyAdminPathsInRequestLogs;
76-
return this;
77-
}
78-
7956
@Override
8057
public void run(final GuiceyEnvironment environment) throws Exception {
8158
environment.manage(new ServletRegistration(environment.environment()));
@@ -91,7 +68,7 @@ private void registerServlet(final String path, final Environment environment) {
9168
// In admin context LogbackAccessRequestLogAwareHandler not registered, but our admin servlet calls
9269
// the main context, which will trigger LogbackAccessRequestLog, but without a proper handler it would fail
9370
environment.getAdminContext()
94-
.insertHandler(new LogbackAccessRequestLogAwareCustomHandler(identifyAdminContext));
71+
.insertHandler(new LogbackAccessRequestLogAwareCustomHandler());
9572
logger.info("Admin REST registered on path: {}", path);
9673
}
9774

guicey-admin-rest/src/main/java/ru/vyarus/guicey/admin/log/LogbackAccessRequestLogAwareCustomHandler.java

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package ru.vyarus.guicey.admin.log;
22

33
import org.eclipse.jetty.ee10.servlet.ServletContextRequest;
4-
import org.eclipse.jetty.http.HttpURI;
54
import org.eclipse.jetty.server.Handler;
65
import org.eclipse.jetty.server.Request;
76
import org.eclipse.jetty.server.Response;
@@ -26,31 +25,14 @@
2625
*/
2726
public class LogbackAccessRequestLogAwareCustomHandler extends Handler.Wrapper {
2827

29-
private final boolean identifyAdminContext;
30-
31-
/**
32-
* Creates custom logback handler.
33-
*
34-
* @param identifyAdminContext true to identify admin context logs
35-
*/
36-
public LogbackAccessRequestLogAwareCustomHandler(final boolean identifyAdminContext) {
37-
this.identifyAdminContext = identifyAdminContext;
38-
}
39-
4028
@Override
4129
public boolean handle(final Request request,
4230
final Response response,
4331
final Callback callback) throws Exception {
4432
final boolean handled = super.handle(request, response, callback);
4533
// apply ONLY for rest simulation (for other cases simply not required, because requests not logged)
4634
if (handled && request.getAttribute(AdminRestServlet.ADMIN_PROPERTY) != null) {
47-
ServletContextRequest servletContextRequest = Request.as(request, ServletContextRequest.class);
48-
if (identifyAdminContext) {
49-
// indicate admin context call in log
50-
servletContextRequest = (ServletContextRequest) servletContextRequest
51-
.wrap(request, HttpURI.build(request.getHttpURI())
52-
.uri(request.getHttpURI() + " (ADMIN REST)"));
53-
}
35+
final ServletContextRequest servletContextRequest = Request.as(request, ServletContextRequest.class);
5436
if (servletContextRequest != null) {
5537
final Request unwrapped = Request.unWrap(request);
5638
if (!(unwrapped instanceof HttpChannelState.ChannelRequest channelRequest)) {

guicey-admin-rest/src/test/groovy/ru/vyarus/guicey/admin/AdminRestIdentityInLogsTest.groovy

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class AdminRestIdentityInLogsTest extends AbstractTest {
3535
res = new URL("http://localhost:8081/api/hybrid/hello").getText()
3636
sleep(100)
3737
then: "admin context identified"
38-
out.getText().replace("\r", "").contains("\"GET /api/hybrid/hello (ADMIN REST) HTTP/1.1\"")
38+
out.getText().replace("\r", "").contains("\"GET /api/hybrid/hello HTTP/1.1\"")
3939

4040
}
4141

@@ -45,8 +45,7 @@ class AdminRestIdentityInLogsTest extends AbstractTest {
4545
@Override
4646
void initialize(Bootstrap<Configuration> bootstrap) {
4747
bootstrap.addBundle(GuiceBundle.builder()
48-
.bundles(new AdminRestBundle()
49-
.identifyAdminContextInRequestLogs())
48+
.bundles(new AdminRestBundle())
5049
.extensions(HybridResource)
5150
.build()
5251
)

guicey-admin-rest/src/test/groovy/ru/vyarus/guicey/admin/AsyncResourceTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class AsyncResourceTest extends Specification {
3939
@Override
4040
void initialize(Bootstrap<Configuration> bootstrap) {
4141
bootstrap.addBundle(GuiceBundle.builder()
42-
.bundles(new AdminRestBundle("/api/*").identifyAdminContextInRequestLogs())
42+
.bundles(new AdminRestBundle("/api/*"))
4343
.extensions(AsyncResource)
4444
.build())
4545
}

0 commit comments

Comments
 (0)