You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Error reporting when calling RelationshipApi.createRelationship() using Java Client for Ory Keto(verison:0.11.0-alpha.0),detail info:
Exception in thread "main" java.lang.NoSuchMethodError: okhttp3.RequestBody.create(Ljava/lang/String;Lokhttp3/MediaType;)Lokhttp3/RequestBody;
at sh.ory.ApiClient.serialize(ApiClient.java:998)
at sh.ory.ApiClient.buildRequest(ApiClient.java:1251)
at sh.ory.ApiClient.buildCall(ApiClient.java:1203)
at sh.ory.api.RelationshipApi.createRelationshipCall(RelationshipApi.java:264)
at sh.ory.api.RelationshipApi.createRelationshipValidateBeforeCall(RelationshipApi.java:269)
at sh.ory.api.RelationshipApi.createRelationshipWithHttpInfo(RelationshipApi.java:307)
at sh.ory.api.RelationshipApi.createRelationship(RelationshipApi.java:288)
at com.tech.fate.portal.flow.KetoTest.createRelationship(KetoTest.java:105)
at com.tech.fate.portal.flow.KetoTest.main(KetoTest.java:46)
Secondly, I use the Java Client for Ory Keto(verison:0.11.0-alpha.0) to call the keto service according to the demo in the guides
1.init a springboot project
2.import Java Client for Ory Keto(verison:0.11.0-alpha.0) in the pom.xml
4.I found that the order of the incoming parameters is wrong when ApiClient#serialize calls RequestBody#create: the first parameter of RequestBody#create of okhttp3 is MediaType, but when ApiClient#serialize is called, the second parameter is passed in as MediaType:
ApiClient:
public RequestBody serialize(Object obj, String contentType) throws ApiException {
if (obj instanceof byte[]) {
// Binary (byte array) body parameter support.
return RequestBody.create((byte[]) obj, MediaType.parse(contentType));
} else if (obj instanceof File) {
// File body parameter support.
return RequestBody.create((File) obj, MediaType.parse(contentType));
} else if ("text/plain".equals(contentType) && obj instanceof String) {
return RequestBody.create((String) obj, MediaType.parse(contentType));
} else if (isJsonMime(contentType)) {
String content;
if (obj != null) {
content = JSON.serialize(obj);
} else {
content = null;
}
return RequestBody.create(content, MediaType.parse(contentType));
} else if (obj instanceof String) {
return RequestBody.create((String) obj, MediaType.parse(contentType));
} else {
throw new ApiException("Content type "" + contentType + "" is not supported");
}
}
Exception in thread "main" java.lang.NoSuchMethodError: okhttp3.RequestBody.create(Ljava/lang/String;Lokhttp3/MediaType;)Lokhttp3/RequestBody;
at sh.ory.ApiClient.serialize(ApiClient.java:998)
at sh.ory.ApiClient.buildRequest(ApiClient.java:1251)
at sh.ory.ApiClient.buildCall(ApiClient.java:1203)
at sh.ory.api.RelationshipApi.createRelationshipCall(RelationshipApi.java:264)
at sh.ory.api.RelationshipApi.createRelationshipValidateBeforeCall(RelationshipApi.java:269)
at sh.ory.api.RelationshipApi.createRelationshipWithHttpInfo(RelationshipApi.java:307)
at sh.ory.api.RelationshipApi.createRelationship(RelationshipApi.java:288)
at com.tech.fate.portal.flow.KetoTest.createRelationship(KetoTest.java:105)
at com.tech.fate.portal.flow.KetoTest.main(KetoTest.java:46)
Preflight checklist
Describe the bug
Error reporting when calling RelationshipApi.createRelationship() using Java Client for Ory Keto(verison:0.11.0-alpha.0),detail info:
Exception in thread "main" java.lang.NoSuchMethodError: okhttp3.RequestBody.create(Ljava/lang/String;Lokhttp3/MediaType;)Lokhttp3/RequestBody;
at sh.ory.ApiClient.serialize(ApiClient.java:998)
at sh.ory.ApiClient.buildRequest(ApiClient.java:1251)
at sh.ory.ApiClient.buildCall(ApiClient.java:1203)
at sh.ory.api.RelationshipApi.createRelationshipCall(RelationshipApi.java:264)
at sh.ory.api.RelationshipApi.createRelationshipValidateBeforeCall(RelationshipApi.java:269)
at sh.ory.api.RelationshipApi.createRelationshipWithHttpInfo(RelationshipApi.java:307)
at sh.ory.api.RelationshipApi.createRelationship(RelationshipApi.java:288)
at com.tech.fate.portal.flow.KetoTest.createRelationship(KetoTest.java:105)
at com.tech.fate.portal.flow.KetoTest.main(KetoTest.java:46)
Reproducing the bug
First, I started the keto service:
1.mkdir data & cd data
2.clone https://github.com/ory/keto.git
3.download https://raw.githubusercontent.com/ory/meta/master/install.sh
4.bash install.sh -d -b . keto v0.11.1-alpha.0
5.sudo mv ./keto /usr/local/bin/
6.keto serve -c /data/keto/contrib/docs-code-samples/expand-api-display-access/keto.yml
Secondly, I use the Java Client for Ory Keto(verison:0.11.0-alpha.0) to call the keto service according to the demo in the guides
1.init a springboot project
2.import Java Client for Ory Keto(verison:0.11.0-alpha.0) in the pom.xml
sh.ory.keto
keto-client
0.11.0-alpha.0
3.Create a junit test class as follows and test it according to the example(https://github.com/ory/client-java/blob/master/docs/RelationshipApi.md#createRelationship)
private static void createRelationship() {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://localhost:4467");
RelationshipApi apiInstance = new RelationshipApi(defaultClient);
CreateRelationshipBody createRelationshipBody = new CreateRelationshipBody(); // CreateRelationshipBody |
createRelationshipBody.setNamespace("messages");
createRelationshipBody.setObject("lyl_obj");
createRelationshipBody.setRelation("lyl_relation");
createRelationshipBody.setSubjectId("lyl_sub");
SubjectSet subjectSet = new SubjectSet();
subjectSet.setNamespace("messages");
subjectSet.setObject("lyl_obj");
subjectSet.setRelation("lyl_relation");
createRelationshipBody.setSubjectSet(subjectSet);
try {
Relationship result = apiInstance.createRelationship(createRelationshipBody);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling RelationshipApi#createRelationship");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
4.I found that the order of the incoming parameters is wrong when ApiClient#serialize calls RequestBody#create: the first parameter of RequestBody#create of okhttp3 is MediaType, but when ApiClient#serialize is called, the second parameter is passed in as MediaType:
ApiClient:
public RequestBody serialize(Object obj, String contentType) throws ApiException {
if (obj instanceof byte[]) {
// Binary (byte array) body parameter support.
return RequestBody.create((byte[]) obj, MediaType.parse(contentType));
} else if (obj instanceof File) {
// File body parameter support.
return RequestBody.create((File) obj, MediaType.parse(contentType));
} else if ("text/plain".equals(contentType) && obj instanceof String) {
return RequestBody.create((String) obj, MediaType.parse(contentType));
} else if (isJsonMime(contentType)) {
String content;
if (obj != null) {
content = JSON.serialize(obj);
} else {
content = null;
}
return RequestBody.create(content, MediaType.parse(contentType));
} else if (obj instanceof String) {
return RequestBody.create((String) obj, MediaType.parse(contentType));
} else {
throw new ApiException("Content type "" + contentType + "" is not supported");
}
}
okhttp3:
public static RequestBody create(@nullable MediaType contentType, String content) {
Charset charset = StandardCharsets.UTF_8;
if (contentType != null) {
charset = contentType.charset();
if (charset == null) {
charset = StandardCharsets.UTF_8;
contentType = MediaType.parse(contentType + "; charset=utf-8");
}
}
Relevant log output
Relevant configuration
Version
0.11.0-alpha.0
On which operating system are you observing this issue?
None
In which environment are you deploying?
None
Additional Context
No response
The text was updated successfully, but these errors were encountered: