I am getting this exception
Character decoding failed. Parameter [updatedLocalInfo] with value
org.apache.tomcat.util.buf.UDecoder$DecodeException: isHexDigit
I am passing request post data as JSON string and one of the values contains'%'
Because of this '%' i am getting this exception.
I am not able to figure out why this exception is Coming and how to fix it.
For information, The json which i am passing is
[{"taxInformation":"Applicable Taxes Extra","happyHourDesc":"40% off","happyHourTime":"4 to 8 PM","offer":"No Offers"}]
I am passing request post data as JSON string
My guess would be you're passing the JSON string without properly encoding it. When you send information from the client to the server via HTTP GET or POST, the information must be properly encoded. The most common way to do that is via URL encoding (even if it's POST data).
You haven't said how you're sending the data, but it sounds like you probably need to use encodeURIComponent at some stage during the generation of the data you're sending from the client to the server.
Related
I want to hit a URL which contains data, i want to retreive this data using spring boot and convert it to AVRO format. data needs to be picked up in JSON format
data and url in one sentence raises alarm. Unless you have a particular need (usually legacy reasons) to use URL to send data, use requestbody for sending the data.
Remember, many browsers will have URL character limit even though http protocol doesn't talk about any
If you are adamant about sending Jsondata using url, either look into base64encode it and send and then base64decode it on serverside.
Or do URL encoding and Decoding . Because there is a highchance that the data might not be URL-safe
In restfull WS, how to tell client to send only csv and text format file.
In content-type header, client set the format in which it is sending request and in Accept header, client set the format in which it want to accept response.
But how to tell client to send only content-type csv or file ? Is this through some documentation ?
The 415 status code seems to be suitable for this situation:
6.5.13. 415 Unsupported Media Type
The 415 (Unsupported Media Type) status code indicates that the
origin server is refusing to service the request because the payload
is in a format not supported by this method on the target resource.
The format problem might be due to the request's indicated
Content-Type or Content-Encoding, or as a result of inspecting the
data directly.
The response payload could contain a list of the media types supported by the server.
Image you have an endpoint called /textfiles - the developer using your API is usually reading your documentation on how to implement this endpoint. Unless you're not doing some auto-discovery magic (which I guess is still not common).
If we take Facebook for example, they just state in their documentation which files you can send:
We accept the following files: 3g2, 3gp, 3gpp, [...]
Your question:
But how to tell client to send only content-type csv or file ?
is also a bit unclear. When the user has sent the request, he already attached the files he thought he could send. So here you would rather send an error with a message, which files are allowed. So are we talking about some "pre"-requests here?
From a backend developers point of view I can just tell you: It's in the documentation. Handle errors properly, document and your implementing developer will not hate you :)
if i develop a restful application using spring i would set the produces attribute to return csv or plain text ( https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestMapping.html) . if the client tries to request a resource other than csv or text it will recieve an error . probably 415
I have to send some parameters for making body for requesting to the server.
like this:
"UserName":"a.m",
"CityId":"1",
"UserCategories":
[
{"CategoryId":"ab2d948a-59d1-420d-a29b-8fd88c2d637c"},
{"CategoryId":"237b6334-3c1f-44ac-bd87-a8e6be0b2144"}
]
I don't know how can I send UserCategories as an array.because it is not String that I can send it like other parameters for making body.
I should have the body like this for getting response:
body: {"CityId":"1","UserName":"a.m","UserCategories":[{"UserCategories":"4211f3f4-f506-4458-b96a-0b496515e019"},{"UserCategories":"df7487b3-2043-46ec-97d4-790bfbe83cfc"}]}
but now my body is:
body: {"CityId":"1","UserName":"a.m","UserCategories":"[{"UserCategories":"4211f3f4-f506-4458-b96a-0b496515e019"},{"UserCategories":"df7487b3-2043-46ec-97d4-790bfbe83cfc"}]"}
I'm really confused!
When you send or receive JSON data, it is always as a string. We might speak of JSON objects or JSON arrays, but they are really string representations of objects and arrays. You can send the data exactly as you have written here as long as you enclose the entire thing in {}. You can send just the array in string form if you wish, exactly as you typed it here. The sender should create a string from the array and the receiver should parse the JSON string into an array. There are many libraries available to help you do this in every language.
your existing UserCategories object is List/Array format after that changed in String format so only its happen
"UserCategories":"[
{"UserCategories":"4211f3f4-f506-4458-b96a-0b496515e019"},
{"UserCategories":"df7487b3-2043-46ec-97d4-790bfbe83cfc"}]"
this is your second-time Json, Here see your List sent with ""
like "UserCategories":"[]"
Yes. You can do that by using retrofit library. You can sent object,arraylist using Retrofit.
https://futurestud.io/tutorials/retrofit-send-objects-in-request-body.Check this url to sent Object. You can also sent arraylist under Object In body
I'm using JMeter to do some load tests on my JSF application and I'm having trouble passing the ViewState along the pages. The ViewState variable doesn't get extracted at all or it doesn't get passed along the pages.
I've recorded my test steps with a proxy server and this is what it looks like:
I've added the Regex extractor in the first GET request. Tested the regex and it is correct.
In every POST request I replace the hardwired View IDs with my variable.
And what I get when I send the request is the following:
The POST parameters are incorrect, as it sends the name of the variable.
POST data:
loginForm%3ArequestToken=&loginForm%3Ausername=heller&loginForm%3Apassword=%21QAYxsw2%A7EDC&loginForm%3AloginButton=Anmelden&com.sun.faces.VIEW=%24%7BjsfViewState%7D&loginForm=loginForm
Could you tell what I'm doing wrong here?
Thanks!
The ViewState parameter is an encoded value (Base64 I believe?) and may contain values that would be inappropriate if passed in a GET request through the url. URL parameters are typically encoded so that special values (Eg. space -> %20) can be represented and decoded when the request reaches the server.
The issue here is that the following request is a POST meaning that the parameters do not need to be URL encoded.
com.sun.faces.VIEW=%24%7BjsfViewState%7D&loginForm=loginForm
The above shows that JMeter or some other process is URL encoding the ViewState in the request which is incorrect. The value of the ViewState should simply be sent as is.
Found my problem: the regex was wrong, so it couldn't find anything in the response. I had to change the regex. Noticed it after adding a default value "NOT FOUND".
I have two servlet: first servlet is similar to a client and creates an HttpURLConnection to call the second servlet.
I would like send a special error, formatted like a JSON object, so I call sendError method in this way:
response.sendError(code, "{json-object}")
But in the first servlet when I read error with getResponseMessage method I just get standard HTTP message and not my json object as a string.
How I can get my json string?
From the HttpServletResponse#sendError() javadoc:
The server defaults to creating the response to look like an HTML-formatted server error page containing the specified message, setting the content type to "text/html", leaving cookies and other headers unmodified. If an error-page declaration has been made for the web application corresponding to the status code passed in, it will be served back in preference to the suggested msg parameter.
So with this approach you have no other option than extracting the message from the HTML response yourself. JSoup may however be useful in this.
To achieve what you want, you need to set the error code and write the response yourself, e.g.
response.setStatus(code);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(json);
Instead of code you could by the way also use one of the HttpServletResponse.SC_XXX constants for this.