Matt Clark Matt Clark - 1 year ago 119
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="" dest="${dir.tmp}/status" />
<loadfile property="status" srcFile="${dir.tmp}/status" />
<echo message="${status}" />

The above is throwing the following error on the

[get] Getting:

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

[get] Error opening connection Invalid Http response

[get] Can't get to C:\path\to\build\tmp\status

What exactly is the format that
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.

{"status": "HEALTHY"}

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


Running with

$ant status -debug

provides no useful output other then that already posted.

$curl -v
* STATE: INIT => CONNECT handle 0x6000578b0; line 1108 (connection #-5000)
* Added connection 0. The cache now contains 1 members
* Trying
* STATE: CONNECT => WAITCONNECT handle 0x6000578b0; line 1161 (connection #0)
* Connected to ( 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:
> 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 left intact
* Expire cleared

Answer Source

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 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 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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download