Sling request.getParameter() ommitting values | Community
Skip to main content
Level 4
July 27, 2023
Solved

Sling request.getParameter() ommitting values

  • July 27, 2023
  • 3 replies
  • 1445 views

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.
Best answer by Ekhlaque

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

 

3 replies

Peter_Puzanovs
Community Advisor
Community Advisor
July 27, 2023

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

Level 4
July 27, 2023

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

nitesh_kumar-1
Adobe Employee
Adobe Employee
July 27, 2023

Hi @goyalkritika ,

 

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

 

Hope that helps!

 

Regards,

Nitesh

Ekhlaque
Adobe Employee
EkhlaqueAdobe EmployeeAccepted solution
Adobe Employee
July 27, 2023

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