Return type of org.apache.http.conn.EofSensorInputStream from HTTP PUT

I am working on a driver for a Rain Bird sprinkler controller. The controller expects a POST that contains an encrypted "application/octet-stream" payload. It sends a similar payload back. I am starting with a very simple test of sending a request for the controller version to get the plumbing all working correctly. I can successfully send the encrypted message but resp does not seem to come back correctly.

Rather than data in the resp it returns the following - <org.apache.http.conn.EofSensorInputStream@14852be wrappedStream=null selfClosed=true eofWatcher=ResponseEntityProxy{[Content-Type: application/octet-stream,Content-Length: 128,Chunked: false]}>

Unsurprisingly I am not able to pull any usable data out of it. Does anyone have any thoughts on why this is happening? I have a fully working Python application that sends and receives correctly. I am sending the exact same data in both so this seems to be something in the hubitat HttpPost library with how it is receiving the incoming data or I should be catching it some other way than result=resp.data.

Any thoughts???

the code looks like this

def GetVersion() {
request_id = Math.floor((new Date()).getTime()/1000);

//This is the command to get controller version
strSendData = /{"id":$request_id,"jsonrpc":"2.0","method":"tunnelSip","params":{"data":"02","length":1}}/

//encrypt payload with shared password
byte [] baEncryptedSendData = encrypt (strSendData, SprinklerPassword)
if (isDebug) { log.debug "encrypt return = " + baEncryptedSendData.encodeHex().toString() }  

 def postParams = [
uri: "http://$SprinklerIP/stick",
    contentType: "application/octet-stream",
    requestContentType: "application/octet-stream",
    headers: [
    "Accept-Language": "en",
    "Accept-Encoding": "gzip, deflate",
    "User-Agent": "RainBird/2.0 CFNetwork/811.5.4 Darwin/16.7.0",
    "Accept": "*/*",
    "Connection": "keep-alive"
    ],
	body : baEncryptedSendData
]

    httpPost(postParams) { resp ->
    
    result = resp.data

    log.debug "Response Status: ${resp.status}"
    log.debug "Received Headers: ${resp.getAllHeaders()}"
    log.debug "resp.data read allowed: ${resp.data.isReadAllowed ()}"    
    log.debug "result : ${result}"
    log.debug "result dump: ${result.dump()}"
        
   }
    
   if (isDebug) { log.debug "Return from rainbird controller = " + result.dump() }  

}

The log.debug lines above return

2020-06-30 10:25:38.607 am debugReturn from rainbird controller = <org.apache.http.conn.EofSensorInputStream@14852be wrappedStream=null selfClosed=true eofWatcher=ResponseEntityProxy{[Content-Type: application/octet-stream,Content-Length: 128,Chunked: false]}>

app:1652020-06-30 10:25:38.600 am debugresult dump: <org.apache.http.conn.EofSensorInputStream@14852be wrappedStream=null selfClosed=true eofWatcher=ResponseEntityProxy{[Content-Type: application/octet-stream,Content-Length: 128,Chunked: false]}>

app:1652020-06-30 10:25:38.594 am debugresult : n����?��@r����D$���Lj�*�W0�:Y�p\@t�d�2Is'�ڮ��mA���E�v,orв�4Yp�p��ݺ�F��=vS>���u�Qv_��������ox��.e��=���\

app:1652020-06-30 10:25:38.590 am debugresp.data read allowed: true

app:1652020-06-30 10:25:38.585 am debugReceived Headers: [Connection: Close, Content-type: application/octet-stream, Content-length: 128]

app:1652020-06-30 10:25:38.583 am debugResponse Status: 200

I also tried the following

Wrote a quick test harness in node.js that records an incoming POST to a file
Redirected my hubitat code to send to the test harness
Sent the resultant recorded binary file from postman to the Rain Bird device with the same headers set
The Rain Bird returns data to postman with no issue
This would appear to verify there is nothing wrong with the encrypted payload data

So either the hubitat HTTP POST code has some kind of bug with returned "application/octet-stream" data or I ma missing something super obvious :slight_smile:

You are getting an InputStream back because the server is responding with binary data instead of text. What are you trying to do with the response? If you just want the bytes you can do something like this:

byte[] responseBytes = resp.data.bytes

Thanks. I was confused because the documentation said the return would be a HttpResponseDecorator object. I'll give this a whirl.

Yes, that is what you are getting, that is what resp is in your code. you are then calling getData() :

on that object.

http://javadox.com/org.codehaus.groovy.modules.http-builder/http-builder/0.6/groovyx/net/http/HttpResponseDecorator.html#getData()