public ServerResponse(final BuiltResponse response) { this.setEntity(response.getEntity()); this.setAnnotations(response.getAnnotations()); this.setStatus(response.getStatus()); this.setMetadata(response.getMetadata()); this.setEntityClass(response.getEntityClass()); this.setGenericType(response.getGenericType()); this.setReasonPhrase(response.getReasonPhrase()); } }
private BuiltResponse createResponse(Object value, MediaType contentType) { BuiltResponse responseImpl = new BuiltResponse(); responseImpl.setEntity(value); if (contentType != null) responseImpl.getMetadata().putSingle(HttpHeaderNames.CONTENT_TYPE, contentType); return responseImpl; }
@Override public boolean bufferEntity() { abortIfClosed(); // no-op return false; }
public static Exception getCause(BuiltResponse resp) { if (resp == null || resp.getStatus() != Status.EXPECTATION_FAILED.getStatusCode()) return null; String exceptionClass = resp.getHeaderString(EXCEPTION_HEADER); if (!StringUtils.isBlank(exceptionClass)) { String body = resp.readEntity(String.class); resp.close(); try { ByteArrayInputStream bais = new ByteArrayInputStream( Base64.decode(body.getBytes(MotanConstants.DEFAULT_CHARACTER))); ObjectInputStream ois = new ObjectInputStream(bais); return (Exception) ois.readObject(); } catch (Exception e) { LoggerUtil.error("deserialize " + exceptionClass + " error", e); } } return null; }
Object entity = jaxrsResponse.isClosed() ? null : jaxrsResponse.getEntity(); response.setStatus(jaxrsResponse.getStatus()); commitHeaders(jaxrsResponse, response); return; Class type = jaxrsResponse.getEntityClass(); Type generic = jaxrsResponse.getGenericType(); Annotation[] annotations = jaxrsResponse.getAnnotations(); @SuppressWarnings(value = "unchecked") final MediaType mt = jaxrsResponse.getMediaType(); MessageBodyWriter writer = providerFactory.getMessageBodyWriter( type, generic, annotations, mt); response.setStatus(jaxrsResponse.getStatus()); final BuiltResponse built = jaxrsResponse; CommitHeaderOutputStream.CommitCallback callback = new CommitHeaderOutputStream.CommitCallback() jaxrsResponse.getMetadata(), os, request);
Class type = jaxrsResponse.getEntityClass(); Object ent = jaxrsResponse.getEntity(); Type generic = jaxrsResponse.getGenericType(); if (generic == null) else generic = type; Annotation[] annotations = jaxrsResponse.getAnnotations(); if (annotations == null && method != null)
build.addMethodAnnotations(getMethodAnnotations()); return build; Headers<Object> metadata = new Headers<Object>(); metadata.putAll(r.getMetadata()); rtn = new BuiltResponse(r.getStatus(), r.getStatusInfo().getReasonPhrase(), metadata, r.getEntity(), null); rtn1.addMethodAnnotations(getMethodAnnotations()); if (rtn1.getGenericType() == null) rtn1.setGenericType(rtn1.getEntityClass()); rtn1.setGenericType(method.getGenericReturnType()); if (jaxrsResponse.getGenericType() == null) jaxrsResponse.setGenericType(jaxrsResponse.getEntityClass()); jaxrsResponse.setGenericType(method.getGenericReturnType()); jaxrsResponse.addMethodAnnotations(getMethodAnnotations()); return jaxrsResponse;
if (response instanceof BuiltResponse) { BuiltResponse built = (BuiltResponse) response; setEntityClass(built.getEntityClass()); setGenericType(built.getGenericType()); setAnnotations(built.getAnnotations());
@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()); } } }
@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); }
Headers<Object> metadata = new Headers<Object>(); metadata.putAll(r.getMetadata()); builtResponse = new BuiltResponse(r.getStatus(), r.getStatusInfo().getReasonPhrase(), metadata, r.getEntity(), method.getMethodAnnotations()); Type newType = adaptGenericType(unwrappedType); jaxrsResponse.setGenericType(newType); jaxrsResponse.addMethodAnnotations(method.getMethodAnnotations()); builtResponse = jaxrsResponse;
if (builtResponse.getEntity() instanceof OutboundSseEvent) OutboundSseEvent entity = (OutboundSseEvent)builtResponse.getEntity(); elementType = entity.getMediaType(); .data(builtResponse.getEntityClass(), builtResponse.getEntity()) .build();
@Override public synchronized Object getEntity() { abortIfClosed(); Object entity = super.getEntity(); if (entity != null) { return entity; } //Check if the entity was previously fully consumed if (streamFullyRead && bufferedEntity == null) { throw new IllegalStateException(); } return getEntityStream(); }
public static MediaType getResponseMediaType(BuiltResponse jaxrsResponse, HttpRequest request, HttpResponse response, ResteasyProviderFactory providerFactory, ResourceMethodInvoker method) { MediaType mt = null; if (!jaxrsResponse.isClosed() && jaxrsResponse.getEntity() != null) { if ((mt = jaxrsResponse.getMediaType()) == null) { mt = getDefaultContentType(request, jaxrsResponse, providerFactory, method); } boolean addCharset = true; ResteasyDeployment deployment = ResteasyContext.getContextData(ResteasyDeployment.class); if (deployment != null) { addCharset = deployment.isAddCharset(); } if (addCharset) { if (!mt.getParameters().containsKey(MediaType.CHARSET_PARAMETER)) { if (MediaTypeHelper.isTextLike(mt)) { mt = mt.withCharset(StandardCharsets.UTF_8.toString()); } } } } return mt; }
@Override public Class<?> getEntityClass() { return jaxrsResponse.getEntityClass(); }
.mediaType(builtResponse.getMediaType()) .data(builtResponse.getEntityClass(), builtResponse.getEntity()) .build(); sendingEvent = true;
@Override public Response build() { if (status == -1 && entity == null) status = 204; else if (status == -1) status = 200; return new BuiltResponse(status, reasonPhrase, metadata, entity, entityAnnotations); }
String mediaTypeString = builtResponse.getHeaderString("Content-Type"); if (mediaTypeString == null) headerMap.putAll(builtResponse.getHeaders()); headerMap.remove("Content-Type"); headerMap.add("Content-Type", mediaType); builtResponse.setMetadata(headerMap);
@Override public Type getEntityType() { return jaxrsResponse.getGenericType(); }