Search in sources :

Example 26 with WrappedException

use of com.revolsys.util.WrappedException in project com.revolsys.open by revolsys.

the class OgcWmsImageLayer method initializeDo.

@Override
protected boolean initializeDo() {
    final boolean initialized = super.initializeDo();
    if (initialized) {
        try {
            final WmsClient wmsClient;
            if (Property.hasValue(this.connectionName)) {
                final WebService<?> webService = WebServiceConnectionManager.getWebService(this.connectionName);
                if (webService == null) {
                    Logs.error(this, getPath() + ": Web service " + this.connectionName + ": no connection configured");
                    return false;
                } else if (webService instanceof WmsClient) {
                    wmsClient = (WmsClient) webService;
                } else {
                    Logs.error(this, getPath() + ": Web service " + this.connectionName + ": is not a OGS WMS service");
                    return false;
                }
            } else if (Property.hasValue(this.serviceUrl)) {
                wmsClient = new WmsClient(this.serviceUrl);
            } else {
                Logs.error(this, getPath() + ": A record store layer requires a connection entry with a name or url, username, and password ");
                return false;
            }
            final WmsLayerDefinition wmsLayerDefinition = wmsClient.getLayer(this.layerName);
            setWmsLayerDefinition(wmsLayerDefinition);
            return wmsLayerDefinition != null;
        } catch (final WrappedException e) {
            final Throwable cause = Exceptions.unwrap(e);
            if (cause instanceof UnknownHostException) {
                return setNotExists("Unknown host: " + cause.getMessage());
            } else {
                throw e;
            }
        }
    }
    return initialized;
}
Also used : WrappedException(com.revolsys.util.WrappedException) UnknownHostException(java.net.UnknownHostException) WmsLayerDefinition(com.revolsys.gis.wms.capabilities.WmsLayerDefinition) WmsClient(com.revolsys.gis.wms.WmsClient)

Example 27 with WrappedException

use of com.revolsys.util.WrappedException in project com.revolsys.open by revolsys.

the class ArcGisRestServerTileCacheLayer method initializeDo.

@Override
protected boolean initializeDo() {
    synchronized (this.initSync) {
        if (this.mapService == null) {
            try {
                if (Property.hasValue(this.connectionName)) {
                    final WebService<?> webService = WebServiceConnectionManager.getWebService(this.connectionName);
                    if (webService instanceof ArcGisRestCatalog) {
                        final ArcGisRestCatalog catalog = (ArcGisRestCatalog) webService;
                        final WebServiceResource service = catalog.getWebServiceResource(this.servicePath);
                        if (service instanceof MapService) {
                            this.mapService = (MapService) service;
                        } else {
                            Logs.error(this, getPath() + ": Web service " + this.connectionName + " is not a ArcGIS service");
                            return false;
                        }
                    } else {
                        Logs.error(this, getPath() + ": Web service " + this.connectionName + " " + this.servicePath + " is not a ArcGIS Map service");
                        return false;
                    }
                } else {
                    // TODO username/password
                    this.mapService = MapService.getMapService(this.url);
                }
                if (this.mapService == null) {
                    Logs.error(this, "Unable to connect to ArcGIS rest server");
                    return false;
                } else {
                    final TileInfo tileInfo = this.mapService.getTileInfo();
                    if (tileInfo == null) {
                        Logs.info(this, this.url + " does not contain a tileInfo definition.");
                        return false;
                    } else {
                        this.geometryFactory = tileInfo.getGeometryFactory();
                        final BoundingBox boundingBox = this.mapService.getFullExtent();
                        setBoundingBox(boundingBox);
                        return true;
                    }
                }
            } catch (final WrappedException e) {
                final Throwable cause = Exceptions.unwrap(e);
                if (cause instanceof UnknownHostException) {
                    // cause.getMessage());
                    return setNotExists("Unknown host: " + cause.getMessage());
                } else {
                    throw e;
                }
            }
        } else {
            return true;
        }
    }
}
Also used : ArcGisRestCatalog(com.revolsys.record.io.format.esri.rest.ArcGisRestCatalog) TileInfo(com.revolsys.record.io.format.esri.rest.map.TileInfo) WrappedException(com.revolsys.util.WrappedException) UnknownHostException(java.net.UnknownHostException) WebServiceResource(com.revolsys.webservice.WebServiceResource) BoundingBox(com.revolsys.geometry.model.BoundingBox) MapService(com.revolsys.record.io.format.esri.rest.map.MapService)

Example 28 with WrappedException

use of com.revolsys.util.WrappedException in project com.revolsys.open by revolsys.

the class Logs method getMessageAndException.

public static Throwable getMessageAndException(final StringBuilder messageText, final String message, final Throwable e) {
    Throwable logException = e;
    final Set<String> messages = Sets.newLinkedHash(message);
    if (Property.hasValue(message)) {
        messageText.append(message);
    }
    while (logException instanceof WrappedException || logException instanceof NestedRuntimeException) {
        if (messageText.length() > 0) {
            messageText.append('\n');
        }
        messageText.append(logException.getClass().getName());
        messageText.append(": ");
        final String wrappedMessage = logException.getMessage();
        if (messages.add(wrappedMessage)) {
            messageText.append(wrappedMessage);
        }
        final Throwable cause = logException.getCause();
        if (cause == null) {
            break;
        } else {
            logException = cause;
        }
    }
    if (logException instanceof SQLException) {
        final SQLException sqlException = (SQLException) logException;
        final List<Throwable> exceptions = Lists.toArray(sqlException);
        final int exceptionCount = exceptions.size();
        if (exceptionCount > 0) {
            logException = exceptions.remove(exceptionCount - 1);
            for (final Throwable throwable : exceptions) {
                if (messageText.length() > 0) {
                    messageText.append('\n');
                }
                if (throwable == sqlException) {
                    messageText.append(sqlException.getClass().getName());
                    messageText.append(": ");
                    final String wrappedMessage = sqlException.getMessage();
                    if (messages.add(wrappedMessage)) {
                        messageText.append(wrappedMessage);
                    }
                } else {
                    messageText.append(Exceptions.toString(throwable));
                }
            }
        }
    }
    return logException;
}
Also used : WrappedException(com.revolsys.util.WrappedException) NestedRuntimeException(org.springframework.core.NestedRuntimeException) SQLException(java.sql.SQLException)

Aggregations

WrappedException (com.revolsys.util.WrappedException)28 ChannelReader (com.revolsys.io.channels.ChannelReader)20 EOFException (java.io.EOFException)19 NoSuchResourceException (com.revolsys.spring.resource.NoSuchResourceException)14 ParameterValueString (com.revolsys.geometry.cs.ParameterValueString)12 ParameterName (com.revolsys.geometry.cs.ParameterName)7 Area (com.revolsys.geometry.cs.Area)4 Authority (com.revolsys.geometry.cs.Authority)4 ParameterValue (com.revolsys.geometry.cs.ParameterValue)4 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)4 IntHashMap (com.revolsys.collection.map.IntHashMap)3 BaseAuthority (com.revolsys.geometry.cs.BaseAuthority)3 CoordinateOperationMethod (com.revolsys.geometry.cs.CoordinateOperationMethod)3 Ellipsoid (com.revolsys.geometry.cs.Ellipsoid)3 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)3 PrimeMeridian (com.revolsys.geometry.cs.PrimeMeridian)3 GeodeticDatum (com.revolsys.geometry.cs.datum.GeodeticDatum)3 VerticalDatum (com.revolsys.geometry.cs.datum.VerticalDatum)3 AngularUnit (com.revolsys.geometry.cs.unit.AngularUnit)3 UnitOfMeasure (com.revolsys.geometry.cs.unit.UnitOfMeasure)3