从 RPG 调用 iSeries 上的远程 Java 程序

发布于 2024-08-02 11:21:37 字数 335 浏览 5 评论 0原文

我正在寻找从在 Iseries V5r4 上运行的 RPG 调用 Java 程序。远程程序是一个 Web 服务客户端(执行邮政编码查找),在 Websphere 中运行。

理想情况下我想直接从 RPG 中调用它?这可能吗?或者我是否必须创建一个java程序来在iSeries上运行并使用RMI或其他东西来调用远程java程序。

我们不热衷于直接调用外部 Web 服务,因为这意味着打开从其他世界直接到 iSeries 的路径。

我不是 RPG 程序员,只是在寻找一些东西来为我们的人员指明正确的方向,或者寻找任何我需要启用的东西来使 java 程序更适合 RPG 人员使用。

谢谢, 斯科特

I'm looking to invoke a Java program from RPG running on Iseries V5r4. The remote program is a web service client (performing a postcode lookup), running in Websphere.

Ideally I'd like to call it direct from RPG? is that possible? or do I have to create a java program to run on the iSeries and use RMI or something to call the remote java program.

We aren't keen on calling the extenral webservice direct as it means opening path from otherside world direct to iSeries.

I'm not an RPG programmer, just looking for something to point our guys in the right direction or anything I need to enable to make the java programs more consumable for the RPG folks.

Thanks,
Scott

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

残龙傲雪 2024-08-09 11:21:37

由于该程序运行在远程服务器上,因此您无法直接从 RPG 中调用它。鉴于它是一个 Web 服务,我将创建一个在 iSeries 上运行的 Java 程序,并从 RPG 中调用该 Java 程序。如今,RPG 可以直接与 Java 交互。您必须创建一些 D 规范来声明方法调用的类和原型。在以下示例中,假设“tools”包中存在一个名为 ServiceCaller 的 Java 类。它有一个名为 getServiceReply 的方法,该方法接受三个字符字段并返回一个整数。

 *Define the Java class locally.                                       
DServiceCaller    S               O   CLASS(*JAVA:'tools.ServiceCaller')

 *Class constructor.  No parameters.                                   
DnewServiceCaller PR              O   EXTPROC(*JAVA:                   
D                                       'tools.ServiceCaller':          
D                                       *CONSTRUCTOR)                  
D                                     CLASS(*JAVA:'tools.ServiceCaller')

 *GetServiceReply.
 *public int getServiceReply(byte[] parm1, byte[] parm2, byte[] parm3)
DgetServiceReply  PR            10I 0 EXTPROC(*JAVA:
D                                       'tools.ServiceCaller':
D                                       'getServiceReply')
D Parm1                        400A   CONST
D Parm2                        400A   CONST
D Parm3                        400A   CONST

您的 RPG 计算规范将类似于以下自由格式示例:

/free
  ServiceCaller = newServiceCaller();
  iReply = getServiceReply(ServiceCaller:'Parm1':'Parm2':'Parm3');
/end-free

在 java 代码内,在 getServiceReply 方法内,将这些字节数组转换为如下字符串:

sParm1 = new String(parm1);
sParm2 = new String(parm2);
sParm3 = new String(parm3);

当然,这是一个过于简化的示例,您的应用程序需求将略有不同。您需要添加错误处理代码,以防 Web 服务不响应。您可能还想在类中使用 getter 和 setter。这完全取决于您的应用程序需求和远程 Web 服务的要求。

关于 RPG 类型到 Java 类型的一些注释:

RPG Type      Java Type
10I 0         int
 3I 0         byte
 5I 0         short
20I 0         long
  N           boolean
  A           byte[]

如果您感觉特别雄心勃勃,您可以从 RPG 中调用本机 Java HTTP 类。但我发现专门为与 RPG 交互而编写的自定义 Java 程序充当中间人是一种更简单的方法。虽然 RPG 可以与 Java 对话,但它并不像 Java 与 Java 对话那么漂亮。

有关从 RPG 调用 Java 的更多信息,请参阅 ILE RPG 程序员指南。 V5R4 版本可以在这里找到: http://publib .boulder.ibm.com/infocenter/iseries/v5r4/topic/books/sc092507.pdf

Since the program is running on a remote server, you can't call it directly from RPG. Given that it's a web service, I would create a Java program to run on the iSeries and call that Java program from within RPG. Nowaday's, RPG can interface directly with Java. You have to create some D-specs to declare the class and prototype out the method calls. In the following example, assume a Java class exists called ServiceCaller in the package 'tools'. It has a single method called getServiceReply which accepts three character fields and returns an integer.

 *Define the Java class locally.                                       
DServiceCaller    S               O   CLASS(*JAVA:'tools.ServiceCaller')

 *Class constructor.  No parameters.                                   
DnewServiceCaller PR              O   EXTPROC(*JAVA:                   
D                                       'tools.ServiceCaller':          
D                                       *CONSTRUCTOR)                  
D                                     CLASS(*JAVA:'tools.ServiceCaller')

 *GetServiceReply.
 *public int getServiceReply(byte[] parm1, byte[] parm2, byte[] parm3)
DgetServiceReply  PR            10I 0 EXTPROC(*JAVA:
D                                       'tools.ServiceCaller':
D                                       'getServiceReply')
D Parm1                        400A   CONST
D Parm2                        400A   CONST
D Parm3                        400A   CONST

Your RPG calc specs will look something like this free-form example:

/free
  ServiceCaller = newServiceCaller();
  iReply = getServiceReply(ServiceCaller:'Parm1':'Parm2':'Parm3');
/end-free

Inside the java code, within the getServiceReply method, convert those byte arrays to strings like this:

sParm1 = new String(parm1);
sParm2 = new String(parm2);
sParm3 = new String(parm3);

Granted, this is an oversimplified example and your application needs will be slightly different. You will want to add error handling code in case the web service doesn't reply. You may also want to use getters and setters in your class. It all depends on your application needs and the requirements of the remote web service.

Some notes on RPG types to Java types:

RPG Type      Java Type
10I 0         int
 3I 0         byte
 5I 0         short
20I 0         long
  N           boolean
  A           byte[]

If you are feeling particularly ambitious, you can call the native Java HTTP classes from within your RPG. But I've found that a custom Java program to act as an in-between that is written specifically to talk to RPG is an easier way to go. Although RPG can talk to Java, it's not as pretty as Java talking to Java.

Additional information on calling Java from RPG can be found in the ILE RPG Programmer's guide. The V5R4 version can be found here: http://publib.boulder.ibm.com/infocenter/iseries/v5r4/topic/books/sc092507.pdf

烛影斜 2024-08-09 11:21:37

由于它是一个 Web 服务,另一个解决方案是使用 Scott Klement 的 HTTP API。您可以在他的网站 http://www.scottklement.com/httpapi/ 上找到它。

对我来说最大的好处之一是这完全是 RPG,并且不使用任何有时会有点迟缓的 Java。我不太熟悉 Web 服务在 Java 中的工作方式,但看来您不必形成所有 XML,它已经为您完成了。使用 HTTP API,您需要自己完成此操作。

斯科特·克莱门特 (Scott Klement) 在他的网站上还有其他一些有用的东西。另一个提供一些简洁工具的网站是 http://www.think400.dk/downloads.htm

Since the is a web service, another solution would be to use Scott Klement's HTTP API. It's available on his website at http://www.scottklement.com/httpapi/.

One of the big benefits for me is this is entirely RPG and doesn't use any Java which can be a bit sluggish sometimes. I'm not real familiar with how web services work in Java but it appears that you don't have to form all of the XML and it's done for you. With the HTTP API you would need to do that yourself.

Also Scott Klement has several other useful things on his website. Another site with some neat tools is http://www.think400.dk/downloads.htm.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文