Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
3.2.2
-
None
-
None
-
Unknown
Description
The JAX-RS 2.1 TCK is using ClientRequestFilters to verify that it is on a separate thread than the main client thread. Although it is not specific in the spec that providers like filters must be invoked on a new thread, I believe this line from the spec (section 8.4) is what they base this test on:
Note that in this example, the call to get after calling async returns immediately without blocking the caller’s thread.
Currently, we call WebClient.doInvokeAsync(...) which calls prepareAsyncClient(...) which calls doRunInterceptorChain(...) - all on the main client thread. As a result the filters on the outbound chain get executed on the same thread which breaks the test.
I wrote a simpler test case that similarly breaks, but could use some help with how to implement the fix:
public static class ThreadCheckFilter implements ClientRequestFilter {
@Override
public void filter(ClientRequestContext context) throws IOException
{ final Thread currentThread = Thread.currentThread(); context.abortWith(Response.ok(currentThread.getName()) .header("ThreadID", currentThread.getId()) .build()); }}
@Test
public void testClientRequestFilterRunsOnSepaarateThreadWhenInvokedAsynchronously() throws Exception
{ final Thread currentThread = Thread.currentThread(); Client client = ClientBuilder.newClient(); client.register(ThreadCheckFilter.class); WebTarget target = client.target("http://localhost:8080/notReal"); AsyncInvoker invoker = target.request().async(); Future<Response> future = invoker.get(); Response response = future.get(); assertNotEquals(currentThread.getName(), response.readEntity(String.class)); assertNotEquals(currentThread.getId(), Long.parseLong(response.getHeaderString("ThreadID"))); }