use of org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult in project org.hl7.fhir.core by hapifhir.
the class FilesystemPackageCacheManager method fetchFromUrlSpecific.
private InputStream fetchFromUrlSpecific(String source, boolean optional) throws FHIRException {
try {
SimpleHTTPClient http = new SimpleHTTPClient();
HTTPResult res = http.get(source);
res.checkThrowException();
return new ByteArrayInputStream(res.getContent());
} catch (Exception e) {
if (optional)
return null;
else
throw new FHIRException("Unable to fetch: " + e.getMessage(), e);
}
}
use of org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult in project org.hl7.fhir.core by hapifhir.
the class SimpleHTTPClient method post.
public HTTPResult post(String url, String contentType, byte[] content, String accept) throws IOException {
URL u = new URL(url);
HttpURLConnection c = (HttpURLConnection) u.openConnection();
c.setDoOutput(true);
c.setDoInput(true);
c.setRequestMethod("POST");
c.setRequestProperty("Content-type", contentType);
if (accept != null) {
c.setRequestProperty("Accept", accept);
}
setHeaders(c);
c.getOutputStream().write(content);
c.getOutputStream().close();
return new HTTPResult(url, c.getResponseCode(), c.getResponseMessage(), c.getRequestProperty("Content-Type"), TextFile.streamToBytes(c.getResponseCode() >= 400 ? c.getErrorStream() : c.getInputStream()));
}
use of org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult in project org.hl7.fhir.core by hapifhir.
the class IgLoader method fetchFromUrlSpecific.
private byte[] fetchFromUrlSpecific(String source, String contentType, boolean optional, List<String> errors) throws FHIRException, IOException {
try {
SimpleHTTPClient http = new SimpleHTTPClient();
try {
// try with cache-busting option and then try withhout in case the server doesn't support that
HTTPResult res = http.get(source + "?nocache=" + System.currentTimeMillis(), contentType);
res.checkThrowException();
return res.getContent();
} catch (Exception e) {
HTTPResult res = http.get(source, contentType);
res.checkThrowException();
return res.getContent();
}
} catch (IOException e) {
if (errors != null) {
errors.add("Error accessing " + source + ": " + e.getMessage());
}
if (optional)
return null;
else
throw e;
}
}
Aggregations