-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created a ClientRequestFilter to use with correlation id
- Loading branch information
Davide Cerbo
committed
Nov 14, 2016
1 parent
ef06d73
commit f06b32f
Showing
2 changed files
with
47 additions
and
0 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
27 changes: 27 additions & 0 deletions
27
...ationid/src/main/java/com/nutcore/nut/correlationid/CorrelationIdClientRequestFilter.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,27 @@ | ||
package com.nutcore.nut.correlationid; | ||
|
||
import javax.ws.rs.client.ClientRequestContext; | ||
import javax.ws.rs.client.ClientRequestFilter; | ||
import javax.ws.rs.core.MultivaluedMap; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
|
||
/** | ||
* Created by davidecerbo on 14/11/2016. | ||
*/ | ||
public class CorrelationIdClientRequestFilter implements ClientRequestFilter | ||
{ | ||
|
||
@Override | ||
public void filter(ClientRequestContext requestContext) throws IOException | ||
{ | ||
CorrelationId correlationId = CorrelationIdUtil.getId(); | ||
if(correlationId != null){ | ||
MultivaluedMap<String, Object> headers = requestContext.getHeaders(); | ||
headers.put(CorrelationIdFilter.CORRELATION_ID_HEADER, Arrays.asList(correlationId.getId())); | ||
headers.put(CorrelationIdFilter.CORRELATION_ID_SOURCE_HEADER, Arrays.asList(correlationId.getSource())); | ||
headers.put(CorrelationIdFilter.CORRELATION_ID_TIME_HEADER, Arrays.asList(correlationId.getCreationTime())); | ||
} | ||
} | ||
|
||
} |