Cannot create/update REST resource [message #1854199] |
Fri, 05 August 2022 14:49 |
J D Messages: 108 Registered: February 2021 |
Senior Member |
|
|
Hi there everyone,
I'm having problems creating/updating REST resources on a remote server. The methods I'm using are shown below:
// POST
public Response post(ContactEntityDo entity) {
Map<String, String> params = Map.of("schema", SCHEMA_NAME);
JSONObject jsParams = new JSONObject(params);
WebTarget target = helper().target(RESOURCE_PATH).queryParam("params",
UriComponent.encode(jsParams.toString(), UriComponent.Type.QUERY_PARAM_SPACE_ENCODED));
return target.request().accept(MediaType.APPLICATION_JSON).post(Entity.json(entity),
Response.class);
}
// PUT
public Response put(ContactEntityDo entity) {
Map<String, String> params = Map.of("schema", SCHEMA_NAME);
JSONObject jsParams = new JSONObject(params);
WebTarget target = helper().target(RESOURCE_PATH).queryParam("params",
UriComponent.encode(jsParams.toString(), UriComponent.Type.QUERY_PARAM_SPACE_ENCODED));
return target.request().accept(MediaType.APPLICATION_JSON).put(Entity.json(entity),
Response.class);
}
Here is the stacktrace
java.lang.NullPointerException: null
at org.eclipse.scout.apps.ygclient.client.rest.common.ResponseRestClientHelper.transformException(ResponseRestClientHelper.java:34)
at org.eclipse.scout.rt.rest.client.proxy.RestClientProxyFactory$RestProxyInvocationHandler.transformException(RestClientProxyFactory.java:256)
at org.eclipse.scout.rt.rest.client.proxy.RestClientProxyFactory$RestProxyInvocationHandler.invoke(RestClientProxyFactory.java:206)
at com.sun.proxy.$Proxy58.post(Unknown Source)
at org.eclipse.scout.apps.ygclient.client.rest.collaborator.contact.ContactRestResourceClient.post(ContactRestResourceClient.java:61)
at org.eclipse.scout.apps.ygclient.client.collaborator.contact.ContactForm$MainBox$GeneralBox$SaveButton.execClickAction(ContactForm.java:352)
at org.eclipse.scout.rt.client.ui.form.fields.button.AbstractButton$LocalButtonExtension.execClickAction(AbstractButton.java:515)
at org.eclipse.scout.rt.client.extension.ui.form.fields.button.ButtonChains$ButtonClickActionChain$1.callMethod(ButtonChains.java:59)
at org.eclipse.scout.rt.client.extension.ui.form.fields.button.ButtonChains$ButtonClickActionChain$1.callMethod(ButtonChains.java:1)
at org.eclipse.scout.rt.shared.extension.AbstractExtensionChain.callChain(AbstractExtensionChain.java:118)
at org.eclipse.scout.rt.client.extension.ui.form.fields.button.ButtonChains$ButtonClickActionChain.execClickAction(ButtonChains.java:62)
at org.eclipse.scout.rt.client.ui.form.fields.button.AbstractButton.interceptClickAction(AbstractButton.java:499)
at org.eclipse.scout.rt.client.ui.form.fields.button.AbstractButton.doClick(AbstractButton.java:341)
at org.eclipse.scout.rt.client.ui.form.fields.button.AbstractButton$P_UIFacade.fireButtonClickFromUI(AbstractButton.java:469)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.eclipse.scout.rt.client.ModelContextProxy.lambda$1(ModelContextProxy.java:49)
at org.eclipse.scout.rt.platform.chain.callable.CallableChain$Chain.continueChain(CallableChain.java:227)
at org.eclipse.scout.rt.platform.transaction.TransactionProcessor.runTxMandatory(TransactionProcessor.java:156)
at org.eclipse.scout.rt.platform.transaction.TransactionProcessor.runTxRequired(TransactionProcessor.java:139)
at org.eclipse.scout.rt.platform.transaction.TransactionProcessor.intercept(TransactionProcessor.java:78)
at org.eclipse.scout.rt.platform.chain.callable.CallableChain$Chain.continueChain(CallableChain.java:222)
at org.eclipse.scout.rt.platform.chain.callable.CallableChain.call(CallableChain.java:170)
at org.eclipse.scout.rt.platform.context.RunContext.call(RunContext.java:158)
at org.eclipse.scout.rt.client.ModelContextProxy.lambda$0(ModelContextProxy.java:49)
at com.sun.proxy.$Proxy62.fireButtonClickFromUI(Unknown Source)
at org.eclipse.scout.rt.ui.html.json.form.fields.button.JsonButton.handleUiEvent(JsonButton.java:145)
at org.eclipse.scout.rt.ui.html.json.JsonEventProcessor.processEvent(JsonEventProcessor.java:52)
at org.eclipse.scout.rt.ui.html.json.JsonEventProcessor.processEvents(JsonEventProcessor.java:37)
...........
The problem seems to be from the return line in both of the methods. This is line 61 of my ContactRestResourceClient.java class
return target.request().accept(MediaType.APPLICATION_JSON).post(Entity.json(entity),
Response.class);
I've read Chapter 17 REST of the Scout Technical Guide, but I still cannot solve the problem. Can anyone please help me figure out what I'm doing wrong?
Cheers,
JD
[Updated on: Fri, 05 August 2022 15:27] Report message to a moderator
|
|
|
|
|
Re: Cannot create/update REST resource [message #1854221 is a reply to message #1854218] |
Mon, 08 August 2022 11:30 |
|
...
ErrorDo error = response.readEntity(ErrorResponse.class).getError();
throw new VetoException(error.getMessage()).withTitle(error.getTitle());
Apparently, the "error" attribute of the ErrorResponse object is null. You might want to add a null-check here.
Quote:
The exception message is shown in the attached image. It's in French, but tit says an internal processing error occurred with error code N20.
What you are seeing is the NullPointerException caused by the error transformation, not the original error. Try setting a breakpoint and inspecting the content of the ErrorResponse object.
Regards,
Beat
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03730 seconds