OneBusAway / onebusaway-application-modules

The core OneBusAway application suite.
https://github.com/OneBusAway/onebusaway-application-modules/wiki
Other
207 stars 133 forks source link

Can't retrieve arrivals for stopIds containing forward slash "/" #182

Open barbeau opened 8 years ago

barbeau commented 8 years ago

In the Boston OBA server, we hit the following stopId: 1_Forge Park / 495

It can be seen in the list of stops returned in this stops-for-location query: http://developer.onebusaway.org/mbta-api/api/where/stops-for-location.json?lat=42.078482127189595&lon=-71.43382396548986&latSpan=0.08702002322407765&lonSpan=0.07993753999471664&version=2&key=TEST

When using this stopId in a REST API request URL, I believe forward slashes should be escaped as %2F?

But getting arrivals using the escaped slash gives a 404: http://developer.onebusaway.org/mbta-api/api/where/arrivals-and-departures-for-stop/1_Forge%20Park%20%2F%20495.json&key=TEST

@sheldonabrown Do you know if OBA server requests are expected to work with / in the stopId? Not sure how the entire OBA stack would react to this, or if it should be preprocessed out of the data.

We’re trying to figure out how to handle client-side.

sheldonabrown commented 8 years ago

I did quite a bit of research into this, and there is nothing that precludes the AgencyAndId from containing a slash. Upon introspection, the value is happily stored as "1_Forge Park / 495" in the transit graph. However, it appears the Struts stack is trying to url decode parameters on our behalf and getting it wrong. The Struts convention plugin is making the assumption '/' will not be embedded in strings and not passing the '/' through as part of the parameter. As such, there is no way to properly request that value.

Initial research is inconclusive if struts can be configured to support this. I see references to '/' characters in action names but not in the parameters themselves.

It looks like forward slash works with the SIRI API however.

So yes, this seems like a bug in the struts configuration of the api webapp, if not struts itself.

barbeau commented 8 years ago

@sheldonabrown Thanks for looking into this! So to summarize, for us to support this properly client-side, we should assume that the proper way to handle this is to encode / to %2F, and submit this in the API request, such as: http://developer.onebusaway.org/mbta-api/api/where/arrivals-and-departures-for-stop/1_Forge%20Park%20%2F%20495.json&key=TEST

Is that correct?

And a server-side fix would come later.

sheldonabrown commented 7 years ago

To be honest, I'm not sure. As '/' is not illegal, its more to do with how I can convince struts to pass along the character. I would suspect that no url encoding is necessary in this case, especially since it works as is for the SIRI API.

barbeau commented 7 years ago

What's the corresponding SIRI API request for this?

sheldonabrown commented 7 years ago

I was testing against an updated version of SIRI -- the one currently deployed for Boston is quite old now. The updated version worked with:

/api/siri/stop-monitoring.json?key=&OperatorRef=1&MonitoringRef=Forge Park / 495

Though the currently deployed version does not.

barbeau commented 7 years ago

Ok, thanks! That was confusing me, as I couldn't get it to work on currently deployed version.

sharadagarwal commented 7 years ago

FYI, I'm having a similar problem with route Ids. For example, in Atlanta there is a route with Id "GRTA_431 - BrandsMart/Stockbridge to Midtown". This API call does not work: http://atlanta.onebusaway.org:80/api/api/where/stops-for-route/GRTA_431%20-%20BrandsMart%2FStockbridge%20to%20Midtown.xml?key=TEST&Version=2

barbeau commented 7 years ago

@sheldonabrown would you be against preprocessing out forward slashes in all agencyAndId fields during bundle building?

We do caching of stops on Android and this is proving to be a headache to work around. I'd personally prefer to just not deal with them at all.

sheldonabrown commented 7 years ago

Yes, personally I like this option much better. Otherwise figuring out the proper struts config might take far too long.