Tenho uma classe chamada Application
que é um listener
, ela instancia objetos de ServidorRadius
onde o mesmo precisa acessar os repositórios que são injetados com CDI
, porém radiusRepository
está retornando null
.
Application
:
@ApplicationScoped
public class Application implements ServletContextListener {
@Inject
private Logger log;
@Inject
private RadiusRepository radiusRepository;
@Inject
private RadiusRegistration radiusRegistration;
private static List<Radius> radius;
private static List<ServidorRadius> servidor = new ArrayList<ServidorRadius>();
@Override
public void contextInitialized(ServletContextEvent sce) {
try{
radius = radiusRepository.findAllRadius();
for(Radius r : radius){
ServidorRadius radiusS = new ServidorRadius(r.getMetodoDeAutenticacao(), r.getAcctPort(), r.getAuthPort());
if(r.getStart())
radiusS.start(true, true);
servidor.add(radiusS);
}
} catch (NoResultException ne){
//
} catch (Exception e){
e.printStackTrace();
}
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
try{
for(ServidorRadius sr : servidor){
sr.stop();
}
} catch (Exception e){
e.printStackTrace();
}
}
public static void addServidorRadius(Radius radius){
servidor.add(new ServidorRadius(radius.getMetodoDeAutenticacao(), radius.getAcctPort(), radius.getAuthPort()));
}
public static void stopRadius(Radius radius){
try{
for(ServidorRadius sr : servidor){
if(sr.getAcctPort() == radius.getAcctPort() && sr.getAuthPort() == radius.getAuthPort())
sr.stop();
}
} catch (Exception e){
e.printStackTrace();
}
}
public static void startRadius(Radius radius){
try{
Boolean started = false;
for(ServidorRadius sr : servidor){
if(sr.getAcctPort() == radius.getAcctPort() && sr.getAuthPort() == radius.getAuthPort()){
sr.start(true, true);
started = true;
}
}
if(!started){
addServidorRadius(radius);
startRadius(radius);
}
} catch (Exception e){
e.printStackTrace();
}
}
}
ServidorRadius
:
public class ServidorRadius extends RadiusServer {
private MetodoDeAutenticacao metodoDeAutenticacao;
@Inject
private RadiusRepository radiusRepository;
@Inject
private LoginRepository loginRepository;
@Inject
private RadiusRegistration radiusRegistration;
private Login login;
private AccessRequest accessRequest;
private Concentrador concentrador;
public ServidorRadius(MetodoDeAutenticacao metodoDeAutenticacao, Integer acctPort, Integer authPort){
this.metodoDeAutenticacao = metodoDeAutenticacao;
this.setAcctPort(acctPort);
this.setAuthPort(authPort);
}
@Override
public String getSharedSecret(InetSocketAddress client) {
if(radiusRepository == null)
System.out.println("Is null");
try{
concentrador = radiusRepository.findConcentradorByIp(client.getAddress().getHostAddress());
if(concentrador.getIp().equals(client.getAddress().getHostAddress()))
return concentrador.getSenha();
} catch (NoResultException ne){
// TODO
} catch (Exception e){
//TODO
e.printStackTrace();
}
return null;
}
}
Output
18:46:21,741 INFO [stdout] (Radius Auth Listener) Is null
18:46:21,742 ERROR [stderr] (Radius Auth Listener) java.lang.NullPointerException
18:46:21,742 ERROR [stderr] (Radius Auth Listener) at com.authnet.util.ServidorRadius.getSharedSecret(ServidorRadius.java:60)
18:46:21,742 ERROR [stderr] (Radius Auth Listener) at org.tinyradius.util.RadiusServer.listen(RadiusServer.java:332)
18:46:21,742 ERROR [stderr] (Radius Auth Listener) at org.tinyradius.util.RadiusServer.listenAuth(RadiusServer.java:289)
18:46:21,742 ERROR [stderr] (Radius Auth Listener) at org.tinyradius.util.RadiusServer$1.run(RadiusServer.java:108)
Acredito que o problema seja quando eu instancio o ServidorRadius
com o comando new
, mas não sei outra alternativa.