Oracle:Java 存储过程发送 JMS 消息 [英] Oracle: Java stored procedure sending JMS Message

查看:26
本文介绍了Oracle:Java 存储过程发送 JMS 消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 oracle 数据库存储过程向 java 应用程序发送点对点 JMS 消息.这两个点"位于不同的机器上,我已经确认它们可以通过 ping 相互通信.

I am attempting to send a Point-to-Point JMS message from an oracle database stored procedure to a java application. The two 'points' sit on different machines, which I've confirmed can talk to each other via ping.

我创建了一个 Java 应用程序,能够成功地从应用程序服务器中的队列中取出消息.该应用程序在 JBoss v4.2.3 服务器中运行.我已经能够成功地从远程 Java 应用程序发送 JMS 消息,所以我确信在服务器中运行的代码没有问题.

I've created a java application able to successfully take messages off a queue within the application server. The application is running within a JBoss v4.2.3 server. I've been able to successfully send a JMS message from a remote java application, so I'm sure the code running within the server is ok.

我从正在工作的远程 java 应用程序中获取了代码,并将其成功加载到 oracle 存储过程中.我还设法(我相信!)使用 loadjava 实用程序将所需的 jar 文件加载到 oracle 中.我加载的三个 jar 文件是:

I've taken code from the working remote java application and loaded this successfully into an oracle stored procedure. I've also managed to (I believe!) load into oracle the required jar files using the loadjava utility. The three jar files I've loaded in are:

   * jms-1.1 
   * jbossmq-3.2.3
   * jboss-client-4.0.2

这三个 jar 用于在工作的远程 java 应用程序中,并且似乎是所需的全部.加载到存储过程中包含的代码如下:

The three jars are used within the working remote java application and appear to be all that's required. The code contained loaded into the stored procedure is as follows:

    package com.base.jms.client;

    import java.util.Hashtable;

    import javax.jms.JMSException;
    import javax.jms.Queue;
    import javax.jms.QueueConnection;
    import javax.jms.QueueConnectionFactory;
    import javax.jms.QueueSender;
    import javax.jms.QueueSession;
    import javax.jms.TextMessage;
    import javax.naming.Context;
    import javax.naming.InitialContext;

    public class StandAloneClient {

        public static String send() throws Exception {

            String result = "Starting -> ";

            try {

                Hashtable env = new Hashtable();
                env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                env.put(Context.PROVIDER_URL, "192.168.111.242:1099");
                env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

                result = result + "Environment -> ";

                // set up stuff
                Context ic = new InitialContext(env);
                result = result + "Context -> ";

                QueueConnectionFactory connectionFactory = (QueueConnectionFactory) ic.lookup("ConnectionFactory");
                result = result + "Factory -> ";

                Queue queue = (Queue) ic.lookup("queue/A");
                result = result + "Queue -> ";

                QueueConnection connection = connectionFactory.createQueueConnection();
                result = result + "Connection -> ";

                QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
                result = result + "Session -> ";

                QueueSender sender = session.createSender(queue);
                connection.start();

                result = result + "Sender -> ";

                TextMessage myMessage = session.createTextMessage();
                myMessage.setText(result);
                sender.send(myMessage);

                result = result + "Sending Message -> ";

                sender.close();
                session.close();
                connection.close();

                result = result + "Close";

            } catch (JMSException e) {
                result = result + "JMS Exception";

                /*
                if(e.getMessage() != null) {
                    result = result + ":" + e.getMessage();
                }*/

            } catch (Exception e) {
                result = result + "Exception";

                /*
                if(e.getMessage() != null) {
                    result = result + ":" + e.getMessage();
                }*/

            }

            return result;
        }

    }

我已经添加了结果字符串,所以我可以尝试确定它在代码中的哪个位置摔倒.为了创建和测试这个过程,我在 sqlplus 中执行以下命令:

I've added the result string in so I can try and determine where in the code it's falling over. To create and test this procedure, I'm executing the following commands in sqlplus:

create or replace function send_jms return VARCHAR2 as language java name 'com.base.jms.client.StandAloneClient.send() return java.lang.String';

variable myString varchar2(20);
call send_jms() into :myString;
Call completed.
print myString;

一切似乎都已正确加载和编译,但消息并未发送.返回的结果字符串暗示它在尝试从 InitialContext 检索 QueueConnectionFactory 类时摔倒了.返回的结果字符串为:

Everything seems to be loaded and compiling correctly, however the message is not being sent. The result string returned implicates it's falling over when attempting to retrieve the QueueConnectionFactory class from the InitialContext. The result string returned is:

Starting -> Environment -> Context -> Exception

我不知道为什么这不起作用,并且无法从抛出的异常中收集更多信息.任何人都可以确认我这样做是正确的,如果我是,看看我做错了什么?

I'm at a loss as to why this is not working, and have been unable to glean more from the Exception thrown. Can anyone confirm that I am doing this correctly, and if I am, see what I am doing wrong?

对于长篇文章深表歉意,但提前感谢您的观看!

Apologies for the long post but thank you in advance for looking at it!

推荐答案

我并不是在 Oracle 数据库中运行 Java 和 JMS 的专家(尽管我分别了解这三个组件中的每一个).但是从您的描述来看,您似乎没有考虑 Java 的 Oracle 安全模型.

I'm not exactly an expert about running Java and JMS within the Oracle database (though I know each of the three components separately). But from your description it seems you haven't taken the Oracle security model for Java into consideration.

Oracle 不会让任何组件在没有明确授权的情况下访问网络(或文件系统等).所以开始阅读 Oracle JVM 安全性了解您可能需要如何配置 Oracle 以让您连接到远程机器.

Oracle will not let any component access the network (or the file system etc.) without having explicitly being granted the right to. So start reading about Oracle JVM security to learn how you might need to configure Oracle for letting you connect to a remote machine.

授予权限可能涉及以下语句:

Granting the permissions could involve the following statement:

EXEC DBMS_JAVA.GRANT_PERMISSION('YOUR_SCHEMA', 'SYS:java.net.SocketPermission', '192.168.111.242', 'connect,accept,resolve');

这篇关于Oracle:Java 存储过程发送 JMS 消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆