RestClient implements AutoCloseable { static <T extends BmcRequest> InvocationInformation preprocessRequest( WrappedInvocationBuilder ib, T request) { NonSubmittingInvocationBuilder nonSubmittingInvocationBuilder = new NonSubmittingInvocationBuilder(ib); Consumer<Invocation.Builder> invocationPreprocessor = request.getInvocationCallback(); if (invocationPreprocessor != null) { invocationPreprocessor.accept(nonSubmittingInvocationBuilder); } Object first = ib.getHeaders().getFirst(BmcException.OPC_REQUEST_ID_HEADER); String requestId; if (first == null) { requestId = generateRequestId(); LOG.debug("Generated request ID: {} for URI {}", requestId, ib.getRequestUri()); ib.header(BmcException.OPC_REQUEST_ID_HEADER, requestId); } else { requestId = first.toString(); LOG.debug("User-set request ID: {}", requestId); } return new InvocationInformation(requestId, ib.getHeaders()); } RestClient(
            @NonNull Client client,
            @NonNull EntityFactory entityFactory,
            JaxRsCircuitBreaker circuitBreaker); void setEndpoint(@NonNull String endpoint); @Override void close(); WrappedWebTarget getBaseTarget(); Response get(
            @NonNull WrappedInvocationBuilder ib, @NonNull T request); Future<Response> get(
            @NonNull WrappedInvocationBuilder ib,
            @NonNull T request,
            @Nullable Consumer<Response> onSuccess,
            @Nullable Consumer<Throwable> onError); Response post(
            @NonNull WrappedInvocationBuilder ib, @Nullable Object body, @NonNull T request); Future<Response> post(
            @NonNull WrappedInvocationBuilder ib,
            @Nullable Object body,
            @NonNull T request,
            @Nullable Consumer<Response> onSuccess,
            @Nullable Consumer<Throwable> onError); Response post(
            @NonNull WrappedInvocationBuilder ib, @NonNull T request); Future<Response> post(
            @NonNull WrappedInvocationBuilder ib,
            @NonNull T request,
            @Nullable Consumer<Response> onSuccess,
            @Nullable Consumer<Throwable> onError); Response patch(
            @NonNull WrappedInvocationBuilder ib, @NonNull T request); Response patch(
            @NonNull WrappedInvocationBuilder ib, @Nullable Object body, @NonNull T request); Future<Response> patch(
            @NonNull WrappedInvocationBuilder ib,
            @NonNull T request,
            @Nullable Consumer<Response> onSuccess,
            @Nullable Consumer<Throwable> onError); Future<Response> patch(
            @NonNull WrappedInvocationBuilder ib,
            @Nullable Object body,
            @NonNull T request,
            @Nullable Consumer<Response> onSuccess,
            @Nullable Consumer<Throwable> onError); Response put(
            @NonNull WrappedInvocationBuilder ib, @NonNull T request); Response put(
            @NonNull WrappedInvocationBuilder ib, @Nullable Object body, @NonNull T request); Future<Response> put(
            @NonNull WrappedInvocationBuilder ib,
            @NonNull T request,
            @Nullable Consumer<Response> onSuccess,
            @Nullable Consumer<Throwable> onError); Future<Response> put(
            @NonNull WrappedInvocationBuilder ib,
            @Nullable Object body,
            @NonNull T request,
            @Nullable Consumer<Response> onSuccess,
            @Nullable Consumer<Throwable> onError); Response delete(
            @NonNull WrappedInvocationBuilder ib, @NonNull T request); Future<Response> delete(
            @NonNull WrappedInvocationBuilder ib,
            @NonNull T request,
            @Nullable Consumer<Response> onSuccess,
            @Nullable Consumer<Throwable> onError); Response head(
            @NonNull WrappedInvocationBuilder ib, @NonNull T request); Future<Response> head(
            @NonNull WrappedInvocationBuilder ib,
            @NonNull T request,
            @Nullable Consumer<Response> onSuccess,
            @Nullable Consumer<Throwable> onError);  }
@Test @Ignore public void filter_headerAbsent() throws IOException { final String testVal = "testVal"; final String testKey = "testKey"; URI requestURI = PowerMockito.mock(URI.class); BmcRequest request = new BmcRequest(); request.setInvocationCallback( new Consumer<Invocation.Builder>() { @Override public void accept(Invocation.Builder builder) { builder.header(testKey, testVal); } }); WrappedInvocationBuilder wib = new WrappedInvocationBuilder(ib, requestURI); RestClient.InvocationInformation info = RestClient.preprocessRequest(wib, request); assertEquals(1, info.getHeadersSetInCallback().size()); assertEquals(testVal, info.getHeadersSetInCallback().getFirst(testKey)); assertNotNull(info.getRequestId()); assertFalse(testVal.equals(info.getRequestId())); }
@Test @Ignore public void filter_noCallback() throws IOException { BmcRequest request = new BmcRequest(); URI requestURI = PowerMockito.mock(URI.class); WrappedInvocationBuilder wib = new WrappedInvocationBuilder(ib, requestURI); RestClient.InvocationInformation info = RestClient.preprocessRequest(wib, request); assertEquals(0, info.getHeadersSetInCallback().size()); assertNotNull(info.getRequestId()); }