public static ResponseBuilder fromResponse(Response response) { return fromResponse(response, true); }
protected Response buildResponse(Response response, String responseText) { Response.ResponseBuilder rb = JAXRSUtils.fromResponse(response); if (responseText != null) { rb.type(MediaType.TEXT_PLAIN).entity(responseText); } return rb.build(); }
public static Response copyResponseIfNeeded(Response response) { if (!(response instanceof ResponseImpl)) { Response r = fromResponse(response).build(); Field[] declaredFields = ReflectionUtil.getDeclaredFields(response.getClass()); for (Field f : declaredFields) { Class<?> declClass = f.getType(); if (declClass == Annotation[].class) { try { Annotation[] fieldAnnotations = ReflectionUtil.accessDeclaredField(f, response, Annotation[].class); ((ResponseImpl)r).setEntityAnnotations(fieldAnnotations); } catch (Throwable ex) { LOG.warning("Custom annotations if any can not be copied"); } break; } } return r; } return response; }
public static Response copyResponseIfNeeded(Response response) { if (!(response instanceof ResponseImpl)) { Response r = fromResponse(response).build(); Field[] declaredFields = ReflectionUtil.getDeclaredFields(response.getClass()); for (Field f : declaredFields) { Class<?> declClass = f.getType(); if (declClass == Annotation[].class) { try { Annotation[] fieldAnnotations = ReflectionUtil.accessDeclaredField(f, response, Annotation[].class); ((ResponseImpl)r).setEntityAnnotations(fieldAnnotations); } catch (Throwable ex) { LOG.warning("Custom annotations if any can not be copied"); } break; } } return r; } else { return response; } }
public Response toResponse(WebApplicationException ex) { Response r = ex.getResponse(); if (r == null) { r = Response.serverError().build(); } boolean doAddMessage = r.getEntity() != null ? false : addMessageToResponse; Message msg = PhaseInterceptorChain.getCurrentMessage(); FaultListener flogger = null; if (msg != null) { flogger = (FaultListener)PhaseInterceptorChain.getCurrentMessage() .getContextualProperty(FaultListener.class.getName()); } String errorMessage = doAddMessage || flogger != null ? buildErrorMessage(r, ex) : null; if (flogger == null || !flogger.faultOccurred(ex, errorMessage, msg)) { Level level = printStackTrace ? Level.WARNING : Level.FINE; LOG.log(level, getStackTrace(ex)); } if (doAddMessage) { r = JAXRSUtils.copyResponseIfNeeded(r); r = JAXRSUtils.fromResponse(r).entity(errorMessage).type(MediaType.TEXT_PLAIN).build(); } return r; }
protected ResponseBuilder setResponseBuilder(Message outMessage, Exchange exchange) throws Exception { Response response = exchange.get(Response.class); if (response != null) { return JAXRSUtils.fromResponse(JAXRSUtils.copyResponseIfNeeded(response));
if (response != null) { outMessage.getExchange().getInMessage().put(Message.PROTOCOL_HEADERS, response.getStringHeaders()); return JAXRSUtils.fromResponse(JAXRSUtils.copyResponseIfNeeded(response));
if (response != null) { outMessage.getExchange().getInMessage().put(Message.PROTOCOL_HEADERS, response.getStringHeaders()); return JAXRSUtils.fromResponse(JAXRSUtils.copyResponseIfNeeded(response));
rb = JAXRSUtils.fromResponse(currentResponse);
protected Response handleResponse(Message outMessage, Class<?> responseClass, Type genericType) { try { ResponseBuilder rb = setResponseBuilder(outMessage, outMessage.getExchange()); Response currentResponse = rb.clone().build(); ((ResponseImpl)currentResponse).setOutMessage(outMessage); Object entity = readBody(currentResponse, outMessage, responseClass, genericType, new Annotation[]{}); if (entity == null) { int status = currentResponse.getStatus(); if (status >= 400) { entity = currentResponse.getEntity(); } } rb = JAXRSUtils.fromResponse(currentResponse, false); rb.entity(entity instanceof Response ? ((Response)entity).getEntity() : entity); Response r = rb.build(); getState().setResponse(r); ((ResponseImpl)r).setOutMessage(outMessage); return r; } catch (Throwable ex) { throw (ex instanceof ProcessingException) ? (ProcessingException)ex : new ProcessingException(ex); } finally { ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies(); } }
protected Response handleResponse(Message outMessage, Class<?> responseClass, Type genericType) { try { ResponseBuilder rb = setResponseBuilder(outMessage, outMessage.getExchange()); Response currentResponse = rb.clone().build(); ((ResponseImpl)currentResponse).setOutMessage(outMessage); Object entity = readBody(currentResponse, outMessage, responseClass, genericType, new Annotation[]{}); if (entity == null) { int status = currentResponse.getStatus(); if (status >= 400) { entity = currentResponse.getEntity(); } } rb = JAXRSUtils.fromResponse(currentResponse, false); rb.entity(entity instanceof Response ? ((Response)entity).getEntity() : entity); Response r = rb.build(); getState().setResponse(r); ((ResponseImpl)r).setOutMessage(outMessage); return r; } catch (Throwable ex) { throw (ex instanceof ProcessingException) ? (ProcessingException)ex : new ProcessingException(ex); } finally { ClientProviderFactory.getInstance(outMessage).clearThreadLocalProxies(); } }