HTTPServiceInvoker

(This tag must be placed inside an <EventHandlers> tag or a <MessageHandlers> tag)

The HTTPServiceInvoker tag is used to create an HTTP Service instance and make a GET or POST request to that service. To use this tag, you need to specify the same attributes you would when creating an HTTP service with the <mx:HTTPService> tag (with the exception of xmlDecode, xmlEncode, and lastResult). In addition, you need to specify what method to call. This tag will also accept all mx.rpc.http.HTTPService tag attributes.

<HTTPServiceInvoker url="URLToCall" />

The above example would be the same as doing the following:

<mx:HTTPService id="myServiceInstance" url="http://www.example.com/services">

myServiceInstance.send();

You would also need to either create event handlers for the server result and fault or create a Responder to handle them. That is not necessary when using the HTTPServiceInvoker tag. See section "Handling a service result or fault".

With this tag, you can also utilize an already created HTTPService instance. This is useful when the same services are used by several EventHandlers blocks or several EventMaps.

Suppose you have a HTTP Service tag (either in the event map itself or in a different file):

<mx:HTTPService id="myService" url="http://www.example.com/services" />

You can call a method on that already created service as follows:

<HTTPServiceInvoker instance="{myService}" />

Attributes

url

required if no instance is specified

This attribute specify the address to send the request. Refer to mx.rpc.http.HTTPService documentation for more information.

instance

An HTTPService instance

The instance attribute specifies the already created service instance to use to make the call. This attribute must be supplied using bindings because it needs to point to an already created object.

Suppose you have a HTTPService already created:

<mx:HTTPService id="myService" url="http://www.example.com/services" />

You can make a call to this service by using the HTTPServiceInvoker tag, with instance {myService}. Note that any property you need for your service must be defined in the HTTPService tag.

<HTTPServiceInvoker instance="{myService}" />

debug

Boolean

Whether to show debugging information for this HTTPService resultHandlers and faultHandlers. If true, Console output will show debugging information as those handlers run.

Inner tags

Request

You can add variables to your HTTP request by using the Request inner tag. If using GET method, these variables will be sent as query string parameters. Otherwise, they will be added to the POST request.

As attributes of the Request tag, you specify the names of the variables you want to send and set the values of those variables by settings the value of the attributes.

Suppose you need to send a "photo_id" variable and a username variable with your request. Then you will specify:

<HTTPServiceInvoker instance="{myService}">
	<Request 
		photo_id="17"
		username="{event.username}" />
</HTTPServiceInvoker>

resultHandlers

A set of handlers to run when the server call returns a result. Inside this inner tag, you can use the same tags you would in the main body of an <EventHandlers> block, including other service calls.

faultHandlers

A set of handlers to run when the server call returns a fault. Inside this inner tag, you can use the same tags you would in the main body of an <EventHandlers>, including other service calls.

Handling a service result or fault

You can have a resultHandlers block and a faultHandlers block inside the tag to handle service results and faults.

<HTTPServiceInvoker url="URLToCall">

	<resultHandlers>
		... this list executes when server returns results ...
	</resultHandlers>
	
	<faultHandlers>
		... this list executes when server returns an error ...
	</faultHandlers>
	
</HTTPServiceInvoker>

See "Handling a service result or fault" for more information.

17 responses so far

  1. Is there a way to supply a hash to the Request tag? For example, with traditional mx:request, I can have:

    <mx:request>
    <person>
    <name> Joe </name>
    <age> 29 </age>
    </person>
    </mx:request>
  2. Or conversely, I could have httpSvc.send({person: {name: Joe} {age: 29}})
  3. Hi Justin,
    The HTTPServiceInvoker tag has a request attribute that works the same way as the <mx:request> as you showed in your first comment. I haven't tried it, but I think you should also be able to say:
    <code>
    <HTTPServiceInvoker request="{person: {name: Joe} {age: 29}}" ...>
    </code>

    Both ways would only work for literal values, however, but you would not be able to access what we call "Smart Objects", such as event, result, lastReturn. So you won't be able to supply event.age as a replacement for the value "29".

    To get around that, you could create your object before you pass it to the request using ObjectBuilder:

    <code>
    <ObjectBuilder generator="{Object}" cache="false">
       <Properties name="{event.name}" age="{event.age}" />
    </ObjectBuilder>

    <HTTPServiceInvoker>
        <Request person="{lastReturn}" />
    </HTTPServiceInvoker >
    </code>

    If you need more "nesting", then you could have multiple ObjectBuilder tags, but to be honest, it would be messy. I would suggest you to use another class to do that, so you would use <MethodInvoker> to call a function "createMyPerson(name, age)" or similar, and then pass that with lastReturn to the Request tag. That would make it nicer if your object has many levels of nested properties.
  4. Laura,

    Thanks for the response; the information about the ObjectBuilder was very helpful. As it is, I ended up nesting the data within the event itself (converting the public property to a getter/setter with the business logic I needed) and that worked perfectly. I thought that it probably makes better sense to have the logic in the custom creation event than cluttering the EventMap.
  5. First, great framework so far, but I still have to work out some techniques for bigger applications. I hope you have some recommendations or can add some stuff to the best practice section.

    I want to set some Request Parameters depending from a kind of Authorization Manager like you used in the cafeTownsend example.
    <HTTPServiceInvoker ...
    <Request username="{AuthorizationManager.user.name}" />

    However, I cannot access the manager from this scope, without using the ObjectBuilder in every HTTPServiceInvoker. I will have loads of them.

    Can you give a recommendation?

    The other problem is to create a Manager Object and setting values given via flashVars. I cannot access the Application from inside the EventMap.

    Thanks in advance!
    Simon
  6. I've try to use &lt;mx request&gt; tag inside the HTTPServiceInvoker tag but it cause an error to the compiler.I changed it to &lt;mate request&gt; but the problem still exist.How can i use the &lt;mx request&gt; tag in HTTPServiceInvoker as i use it in HTTPService ?<br /><br />My xml is like :<br />&lt;content name=&quot;/MainPageTemplate&quot;&gt;<br />&lt;page name=&quot;Mobile Marketing Platform Keyword Manager&quot; /&gt; <br />&lt;content localname=&quot;Nav&quot; name=&quot;/TwoRowNav&quot;&gt;<br />&lt;content localname=&quot;MSMNav&quot; name=&quot;/:MSMNav&quot;&gt;<br />&lt;content localname=&quot;MSMNav&quot; name=&quot;/MSMNav&quot;&gt;<br />&lt;Client&gt;<br /> &lt;clientId&gt;2&lt;/clientId&gt; <br /> &lt;name&gt;Velti Tech&lt;/name&gt; <br />&lt;Product&gt;<br /> &lt;productId&gt;6&lt;/productId&gt; <br /> &lt;clientId&gt;2&lt;/clientId&gt; <br /> &lt;name&gt;V-Phone&lt;/name&gt; <br /> &lt;/Product&gt;<br /> &lt;/Client&gt;<br />&lt;Client&gt;<br /> &lt;clientId&gt;4&lt;/clientId&gt; <br /> &lt;name&gt;General Motors&lt;/name&gt; <br />&lt;Product&gt;<br /> &lt;productId&gt;8&lt;/productId&gt; <br /> &lt;clientId&gt;4&lt;/clientId&gt; <br /> &lt;name&gt;Saturn Vue&lt;/name&gt; <br /> &lt;/Product&gt;<br /> &lt;/Client&gt;<br />&lt;/content&gt;<br />&lt;/content&gt;<br />&lt;/content&gt;<br /> &lt;/content&gt;<br /><br />and i want to use clientId and productId<br /><br />Thanks <br /><br />Aris
  7. How would I go about specifying a variable URL for the request? I need to pass an id to the server script as part of the URL. Thanks in advance!
  8. Panos,<br />Do you want to send that whole xml as the request?<br /><br />franz,<br />You need to use the Request inner tag. If the variable happens to be &quot;id&quot;, the you need to use<br />&lt;Request _id=&quot;YOUR ID&quot; /&gt; (note the underscore).
  9. I only want to past productId and cientId.I have done it with tag<br /> &lt;Request /&gt;<br /><br />Thanks for the answer<br /><br /><br />Panos
  10. &lt;HTTPServiceInvoker id=&quot;httpService&quot; url...&quot; <br />resultFormat=&quot;e4x&quot; debug=&quot;true&quot;&gt;<br /> &lt;Request &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sqlName=&quot;listTrackByLayout&quot; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;layout_sa=&quot;{event.layoutSa}&quot;<br />&nbsp;&nbsp;&nbsp;trk_type =&quot;{event.trkType}&quot; /&gt;<br />&lt;resultHandlers&gt; ... &lt;/resultHandlers&gt;<br />&lt;faultHandlers&gt; ... &lt;/faultHandlers&gt;<br />&lt;/HTTPServiceInvoker&gt;<br /><br />If I have multiple request parameter set by event object , my back end servlet can only get one parameter passed by event. that is layout_sa. <br />and trk_type parameter cannot be catched by back end. <br />if I used explicit parameter ,layout_sa=&quot;1&quot;, then I can get another event passed parameter trk_type.<br /><br />What should I do in this case ?
  11. I've used <br />&lt;Request <br /> _id=&quot;{event.myId}&quot;<br /> rmk=&quot;{event.rmk}&quot; /&gt;<br />to send the parameter &quot;id&quot; to server side, but what the server get is:<br />&amp;id=event%2EmyId&amp;rmk=testing<br /><br />Seems it directly print out the name &quot;event.myId&quot; but not the value of it. <br /><br />Could anyone please help? Thanks!
  12. Does the method default to POST?
  13. Ankur,<br />I believe HTTPService (the normal Flex HTTPService) defaults to GET, so I think that is the default for the HTTPServiceInvoker tag.
  14. I have been trying to use HttpServiceInvoker to fetch data from web service using following code:<br /><br />&lt;!-- UserEvent.FETCH_COMMENTS________________________________________________________________________ --&gt;<br />&nbsp;&nbsp;&nbsp;&lt;mate:EventHandlers type=&quot;{UserEvent.FETCH_COMMENTS}&quot; &gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mate:MethodInvoker generator=&quot;{Config}&quot; method=&quot;getappServicesURL&quot; cache=&quot;global&quot;/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mate:MethodInvoker generator=&quot;{UrlConstructor}&quot; method=&quot;fetchURL&quot; arguments=&quot;{[event,lastReturn,event.userid]}&quot; /&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mate:HTTPServiceInvoker useProxy=&quot;false&quot; url=&quot;{lastReturn}&quot; method=&quot;GET&quot; resultFormat=&quot;e4x&quot; &gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mate:resultHandlers&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mate:MethodInvoker generator=&quot;{Helper}&quot; method=&quot;parseComments&quot; arguments=&quot;{resultObject}&quot; cache=&quot;none&quot; /&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mate:MethodInvoker generator=&quot;{ModelManager}&quot; method=&quot;setCommentList&quot; arguments=&quot;{lastReturn}&quot;/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/mate:resultHandlers&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/mate:HTTPServiceInvoker&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&lt;/mate:EventHandlers&gt;<br />&lt;!-- UserEvent.POST_COMMENT ________________________________________________________________________ --&gt;<br />&nbsp;&nbsp;&nbsp;&lt;mate:EventHandlers type=&quot;{UserEvent.POST_COMMENT}&quot;&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mate:MethodInvoker generator=&quot;{Config}&quot; method=&quot;getappServicesURL&quot; cache=&quot;global&quot;/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mate:MethodInvoker generator=&quot;{UrlConstructor}&quot; method=&quot;fetchURL&quot; arguments=&quot;{[event,lastReturn]}&quot; /&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mate:HTTPServiceInvoker useProxy=&quot;false&quot; request=&quot;{event.xmlPayLoad}&quot; url=&quot;{lastReturn}&quot; method=&quot;POST&quot; resultFormat=&quot;e4x&quot; contentType=&quot;application/xml&quot; &gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mate:resultHandlers&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mate:EventAnnouncer generator=&quot;{UserEvent}&quot; type=&quot;{UserEvent.FETCH_COMMENTS}&quot;&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;mate:Properties userid=&quot;{event.userid}&quot;/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/mate:EventAnnouncer&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/mate:resultHandlers&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/mate:HTTPServiceInvoker&gt;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&lt;/mate:EventHandlers&gt;<br /><br />Hoewever, I noticed that the {resultObject} in Fetch_Comments event does not change teven after raising the event multiple times. Any idea what is wrong in the code ?
  15. How to pass a parameter value from event to the url mentioned below.<br /><br />&lt;mx:HTTPService id=&quot;myService&quot; url=&quot;<a rel="nofollow" href="http://www.example.com/services&quot">http://www.example.com/services&quot</a>;; /&gt;<br /><br />&lt;EventHandlers type=&quot;{TestEevent.TEST}&quot; debug=&quot;true&quot;&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;MethodInvoker id = &quot;homeServices&quot; generator=&quot;{HomeServices}&quot; method=&quot;setUserId&quot; arguments=&quot;{[event.userId]}&quot; cache=&quot;none&quot;/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;HTTPServiceInvoker instance=&quot;{services.getUserService(event.userId)}&quot; debug=&quot;true&quot;&gt;<br /><br />...<br /><br />I am using like this. Here instead of setting the event.userId parameter value its setting &quot;event.userId&quot; as a string .. how to resolve this.
  16. I am still getting to know my way around Mate, so I may be overlooking something obvious. Here's what i want to accomplish:

    I am interested in encapsulating the resultHandler and faultHandler inside a service class. For example, I have a custom HTTPServcice.mxml file with the appropriate <s:HTTPService> tag and properties. I also have added internal methods to handle both success and fault results. I invoke the service from the EventMap using <InlineInvoker> :

    <EventHandlers type="arguments="GET_SMART_SUGGEST_KEYWORDS" />
    <InlineInvoker method="{httpService.getSmartSuggestData}" arguments="{event.data}"/>
    </EventHandlers>

    This is working as expected however, I want to dispatch an event back to the EventMap after the resuls are returned and reworked for the desired data structure which is handled inside the HTTPService.mxml. The EventMap is not responding to the event dispatched.

    I have tried several approaches with out any luck. FYI, I am passing the scope.dispatcher to the Service on instantiation like so:

    <services:HTTPService id="httpService" dispatcher="{scope.dispatcher}" />

    Any help will be appreciated. Thanks in advance.
  17. Ok, I stumbled on a solution. Passing scope.dispatcher in the arguments array on <InlineInvoker> solves my issue.

    <InlineInvoker method="{httpService.getSmartSuggestData}" arguments="{[event.data, scope.dispatcher]}"/>

    Not sure if this is ultimately correct so any recommendations for an alternate approach are welcome

Leave a response

If you need help or want to comment on something not related to this page, please post in the forums. Thanks!

Leave this field empty