use of com.palantir.conjure.java.api.errors.RemoteException in project dialogue by palantir.
the class MyServiceIntegrationTest method testGetGreetingAsyncRemoteException.
@Test
public void testGetGreetingAsyncRemoteException() {
String errorBody = "{\"errorCode\":\"FAILED_PRECONDITION\",\"errorName\":\"Default:FailedPrecondition\"," + "\"errorInstanceId\":\"839ccac1-3944-479a-bcd2-3196b5fa16ee\",\"parameters\":{\"key\":\"value\"}}";
undertowHandler = exchange -> {
exchange.assertMethod(HttpMethod.GET);
exchange.assertPath("/greeting");
exchange.assertAccept().isEqualTo("text/csv");
exchange.assertContentType().isNull();
exchange.assertNoBody();
exchange.exchange.setStatusCode(500);
exchange.setContentType("application/json");
exchange.writeStringBody(errorBody);
};
assertThatThrownBy(() -> myServiceDialogue.getGreetingAsync().get()).isExactlyInstanceOf(ExecutionException.class).hasCauseExactlyInstanceOf(RemoteException.class).satisfies(executionException -> {
RemoteException remoteException = (RemoteException) executionException.getCause();
assertThat(remoteException.getError()).isEqualTo(SerializableError.builder().errorCode("FAILED_PRECONDITION").errorName("Default:FailedPrecondition").errorInstanceId("839ccac1-3944-479a-bcd2-3196b5fa16ee").putParameters("key", "value").build());
});
}
use of com.palantir.conjure.java.api.errors.RemoteException in project dialogue by palantir.
the class SingleParamServicesTest method runTestCase.
@Test
public void runTestCase() throws Exception {
Assume.assumeFalse(Cases.shouldIgnore(endpointName, jsonString));
log.info("Invoking {} {}({})", SafeArg.of("serviceName", serviceName), SafeArg.of("endpointName", endpointName), SafeArg.of("jsonString", jsonString));
Object service = servicesMaps.get(serviceName);
for (Method method : servicesMaps.get(serviceName).getClass().getMethods()) {
String name = method.getName();
// Need to set accessible true work around dialogues anonymous class impl
method.setAccessible(true);
if (method.getParameterCount() == 1) {
// conjure-java generates `default` methods for optional query params, we don't want to call these
continue;
}
if (endpointName.get().equals(name)) {
try {
// HACKHACK, index parameter order is different for different services.
if ("singleHeaderService".equals(serviceName)) {
Type type = getRawType(method.getGenericParameterTypes()[0]);
Class<?> cls = ClassUtils.getClass(type.getTypeName());
method.invoke(service, objectMapper.readValue(jsonString, cls), index);
} else {
Type type = getRawType(method.getGenericParameterTypes()[1]);
Class<?> cls = ClassUtils.getClass(type.getTypeName());
method.invoke(service, index, objectMapper.readValue(jsonString, cls));
}
log.info("Successfully post param to endpoint {} and index {}", SafeArg.of("endpointName", endpointName), SafeArg.of("index", index));
} catch (RemoteException e) {
log.error("Caught exception with params: {}", SafeArg.of("errorParameters", e.getError().parameters()), e);
throw e;
}
}
}
}
use of com.palantir.conjure.java.api.errors.RemoteException in project dialogue by palantir.
the class DefaultClientsBlockingTest method testRemoteException.
@Test
public void testRemoteException() {
RemoteException remoteException = remoteException(new ServiceException(ErrorType.INVALID_ARGUMENT));
ListenableFuture<Object> failedFuture = Futures.immediateFailedFuture(remoteException);
assertThatThrownBy(() -> DefaultClients.INSTANCE.block(failedFuture)).isInstanceOf(RemoteException.class).hasFieldOrPropertyWithValue("status", ErrorType.INVALID_ARGUMENT.httpErrorCode());
}
use of com.palantir.conjure.java.api.errors.RemoteException in project dialogue by palantir.
the class ErrorDecoderTest method testSpecificException.
@Test
public void testSpecificException() {
RemoteException exception = encodeAndDecode(new IllegalArgumentException("msg"));
assertThat(exception).isInstanceOf(RemoteException.class);
assertThat(exception.getMessage()).startsWith("RemoteException: java.lang.IllegalArgumentException (msg)");
}
use of com.palantir.conjure.java.api.errors.RemoteException in project conjure-java-runtime by palantir.
the class SingleParamServicesTest method runTestCase.
private void runTestCase(ImmutableMap<String, Object> servicesMaps) throws Exception {
Assume.assumeFalse(Cases.shouldIgnoreJersey(endpointName, jsonString));
log.info("Invoking {} {}({})", serviceName, endpointName, jsonString);
Object service = servicesMaps.get(serviceName);
for (Method method : servicesMaps.get(serviceName).getClass().getMethods()) {
String name = method.getName();
if (method.getParameterCount() == 1) {
// conjure-java generates `default` methods for optional query params, we don't want to call these
continue;
}
if (endpointName.get().equals(name)) {
try {
// HACKHACK, index parameter order is different for different services.
if ("singleHeaderService".equals(serviceName)) {
Type type = method.getGenericParameterTypes()[0];
Class<?> cls = ClassUtils.getClass(type.getTypeName());
method.invoke(service, jsonMapper.readValue(jsonString, cls), index);
} else {
Type type = method.getGenericParameterTypes()[1];
Class<?> cls = ClassUtils.getClass(type.getTypeName());
method.invoke(service, index, jsonMapper.readValue(jsonString, cls));
}
log.info("Successfully post param to endpoint {} and index {}", endpointName, index);
} catch (RemoteException e) {
log.error("Caught exception with params: {}", e.getError().parameters(), e);
throw e;
}
}
}
}
Aggregations