java.net.ProtocolException:Unexpected status line:

Hi, 
What's wrong with the code below?
Generated entities with  TMS Data Modeler from  SQLITE database:


unit ffpf
...
type 
 Tos = class;
 Tcond = class;
 ...
  [Entity]
  [Table('os')]
  [Id('Fidos', TIdGenerator.IdentityOrSequence)]
  Tos = class
  private
    [Column('idos', [TColumnProp.Required, TColumnProp.NoInsert, TColumnProp.NoUpdate])]
    Fidos: Integer;
    
    [Column('denos', [TColumnProp.Required], 30)]
    Fdenos: string;
    
    [Column('telefon1', [], 15)]
    Ftelefon1: Nullable<string>;
    
    [Column('telefon2', [], 15)]
    Ftelefon2: Nullable<string>;
    
    [Column('fax', [], 15)]
    Ffax: Nullable<string>;
    
    [Column('email', [], 50)]
    Femail: Nullable<string>;
    
    [Column('adresa', [], 100)]
    Fadresa: Nullable<string>;
    
    [Column('idosrnp', [TColumnProp.Required])]
    Fidosrnp: TGuid;
    
    [Column('idamjos', [])]
    Fidamjos: Nullable<Integer>;
    
    [Column('iderp', [])]
    Fiderp: Nullable<string>;
    
    [Association([TAssociationProp.Lazy, TAssociationProp.Required], CascadeTypeAll - [TCascadeType.Remove])]
    [JoinColumn('idds', [TColumnProp.Required], 'idds')]
    Fidds: Proxy<Tds>;
    function Getidds: Tds;
    procedure Setidds(const Value: Tds);
  public
    property idos: Integer read Fidos write Fidos;
    property denos: string read Fdenos write Fdenos;
    property telefon1: Nullable<string> read Ftelefon1 write Ftelefon1;
    property telefon2: Nullable<string> read Ftelefon2 write Ftelefon2;
    property fax: Nullable<string> read Ffax write Ffax;
    property email: Nullable<string> read Femail write Femail;
    property adresa: Nullable<string> read Fadresa write Fadresa;
    property idosrnp: TGuid read Fidosrnp write Fidosrnp;
    property idamjos: Nullable<Integer> read Fidamjos write Fidamjos;
    property iderp: Nullable<string> read Fiderp write Fiderp;
    property idds: Tds read Getidds write Setidds;
  end;
  
  [Entity]
  [Table('cond')]
  [Id('Fidcond', TIdGenerator.IdentityOrSequence)]
  Tcond = class
  private
    [Column('idcond', [TColumnProp.Required, TColumnProp.NoInsert, TColumnProp.NoUpdate])]
    Fidcond: Integer;
    
    [Column('condl', [TColumnProp.Required], 40)]
    Fcondl: string;
    
    [Column('ciocan', [TColumnProp.Required], 15)]
    Fciocan: string;
    
    [Column('ciocanp', [], 15)]
    Fciocanp: Nullable<string>;
    
    [Association([TAssociationProp.Lazy, TAssociationProp.Required], CascadeTypeAll - [TCascadeType.Remove])]
    [JoinColumn('idos', [TColumnProp.Required], 'idos')]
    Fidos: Proxy<Tos>;
    function Getidos: Tos;
    procedure Setidos(const Value: Tos);
  public
    property idcond: Integer read Fidcond write Fidcond;
    property condl: string read Fcondl write Fcondl;
    property ciocan: string read Fciocan write Fciocan;
    property ciocanp: Nullable<string> read Fciocanp write Fciocanp;
    property idos: Tos read Getidos write Setidos;
  end;
  ...


Create a service in a XData REST:
 
unit fondpfInterface;


interface
uses
  Xdata.Service.Common, Generics.Collections, ffpf;


type
  [ServiceContract]
  //[URIPathSegment('GetUnOS')]
  Ifondpf = interface(IInvokable)
  ['{DDAB9F9C-3C88-47C5-A3ED-877683AEC389}']
    function ExtragOS(denos:string) : TList<Tos>;
    function ScriuListaCond(ListaCond:TList<TCond>;osu:Tos):integer;
    {With this function I'm trying to send a list of Tcond objects to be written in the database. I call this function on the Android smartphone}
  end;


implementation


initialization
  RegisterServiceType(TypeInfo(Ifondpf));
end.

Implementationa of service:


unit fondpf;


interface
uses
  System.Classes,Generics.Collections, ffpf, fondpfInterface,
  XData.Server.Module,  Aurelius.Criteria.Dictionary,
  Aurelius.Engine.ObjectManager,Aurelius.Criteria.Linq, Aurelius.Criteria.Projections,
  XData.Service.Common;


type
  [ServiceImplementation]
  Tfondpf = class(TInterfacedObject, Ifondpf)
  private
    function ExtragOS(denos:string) : TList<Tos>;
    function ScriuListaCond(ListaCond:TList<TCond>;osu:Tos):integer;
  end;


implementation


{ Tfondpf }


function Tfondpf.ExtragOS(denos: string): TList<Tos>;
begin
   Result := TXDataOperationContext.Current.GetManager.Find<Tos>.Where(Linq.Eq('denos',denos))
    .List;
end;


function Tfondpf.ScriuListaCond(ListaCond: TList<TCond>; osu: Tos): integer;
var
  el,pp: Tcond;
  i:Integer;
begin
 i:=0;
 for el in ListaCond do
 begin
    pp := Tcond.Create;
    try
      pp.condl := el.condl;
      pp.ciocan := el.ciocan;
      pp.ciocanp := '';
      pp.idos := osu;
      TXDataOperationContext.Current.GetManager.Save(pp);
      i:=i+1;
      //pp.Free;
    finally
    //if not TXDataOperationContext.Current.GetManager.IsAttached(pp) then
      pp.Free;
    end;
 end;
 el.Free;
 //ListaCond.Clear;
 osu.Free;
 ListaCond.Free;
 Result:=i;
end;


initialization
  RegisterServiceType(Tfondpf);
end.
 
Client : from Android uses this service

procedure TfrmClient.bInsMultipluClick(Sender: TObject);
var
  os: Tos;
  postListCond: Ifondpf;
  cond: Tcond;
  condList: TList<Tcond>;
  idos_, i, pers: integer;
begin
  pers:=0;
  condList := Client.List<Tcond>;
  condList.Clear;
  {I choose idos from Tos}
  os := Client.Get<Tos>(2);
  {eNrPers.Text is number of records to be inserted in cond Table (Tcond)
  This is about how I try to solve a need in an application that now uses datasnap. The average number of records is 1000.}
  for i := 1 to StrToInt(eNrPers.Text) do
  begin
    cond := Tcond.Create;
    try
      cond.condl := eNume.Text + i.ToString;
      cond.ciocan := eCiocan.Text + i.ToString;
      cond.ciocanp := '';
      cond.idos := os;
      condList.Add(cond);
    finally
    cond.Free;
    end;
  end;
  postListCond := Client.Service<Ifondpf>;
  pers := postListCond.ScriuListaCond(condList,os);
  ShowMessage('I added ' + i.ToString + ' rows ');
  condList.Free;
  os.Free;
end; 


I use:
 REST server: Xdata server
 Last version of TMS Business
 RAD Studio Tokyo Ent 10.2.1
 Windows 10 Ent for server , SQLITE
 test client of Android 8.0.0, 4.4, 6.0.1
Problems:
1. At first execution of "TfrmClient.bInsMultipluClick(Sender: TObject)" everything works well.
2. At the next request I get the error: "java.net.ProtocolException: Unexpected status line:{."
3. Trying once again works well. 
4. the first call goes, the next one gives the error,

Any help is welcome
Respectfully,
Grigore

Hello,

In Tfondpf.ScriuListaCond implementation, you don't need to destroy any object there. No need to call pp.Free, el.Free, osu.Free or ListaCond.Free.
They are all destroying automatically by XData and probably a double destruction is happening server side, which might be the reason for unpredictable results. Please try to remove those destruction and see if everything works as expected.

Hi,

in Tfondpf.ScriuListaCond implementation, I have eliminated the destruction of objects: pp.Free, el.Free, osu.Free and ListaCond.Free .
Now it always works.

Thank you for your prompt answer.

Respectfully,
Grigore