@Override @Delete public Representation delete() { final String topicName = (String) getRequest().getAttributes().get("topicName"); if (_autoTopicWhitelistingManager != null) { _autoTopicWhitelistingManager.addIntoBlacklist(topicName); } if (!_helixMirrorMakerManager.isTopicExisted(topicName)) { getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND); return new StringRepresentation( String.format("Failed to delete not existed topic: %s", topicName)); } try { _helixMirrorMakerManager.deleteTopicInMirrorMaker(topicName); return new StringRepresentation( String.format("Successfully finished delete topic: %s", topicName)); } catch (Exception e) { getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); LOGGER.error("Failed to delete topic: {}, with exception: {}", topicName, e); return new StringRepresentation( String.format("Failed to delete topic: %s, with exception: %s", topicName, e)); } }
return new StringRepresentation(responseJson.toJSONString()); } else { getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND); return new StringRepresentation(String .format("Failed to get ExternalView for topic: %s, it is not existed!", topicName)); getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); return new StringRepresentation(String .format("Failed to get ExternalView for topic: %s, with exception: %s", topicName, e));
@Override @Put("json") public Representation put(Representation entity) { try { String jsonRequest = entity.getText(); TopicPartition topicPartitionInfo = TopicPartition.init(jsonRequest); if (_autoTopicWhitelistingManager != null) { _autoTopicWhitelistingManager.removeFromBlacklist(topicPartitionInfo.getTopic()); } if (_helixMirrorMakerManager.isTopicExisted(topicPartitionInfo.getTopic())) { _helixMirrorMakerManager.expandTopicInMirrorMaker(topicPartitionInfo); return new StringRepresentation( String.format("Successfully expand topic: %s", topicPartitionInfo)); } else { getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND); return new StringRepresentation(String.format( "Failed to expand topic, topic: %s is not existed!", topicPartitionInfo.getTopic())); } } catch (IOException e) { LOGGER.error("Got error during processing Put request", e); getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); return new StringRepresentation( String.format("Failed to expand topic, with exception: %s", e)); } }
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND); return new StringRepresentation(String.format( "Failed to add new topic: %s, it is already existed!", topicPartitionInfo.getTopic())); getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); return new StringRepresentation( String.format("Failed to add new topic, with exception: %s", e));
@Override public void handle(Request request, Response response) { response.setStatus(Status.CLIENT_ERROR_NOT_FOUND, "No virtual host could handle the request"); } };
/** * Permanently redirects the client to a target URI. The client is expected * to reuse the same method for the new request. * * @param targetRef * The target URI reference. */ public void redirectPermanent(Reference targetRef) { setLocationRef(targetRef); setStatus(Status.REDIRECTION_PERMANENT); }
/** * Sets the status. * * @param status * The status to set (code and reason phrase). * @param description * The longer status description. */ public void setStatus(Status status, String description) { setStatus(new Status(status, description)); }
/** * Sets the status. * * @param status * The status to set. * @param throwable * The related error or exception. */ public void setStatus(Status status, Throwable throwable) { setStatus(new Status(status, throwable)); }
/** * Temporarily redirects the client to a target URI. The client is expected * to reuse the same method for the new request. * * @param targetRef * The target reference. */ public void redirectTemporary(Reference targetRef) { setLocationRef(targetRef); setStatus(Status.REDIRECTION_TEMPORARY); }
public Response prepareResponse(Response response, boolean withEnvelope) { if (response == null || status == null || description == null) return null; // fill status with description and make sure entity is of type JSON response.setStatus(status, description); Gson gson = new Gson(); if (!withEnvelope && result != null) response.setEntity(gson.toJson(result), MEDIA_TYPE); else response.setEntity(gson.toJson(this), MEDIA_TYPE); return response; }
@Override protected int thresholdReached(Request request, Response response, CounterResult counterResult) { Context.getCurrentLogger().log( Level.FINE, "The current request has been blocked because \"" + counterResult.getCountedValue() + "\" issued too many requests."); response.setStatus(Status.CLIENT_ERROR_TOO_MANY_REQUESTS); return Filter.SKIP; }
@Override protected int thresholdReached(Request request, Response response, CounterResult counterResult) { Context.getCurrentLogger().log( Level.FINE, "The current request has been blocked because \"" + counterResult.getCountedValue() + "\" issued too many requests."); response.setStatus(Status.CLIENT_ERROR_TOO_MANY_REQUESTS); return Filter.SKIP; }
@Override protected int thresholdReached(Request request, Response response, CounterResult counterResult) { Context.getCurrentLogger().log( Level.FINE, "The current request has been blocked because \"" + counterResult.getCountedValue() + "\" issued too many requests."); response.setStatus(Status.CLIENT_ERROR_TOO_MANY_REQUESTS); return Filter.SKIP; }
@Override protected int thresholdReached(Request request, Response response, CounterResult counterResult) { Context.getCurrentLogger().log( Level.FINE, "The current request has been blocked because \"" + counterResult.getCountedValue() + "\" issued too many requests."); response.setStatus(Status.CLIENT_ERROR_TOO_MANY_REQUESTS); return Filter.SKIP; }
private int sendErrorPage(Response response, Exception ex) { response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST, ex.getMessage()); response.setEntity(getErrorPage(ex)); return STOP; }
@Override public void handle(Request request, Response response) { LOG.debug("MethodRouter [{}] received request method: [{}]" , uriPattern, request.getMethod()); Restlet target = routes.get(request.getMethod()); if (target != null) { target.handle(request, response); } else { LOG.debug("No route for request method: [{}]", request.getMethod()); response.setStatus(Status.CLIENT_ERROR_NOT_FOUND); } }
private void put( Request request, Response response ) { execute( request, response, resource -> { T value = convertToObject( identityType, request ); resource.put( value ); response.setStatus( Status.SUCCESS_OK ); } ); }
@Override public void challenge(Response response, boolean stale) { // Load the FreeMarker template Representation ftl = new ClientResource( LocalReference.createClapReference(getClass().getPackage()) + "/Login.ftl").get(); // Wraps the bean with a FreeMarker representation response.setEntity(new TemplateRepresentation(ftl, response .getRequest().getResourceRef(), MediaType.TEXT_HTML)); response.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED); }
@Override protected void doCatch(Throwable t) { final OAuthException oex = OAuthException.toOAuthException(t); // XXX: Generally, we only communicate with TokenVerifier. So we don't // need HTTP 400 code. // getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST); getResponse().setStatus(Status.SUCCESS_OK); getResponse().setEntity(responseErrorRepresentation(oex)); }
private void post( final Request request, final Response response ) { execute( request, response, resource -> { RestForm form = createRestForm( request ); RestLink link = resource.post( form ); response.setLocationRef( link.path().get() ); response.setStatus( Status.REDIRECTION_SEE_OTHER ); } ); }