/** The HTTP error to be used when an error is triggered. */ public Response<?> createErrorResponse() { Response<?> call; try { call = errorFactory.call(); } catch (Exception e) { throw new IllegalStateException("Error factory threw an exception.", e); } if (call == null) { throw new IllegalStateException("Error factory returned null."); } if (call.isSuccessful()) { throw new IllegalStateException("Error factory returned successful response."); } return call; }
@Override public void onResponse(Call<R> call, Response<R> response) { if (response.isSuccessful()) { future.complete(response.body()); } else { future.completeExceptionally(new HttpException(response)); } }
@Override public void onResponse(Call<R> call, Response<R> response) { if (response.isSuccessful()) { future.complete(response.body()); } else { future.completeExceptionally(new HttpException(response)); } }
@Override public void onResponse(Call<T> call, Response<T> response) { if (response.isSuccessful()) { promise.success(response.body()); } else { promise.failure(new HttpException(response)); } }
@Override public void onResponse(Call<Page> call, Response<Page> response) { if (!response.isSuccessful()) { System.out.println(call.request().url() + ": failed: " + response.code()); return; } // Print this page's URL and title. Page page = response.body(); HttpUrl base = response.raw().request().url(); System.out.println(base + ": " + page.title); // Enqueue its links for visiting. for (String link : page.links) { HttpUrl linkUrl = base.resolve(link); if (linkUrl != null && fetchedUrls.add(linkUrl)) { crawlPage(linkUrl); } } }
@Override public void onResponse(Call<R> call, Response<R> response) { if (response.isSuccessful()) { future.complete(response.body()); } else { future.completeExceptionally(new HttpException(response)); } }
@GET @Timed @Path("/namespace/{namespace}") @ApiOperation(value = "Get all metrics of a namespace from node") @ApiResponses(value = { @ApiResponse(code = 404, message = "No such metric namespace") }) public MetricsSummaryResponse byNamespace(@ApiParam(name = "nodeId", value = "The id of the node whose metrics we want.", required = true) @PathParam("nodeId") String nodeId, @ApiParam(name = "namespace", required = true) @PathParam("namespace") String namespace) throws IOException, NodeNotFoundException { final Response<MetricsSummaryResponse> result = getResourceForNode(nodeId).byNamespace(namespace).execute(); if (result.isSuccessful()) { return result.body(); } else { throw new WebApplicationException(result.message(), BAD_GATEWAY); } } }
/** * Adds the issue from the response or throws an error if the request was unsuccessful. * * @param repository The issues repository * @param response The issue response to add * @param error String to print if unsuccessful * @return The added issue */ private Issue addIssueOrThrow(Repository repository, Response<Issue> response, @StringRes int error) { if (response.isSuccessful()) { return addIssue(repository, response.body()); } else { Toast.makeText(context, error, Toast.LENGTH_SHORT).show(); return Issue.builder().build(); } } }
@POST @Timed @Path("/multiple") @ApiOperation("Get the values of multiple metrics at once from node") @ApiResponses(value = { @ApiResponse(code = 400, message = "Malformed body") }) @NoAuditEvent("only used to get multiple metric values") public MetricsSummaryResponse multipleMetrics(@ApiParam(name = "nodeId", value = "The id of the node whose metrics we want.", required = true) @PathParam("nodeId") String nodeId, @ApiParam(name = "Requested metrics", required = true) @Valid @NotNull MetricsReadRequest request) throws IOException, NodeNotFoundException { final Response<MetricsSummaryResponse> result = getResourceForNode(nodeId).multipleMetrics(request).execute(); if (result.isSuccessful()) { return result.body(); } else { throw new WebApplicationException(result.message(), BAD_GATEWAY); } }
@GET @Timed @Path("/names") @ApiOperation(value = "Get all metrics keys/names from node") @RequiresPermissions(RestPermissions.METRICS_ALLKEYS) public MetricNamesResponse metricNames(@ApiParam(name = "nodeId", value = "The id of the node whose metrics we want.", required = true) @PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException { final Response<MetricNamesResponse> result = getResourceForNode(nodeId).metricNames().execute(); if (result.isSuccessful()) { return result.body(); } else { throw new WebApplicationException(result.message(), BAD_GATEWAY); } }
@GET @Path("{jobId}") @Timed @ApiOperation(value = "Get job with the given ID") @Produces(MediaType.APPLICATION_JSON) public SystemJobSummary getJob(@ApiParam(name = "jobId", required = true) @PathParam("jobId") String jobId) throws IOException { for (Map.Entry<String, Node> entry : nodeService.allActive().entrySet()) { final RemoteSystemJobResource remoteSystemJobResource = remoteInterfaceProvider.get(entry.getValue(), this.authenticationToken, RemoteSystemJobResource.class); try { final Response<SystemJobSummary> response = remoteSystemJobResource.get(jobId).execute(); if (response.isSuccessful()) { // Return early because there can be only one job with the same ID in the cluster. return response.body(); } } catch (IOException e) { LOG.warn("Unable to fetch system jobs from node {}:", entry.getKey(), e); } } throw new NotFoundException("System job with id " + jobId + " not found!"); }
@POST @Timed @ApiOperation(value = "Resume message processing on node") @Path("resume") @NoAuditEvent("proxy resource, audit event will be emitted on target node") public void resume(@ApiParam(name = "nodeId", value = "The id of the node where processing will be resumed.", required = true) @PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException { final Response response = this.getRemoteSystemProcessingResource(nodeId).resume().execute(); if (!response.isSuccessful()) { LOG.warn("Unable to resume message processing on node {}: {}", nodeId, response.message()); throw new WebApplicationException(response.message(), BAD_GATEWAY); } } }
@POST @Timed @ApiOperation(value = "Pause message processing on node", notes = "If the message journal is enabled, incoming messages will be spooled on disk, if it is disabled, " + "you might lose messages from inputs which cannot buffer themselves, like AMQP or Kafka-based inputs.") @Path("pause") @NoAuditEvent("proxy resource, audit event will be emitted on target node") public void pause(@ApiParam(name = "nodeId", value = "The id of the node where processing will be paused.", required = true) @PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException { final Response response = this.getRemoteSystemProcessingResource(nodeId).pause().execute(); if (!response.isSuccessful()) { LOG.warn("Unable to pause message processing on node {}: {}", nodeId, response.message()); throw new WebApplicationException(response.message(), BAD_GATEWAY); } }
@GET @Timed @ApiOperation(value = "Get JVM information of the given node") @Path("{nodeId}/jvm") public SystemJVMResponse jvm(@ApiParam(name = "nodeId", value = "The id of the node where processing will be paused.", required = true) @PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException { final Node targetNode = nodeService.byNodeId(nodeId); final RemoteSystemResource remoteSystemResource = remoteInterfaceProvider.get(targetNode, this.authenticationToken, RemoteSystemResource.class); final Response<SystemJVMResponse> response = remoteSystemResource.jvm().execute(); if (response.isSuccessful()) { return response.body(); } else { LOG.warn("Unable to get jvm information on node {}: {}", nodeId, response.message()); throw new WebApplicationException(response.message(), BAD_GATEWAY); } }
@Override public void onNext(Response<R> response) { if (response.isSuccessful()) { observer.onNext(response.body()); } else { terminated = true; Throwable t = new HttpException(response); try { observer.onError(t); } catch (Throwable inner) { Exceptions.throwIfFatal(inner); RxJavaPlugins.onError(new CompositeException(t, inner)); } } }
@GET @Timed @ApiOperation(value = "List all installed plugins on the given node") public PluginList list(@ApiParam(name = "nodeId", value = "The id of the node where processing will be paused.", required = true) @PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException { final Node targetNode = nodeService.byNodeId(nodeId); final RemoteSystemPluginResource remoteSystemPluginResource = remoteInterfaceProvider.get(targetNode, this.authenticationToken, RemoteSystemPluginResource.class); final Response<PluginList> response = remoteSystemPluginResource.list().execute(); if (response.isSuccessful()) { return response.body(); } else { LOG.warn("Unable to get plugin list on node {}: {}", nodeId, response.message()); throw new WebApplicationException(response.message(), BAD_GATEWAY); } } }
@GET @Timed @ApiOperation(value = "Get a thread dump of the given node") @RequiresPermissions(RestPermissions.THREADS_DUMP) @Path("{nodeId}/threaddump") public SystemThreadDumpResponse threadDump(@ApiParam(name = "nodeId", value = "The id of the node where processing will be paused.", required = true) @PathParam("nodeId") String nodeId) throws IOException, NodeNotFoundException { final Node targetNode = nodeService.byNodeId(nodeId); final RemoteSystemResource remoteSystemResource = remoteInterfaceProvider.get(targetNode, this.authenticationToken, RemoteSystemResource.class); final Response<SystemThreadDumpResponse> response = remoteSystemResource.threadDump().execute(); if (response.isSuccessful()) { return response.body(); } else { LOG.warn("Unable to get thread dump on node {}: {}", nodeId, response.message()); throw new WebApplicationException(response.message(), BAD_GATEWAY); } } }
@Override public void onNext(Response<R> response) { if (response.isSuccessful()) { subscriber.onNext(response.body()); } else { subscriberTerminated = true; Throwable t = new HttpException(response); try { subscriber.onError(t); } catch (OnCompletedFailedException | OnErrorFailedException | OnErrorNotImplementedException e) { RxJavaPlugins.getInstance().getErrorHandler().handleError(e); } catch (Throwable inner) { Exceptions.throwIfFatal(inner); CompositeException composite = new CompositeException(t, inner); RxJavaPlugins.getInstance().getErrorHandler().handleError(composite); } } }
private Single<GitReference> getValidRef(GitService service, GitReference ref, String branch) { if (!isValidRef(ref)) { return service.getGitReference(repo.owner().login(), repo.name(), branch) .map(response -> { if (response.isSuccessful()) { GitReference fetchedRef = response.body(); if (isValidRef(fetchedRef)) { return fetchedRef; } else { throw new IOException("Reference does not have associated commit SHA-1"); } } else { throw new IOException("Request for Git Reference was unsuccessful"); } }); } return Single.just(ref); }
@Test public void post() throws Exception { final Response<Void> response = service.post(new Pojo("Cony", 26)).get(); assertThat(response.isSuccessful()).isTrue(); }