Java Web 服务和 BPEL
我在尝试使用这个网络服务时遇到了一些困难(它与作业相关,但不是实际的作业)。这个 BPEL 流程似乎提供了异步回调,我只是不确定到底如何使用它。 wsimport 生成了以下类:
> AttributedQName.java
> AttributedURI.java
> EndpointReferenceType.java
> N6368808CreditFlow.java
> N6368808CreditFlowCallback.java
> N6368808CreditFlowCallbackService.java
> N6368808CreditFlowProcessRequest.java
> N6368808CreditFlowProcessResponse.java
> N6368808CreditFlow_Service.java
> ObjectFactory.java
> ReferencePropertiesType.java
> Relationship.java ServiceNameType.java
> package-info.java
N6368808CreditFlow.java 是具有启动方法的接口,我假设信用方法是因为它是唯一可用的方法,它接受请求作为参数。而 N6368808CreditFlowCallback.java 包含一个 onResult 方法,该方法将 Response 作为参数。
如何使用这项服务?我已经能够调用该方法,但没有收到发回的响应(不知道如何获得响应,因为 onResult 方法不执行任何操作,并且启动方法返回 void(甚至没有回调或响应))。
到目前为止,这是我的代码:
N6368808CreditFlow_Service service1 = new N6368808CreditFlow_Service();
N6368808CreditFlow port = service1.getN6368808CreditFlowPort();
N6368808CreditFlowProcessRequest rqt = new N6368808CreditFlowProcessRequest();
rqt.setSsn("123456789");
port.initiate(rqt);
System.out.println("Done");
根据 BPEL 控制台,哪个代码可以工作,并且给出“123456789”,我的问题是如何获得响应?
以下是 BPEL 源代码的片段:
<sequence name="main">
<!--
Receive input from requestor. (Note: This maps to operation defined in n6368808_CreditFlow.wsdl)
-->
<receive name="receiveInput" partnerLink="client" portType="client:n6368808_CreditFlow" operation="initiate" variable="inputVariable" createInstance="yes"/>
<!--
Asynchronous callback to the requester. (Note: the callback location and correlation id is transparently handled using WS-addressing.)
-->
- <scope name="getCreditRating">
- <sequence name="Sequence_1">
- <assign name="assign_SSN">
- <copy>
<from variable="inputVariable" part="payload" query="/client:n6368808_CreditFlowProcessRequest/client:ssn"/>
<to variable="invoke_CRS_process_InputVariable" part="payload" query="/ns1:ssn"/>
</copy>
</assign>
<invoke name="invoke_CRS" partnerLink="CreditRatingService" portType="ns1:CreditRatingService" operation="process" inputVariable="invoke_CRS_process_InputVariable" outputVariable="invoke_CRS_process_OutputVariable"/>
- <assign name="return_SSN">
- <copy>
<from variable="invoke_CRS_process_OutputVariable" part="payload" query="/ns1:rating"/>
<to variable="outputVariable" part="payload" query="/client:n6368808_CreditFlowProcessResponse/client:creditRating"/>
</copy>
</assign>
</sequence>
</scope>
<invoke name="callbackClient" partnerLink="client" portType="client:n6368808_CreditFlowCallback" operation="onResult" inputVariable="outputVariable"/>
</sequence>
</process>
I'm struggling a little attempting to consume this web service (it is homework related but not actual homework). This BPEL process seems to provide asynchronous callbacks, I'm just not sure exactly how it is to be used.
The wsimport generated the classes below:
> AttributedQName.java
> AttributedURI.java
> EndpointReferenceType.java
> N6368808CreditFlow.java
> N6368808CreditFlowCallback.java
> N6368808CreditFlowCallbackService.java
> N6368808CreditFlowProcessRequest.java
> N6368808CreditFlowProcessResponse.java
> N6368808CreditFlow_Service.java
> ObjectFactory.java
> ReferencePropertiesType.java
> Relationship.java ServiceNameType.java
> package-info.java
The N6368808CreditFlow.java is the interface with the initiate method which is I assume the credit method as it is the only method available, it takes a request as a parameter. Whereas the N6368808CreditFlowCallback.java contains an onResult method which takes a Response as a parameter.
How does one consume this service? I've been able to call the method but not get a response sent back (not sure how to get a response as the onResult method doesn't do anything and the initiate method returns void (not even a callback or response)).
Here is my code so far:
N6368808CreditFlow_Service service1 = new N6368808CreditFlow_Service();
N6368808CreditFlow port = service1.getN6368808CreditFlowPort();
N6368808CreditFlowProcessRequest rqt = new N6368808CreditFlowProcessRequest();
rqt.setSsn("123456789");
port.initiate(rqt);
System.out.println("Done");
Which according to the BPEL console works and it is given "123456789", my question is how do you get the response?
Here is a snippet from the BPEL source:
<sequence name="main">
<!--
Receive input from requestor. (Note: This maps to operation defined in n6368808_CreditFlow.wsdl)
-->
<receive name="receiveInput" partnerLink="client" portType="client:n6368808_CreditFlow" operation="initiate" variable="inputVariable" createInstance="yes"/>
<!--
Asynchronous callback to the requester. (Note: the callback location and correlation id is transparently handled using WS-addressing.)
-->
- <scope name="getCreditRating">
- <sequence name="Sequence_1">
- <assign name="assign_SSN">
- <copy>
<from variable="inputVariable" part="payload" query="/client:n6368808_CreditFlowProcessRequest/client:ssn"/>
<to variable="invoke_CRS_process_InputVariable" part="payload" query="/ns1:ssn"/>
</copy>
</assign>
<invoke name="invoke_CRS" partnerLink="CreditRatingService" portType="ns1:CreditRatingService" operation="process" inputVariable="invoke_CRS_process_InputVariable" outputVariable="invoke_CRS_process_OutputVariable"/>
- <assign name="return_SSN">
- <copy>
<from variable="invoke_CRS_process_OutputVariable" part="payload" query="/ns1:rating"/>
<to variable="outputVariable" part="payload" query="/client:n6368808_CreditFlowProcessResponse/client:creditRating"/>
</copy>
</assign>
</sequence>
</scope>
<invoke name="callbackClient" partnerLink="client" portType="client:n6368808_CreditFlowCallback" operation="onResult" inputVariable="outputVariable"/>
</sequence>
</process>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 BPEL 流程确实是异步的,流程实例在接收活动使用消息时启动,响应通过调用活动发送。为了接收响应,您的 Java 客户端需要打开一个实现 client:n6368808_CreditFlowCallback 端口类型的 Web 服务端点。 BPEL 引擎如何确定回调的端点地址是引擎特定的。理论上,合作伙伴链路的合作伙伴角色通过接收到的消息进行初始化(即该消息需要传送回调EPR)。然而,这取决于您的 BPEL 引擎是否以及如何实现合作伙伴角色的初始化。
通常我建议使用异步流程建模范例,因为它始终支持长时间运行的流程。然而,如果您使用异步传输协议(如 JMS)或者绝对确定所调用的 Web 服务运行时间不足(即整个处理时间不太可能比 HTTP 连接超时时间更长),您可以考虑对流程进行同步建模,通过用回复替换调用(与接收相同的合作伙伴链接、端口类型和操作)。如果有疑问,请坚持使用异步模型。
Your BPEL process is indeed asynchronous, the process instance is started when a message is consumed by the receive activity, the response is sent via an invoke activity. In order to receive the response, your Java client needs to open a Web service endpoint which implements the client:n6368808_CreditFlowCallback port type. How the BPEL engine determines the callback's endpoint address is engine specific. Theoretically, the partner link's partner role gets initialized with the received message (i.e. the message needs to communicate the callback EPR). However it depends if and how your BPEL engine implements the initialization of partner roles.
Usually I recommend using the asynchronous process modeling paradigm, as it always supports for long-running processes. If you however use an asynchronous transport protocol (like JMS) or are absolutely sure that the called Web services is running short (i.e. it is unlikely that the whole processing takes longer than an HTTP connection timeout), you may consider modeling the process synchronous, by replacing the invoke with a reply (to the same partnerlink, porttype and operation as the receive). If in doubt, stick to the async model.