public void redirectGetToHtmlUiResource(Operation op, String htmlResourcePath) { // redirect using relative url without host:port // not so much optimization as handling the case of port forwarding/containers try { op.addResponseHeader(Operation.LOCATION_HEADER, URLDecoder.decode(htmlResourcePath, Utils.CHARSET)); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } op.setStatusCode(Operation.STATUS_CODE_MOVED_TEMP); op.complete(); }
private void handledLeasedState(Operation op, Closure closure) { logInfo("Closure is already being executed by : %s", closure.documentSelfLink); op.setStatusCode(Operation.STATUS_CODE_BAD_REQUEST); op.fail(new IllegalArgumentException( String.format("Closure has already been executed: %s", closure.documentSelfLink))); }
private static void handleValidationException(Operation op, Throwable e) { Throwable ex = e; if (!(e instanceof IllegalArgumentException) && !(e instanceof LocalizableValidationException)) { ex = new IllegalArgumentException(e.getMessage()); } op.setStatusCode(Operation.STATUS_CODE_BAD_REQUEST); // with body = null fail(ex) will populate it with the proper ServiceErrorResponse content op.setBody(null); op.fail(ex); }
private static void returnLatestOrFail(QueryTask response, Operation get, FailRequest fr) { if (response.results.documentLinks.isEmpty()) { get.setStatusCode(Operation.STATUS_CODE_NOT_FOUND); fr.failRequest(get, new IllegalStateException("Latest state not found"), false); return; } String latest = response.results.documentLinks.get(0); Object obj = response.results.documents.get(latest); get.setBodyNoCloning(obj).complete(); }
public static void failServerNotAvailable(Operation inboundOp) { Throwable e = new IllegalStateException("Server unavailable"); inboundOp.setStatusCode(Operation.STATUS_CODE_UNAVAILABLE); ServiceErrorResponse rsp = new ServiceErrorResponse(); rsp.message = e.getMessage(); rsp.details = EnumSet.of(ServiceErrorResponse.ErrorDetail.SHOULD_RETRY); rsp.statusCode = inboundOp.getStatusCode(); inboundOp.fail(e, rsp); } }
@Override public void handleGet(Operation get) { get.addResponseHeader(Operation.LOCATION_HEADER, "../"); get.setStatusCode(Operation.STATUS_CODE_MOVED_TEMP); get.complete(); }
private void completeOperationSuccess(Operation op) { op.setStatusCode(HttpURLConnection.HTTP_NO_CONTENT); op.setBody(null); op.complete(); }
protected void completeOperationSuccess(Operation op) { op.setStatusCode(HttpURLConnection.HTTP_NO_CONTENT); op.setBody(null); op.complete(); }
private void failWithTimeout(Operation op, Object originalBody) { Throwable e = new TimeoutException(op.getUri() + ":" + op.getExpirationMicrosUtc()); op.setStatusCode(Operation.STATUS_CODE_TIMEOUT); fail(e, op, originalBody); }
@Override public void handlePut(Operation put) { if (put.hasPragmaDirective(Operation.PRAGMA_DIRECTIVE_POST_TO_PUT)) { put.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED); put.complete(); return; } // unsupported op put.fail(Operation.STATUS_CODE_BAD_METHOD); }
@Override public void handlePut(Operation put) { if (put.hasPragmaDirective(Operation.PRAGMA_DIRECTIVE_POST_TO_PUT)) { put.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED); put.complete(); return; } // unsupported op put.fail(Operation.STATUS_CODE_BAD_METHOD); }
public static void fail(Operation request, int statusCode, int errorCode, Throwable e) { request.setStatusCode(statusCode); ServiceErrorResponse r = Utils.toServiceErrorResponse(e); r.statusCode = statusCode; r.errorCode = errorCode; if (e instanceof ServiceNotFoundException) { r.stackTrace = null; } request.setContentType(Operation.MEDIA_TYPE_APPLICATION_JSON).fail(e, r); }
@Override public void handlePost(Operation post) { logInfo("Received POST operation with body '%s'", post.getBody(String.class)); post.setStatusCode(Operation.STATUS_CODE_CREATED).complete(); }
private void completeWith304(Operation op) { op.setBody("should not be a body"); op.setStatusCode(STATUS_CODE_NOT_MODIFIED); op.complete(); } }
private void completeWith304(Operation op) { op.setBody("should not be a body"); op.setStatusCode(STATUS_CODE_NOT_MODIFIED); op.complete(); } }
@Override public boolean queueRequest(Operation op) { if (op.getUri().getPath().equals(SELF_LINK)) { return false; } op.addResponseHeader(Operation.LOCATION_HEADER, "http://www.vmware.com"); op.setStatusCode(Operation.STATUS_CODE_MOVED_TEMP); op.complete(); return true; } }
private void completeWith304(Operation op) { NotModifiedOwnerSelectedService.State bogusBody = new NotModifiedOwnerSelectedService.State(); bogusBody.name = "should not be a body"; op.setBody(bogusBody); op.setStatusCode(STATUS_CODE_NOT_MODIFIED); op.complete(); } }
private void completeWith304(Operation op) { NotModifiedOwnerSelectedService.State bogusBody = new NotModifiedOwnerSelectedService.State(); bogusBody.name = "should not be a body"; op.setBody(bogusBody); op.setStatusCode(STATUS_CODE_NOT_MODIFIED); op.complete(); } }
@Override public void handleGet(Operation get) { get.setStatusCode(Operation.STATUS_CODE_CONFLICT); get.setContentType("text/xml"); get.setBody("<error>hello</error>"); get.setKeepAlive(keepAlive); get.complete(); } };
@Override public void handleGet(Operation get) { ServiceErrorResponse body = new ServiceErrorResponse(); body.message = "hello"; get.setStatusCode(Operation.STATUS_CODE_CONFLICT); get.setContentType("text/xml"); get.setBody(body); get.setKeepAlive(keepAlive); get.complete(); } };