Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hopeslayer1 opened this issue Nov 17, 2023 · 30 comments

Comments

@hopeslayer1
Copy link

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
Copy link
Collaborator

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
Copy link
Author

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
Copy link
Author

Screenshot 2023-11-21 161312

@stefanhahmann
Copy link
Collaborator

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

@stefanhahmann
Copy link
Collaborator

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

@stefanhahmann
Copy link
Collaborator

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
Copy link
Author

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
Copy link
Collaborator

I just made another commit: 80ec067
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
Copy link
Author

hopeslayer1 commented Nov 28, 2023

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
Copy link
Collaborator

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
Copy link
Author

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
Copy link
Collaborator

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
Copy link
Author

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

@hopeslayer1
Copy link
Author

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
Copy link
Collaborator

stefanhahmann commented Nov 29, 2023

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
Copy link
Collaborator

stefanhahmann commented Nov 29, 2023

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
Copy link
Author

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
Copy link
Author

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

@hopeslayer1
Copy link
Author

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

@stefanhahmann
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Author

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
Copy link
Collaborator

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
Copy link
Author

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

@stefanhahmann
Copy link
Collaborator

stefanhahmann commented Dec 4, 2023

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
Copy link
Author

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

@stefanhahmann
Copy link
Collaborator

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
Copy link
Author

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
Copy link
Collaborator

stefanhahmann commented Dec 4, 2023

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants