Quantcast
Channel: Mendix Forum Questions
Viewing all articles
Browse latest Browse all 82389

Consuming a REST service with dynamic attributes

$
0
0

Hi there

We are trying to consume a REST service with dynamic attributes based on a record type.  An example is shown below.

Event type 4:

   {"eventType":4,"eventDate":1498521600000,"clientId":41,"log":"","properties":{"new_total":"£0.00","link":"http://localhost/customer/41/claim/3505166282169","claimant_name":"JOE BLOGGS","previous_total":"£37,617.00","reference_number":"05166282169"
      }
   },

 Event type 17:

   {"eventType":17,"eventDate":1498521600000,"clientId":41,"log":"","properties":{"payment_type":"Payment","payment_status":"Authorised","link":"https://localhost/customer/41/claim/3105171345044","payee_name":"JANE DOE","reference_number":"05171345044","payment_status_prefix":" has been ","payee_name_prefix":" to ","claim_payment_amount":"£16.74"
      }
   },

As you can see, the two event types have different attributes in the properties section in the two JSON snippets above.  When creating the structures in Mendix using the JSON examples, Mendix seems to take only the key/value pairs in the first record type.  In order to overcome this, I manually added the attributes that the first event type record is missing.  When calling the REST API with the updated record type including all attributes it falls over with the following error:

com.mendix.modules.microflowengine.MicroflowException: Error calling REST service
	at DataServices_Clients_ref.Clients_ref_GetActivityLog_New (CallRest : 'Call REST (GET)')
	at DataLoad.SCH_LoadClientActivityLog (SubMicroflow : 'Clients_ref_GetActivityLog_New')
	at AdminPanel.SUB_LoadClientActivityLog (SubMicroflow : 'SCH_LoadClientActivityLog')

Advanced stacktrace:
	at com.mendix.integration.actions.microflow.RestCallAction.execute(RestCallAction.scala:48)

Caused by: com.mendix.modules.microflowengine.MicroflowException: 500: Internal Server Error
	at DataServices_Clients_ref.Clients_ref_GetActivityLog_New (CallRest : 'Call REST (GET)')
	at DataLoad.SCH_LoadClientActivityLog (SubMicroflow : 'Clients_ref_GetActivityLog_New')
	at AdminPanel.SUB_LoadClientActivityLog (SubMicroflow : 'SCH_LoadClientActivityLog')

Advanced stacktrace:
	at com.mendix.integration.actions.microflow.RestCallAction.checkStatusCode(RestCallAction.scala:89)
	at com.mendix.integration.actions.microflow.RestCallAction.com$mendix$integration$actions$microflow$RestCallAction$$handleResponse(RestCallAction.scala:68)
	at com.mendix.integration.actions.microflow.RestCallAction$$anonfun$execute$1$$anonfun$apply$1.apply(RestCallAction.scala:43)
	at com.mendix.integration.actions.microflow.RestCallAction$$anonfun$execute$1$$anonfun$apply$1.apply(RestCallAction.scala:42)
	at com.mendix.integration.util.AutoCloseableUtil$.using(AutoCloseableUtil.scala:6)
	at com.mendix.integration.actions.microflow.RestCallAction$$anonfun$execute$1.apply(RestCallAction.scala:42)
	at com.mendix.integration.actions.microflow.RestCallAction$$anonfun$execute$1.apply(RestCallAction.scala:41)
	at com.mendix.integration.util.AutoCloseableUtil$.using(AutoCloseableUtil.scala:6)
	at com.mendix.integration.actions.microflow.RestCallAction.execute(RestCallAction.scala:41)
	at com.mendix.modules.microflowengine.microflow.impl.MicroflowObject.execute(MicroflowObject.java:47)
	at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAfterBreakingIfNecessary(MicroflowImpl.java:200)
	at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAction(MicroflowImpl.java:157)
	at com.mendix.systemwideinterfaces.core.UserAction.execute(UserAction.java:50)
	at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.doCall(CoreActionHandlerImpl.scala:73)
	at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.call(CoreActionHandlerImpl.scala:53)
	at com.mendix.core.actionmanagement.CoreAction.call(CoreAction.java:51)
	at com.mendix.basis.actionmanagement.ActionManager$1.execute(ActionManager.java:170)
	at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:33)
	at com.mendix.basis.actionmanagement.ActionManager.executeSync(ActionManager.java:174)
	at com.mendix.basis.component.InternalCore.executeSync(InternalCore.java:609)
	at com.mendix.modules.microflowengine.actions.SubMicroflowAction.execute(SubMicroflowAction.scala:44)
	at com.mendix.modules.microflowengine.microflow.impl.MicroflowObject.execute(MicroflowObject.java:47)
	at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAfterBreakingIfNecessary(MicroflowImpl.java:200)
	at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAction(MicroflowImpl.java:157)
	at com.mendix.systemwideinterfaces.core.UserAction.execute(UserAction.java:50)
	at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.doCall(CoreActionHandlerImpl.scala:73)
	at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.call(CoreActionHandlerImpl.scala:53)
	at com.mendix.core.actionmanagement.CoreAction.call(CoreAction.java:51)
	at com.mendix.basis.actionmanagement.ActionManager$1.execute(ActionManager.java:170)
	at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:33)
	at com.mendix.basis.actionmanagement.ActionManager.executeSync(ActionManager.java:174)
	at com.mendix.basis.component.InternalCore.executeSync(InternalCore.java:609)
	at com.mendix.modules.microflowengine.actions.SubMicroflowAction.execute(SubMicroflowAction.scala:44)
	at com.mendix.modules.microflowengine.microflow.impl.MicroflowObject.execute(MicroflowObject.java:47)
	at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAfterBreakingIfNecessary(MicroflowImpl.java:200)
	at com.mendix.modules.microflowengine.microflow.impl.MicroflowImpl.executeAction(MicroflowImpl.java:157)
	at com.mendix.systemwideinterfaces.core.UserAction.execute(UserAction.java:50)
	at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.doCall(CoreActionHandlerImpl.scala:73)
	at com.mendix.basis.actionmanagement.CoreActionHandlerImpl.call(CoreActionHandlerImpl.scala:53)
	at com.mendix.core.actionmanagement.CoreAction.call(CoreAction.java:51)
	at com.mendix.basis.actionmanagement.ActionManager$1.execute(ActionManager.java:170)
	at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:33)
	at com.mendix.basis.actionmanagement.ActionManager.executeSync(ActionManager.java:174)
	at com.mendix.basis.component.InternalCore.execute(InternalCore.java:531)
	at com.mendix.webui.actions.client.ExecuteAction.execute(ExecuteAction.java:143)
	at com.mendix.webui.requesthandling.ClientRequestHandler$$anonfun$handleRequest$1.apply$mcV$sp(ClientRequestHandler.scala:308)
	at com.mendix.webui.requesthandling.ClientRequestHandler$$anonfun$handleRequest$1.apply(ClientRequestHandler.scala:293)
	at com.mendix.webui.requesthandling.ClientRequestHandler$$anonfun$handleRequest$1.apply(ClientRequestHandler.scala:293)
	at com.mendix.basis.actionmanagement.IMonitoredAction$$anon$1.execute(IMonitoredAction.scala:47)
	at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:33)
	at com.mendix.basis.actionmanagement.IMonitoredAction$class.monitor(IMonitoredAction.scala:49)
	at com.mendix.webui.requesthandling.ClientRequestHandler$ClientMonitoredAction.monitor(ClientRequestHandler.scala:410)
	at com.mendix.webui.requesthandling.ClientRequestHandler.handleRequest(ClientRequestHandler.scala:293)
	at com.mendix.webui.requesthandling.ClientRequestHandler.handleActionWithSessionRequired(ClientRequestHandler.scala:235)
	at com.mendix.webui.requesthandling.ClientRequestHandler.handleAction(ClientRequestHandler.scala:202)
	at com.mendix.webui.requesthandling.ClientRequestHandler.liftedTree1$1(ClientRequestHandler.scala:101)
	at com.mendix.webui.requesthandling.ClientRequestHandler.processRequest(ClientRequestHandler.scala:93)
	at com.mendix.externalinterface.connector.RequestHandler.doProcessRequest(RequestHandler.java:40)
	at com.mendix.external.connector.MxRuntimeConnector$1.execute(MxRuntimeConnector.java:70)
	at com.mendix.external.connector.MxRuntimeConnector$1.execute(MxRuntimeConnector.java:67)
	at com.mendix.util.classloading.Runner.doRunUsingClassLoaderOf(Runner.java:33)
	at com.mendix.external.connector.MxRuntimeConnector.processRequest(MxRuntimeConnector.java:73)
	at com.mendix.basis.impl.MxRuntimeImpl.processRequest(MxRuntimeImpl.java:885)
	at com.mendix.m2ee.appcontainer.server.handler.RuntimeHandler.handle(RuntimeHandler.java:41)
	at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
	at org.eclipse.jetty.server.Server.handle(Server.java:368)
	at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)
	at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:953)
	at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1014)
	at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:861)
	at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
	at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
	at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
	at java.lang.Thread.run(Thread.java:745)

I suspect the reason for this is the fact that Mendix expects values in the mapping that I manually added and it then crashes if the API doesn't provide a key/value pair.  Is there any way we can force the call to the API to be a bit more lenient on the attribute mappings and not to error when it does not find a specific attribute?

Thanks


Viewing all articles
Browse latest Browse all 82389

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>