FraunhoferIVI / openlr

This repository contains an implementation to transfer traffic incident data requested from HERE Traffic API to an OpenStreetMap database. This allows to view HERE traffic data in GIS Viewer, such as QGIS.
GNU Lesser General Public License v2.1
18 stars 1 forks source link

java.lang.NullPointerException: Cannot invoke "java.net.URL.getPath()" because "url" is null #19

Open hopeslayer1 opened 10 months ago

hopeslayer1 commented 10 months ago

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.net.URL.getPath()" because "url" is null at HereApi.HereTrafficV7.getToken(HereTrafficV7.java:186) at HereApi.HereTrafficV7.update(HereTrafficV7.java:262) at Here2Osm.main(Here2Osm.java:23) Any idea on how i can fix this?

stefanhahmann commented 10 months ago

You likely, have not create the "credentials.properties" file. Cf.: https://github.com/FraunhoferIVI/openlr/blob/master/SETUP.md#HERE-Api-Key

It is recommended to go through the steps described in SETUP.md before trying to run the script.

hopeslayer1 commented 10 months ago

I followed all the steps, got the credentials.properties file and I keep getting that error everytime, i put the file in the folder called target, is that correct?

hopeslayer1 commented 10 months ago

Screenshot 2023-11-21 161312

stefanhahmann commented 10 months ago

This looks correct to me. Did you run java -jar target\here2osm.jar from folder C:\Program Files\PostgreSQL\OpenLr\openlr-master ?

stefanhahmann commented 10 months ago

Can you also try to run java -jar here2osm.jar from C:\Program Files\PostgreSQL\OpenLr\openlr-master\target

stefanhahmann commented 10 months ago

I added 3 commits:

Can you try to pull again and maven install again and the run java -jar here2osm.jar from the target subfolder.

hopeslayer1 commented 9 months ago

This fixed the issue, now I need to figure out how to make it work on my side. I think it's because I just enabled the freemium api. 6695 [main] INFO HereApi.ApiRequest - request-URL: https://data.traffic.hereapi.com/v7/flow?locationReferencing=olr&in=bbox:33.835,47.254,33.197,47.262 7182 [main] ERROR HereApi.ApiRequest - GET Request failed 7183 [main] INFO HereApi.ApiRequest - request-URL: https://data.traffic.hereapi.com/v7/incidents?locationReferencing=olr&in=bbox:33.835,47.254,33.197,47.262 7480 [main] ERROR HereApi.ApiRequest - GET Request failed 7594 [main] INFO org.jooq.Constants -

stefanhahmann commented 9 months ago

I just made another commit: https://github.com/FraunhoferIVI/openlr/commit/80ec0679a0af7ff28a601a948a1f044a57054c07 This should lead to more verbose/specific logging in case of failing GET-Requests.

Can you pull again, maven install again and then run java -jar here2osm.jar again?

hopeslayer1 commented 9 months ago

Error.txt This is what I get now, the new commit fixed the other issues, also I recommend adding that you should not tick "Allow access only in this project" on the Here platform, that gave another error after retrying today.

stefanhahmann commented 9 months ago

Error.txt This is what I get now, the new commit fixed the other issues, also I recommend adding that you should not tick "Allow access only in this project" on the Here platform, that gave another error after retrying today.

I think the reason for this error is the bounding box that you specify.

If I try to run curl -H "Authorization: Bearer YOUR_TOKEN" "https://data.traffic.hereapi.com/v7/flow?locationReferencing=olr&in=bbox:13.400,52.500,13.405,52.505", I am getting a proper reply from the HERE servers:

grafik

but when I try to run curl -H "Authorization: Bearer YOUR_TOKEN" "https://data.traffic.hereapi.com/v7/flow?locationReferencing=olr&in=bbox:27.281,47.061,27.411,47.131"

I get this: grafik

Thus, I would recommend to use a different bounding box. The order of the bounding box is expected to be: long_min, lat_min, long_max, lat_max

hopeslayer1 commented 9 months ago

I tried with a different bounding box, i checked again to be sure that the order is correct and everything is ok on this side but i keep getting this error: Exception in thread "main" java.lang.UnsupportedOperationException: JsonNull at com.google.gson.JsonElement.getAsString(JsonElement.java:179) at HereApi.FlowJsonParser.parse(FlowJsonParser.java:85) at HereApi.HereTrafficV7.update(HereTrafficV7.java:323) at Here2Osm.main(Here2Osm.java:23)

stefanhahmann commented 9 months ago

Can you try to run curl -H "Authorization: Bearer YOUR_TOKEN" "https://data.traffic.hereapi.com/v7/flow?locationReferencing=olr&in=bbox:long_min,lat_min,long_max,lat_max" from the command line and check the result? I am assuming the reason of the error not in the code, but in the result delivered by the here api to it.

hopeslayer1 commented 9 months ago

do i run it in the target folder or it doesn't matter?

hopeslayer1 commented 9 months ago

C:\Program Files\PostgreSQL\openlr-master\target>curl -H "Authorization: Bearer YOUR_TOKEN" "https://data.traffic.hereapi.com/v7/flow?locationReferencing=olr&in=bbox:27.280,47.060,27.285,47.065" curl: (35) schannel: next InitializeSecurityContext failed: Unknown error (0x80092012) - The revocation function was unable to check revocation for the certificate.

stefanhahmann commented 9 months ago

You need to replace YOUR_TOKEN with your token. You can find the token in the log files after a log statement called "token: ". I tried again with the token that I found in the error.txt that you send, but the token seems to be outdated:

grafik

The curl statement you can run from everywhere.

stefanhahmann commented 9 months ago

Btw: the coordinates you specify relate to a rather rural region in eastern romania, where HERE might not have any traffic flow data that they can provide. Is this really the region you are interested?

hopeslayer1 commented 9 months ago

It worked, the coordinates were ok, i reverted to the initial ones, i created a new token and i disabled the antivirus and it worked, the issue was caused because the antivirus was blocking the connection for some reason. Thank you for the help, now I can use it in Qgis!

hopeslayer1 commented 9 months ago

I got the result, how can i add the information into the database?

hopeslayer1 commented 9 months ago

since with java -jar here2osm.jar its still not working even though with curl it works just fine

stefanhahmann commented 9 months ago

since with java -jar here2osm.jar its still not working even though with curl it works just fine

Can you specify more detailed what is not working? Which error message do you get when running java -jar here2osm.jar and which result do you get when running via curl?

stefanhahmann commented 9 months ago

It worked, the coordinates were ok, i reverted to the initial ones, i created a new token and i disabled the antivirus and it worked, the issue was caused because the antivirus was blocking the connection for some reason. Thank you for the help, now I can use it in Qgis!

Great to here this. I was not aware that an Antivirus protection could be a problem.

hopeslayer1 commented 9 months ago

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.length()" because "s" is null at java.base/java.io.StringReader.(StringReader.java:50) at HereApi.FlowJsonParser.parse(FlowJsonParser.java:83) at HereApi.HereTrafficV7.update(HereTrafficV7.java:323) at Here2Osm.main(Here2Osm.java:23) I get this from java curl.txt and this from curl

stefanhahmann commented 9 months ago

The result from the direct curl call seems to be good. For the java part, it would be interesting to have the full log file as well. There must have been an error before the error that you posted.

Are you using the same token for curl and for java?

hopeslayer1 commented 9 months ago

java error.txt for java i just ran the command from setup: java -jar here2osm.jar

stefanhahmann commented 9 months ago

As you can see in the error.txt:

9289 [main] ERROR HereApi.ApiRequest - GET Request failed. Status code: 403 9291 [main] ERROR HereApi.ApiRequest - Response from server: {"error":"Forbidden","error_description":"These credentials do not authorize access"}

Your credentials do not allow access to the server.

You need to make sure that you use the same token that works for the curl request also for the java request. The credentials.properties may need to be updated for this. Perhaps you may even need another token from HERE. You can test, if the token works with using curl.

hopeslayer1 commented 9 months ago

java_new.txt curl_new.txt Got new credentials, I guess it worked but the layer is empty when importing in Qgis

stefanhahmann commented 9 months ago

java_new.txt curl_new.txt Got new credentials, I guess it worked but the layer is empty when importing in Qgis

At least the Java code now is trying to process a proper response from the HERE API.

Now the program says: Could not decode olr code: CCkBEAAlJBOcPyGJdQAJBQQEA5IACgUEBIETAP+h/40ACQUEBAMVADAAAA== This means it cannot map the OpenLR code given from HERE to the data in your database. It is difficult to say, why this happens, without looking at your database. Can you make sure that your database covers the same region that you are querying in the request? If this is the case and it still does not work, I would recommend to try the Hamburg example that is described in the setup procedure and see, if you get this to work, since we know for sure that for this region, it has been working in the past.

hopeslayer1 commented 9 months ago

My database is the entire Romania file and I didn't use a clipping box, I used the entire file, maybe that could be an issue?

stefanhahmann commented 9 months ago

My database is the entire Romania file and I didn't use a clipping box, I used the entire file, maybe that could be an issue?

Not clipping should not be an issue. However, so far, we only tested with smaller regions, e.g. city of Hamburg (Germany). It would be interesting to know, if the Hamburg example works for you.

hopeslayer1 commented 9 months ago

I'll try the exemple today or later tomorrow and I'll come back with a reply