I have working JBoss AS 7 (7.1.1 final) server on localhost with some queue.
And I want to connect to that queue in a desktop application.
So I wrote something like this:
Hashtable env = new Hashtable();
env.put(Context.PROVIDER_URL, "remote://localhost:4447");
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
InitialContext initialContext = new InitialContext(env);
ConnectionFactory connectionFactory = (ConnectionFactory)
initialContext.lookup("RemoteConnectionFactory"); // <- there is it fail
But it results in this exception:
Exception in thread "main" javax.naming.CommunicationException: Could not obtain connection to any of these urls: remote://localhost:4447 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to connect to server remote:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server remote:1099 [Root exception is java.net.UnknownHostException: remote]]]
Of course, I have jbosscall-client.jar in class path.
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
properties.put(Context.PROVIDER_URL, "remote://localhost:4447");
properties.put(Context.SECURITY_PRINCIPAL, "hlib");
properties.put(Context.SECURITY_CREDENTIALS, "password1");
InitialContext context = new InitialContext(properties);
ConnectionFactory factory = (ConnectionFactory) context.lookup("jms/RemoteConnectionFactory");
This code workl well if 'application user' for jboss have been added.