Android Question okHTTPUtils method DELETE with json problem

mojako

Member
Licensed User
Guys,

need help and advice please,
we have to parsing some json data to internet with DELETE method but we meet no solution with B4A.
we try parsing through www.hurl.it in chrome to make sure that all parameter and json data included when we submit. Then it is success.
this is the data and delete method : (see hurl2.png)
and the result success : (see hurl.png)

we already use GetRequest.InitializeDelete as Method Delete like in this thread
and also follow this thread
But both of thread can bring any solution for us..

bellow is our code :

Public Sub CancelOrder(optype As String, token As String, therapistId As String, deviceId As String, username As String, orderId As String, reasonId As String, reasonText As String)
ProgressDialogShow("... mohon sabar... ")
opProses = optype
dim wsxHttpJob as httpjob
wsxHttpJob.initialized("job",me)
Dim mCncl As Map
mCncl.Initialize
mCncl.Put("reasonId",reasonId)
mCncl.Put("reasonText",reasonText)
mCncl.Put("username", username)
mCncl.Put("deviceId", deviceId)
Dim jg1 As JSONGenerator
jg1.Initialize(mCncl)
wsxHttpJob.PostString("http://my-url.com?token="&token,jg1.ToPrettyString(4))
wsxHttpJob.GetRequest.SetHeader("Content-Type","application/json;charset=UTF-8")
wsxHttpJob.GetRequest.SetHeader("Accept", "*/*")
wsxHttpJob.GetRequest.InitializeDelete(urlLocation & urlReschedule & orderId& "?access_token="&token)
wsxHttpJob.Username = AuthUsername
wsxHttpJob.Password = AuthPassword
End Sub
and result when job.success is false and message is :
Unsupported Media Type

is there something that we missing?
thank you.
 

Attachments

  • hurl2.png
    hurl2.png
    49 KB · Views: 299
  • hurl.png
    hurl.png
    160.6 KB · Views: 354
Last edited:

MarcoRome

Expert
Licensed User
Longtime User
Try so:

B4X:
Public Sub CancelOrder(optype As String, token As String, therapistId As String, deviceId As String, username As String, orderId As String, reasonId As String, reasonText As String)
ProgressDialogShow("... mohon sabar... ")
Dim Link as String = urlLocation & urlReschedule & orderId& "?access_token="&token
opProses = optype
dim wsxHttpJob as httpjob
wsxHttpJob.initialized("job",me)
Dim jg1 As JSONGenerator
jg1.Initialize(CreateMap($"reasonId":${reasonId},"reasonText":${reasonText},etc......"$)
wsxHttpJob.Username = AuthUsername
wsxHttpJob.Password = AuthPassword
wsxHttpJob.PostString(Link,jg1.ToPrettyString(4))
wsxHttpJob.GetRequest.SetHeader("Content-Type","application/json")
wsxHttpJob.GetRequest.SetHeader("User-Agent", "runscope/0.1")
wsxHttpJob.GetRequest.SetHeader("Accept", "*/*")
wsxHttpJob.GetRequest.SetContentEncoding("gzip, deflate")
wsxHttpJob.GetRequest.InitializeDelete(Link)
...
 
Upvote 0

mojako

Member
Licensed User
Try so:

B4X:
Public Sub CancelOrder(optype As String, token As String, therapistId As String, deviceId As String, username As String, orderId As String, reasonId As String, reasonText As String)
ProgressDialogShow("... mohon sabar... ")
Dim Link as String = urlLocation & urlReschedule & orderId& "?access_token="&token
opProses = optype
dim wsxHttpJob as httpjob
wsxHttpJob.initialized("job",me)
Dim jg1 As JSONGenerator
jg1.Initialize(CreateMap($"reasonId":${reasonId},"reasonText":${reasonText},etc......"$)
wsxHttpJob.Username = AuthUsername
wsxHttpJob.Password = AuthPassword
wsxHttpJob.PostString(Link,jg1.ToPrettyString(4))
wsxHttpJob.GetRequest.SetHeader("Content-Type","application/json")
wsxHttpJob.GetRequest.SetHeader("User-Agent", "runscope/0.1")
wsxHttpJob.GetRequest.SetHeader("Accept", "*/*")
wsxHttpJob.GetRequest.SetContentEncoding("gzip, deflate")
wsxHttpJob.GetRequest.InitializeDelete(Link)
...
still no luck @MarcoRome error when job.success (Content type 'null') :

{"timestamp":1491914377209,"status":415,"error":"Unsupported Media Type","exception":"org.springframework.web.HttpMediaTypeNotSupportedException","message":"Content type 'null' not supported","path":"/order/2042"}
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Tried moving your .setHeader and .setContentEncoding after the .initializeDelete?
 
Upvote 0

mojako

Member
Licensed User
Can you paste code
dear @MarcoRome, here the latest code with moving .setHeader and .setContentEncoding suggested from @mc73 :
B4X:
ProgressDialogShow("... Please wait ... ")
    opProses = optype
    Dim link As String=urlLocation & urlReschedule & orderId &"?access_token="&token
    'Dim mCncl As Map
    'mCncl.Initialize
    'mCncl.Put("reasonId",reasonId)
    'mCncl.Put("reasonText",reasonText)
    'mCncl.Put("username", username)
    'mCncl.Put("deviceId", deviceId)
    Dim jg1 As JSONGenerator
    jg1.Initialize(CreateMap("reasonId":reasonId,"reasonText":reasonText,"username":username,"deviceId":deviceId))
    wsxHttpJob.Username = AuthUsername
    wsxHttpJob.Password = AuthPassword
    wsxHttpJob.PostString(link,jg1.ToPrettyString(4))
    wsxHttpJob.GetRequest.InitializeDelete(link)
    wsxHttpJob.GetRequest.SetHeader("Content-Type","application/json")
    wsxHttpJob.GetRequest.SetHeader("User-Agent", "runscope/0.1")
    wsxHttpJob.GetRequest.SetHeader("Accept", "*/*")
    wsxHttpJob.GetRequest.SetContentEncoding("gzip, deflate")

the latest response from job.success :

{"timestamp":1491961438838,"status":400,"error":"Bad Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"Required request body is missing: public org.springframework.http.ResponseEntity<com.openhorizon.jiva.antareja.rest.BaseResponse> com.openhorizon.jiva.antareja.rest.OrderRestController.cancelOrder(java.lang.String,com.openhorizon.jiva.antareja.rest.CancelOrderRequest)","path":"/order/2042"}
 
Last edited:
Upvote 0

mojako

Member
Licensed User
You need to use Job.GetRequest.SetContentType instead of setting the Content-Type header.
I did it also @Erel, but not working either..
other function we made for POST, GET, PUT are work fine with job.GetRequest.SetContentType.. but for DELETE we got stuck..
the server still looking for request body ... as job.success response above..
 
Upvote 0

mojako

Member
Licensed User
I see the problem. This is not the correct way to add a DELETE feature to OkHttpUtils2.

Add this method to HttpJob module:
B4X:
Public Sub Delete(Link As String, Data() As Byte)
   req.InitializeDelete2(Link, Data)
   CallSubDelayed2(HttpUtils2Service, "SubmitJob", Me)
End Sub
@Erel where do I get the latest HttpJob module?
 
Upvote 0

mojako

Member
Licensed User
I see the problem. This is not the correct way to add a DELETE feature to OkHttpUtils2.

Add this method to HttpJob module:
B4X:
Public Sub Delete(Link As String, Data() As Byte)
   req.InitializeDelete2(Link, Data)
   CallSubDelayed2(HttpUtils2Service, "SubmitJob", Me)
End Sub
yesssss it's work.. after I added this feature to the source code HttpJob Module then compile it to library then re attached my okHttpUtils2 to my project and do some modification it works.
this the latest my function and latest library if somebody next me need it.

B4X:
    ProgressDialogShow("... Please wait ... ")
    opProses = optype
    Dim link As String=urlLocation & urlReschedule & orderId &"?access_token="&token
    Dim mCncl As Map
    mCncl.Initialize
    mCncl.Put("reasonId",reasonId)
    mCncl.Put("reasonText",reasonText)
    mCncl.Put("username", username)
    mCncl.Put("deviceId", deviceId)
    Dim jg1 As JSONGenerator
    Dim db As ByteConverter
   
    jg1.Initialize(CreateMap("reasonId":reasonId,"reasonText":reasonText,"username":username,"deviceId":deviceId))
    Dim data() As Byte = db.StringToBytes(jg1.ToPrettyString(4), "UTF8")
    wsxHttpJob.PostString(link,jg1.ToPrettyString(4))
    wsxHttpJob.GetRequest.InitializeDelete2(link,data)
    wsxHttpJob.GetRequest.SetContentType("application/json")
    wsxHttpJob.GetRequest.SetHeader("User-Agent", "runscope/0.1")
    wsxHttpJob.GetRequest.SetHeader("Content-Length", "159")
    wsxHttpJob.GetRequest.SetHeader("Accept", "*/*")
    wsxHttpJob.GetRequest.SetContentEncoding("gzip, deflate")

thanks to you @mc73 , @MarcoRome and specially to you @Erel
 

Attachments

  • OkHttpUtils2.jar
    10.3 KB · Views: 306
  • OkHttpUtils2.xml
    9.7 KB · Views: 363
Upvote 0
Top