Source:
<code>public Response handle(Request request) throws Exception { MultivaluedMap<String, Object> requestHeaders = new MultivaluedHashMap<>(); for (Map.Entry<String, String> entry : request.getHeaders().entries()) { requestHeaders.add(entry.getKey(), entry.getValue()); } Invocation.Builder invocationBuilder = client.target(request.getUri()).request().headers(requestHeaders); Invocation invocation; if (request.getBodyGenerator() == null) { invocation = invocationBuilder.build(request.getMethod()); } else { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); request.getBodyGenerator().write(byteArrayOutputStream); byteArrayOutputStream.close(); byte[] bytes = byteArrayOutputStream.toByteArray(); Entity<byte[]> entity = Entity.entity(bytes, (String) getOnlyElement(requestHeaders.get("Content-Type"))); invocation = invocationBuilder.build(request.getMethod(), entity); } javax.ws.rs.core.Response result; try { result = invocation.invoke(javax.ws.rs.core.Response.class); } catch (ProcessingException exception) { if (trace) { log.warn(exception.getCause(), "%-8s %s -> Exception", request.getMethod(), request.getUri()); } <START> throw (Exception) exception.getCause(); <END> } catch (Throwable throwable) { if (trace) { log.warn(throwable, "%-8s %s -> Fail", request.getMethod(), request.getUri()); } throw throwable; } ImmutableListMultimap.Builder<String, String> responseHeaders = ImmutableListMultimap.builder(); for (Map.Entry<String, List<String>> headerEntry : result.getStringHeaders().entrySet()) { for (String value : headerEntry.getValue()) { responseHeaders.put(headerEntry.getKey(), value); } } if (trace) { log.warn("%-8s %s -> OK", request.getMethod(), request.getUri()); } return new TestingResponse(HttpStatus.OK, responseHeaders.build(), result.readEntity(byte[].class)); }</code><technical_language>This ClassCastException, anything. needs wrapped if extend Exception</technical_language>

Target:
public Response handle(Request request) throws Exception { MultivaluedMap<String, Object> requestHeaders = new MultivaluedHashMap<>(); for (Map.Entry<String, String> entry : request.getHeaders().entries()) { requestHeaders.add(entry.getKey(), entry.getValue()); } Invocation.Builder invocationBuilder = client.target(request.getUri()).request().headers(requestHeaders); Invocation invocation; if (request.getBodyGenerator() == null) { invocation = invocationBuilder.build(request.getMethod()); } else { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); request.getBodyGenerator().write(byteArrayOutputStream); byteArrayOutputStream.close(); byte[] bytes = byteArrayOutputStream.toByteArray(); Entity<byte[]> entity = Entity.entity(bytes, (String) getOnlyElement(requestHeaders.get("Content-Type"))); invocation = invocationBuilder.build(request.getMethod(), entity); } javax.ws.rs.core.Response result; try { result = invocation.invoke(javax.ws.rs.core.Response.class); } catch (ProcessingException exception) { if (trace) { log.warn(exception.getCause(), "%-8s %s -> Exception", request.getMethod(), request.getUri()); } if (exception.getCause() instanceof Exception) { throw (Exception) exception.getCause(); } throw exception; } catch (Throwable throwable) { if (trace) { log.warn(throwable, "%-8s %s -> Fail", request.getMethod(), request.getUri()); } throw throwable; } ImmutableListMultimap.Builder<String, String> responseHeaders = ImmutableListMultimap.builder(); for (Map.Entry<String, List<String>> headerEntry : result.getStringHeaders().entrySet()) { for (String value : headerEntry.getValue()) { responseHeaders.put(headerEntry.getKey(), value); } } if (trace) { log.warn("%-8s %s -> OK", request.getMethod(), request.getUri()); } return new TestingResponse(HttpStatus.OK, responseHeaders.build(), result.readEntity(byte[].class)); }