Search in sources :

Example 26 with TypedInputStream

use of org.apache.jena.atlas.web.TypedInputStream in project jena by apache.

the class TestHttpOperations method query_by_post_2.

@Test
public void query_by_post_2() {
    String qs = Convert.encWWWForm("ASK{}");
    String u = serviceQuery() + "?query=" + qs;
    try (TypedInputStream in = HttpOp.execHttpPostStream(u, null, null)) {
        Assert.assertNotNull(in);
    }
}
Also used : TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) Test(org.junit.Test)

Example 27 with TypedInputStream

use of org.apache.jena.atlas.web.TypedInputStream in project jena by apache.

the class TestFusekiTestAuth method testServer_auth.

@Test
public void testServer_auth() {
    BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
    Credentials credentials = new UsernamePasswordCredentials(USER, PASSWORD);
    credsProvider.setCredentials(AuthScope.ANY, credentials);
    HttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
    try (TypedInputStream in = HttpOp.execHttpGet(FusekiTestAuth.urlDataset(), "*/*", client, null)) {
    }
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpClient(org.apache.http.client.HttpClient) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Test(org.junit.Test)

Example 28 with TypedInputStream

use of org.apache.jena.atlas.web.TypedInputStream in project jena by apache.

the class TestAdmin method list_datasets_2.

@Test
public void list_datasets_2() {
    try (TypedInputStream in = execHttpGet(ServerCtl.urlRoot() + "$/" + opDatasets)) {
        assertEqualsIgnoreCase(WebContent.contentTypeJSON, in.getContentType());
        JsonValue v = JSON.parseAny(in);
        assertNotNull(v.getAsObject().get("datasets"));
        checkJsonDatasetsAll(v);
    }
}
Also used : JsonValue(org.apache.jena.atlas.json.JsonValue) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) Test(org.junit.Test)

Example 29 with TypedInputStream

use of org.apache.jena.atlas.web.TypedInputStream in project jena by apache.

the class JenaIOEnvironment method createLocationMapper.

/** Search a path (which is delimited by ";" because ":" is used in URIs)
     *  to find a description of a LocationMapper, then create and return a
     *  LocationMapper based on the description.
     */
public static LocationMapper createLocationMapper(String configPath) {
    if (configPath == null || configPath.length() == 0) {
        log.warn("Null configuration");
        return null;
    }
    // Make a file manager to look for the location mapping file
    StreamManager smgr = new StreamManager();
    smgr.addLocator(new LocatorFile());
    smgr.addLocator(new LocatorClassLoader(smgr.getClass().getClassLoader()));
    try {
        String uriConfig = null;
        TypedInputStream in = null;
        StringTokenizer pathElems = new StringTokenizer(configPath, AdapterFileManager.PATH_DELIMITER);
        while (pathElems.hasMoreTokens()) {
            String uri = pathElems.nextToken();
            if (uri == null || uri.length() == 0)
                break;
            in = smgr.openNoMapOrNull(uri);
            if (in != null) {
                uriConfig = uri;
                break;
            }
        }
        if (in == null) {
            log.debug("Failed to find configuration: " + configPath);
            return null;
        }
        String syntax = FileUtils.guessLang(uriConfig);
        Model model = ModelFactory.createDefaultModel();
        model.read(in, uriConfig, syntax);
        return processConfig(model);
    } catch (JenaException ex) {
        LoggerFactory.getLogger(LocationMapper.class).warn("Error in configuration file: " + ex.getMessage());
        return new LocationMapper();
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) StringTokenizer(java.util.StringTokenizer) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream)

Example 30 with TypedInputStream

use of org.apache.jena.atlas.web.TypedInputStream in project jena by apache.

the class LocatorFTP method performOpen.

@Override
public TypedInputStream performOpen(String uri) {
    if (uri.startsWith("ftp://")) {
        try {
            URL url = new URL(uri);
            InputStream in = url.openStream();
            ContentType ct = RDFLanguages.guessContentType(uri);
            return new TypedInputStream(in, ct);
        } catch (MalformedURLException ex) {
            throw new RiotException("Bad FTP URL: " + uri, ex);
        } catch (IOException ex) {
            // This includes variations on "not found"
            IO.exception(ex);
        }
    }
    return null;
}
Also used : MalformedURLException(java.net.MalformedURLException) ContentType(org.apache.jena.atlas.web.ContentType) RiotException(org.apache.jena.riot.RiotException) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) URL(java.net.URL)

Aggregations

TypedInputStream (org.apache.jena.atlas.web.TypedInputStream)32 Test (org.junit.Test)11 BaseTest (org.apache.jena.atlas.junit.BaseTest)8 HttpException (org.apache.jena.atlas.web.HttpException)7 ContentType (org.apache.jena.atlas.web.ContentType)6 InputStream (java.io.InputStream)4 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)4 HttpClient (org.apache.http.client.HttpClient)4 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)4 IOException (java.io.IOException)3 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 JsonValue (org.apache.jena.atlas.json.JsonValue)3 HttpEntity (org.apache.http.HttpEntity)2 Credentials (org.apache.http.auth.Credentials)2 FusekiTestAuth.assertAuthHttpException (org.apache.jena.fuseki.embedded.FusekiTestAuth.assertAuthHttpException)2 Model (org.apache.jena.rdf.model.Model)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 NoSuchFileException (java.nio.file.NoSuchFileException)1 AccessControlException (java.security.AccessControlException)1