@Override public void filter(ContainerRequestContext request, ContainerResponseContext response) throws IOException { super.filter(request, response); if (response instanceof ContainerResponseContextImpl) { ContainerResponseContextImpl containerResponseImpl = (ContainerResponseContextImpl) response; EnrichQueryMetrics e = FindAnnotation.findAnnotation(containerResponseImpl.getJaxrsResponse().getAnnotations(), EnrichQueryMetrics.class); if (e != null) { Object entity = response.getEntity(); if (entity instanceof GenericResponse) { @SuppressWarnings("unchecked") GenericResponse<String> qidResponse = (GenericResponse<String>) entity; request.setProperty(QueryCall.class.getName(), new QueryCall(e.methodType(), qidResponse.getResult())); } else if (entity instanceof BaseQueryResponse) { BaseQueryResponse baseResponse = (BaseQueryResponse) entity; request.setProperty(QueryCall.class.getName(), new QueryCall(e.methodType(), baseResponse.getQueryId())); } else if (entity instanceof QueryExecutorBean.ExecuteStreamingOutputResponse) { // The ExecuteStreamingOutputResponse class updates the metrics, no need to do it here } else { log.error("Unexpected response class for metrics annotated query method " + request.getUriInfo().getPath() + ". Response class was " + (entity == null ? "null response" : entity.getClass().toString())); } } } }
@Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { ContainerResponseContextImpl ctx = (ContainerResponseContextImpl)responseContext; BuiltResponse jaxrsResposne = ctx.getJaxrsResponse(); ServerResponse serverResponse = new ServerResponse(jaxrsResposne); try { interceptor.postProcess(serverResponse); } finally { jaxrsResposne.setStatus(serverResponse.getStatus()); jaxrsResposne.setAnnotations(serverResponse.getAnnotations()); jaxrsResposne.setEntity(serverResponse.getEntity()); jaxrsResposne.setMetadata(serverResponse.getMetadata()); jaxrsResposne.setEntityClass(serverResponse.getEntityClass()); jaxrsResposne.setGenericType(serverResponse.getGenericType()); } } }