private static void handleHttpException(HttpException ex, boolean ignore404) { if ( ex.getResponseCode() == HttpSC.NOT_FOUND_404 && ignore404 ) return ; throw ex; }
public void sync() { try { checkDeltaConnection(); PatchLogInfo logInfo = getPatchLogInfo(); sync(logInfo); } catch (HttpException ex) { if ( ex.getResponseCode() == -1 ) throw new HttpException(HttpSC.SERVICE_UNAVAILABLE_503, HttpSC.getMessage(HttpSC.SERVICE_UNAVAILABLE_503), ex.getMessage()); throw ex; } }
private QueryExceptionHTTP rewrap(HttpException httpEx) { // The historical contract of HTTP Queries has been to throw QueryExceptionHTTP however using the standard // ARQ HttpOp machinery we use these days means the internal HTTP errors come back as HttpException // Therefore we need to wrap appropriately responseCode = httpEx.getResponseCode(); if (responseCode != -1) { // Was an actual HTTP error String responseLine = httpEx.getStatusLine() != null ? httpEx.getStatusLine() : "No Status Line"; return new QueryExceptionHTTP(responseCode, "HTTP " + responseCode + " error making the query: " + responseLine, httpEx); } else if (httpEx.getMessage() != null) { // Some non-HTTP error with a valid message e.g. Socket Communications failed, IO error return new QueryExceptionHTTP(responseCode, "Unexpected error making the query: " + httpEx.getMessage(), httpEx); } else if (httpEx.getCause() != null) { // Some other error with a cause e.g. Socket Communications failed, IO error return new QueryExceptionHTTP(responseCode, "Unexpected error making the query, see cause for further details", httpEx); } else { // Some other error with no message and no further cause return new QueryExceptionHTTP(responseCode, "Unexpected error making the query", httpEx); } }
public QueryExceptionHTTP(int responseCode, String message, final HttpException ex) { this(responseCode, message, ex.getCause()); this.statusLine = ex.getStatusLine(); this.response = ex.getResponse(); }
return JSON.parseAny(x) ; } catch (HttpException ex) { if ( HttpSC.BAD_REQUEST_400 == ex.getResponseCode() ) { throw new DeltaBadRequestException(ex.getMessage());
private static void expectQuery(Runnable action, int expected) { try { action.run(); throw new HttpException("action completed"); } catch (QueryExceptionHTTP ex) { if ( ex.getResponseCode() != expected ) throw ex; } }
} catch (HttpException httpEx) { responseCode = httpEx.getResponseCode(); throw new QueryExceptionHTTP(responseCode, "Error making the query, see cause for details", httpEx.getCause());
public static RuntimeException makeHumanFriendly(Exception e) { RuntimeException result; if(e instanceof HttpException) { HttpException x = (HttpException)e; result = new HttpException(x.getResponse(), e); } else if(e instanceof QueryExceptionHTTP) { QueryExceptionHTTP x = (QueryExceptionHTTP)e; result = new QueryExceptionHTTP(x.getResponseMessage() + " " + x.getMessage(), e); } else { result = new RuntimeException(e); } return result; } }
@Override protected Graph getVocabulary(final String url) { final Graph graph = createDefaultGraph(); try { RDFParser.source(url).httpAccept("application/ld+json").parse(graph); } catch (final HttpException ex) { LOGGER.warn("Could not fetch {}: {}", url, ex.getMessage()); assumeTrue(false, "Error fetching the URL (" + url + "): skip the test"); } return graph; }
@Override public void write(List<? extends Entry<? extends Node, ? extends Diff<? extends DatasetGraph>>> items) throws Exception { List<Diff<? extends DatasetGraph>> diffs = Lists.newArrayList(); for(Entry<? extends Node, ? extends Diff<? extends DatasetGraph>> item : items) { Diff<? extends DatasetGraph> diff = item.getValue(); diffs.add(diff); } Diff<DatasetGraph> diff = UpdateDiffUtils.combineDatasetGraph(diffs); try { UpdateExecutionUtils.executeUpdateDatasetGraph(uef, diff); } catch(Exception e) { if(e instanceof HttpException) { HttpException x = (HttpException)e; String response = x.getResponse(); throw new RuntimeException(response, e); } } }
} catch (HttpException ex) { if ( ex.getMessage() == null ) ServletOps.responseSendError(response, ex.getResponseCode()); else ServletOps.responseSendError(response, ex.getResponseCode(), ex.getMessage()); } catch (RuntimeIOException ex) { log.warn(format("[%d] Runtime IO Exception (client left?) RC = %d : %s", id, HttpSC.INTERNAL_SERVER_ERROR_500, ex.getMessage()), ex) ;
private static boolean isFuseki(HttpOptions request, HttpClient httpClient, HttpContext httpContext) { try { HttpResponse response = httpClient.execute(request); // Fuseki does not send "Server" in release mode. // (best practice). // All we can do is try for the "Fuseki-Request-ID" String reqId = safeGetHeader(response, "Fuseki-Request-ID"); if ( reqId != null ) return true; // If returning "Server" String serverIdent = safeGetHeader(response, "Server"); if ( serverIdent != null ) { Log.debug(ARQ.getHttpRequestLogger(), "Server: "+serverIdent); boolean isFuseki = serverIdent.startsWith("Apache Jena Fuseki"); if ( !isFuseki ) isFuseki = serverIdent.toLowerCase().contains("fuseki"); return isFuseki; } return false; } catch (IOException ex) { throw new HttpException("Failed to check for a Fuseki server", ex); } }
} catch (HttpException httpEx) { if (httpEx.getResponseCode() == 414) return execPost(); throw httpEx; responseCode = httpEx.getResponseCode(); throw new QueryExceptionHTTP(responseCode, "Error making the query, see cause for details", httpEx.getCause());
static void ping(DeltaLink dLink) { Objects.requireNonNull(dLink); try { dLink.ping(); } catch (HttpException ex) { Throwable ex2 = ex; if ( ex.getCause() != null ) ex2 = ex.getCause(); throw new CmdException(ex2.getMessage()); } catch (JsonException ex) { throw new CmdException("Not an RDF Patch server"); } }
@Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { UpdateProcessor updateProcessor = uef.createUpdateProcessor(updateRequest); try { updateProcessor.execute(); } catch(Exception e) { if(e instanceof HttpException) { HttpException x = (HttpException)e; logger.debug(x.getResponse()); } throw e; } return RepeatStatus.FINISHED; } }
private static void handleHttpException(HttpException ex, boolean ignore404) { if ( ex.getResponseCode() == HttpSC.NOT_FOUND_404 && ignore404 ) return ; throw ex; }
} catch (HttpException ex) { if ( ex.getMessage() == null ) ServletOps.responseSendError(response, ex.getResponseCode()); else ServletOps.responseSendError(response, ex.getResponseCode(), ex.getMessage()); } catch (RuntimeIOException ex) { log.warn(format("[%d] Runtime IO Exception (client left?) RC = %d : %s", id, HttpSC.INTERNAL_SERVER_ERROR_500, ex.getMessage()), ex) ;
private static boolean isFuseki(HttpOptions request, HttpClient httpClient, HttpContext httpContext) { try { HttpResponse response = httpClient.execute(request); // Fuseki does not send "Server" in release mode. // (best practice). // All we can do is try for the "Fuseki-Request-ID" String reqId = safeGetHeader(response, "Fuseki-Request-ID"); if ( reqId != null ) return true; // If returning "Server" String serverIdent = safeGetHeader(response, "Server"); if ( serverIdent != null ) { Log.debug(ARQ.getHttpRequestLogger(), "Server: "+serverIdent); boolean isFuseki = serverIdent.startsWith("Apache Jena Fuseki"); if ( !isFuseki ) isFuseki = serverIdent.toLowerCase().contains("fuseki"); return isFuseki; } return false; } catch (IOException ex) { throw new HttpException("Failed to check for a Fuseki server", 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 ; } }