use of com.fasterxml.jackson.core.JsonProcessingException in project riposte by Nike-Inc.
the class ExceptionHandlingHandlerTest method processError_returns_value_of_processUnhandledError_if_riposteErrorHandler_returns_null.
@Test
public void processError_returns_value_of_processUnhandledError_if_riposteErrorHandler_returns_null() throws UnexpectedMajorErrorHandlingError, JsonProcessingException {
// given
HttpProcessingState stateMock = mock(HttpProcessingState.class);
Object msg = new Object();
Throwable cause = new Exception();
ExceptionHandlingHandler handlerSpy = spy(handler);
ResponseInfo<ErrorResponseBody> responseInfoMockFromCatchallMethod = mock(ResponseInfo.class);
doReturn(null).when(riposteErrorHandlerMock).maybeHandleError(any(), any());
doReturn(responseInfoMockFromCatchallMethod).when(handlerSpy).processUnhandledError(stateMock, msg, cause);
// when
ResponseInfo<ErrorResponseBody> response = handlerSpy.processError(stateMock, msg, cause);
// then
verify(riposteErrorHandlerMock).maybeHandleError(any(), any());
assertThat(response, is(responseInfoMockFromCatchallMethod));
}
use of com.fasterxml.jackson.core.JsonProcessingException in project dropbox-sdk-java by dropbox.
the class DbxRequestUtil method unexpectedStatus.
public static DbxException unexpectedStatus(HttpRequestor.Response response, String userId) throws NetworkIOException, BadResponseException {
String requestId = getRequestId(response);
String message = null;
DbxException networkError;
switch(response.getStatusCode()) {
case 400:
message = DbxRequestUtil.messageFromResponse(response, requestId);
networkError = new BadRequestException(requestId, message);
break;
case 401:
message = DbxRequestUtil.messageFromResponse(response, requestId);
networkError = new InvalidAccessTokenException(requestId, message);
break;
case 403:
try {
ApiErrorResponse<AccessError> accessErrorResponse = new ApiErrorResponse.Serializer<AccessError>(AccessError.Serializer.INSTANCE).deserialize(response.getBody());
if (accessErrorResponse.getUserMessage() != null) {
message = accessErrorResponse.getUserMessage().toString();
}
AccessError accessError = accessErrorResponse.getError();
networkError = new AccessErrorException(requestId, message, accessError);
} catch (JsonProcessingException ex) {
throw new BadResponseException(requestId, "Bad JSON: " + ex.getMessage(), ex);
} catch (IOException ex) {
throw new NetworkIOException(ex);
}
break;
case 422:
try {
ApiErrorResponse<PathRootError> pathRootErrorResponse = new ApiErrorResponse.Serializer<PathRootError>(Serializer.INSTANCE).deserialize(response.getBody());
if (pathRootErrorResponse.getUserMessage() != null) {
message = pathRootErrorResponse.getUserMessage().toString();
}
PathRootError pathRootError = pathRootErrorResponse.getError();
networkError = new PathRootErrorException(requestId, message, pathRootError);
} catch (JsonProcessingException ex) {
throw new BadResponseException(requestId, "Bad JSON: " + ex.getMessage(), ex);
} catch (IOException ex) {
throw new NetworkIOException(ex);
}
break;
case 429:
try {
int backoffSecs = Integer.parseInt(getFirstHeader(response, "Retry-After"));
networkError = new RateLimitException(requestId, message, backoffSecs, TimeUnit.SECONDS);
break;
} catch (NumberFormatException ex) {
networkError = new BadResponseException(requestId, "Invalid value for HTTP header: \"Retry-After\"");
break;
}
case 500:
networkError = new ServerException(requestId, message);
break;
case 503:
// API v1 may include Retry-After in 503 responses, v2 does not
String retryAfter = getFirstHeaderMaybe(response, "Retry-After");
try {
if (retryAfter != null && !retryAfter.trim().isEmpty()) {
int backoffSecs = Integer.parseInt(retryAfter);
networkError = new RetryException(requestId, message, backoffSecs, TimeUnit.SECONDS);
break;
} else {
networkError = new RetryException(requestId, message);
break;
}
} catch (NumberFormatException ex) {
networkError = new BadResponseException(requestId, "Invalid value for HTTP header: \"Retry-After\"");
break;
}
default:
networkError = new BadResponseCodeException(requestId, "unexpected HTTP status code: " + response.getStatusCode() + ": " + message, response.getStatusCode());
}
DbxGlobalCallbackFactory factory = DbxRequestUtil.sharedCallbackFactory;
if (factory != null) {
DbxNetworkErrorCallback callback = factory.createNetworkErrorCallback(userId);
callback.onNetworkError(networkError);
}
return networkError;
}
use of com.fasterxml.jackson.core.JsonProcessingException in project jsonschema2pojo by joelittlejohn.
the class ContentResolver method resolveFromClasspath.
private JsonNode resolveFromClasspath(URI uri) {
String path = removeStart(removeStart(uri.toString(), uri.getScheme() + ":"), "/");
InputStream contentAsStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
if (contentAsStream == null) {
throw new IllegalArgumentException("Couldn't read content from the classpath, file not found: " + uri);
}
try {
return OBJECT_MAPPER.readTree(contentAsStream);
} catch (JsonProcessingException e) {
throw new IllegalArgumentException("Error parsing document: " + uri, e);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Unrecognised URI, can't resolve this: " + uri, e);
} catch (IOException e) {
throw new IllegalArgumentException("Unrecognised URI, can't resolve this: " + uri, e);
}
}
use of com.fasterxml.jackson.core.JsonProcessingException in project druid by druid-io.
the class LookupCoordinatorManagerTest method testParseErrorUpdateAllOnHost.
@Test
public void testParseErrorUpdateAllOnHost() throws Exception {
final AtomicReference<List<Map<String, Object>>> configVal = new AtomicReference<>(null);
final URL url = LookupCoordinatorManager.getLookupsURL(HostAndPort.fromString("localhost"));
EasyMock.reset(configManager);
EasyMock.expect(configManager.watch(EasyMock.anyString(), EasyMock.<TypeReference>anyObject())).andReturn(configVal);
final JsonProcessingException ex = EasyMock.createStrictMock(JsonProcessingException.class);
final ObjectMapper mapper = EasyMock.createStrictMock(ObjectMapper.class);
EasyMock.expect(mapper.writeValueAsBytes(EasyMock.eq(SINGLE_LOOKUP_MAP))).andThrow(ex);
expectedException.expectCause(new BaseMatcher<Throwable>() {
@Override
public boolean matches(Object o) {
return ex == o;
}
@Override
public void describeTo(Description description) {
}
});
EasyMock.replay(mapper);
final LookupCoordinatorManager manager = new LookupCoordinatorManager(client, discoverer, mapper, configManager, lookupCoordinatorManagerConfig);
try {
manager.updateAllOnHost(url, SINGLE_LOOKUP_MAP);
} finally {
EasyMock.verify(mapper);
}
}
use of com.fasterxml.jackson.core.JsonProcessingException in project druid by druid-io.
the class AsyncQueryForwardingServlet method sendProxyRequest.
@Override
protected void sendProxyRequest(HttpServletRequest clientRequest, HttpServletResponse proxyResponse, Request proxyRequest) {
proxyRequest.timeout(httpClientConfig.getReadTimeout().getMillis(), TimeUnit.MILLISECONDS);
proxyRequest.idleTimeout(httpClientConfig.getReadTimeout().getMillis(), TimeUnit.MILLISECONDS);
final Query query = (Query) clientRequest.getAttribute(QUERY_ATTRIBUTE);
if (query != null) {
final ObjectMapper objectMapper = (ObjectMapper) clientRequest.getAttribute(OBJECTMAPPER_ATTRIBUTE);
try {
proxyRequest.content(new BytesContentProvider(objectMapper.writeValueAsBytes(query)));
} catch (JsonProcessingException e) {
Throwables.propagate(e);
}
}
super.sendProxyRequest(clientRequest, proxyResponse, proxyRequest);
}
Aggregations