We have a web service that one of its parameters is called source and this source is always validated against a code in the database.
For each of our services, I have to validate this code. This code does not change, so I want to keep it in a constant, but I still have to validate it to prevent clients from sending a wrong code.
Basically, what I want is the following:
@Service
public class Service {
@Autowired
private LogBS logBS;
// Eu sei que a palavra reservada "this" não pode ser utilizada em contexto estático.
public static final Long CODIGO_LOG_WEB_SERVICE = this.logBS.recuperarCodigoLogWebService("webServiceName");
public void validarCodigoOrigem(final Long origem) {
if (!origem.equals(CODIGO_LOG_WEB_SERVICE)) {
throw new ServiceException("Código de web service errado!");
}
}
}
I know something similar can be done with the Spring cache, but is it possible to do it with a constant?