Class: OpenWFE::SoapParticipant

Inherits:
Object
  • Object
show all
Includes:
LocalParticipant
Defined in:
lib/openwfe/participants/soapparticipants.rb

Overview

Wrapping a simple web service call within an OpenWFEru participant.

quote_service = OpenWFE::SoapParticipant.new(
    "http://services.xmethods.net/soap",        # service URI
    "urn:xmethods-delayed-quotes",              # namespace
    "getQuote",                                 # operation name
    [ "symbol" ])                               # param arrays (workitem fields)

engine.register_participant("quote_service", quote_service)

By default, call params for the SOAP operations are determined by iterating the parameters and fetching the values under the corresponding workitem fields. This behaviour can be changed by overriding the prepare_call_params() method.

On the return side, you can override the method handle_call_result for better mappings between web service calls and the workitems.

Instance Attribute Summary

Attributes included from Contextual

#application_context

Instance Method Summary collapse

Methods included from LocalParticipant

#call_block, #get_flow_expression, #reply_to_engine

Methods included from Contextual

#get_work_directory, #init_service, #lookup

Methods included from Logging

#ldebug, #ldebug_callstack, #lerror, #lfatal, #linfo, #llog, #lunknown, #lwarn

Methods included from OwfeServiceLocator

#get_engine, #get_error_journal, #get_expool, #get_expression_map, #get_expression_pool, #get_expression_storage, #get_expression_storages, #get_journal, #get_participant_map, #get_scheduler, #get_wfid_generator

Constructor Details

#initialize(endpoint_url, namespace, method_name, params, param_prefix = "") ⇒ SoapParticipant

Returns a new instance of SoapParticipant.



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/openwfe/participants/soapparticipants.rb', line 70

def initialize \
    (endpoint_url, namespace, method_name, params, param_prefix="")

    super()

    @driver = SOAP::RPC::Driver.new(endpoint_url, namespace)

    @method_name = method_name
    @params = params
    @param_prefix = param_prefix

    @driver.add_method(method_name, *params)
end

Instance Method Details

#consume(workitem) ⇒ Object

The method called by the engine when the flow reaches an instance of this Participant class.



88
89
90
91
92
93
94
95
96
97
# File 'lib/openwfe/participants/soapparticipants.rb', line 88

def consume (workitem)

    call_params = prepare_call_params(workitem)

    call_result = @driver.send(@method_name, *call_params)

    handle_call_result(call_result, workitem)

    reply_to_engine(workitem)
end

#handle_call_result(result, workitem) ⇒ Object

This implementation simply stuffs the result into the workitem as an attribute named “__result__”.

Feel free to override this method.



118
119
120
121
# File 'lib/openwfe/participants/soapparticipants.rb', line 118

def handle_call_result (result, workitem)

    workitem.attributes["__result__"] = result
end

#prepare_call_params(workitem) ⇒ Object

The base implementation : assumes that for each webservice operation param there is a workitem field with the same name.

Feel free to override this method.



105
106
107
108
109
110
# File 'lib/openwfe/participants/soapparticipants.rb', line 105

def prepare_call_params (workitem)

    @params.collect do |param|
        get_param workitem, param
    end
end