B4J Question Https job - error

DarkoT

Active Member
Licensed User
Hi guys,

need little help... I'm working on two same applications; one will run on android and second on desktop (windows). I need to connect app with WEB API and using POST method. On android (B4A) working everything perfect, but in B4J the same routine give me after transferring some workorders error:

Waiting for debugger to connect...
Program started.
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
9817
9820
9810
9790
9782
9777
9766
9759
9751
Error occurred on line: 93 (HttpUtils2Service)
java.io.FileNotFoundException: C:\Users\darko\AppData\Local\Temp\12 (Access is denied)
at java.base/java.io.FileOutputStream.open0(Native Method)
at java.base/java.io.FileOutputStream.open(FileOutputStream.java:298)
at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:237)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:465)
at b4j.example.httputils2service._hc_responsesuccess(httputils2service.java:144)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA$3.run(BA.java:267)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._enterNestedEventLoopImpl(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._enterNestedEventLoop(WinApplication.java:201)
at javafx.graphics/com.sun.glass.ui.Application.enterNestedEventLoop(Application.java:509)
at javafx.graphics/com.sun.glass.ui.EventLoop.enter(EventLoop.java:107)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.enterNestedEventLoop(QuantumToolkit.java:591)
at javafx.graphics/javafx.stage.Stage.showAndWait(Stage.java:465)
at anywheresoftware.b4j.objects.Form.ShowAndWait(Form.java:231)
at b4j.example.pgsetupdata._showpage(pgsetupdata.java:89)
at b4j.example.pgmain$ResumableSub_lblUserInfo_MouseClicked.resume(pgmain.java:240)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:47)
at jdk.internal.reflect.GeneratedMethodAccessor7.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:42)
at anywheresoftware.b4a.keywords.Common$2$1.run(Common.java:1051)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)

Here is a part of code - marked where is a error:

B4X:
Dim url As String = B4XPages.MainPage.SetupData.Get("http_link") & "worders/" & B4XPages.MainPage.DefaultPartner & "/" & JobID
    Dim requestBody As String = "" ' Modify this as per your requirements
    
    Dim headers As Map
    headers.Initialize
    headers.Put("Content-Type", "application/json")
    headers.Put("x-api-key", "0ffcf6bd-8644-4252-b5fe-fb655d2c621e")
    
    Dim job As HttpJob
    job.Initialize("job", Me)
    job.PostString(url, requestBody)
    
    For Each headerKey As String In headers.Keys
        job.GetRequest.SetHeader(headerKey, headers.Get(headerKey))
    Next
    ' job.GetRequest.Timeout = B4XPages.MainPage.SetupData.Get("dilite_timeout")

    ' THIS ROUTINE GIVE ME ERROR AFTER TRASFERING 10 WORKORDERS
    Wait For (job) JobDone(job As HttpJob)
    
    
    If job.Success Then
        Dim response As String = job.GetString
        ' Log(response) ' Do something with the response

        Dim jRead As JSONParser
        jRead.Initialize(response)

        Dim jRoot As List = jRead.NextArray
        For Each coljRoot As Map In jRoot
            Dim WoId As String = coljRoot.Get("id")
            Dim WoStatus As String = coljRoot.Get("status")
            Dim WoStatusName As String = coljRoot.Get("status_name")
            Dim WoLength As String = coljRoot.Get("length")
            Dim WoWidth As String = coljRoot.Get("width")
            Dim WoTitle As String = coljRoot.Get("title")
            Dim WoProductId As String = coljRoot.Get("product_id")
            Dim WoProductName As String = coljRoot.Get("product_name")
            Dim WoQty As String = coljRoot.Get("qty")
            Dim WoCustomerName As String = coljRoot.Get("customer_name")
            Dim WoCustomerId As String = coljRoot.Get("customer_id")
            Dim WoMaterialId As String = coljRoot.Get("material_id")
            Dim WoMaterialName As String = coljRoot.Get("material_name")
            
            ' zapišemo v bazo
            Wait for (WriteWo2Dilite(WoId, JobID, WoTitle, WoStatus, WoStatusName, WoLength, WoWidth, WoQty, WoProductId, WoProductName, WoMaterialId, WoMaterialName, WoCustomerId, WoCustomerName)) complete(Uspesno As Boolean)
            
            Dim tasks As List = coljRoot.Get("tasks")
            For Each coltasks As Map In tasks
                Dim TaskId As String = coltasks.Get("id")
                Dim TaskType As String = coltasks.Get("type")
                Dim TaskGroup As String = coltasks.Get("subtype")
                If TaskGroup = "-" Then TaskGroup = TaskType
                Dim TaskStatus As String = coltasks.Get("status")
                Dim TaskNameId As String = coltasks.Get("task_name_id")
                Dim TaskName As String = coltasks.Get("task_name_name")
                Dim TaskRemark As String = coltasks.Get("remark")
                Dim TaskMachineID As String = coltasks.Get("machine_id")
                Dim TaskMachineName As String = coltasks.Get("machine_name")
                Dim TaskMaterialId As String = coltasks.Get("material_id")
                Dim TaskMaterialName As String = coltasks.Get("material_name")
                
                ' določimo delovno mesto
                Dim WorkingDepartment As String = ""
                If coltasks.Get("type") <> "-" And coltasks.Get("subtype") = "-" Then WorkingDepartment = TaskType
                If coltasks.Get("subtype") <> "-" Then WorkingDepartment = TaskName
                
                ' zapišemo podatke v bazo
                Wait for (WriteTask2Dilite(TaskId, WoId, TaskGroup, TaskType, WorkingDepartment, TaskStatus, TaskRemark, TaskName, TaskNameId, TaskMachineID, TaskMachineName, TaskMaterialId, TaskMaterialName)) complete(Uspesno As Boolean)
            Next
        Next
            
    Else
        Log("Error: " & job.ErrorMessage)
    End If

    job.Release
    Return True

What can be wrong? Why have I error just on B4J but not on B4A?


Thanks’ for help...
Darko
 
Solution
Looks like the default temporary folder is inaccessible. You can set it to a different folder by setting HttpUtils2Service.TempFolder = ...
Thank you @Erel; you will not believe... It was FOLDER created in windows %TEMP% (folder name was 12) and I assume than system creates file with same name (as is running http job). And there was conflict between FILE NAME and FOLDER inside of %temp% folder...

Thank you - I solved simple - I deleted folder with name 12 :)

Regards,
Darko

DarkoT

Active Member
Licensed User
Looks like the default temporary folder is inaccessible. You can set it to a different folder by setting HttpUtils2Service.TempFolder = ...
Thank you @Erel; you will not believe... It was FOLDER created in windows %TEMP% (folder name was 12) and I assume than system creates file with same name (as is running http job). And there was conflict between FILE NAME and FOLDER inside of %temp% folder...

Thank you - I solved simple - I deleted folder with name 12 :)

Regards,
Darko
 
Upvote 0
Solution
Top