Search in sources :

Example 1 with HttpException

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

the class TestFusekiTestAuth method testServer_auth_bad_password.

@Test(expected = HttpException.class)
public void testServer_auth_bad_password() {
    BasicCredentialsProvider credsProv = new BasicCredentialsProvider();
    credsProv.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(USER, "WRONG"));
    HttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProv).build();
    try (TypedInputStream in = HttpOp.execHttpGet(FusekiTestAuth.urlDataset(), "*/*", client, null)) {
    } catch (HttpException ex) {
        throw assertAuthHttpException(ex);
    }
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpClient(org.apache.http.client.HttpClient) HttpException(org.apache.jena.atlas.web.HttpException) FusekiTestAuth.assertAuthHttpException(org.apache.jena.fuseki.embedded.FusekiTestAuth.assertAuthHttpException) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Test(org.junit.Test)

Example 2 with HttpException

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

the class TestFusekiTestServer method testServer_2.

@Test
public void testServer_2() {
    BasicCredentialsProvider credsProv = new BasicCredentialsProvider();
    credsProv.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("USER", "PASSWORD"));
    HttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProv).build();
    // No auth set - should work.
    try (TypedInputStream in = HttpOp.execHttpGet(FusekiTestServer.urlDataset(), "*/*")) {
    } catch (HttpException ex) {
        Assert.assertTrue(ex.getResponseCode() == HttpSC.FORBIDDEN_403 || ex.getResponseCode() == HttpSC.UNAUTHORIZED_401);
        throw ex;
    }
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpClient(org.apache.http.client.HttpClient) HttpException(org.apache.jena.atlas.web.HttpException) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 3 with HttpException

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

the class TestFusekiTestAuth method testServer_auth_bad_user.

@Test(expected = HttpException.class)
public void testServer_auth_bad_user() {
    BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
    Credentials credentials = new UsernamePasswordCredentials("USERUSER", PASSWORD);
    credsProvider.setCredentials(AuthScope.ANY, credentials);
    HttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
    try (TypedInputStream in = HttpOp.execHttpGet(FusekiTestAuth.urlDataset(), "*/*", client, null)) {
    } catch (HttpException ex) {
        throw assertAuthHttpException(ex);
    }
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpClient(org.apache.http.client.HttpClient) HttpException(org.apache.jena.atlas.web.HttpException) FusekiTestAuth.assertAuthHttpException(org.apache.jena.fuseki.embedded.FusekiTestAuth.assertAuthHttpException) 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 4 with HttpException

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

the class TestHttpOp method queryGet_02.

@Test(expected = HttpException.class)
public void queryGet_02() {
    try {
        // No query.
        TypedInputStream in = HttpOp.execHttpGet(queryURL + "?query=");
        IO.close(in);
    } catch (HttpException ex) {
        assertEquals(ex.getResponseCode(), HttpSC.BAD_REQUEST_400);
        throw ex;
    }
}
Also used : HttpException(org.apache.jena.atlas.web.HttpException) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 5 with HttpException

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

the class TestHttpOp method httpGet_02.

@Test(expected = HttpException.class)
public void httpGet_02() {
    try {
        TypedInputStream in = HttpOp.execHttpGet(urlRoot() + "does-not-exist");
        IO.close(in);
    } catch (HttpException ex) {
        assertEquals(HttpSC.NOT_FOUND_404, ex.getResponseCode());
        throw ex;
    }
}
Also used : HttpException(org.apache.jena.atlas.web.HttpException) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Aggregations

HttpException (org.apache.jena.atlas.web.HttpException)12 TypedInputStream (org.apache.jena.atlas.web.TypedInputStream)7 Test (org.junit.Test)4 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)3 HttpClient (org.apache.http.client.HttpClient)3 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 BaseTest (org.apache.jena.atlas.junit.BaseTest)2 FusekiTestAuth.assertAuthHttpException (org.apache.jena.fuseki.embedded.FusekiTestAuth.assertAuthHttpException)2 File (java.io.File)1 HttpEntity (org.apache.http.HttpEntity)1 HttpResponse (org.apache.http.HttpResponse)1 StatusLine (org.apache.http.StatusLine)1 Credentials (org.apache.http.auth.Credentials)1 HttpOptions (org.apache.http.client.methods.HttpOptions)1 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)1 FileEntity (org.apache.http.entity.FileEntity)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1