REST services call

  

Hi,

I use REST services to consume data. This works fine.

In the backend we made some changes we added a few new fields and new table.

In Oustsystems I changed the REST api,  this resulted in changed Output Response (extra attribute and extra structure files).

If I test this in the  "Consume REST api method" tool I get the right data. So far so good.


Unfortunally, if I use this REST api method in my application I get a error for example "ssadso_ch_srt". (adso_ch_srt isone of  the new attributes)

If I debug my application I see in the OnAfterResponse the right JSON file in de response variable.But the response variable from my REST api holds the "old" structure. So it is obvious that he launched an error.But I don't understand why he holds the old response structure. I think some where he cached the old structure.


If I built a new application and I use the same REST call  it works fine.

Can anybody help me? 

Hi Arnold,

Just to clarify, the module you are calling your REST api method is the same module where you consume the REST api? or are you doing this in two different modules? If it's this last case, then you might need to refresh dependencies on the module calling your REST api method (given that you changed the module that consumes the REST api when you added the new attributes).

Hi Arnold,

I think this thread has the solution to your problem.


Cheers,

Tiago.

Hi Arnold,

I don´t know if this is your case, but recently I have same similar issue regarding this. In my case I had remapped the api to create a new structure in a right way.

Therefore, I saw in the latest version of Development Env, they fix a bug related to response structures in Swagger parser. It is still a release candidate version, but maybe could be one solution for it.

https://www.outsystems.com/home/downloadsdetail/110/2067/ 

  • Fixes the generation of response structures in Swagger parser. (RPD-3208)


Best regards

Fabio Fantato

Jorge Martins wrote:

Hi Arnold,

Just to clarify, the module you are calling your REST api method is the same module where you consume the REST api? or are you doing this in two different modules? If it's this last case, then you might need to refresh dependencies on the module calling your REST api method (given that you changed the module that consumes the REST api when you added the new attributes).

yes, I do this in different modules , and i refreshed the dependecies more than twice ..... But no result


Fantato wrote:

Hi Arnold,

I don´t know if this is your case, but recently I have same similar issue regarding this. In my case I had remapped the api to create a new structure in a right way.

Therefore, I saw in the latest version of Development Env, they fix a bug related to response structures in Swagger parser. It is still a release candidate version, but maybe could be one solution for it.

https://www.outsystems.com/home/downloadsdetail/110/2067/ 

  • Fixes the generation of response structures in Swagger parser. (RPD-3208)


Best regards

Fabio Fantato

Installed the new version, but result is the same

Arnold Groote wrote:

Fantato wrote:

Hi Arnold,

I don´t know if this is your case, but recently I have same similar issue regarding this. In my case I had remapped the api to create a new structure in a right way.

Therefore, I saw in the latest version of Development Env, they fix a bug related to response structures in Swagger parser. It is still a release candidate version, but maybe could be one solution for it.

https://www.outsystems.com/home/downloadsdetail/110/2067/ 

  • Fixes the generation of response structures in Swagger parser. (RPD-3208)


Best regards

Fabio Fantato

Installed the new version, but result is the same


I also delete the 'old' REST -API method and the Structure files and rebuild a new one. Result negative same error


Tiago Gafeira wrote:

Hi Arnold,

I think this thread has the solution to your problem.


Cheers,

Tiago.

Hi, i get the same error


Hi Arnold,

With REST, you have great control over what the input and output structures look like - you can manually change the structures, add attributes, rename attributes (design-time only or runtime in JSON). If you add all methods of a REST API by consuming the Swagger definition, the input/output structures are created according to that definition (at least when consuming OutSystems-generated Swagger definitions, your mileage may vary with other suppliers' Swagger defs). Note that there have been a number of issues in the past that prevent the Swagger to be updated after changing the exposed REST API, so first check (if you haven't done already) that the Swagger is what you expect it to be).

In general, if the output of a REST method doesn't completely match what the Platform expects, extra attributes are ignored, and non-existing attributes are given the default value. The only reason for an error is afaik when you have an attribute that's mandatory but isn't in the response.

Unfortunately your description of your exact problems isn't very precise, so I can't tell what the problem is in this particular instant. You say "in Oustsystems I changed the REST api,  this resulted in changed Output Response (extra attribute and extra structure files)." But what did you do on the consuming side? A change to the exposed REST API does not "result" in any changes to the consuming side, you need to either delete and reconsume the API, or manually add/change the new/changed method. Also, you say "get a error for example "ssadso_ch_srt"", but OutSystems errors are much more verbose than that. What does the actual error say? Can you give a dump from Service Center?

Hi Kilian,


 I deleted the old Rest- api mehod inclusive the Structure files.

Generated the new Api call with the new Structure files.

Than I checked the depencies in de calling module and refreshed them.


Stack message:




ssAdso_ch_srt


Environment Information
Stack:
ssAdso_ch_srt
java.lang.NoSuchFieldError: ssAdso_ch_srt
   at oswinkel_is.ccwinkelservices.RESTTtadreItem.toStructure(Unknown Source)
   at oswinkel_is.ccwinkelservices.RESTTtadreItem$1.executeImpl(Unknown Source)
   at oswinkel_is.ccwinkelservices.RESTTtadreItem$1.executeImpl(Unknown Source)
   at outsystems.hubedition.util.delegates.Func$Func1.execute(Unknown Source)
   at outsystems.hubedition.runtimeplatform.db.OSList.innerFromArray(Unknown Source)
   at oswinkel_is.recordlists.RLTtadreItemList.toList(Unknown Source)
   at oswinkel_is.ccwinkelservices.RESTTtafneItem.toStructure(Unknown Source)
   at oswinkel_is.ccwinkelservices.RESTTtafneItem$1.executeImpl(Unknown Source)
   at oswinkel_is.ccwinkelservices.RESTTtafneItem$1.executeImpl(Unknown Source)
   at outsystems.hubedition.util.delegates.Func$Func1.execute(Unknown Source)
   at outsystems.hubedition.runtimeplatform.db.OSList.innerFromArray(Unknown Source)
   at oswinkel_is.recordlists.RLTtafneItemList.toList(Unknown Source)
   at oswinkel_is.ccwinkelservices.RESTResult.toStructure(Unknown Source)
   at oswinkel_is.ccwinkelservices.RESTGetAfneResponse.toStructure(Unknown Source)
   at oswinkel_is.actions.ActGetAfne.executeGetAfne(Unknown Source)
   at oswinkel_is.actions.ActActionnewW.executeActionnewW(Unknown Source)
   at oswinkel_cs.referencesproxy.rssespacewinkel_is.actions.ActActionnewW.mosActionnewW(Unknown Source)
   at oswinkel_cs.actions.ActActionnewW.executeActionnewW(Unknown Source)
   at oswinkel_cs.actions.ActAction1.executeAction1(Unknown Source)
   at oswinkel.referencesproxy.rssespacewinkel_cs.actions.ActAction1.mosAction1(Unknown Source)
   at oswinkel.actions.ActAction1.executeAction1(Unknown Source)
   at oswinkel.managedbean.flowmainflowwinkel.ScrnWinkel_afne.commandSearch(Unknown Source)
   at oswinkel.managedbean.flowmainflowwinkel.ScrnWinkel_afne.lnk77Click(Unknown Source)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:498)
   at com.sun.el.parser.AstValue.invoke(AstValue.java:292)
   at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
   at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68)
   at outsystems.hubedition.webwidgets.uicomponent.utils.MethodExpressionEventListener.invokeAction(Unknown Source)
   at outsystems.hubedition.webwidgets.ajaxEvents.MethodExpressionAjaxClickEventListener.processAjaxClickEvent(Unknown Source)
   at outsystems.hubedition.webwidgets.ajaxEvents.AjaxClickEvent.processListener(Unknown Source)
   at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:813)
   at outsystems.hubedition.webwidgets.uicomponent.os_controls.WebBlockInstanceComponent.broadcast(Unknown Source)
   at outsystems.hubedition.webwidgets.uicomponent.os_controls.WebBlockInstanceComponent.broadcast(Unknown Source)
   at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
   at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
   at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
   at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
   at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
   at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
   at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130)
   at outsystems.hubedition.webwidgets.BaseRequestStartupFilter.doFilter(Unknown Source)
   at oswinkel.RequestStartupFilter.doFilter(Unknown Source)
   at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
   at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
   at outsystems.hubedition.webwidgets.filters.HttpContextFilter.doFilter(Unknown Source)
   at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
   at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
   at outsystems.hubedition.webwidgets.filters.CacheControlFilter.doFilter(Unknown Source)
   at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
   at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
   at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)
   at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)
   at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
   at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
   at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
   at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
   at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56)
   at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
   at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
   at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:63)
   at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
   at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)
   at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
   at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
   at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
   at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
   at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
   at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261)
   at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:247)
   at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:76)
   at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:166)
   at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199)
   at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:765)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
   at java.lang.Thread.run(Thread.java:748)

 

Hi Arnold,

 I deleted the old Rest- api mehod inclusive the Structure files.

There's no such thing as a "structure file". We just call them Structures. What did you delete, the exposed or consumed structures?

Generated the new Api call with the new Structure files.

How did you "generate" the REST API? Did you actually recreate the exposed REST API? That was not what we intended, you needed to reconsume the REST API.

[Then] I checked the depencies in [the] calling module and refreshed them.

Refreshing the dependencies refreshes has nothing to do with the REST APIs! It refreshes references to Actions, Entitites etc.

Ok, so I'm taking a guess at what you did. Instead of removing the consumed REST API from the consuming module, and re-referencing the REST API (via "Consume REST API", "Add all methods" etc.), you recreated the exposed REST API, and did nothing with the consumed REST API, assuming that refreshing references also works for REST APIs (which it doesn't). Since the problem you are having lies at the consuming side, it is clear why you're stuck.

So, this is what you need to do:

  1. Remove the consumed REST API from the consuming module. The Structures associated with it will be automatically deleted.
  2. Re-reference the REST API, by selecting "Consume REST API" from the context menu (I guess you must've done this before?), click the "Add all methods" button, enter the URL, press Ok. This recreates the API and the Sructures, the latter reflecting the changes you made producer-side.

The above steps will solve your immediate problems. That said, this is all fairly basic stuff, so you might want to revisit the online training about these topics, and hopefully gain understanding about the difference between exposing/consuming Actions vs. REST APIs, refreshing references, etc.




Hi,

I only using "Consume REST APi".

What you proposed  , that's what i have done several times.

Unfortunately , I must  manually delete the asssoicated Structures, does not work automatically.  


  1. Remove the consumed REST API from the consuming module. The Structures associated with it will be automatically deleted.
  2. Re-reference the REST API, by selecting "Consume REST API" from the context menu (I guess you must've done this before?), click the "Add all methods" button, enter the URL, press Ok. This recreates the API and the Sructures, the latter reflecting the changes you made producer-side.



Hi Arnold,

I just did a quick test, but deleting the consumed REST API from an eSpace also deletes the associated structures. In fact, the structures are listed in a Folder below the REST API icon (Data tab, Structures folder):

If you delete the REST API from the Integrations folder on the Logic tab, the Structures also disappear (in the example below, delete MyRestApi). Only if you only delete the method, but not the REST API itself, the structures remain, marked as "unused" (and you get a TrueChange warning).

As for your problem, have you already checked the Swagger definition? Is it correct? If so, have you compared the Swagger with the generated Structures? Are they equal? Do you have the Attribute that causes the error?

Solution

Arnold Groote wrote:


The server where OS is running on has been rebooted. 

This has solved the problem.

Somewhere caching maybe???

Thanks to you all for the response.

Regards Arnold 

Hi,

I use REST services to consume data. This works fine.

In the backend we made some changes we added a few new fields and new table.

In Oustsystems I changed the REST api,  this resulted in changed Output Response (extra attribute and extra structure files).

If I test this in the  "Consume REST api method" tool I get the right data. So far so good.


Unfortunally, if I use this REST api method in my application I get a error for example "ssadso_ch_srt". (adso_ch_srt isone of  the new attributes)

If I debug my application I see in the OnAfterResponse the right JSON file in de response variable.But the response variable from my REST api holds the "old" structure. So it is obvious that he launched an error.But I don't understand why he holds the old response structure. I think some where he cached the old structure.


If I built a new application and I use the same REST call  it works fine.

Can anybody help me? 



Solution

Glad you found the solution, even though it's a bit "heavy". Happy coding!