Search in sources :

Example 16 with HTTPResult

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

the class ValidationEngine method handleOutput.

public void handleOutput(Resource r, String output, String version) throws FHIRException, IOException {
    if (output.startsWith("http://")) {
        ByteArrayOutputStream bs = new ByteArrayOutputStream();
        handleOutputToStream(r, output, bs, version);
        SimpleHTTPClient http = new SimpleHTTPClient();
        HTTPResult res = http.post(output, "application/fhir+xml", bs.toByteArray(), "application/fhir+xml");
        res.checkThrowException();
    } else {
        FileOutputStream s = new FileOutputStream(output);
        handleOutputToStream(r, output, s, version);
    }
}
Also used : HTTPResult(org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult)

Example 17 with HTTPResult

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

the class Scanner method download.

protected void download(String address, String filename) throws IOException {
    SimpleHTTPClient http = new SimpleHTTPClient();
    HTTPResult res = http.get(address);
    res.checkThrowException();
    TextFile.bytesToFile(res.getContent(), filename);
}
Also used : HTTPResult(org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult) SimpleHTTPClient(org.hl7.fhir.utilities.SimpleHTTPClient)

Example 18 with HTTPResult

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

the class ValidationTests method fetchRaw.

@Override
public byte[] fetchRaw(IResourceValidator validator, String source) throws MalformedURLException, IOException {
    SimpleHTTPClient http = new SimpleHTTPClient();
    HTTPResult res = http.get(source);
    res.checkThrowException();
    return res.getContent();
}
Also used : HTTPResult(org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult)

Example 19 with HTTPResult

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

the class PackageVisitor method processFeed.

private void processFeed(Set<String> list, String str) throws IOException, ParserConfigurationException, SAXException {
    System.out.println("Feed " + str);
    try {
        SimpleHTTPClient fetcher = new SimpleHTTPClient();
        HTTPResult res = fetcher.get(str + "?nocache=" + System.currentTimeMillis());
        res.checkThrowException();
        Document xml = XMLUtil.parseToDom(res.getContent());
        for (Element channel : XMLUtil.getNamedChildren(xml.getDocumentElement(), "channel")) {
            for (Element item : XMLUtil.getNamedChildren(channel, "item")) {
                String pid = XMLUtil.getNamedChildText(item, "title");
                if (pid.contains("#")) {
                    list.add(pid.substring(0, pid.indexOf("#")));
                }
            }
        }
    } catch (Exception e) {
        System.out.println("   " + e.getMessage());
    }
}
Also used : HTTPResult(org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult) SimpleHTTPClient(org.hl7.fhir.utilities.SimpleHTTPClient) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 20 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)

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