Search in sources :

Example 1 with RequestData

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;
}
Also used : RequestData(org.killbill.commons.request.RequestData)

Example 2 with RequestData

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);
}
Also used : PluginDispatcherReturnType(org.killbill.billing.payment.dispatcher.PluginDispatcher.PluginDispatcherReturnType) RequestData(org.killbill.commons.request.RequestData) Callable(java.util.concurrent.Callable) Test(org.testng.annotations.Test)

Example 3 with RequestData

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;
                }
            }
        });
    }
}
Also used : Function(com.google.common.base.Function) BiFunction(java.util.function.BiFunction) RequestData(org.killbill.commons.request.RequestData) List(java.util.List)

Aggregations

RequestData (org.killbill.commons.request.RequestData)3 Function (com.google.common.base.Function)1 List (java.util.List)1 Callable (java.util.concurrent.Callable)1 BiFunction (java.util.function.BiFunction)1 PluginDispatcherReturnType (org.killbill.billing.payment.dispatcher.PluginDispatcher.PluginDispatcherReturnType)1 Test (org.testng.annotations.Test)1