Ignore:
Timestamp:
08/13/13 11:06:15 (11 years ago)
Author:
g.georgovassilis@mpi.nl
Message:

#269 BaseRemoteService? abstracts HTTP communication away for XML services, added facility for mocking services in unit tests, moved tests into src/test

Location:
ComponentRegistry/branches/ggeorgovassilis_workspace/ComponentBrowserGui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/branches/ggeorgovassilis_workspace/ComponentBrowserGui

    • Property svn:ignore
      •  

        old new  
        88.flexConfig.xml
        99.metadata
         10
         11libs
         12
         13.FlexUnitSettings
  • ComponentRegistry/branches/ggeorgovassilis_workspace/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/services/IsocatService.as

    r1591 r3366  
    22        import com.adobe.net.URI;
    33       
    4         import flash.events.EventDispatcher;
    5        
    6         import mx.controls.Alert;
    74        import mx.managers.CursorManager;
    8         import mx.messaging.messages.HTTPRequestMessage;
    9         import mx.rpc.events.FaultEvent;
    10         import mx.rpc.events.ResultEvent;
    115        import mx.rpc.http.HTTPService;
    12         import mx.utils.StringUtil;
    136
    14         public class IsocatService extends EventDispatcher {
     7        public class IsocatService extends BaseRemoteService {
    158                public static const PROFILE_LOADED:String = "ProfileLoaded";
    169                public static const TYPE_SIMPLE:String = "simple";
     
    2720
    2821                public function IsocatService() {
     22                        super(PROFILE_LOADED);
    2923                }
    3024
     
    3529                public function load(keyword:String, type:String):void {
    3630                        if (keyword) {
    37                                 createClient();
    3831                                CursorManager.setBusyCursor();
    3932                                var uri:URI = new URI(Config.instance.isocatSearchUrl);
     
    4134                                if (type)
    4235                                    uri.setQueryValue("type", type);
    43                                 service.url = uri.toString();
    44                                 service.send();
     36                                dispatchRequest(uri);
    4537                        }
    4638                }
     
    5345                }
    5446
    55                 private function createClient():void {
    56                         service = new HTTPService();
    57                         service.method = HTTPRequestMessage.GET_METHOD;
    58                         service.resultFormat = HTTPService.RESULT_FORMAT_E4X;
    59                         service.addEventListener(ResultEvent.RESULT, handleResult);
    60                         service.addEventListener(FaultEvent.FAULT, handleError);
    61                 }
    62 
    63 
    64                 private function handleResult(resultEvent:ResultEvent):void {
     47                override protected function handleXmlResult(result:XML):void {
    6548                        CursorManager.removeBusyCursor();
    66                         if (resultEvent.statusCode >= 200 && resultEvent.statusCode < 300) {
    67                                 var data:XML = new XML(resultEvent.result);
    68                                 searchResults = data.dcif::dataCategory;
    69                         } else {
    70                                 Alert.show("Unexpected error, server returned status: " + resultEvent.statusCode + "\n Message = ");
    71                         }
    72                 }
    73 
    74                 private function handleError(faultEvent:FaultEvent):void {
    75                         CursorManager.removeBusyCursor();
    76                         var errorMessage:String = StringUtil.substitute("Error in {0} status {1}: {2}", this, faultEvent.statusCode, faultEvent.fault.faultString);
    77                         Alert.show(errorMessage);
     49                        searchResults = result.dcif::dataCategory;
    7850                }
    7951
Note: See TracChangeset for help on using the changeset viewer.