I am getting an alpha-numeric value as part of request.
For example -> If request has token=qoN3qSQ+KwL+uwbpzITSHDBRl3xuqM0AYx3CSkoSUU= as query param value, req.getParameter("token") gives us qoN3qSQ KwL uwbpzITSHDBRl3xuqM0AYx3CSkoSUU=
So, basically it is ommitting the '+' from the value. How to resolve this?
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @goyalkritika ,If the value is encoded value ,Here's an example of how you can encode the "token" parameter value before sending the request:
import java.net.URLEncoder; import java.nio.charset.StandardCharsets; public class YourClassName { public static void main(String[] args) { String tokenValue = "qoN3qSQ+KwL+uwbpzITSHDBRl3xuqM0AYx3CSkoSUU="; String encodedValue = URLEncoder.encode(tokenValue, StandardCharsets.UTF_8); System.out.println("Encoded Value: " + encodedValue); // Now you can use the encodedValue in your request URL, like: "token=" + encodedValue } }
Hi Goyal,
Ideally, ask upstream system to encode the url before passing it into AEM. We ended up actually excluding plus from our token's to accept only letters, numbers and dashes.
Given it's not possible, you can configure Apache to URL Rewrite any + into %20 before sending into Publishers.
Then we can unencode our URL.
Regards,
Peter
The value is an encoded value. Is this even possible to exclude certain characters from encoding?
Hi @goyalkritika ,
'+' is a special character and needs to be URL encoded. See https://www.urlencoder.io/learn/.
Hope that helps!
Regards,
Nitesh
Hi @goyalkritika ,If the value is encoded value ,Here's an example of how you can encode the "token" parameter value before sending the request:
import java.net.URLEncoder; import java.nio.charset.StandardCharsets; public class YourClassName { public static void main(String[] args) { String tokenValue = "qoN3qSQ+KwL+uwbpzITSHDBRl3xuqM0AYx3CSkoSUU="; String encodedValue = URLEncoder.encode(tokenValue, StandardCharsets.UTF_8); System.out.println("Encoded Value: " + encodedValue); // Now you can use the encodedValue in your request URL, like: "token=" + encodedValue } }
Views
Likes
Replies