@Override public synchronized void resume() { if(!suspended) throw new RuntimeException("Cannot resume: not suspended"); if(inFilter) { // suspend/resume within filter, same thread: just ignore and move on suspended = false; return; } ResteasyProviderFactory.pushContextDataMap(contextDataMap); // go on, but with proper exception handling try { filter(); }catch(Throwable t) { // don't throw to client writeException(t); } }
@Override public void setEntity(Object entity) { //if (entity != null) logger.info("*** setEntity(Object) " + entity.toString()); jaxrsResponse.setEntity(entity); // todo TCK does weird things in its testing of get length // it resets the entity in a response filter which results // in a bad content-length being sent back to the client // so, we'll remove any content-length setting getHeaders().remove(HttpHeaders.CONTENT_LENGTH); }
@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())); } } } }
ContainerResponseContextImpl responseContext = new ContainerResponseContextImpl(request, response, jaxrsResponse, requestContext, responseFilters, onComplete, continuation); responseContext.filter();
@Override public synchronized void resume(Throwable t) { if(!suspended) throw new RuntimeException("Cannot resume: not suspended"); if(inFilter) { // not suspended, or suspend/abortWith within filter, same thread: collect and move on throwable = t; suspended = false; } else { ResteasyProviderFactory.pushContextDataMap(contextDataMap); writeException(t); } }
@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()); } } }
else writeException(throwable); return;
@Override public void setEntity(Object entity, Annotation[] annotations, MediaType mediaType) { //if (entity != null) logger.info("*** setEntity(Object, Annotation[], MediaType) " + entity.toString() + ", " + mediaType); jaxrsResponse.setEntity(entity); jaxrsResponse.setAnnotations(annotations); jaxrsResponse.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, mediaType); // todo TCK does weird things in its testing of get length // it resets the entity in a response filter which results // in a bad content-length being sent back to the client // so, we'll remove any content-length setting getHeaders().remove(HttpHeaders.CONTENT_LENGTH); }