I'm trying to make it possible to use full functionality of my Jersey webservice by both using regular HTTP method calls (GET,PUT,POST,DELETE), and specifying the method in URL while using POST method.
So to delete /resource client will be able to use:
DELETE /resource
or
POST /resource?method=DELETE
Does jersey support that? Or what would be the least-intrusive way to implement that?
The only way I can think of would be writing a Filter which wraps the original HttpServletRequest with my class whose getMethod returns the parsed HTTP method from the URL. Is this the only solution?
Thanks in advance.
Just add PostReplaceFilter to your app: http://jersey.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/container/filter/PostReplaceFilter.html
Related
I've read https://www.playframework.com/documentation/2.5.x/ScalaHttpFilters#more-powerful-filters, but I still don't understand how to access the request body inside the filter chain. I'm trying to make an accumulator but I'm not sure how to access the nextFilter in the apply method of EssentialAction. If anyone knows how to actually access the request body inside the filter chain let me know! I'm working in java
In order to parse the body of the request, you can use Action composition in your filters. You must actually stream / parse the body in the filter manually, and then let the framework parse it again as it passes to your controller.
Here is a good article on how this can be achieved.
https://www.javacodegeeks.com/2013/02/understanding-the-play-filter-api.html
I want to understand how a RESTful web service identifies if a correct request method is called.
For example,
I have a REST service it exposes one operation which is of type GET.
Assume a REST client has invoked the operation using a wrong request method(PUT).
In this scenario, how the service/framework identifies a correct request method is invoked?
I have gone through various posts to understand the scenario but I don't find any information.
Please let me know your comments.
The first line sent in an HTTP request looks like this:
GET /index.html HTTP/1.1
The HTTP request thus contains the HTTP method (POST, PUT, GET, etc.). The framework reads this method, and invokes the Java method that is mapped (thanks to annotations, or XML configuration, or whatever) to the URL (also contained in the HTTP request, as shown above) and the HTTP method. If none is found, then an error response is sent back (405 Method Not Allowed, if the resource is found, but with another method, or 404 if the resource is not found).
It's the http protocol not REST that checks headers, and reports back with an error code.
REST is sort of a strategy, not an implementation.
Hope this helps.
Hi I was just curious when is the doPut() method in a servlet called. I know that if the form on a jsp/html page has a "post" method then the doPost() is called otherwise if it has a "GET" then the doGet() is called.When is the doPut() called ??
When an HTTP PUT request is received, naturally.
Can a page do a PUT request by code?
The only valid method attribute values of a <form> are get and post, according to the HTML5 spec. I assume that's what you're asking.
The doPut() method handles requests send by using the HTTP PUT method. The PUT method allows a client to store information on the server. For an example, you can use it to post an image file to the server. As the above answer says, goGet() and doPost() are in use, mostly. In my case, I use only these two, and I am getting only get requests, so I simply transfer the get request to doPost() and do my job easily.
if you want to send some confidential values in url via form you must use the post method, If you will use the get method for the form like login the values parameters like userid and password will be visible in url and anyone can hack that thing. So better to use post method in forms. By default it will call get method.
in get the url is like http://url?method=methodname&userid=123&password=123
so if you use post method the url will be like this http://url/methodname.do
My app started by another app, and at initiating it must get POST parameters. I read that i can get GET parameters using Window.Location.getParameter . But I need to get POST parameter from request. How to implement it?
"get" in getParameter() means "retrieve", it's the standard Java naming convention for getters; it has nothing to do with the HTTP request method.
I am trying to fix a bug in sitebricks where it consumes the input stream in of the data of all servlets even those not using site bricks.
HiddenMethodFilter.java line:66
String methodName = httpRequest.getParameter(this.hiddenFieldName);
See http://code.google.com/p/google-sitebricks/issues/detail?id=45
Yes you can provide your own request, see Modify request parameter with servlet filter.
Furthermore may be extending the wrong sitebricks filter might be easier than chaining.
Obivously not, since the servlet container is required to read and consume the data in the InputStream before it is able to give you the request parameters. The other way around if you consume the InputStream first, the container won't have access to the request parameters later.
Why can't you fix the bug using the suggestion in the linked issue suggesting to configure the HiddenMethodFilter only for the URLs related to Site Bricks?