props.put(Context.INITIAL_CONTEXT_FACTORY, connectionSettings.getInitialContextName());
Class simplePrincipalClass = Class.forName("org.jboss.security.SimplePrincipal");
Principal p = (Principal) simplePrincipalClass.getConstructor(String.class).newInstance(connectionSettings.getPrincipal());
SetPrincipalInfoAction.setPrincipalInfo(p,connectionSettings.getCredentials());
} catch (ClassNotFoundException e1) {
throw new ConnectionException("Secured connection not available with this version of JBoss " + e1.toString(),e1);
} catch (Exception e1) {
throw new ConnectionException("Unable to make secured connection to JBoss due to missing or unexpected security classes",e1);
}
}
} else {
props.put(Context.INITIAL_CONTEXT_FACTORY, connectionSettings.getInitialContextName());
}
props.put(Context.PROVIDER_URL, connectionSettings.getServerUrl());
try {
InitialContext context = new InitialContext(props);
return context;
} catch(NoInitialContextException e) {
// Try to be more helpful, indicating the reason we couldn't make the connection in this
// common case of missing libraries
if (e.getCause() instanceof ClassNotFoundException) {
throw new ConnectionException("Necessary classes not found for remote connection, check installation path configuration.",e.getCause());
}
throw e;
}
}