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.
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
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
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)
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.
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)
HttpUtils2 releases all responses (in the original code).
Anyway, it seems like you don't need to call Release in this case. Try the following test:
- Send 10 DELETE requests and see whether they all complete. If only 5 complete then there is a leak.