Search in sources :

Example 6 with InternalServerErrorException

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
    }
}
Also used : InternalServerErrorException(com.google.api.server.spi.response.InternalServerErrorException) Test(org.junit.Test)

Example 7 with InternalServerErrorException

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);
    }
}
Also used : UnauthorizedException(com.google.api.server.spi.response.UnauthorizedException) BadRequestException(com.google.api.server.spi.response.BadRequestException) InternalServerErrorException(com.google.api.server.spi.response.InternalServerErrorException) Level(java.util.logging.Level) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 8 with InternalServerErrorException

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
    }
}
Also used : InternalServerErrorException(com.google.api.server.spi.response.InternalServerErrorException) Test(org.junit.Test)

Example 9 with InternalServerErrorException

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
    }
}
Also used : InternalServerErrorException(com.google.api.server.spi.response.InternalServerErrorException) IOException(java.io.IOException) Test(org.junit.Test)

Example 10 with InternalServerErrorException

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
    }
}
Also used : InternalServerErrorException(com.google.api.server.spi.response.InternalServerErrorException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

InternalServerErrorException (com.google.api.server.spi.response.InternalServerErrorException)12 Test (org.junit.Test)9 IOException (java.io.IOException)4 ApiConfigException (com.google.api.server.spi.config.ApiConfigException)1 ApiMethod (com.google.api.server.spi.config.ApiMethod)1 ApiKey (com.google.api.server.spi.config.model.ApiKey)1 BadRequestException (com.google.api.server.spi.response.BadRequestException)1 ForbiddenException (com.google.api.server.spi.response.ForbiddenException)1 UnauthorizedException (com.google.api.server.spi.response.UnauthorizedException)1 ApiConfigs (com.google.api.services.discovery.model.ApiConfigs)1 DatabaseReference (com.google.firebase.database.DatabaseReference)1 TaskCompletionSource (com.google.firebase.tasks.TaskCompletionSource)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Level (java.util.logging.Level)1