Webservice "internal server error"

Hi!

I’ve developed some webservices using xojo web 2017r2 (old web) and HandleSpecialUrl

Some of these ws don’t work on the customer server, on my dev server they work perfectly.

I get this error (in postman)

<!DOCTYPE html>

<html>

<head>

    <title>Internal Server Error</title>

</head>

<body>

    <h1>Internal Server Error</h1>

    <p>The server encountered an unhandled IOException while executing this request.</p>

</body>

</html>

I’ve made a backup of the customer’s db, installed locally on my server and tested all the webservices, they all work.

what should I check?

this is one of the faulty ws

Dim db As New MSSQLServerDatabase

db.Host =host // or just the IP if using the default instance
db.DatabaseName = dbnm
db.UserName = user  // or "Domain\UserID for trusted domain accounts
db.Password = pass


If db.Connect Then
  Dim f As FolderItem
  Dim textInput As TextInputStream
  Dim rowFromFile As String
  if DebugBuild then
    f = GetFolderItem("T:\AHR WEBSERVICE\evasione.txt")
  else
    f = GetFolderItem("evasione.txt") 
  end if
  
  filtro = filtro.replaceAll("%20", " ")
  
  
  Dim stringa_sql as string
  stringa_sql= "select "
  If f <> Nil Then
    textInput = TextInputStream.Open(f)
    Do
      rowFromFile = textInput.ReadLine(Encodings.ASCII) // Specify the actual encoding
      if rowFromFile.Mid(1,5)="field" then
        stringa_sql=stringa_sql+rowFromFile.Mid(7).Trim+","
      end if
      if rowFromFile.Mid(1,5)="order" then
        stringa_sql=stringa_sql.MidB(1,(stringa_sql.len-1))+" from "+codazi+"DOC_DETT left outer join "+codazi+"DOC_MAST on "+codazi+"DOC_DETT.MVSERIAL="+codazi+"DOC_MAST.MVSERIAL where MVTIPRIG='R'"
        if len(filtro.Trim)>0 then
          stringa_sql=stringa_sql+" and ABRIFB2B ='"+filtro+"'"
        end if 
        stringa_sql=stringa_sql+ " order by "+rowFromFile.Mid(7).Trim
      end if
    Loop Until textInput.EOF
    textInput.Close
  End If
  
  Dim ps As MSSQLServerPreparedStatement
  ps = db.Prepare(stringa_sql)
  
  Dim rs As RecordSet = ps.SQLSelect
  'Dim rs As RecordSet 
  'rs = db.SQLSelect(stringa_sql)
  
  dim item as new JSONItem
  dim a as jsonitem
  dim i,numrec as Integer
  dim valore as string
  
  if rs <> Nil Then
    While Not rs.EOF
      a = new JSONItem
      numrec=0
      If f <> Nil Then
        textInput = TextInputStream.Open(f)
        Do
          rowFromFile = textInput.ReadLine(Encodings.ASCII) // Specify the actual encoding
          numrec=numrec+1
          if rowFromFile.Mid(1,5)="field" then
            valore = rs.IdxField(numrec).StringValue.DefineEncoding(Encodings.SystemDefault) '.DefineEncoding(encodings.UTF8)
            valore = valore.ReplaceAll(Chr(34),"")
            valore = valore.ReplaceAll("è","e'")
            valore = valore.ReplaceAll("é","e'")
            valore = valore.ReplaceAll("à","a'")
            valore = valore.ReplaceAll("ì","ì'")
            valore = valore.ReplaceAll("ò","o'")
            valore = valore.ReplaceAll("ù","u'")
            a.Value("'"+rowFromFile.Mid(7).Trim+"'") = valore
          end if
        Loop Until textInput.EOF
        textInput.Close
      End If
      item.append(a)
      rs.MoveNext
    Wend
    'rs = nil
    rs.Close
  End If
  db.Close
  
  Return item // And return it to the caller
Else
  MsgBox("Connection error:" + db.ErrorMessage)
End If

and this is what I’ve in handlespecialurl

dim data as string = Request.Entity.DefineEncoding(encodings.UTF8) // We have to apply the right encoding to the received data
dim input as JSONItem = new JSONItem( data ) // Creating a new JSON object from it
dim output as JSONItem

dim parametri,parametro1,parametro2,parametro3,parametro4,parametro5,parametro6,parametro7,parametro8 as string

parametri = Request.QueryString

Select Case Request.Path // What is the method received as part of the request? (URL)
  
case "GetClienti"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  '
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  '
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  '
  'parametro4 = NthField(Request.QueryString, "&", 4)
  'parametro4 = NthField(parametro4, "=", 2)
  
  'output = GetAlunni(parametro1,parametro2,parametro3,parametro4) 
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetClienti(parametro3)
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
case "GetDestinazioniCli"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  '
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  '
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  '
  'parametro4 = NthField(Request.QueryString, "&", 4)
  'parametro4 = NthField(parametro4, "=", 2)
  
  'output = GetAlunni(parametro1,parametro2,parametro3,parametro4) 
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetDestinazioniCli(parametro3)
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
  
case "GetFornitori"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  '
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  '
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  '
  'parametro4 = NthField(Request.QueryString, "&", 4)
  'parametro4 = NthField(parametro4, "=", 2)
  
  'output = GetAlunni(parametro1,parametro2,parametro3,parametro4) 
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetFornitori(parametro3)
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
case "GetDestinazioniFor"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  '
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  '
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  '
  'parametro4 = NthField(Request.QueryString, "&", 4)
  'parametro4 = NthField(parametro4, "=", 2)
  
  'output = GetAlunni(parametro1,parametro2,parametro3,parametro4) 
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetDestinazioniFor(parametro3)
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
case "GetArticoli"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetArticoli(parametro3) 
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
case "GetCodiciArticoli"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetCodiciArticoli(parametro3) 
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
case "GetSaldi"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetSaldi(parametro3) 
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
case "GetListini"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetListini(parametro3) 
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
case "GetScaglioni"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetScaglioni(parametro3) 
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
case "GetContratti"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetContratti(parametro3) 
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
case "GetContrattiRighe"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetContrattiRighe(parametro3) 
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
  
case "GetCodiciIva"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetCodiciIva(parametro3) 
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
case "GetFamiglie"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetFamiglie(parametro3) 
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
case "GetGruppi"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetGruppi(parametro3) 
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
case "GetCategorieOmo"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetCategorieOmo(parametro3) 
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
case "GetMarchi"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetMarchi(parametro3) 
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
case "GetTipoProvvigioni"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetTipoProvvigioni(parametro3) 
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
  
case "GetTipoScomag"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetTipoScomag(parametro3) 
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
case "GetCategorieComm"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetCategorieComm(parametro3) 
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
case "GetValute"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetValute(parametro3) 
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
case "GetZone"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetZone(parametro3) 
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
case "GetAgenti"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetAgenti(parametro3) 
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
case "GetPagamenti"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetPagamenti(parametro3) 
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
case "GetEvasione"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  
  parametro3 = NthField(Request.QueryString, "&", 3)
  parametro3 = NthField(parametro3, "=", 2)
  
  if parametro1=wsuser and parametro2=wspass then
    output = GetEvasione(parametro3) 
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
  
case "PostOrdine"
  ' isoliamo i parametri
  parametro1 = NthField(Request.QueryString, "&", 1)
  parametro1 = NthField(parametro1, "=", 2)
  
  parametro2 = NthField(Request.QueryString, "&", 2)
  parametro2 = NthField(parametro2, "=", 2)
  
  parametro3 = data
  
  if parametro1=wsuser and parametro2=wspass then
    output = PostOrdine(parametro3) 
    Request.Header("Content-Type")="application/json"
    Request.Print( output.ToString ) // And send it back to the client that made the request, converting the JSON to a String in first place
  else
    Request.Print( "Autenticazione Fallita!" )
  end if
  
  
end select

Return true

Hi Ciro,

First of all I would replace the code below with a copyfile build script.

And just use

f = GetFolderItem("evasione.txt")

Next I would try to duplicate the runtime environment as close as possible e.g. use project->run paused then copy the debug build to the same location (Program Files?) before running the executable. If the project is running standalone as a service you should create the service for the debug executable and start the service (while running paused).

This may help determining the issue.

HTH
Wayne

1 Like

Some other things to consider…

You’re checking If f <> Nil In several places, but you’re not checking if f.exists. It’s certainly possible that these two could be different.

Also, the fact that you are getting an internal server error may mean that your code is producing an Exception and since you have no exception handling in your code, you could be getting IOExceptions when trying to read from a non-existent file.

Regarding this… use this instead:

filtro = DecodeUrlComponent(filtro)

because it will handle all of the special characters, not just spaces.

1 Like

I don’t see if your app is CGI or Stand Alone.

It’s stand alone.

maybe I found the problem

f = GetFolderItem("evasione.txt")

the file is not on the right folder… ops!

3 Likes