Sling request.getParameter() ommitting values | Community
Skip to main content
Level 4
Jul 27, 2023 10:39 AM UTC
Solved

Sling request.getParameter() ommitting values

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Ekhlaque
EkhlaqueAccepted solution
Employee
Jul 27, 2023 11:37 AM UTC

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
}
}

 

4 replies

Ekhlaque
EkhlaqueAccepted solution
Employee
Jul 27, 2023 11:37 AM UTC

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
}
}

 

Translate
nitesh_kumar-1
Employee
Jul 27, 2023 11:02 AM UTC

Hi @goyalkritika ,

 

'+' is a special character and needs to be URL encoded. See https://www.urlencoder.io/learn/.

 

Hope that helps!

 

Regards,

Nitesh

Translate
Peter_Puzanovs
New Participant
Jul 27, 2023 10:56 AM UTC

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

Translate
Level 4
Jul 27, 2023 10:58 AM UTC

The value is an encoded value. Is this even possible to exclude certain characters from encoding?

Translate