Source:
<code>public void testasync1() throws Exception { <START> Client client = ResteasyClientBuilder.newClient(); <END> Response response = null; latch = new CountDownLatch(1); long start = System.currentTimeMillis(); response = client.target("http://localhost:" + TestPortProvider.getPort() + "?asynch=true").request().post(Entity.entity("content", "text/plain")); long end = System.currentTimeMillis() - start; Assert.assertEquals(HttpServletResponse.SC_ACCEPTED, response.getStatus()); String jobUrl = response.getHeaderString(HttpHeaders.LOCATION); response.close(); Builder jobBuilder = client.target(jobUrl).request(); response = jobBuilder.get(); Assert.assertEquals(HttpServletResponse.SC_ACCEPTED, response.getStatus()); Assert.assertTrue(latch.await(3, TimeUnit.SECONDS)); response.close(); URI oldUri = new URI(jobUrl); String existingQueryString = oldUri.getQuery(); String newQuery = (existingQueryString == null ? "" : "&") + "wait=1000"; URI newUri = new URI(oldUri.getScheme(), oldUri.getAuthority(), oldUri.getPath(), newQuery, oldUri.getFragment()); response = client.target(newUri).request().get(); Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus()); Assert.assertEquals("content", response.readEntity(String.class)); response = jobBuilder.get(); Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus()); Assert.assertEquals("content", response.readEntity(String.class)); response = jobBuilder.delete(); Assert.assertEquals(HttpServletResponse.SC_NO_CONTENT, response.getStatus()); response = jobBuilder.get(); Assert.assertEquals(HttpServletResponse.SC_GONE, response.getStatus()); response.close(); }</code><technical_language>Close client () :-)</technical_language>

Target:
public void testasync1() throws Exception { Response response = null; latch = new CountDownLatch(1); long start = System.currentTimeMillis(); response = client.target("http://localhost:" + TestPortProvider.getPort() + "?asynch=true").request().post(Entity.entity("content", "text/plain")); long end = System.currentTimeMillis() - start; Assert.assertEquals(HttpServletResponse.SC_ACCEPTED, response.getStatus()); String jobUrl = response.getHeaderString(HttpHeaders.LOCATION); response.close(); Builder jobBuilder = client.target(jobUrl).request(); response = jobBuilder.get(); Assert.assertEquals(HttpServletResponse.SC_ACCEPTED, response.getStatus()); Assert.assertTrue(latch.await(3, TimeUnit.SECONDS)); response.close(); URI oldUri = new URI(jobUrl); String existingQueryString = oldUri.getQuery(); String newQuery = (existingQueryString == null ? "" : "&") + "wait=1000"; URI newUri = new URI(oldUri.getScheme(), oldUri.getAuthority(), oldUri.getPath(), newQuery, oldUri.getFragment()); response = client.target(newUri).request().get(); Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus()); Assert.assertEquals("content", response.readEntity(String.class)); response = jobBuilder.get(); Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus()); Assert.assertEquals("content", response.readEntity(String.class)); response = jobBuilder.delete(); Assert.assertEquals(HttpServletResponse.SC_NO_CONTENT, response.getStatus()); response = jobBuilder.get(); Assert.assertEquals(HttpServletResponse.SC_GONE, response.getStatus()); response.close(); }