private static void handleHttpException(HttpException ex, boolean ignore404) { if ( ex.getResponseCode() == HttpSC.NOT_FOUND_404 && ignore404 ) return ; throw ex; }
private static void handleHttpException(HttpException ex, boolean ignore404) { if ( ex.getResponseCode() == HttpSC.NOT_FOUND_404 && ignore404 ) return ; throw ex; }
protected void doDelete(String url) { try { HttpOp.execHttpDelete(url, noResponse, null, null, this.authenticator) ; } catch (HttpException ex) { if ( ex.getResponseCode() == HttpSC.NOT_FOUND_404 ) return ; } }
protected boolean doHead(String url) { try { HttpOp.execHttpHead(url, WebContent.defaultGraphAcceptHeader, noResponse, client, null) ; return true ; } catch (HttpException ex) { if ( ex.getResponseCode() == HttpSC.NOT_FOUND_404 ) return false ; throw ex ; } }
protected void doDelete(String url) { try { HttpOp.execHttpDelete(url, noResponse, client, null) ; } catch (HttpException ex) { if ( ex.getResponseCode() == HttpSC.NOT_FOUND_404 ) return ; } }
protected Graph doGet(String url) { HttpCaptureResponse<Graph> graph = HttpResponseLib.graphHandler() ; try { HttpOp.execHttpGet(url, graphAcceptHeader, graph, client, null) ; } catch (HttpException ex) { if ( ex.getResponseCode() == HttpSC.NOT_FOUND_404 ) return null ; throw ex ; } return graph.get() ; }
public static TypedInputStream execHttpPostStream(String url, String contentType, String content, String acceptType, HttpClient httpClient, HttpContext httpContext) { CaptureInput handler = new CaptureInput(); try { execHttpPost(url, contentType, content, acceptType, handler, httpClient, httpContext); } catch (HttpException ex) { if (ex.getResponseCode() == HttpSC.NOT_FOUND_404) return null; throw ex; } return handler.get(); }
/** Assert that an {@code HttpException} ias an authorization failure. * This is normally 403. 401 indicates no retry with credentials. */ public static HttpException assertAuthHttpException(HttpException ex) { int rc = ex.getResponseCode(); Assert.assertTrue(rc == HttpSC.FORBIDDEN_403 || rc == HttpSC.UNAUTHORIZED_401 ); return ex; } }
private void gspHttp(RDFConnection conn, int statusCode, String graphName) { try { gsp(conn, graphName); if ( statusCode < 200 && statusCode > 299 ) fail("Should have responded with "+statusCode); } catch (HttpException ex) { assertEquals(statusCode, ex.getResponseCode()); } }
private void gspHttp(int statusCode, String user, String password, String queryString) { try { gsp(user, password, queryString); if ( statusCode < 200 && statusCode > 299 ) fail("Should have responded with "+statusCode); } catch (HttpException ex) { assertEquals(statusCode, ex.getResponseCode()); } }
@Test public void access_deny_ds() { try( TypedInputStream in = HttpOp.execHttpGet(serverURL+"ds") ) { fail("Didn't expect to succeed"); } catch (HttpException ex) { if ( ex.getResponseCode() != HttpSC.UNAUTHORIZED_401 ) throw ex; } }
@Test public void access_deny_nowhere() { try( TypedInputStream in = HttpOp.execHttpGet(serverURL+"nowhere") ) { fail("Didn't expect to succeed"); } catch (HttpException ex) { if ( ex.getResponseCode() != HttpSC.UNAUTHORIZED_401 ) throw ex; } }
@Test public void access_service_ctl_userX() { // userX -- can't login, not allowed. HttpClient hc = LibSec.httpClient(authSetupX); try( TypedInputStream in = HttpOp.execHttpGet(serverURL+"ctl", null, hc, null) ) { fail("Didn't expect to succeed"); } catch (HttpException ex) { if ( ex.getResponseCode() != HttpSC.UNAUTHORIZED_401) throw ex; } } }
@Test public void access_server() { try( TypedInputStream in = HttpOp.execHttpGet(serverURL) ) { assertNotNull(in); fail("Didn't expect to succeed"); } catch (HttpException ex) { // 404 is OK - no static file area. if ( ex.getResponseCode() != HttpSC.NOT_FOUND_404 ) throw ex; } }
@Test public void access_server() { try( TypedInputStream in = HttpOp.execHttpGet(serverURL) ) { assertNotNull(in); fail("Didn't expect to succeed"); } catch (HttpException ex) { // 404 is OK - no static file area. if ( ex.getResponseCode() != HttpSC.NOT_FOUND_404 ) throw ex; } }
@Test public void access_service_ctl_user2() { // user2 -- can login, not allowed. HttpClient hc = LibSec.httpClient(authSetup2); try( TypedInputStream in = HttpOp.execHttpGet(serverURL+"ctl", null, hc, null) ) { fail("Didn't expect to succeed"); } catch (HttpException ex) { if ( ex.getResponseCode() != HttpSC.FORBIDDEN_403) throw ex; } }
@Test public void access_service_ctl_user2() { // user2 -- can login, not allowed. HttpClient hc = LibSec.httpClient(authSetup2); try( TypedInputStream in = HttpOp.execHttpGet(serverURL+"ctl", null, hc, null) ) { fail("Didn't expect to succeed"); } catch (HttpException ex) { if ( ex.getResponseCode() != HttpSC.FORBIDDEN_403) throw ex; } }
@Test public void access_allow_nowhere() { HttpClient hc = LibSec.httpClient(authSetup1); HttpCaptureResponse<TypedInputStream> handler = new CaptureInput(); try( TypedInputStream in = HttpOp.execHttpGet(serverURL+"nowhere", null, hc, null) ) { // null for 404. assertNull(in); } catch (HttpException ex) { if ( ex.getResponseCode() != HttpSC.NOT_FOUND_404) throw ex; } }
@Test public void access_serverNone() { test("testing/Access/config-server-0.ttl", fusekiServer -> { // Server access. try (TypedInputStream in = HttpOp.execHttpGet(serverURL(fusekiServer))) { assertNotNull(in); } catch (HttpException ex) { // 404 is OK - no static file area. if ( ex.getResponseCode() != HttpSC.NOT_FOUND_404 ) throw ex; } }); }
@Test public void access_serverAny_user1() { test("testing/Access/config-server-1.ttl", fusekiServer->{ // Must be logged in. HttpClient hc = LibSec.httpClient(authSetup1(fusekiServer)); try( TypedInputStream in = HttpOp.execHttpGet(serverURL(fusekiServer), null, hc, null) ) { assertNull(in); } catch (HttpException ex) { // 404 is OK - no static file area. if ( ex.getResponseCode() != HttpSC.NOT_FOUND_404 ) throw ex; } }); }