My colleague suggested removing content-type request header. From curl the connection to oData worked, comparing the request headers.
Curl displayed:
> GET /sites/team-sites/operations/_vti_bin/listdata.svc/UBCal?=3 HTTP/1.1
> Authorization: NTLM <redacted>
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Host: hostname
> Accept: */*
Java showed the following in the trace logs:
Accept: text/html, image/gif, image/jpeg, *;q=.2, */*; q=.2
I set the Accept request header to "*/*
" to the getAuthenticatedResponse method as follows:
//Added for oData to work
conn.setRequestProperty("Accept", "*/*");
InputStream stream = conn.getInputStream();
....
This resolved the 400 error and I get the feed from Sharepoint oData service. Seems like Java set some default request headers which interfered.