last day (14 days later) » 

11:39 AM
1
A: Reading parameters from request body

EphiServletRequest (and by extension, HttpServletRequest) (1) objects have built-in support to get the parameters of the request. You can get a specific parameter by using : String paramValue = request.getParameter('parameterName'); The return type will always be String. Note that this method al...

 
requet.getParameter does not support to get parameters from request body. If we have parameters in request url we will be able to use that method. But we can't get any parameters from body by using above
I'm using POST here
Please point me the location of the documentation
I can searched for ServletRequest.getParameter() in the documentations you pointed. But 0 references
No Ephi. The documentation does not say like that. We can only read parameters using request.getParameter() if the parameters are sent as part of the URL. Otherwise we can't use above method. I just as you suggested. But I got null.
New code in the sense? I have the same code as in my original question. I just need to read the parameters from the request body. Seems we don't have a direct way to access this as we are getting raw data from the request body. tutorials.jenkov.com/java-servlets/httprequest.html
 
The site you linked says the exact contrary.
 
What do you mean?
 
If you just want to get en parameter value from your request, just don't call getInputStream() ; directly call getParameter() on the request, no need to read the request's body
 
But when doing that I get null as the result. Do you have any working sample?
 
11:39 AM
Not any that I could show you ; please edit your question and add the code you used to try getParameter() ; the whole code.
 
I have only that code. I don't have the access to the rest of the code. I don't need to read values from the request. But I need to read values from post request body. If I just get request. getParameterMap() it also shows null as my request url does not contain any parameters. Only my request body have the values.
 
If you don't have access to the code, what exactly are you trying to do and where ?
getParameter and other methods ARE used when treating POST requests
I need more information to help you
where does the request come from ? a HTML form ?
where do you treat the request ? a servlet ?
 
OK.. I have a remote client. And the client invokes my rest endpoint.
These are the request details
URL: https://204.93.35.235:9443/oauth2/token
2.726187 --> BODY: code=e441f1a6-96ac-3083-8831-511f9dff4782&client_secret=AtO0zxf62KoYasYTobOGRXVRZXsa&grant_type=authorization_code&client_id=4rYClwGnY4CE_XXAkMCoWuI4mnIa&redirect_uri=https%3A%2F%2Fop.certification.openid.net%3A60746%2Fauthz_cb
2.726197 --> HEADERS: {'Content-Type': 'application/x-www-form-urlencoded'}
43.989028 <-- STATUS: 200
As you can see in the URL the request does not have any parameters
Only the request body contains the parameters
 
That is not the point :)
So that is an HTTP POST request ?
 
yes
 
11:46 AM
Received by an HttpServlet ?
 
May be
I only have the rest endpoint
 
the code written in your question, you have access to it ?
 
yes
 
could you show me the file ?
 
It is part of my endpoint
file in the sense the endpoint?
 
11:49 AM
yup
 
@POST
@Path("/")
@Produces("application/json")
public Response issueAccessToken(@Context HttpServletRequest request,
MultivaluedMap<String, String> paramMap) throws OAuthSystemException {

try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext
.getThreadLocalCarbonContext();
carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);

HttpServletRequestWrapper httpRequest = new OAuthRequestWrapper(request, paramMap);
 
Lemme take a look
 
OK thanks
 
you can't use the paramMap ?
the method parameter
 
Ya.. I can directly use it. It contains all the values. I was just wondering whether we can use request parameter
 
11:59 AM
and normally calling getParameter on the request would work
the parameters must not always be in the url
Don't forget to remove all your comments to avoid pollution ;)
 
OK thanks a lot.
:)
 
So your problem is solved ? :)
 

last day (14 days later) »