javax.jms.ConnectionFactory仅在以根用户登录时连接



我以root身份在RHEL 6机器上执行以下代码,它运行完美。但是当我以较小权限的任何用户执行它时,我得到javax.naming.NamingException:连接到任何服务器失败。服务器tride: [remote://myserver::myport]。这似乎是一个权限问题,但我的程序访问的所有文件设置为777。

是什么导致了这种情况的发生?

更新显然它不解析主机名到ip地址,除非我是根。现在我使用ipaddress代替(我将使用Iputils稍后解析)。现在我得到以下错误:

javax.jms.JMSException: Failed to create session factory
        at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:587)
        at org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:107)
        at myclass.run(myclass.java:172)
        at java.lang.Thread.run(Thread.java:744)
Caused by: HornetQException[errorType=NOT_CONNECTED message=HQ119007: Cannot connect to server(s). Tried with all available servers.]
        at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:863)
        at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:583)
InitialContext context = null;
Properties properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
properties.setProperty("java.naming.provider.port", hostPort);
properties.setProperty("jboss.naming.client.ejb.context", "true");
properties.setProperty(Context.PROVIDER_URL, "remote://" + hostAddr + ":" + hostPort);
properties.setProperty("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
properties.setProperty("jboss.naming.client.remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "true");
properties.setProperty("jboss.naming.client.connect.options.org.xnio.Options.SSL_STARTTLS", "true");
properties.setProperty(Context.SECURITY_PRINCIPAL, userName);
properties.setProperty(Context.SECURITY_CREDENTIALS, userPass);
try
{
  context = new InitialContext(properties);
  ConnectionFactory cf = (ConnectionFactory) context.lookup(connectionFactory);
  Destination destination = (Destination) context.lookup(jMSTopicName);
  Connection conn = cf.createConnection(userName, userPass);
  Session sesh = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
  MessageConsumer consumer = sesh.createConsumer(destination, selector + selectorNum);
  consumer.setMessageListener(this);

您是否尝试在受限端口(如80)上托管主机?

最新更新