Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unitialized Reply
#1
Bom dia,
Estou utilizando de ContentHandlers para realizar requisições de dados simples, como por exemplo obter um data source json para preenchimento de um Chart ou até mesmo a criação de um datatable de forma dinâmica.
Exemplificando melhor a questão:

Code:
                  solicitação
Pagina de Dados ----------------> ContentHandler

                  resposta
Pagina de Dados <---------------- ContentHandler


No entanto estou recebendo a seguinte mensagem "Uninitialized Reply".

Segue abaixo meu fonte:
  • Server Controller
Code:
procedure TIWServerController.IWServerControllerBaseConfig(Sender: TObject);
begin
  // This framework requires to disable IW embeded JQuery
  JavaScriptOptions.RenderjQuery := False;

  with THandlers.Add('/', 'getGraphicData', TContentChart.Create) do
  begin
    CanStartSession := false;
    RequiresSessionStart := true;
  end;

end;



  • ContentHandler

Code:
  if Assigned(aReply) then
    begin

      //Verify action
      if aParams.Values['action'] = 'GV' then
      begin

        try
          FDataSet := TFDQuery.Create(nil);
          FDataSet.SQL.Clear;
          ...
          ...
          FDataSet.Open();

          JSON := '[' + sLineBreak;
          FDataSet.First;
          while not FDataSet.Eof do
          begin
           ...
           ...
            FDataSet.Next;
          end;
          JSON := ']' + sLineBreak;
          aReply.WriteString(JSON);

        finally
          FreeAndNil(FDataSet);
        end;

      end;
    end;
  end;
 

Está faltando ou preciso implementar algo?
Desde já agradeço a atenção.
Reply
#2
Olá Raphael, inverta a ordem e faça um teste:
Code:
procedure TIWServerController.IWServerControllerBaseConfig(Sender: TObject);
begin
  // This framework requires to disable IW embeded JQuery
  JavaScriptOptions.RenderjQuery := False;

  with THandlers.Add('/', 'getGraphicData', TContentChart.Create) do
  begin
    CanStartSession := True;        {<-- Aqui}
    RequiresSessionStart := False;  {<-- Aqui}
  end;
Reply
#3
Olá Nilton,
Fiz o teste conforme pediu, e continuo a receber a mesma mensagem.

Para mais informações:

Versão Delphi: XE5
Versão IW: 14.2.8

Att,
Reply
#4
Manda o seu ContentHandle COMPLETO, pode ser nele o problema.
Reply
#5
Conforme solicitado, segue fonte.
OBS: Algumas partes de código foram ocultas para preservar as regas de negócio do cliente, e não influenciam no caso.



Code:
unit IWContents.Test;

interface

uses
  Classes,
  IW.Content.Base,
  HTTPApp,
  IWApplication,
  IW.HTTP.Request,
  IW.HTTP.Reply;

type
  TContentChart = class(TContentBase)
  protected
    function Execute(aRequest: THttpRequest; aReply: THttpReply; const aPathname: string; aSession: TIWApplication; aParams: TStrings): boolean; override;
  public
    constructor Create; override;
  end;

implementation

uses
  IW.Content.Handlers,
  IWMimeTypes,
  FireDAC.Comp.Client,
  ServerController,
  System.DateUtils,
  System.SysUtils,
  ...;
 
constructor TContentChart.Create;
begin
  inherited;
  mFileMustExist := False;
  mCanStartSession:= true;
//  mRequiresSessionStart := true;
end;

function TContentChart.Execute(aRequest: THttpRequest; aReply: THttpReply; const aPathname: string; aSession: TIWApplication; aParams: TStrings): boolean;
var
  JSON: string;
  FDataSet: TFDquery;
begin
  Result := true;
  JSON := '';

  if aParams.Count > 0 then
  begin

    if Assigned(aReply) then
    begin

      //Verify Action
      if aParams.Values['action'] = 'GV' then
      begin

        try
          FDataSet := TFDQuery.Create(nil);
          FDataSet.SQL.Clear;
          ...
          FDataSet.Open();

          JSON := '[' + sLineBreak;
          FDataSet.First;
          while not FDataSet.Eof do
          begin
            ...
            FDataSet.Next;
          end;
          JSON := ']' + sLineBreak;
          aReply.WriteString(JSON);

        finally
          FreeAndNil(FDataSet);
        end;

      end;
    end;
  end;

end;

initialization

end.
Reply
#6
Raphael, duas coisinhas pra testar:
1o.
Code:
constructor TContentChart.Create;
begin
  inherited;
  mFileMustExist := False;  {<-- Somente esse}
end;
2o.
Code:
if Assigned(aReply) then
    begin
      aReply.ContentType:= MIME_JSON;  {<-- AQUI}
      //Verify Action
      if aParams.Values['action'] = 'GV' then
Reply
#7
Jose Nilton, mesma mensagem.
Já tentei diversos métodos diferentes e todos resultam neste mesmo problema.

"...raised exception class Exception with message 'Uninitialized reply".
Reply
#8
"...raised exception class Exception with message 'Uninitialized reply".

This happens when NO response is provided. You must *always* provide a response of some sort.
Reply
#9
Obrigado Nilton pela Ajuda.
Thanks kudzu for your answer.

O problema foi resolvido criando um novo ContentHandler do zero.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)