crotwell / seisFile

A library for reading and writing seismic file formats in java.
GNU Lesser General Public License v3.0
27 stars 20 forks source link

Error readin QuakeML list #29

Closed andreabono closed 1 year ago

andreabono commented 1 year ago

I've a issue running the following code:

public EventIterator read_quakeml_list(String host, String time_start, String time_end, 
            float min_magnitude,
            float max_depth){
        try {
            FDSNEventQueryParams queryParams = new FDSNEventQueryParams();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            sdf.setTimeZone(TimeZone.getTimeZone("UTC"));

            queryParams.setHost(host); 
            queryParams.setStartTime(sdf.parse(time_start).toInstant());
            queryParams.setEndTime(sdf.parse(time_end).toInstant());
            queryParams.setMaxDepth(max_depth);
            queryParams.setMinMagnitude(min_magnitude);
            queryParams.setOrderBy(FDSNEventQueryParams.ORDER_TIME_ASC);

            FDSNEventQuerier querier = new FDSNEventQuerier(queryParams);
            Quakeml quakeml = querier.getQuakeML();   //  <<<<<<<<        ERROR HERE
            //
            if (!quakeml.checkSchemaVersion()) {
                log_locally_for_bad_format(quakeml);
            }
            //          
            return quakeml.getEventParameters().getEvents();
            //
        } catch (Exception ex) {

            ex.printStackTrace();
            return null;
        }
    }  

The ERROR HERE line raises an edu.sc.seis.seisFile.fdsnws.FDSNWSException: Code: 406 Not Acceptable when running on the following parameters:
http://ws.resif.fr:80/fdsnws/event/1/query?endtime=2023-05-02T23:59:59.000Z&maxdepth=1000.0&minmagnitude=-2.0&orderby=time-asc&starttime=2023-05-02T00:00:00.000Z

Here follows the stack trace:

edu.sc.seis.seisFile.fdsnws.FDSNWSException: Code: 406 Not Acceptable
 uri: http://ws.resif.fr:80/fdsnws/event/1/query?endtime=2023-05-02T23:59:59.000Z&maxdepth=1000.0&minmagnitude=-2.0&orderby=time-asc&starttime=2023-05-02T00:00:00.000Z ret code406
    at edu.sc.seis.seisFile.fdsnws.AbstractFDSNQuerier.processConnection(AbstractFDSNQuerier.java:94)
    at edu.sc.seis.seisFile.fdsnws.AbstractFDSNQuerier.connect(AbstractFDSNQuerier.java:74)
    at edu.sc.seis.seisFile.fdsnws.FDSNEventQuerier.getQuakeML(FDSNEventQuerier.java:33)
    at org.ingv.pfx.fdsn.FDSN_ws_reader.read_quakeml_list(FDSN_ws_reader.java:62)
    at org.ingv.pfx.MapFormController.Read_FDSN_events_list(MapFormController.java:1064)
    at org.ingv.pfx.MapFormController.SearchAndShowLocations_FDSN(MapFormController.java:952)
    at org.ingv.pfx.MapFormController$3.changed(MapFormController.java:453)
    at org.ingv.pfx.MapFormController$3.changed(MapFormController.java:448)
    at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:181)
    at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80)
    at javafx.beans.property.ReadOnlyIntegerPropertyBase.fireValueChangedEvent(ReadOnlyIntegerPropertyBase.java:78)
    at javafx.beans.property.ReadOnlyIntegerWrapper.fireValueChangedEvent(ReadOnlyIntegerWrapper.java:102)
    at javafx.beans.property.IntegerPropertyBase.markInvalid(IntegerPropertyBase.java:114)
    at javafx.beans.property.IntegerPropertyBase.set(IntegerPropertyBase.java:148)
    at javafx.scene.control.SelectionModel.setSelectedIndex(SelectionModel.java:69)
    at javafx.scene.control.TabPane$TabPaneSelectionModel.select(TabPane.java:648)
    at javafx.scene.control.TabPane$TabPaneSelectionModel.select(TabPane.java:670)
    at javafx.scene.control.TabPane$TabPaneSelectionModel.select(TabPane.java:589)
    at com.sun.javafx.scene.control.behavior.TabPaneBehavior.selectTab(TabPaneBehavior.java:82)
    at javafx.scene.control.skin.TabPaneSkin$TabHeaderSkin$5.handle(TabPaneSkin.java:1531)
    at javafx.scene.control.skin.TabPaneSkin$TabHeaderSkin$5.handle(TabPaneSkin.java:1509)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3894)
    at javafx.scene.Scene.processMouseEvent(Scene.java:1887)
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2620)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:411)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:301)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:450)
    at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:424)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:449)
    at com.sun.glass.ui.View.handleMouseEvent(View.java:551)
    at com.sun.glass.ui.View.notifyMouse(View.java:937)
    at com.sun.glass.ui.mac.MacView.notifyMouse(MacView.java:127)
crotwell commented 1 year ago

Underlying issue seems to be that ws.resif.fr does a 301 redirect to https://api.franceseisme.fr and the http client is failing to handle the https verification stuff correctly. Actually, I think ssl is disabled by default.

crotwell commented 1 year ago

Also another issue, maybe the real one, is that ws.resif.fr returns a 406 if the Accept header is "application/xml". I feel like this is a bug in their server, but a workaround would be to

FDSNEventQuerier querier = new FDSNEventQuerier(queryParams);
querier.setAcceptHeader("*/*");

You can see this with curl. This fails with a 406:

curl -v -L -H "Accept: application/xml" -o data.quakeml 'http://ws.resif.fr:80/fdsnws/event/1/query?endtime=2023-05-02T23:59:59.999Z&minmagnitude=-2.0&orderby=time-asc&starttime=2023-05-02T00:00:00.000Z'

but this succeeds:

curl -v -L -H "Accept: */*" -o data.quakeml 'http://ws.resif.fr:80/fdsnws/event/1/query?endtime=2023-05-02T23:59:59.999Z&minmagnitude=-2.0&orderby=time-asc&starttime=2023-05-02T00:00:00.000Z'

I will attempt to contact them to see if they will allow application/xml.

crotwell commented 1 year ago

Issue created with RESIF here: https://gitlab.com/resif/sismo-help/-/issues/127

Closing this as I believe either the workaround or RESIF fixing the server resolves this. Let me know if you are still having trouble.

andreabono commented 1 year ago

Great, I'll be waiting for the new release!!. Thanks a lot!!

crotwell commented 1 year ago

Resif has fixed their server to allow the Accept header.