AnsweredAssumed Answered

Problem in the Webscript service to call api/login

Question asked by ramos69 on May 4, 2010
Hello, i'm having a problem to call api/login service…


RPC Fault faultString="HTTP request error" faultCode="Server.Error.Request" faultDetail="Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Erro de fluxo. URL: http://10.0.20.5:8080/alfresco/service/api/login?password=aaaaaa&username=aaaaa"]. URL: http://10.0.20.5:8080/alfresco/service/api/login"]


Can someone help me?

I'm sending my Webscriptservice and my LoginWebscript…


WebscriptService.as

package webscripts
{
   import models.global.UserInfo;
   
   import mx.rpc.AsyncToken;
   import mx.rpc.Fault;
   import mx.rpc.events.FaultEvent;
   import mx.rpc.events.ResultEvent;
   import mx.rpc.http.HTTPService;
   import mx.rpc.soap.WebService;
   
   import webscripts.error.ErroMsg;
   import webscripts.events.FailureEvent;
   import webscripts.events.SuccessEvent;
   import webscripts.events.WebScriptError;
   import mx.utils.Base64Encoder;

   
   public class Webscriptservice extends HTTPService
   {
      
      public static const GET:String = "GET";
      public static const POST:String = "POST";
      public static const PUT:String = "PUT";
      public static const DELETE:String = "DELETE";
      
      
      // parte final do url do webscript
      private var _url:String;
      
      // definição do metodo HTTP
      private var _method:String;
      
      // Indica se o metodo GET deve ser feito por tunel
      private var _alwaysTunnelGetMethod:Boolean= true;
      
      //Indica se o ticket é necessário para efectuar o webservice
      private var _ticketRequired:Boolean= true;
      
      
      
      
      
      public function Webscriptservice(url:String, method:String, onSuccess:Function=null, onFailure:Function=null, ticketRequired:Boolean=true, alwaysTunnelGetMethod:Boolean= true)
      {
         super();
         
         _url= url;
         _method=method;
         _alwaysTunnelGetMethod = alwaysTunnelGetMethod;
         _ticketRequired = ticketRequired;
         
         
         if (_method == GET && _alwaysTunnelGetMethod == false)
         {
            
         this.method = GET;
            
         }
         else{
            this.method = POST;
         }
         
         this.url = url;
         trace("url " + url);
         
         // Regista os eventos
         addEventListener(ResultEvent.RESULT,onResultEvent);
         addEventListener(FaultEvent.FAULT,onFaultEvent);
         
   
         if(onSuccess !=null){
            
            addEventListener(SuccessEvent.SUCCESS, onSuccess);
            
         }
         if (onFailure != null){
            
            addEventListener(FailureEvent.FAILURE, onFailure);
         }
         
         // usar o formato E4X como default
         resultFormat = HTTPService.RESULT_FORMAT_E4X;
         
      }
      
      
      
      public function execute(parameters:Object=null):AsyncToken{
         
         var result:AsyncToken = null;
         
         try{
         
            if(parameters == null){
               
               parameters = new Object();
               
            }
            /*var model:UserInfo = UserInfo.getInstance();
            var headerList:Array = new Array();
            //var model:UserInfo = UserInfo.getInstance();
            var encoder:Base64Encoder = new Base64Encoder();
            encoder.encode(model.loginUserName + ":" + model.loginPassword);
            
            headerList["Authorization"] = "Basic " + encoder.toString();
            
            this.headers = headerList;         
            trace("execute dps do 1º if");
            trace(_ticketRequired);*/
         
            if(_ticketRequired == true){
               var model:UserInfo = UserInfo.getInstance();
               var ticket:String = model.loginTicket;
               if(ticket == null){
                  
                  throw new Error(" Webscript não executado pois ticket requerido não está disponivel");
                  
               }
               trace("execute dps do 2º if");
               parameters.ticket= ticket;
               trace(_ticketRequired);
            }
            trace("execute _ticketrequired a false");
            trace(this.method + _method);
            
            
            if(this.method == POST && _method !=POST){
               
               parameters.alf_method = _method;
               
            }
            
            result= send(parameters);
            trace(result.valueOf());
         }
         
         catch (error:Error)
         {
            trace("execute error");
            ErroMsg.getInstance().raiseError(ErroMsg.APPLICATION_ERROR,error);
            
         }
         
         return result;
      
      }
      
      
      public function onResultEvent(event:ResultEvent):void{
         trace("onResultEvent");
         dispatchEvent( new SuccessEvent( SuccessEvent.SUCCESS, event.bubbles, event.cancelable, event.result, event.token, event.message));
         
         
      }
      
      public function onFaultEvent(event:FaultEvent):void{
         trace("onFaultEvent");
         var fault:Fault= event.fault;
         trace(fault);
         
         if(hasEventListener(FailureEvent.FAILURE)== true){
            dispatchEvent( new FailureEvent( FailureEvent.FAILURE, false, true, fault));
            
         }
         else{
            var error:WebScriptError = new WebScriptError(" WebScriptError " + _method + " " + this.url + " " + fault.faultString);
            ErroMsg.getInstance().raiseError(ErroMsg.APPLICATION_ERROR,error);
            
         }
         
      }
      
      
      
      
      
      
      
   }
}



LoginWebscript.as

package webscripts
{
   import flash.events.EventDispatcher;
   import flash.events.IEventDispatcher;
   import flash.sampler.NewObjectSample;
   
   import mx.rpc.http.HTTPService;
   import mx.rpc.IResponder;
   import mx.rpc.events.FaultEvent;
   import mx.rpc.events.ResultEvent;

   
   import webscripts.error.ErroMsg;
   import webscripts.events.ErrorRaisedEvent;
   import webscripts.events.FailureEvent;
   import webscripts.events.SuccessEvent;
   import webscripts.events.WebScriptError;
   
   public class LoginWebScript extends EventDispatcher
   {
      
      private static var _instance:LoginWebScript;
      
      private var _ticket:String;
      
      
      public function LoginWebScript(access:Access)
      {
         if(access!=null){
            _instance = this;
         }else{
            throw new Error("nao se pode instanciar directamente");
         }
      }
      
      public static function get instance():LoginWebScript{
         
         if(LoginWebScript._instance==null){
            
            LoginWebScript._instance = new LoginWebScript(new Access);
            
            
         }
         
         return LoginWebScript._instance;
         
      }
      
      
      public function login(username:String, password:String):void{
         
         ErroMsg.getInstance().addEventListener(ErrorRaisedEvent.ERROR_RAISED,onErrorRaised);
         
         var url:String = "http://10.0.20.5:8080/alfresco/service/api/login";
         var webscript:Webscriptservice= new Webscriptservice(url, Webscriptservice.GET,onLoginSuccess,onLoginFailure,false,false);         
         webscript.resultFormat = HTTPService.RESULT_FORMAT_E4X;
         var params:Object= new Object();
         params.username = username;
         params.password = password;
         trace(params.username);
         trace(params.password);
         trace('login');
         webscript.execute(params);
         
      }
      
      public function onLoginSuccess(event:SuccessEvent):void{
         trace("onLoginSucess");
         _ticket = event.result.ticket;
         
         
      }
      
      
      public function onLoginFailure(event:FailureEvent):void{
         trace("onLoginFailure");
         
         
         
      }
      
      
      protected function onErrorRaised(event:ErrorRaisedEvent):void{
         
   
         
         
      }
      
      
      
   }
   
}
class Access{}






Outcomes