B4J Question HTTPJob JobDone not called for empty response body

jmon

Well-Known Member
Licensed User
Longtime User
Hello,

I'm working on a project that requires Google Calendar API. I manage to get a response from the POST and GET methods, but I don't from the DELETE method.

As you can see from this page : https://developers.google.com/google-apps/calendar/v3/reference/calendars/delete
Response
If successful, this method returns an empty response body.
delete returns an empty response. I don't get any feedback from my call, the JobDone event is never called.

My code is this:
B4X:
Dim job As HttpJob
job.Initialize("CalendarDelete", Me)
job.Tag = Tag
job.Delete("https://www.googleapis.com/calendar/v3/calendars/" & su.EncodeUrl(CalendarId, "UTF8") _
        & "?access_token=" & oAuthAccessToken)

Is there a way to get the feedback?

Thanks for your help.
Jmon.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You will need to modify HttpUtils2 source code with a small change.

Change hc_ResponseSuccess to:
B4X:
Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)
   If Response.ContentLength = 0 Then
     CompleteJob(TaskId, True, "")
   Else
     Response.GetAsynchronously("response", File.OpenOutput(TempFolder, TaskId, False), _
       True, TaskId)
   End If
End Sub
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
You will need to modify HttpUtils2 source code with a small change.

Change hc_ResponseSuccess to:
B4X:
Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)
   If Response.ContentLength = 0 Then
     CompleteJob(TaskId, True, "")
   Else
     Response.GetAsynchronously("response", File.OpenOutput(TempFolder, TaskId, False), _
       True, TaskId)
   End If
End Sub

Thank you,

How to I do that? I opened the jar with 7z, and read the httpjob.class file but It looks obfuscated or something like that:
Capture.PNG

Thank you
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
So I've edited and compiled the code, I get an error:
httputils2service._hc_responsesuccess (java line: 70)
java.lang.NullPointerException
at anywheresoftware.b4a.http.HttpClientWrapper$HttpResponeWrapper.getContentLength(HttpClientWrapper.java:543)
at b4j.example.httputils2service._hc_responsesuccess(httputils2service.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.BA$3.run(BA.java:178)
at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$149(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)

Thank you
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This means that the web service didn't return the content length header.

You can use this line to get the HttpJob:
B4X:
Dim job As HttpJob = TaskIdToJob.Get(TaskId)

When you send a DELETE request set HttpJob.Tag to Delete. Now you can check the tag value in the ResponseSuccess sub and if it is Delete then call CompleteJob.
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
hum... it gives me an error if I release the Response:
Program started.
httputils2service._hc_responsesuccess (java line: 83)
org.apache.http.MalformedChunkCodingException: Bad chunk header
at org.apache.http.impl.io.ChunkedInputStream.getChunkSize(ChunkedInputStream.java:231)
at org.apache.http.impl.io.ChunkedInputStream.nextChunk(ChunkedInputStream.java:183)
at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:152)
at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:175)
at org.apache.http.impl.io.ChunkedInputStream.exhaustInputStream(ChunkedInputStream.java:277)
at org.apache.http.impl.io.ChunkedInputStream.close(ChunkedInputStream.java:261)
at org.apache.http.entity.BasicHttpEntity.consumeContent(BasicHttpEntity.java:142)
at org.apache.http.conn.BasicManagedEntity.consumeContent(BasicManagedEntity.java:98)
at anywheresoftware.b4a.http.HttpClientWrapper$HttpResponeWrapper.Release(HttpClientWrapper.java:531)
at b4j.example.httputils2service._hc_responsesuccess(httputils2service.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.BA$3.run(BA.java:178)
at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$149(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)

In the original HttpUtils2, the response was not released.
 
Upvote 0
Top