Wikidata-Toolkit: NoSuchMethodError when following FetchOnlineDataExample
I am using exactly the code from FetchOnlineDataExample.java
(from here) and nothing else:
public static void main(String[] args) {
WikibaseDataFetcher wbdf = new WikibaseDataFetcher(
BasicApiConnection.getWikidataApiConnection(),
Datamodel.SITE_WIKIDATA);
try {
EntityDocument q42 = wbdf.getEntityDocument("Q42");
System.out.println(q42);
} catch (MediaWikiApiErrorException | IOException e) {
e.printStackTrace();
}
}
And get this error:
Exception in thread "main" java.lang.NoSuchMethodError: 'okhttp3.RequestBody okhttp3.RequestBody.create(java.lang.String, okhttp3.MediaType)'
at org.wikidata.wdtk.wikibaseapi.ApiConnection.sendRequest(ApiConnection.java:396)
at org.wikidata.wdtk.wikibaseapi.ApiConnection.sendJsonRequest(ApiConnection.java:364)
at org.wikidata.wdtk.wikibaseapi.WbGetEntitiesAction.wbGetEntities(WbGetEntitiesAction.java:202)
at org.wikidata.wdtk.wikibaseapi.WbGetEntitiesAction.wbGetEntities(WbGetEntitiesAction.java:108)
at org.wikidata.wdtk.wikibaseapi.WikibaseDataFetcher.getEntityDocumentMap(WikibaseDataFetcher.java:404)
at org.wikidata.wdtk.wikibaseapi.WikibaseDataFetcher.getEntityDocuments(WikibaseDataFetcher.java:187)
at org.wikidata.wdtk.wikibaseapi.WikibaseDataFetcher.getEntityDocuments(WikibaseDataFetcher.java:156)
at org.wikidata.wdtk.wikibaseapi.WikibaseDataFetcher.getEntityDocument(WikibaseDataFetcher.java:138)
I have this in my pom.xml
:
<!-- https://mvnrepository.com/artifact/org.wikidata.wdtk/wdtk-wikibaseapi -->
<dependency>
<groupId>org.wikidata.wdtk</groupId>
<artifactId>wdtk-wikibaseapi</artifactId>
<version>0.12.1</version>
</dependency>
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 41 (14 by maintainers)
Commits related to this issue
- Swap arguments in RequestBody.create method. Closes #600. — committed to Wikidata/Wikidata-Toolkit by wetneb 2 years ago
- Revert "Upgraded to JUnit5 (#536)" Upgrading to JUnit5 requires upgrading OkHTTP to a newer version, but our okhttp-signpost dependency still relies on an earlier version. This closes #600. This re... — committed to Wikidata/Wikidata-Toolkit by wetneb 2 years ago
- Revert "Upgraded to JUnit5 (#536)" Upgrading to JUnit5 requires upgrading OkHTTP to a newer version, but our okhttp-signpost dependency still relies on an earlier version. This closes #600. This re... — committed to Wikidata/Wikidata-Toolkit by wetneb 2 years ago
- Revert "Upgraded to JUnit5 (#536)" (#694) Upgrading to JUnit5 requires upgrading OkHTTP to a newer version, but our okhttp-signpost dependency still relies on an earlier version. This closes #600... — committed to Wikidata/Wikidata-Toolkit by wetneb 2 years ago
- Add explicit dependency to okhttp, for #600 — committed to Wikidata/Wikidata-Toolkit by wetneb 2 years ago
- Add explicit dependency to okhttp, for #600 (#705) — committed to Wikidata/Wikidata-Toolkit by wetneb 2 years ago
@wetneb Aren’t we missing okhttp 4.x dependency in wikibaseapi module? It could spare downstream projects of the need to declare the dependency in their own POM.
Also adding com.squareup.okhttp3:okhttp:4.2.2 seems to work! I hadn’t tried to add both okhttp-urlconnection and okhttp next to wdtk-wikibaseapi. Thanks!
@Lhaaits I will have to test this on my own app
@wetneb Mockwebserver alternative is a lot of work. Merging #694 makes it harder, because junit5 upgrade would have to be reapplied after it. I had to give my attention to two other opensource projects, so I am only getting around to this now.
My solution for now is to have a
public class FixedBasicApiConnection extends BasicApiConnection
that overridessendRequest()
and passes the parameters in swapped order toRequestBody.create()
, then it works. If this is actually a general bug and not something local for me, I’d be happy to make a PR that swaps the parameters inApiConnection
.The pom.xml file in this repository is for the development version of WDTK, it is normal that versions of WDTK released in the past use other versions of this dependency. So the issue probably comes from somewhere else…