WebScriptRequest - how to know different verbs (POST, PUT, DELETE, GET)

cancel
Showing results for 
Search instead for 
Did you mean: 
raghav
Member II

WebScriptRequest - how to know different verbs (POST, PUT, DELETE, GET)

Is there a way to know the verb (GET, POST, PUT, DELETE) inside the execute method of AbstractWebScript? Does WebScriptRequest know anything about whether the call is a GET, or a PUT, or a POST, or a DELETE?

I can always create another web script  (one for PUT, another for POST etc.). 

I can also differentiate between the verbs, if the URI is different for PUT, GET etc.

But I was wondering if the WebScriptRequest has a way to determine the verb type (whether it is GET, POST, PUT, DELETE).

3 Replies
afaust
Master

Re: WebScriptRequest - how to know different verbs (POST, PUT, DELETE, GET)

Yes, you technically can get the verb from the description, which holds the method the web script was defined for. Since each web script inherently is associated to a single verb based on the bean name, you will typically only need to check the verb if you re-use the same implementation class for different web scripts, e.g. to build a dispatcher-like web script.

The web script request itself does not contain that information, though you could technically retrieve it from there as well via the reference to the HttpServletRequest - but that would require you to cast the request to one of the specific implementation classes and it is not guaranteed you will get the one implementation class that will allow you to access the servlet request.

raghav
Member II

Re: WebScriptRequest - how to know different verbs (POST, PUT, DELETE, GET)

1. We cannot get the verb (e.g. GET, POST etc.) from WebScriptRequest because, we cannot cast the WebScriptRequest to HttpRequest (it will throw runtime error).

2. None of the methods of WebScript request return the verb. 

3. The header does not include the verb (which is obvious, but wanted to state it).

Is there anything that I put in descriptor, which will possibly return the verb from the WebScriptRequest, inside the execute method ?

My descriptor (xxxx.post.desc.xml loks like):

<webscript>
   <shortname></shortname>
   <description>??? Can I put anything here</description>
   <url>/example/aNumber</url>
   <format default="json">extension</format>
   <transaction>required</transaction>
<authentication runas="admin">none</authentication>

</webscript>

afaust
Master

Re: WebScriptRequest - how to know different verbs (POST, PUT, DELETE, GET)

The WebScriptRequest sure does provide that information: request.getServiceMatch().getWebScript().getDescription().getMethod().