use of org.jboss.resteasy.plugins.providers.jaxb.JAXBUnmarshalException in project stdlib by petergeneric.
the class RemoteExceptionClientResponseFilter method filter.
@Override
public void filter(final ClientRequestContext requestContext, final ClientResponseContext responseContext) throws IOException {
final int code = responseContext.getStatus();
String operationId;
if (Tracing.isVerbose()) {
operationId = requestContext.getHeaderString(TracingConstants.HTTP_HEADER_CORRELATION_ID);
if (operationId != null)
Tracing.logOngoing(operationId, "HTTP:resp", () -> "" + code);
else
// can't find outgoing trace id
operationId = Tracing.log("HTTP:resp:unexpected", () -> "" + code);
} else {
operationId = null;
}
if (code >= 200 && code <= 299)
// Do not run if the return code is 2xx
return;
if (responseContext.getHeaders().containsKey(RestThrowableConstants.HEADER_RICH_EXCEPTION)) {
try {
final InputStream is = responseContext.getEntityStream();
RestFailure failure;
if (tryParseLegacyExceptionNamespace) {
// If parsing the legacy namespace fails, throw the original parse error back to the client
try {
// Mark the start of the stream so we can reset back to it if we need to process this as a legacy exception
is.mark(Integer.MAX_VALUE);
failure = parseResponse(is);
} catch (JAXBUnmarshalException e) {
log.trace("Error parsing rich exception response, will fall back on parsing it as a legacy exception XML", e);
try {
failure = parseLegacyResponse(is);
} catch (Throwable legacyFailure) {
log.trace("Error parsing rich exception response as legacy rich exception XML!", legacyFailure);
// throw the original exception
throw e;
}
}
} else {
failure = parseResponse(is);
}
if (Tracing.isVerbose() && failure != null && failure.exception != null) {
final ExceptionInfo ei = failure.exception;
Tracing.logOngoing(operationId, "HTTP:error", () -> ei.shortName + " " + ei.detail);
}
RestException exception = exceptionFactory.build(failure, responseContext);
// Try to shorten the stack trace
exception.fillInStackTrace();
throw exception;
} catch (ResponseProcessingException e) {
throw e;
} catch (Throwable e) {
throw new ResponseProcessingException(null, "Error mapping exception from thrown from " + requestContext.getUri() + " to exception!", e);
}
}
}
use of org.jboss.resteasy.plugins.providers.jaxb.JAXBUnmarshalException in project candlepin by candlepin.
the class JAXBUnmarshalExceptionMapperTest method handleExceptionWithResponse.
@Test
public void handleExceptionWithResponse() {
Response mockr = mock(Response.class);
when(mockr.getStatus()).thenReturn(500);
JAXBUnmarshalException nfe = new JAXBUnmarshalException("unacceptable", mockr);
JAXBUnmarshalExceptionMapper nfem = injector.getInstance(JAXBUnmarshalExceptionMapper.class);
Response r = nfem.toResponse(nfe);
assertEquals(500, r.getStatus());
verifyMessage(r, rtmsg("unacceptable"));
}
use of org.jboss.resteasy.plugins.providers.jaxb.JAXBUnmarshalException in project candlepin by candlepin.
the class JAXBUnmarshalExceptionMapperTest method handleExceptionWithoutResponse.
@Test
public void handleExceptionWithoutResponse() {
JAXBUnmarshalException nfe = new JAXBUnmarshalException("unacceptable");
JAXBUnmarshalExceptionMapper nfem = injector.getInstance(JAXBUnmarshalExceptionMapper.class);
Response r = nfem.toResponse(nfe);
assertEquals(400, r.getStatus());
verifyMessage(r, rtmsg("unacceptable"));
}
Aggregations