Matt Clark Matt Clark - 4 months ago 15
Java Question

ant's get task throws IOException

I am setting up an ant task to poll and endpoint of my application to get the health status, the output of this task should simply display the json output from the endpoint, here is what I have tried

<target name="status">

<get src="http://127.0.0.1:8840/-/system/get_health" dest="${dir.tmp}/status" />
<loadfile property="status" srcFile="${dir.tmp}/status" />
<echo message="${status}" />
</target>


The above is throwing the following error on the
get



[get] Getting: http://127.0.0.1:8840/-/system/get_health

[get] To: C:\path\to\build\tmp\status

[get] Error opening connection java.io.IOException: Invalid Http response

[get] Can't get http://127.0.0.1:8840/-/system/get_health to C:\path\to\build\tmp\status


What exactly is the format that
get
is expecting to get back?

As far as I know, this is a plain text output, there are no headers.

I can view the output with both curl, and using chrome.

$curl http://127.0.0.1:8840/-/system/get_health
{"status": "HEALTHY"}


Is there any way to ignore this error and save the output anyway? Or is there another way to do this?

Edit

Running with

$ant status -debug


provides no useful output other then that already posted.

$curl -v http://127.0.0.1:8840/-/system/get_health
* STATE: INIT => CONNECT handle 0x6000578b0; line 1108 (connection #-5000)
* Added connection 0. The cache now contains 1 members
* Trying 127.0.0.1...
* STATE: CONNECT => WAITCONNECT handle 0x6000578b0; line 1161 (connection #0)
* Connected to 127.0.0.1 (127.0.0.1) port 8840 (#0)
* STATE: WAITCONNECT => SENDPROTOCONNECT handle 0x6000578b0; line 1260 (connection #0)
* STATE: SENDPROTOCONNECT => DO handle 0x6000578b0; line 1278 (connection #0)
> GET /-/system/get_health HTTP/1.1
> Host: 127.0.0.1:8840
> User-Agent: curl/7.48.0
> Accept: */*
>
* STATE: DO => DO_DONE handle 0x6000578b0; line 1357 (connection #0)
* STATE: DO_DONE => WAITPERFORM handle 0x6000578b0; line 1484 (connection #0)
* STATE: WAITPERFORM => PERFORM handle 0x6000578b0; line 1494 (connection #0)
* Increasing bytecount by 23 from hbuflen
{"status": "HEALTHY"}
* nread <= 0, server closed connection, bailing
* STATE: PERFORM => DONE handle 0x6000578b0; line 1652 (connection #0)
* Curl_done
* Connection #0 to host 127.0.0.1 left intact
* Expire cleared

Answer

Interestingly, this was poor execution in the web socket handler I am using, in that it never actually returned the status line in the response.

I had to drop down to using netcat to see that the raw data from the server :

$ echo -e "GET /-/system/get_health HTTP/1.1\n\n" | nc 127.0.0.1 8840
{"status": "HEALTHY"}
$

Was not as it should be to fit proper HTTP spec

$ echo -e "GET /-/system/get_health HTTP/1.1\n\n" | nc 127.0.0.1 8840
HTTP/1.1 200 OK

{"status": "HEALTHY"}
$

This was strange in that both chrome and curl seemed to blindly ignore it.

After this was fixed, ant had no problems parsing the response.