use of com.google.api.server.spi.response.InternalServerErrorException in project endpoints-java by cloudendpoints.
the class CachingDiscoveryProviderTest method getRestDocument_internalServerError.
@Test
public void getRestDocument_internalServerError() throws Exception {
CachingDiscoveryProvider provider = createNonExpiringProvider();
when(delegate.getRestDocument(ROOT, NAME, VERSION)).thenThrow(new InternalServerErrorException(""));
try {
provider.getRestDocument(ROOT, NAME, VERSION);
fail("expected InternalServerErrorException");
} catch (InternalServerErrorException e) {
// expected
}
}
use of com.google.api.server.spi.response.InternalServerErrorException in project endpoints-java by cloudendpoints.
the class SystemService method invokeServiceMethod.
/**
* Invokes a {@code method} on a {@code service} given a {@code paramReader} to read parameters
* and a {@code resultWriter} to write result.
*/
public void invokeServiceMethod(Object service, Method method, ParamReader paramReader, ResultWriter resultWriter) throws IOException {
try {
Object[] params = paramReader.read();
logger.log(Level.FINE, "params={0} (String)", Arrays.toString(params));
Object response = method.invoke(service, params);
resultWriter.write(response);
} catch (IllegalArgumentException | IllegalAccessException e) {
logger.log(Level.SEVERE, "exception occurred while calling backend method", e);
resultWriter.writeError(new BadRequestException(e));
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
Level level = Level.INFO;
if (cause instanceof ServiceException) {
resultWriter.writeError((ServiceException) cause);
} else if (cause instanceof IllegalArgumentException) {
resultWriter.writeError(isIllegalArgumentBackendError ? new InternalServerErrorException(cause) : new BadRequestException(cause));
} else if (isOAuthRequestException(cause.getClass())) {
resultWriter.writeError(new UnauthorizedException(cause));
} else if (cause.getCause() != null && cause.getCause() instanceof ServiceException) {
ServiceException serviceException = (ServiceException) cause.getCause();
level = serviceException.getLogLevel();
resultWriter.writeError(serviceException);
} else {
level = Level.SEVERE;
resultWriter.writeError(new InternalServerErrorException(cause));
}
logger.log(level, "exception occurred while calling backend method", cause);
} catch (ServiceException e) {
logger.log(e.getLogLevel(), "exception occurred while calling backend method", e);
resultWriter.writeError(e);
}
}
use of com.google.api.server.spi.response.InternalServerErrorException in project endpoints-java by cloudendpoints.
the class ProxyingDiscoveryServiceTest method getRpcDocument_internalServerError.
@Test
public void getRpcDocument_internalServerError() throws Exception {
ProxyingDiscoveryService discoveryService = createDiscoveryService(true);
when(provider.getRpcDocument(SERVER_ROOT, API_NAME, API_VERSION)).thenThrow(new InternalServerErrorException(""));
try {
discoveryService.getRpcDocument(createRequest("discovery/v1/apis/tictactoe/v1/rest"), API_NAME, API_VERSION);
fail("expected InternalServerErrorException");
} catch (InternalServerErrorException e) {
// expected
}
}
use of com.google.api.server.spi.response.InternalServerErrorException in project endpoints-java by cloudendpoints.
the class ProxyingDiscoveryProviderTest method getRestDocument_internalServerError.
@Test
public void getRestDocument_internalServerError() throws Exception {
when(restRequest.execute()).thenThrow(new IOException());
try {
provider.getRestDocument(REWRITTEN_ROOT, NAME, V1);
fail("expected InternalServerErrorException");
} catch (InternalServerErrorException e) {
// expected
}
}
use of com.google.api.server.spi.response.InternalServerErrorException in project endpoints-java by cloudendpoints.
the class ProxyingDiscoveryProviderTest method getDirectory_internalServerError.
@Test
public void getDirectory_internalServerError() throws Exception {
when(directoryRequest.execute()).thenThrow(new IOException());
try {
provider.getDirectory(REWRITTEN_ROOT);
fail("expected InternalServerErrorException");
} catch (InternalServerErrorException e) {
// expected
}
}
Aggregations