1

异常堆栈跟踪并没有提供太多信息,只是

javax.naming.OperationNoSupportedException

public static Connection getConnection(Context ctx, String factoryName) throws JMSException, NamingException {
    Object objfac = null;
    try {
        objfac = ctx.lookup(factoryName);
    } catch (NoClassDefFoundError e) {
        throw new NamingException("Lookup failed: "+e.toString());
    }
    if (objfac instanceof javax.jms.ConnectionFactory) {
        @SuppressWarnings("unchecked") // The environment is supposed to use String keys only
        Map<String, Object> env = (Map<String, Object>)ctx.getEnvironment();
        if(env.containsKey(Context.SECURITY_PRINCIPAL)) {
            String username = (String)env.get(Context.SECURITY_PRINCIPAL);
            String password = (String)env.get(Context.SECURITY_CREDENTIALS);
            return ((javax.jms.ConnectionFactory) objfac).createConnection(username, password);                
        }
        else {
            return ((javax.jms.ConnectionFactory) objfac).createConnection();
        }
    }
    throw new NamingException("Expected javax.jms.ConnectionFactory, found "+(objfac != null ? objfac.getClass().getName(): "null"));
}

堆栈跟踪是:

在 javax.naming.InitialContext.getEnvironment(InitialContext.java:544) 在 javax.naming.InitialContext.getEnvironment(InitialContext. java:544) 在 org.apache.jmeter.protocol.jms.Utils.getConnection(Utils.java:155) 在 org.apache.jmeter.protocol.jms.client.Publisher.(Publisher.java:130) 在 org. org.apache.jmeter.protocol.jms.sampler.PublisherSampler.sample(PublisherSampler.java:154) 在 org.apache.jmeter 的 apache.jmeter.protocol.jms.sampler.PublisherSampler.initClient(PublisherSampler.java:135)。 org.apache.jmeter.threads.JMeterThread 上的协议.jms.sampler.BaseJMSSampler.sample(BaseJMSSampler.java:80)。process_sampler(JMeterThread.java:429) at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:257) at java.lang.Thread.run(Thread.java:722)

4

1 回答 1

4

您使用的 JNDI 实现不支持该getEnvironment方法,这意味着该代码无法访问用于访问 JMS 服务器的任何凭据。这是我的修复尝试(如果不需要凭据,这可能仅适用于您的情况,我不确定):

if (objfac instanceof javax.jms.ConnectionFactory) {
    @SuppressWarnings("unchecked") // The environment is supposed to use String keys only
    Map<String, Object> env = null;
    try {
       env = (Map<String, Object>)ctx.getEnvironment();
    } catch (javax.naming.OperationNotSupportedException ex) {}
    if(env != null && env.containsKey(Context.SECURITY_PRINCIPAL)) {
        String username = (String)env.get(Context.SECURITY_PRINCIPAL);
        String password = (String)env.get(Context.SECURITY_CREDENTIALS);
        return ((javax.jms.ConnectionFactory) objfac).createConnection(username, password);                
    }
    else {
        return ((javax.jms.ConnectionFactory) objfac).createConnection();
    }
}
于 2014-01-04T18:32:41.000 回答