简体   繁体   English

Java Web服务和BPEL

[英]Java Web Services and BPEL

I'm struggling a little attempting to consume this web service (it is homework related but not actual homework). 我正在努力尝试使用此Web服务(它是与作业相关的,而不是实际的作业)。 This BPEL process seems to provide asynchronous callbacks, I'm just not sure exactly how it is to be used. 该BPEL流程似乎提供了异步回调,但我不确定该如何使用它。 The wsimport generated the classes below: 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

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. N6368808CreditFlow.java是与initiate方法的接口,我假设该方法是credit方法,因为它是唯一可用的方法,它以请求为参数。 Whereas the N6368808CreditFlowCallback.java contains an onResult method which takes a Response as a parameter. N6368808CreditFlowCallback.java包含一个onResult方法,该方法将Response作为参数。

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)). 我已经能够调用该方法,但是没有得到返回的响应(由于onResult方法不执行任何操作,并且initialize方法返回void(甚至没有回调或响应),因此也不确定如何获取响应)。

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? 哪个根据BPEL控制台工作,并且给出“ 123456789”,我的问题是如何获得响应?

Here is a snippet from the BPEL source: 这是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>

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. 您的BPEL流程确实是异步的,当接收活动使用消息时,流程实例将启动,响应是通过调用活动发送的。 In order to receive the response, your Java client needs to open a Web service endpoint which implements the client:n6368808_CreditFlowCallback port type. 为了接收响应,您的Java客户端需要打开一个实现客户端的Web服务端点:n6368808_CreditFlowCallback端口类型。 How the BPEL engine determines the callback's endpoint address is engine specific. BPEL引擎如何确定回调的端点地址是特定于引擎的。 Theoretically, the partner link's partner role gets initialized with the received message (ie the message needs to communicate the callback EPR). 从理论上讲,伙伴链接的伙伴角色将使用接收到的消息进行初始化(即消息需要传达回调EPR)。 However it depends if and how your BPEL engine implements the initialization of partner roles. 但是,这取决于您的BPEL引擎是否以及如何实现伙伴角色的初始化。

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 (ie 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). 但是,如果您使用异步传输协议(例如JMS),或者绝对确定被调用的Web服务运行时间短(即整个处理不太可能花费超过HTTP连接超时的时间),则可以考虑对流程进行同步建模,通过用应答替换调用(与接收相同的partnerlink,porttype和操作)。 If in doubt, stick to the async model. 如有疑问,请坚持使用异步模型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM