Published Rest service Post requests fails with Error while importing, key value should no be null error - Mendix Forum

Published Rest service Post requests fails with Error while importing, key value should no be null error

0

I am following the Create Rest Api in the advanced learning paths.

https://gettingstarted.mendixcloud.com/link/module/98/lecture/827

When I create import mapping for post requests as defined in the "Add a Post Method" module I do not see any errors and I am able to start the project. However at run time I get an exception which seems to suggest that the Import Mapping does not see the values VehicleId value I am sending in the post request. The image below shows my configuration for the published Rest service.

Below is the import mapping.

Here is the add vehicle microflow.

I have not been able to find a solution to this. I get the following exception when I post an object.

com.mendix.systemwideinterfaces.MendixRuntimeException: Error while importing, key value for 'VehicleId' should not be null.

          at com.mendix.integration.importer.handlers.ObjectFinder.$anonfun$createArgs$1(ObjectFinder.scala:107)

          at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:238)

          at scala.collection.immutable.Map$Map1.foreach(Map.scala:128)

          at scala.collection.TraversableLike.map(TraversableLike.scala:238)

          at scala.collection.TraversableLike.map$(TraversableLike.scala:231)

          at scala.collection.AbstractTraversable.map(Traversable.scala:108)

          at com.mendix.integration.importer.handlers.ObjectFinder.createArgs(ObjectFinder.scala:99)

          at com.mendix.integration.importer.handlers.ObjectFinder.findInDatabaseInternal(ObjectFinder.scala:64)

          at com.mendix.integration.importer.handlers.ObjectFinder.findInDatabase(ObjectFinder.scala:54)

          at com.mendix.integration.importer.handlers.ObjectFinder.$anonfun$find$1(ObjectFinder.scala:23)

          at scala.Option.orElse(Option.scala:447)

          at com.mendix.integration.importer.handlers.ObjectFinder.find(ObjectFinder.scala:23)

          at com.mendix.integration.importer.handlers.ObjectMappingHandler.findObject(ObjectMappingHandler.scala:283)

          at com.mendix.integration.importer.handlers.ObjectMappingHandler.getObjectViaDefaultAction(ObjectMappingHandler.scala:243)

          at com.mendix.integration.importer.handlers.ObjectMappingHandler.getObjectImportInfo(ObjectMappingHandler.scala:108)

          at com.mendix.integration.importer.handlers.ObjectMappingHandler.createObjectInfo(ObjectMappingHandler.scala:127)

          at com.mendix.integration.importer.handlers.ObjectMappingHandler.$anonfun$endObjectElement$1(ObjectMappingHandler.scala:85)

          at scala.Option.map(Option.scala:230)

          at com.mendix.integration.importer.handlers.ObjectMappingHandler.endObjectElement(ObjectMappingHandler.scala:80)

          at com.mendix.integration.importer.handlers.StreamingHandler.$anonfun$handleElement$1(StreamingHandler.scala:81)

          at com.mendix.integration.importer.handlers.StreamingHandler.$anonfun$handleElement$1$adapted(StreamingHandler.scala:79)

          at scala.Option.foreach(Option.scala:407)

          at com.mendix.integration.importer.handlers.StreamingHandler.handleElement(StreamingHandler.scala:79)

          at com.mendix.integration.importer.handlers.StreamingHandler.endObject(StreamingHandler.scala:69)

          at com.mendix.integration.importer.json.JsonStreamingHandler.endElement(JsonStreamingHandler.scala:113)

          at com.mendix.integration.importer.json.JsonStreamingHandler.parseObject(JsonStreamingHandler.scala:59)

          at com.mendix.integration.importer.json.JsonStreamingHandler.$anonfun$parse$1(JsonStreamingHandler.scala:37)

          at com.mendix.integration.util.AutoCloseableUtil$.using(AutoCloseableUtil.scala:10)

          at com.mendix.integration.importer.json.JsonStreamingHandler.parse(JsonStreamingHandler.scala:32)

          at com.mendix.integration.importer.json.JsonImporter.$anonfun$parseJson$3(JsonImporter.scala:50)

          at scala.util.Try$.apply(Try.scala:213)

          at com.mendix.integration.importer.json.JsonImporter.$anonfun$parseJson$2(JsonImporter.scala:50)

          at com.mendix.integration.util.AutoCloseableUtil$.using(AutoCloseableUtil.scala:10)

          at com.mendix.integration.importer.json.JsonImporter.$anonfun$parseJson$1(JsonImporter.scala:49)

          at com.mendix.integration.util.AutoCloseableUtil$.using(AutoCloseableUtil.scala:10)

          at com.mendix.integration.importer.json.JsonImporter.parseJson(JsonImporter.scala:48)

          at com.mendix.integration.importer.json.JsonImporter.parse$1(JsonImporter.scala:37)

          at com.mendix.integration.importer.json.JsonImporter.$anonfun$importStream$1(JsonImporter.scala:39)

          at com.mendix.integration.util.ContextUtil$RichContext$.withTransaction$extension(ContextUtil.scala:11)

          at com.mendix.integration.importer.json.JsonImporter.importStream(JsonImporter.scala:39)

          at com.mendix.integration.internal.InternalIntegration.doImportStream(InternalIntegration.scala:92)

          at com.mendix.integration.internal.InternalIntegration.doImportStream$(InternalIntegration.scala:80)

          at com.mendix.integration.internal.InternalIntegrationImpl.doImportStream(InternalIntegrationImpl.scala:38)

          at com.mendix.integration.service.rest.microflowarguments.ObjectOrListArgument.$anonfun$apply$2(ObjectOrListArgument.scala:56)

          at scala.util.Success.flatMap(Try.scala:251)

          at com.mendix.integration.service.rest.microflowarguments.ObjectOrListArgument.apply(ObjectOrListArgument.scala:42)

          at com.mendix.integration.service.rest.microflowarguments.RestMicroflowArguments.bodyArgument(RestMicroflowArguments.scala:86)

          at com.mendix.integration.service.rest.microflowarguments.RestMicroflowArguments.argument(RestMicroflowArguments.scala:68)

          at com.mendix.integration.service.rest.microflowarguments.RestMicroflowArguments.$anonfun$apply$2(RestMicroflowArguments.scala:43)

          at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:238)

          at scala.collection.immutable.List.foreach(List.scala:392)

          at scala.collection.TraversableLike.map(TraversableLike.scala:238)

          at scala.collection.TraversableLike.map$(TraversableLike.scala:231)

          at scala.collection.immutable.List.map(List.scala:298)

          at com.mendix.integration.util.IteratorUtil$RichIterable$.toBreakoutMap$extension(IteratorUtil.scala:22)

          at com.mendix.integration.service.rest.microflowarguments.RestMicroflowArguments.$anonfun$apply$1(RestMicroflowArguments.scala:42)

          at scala.util.Try$.apply(Try.scala:213)

          at com.mendix.integration.service.rest.microflowarguments.RestMicroflowArguments.apply(RestMicroflowArguments.scala:42)

          at com.mendix.integration.service.rest.RestOperationProcessors.getMicroflowResult(RestOperationProcessors.scala:194)

          at com.mendix.integration.service.rest.RestOperationProcessors.$anonfun$operationResponse$5(RestOperationProcessors.scala:127)

          at com.mendix.basis.actionmanagement.IMonitoredAction$$anon$1.execute(IMonitoredAction.scala:47)

          at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:32)

          at com.mendix.basis.actionmanagement.IMonitoredAction.monitor(IMonitoredAction.scala:49)

          at com.mendix.basis.actionmanagement.IMonitoredAction.monitor$(IMonitoredAction.scala:25)

          at com.mendix.integration.service.ServiceMonitoredAction.monitor(ServiceMonitoredAction.scala:7)

          at com.mendix.integration.service.rest.RestOperationProcessors.$anonfun$operationResponse$4(RestOperationProcessors.scala:125)

          at com.mendix.integration.service.rest.RestOperationProcessors.withAuthenticationContext(RestOperationProcessors.scala:157)

          at com.mendix.integration.service.rest.RestOperationProcessors.$anonfun$operationResponse$3(RestOperationProcessors.scala:120)

          at com.mendix.integration.service.rest.RestOperationProcessors.operationResponse(RestOperationProcessors.scala:123)

          at com.mendix.integration.service.rest.RestOperationProcessors.processOperations(RestOperationProcessors.scala:83)

          at com.mendix.integration.service.rest.RestOperationProcessors.$anonfun$createProcessor$1(RestOperationProcessors.scala:62)

          at com.mendix.integration.service.PathProcessors.$anonfun$process$3(PathProcessors.scala:32)

          at scala.Option.fold(Option.scala:251)

          at com.mendix.integration.service.PathProcessors.$anonfun$process$1(PathProcessors.scala:32)

          at scala.collection.Iterator$$anon$11.nextCur(Iterator.scala:484)

          at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:490)

          at scala.collection.Iterator.isEmpty(Iterator.scala:385)

          at scala.collection.Iterator.isEmpty$(Iterator.scala:385)

          at scala.collection.AbstractIterator.isEmpty(Iterator.scala:1429)

          at com.mendix.integration.util.IteratorUtil$RichIterator$.headOption$extension(IteratorUtil.scala:41)

          at com.mendix.integration.util.IteratorUtil$RichIterable$.firstDefined$extension(IteratorUtil.scala:28)

          at com.mendix.integration.service.PathProcessors.process(PathProcessors.scala:29)

          at com.mendix.integration.service.PathProcessors.process$(PathProcessors.scala:28)

          at com.mendix.integration.service.rest.RestOperationProcessors.process(RestOperationProcessors.scala:40)

          at com.mendix.integration.requesthandlers.RestRequestHandler.$anonfun$processRequest$1(RestRequestHandler.scala:29)

          at scala.collection.Iterator$$anon$11.nextCur(Iterator.scala:484)

          at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:490)

          at scala.collection.Iterator.isEmpty(Iterator.scala:385)

          at scala.collection.Iterator.isEmpty$(Iterator.scala:385)

          at scala.collection.AbstractIterator.isEmpty(Iterator.scala:1429)

          at com.mendix.integration.util.IteratorUtil$RichIterator$.headOption$extension(IteratorUtil.scala:41)

          at com.mendix.integration.util.IteratorUtil$RichIterable$.firstDefined$extension(IteratorUtil.scala:28)

          at com.mendix.integration.requesthandlers.RestRequestHandler.processRequest(RestRequestHandler.scala:29)

          at com.mendix.externalinterface.connector.RequestHandler.doProcessRequest(RequestHandler.java:40)

          at com.mendix.external.connector.MxRuntimeConnector$1.execute(MxRuntimeConnector.java:76)

          at com.mendix.external.connector.MxRuntimeConnector$1.execute(MxRuntimeConnector.java:73)

          at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:32)

          at com.mendix.external.connector.MxRuntimeConnector.processRequest(MxRuntimeConnector.java:79)

          at com.mendix.basis.impl.MxRuntimeImpl.processRequest(MxRuntimeImpl.java:963)

          at com.mendix.m2ee.appcontainer.server.handler.RuntimeHandler.service(RuntimeHandler.java:42)

          at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)

          at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:867)

          at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:542)

          at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)

          at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1588)

          at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)

          at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345)

          at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)

          at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:480)

          at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1557)

          at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)

          at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247)

          at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)

          at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)

          at org.eclipse.jetty.server.Server.handle(Server.java:502)

          at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:364)

          at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)

          at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)

          at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)

          at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)

          at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)

          at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)

          at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)

          at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)

          at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366)

          at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)

          at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)

          at java.base/java.lang.Thread.run(Thread.java:834)

asked
4 answers
1

We need to take vehicle ID as Integer instead of Auto Number.

Since, it is not able to fetch auto number.

answered
1

The problem is clear that a field in the Import (incoming) message cannot be mapped to a Autonumber since it is auto generated. The solution is not very obvious. I created a new import message without the VehicleId. I then created an import mapping for the message. I then mapped the import message to the Vehicle entity. I also added an integer parameter to the Import mapping which I mapped to the VehicleId in the entity. This solved my problem.

answered
1

It seems that the Vehicleid you are trying to post is empty. Hence it can not find the object. You might also want to change the behaviour what to do if not found or change the autonumber field. Due to the autofieldnumber you can not change the value. So when posting a Vehicle with vehicleid 10000 you can not create it because it will create it with a totally different vehicleid autonumber.

Regards,

Ronald

 

answered
0
  1. I made the vehicle ID as Integer instead of Auto Number.
  2. I un-selected the Vehicle ID from the Message Defination of Import

 

  1. Change the Import Mapping , Vehicle ID will no longer be there, Make all other attributes as Key:

4.Change in the Microflow as follows to get the new Vehicle ID automatically :

So got the new Auto Generated Vehicle ID every time new Vehicle is created in Database, To check on duplicity key is used for each fields.

answered