Example usage for javax.naming ServiceUnavailableException ServiceUnavailableException

List of usage examples for javax.naming ServiceUnavailableException ServiceUnavailableException

Introduction

In this page you can find the example usage for javax.naming ServiceUnavailableException ServiceUnavailableException.

Prototype

public ServiceUnavailableException() 

Source Link

Document

Constructs a new instance of ServiceUnavailableException.

Usage

From source file:com.tomtom.speedtools.services.lbs.geocode.implementation.TomTomLbsGeoCodeEngine.java

/**
 * Perform actual LBS HTTP query.//from   w  w  w .j a  va 2  s . c  o m
 *
 * @param queryUrl URL to query.
 * @return Valid GeoCoderResponse object.
 * @throws AuthorizationException      Thrown in case API key is rejected by server
 * @throws ServiceUnavailableException Thrown if service is not available.
 * @throws IOException                 Thrown if GET could not be executed for some reason.
 */
@SuppressWarnings("OverlyBroadThrowsClause")
@Nonnull
private static GeoCodeEngineResponse executeLbsQuery(@Nonnull final String queryUrl)
        throws AuthorizationException, ServiceUnavailableException, IOException {
    assert queryUrl != null;
    LOG.debug("executeLbsQuery: url={}", queryUrl);
    final GetMethod get = new GetMethod(queryUrl);
    final int status = new HttpClient().executeMethod(get);

    // Log error message.
    if (status != HttpStatus.SC_OK) {
        LOG.warn("executeLbsQuery: geocoding service failure, url={}, status={} ", queryUrl,
                get.getStatusLine());
    }
    final GeoCodeEngineResponse response;
    switch (status) {

    case HttpStatus.SC_OK:
        try {
            response = unmarshalGeoCoderResponseBody(get.getResponseBodyAsStream());
        } catch (final JAXBException e) {
            LOG.warn("executeLbsQuery: cannot unmarshal response", e);
            throw new IOException("Cannot unmarshal response", e);
        } finally {
            get.releaseConnection();
        }
        assert response != null;
        break;

    case HttpStatus.SC_NO_CONTENT:
        response = new GeoCodeEngineResponse();
        break;

    case HttpStatus.SC_UNAUTHORIZED:
        // Fall through.
    case HttpStatus.SC_METHOD_NOT_ALLOWED:
        // Fall through.
    case HttpStatus.SC_NOT_ACCEPTABLE:
        // Fall through.
    case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
        throw new AuthorizationException();

    case HttpStatus.SC_INTERNAL_SERVER_ERROR:
        // Fall through.
    case HttpStatus.SC_SERVICE_UNAVAILABLE:
        // Fall through.
    case HttpStatus.SC_GATEWAY_TIMEOUT:
        // Fall through.
    case HttpStatus.SC_INSUFFICIENT_STORAGE:
        throw new ServiceUnavailableException();

    default:
        throw new IOException("Cannot call geocoder, status=" + status + " (" + get.getStatusLine() + ')');
    }
    assert response != null;
    return response;
}

From source file:com.tomtom.speedtools.services.lbs.route.implementation.TomTomLbsRouteEngineRouteEngineActorImpl.java

/**
 * Perform actual LBS HTTP query.//from   w  w  w  .j  ava  2  s  .c o  m
 *
 * @param queryUrl URL to query.
 * @return Valid route engine response object.
 * @throws AuthorizationException      Thrown in case API key is rejected by server
 * @throws ServiceUnavailableException Thrown if service is not available.
 * @throws IOException                 Thrown if GET could not be executed for some reason.
 */
@SuppressWarnings("OverlyBroadThrowsClause")
@Nonnull
private static TomTomLbsRouteEngineResponse executeLbsQuery(@Nonnull final String queryUrl)
        throws AuthorizationException, ServiceUnavailableException, IOException {
    assert queryUrl != null;
    LOG.trace("executeLbsQuery: url={}", queryUrl);
    final GetMethod get = new GetMethod(queryUrl);
    final int status = new HttpClient().executeMethod(get);

    // Log error message.
    if (status != HttpStatus.SC_OK) {
        LOG.info("executeLbsQuery: routing service failure, url={}, status={} ", queryUrl, get.getStatusLine());
    }
    final TomTomLbsRouteEngineResponse response;
    switch (status) {

    case HttpStatus.SC_OK:
        try {
            response = unmarshalRouterResponseBody(get.getResponseBodyAsStream());
        } catch (final JAXBException e) {
            LOG.warn("executeLbsQuery: cannot unmarshal response", e);
            throw new IOException("Cannot unmarshal response", e);
        } finally {
            get.releaseConnection();
        }
        assert response != null;
        break;

    case HttpStatus.SC_UNAUTHORIZED:
        // Fall through.
    case HttpStatus.SC_METHOD_NOT_ALLOWED:
        // Fall through.
    case HttpStatus.SC_NOT_ACCEPTABLE:
        // Fall through.
    case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED:
        throw new AuthorizationException();

    case HttpStatus.SC_NO_CONTENT:
        // Fall through.
    case HttpStatus.SC_INTERNAL_SERVER_ERROR:
        // Fall through.
    case HttpStatus.SC_SERVICE_UNAVAILABLE:
        // Fall through.
    case HttpStatus.SC_GATEWAY_TIMEOUT:
        // Fall through.
    case HttpStatus.SC_INSUFFICIENT_STORAGE:
        throw new ServiceUnavailableException();

    default:
        throw new IOException("Cannot call route engine, status=" + status + " (" + get.getStatusLine() + ')');
    }
    assert response != null;
    return response;
}