B4J Question WebApi - Error

DarkoT

Active Member
Licensed User
Hi,
need little help. I created small desktop App based on @aeric solution WebApi which allows to create dynamically web api based on sql query-ies (some of desktop applications still not using web api for exchange data and is very difficult to connect directly to database). If database admin in "house" know the data structure and is familiar with a sql language, there can simple write query and system will create web api with this query. System cover two type of DB - MS SqL server and MySql. In any case - I have one stupid problem and cannot find it. If I run app in debug mode (and stop app with breakpoints) the system works perfectly, but when I run without braking points, the system send error - I cannot find it...

Error:
(NullPointerException) java.lang.NullPointerException


Creating HttpResponseMessage:
Sub SelectFromSql(Query As String, DbType As String) As HttpResponseMessage
    #region Documentation
    ' #Desc1 = Get a category by id
    ' #Desc2 = List all categories
    ' #Elems = 2
    #End region
    Dim List1 As List
    List1.Initialize
    
    Try     
        Dim rs As ResultSet

        ' database type
        If DbType.ToUpperCase = "MSSQL" Then rs = MsSql.ExecQuery2(Query, Null)
        If DbType.ToUpperCase = "MYSQL" Then rs = MySql.ExecQuery2(Query, Null)
        
        ' for all records in returned set
        Do While rs.NextRow
            Dim Map2 As Map
            Map2.Initialize
            For i = 0 To rs.ColumnCount - 1
                Map2.Put(rs.GetColumnName(i), rs.GetString(rs.GetColumnName(i)))
            Next
            ' generiramo list
            List1.Add(Map2)
        Loop
        rs.Close
        
    
        If List1.Size > 0 Then
            Rm.ResponseCode = 200
            Rm.ResponseData = List1
        Else
            Rm.ResponseCode = 404
            Rm.ResponseError = "ERP data for select not found..."
        End If
            
    Catch
        LogError(LastException)
        Rm.ResponseCode = 422
        Rm.ResponseError = "Error Execute Query"
    
    End Try
    
    Return Rm         
End Sub

Public Sub ReturnHttpResponse (mess As HttpResponseMessage, resp As ServletResponse)
    If mess.ResponseCode >= 200 And mess.ResponseCode < 300 Then ' SUCCESS
        If mess.ResponseString = "" Or mess.ResponseString = Null Then mess.ResponseString = "ok"
        If mess.ResponseMessage = "" Then mess.ResponseMessage = "Success"
        mess.ResponseError = Null
    Else ' ERROR
        If mess.ResponseCode = 0 Then mess.ResponseCode = 400
        If mess.ResponseString = "" Or mess.ResponseString = Null Then mess.ResponseString = "error"
        'If mess.ResponseMessage = "" Then mess.ResponseMessage = "Bad Request"
        If mess.ResponseError = "" Then mess.ResponseError = "Bad Request"
        mess.ResponseMessage = Null
    End If
    If mess.ContentType = "" Then mess.ContentType = CONTENT_TYPE_JSON
    If mess.ResponseData.IsInitialized = False Then mess.ResponseData.Initialize   
    ' Override Status Code
    If mess.ResponseCode < 200 Or  mess.ResponseCode > 299 Then
        resp.Status = 200
    Else
        resp.Status = mess.ResponseCode
    End If
    resp.ContentType = mess.ContentType
    Dim Map1 As Map = CreateMap("s": mess.ResponseString, "a": mess.ResponseCode, "r": mess.ResponseData, "m": mess.ResponseMessage, "e": mess.ResponseError)
    resp.Write(Map2Json(Map1))
End Sub

I assume there is somewhere inside of Sub ReturnHttpResponse error... But I can not find it - because the system work's correct when I run debug mode...
If have somebody can take a look I can share full project...

Thank you...
Darko
 

ilan

Expert
Licensed User
Longtime User
1664799131044.png



1664799150519.png
 
Upvote 0
Top