Struts2 Rest Mapper Taking Over Non Rest Json Result

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Struts2 Rest Mapper Taking Over Non Rest Json Result

Paul Zepernick
This was also posted to stackoverflow and relevant config information can be seen in the post: http://stackoverflow.com/questions/39593721/struts2-rest-mapper-taking-over-non-rest-json-result

I am working with the DataTables JS library and am trying to write actions for the grid. I have a api in place that creates the json for me already and I just need to stream it back. I created a custom result to handle this, but the result mapped in the action never runs. No matter what the result type, the REST mapper tries to handle it as soon as it sees that application/json has been requested from the client. I have used the prefix mapping in the configuration to have all url's using /grid to bypass the rest mapper. It seems to be working in some capacity because it runs the correct interceptor stack and is using the @Action annotation information to map the url. However, the result specified is NOT running and is instead being provided by the rest mapper based on the stack trace I am receiving. I would like to completely bypass the rest mapper for any actions in the /grid namespace. Have I done something wrong in the configuration that is still causing rest to be involved in the request to those actions?

Paul R. Zepernick
Sr. Programmer Analyst






Disclaimer: This communication and any files transmitted with it may contain information that is privileged, confidential and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is strictly prohibited. If you received this communication in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: Struts2 Rest Mapper Taking Over Non Rest Json Result

Martin Gainty
to control navigation why not map it?<action name="grid/*" className="org.healthsmart.NonRestfulAction">    <param name="id">{1}</param>    ...</action>
GET: /grid/method="index"when you reference /grid/
struts will call org.healthsmart.NonRestfulAction index method
https://struts.apache.org/docs/restfulactionmapper.html

============or use DMI============
<package name="default" extends="struts-default" strict-method-invocation="true">  
  <action name="grid" class="org.healthsmart.NonRestfulAction">        <result name="success">/WEB-INF/content/hello.jsp</result>        <result name="redisplay" type="redirectAction">hello</result>        <allowed-methods>add</allowed-methods>    </action>
https://struts.apache.org/docs/action-configuration.html#ActionConfiguration-ActionMappings
I would check struts.mapper.prefixMapping for normal "rest prefixMapping vs struts prefixMapping" configurationhttps://struts.apache.org/docs/restfulactionmapper.html
if that looks ok as a last result you can implement a custom mapper which will read the URL and redirect to correct class programaticallyhttp://stackoverflow.com/questions/17697432/struts2-rest-plugin-making-both-struts-actions-rest-actions-work-together-but
Martin
______________________________________________



> From: [hidden email]
> To: [hidden email]
> Subject: Struts2 Rest Mapper Taking Over Non Rest Json Result
> Date: Tue, 20 Sep 2016 15:28:42 +0000
>
> This was also posted to stackoverflow and relevant config information can be seen in the post: http://stackoverflow.com/questions/39593721/struts2-rest-mapper-taking-over-non-rest-json-result
>
> I am working with the DataTables JS library and am trying to write actions for the grid. I have a api in place that creates the json for me already and I just need to stream it back. I created a custom result to handle this, but the result mapped in the action never runs. No matter what the result type, the REST mapper tries to handle it as soon as it sees that application/json has been requested from the client. I have used the prefix mapping in the configuration to have all url's using /grid to bypass the rest mapper. It seems to be working in some capacity because it runs the correct interceptor stack and is using the @Action annotation information to map the url. However, the result specified is NOT running and is instead being provided by the rest mapper based on the stack trace I am receiving. I would like to completely bypass the rest mapper for any actions in the /grid namespace. Have I done something wrong in the configuration that is still causing rest to be involved in the request to those actions?
>
> Paul R. Zepernick
> Sr. Programmer Analyst
>
>
>
>
>
>
> Disclaimer: This communication and any files transmitted with it may contain information that is privileged, confidential and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is strictly prohibited. If you received this communication in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
     
Reply | Threaded
Open this post in threaded view
|

RE: Struts2 Rest Mapper Taking Over Non Rest Json Result

Paul Zepernick
Thanks Martin, it was getting to the correct action class buy it was not using the result I defined in the action.  It was going to its own result implementation based on the fact that I am requesting an application/json data type.  I found out that if I add ".action" to the url it processes everything correctly and goes to the correct result.  I am not sure if that is the intended behavior, a setup issue on my part, or a bug?

-----Original Message-----
From: Martin Gainty [mailto:[hidden email]]
Sent: Tuesday, September 20, 2016 2:24 PM
To: Struts Users Mailing List <[hidden email]>
Subject: RE: Struts2 Rest Mapper Taking Over Non Rest Json Result

to control navigation why not map it?<action name="grid/*" className="org.healthsmart.NonRestfulAction">    <param name="id">{1}</param>    ...</action>
GET: /grid/method="index"when you reference /grid/ struts will call org.healthsmart.NonRestfulAction index method https://struts.apache.org/docs/restfulactionmapper.html

============or use DMI============
<package name="default" extends="struts-default" strict-method-invocation="true">  
  <action name="grid" class="org.healthsmart.NonRestfulAction">        <result name="success">/WEB-INF/content/hello.jsp</result>        <result name="redisplay" type="redirectAction">hello</result>        <allowed-methods>add</allowed-methods>    </action>
https://struts.apache.org/docs/action-configuration.html#ActionConfiguration-ActionMappings
I would check struts.mapper.prefixMapping for normal "rest prefixMapping vs struts prefixMapping" configurationhttps://struts.apache.org/docs/restfulactionmapper.html
if that looks ok as a last result you can implement a custom mapper which will read the URL and redirect to correct class programaticallyhttp://stackoverflow.com/questions/17697432/struts2-rest-plugin-making-both-struts-actions-rest-actions-work-together-but
Martin
______________________________________________



> From: [hidden email]
> To: [hidden email]
> Subject: Struts2 Rest Mapper Taking Over Non Rest Json Result
> Date: Tue, 20 Sep 2016 15:28:42 +0000
>
> This was also posted to stackoverflow and relevant config information can be seen in the post: http://stackoverflow.com/questions/39593721/struts2-rest-mapper-taking-over-non-rest-json-result
>
> I am working with the DataTables JS library and am trying to write actions for the grid. I have a api in place that creates the json for me already and I just need to stream it back. I created a custom result to handle this, but the result mapped in the action never runs. No matter what the result type, the REST mapper tries to handle it as soon as it sees that application/json has been requested from the client. I have used the prefix mapping in the configuration to have all url's using /grid to bypass the rest mapper. It seems to be working in some capacity because it runs the correct interceptor stack and is using the @Action annotation information to map the url. However, the result specified is NOT running and is instead being provided by the rest mapper based on the stack trace I am receiving. I would like to completely bypass the rest mapper for any actions in the /grid namespace. Have I done something wrong in the configuration that is still causing rest to be involved in the request to those actions?
>
> Paul R. Zepernick
> Sr. Programmer Analyst
>
>
>
>
>
>
> Disclaimer: This communication and any files transmitted with it may contain information that is privileged, confidential and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is strictly prohibited. If you received this communication in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
     

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Struts2 Rest Mapper Taking Over Non Rest Json Result

Ken McWilliams
To solve a similar issue I ended up creating my own ContentTypeHandler. As
you already have a result it should be pretty easy to wrap (at least I
found it so). The problem is that after doing so all JSON will be handled
by your new Content type...

While this link shows how to use Jackson, you can create your own
implementation and then apply your own configuration in the same way:
http://struts.apache.org/docs/rest-plugin.html#RESTPlugin-UseJacksonframeworkasJSONContentTypeHandler




On Tue, Sep 20, 2016 at 12:34 PM, Paul Zepernick <
[hidden email]> wrote:

> Thanks Martin, it was getting to the correct action class buy it was not
> using the result I defined in the action.  It was going to its own result
> implementation based on the fact that I am requesting an application/json
> data type.  I found out that if I add ".action" to the url it processes
> everything correctly and goes to the correct result.  I am not sure if that
> is the intended behavior, a setup issue on my part, or a bug?
>
> -----Original Message-----
> From: Martin Gainty [mailto:[hidden email]]
> Sent: Tuesday, September 20, 2016 2:24 PM
> To: Struts Users Mailing List <[hidden email]>
> Subject: RE: Struts2 Rest Mapper Taking Over Non Rest Json Result
>
> to control navigation why not map it?<action name="grid/*"
> className="org.healthsmart.NonRestfulAction">    <param
> name="id">{1}</param>    ...</action>
> GET: /grid/method="index"when you reference /grid/ struts will call
> org.healthsmart.NonRestfulAction index method https://struts.apache.org/
> docs/restfulactionmapper.html
>
> ============or use DMI============
> <package name="default" extends="struts-default" strict-method-invocation="
> true">
>   <action name="grid" class="org.healthsmart.NonRestfulAction">
> <result name="success">/WEB-INF/content/hello.jsp</result>        <result
> name="redisplay" type="redirectAction">hello</result>
> <allowed-methods>add</allowed-methods>    </action>
> https://struts.apache.org/docs/action-configuration.
> html#ActionConfiguration-ActionMappings
> I would check struts.mapper.prefixMapping for normal "rest prefixMapping
> vs struts prefixMapping" configurationhttps://struts.apache.org/docs/
> restfulactionmapper.html
> if that looks ok as a last result you can implement a custom mapper which
> will read the URL and redirect to correct class programaticallyhttp://
> stackoverflow.com/questions/17697432/struts2-rest-plugin-making-
> both-struts-actions-rest-actions-work-together-but
> Martin
> ______________________________________________
>
>
>
> > From: [hidden email]
> > To: [hidden email]
> > Subject: Struts2 Rest Mapper Taking Over Non Rest Json Result
> > Date: Tue, 20 Sep 2016 15:28:42 +0000
> >
> > This was also posted to stackoverflow and relevant config information
> can be seen in the post: http://stackoverflow.com/
> questions/39593721/struts2-rest-mapper-taking-over-non-rest-json-result
> >
> > I am working with the DataTables JS library and am trying to write
> actions for the grid. I have a api in place that creates the json for me
> already and I just need to stream it back. I created a custom result to
> handle this, but the result mapped in the action never runs. No matter what
> the result type, the REST mapper tries to handle it as soon as it sees that
> application/json has been requested from the client. I have used the prefix
> mapping in the configuration to have all url's using /grid to bypass the
> rest mapper. It seems to be working in some capacity because it runs the
> correct interceptor stack and is using the @Action annotation information
> to map the url. However, the result specified is NOT running and is instead
> being provided by the rest mapper based on the stack trace I am receiving.
> I would like to completely bypass the rest mapper for any actions in the
> /grid namespace. Have I done something wrong in the configuration that is
> still causing rest to be involved in the request to those actions?
> >
> > Paul R. Zepernick
> > Sr. Programmer Analyst
> >
> >
> >
> >
> >
> >
> > Disclaimer: This communication and any files transmitted with it may
> contain information that is privileged, confidential and/or exempt from
> disclosure under applicable law. If you are not the intended recipient, you
> are hereby notified that any disclosure, copying, distribution, or use of
> the information contained herein (including any reliance thereon) is
> strictly prohibited. If you received this communication in error, please
> immediately contact the sender and destroy the material in its entirety,
> whether in electronic or hard copy format. Thank you.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
Sent from my C64 using a 300 baud modem