vendredi 26 juin 2015

NameNotFoundException doing JNDI lookup to remote EJB in production JBoss (works locally)

An application (e.g app.EAR) is deployed to a JBoss in my own machine and works fine. When I deploy it to a remote JBoss it is deployed, but when I try to access a functionality that needs a JNDI lookup to a remote EJB I get NameNotFoundException. So, it seems that it was unable to find the requested service. How come? If it works locally?

The dependency with the remote EJB interface is in the lib folder inside the EAR and of course is annotated with @Remote. The JBoss is exactly the same as the production one (I copied the whole JBoss from production to my machine to check if there is any configuration missing).

My lookup code is like this:

private Object lookup(String resourceName, String loginData) {
        if (isPropagateUserCredentials() && (loginData == null || loginData.trim().equals(""))) {
            throw new MyInfraConfigException("somemessage");
        }
        Properties envProperties = new Properties();
        envProperties.putAll(this.jndiProperties);
        if (loginData != null && !loginData.equals("")) {
            envProperties.put(Context.SECURITY_PRINCIPAL, loginData);           
            envProperties.remove(Context.SECURITY_CREDENTIALS);
        }
        Context context = null;
        try {
            context = new InitialContext(envProperties);
            return context.lookup(resourceName);            
        } catch (NameNotFoundException e){
            String message = "Resource "+resourceName+" not found.";
            LoggerFactory.getInstance(this.getClass().getName()).error(message, e);
            throw new com.mypackage.NameNotFoundException(message, e);
        } catch (NamingException e) {
            String message = "Failed to find resource with JNDI: "+e.getMessage();
            LoggerFactory.getInstance(this.getClass().getName()).error(message, e);
            throw new com.mypackage.NamingException(message, e);
        } finally{
            if(context!=null){
                try {
                    context.close();
                } catch (NamingException e) {
                    e.printStackTrace();
                }
            }
        }
    }

The resourceName is ExternalResource.

Any clues?

Aucun commentaire:

Enregistrer un commentaire