Expand my Community achievements bar.

SOLVED

Sling request.getParameter() ommitting values

Avatar

Level 5

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?

1 Accepted Solution

Avatar

Correct answer by
Employee

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

 

View solution in original post

4 Replies

Avatar

Community Advisor

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

Avatar

Level 5

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

Avatar

Employee Advisor

Hi @goyalkritika ,

 

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

 

Hope that helps!

 

Regards,

Nitesh

Avatar

Correct answer by
Employee

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