IllegalStateException when saving a data from rabbitmq queue to DB using JPA

46 Views Asked by At

Iam getting the below error for the piece of code pasted below.

The code receives a json string in the listener and successfully deserialises it but facing error when trying to save a new dto to database.

That new dto is built by using values from the rabbitmq message.

ERROR Caused by: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.

CODE SNIPPET

@RabbitListener(queues = "${userRegistrationQueueName}")
public void createMotorUserPersonResgistration(final String message) {

    log.info("Received message for user registration:" + message);

    UserRegRabbitRequest userRegRabbitRequest = ObjectConverter.jsonToObject(message, UserRegRabbitRequest.class);

    UserDto userDto = userRegRabbitRequest.getUser();
    String idTypeTt = new String();
    if (userDto.getUserIdentification().startsWith("1")) {
        idTypeTt = ApplicationConstants.NATIONAL_ID_TYPE;
    } else {
        idTypeTt = ApplicationConstants.IQAMA_ID_TYPE;
    }
    TxnMotorUserPersonDto txnMotorUserPersonDto = TxnMotorUserPersonDto.builder().userId(userDto.getPkId())
            .dobgDt(idTypeTt.equals(ApplicationConstants.IQAMA_ID_TYPE) ? userDto.getDateOfBirth() : null)
            .dobhDt(idTypeTt.equals(ApplicationConstants.NATIONAL_ID_TYPE) ? userDto.getDateOfBirth() : null)
            .idTypeTt(idTypeTt).idTt(userDto.getUserIdentification())
            .firstNameEnTt(ObjectUtil.getValueOrDefault(userDto.getFirstName(), ""))
            .genderTt(userDto.getGender())
            .lastNameEnTt(ObjectUtil.getValueOrDefault(userDto.getLastName(), ""))
            .secondNameEnTt(ObjectUtil.getValueOrDefault(userDto.getMiddleName(), ""))
            .build();
    txnMotorUserPersonService.save(txnMotorUserPersonDto);
}

Iam getting the below error for the piece of code pasted below.

The code receives a json string in the listener and successfully deserialises it but facing error when trying to save a new dto to database.

0

There are 0 best solutions below

Related Questions in ILLEGALSTATEEXCEPTION