use of org.killbill.commons.request.RequestData in project killbill by killbill.
the class RequestDataFilter method filter.
@Override
public ContainerRequest filter(final ContainerRequest request) {
final List<String> requestIdHeaderRequests = getRequestId(request);
final String requestId = (requestIdHeaderRequests == null || requestIdHeaderRequests.isEmpty()) ? UUIDs.randomUUID().toString() : requestIdHeaderRequests.get(0);
Request.setPerThreadRequestData(new RequestData(requestId));
return request;
}
use of org.killbill.commons.request.RequestData in project killbill by killbill.
the class TestPluginDispatcher method testDispatchWithRequestData.
@Test(groups = "fast")
public void testDispatchWithRequestData() throws TimeoutException, PaymentApiException, ExecutionException, InterruptedException {
final String requestId = "vive la vie et les coquillettes";
final Callable<PluginDispatcherReturnType<String>> delegate = new Callable<PluginDispatcherReturnType<String>>() {
@Override
public PluginDispatcherReturnType<String> call() throws Exception {
return PluginDispatcher.<String>createPluginDispatcherReturnType(Request.getPerThreadRequestData().getRequestId());
}
};
final CallableWithRequestData<PluginDispatcherReturnType<String>> callable = new CallableWithRequestData<PluginDispatcherReturnType<String>>(new RequestData(requestId), UUIDs.getRandom(), null, null, MDC.getCopyOfContextMap(), delegate);
final String actualRequestId = stringPluginDispatcher.dispatchWithTimeout(callable, 100, TimeUnit.MILLISECONDS);
Assert.assertEquals(actualRequestId, requestId);
}
use of org.killbill.commons.request.RequestData in project killbill by killbill.
the class RequestDataFilter method filter.
@Override
public void filter(final ContainerRequestContext requestContext) {
final List<String> requestIdHeaderRequests = getRequestId(requestContext);
final String requestId = (requestIdHeaderRequests == null || requestIdHeaderRequests.isEmpty()) ? UUIDs.randomUUID().toString() : requestIdHeaderRequests.get(0);
Request.setPerThreadRequestData(new RequestData(requestId));
final List<String> kbEncodingHeaders = requestContext.getHeaders().get(KILL_BILL_ENCODING_HEADER);
final String kbEncodingHeader = (kbEncodingHeaders == null || kbEncodingHeaders.isEmpty()) ? null : kbEncodingHeaders.get(0);
if (kbEncodingHeader != null) {
requestContext.getHeaders().replaceAll(new BiFunction<String, List<String>, List<String>>() {
@Override
public List<String> apply(final String k, final List<String> v) {
if (k.equalsIgnoreCase(JaxrsResource.HDR_COMMENT) || k.equalsIgnoreCase(JaxrsResource.HDR_REASON) || k.equalsIgnoreCase(JaxrsResource.HDR_CREATED_BY)) {
return Lists.transform(v, new Function<String, String>() {
@Override
public String apply(final String input) {
if ("base64".equalsIgnoreCase(kbEncodingHeader)) {
try {
return new String(Base64.getDecoder().decode(input));
} catch (final IllegalArgumentException e) {
// Not Base64 after all? Be lenient...
return input;
}
} else {
return input;
}
}
});
} else {
return v;
}
}
});
}
}
Aggregations