1

我正在使用 sun-jms-adapter.rar。在开始使用身份验证之前,我的所有配置都可以正常工作。我还尝试从独立应用程序和无状态 bean 访问队列(这用于将消息发送到队列),并且一切正常。

我的实际配置是:

weblogic-ds.xml

    <connection-factories>

    <!-- SUN JMS JCA Resource adapter, use this to get transacted JMS in beans -->
    <no-tx-connection-factory>
        <jndi-name>CFX/ExternalConnectionFactory</jndi-name>
        <xa-transaction />
        <rar-name>sun-jms-adapter.rar</rar-name>
        <connection-definition>javax.jms.QueueConnectionFactory</connection-definition>
        <config-property name="SessionDefaultType" type="java.lang.String">javax.jms.Queue</config-property>
        <config-property name="JmsProviderAdapterJNDI" type="java.lang.String">java:/DefaultJMSProvider</config-property>
        <config-property name="Destination" type="java.lang.String">javax.jms.Destination</config-property>
        <max-pool-size>20</max-pool-size>
        <depends>jboss.messaging:service=ServerPeer</depends>
    </no-tx-connection-factory>
</connection-factories>

ejb-jar.xml 配置:

    <enterprise-beans>
    <message-driven>
        <ejb-name>QueueReceiverMDB</ejb-name>
        <ejb-class>com.tests.mdb.QueueReceiverMDB</ejb-class>
        <transaction-type>Bean</transaction-type>
        <activation-config>
            <activation-config-property>
                <activation-config-property-name>destination</activation-config-property-name>
                <activation-config-property-value>${weblogic.jms.queue.in}</activation-config-property-value>
            </activation-config-property>
            <activation-config-property>
                <activation-config-property-name>destinationType</activation-config-property-name>
                <activation-config-property-value>javax.jms.Queue</activation-config-property-value>
            </activation-config-property>
            <activation-config-property>
                <activation-config-property-name>ConnectionURL</activation-config-property-name>
                <activation-config-property-value>${weblogic.jms.url}</activation-config-property-value>
            </activation-config-property>
            <activation-config-property>
                <activation-config-property-name>UserName</activation-config-property-name>
                <activation-config-property-value>${weblogic.jms.username}</activation-config-property-value>
            </activation-config-property>
            <activation-config-property>
                <activation-config-property-name>Password</activation-config-property-name>
                <activation-config-property-value>${weblogic.jms.password}</activation-config-property-value>
            </activation-config-property>
        </activation-config>
    </message-driven>
</enterprise-beans>

最后是我的 jboss.xml:

        <message-driven>
        <ejb-name>QueueReceiverMDB</ejb-name>
        <destination-jndi-name>java:/CFX/ExternalConnectionFactory</destination-jndi-name>
        <local-jndi-name>local/QueueReceiverMDB</local-jndi-name>
        <resource-adapter-name>sun-jms-adapter.rar</resource-adapter-name>
        <configuration-name>JMSJCA Message Driven Bean</configuration-name>
    </message-driven>

我总是收到这个错误:

16:25:07,126 警告 [激活] JMSJCA-E016:[sync-QueueReceiver(jms/TestJMSQueueIn) @ [t3://localhost:7001]]:消息传递启动失败(尝试 #1);将在 1 秒后重试。错误是:拒绝访问资源:type=,application=TestJMSModule,destinationType=queue,resource=TestJMSQueueIn,action=receive weblogic.jms.common.JMSSecurityException:拒绝访问资源:type=,application=TestJMSModule,destinationType=queue ,资源=TestJMSQueueIn,操作=在 weblogic.jms.dispatcher.DispatcherAdapter.dispatchSync(DispatcherAdapter.java:45) 的 weblogic.jms.dispatcher.DispatcherAdapter.convertToJMSExceptionAndThrow(DispatcherAdapter.java:110) 处接收 weblogic.jms.client.JMSSession .consumerCreate(JMSSession.java:2982) 在 weblogic.jms.client.JMSSession.setupConsumer(JMSSession.java:

欢迎任何建议...

4

1 回答 1

0

我找到了解决问题的方法,虽然不是最好的,但它确实有效。

在花了很多时间尝试让这个工作之后,我从这里检查了资源适配器的源代码(sun-jms-adapter.rar) ,发现了一个可能的错误。他们不会在创建会话后将凭据放入 initialContext 和关闭上下文中。所以我修改了这个步骤,将“Context.SECURITY_PRINCIPAL”和“Context.SECURITY_CREDENTIALS”添加到上下文中,并保持打开状态。这确实有效。所有这些都在 RAWLObjectFactory 类的 getJndiObject 方法中。

如果有人找到另一种方式和最佳方式,请分享......因为他们在创建队列连接时放置了凭据,所以可能是 weblogic 源的错误。

我留下修改后的代码:

private Object getJndiObject(UrlParser url, String name, String username, String password) throws JMSException {

    if (sLog.isDebugEnabled()) {
        sLog.debug("Looking up JNDI object " + name);
    }

    if (name == null || name.length() == 0) {
        throw Exc.jmsExc(LOCALE.x("E401: The JNDI name is null"));
    }

    InitialContext ctx = null;
    try {
        if (mSpecialISORBMethod != null) {
            // Works on IS only
            if (mSpecialISORBMethodIsOn != null) {
                Boolean isEnabled = (Boolean) mSpecialISORBMethodIsOn.invoke(null, new Object[0]);
                if (!isEnabled.booleanValue()) {
                    throw Exc.rsrcExc(LOCALE.x("E823: CORBA-SE needs to be enabled on" 
                        + " this server. Please change the value of the <se-orb enabled=\"false\"/>"
                        + " to <se-orb enabled=\"true\"/> in the configuration file of "
                        + " the Integration Server (logicalhost/is/domains/<domain-name>"
                        + "/config/domain.xml) and restart the server."));
                }
            }
            final Properties prop = (Properties) mSpecialISORBMethod.invoke(null, new Object[0]);
            prop.put(Context.URL_PKG_PREFIXES, JNDI_WEBLOGIC_PROTOCOL_PACKAGES);
            ctx = new InitialContext(prop);
            return ctx.lookup("corbaname:iiop:1.2@" + url.getHost() + ":" + url.getPort()
                + '#' + name); 
        } else {
            // Will be executed on other application servers than the IS

            //add username/password if not null to context
            Hashtable<String, String> env = new Hashtable<String, String>();
            env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
            env.put(Context.PROVIDER_URL, "t3://" + url.getHost() + ":" + url.getPort());
            if (username != null) {
                env.put(Context.SECURITY_PRINCIPAL, username);
                env.put(Context.SECURITY_CREDENTIALS, password);
            }
            ctx = new InitialContext(env);
            return ctx.lookup(name);
        }
    } catch (Exception e) {
        throw Exc.jmsExc(LOCALE.x("E821: Could not find JNDI object by name [{0}]: {1}", name, e), e);
    } 
    //leave context open
    /*finally {
        safeClose(ctx);
    }*/
}
于 2015-08-06T14:21:30.983 回答