Search in sources :

Example 1 with HTTPResult

use of org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult in project org.hl7.fhir.core by hapifhir.

the class TerminologyCacheManager method fillCache.

private void fillCache(String source) throws IOException {
    try {
        System.out.println("Initialise terminology cache from " + source);
        SimpleHTTPClient http = new SimpleHTTPClient();
        HTTPResult res = http.get(source + "?nocache=" + System.currentTimeMillis());
        res.checkThrowException();
        unzip(new ByteArrayInputStream(res.getContent()), cacheFolder);
    } catch (Exception e) {
        System.out.println("No - can't initialise cache from " + source + ": " + e.getMessage());
    }
}
Also used : HTTPResult(org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult) SimpleHTTPClient(org.hl7.fhir.utilities.SimpleHTTPClient) ByteArrayInputStream(java.io.ByteArrayInputStream) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 2 with HTTPResult

use of org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult in project org.hl7.fhir.core by hapifhir.

the class TerminologyCacheManager method commit.

public void commit(String token) throws IOException {
    // create a zip of all the files
    ByteArrayOutputStream bs = new ByteArrayOutputStream();
    zipDirectory(bs);
    // post it to
    String url = "https://tx.fhir.org/post/tx-cache/" + ghOrg + "/" + ghRepo + "/" + ghBranch + ".zip";
    System.out.println("Sending tx-cache to " + url + " (" + Utilities.describeSize(bs.toByteArray().length) + ")");
    SimpleHTTPClient http = new SimpleHTTPClient();
    http.setUsername(token.substring(0, token.indexOf(':')));
    http.setPassword(token.substring(token.indexOf(':') + 1));
    // accept doesn't matter
    HTTPResult res = http.put(url, "application/zip", bs.toByteArray(), null);
    if (res.getCode() >= 300) {
        System.out.println("sending cache failed: " + res.getCode());
    } else {
        System.out.println("Sent cache");
    }
}
Also used : HTTPResult(org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult) SimpleHTTPClient(org.hl7.fhir.utilities.SimpleHTTPClient) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 3 with HTTPResult

use of org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult in project org.hl7.fhir.core by hapifhir.

the class IgLoader method fetchFromUrlSpecific.

private InputStream fetchFromUrlSpecific(String source, boolean optional) throws FHIRException, IOException {
    try {
        SimpleHTTPClient http = new SimpleHTTPClient();
        HTTPResult res = http.get(source + "?nocache=" + System.currentTimeMillis());
        res.checkThrowException();
        return new ByteArrayInputStream(res.getContent());
    } catch (IOException e) {
        if (optional)
            return null;
        else
            throw e;
    }
}
Also used : HTTPResult(org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult) SimpleHTTPClient(org.hl7.fhir.utilities.SimpleHTTPClient)

Example 4 with HTTPResult

use of org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult in project org.hl7.fhir.core by hapifhir.

the class ProfileLoader method loadProfileFromUrl.

private static byte[] loadProfileFromUrl(String src) throws FHIRException {
    try {
        SimpleHTTPClient http = new SimpleHTTPClient();
        HTTPResult res = http.get(src + "?nocache=" + System.currentTimeMillis());
        res.checkThrowException();
        return res.getContent();
    } catch (Exception e) {
        throw new FHIRException("Unable to find definitions at URL '" + src + "': " + e.getMessage(), e);
    }
}
Also used : HTTPResult(org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult) SimpleHTTPClient(org.hl7.fhir.utilities.SimpleHTTPClient) FHIRException(org.hl7.fhir.exceptions.FHIRException) FHIRException(org.hl7.fhir.exceptions.FHIRException) IOException(java.io.IOException)

Example 5 with HTTPResult

use of org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult in project org.hl7.fhir.core by hapifhir.

the class JsonTrackingParser method fetchJson.

public static JsonObject fetchJson(String source) throws IOException {
    SimpleHTTPClient fetcher = new SimpleHTTPClient();
    HTTPResult res = fetcher.get(source + "?nocache=" + System.currentTimeMillis());
    res.checkThrowException();
    return parseJson(res.getContent());
}
Also used : HTTPResult(org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult) SimpleHTTPClient(org.hl7.fhir.utilities.SimpleHTTPClient)

Aggregations

HTTPResult (org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult)23 SimpleHTTPClient (org.hl7.fhir.utilities.SimpleHTTPClient)17 ByteArrayInputStream (java.io.ByteArrayInputStream)6 IOException (java.io.IOException)6 FHIRException (org.hl7.fhir.exceptions.FHIRException)4 HttpURLConnection (java.net.HttpURLConnection)3 URL (java.net.URL)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 MalformedURLException (java.net.MalformedURLException)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 ParseException (java.text.ParseException)1 HashMap (java.util.HashMap)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TextFile (org.hl7.fhir.utilities.TextFile)1