Good morning, I am currently working with Quarkus and Apache Camel and I am using a variable from the application.properties in a processor, I try to bring it in using the @ConfigProperty annotation, but it is giving me a null error, this is how I have it configured:
The variable is called encryptionKey
UserProfileProcessorUserIdParamReq
@ApplicationScoped
@Slf4j
public class UserProfileProcessorUserIdParamReq implements Processor {
@ConfigProperty(name="aes.encrypt.key")
String encryptionKey;
private final IValidationFieldsUserID validationFields;
public UserProfileProcessorUserIdParamReq() {
validationFields = new ValidationFieldsUserID();
}
@Override
public void process(Exchange exchange) throws Exception {
String documentType;
String documentNumber;
String userId;
String correlatorId;
String tokenInfo;
String userIdDecodedBase64;
String userIdDecrypt;
try {
correlatorId= Optional.ofNullable(exchange.getIn().getHeader("x-correlator")).map(Object::toString).orElse("");
exchange.setProperty("correlatorId",correlatorId);
userId = exchange.getIn().getHeader("user_id").toString();
tokenInfo= Optional.ofNullable(exchange.getIn().getHeader("x-token-info")).map(Object::toString).orElse("");
validationFields.validateUserId(exchange);
userId=validateUserIdValue(userId, tokenInfo);
exchange.setProperty("userIdEncrypt", userId);
userIdDecodedBase64= EncodeBase64.decrypt(userId);
log.info("userIdDecodedBase64" + userIdDecodedBase64);
userIdDecrypt= EncryptUtil.decrypt(userIdDecodedBase64,encryptionKey);
exchange.setProperty("userId", userIdDecrypt);
validateTokenInfo(exchange,userId, tokenInfo);
validateUserIdDecrypt(userIdDecrypt);
documentType = userIdDecrypt.split("-")[0];
documentNumber = userIdDecrypt.split("-")[1];
exchange.setProperty("documentType", documentType);
exchange.setProperty("documentNumber", documentNumber);
exchange.setProperty("isSearchByQueryParam","false");
} catch (RequiredValueException | NullPointerException e) {
throw new RequiredValueException(e.getMessage());
}
catch (NotFoundDataException e) {
throw new NotFoundDataException(e.getMessage());
}
catch (PermissionDeniedException e) {
throw new PermissionDeniedException(e.getMessage());
}
catch (Exception e){
if( e.getMessage().contains("Input byte array"))
throw new NotFoundDataException(e.getMessage());
throw new Exception(e.getMessage());
}
}
private static void validateTokenInfo(Exchange exchange, String userId, String tokenInfoValidated) {
if (!tokenInfoValidated.isEmpty()) {
log.info("Valor del x-token-info: {}", tokenInfoValidated);
/* Se obtiene el Objeto JSON con el valor del campo x-token-info */
JSONObject jsonObject = new JSONObject(tokenInfoValidated);
/*String subValue=jsonObject.get("sub").toString(); */
/* Mediante el optString obtenemos el valor sub si viene (token 3 patas) o no viene (token 2 patas), para este ultimo caso el valor es vacio */
String subValue = jsonObject.optString("sub");
log.info("Valor sub que esta llegando en el valor x-token-info: {}", subValue);
if (!subValue.isEmpty()) {
if(!subValue.equals(userId)) {
throw new PermissionDeniedException("Error validando el campo sub de la autenticacion en el campo x-token-info, no hace match con userId enviado");
}
}
}
}
/* Se valida que el UserId sea un valor valido para venezuela, sea enviado cifrado o no*/
private static void validateUserIdDecrypt (String userId) {
if(!Pattern.matches("^(CI|RIF|P|CD|NIT)(-).*",userId)){
throw new NotFoundDataException("UserId enviado esta en formato incorrecto");
}
}
/*Se valida el valor del campo UserId, si el mismo pudiera contener el valor de me, en este caso se debe extraer el valor de UserId del json token-info, en especifico del campo sub */
private String validateUserIdValue(String userId,String tokenInfo) {
if(userId.equals("me")){
if(!tokenInfo.isEmpty()){
JSONObject jsonObject = new JSONObject(tokenInfo);
userId = jsonObject.optString("sub");
}
else {
throw new RequiredValueException("Se requiere parametro x-token-info (autenticacion 3 patas) para campo userId=me");
}
}
return userId;
}
}
And this is the error it gives:
14:52:44 INFO traceId=2a0a8e8cd93ddb947e2ab7206ef4f25d, parentId=, spanId=394c6d08dec8d551, sampled=true [route23] (vert.x-worker-thread-0) [2024-07-01 14:52:44.0] Descripcion de la Exception: Cannot invoke "String.getBytes()" because "key" is null
This is how it is in my application.properties:
aes.encrypt.key=${AES_ENCRYPT_KEY:xxxxxxxxxxxx}
Like from ResRoute call to processor without constructor:
from("direct:usersQueryParam")
/*.removeHeaders("CamelHttp*") */
.doTry()
.process(new UserProfileProcessorQueryParamReq())
.choice()
/* code */
How can I do here so that it takes the value of the @ConfigProperty?