-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instead of calculating values from the header and having longer parameter lists, MDC is used to store more context information for the error responses. In addition the host name and port are loggable and exposed to the MicroserviceEngine API
- Loading branch information
Showing
14 changed files
with
368 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
ms-common-impl/src/main/java/net/trajano/ms/vertx/jaxrs/MDCInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package net.trajano.ms.vertx.jaxrs; | ||
|
||
import javax.annotation.Priority; | ||
import javax.ws.rs.Priorities; | ||
import javax.ws.rs.container.ContainerRequestContext; | ||
import javax.ws.rs.container.ContainerRequestFilter; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.slf4j.MDC; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import net.trajano.ms.spi.MDCKeys; | ||
import net.trajano.ms.spi.MicroserviceEngine; | ||
|
||
/** | ||
* This populates the MDC based on the data available on the request. This will | ||
* skip the method and request URI if debug is not enabled. | ||
* | ||
* @author Archimedes Trajano | ||
*/ | ||
@Component | ||
@Provider | ||
@Priority(Priorities.AUTHORIZATION) | ||
public class MDCInterceptor implements | ||
ContainerRequestFilter { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(MDCInterceptor.class); | ||
|
||
@Autowired | ||
private MicroserviceEngine engine; | ||
|
||
@Override | ||
public void filter(final ContainerRequestContext requestContext) { | ||
|
||
MDC.put(MDCKeys.REQUEST_ID, requestContext.getHeaderString(MDCKeys.REQUEST_ID)); | ||
if (LOG.isDebugEnabled()) { | ||
MDC.put(MDCKeys.REQUEST_METHOD, requestContext.getMethod()); | ||
MDC.put(MDCKeys.REQUEST_URI, requestContext.getUriInfo().getRequestUri().toASCIIString()); | ||
MDC.put(MDCKeys.HOST, engine.hostname() + ":" + engine.port()); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.