Pass /oauth/token parameters in body - java

Hii I have implemented spring-security-oauth2 in my application. Everything is working fine. But the request goes for token is GET and the parameters are added as Url param.
I want to make it Post request and pass param in Request body.
Is there anyway?

Related

POST Method with JAX-RS does not work correctly with postman tool

I have been testing my REST Service with the PostMan tool. It works fine when I am trying to hit the #POST method with content type application/x-www-form-urlencoded and set all the data in body as a x-www-form-urlencoded parameters.
But when I changed my service method so that it can accept form param only and then I tried to hit service through postman on setting all the parameter as from-data in request body. I am getting null value in form param in service.
postman attachment:
Setting form param
Setting Content type
Service Method

spring NonceExpiredException

I am using spring security 3.2.5. When i pass wrong or empty customer request parameter in the request, I get NonceExpiredException and returning me OK response. For other parameters my webservice is fine.
For example
http://localhost:8080/vtap/devices/?customer=&platform=Andriod
In above url customer parameter is empty. I am getting NonceExpiredException and returning empty OK response and request is not hitting webservice method. I am using spring restfull webservice.Instead of OK response I wanted 400 response.
you can always write a Filter for normalizing your URL and response back 400 as you wish to user before Spring Security Filter even get started ~

Forward to a servlet and set attribute

I'm working with servlets in java; I'm trying to forward from one servlet to another servlet.
I also want to pass an attribute to that other servlet.
When i want to forward to a JSP, it works fine. i do
request.setAttribute("attrName", attribute)
request.getRequestDispatcher("forward.jsp").forward(request, response);
But When I do the same with a servlet:
request.setAttribute("attrName", attribute)
request.getRequestDispatcher("TheServlet").forward(request, response);
My server freaks out and I get the following error:
javax.servlet.ServletRequestWrapper.isAsyncStarted(ServletRequestWrapper.java:395)
I know I can use the following line to redirect to a servlet:
response.sendRedirect("TheServlet");
But for some reason the set Attribute doesn't work when I redirect instead of forward.
redirect is a HTTP response sent to the browser requesting it to submit a new request to the specified URL. Since it results in issuing an entirely new request previous request attributes you set wont be available in the new request.
In terms of forwarding to a servlet, did you check your web.xml configuration. Is it setup so that the forwarded servlet is seeing forwarded requests ?
You could save the attribute to the session in the first servlet and access it from the second.
Use http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getSession()
Also you could pass the attribute value in the URL query string in the redirect. So your redirect URL would look like 'myRedirectUrl?attributeName=attributeValue'
Also additionally try using 'include' method rather than 'forward'.

How to determine a correct request method is executed in RESTful webservice?

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.

Get http request request parameter value

I am calling Restful web service via ajax call. On this page i have google recaptcha whose parameter passing via get httprequest parameter. In rest service, i am getting http request object via #Context but it's returning null for both parameter.
How to resolve this issue

Categories

Resources