Search in sources :

Example 6 with SimpleHTTPClient

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

the class ProfileComparer method cachedFetch.

private String cachedFetch(String id, String source) throws IOException {
    String tmpDir = System.getProperty("java.io.tmpdir");
    String local = Utilities.path(tmpDir, id);
    File f = new File(local);
    if (f.exists())
        return TextFile.fileToString(f);
    SimpleHTTPClient http = new SimpleHTTPClient();
    HTTPResult res = http.get(source);
    res.checkThrowException();
    String result = TextFile.bytesToString(res.getContent());
    TextFile.stringToFile(result, f);
    return result;
}
Also used : HTTPResult(org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult) SimpleHTTPClient(org.hl7.fhir.utilities.SimpleHTTPClient) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile)

Example 7 with SimpleHTTPClient

use of org.hl7.fhir.utilities.SimpleHTTPClient 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 8 with SimpleHTTPClient

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

the class FilesystemPackageCacheManager method loadFromBuildServer.

private void loadFromBuildServer() throws IOException {
    SimpleHTTPClient http = new SimpleHTTPClient();
    http.trustAllhosts();
    HTTPResult res = http.get("https://build.fhir.org/ig/qas.json?nocache=" + System.currentTimeMillis());
    res.checkThrowException();
    buildInfo = (JsonArray) new com.google.gson.JsonParser().parse(TextFile.bytesToString(res.getContent()));
    List<BuildRecord> builds = new ArrayList<>();
    for (JsonElement n : buildInfo) {
        JsonObject o = (JsonObject) n;
        if (o.has("url") && o.has("package-id") && o.get("package-id").getAsString().contains(".")) {
            String u = o.get("url").getAsString();
            if (u.contains("/ImplementationGuide/"))
                u = u.substring(0, u.indexOf("/ImplementationGuide/"));
            builds.add(new BuildRecord(u, o.get("package-id").getAsString(), getRepo(o.get("repo").getAsString()), readDate(o.get("date").getAsString())));
        }
    }
    Collections.sort(builds, new BuildRecordSorter());
    for (BuildRecord bld : builds) {
        if (!ciList.containsKey(bld.getPackageId())) {
            ciList.put(bld.getPackageId(), "https://build.fhir.org/ig/" + bld.getRepo());
        }
    }
    // whether it succeeds or not
    buildLoaded = true;
}
Also used : HTTPResult(org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult) SimpleHTTPClient(org.hl7.fhir.utilities.SimpleHTTPClient) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject)

Example 9 with SimpleHTTPClient

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

the class NpmPackage method fromUrl.

public static NpmPackage fromUrl(String source) throws IOException {
    SimpleHTTPClient fetcher = new SimpleHTTPClient();
    HTTPResult res = fetcher.get(source + "?nocache=" + System.currentTimeMillis());
    res.checkThrowException();
    return fromPackage(new ByteArrayInputStream(res.getContent()));
}
Also used : HTTPResult(org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult) SimpleHTTPClient(org.hl7.fhir.utilities.SimpleHTTPClient) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 10 with SimpleHTTPClient

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

the class PackageClient method fetchUrl.

private InputStream fetchUrl(String source, String accept) throws IOException {
    SimpleHTTPClient http = new SimpleHTTPClient();
    HTTPResult res = http.get(source, accept);
    res.checkThrowException();
    return new ByteArrayInputStream(res.getContent());
}
Also used : HTTPResult(org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult) SimpleHTTPClient(org.hl7.fhir.utilities.SimpleHTTPClient) ByteArrayInputStream(java.io.ByteArrayInputStream)

Aggregations

HTTPResult (org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult)20 SimpleHTTPClient (org.hl7.fhir.utilities.SimpleHTTPClient)17 ByteArrayInputStream (java.io.ByteArrayInputStream)6 IOException (java.io.IOException)5 FHIRException (org.hl7.fhir.exceptions.FHIRException)4 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 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 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 SAXException (org.xml.sax.SAXException)1