Android Question Cannot post to Web Server

Setlodi

Member
Hi there

I have been banging my head on the wall trying to debug my code without success!

I get the following error when I compile my code:

** Activity (main) Resume **
*** Receiver (httputils2service) Receive (first time) ***
ResponseError. Reason: Bad Request, Response: Bad Request
JobName = , Success = false
Error occurred on line: 301 (HttpJob)
java.io.FileNotFoundException: /data/user/0/b4a.example/cache/1: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:575)
at java.io.FileInputStream.<init>(FileInputStream.java:160)
at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:215)
at b4a.example.httpjob._getstring2(httpjob.java:483)
at b4a.example.httpjob._getstring(httpjob.java:123)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA$2.run(BA.java:395)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7891)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:568)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1062)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Linux.open(Native Method)
at libcore.io.ForwardingOs.open(ForwardingOs.java:567)

And heres my code:

B4X:
    Dim XML_String As String = $"<?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">   
    <soap:Body> 
    <Insert_SmartForceData  xmlns="http://tempuri.org/"> 
    <NOTICE_NO>123456</NOTICE_NO> 
    <DOCUMENT_NO>123456</DOCUMENT_NO>   
    <LACODE>123456</LACODE> 
    <NOTICE_STATUS>123456</NOTICE_STATUS> 
    <NOTICE_STAGE>123456</NOTICE_STAGE> 
    <NOTICE_TYPE>123456</NOTICE_TYPE> 
    <INITIALS>123456</INITIALS> 
    <FIRST_NAMES>123456</FIRST_NAMES> 
    <SURNAME>123456</SURNAME> 
    <GENDER>123456</GENDER> 
    <ID_NO>123456</ID_NO> 
    <ID_TYPE_ID>123456</ID_TYPE_ID> 
    <LICENCE_CODE>123456</LICENCE_CODE> 
    <NATIONALITY>123456</NATIONALITY> 
    <OCCUPATION>123456</OCCUPATION> 
    <DOB>123456</DOB> 
    <AGE>123456</AGE> 
    <REGISTRATION_NO>123456</REGISTRATION_NO> 
    <VEHICLE_MAKE>123456</VEHICLE_MAKE> 
    <VEHICLE_TYPE>123456</VEHICLE_TYPE> 
    <VEHICLE_COLOR>123456</VEHICLE_COLOR> 
    <POSTAL_ADDRESS1>123456</POSTAL_ADDRESS1> 
    <POSTAL_ADDRESS2>123456</POSTAL_ADDRESS2> 
    <POSTAL_ADDRESS3>123456</POSTAL_ADDRESS3> 
    <POSTAL_CODE>123456</POSTAL_CODE> 
    <PHYSICAL_ADDRESS1>123456</PHYSICAL_ADDRESS1> 
    <PHYSICAL_ADDRESS2>123456</PHYSICAL_ADDRESS2> 
    <PHYSICAL_ADDRESS3>123456</PHYSICAL_ADDRESS3> 
    <PHYSICAL_POSTAL_CODE>123456</PHYSICAL_POSTAL_CODE> 
    <HOME_TEL>123456</HOME_TEL> 
    <CELL_MOBILE>123456</CELL_MOBILE> 
    <AMOUNT_1>123456</AMOUNT_1> 
    <AMOUNT_2>123456</AMOUNT_2> 
    <AMOUNT_3>123456</AMOUNT_3> 
    <CHARGE_CODE_1>123456</CHARGE_CODE_1> 
    <CHARGE_CODE_2>123456</CHARGE_CODE_2> 
    <CHARGE_CODE_3>123456</CHARGE_CODE_3> 
    <CHARGE_MAIN2>123456</CHARGE_MAIN2> 
    <CHARGE_MAIN3>123456</CHARGE_MAIN3> 
    <LOCATION_CODE>123456</LOCATION_CODE> 
    <OFFICER_NUMBER>123456</OFFICER_NUMBER> 
    <COURT_CODE>123456</COURT_CODE> 
    <COURT_ROOM>123456</COURT_ROOM> 
    <OFFENCE_TIME>123456</OFFENCE_TIME> 
    <OFFENCE_DATE>123456</OFFENCE_DATE> 
    <PAYMENT_DUE_DATE>123456</PAYMENT_DUE_DATE> 
    <COURT_DATE>123456</COURT_DATE> 
    <CAPTURED_DATE>123456</CAPTURED_DATE> 
    <CAPTURER>123456</CAPTURER> 
    <DEVICE_SERIAL_NO>123456</DEVICE_SERIAL_NO 
    </Insert_SmartForceData > 
    </soap:Body> 
    </soap:Envelope>"$
    
'    Log("XML_String = " & XML_String)

Dim job As HttpJob

    job.Initialize("",Me)
    job.PostString("http://154.0.174.160:81/service1.asmx",XML_String)
    job.GetRequest.SetHeader("SOAPAction", "http://tempuri.org/Insert_SmartForceData")
    job.GetRequest.SetContentType("text/xml; charset=utf-8")
    
    Wait For (job) JobDone(j As HttpJob)
    If j.Success Then
        Log("Result = " &  job.GetString)
    Else
        Log("####### Failed")
        Log(j.ErrorMessage)
    End If
    j.Release

I don't know what file is not being found, according to the error message...

Please assist...
 
Solution
ChatGPT says...

The error you're encountering, java.io.FileNotFoundException: /data/user/0/b4a.example/cache/1: open failed: ENOENT (No such file or directory), is typically related to the HttpJob trying to access a file that doesn't exist in the specified path.

Here’s a breakdown of potential issues in your code:
  1. Bad Request (400) Error:
    • This indicates that the server did not understand the request due to malformed syntax. This could be related to the XML you're sending or how it's structured.
  2. FileNotFoundException:
    • This specific error suggests that the HttpJob is trying to access a file (possibly the response body or another resource) that isn't available in the path...

JohnC

Expert
Licensed User
Longtime User
ChatGPT says...

The error you're encountering, java.io.FileNotFoundException: /data/user/0/b4a.example/cache/1: open failed: ENOENT (No such file or directory), is typically related to the HttpJob trying to access a file that doesn't exist in the specified path.

Here’s a breakdown of potential issues in your code:
  1. Bad Request (400) Error:
    • This indicates that the server did not understand the request due to malformed syntax. This could be related to the XML you're sending or how it's structured.
  2. FileNotFoundException:
    • This specific error suggests that the HttpJob is trying to access a file (possibly the response body or another resource) that isn't available in the path /data/user/0/b4a.example/cache/1. This could happen if the response handling expects a file, but it wasn't correctly downloaded or saved.

Possible Fixes:​

  1. Check the XML Structure:
    • Ensure that the XML structure is well-formed and matches the expected format of the SOAP service you're communicating with.
    • One issue in your XML string is that the DEVICE_SERIAL_NO tag is not properly closed with a >.
    • Corrected line: <DEVICE_SERIAL_NO>123456</DEVICE_SERIAL_NO>

  2. HTTP URL:
  3. Handling the Response:
    • If the response from the server is a file, ensure you handle it appropriately in your JobDone method. If you're expecting a string response, make sure you're not inadvertently trying to open a non-existent file.
  4. Caching Issues:
    1. The FileNotFoundException might be related to caching issues. Ensure that the HttpJob isn't incorrectly handling cached data. You might try disabling caching if you suspect this is the case.

Additional Debugging:​

  • Add more logging to see exactly what the server is responding with, which can give you more context.
  • Verify the content of job.GetString after a successful response to ensure the server returns the expected data.
After making these adjustments, test the code again to see if the issue persists.
 
Upvote 0
Solution

drgottjr

Expert
Licensed User
Longtime User
when okhttputils creates and runs a "job", it assigns a
job number to it, eg, "1". it creates a file by that
name and stores the result of the job. when you call
job.release, okhttputils deletes that file.

if the job is not successful, there is no file. when
you call job.release, there is nothing to release. the
error message refers to that file:
java.io.FileNotFoundException: /data/user/0/b4a.example/cache/1

as to why your job was not successful, i cannot say. you'll have
to re-examine your code and the server's api. although the server
does say quite clearly, "bad request"
 
Upvote 0
Top