/** * Indicates if a content is available and can be sent. Several conditions * must be met: the method must allow the sending of content, the content * must exists and have some available data. * * @return True if a content is available and can be sent. */ @Override public boolean isEntityAvailable() { return getWrappedRequest().isEntityAvailable(); }
/** * Indicates if the request entity should be chunked. * * @return True if the request should be chunked */ protected boolean shouldRequestBeChunked(Request request) { return request.isEntityAvailable() && (request.getEntity() != null) && !request.getEntity().hasKnownSize(); } }
private Status createFile(Request request, File file) { // This is simple PUT of the full entity try { if (request.isEntityAvailable()) { Files.copy(request.getEntity().getStream(), file.toPath()); return SUCCESS_CREATED; } if (file.createNewFile()) { return SUCCESS_NO_CONTENT; } } catch (IOException ioe) { getLogger().log(WARNING, "Unable to create the new file", ioe); return new Status(SERVER_ERROR_INTERNAL, ioe); } String message = "Unable to create the new file"; getLogger().warning(message); return new Status(SERVER_ERROR_INTERNAL, message); }
private Status replaceFile(Request request, File file) { File tmp = null; try { tmp = File.createTempFile("restlet-upload", "bin"); if (request.isEntityAvailable()) { Files.copy(request.getEntity().getStream(), tmp.toPath(), REPLACE_EXISTING); } } catch (IOException ioe) { getLogger().log(WARNING, "Unable to create the temporary file", ioe); cleanTemporaryFileIfUploadNotResumed(tmp); return new Status(SERVER_ERROR_INTERNAL, "Unable to create a temporary file"); } return replaceFileByTemporaryFile(request, file, tmp); }
private Status replaceFileByTemporaryFile(Request request, File file, File tmp) { if (!tmp.exists()) { return new Status(SERVER_ERROR_INTERNAL, "Can't replace the existing file without new content."); } // Then delete the existing file if (!IoUtils.delete(file)) { cleanTemporaryFileIfUploadNotResumed(tmp); return new Status(SERVER_ERROR_INTERNAL, "Unable to delete the existing file"); } // Finally move the temporary file to the existing file location if (tmp.renameTo(file)) { if (request.isEntityAvailable()) { return SUCCESS_NO_CONTENT; } return SUCCESS_OK; } // Many aspects of the behavior of the method "renameTo" are inherently platform-dependent. // The rename operation might not be able to move a file from one file system to another. if (!tmp.exists()) { return new Status(SERVER_ERROR_INTERNAL, "Unable to move the temporary file to replace the existing file"); } try { Files.move(tmp.toPath(), file.toPath(), REPLACE_EXISTING); } catch (IOException e) { return new Status(SERVER_ERROR_INTERNAL, e, "Unable to move the temporary file to replace the existing file"); } return SUCCESS_OK; }
private Status createFileWithPartialContent(Request request, File file, Range range) { // This is a partial PUT try (RandomAccessFile raf = new RandomAccessFile(file, "rwd")) { // Go to the desired offset. if (range.getIndex() == Range.INDEX_LAST) { if (raf.length() <= range.getSize()) { raf.seek(range.getSize()); } else { raf.seek(raf.length() - range.getSize()); } } else { raf.seek(range.getIndex()); } // Write the entity to the file. if (request.isEntityAvailable()) { IoUtils.copy(request.getEntity().getStream(), raf); return SUCCESS_CREATED; } return SUCCESS_NO_CONTENT; } catch (FileNotFoundException fnfe) { getLogger().log(WARNING, "Unable to create the new file", fnfe); return new Status(SERVER_ERROR_INTERNAL, fnfe); } catch (IOException ioe) { getLogger().log(WARNING, "Unable to create the new file", ioe); return new Status(SERVER_ERROR_INTERNAL, ioe); } }
if (request.isEntityAvailable()) { IoUtils.copy(request.getEntity().getStream(), raf);
"Infinite redirection loop detected with URI: " + newTargetRef); } else if (request.getEntity() != null && !request.isEntityAvailable()) { getLogger() .warning(
if (!request.isEntityAvailable()) { return;
/** * Creates a low-level HTTP client call from a high-level uniform call. * * @param request * The high-level request. * @return A low-level HTTP client call. */ @Override public ClientCall create(Request request) { ClientCall result = null; try { result = new HttpUrlConnectionCall(this, request.getMethod() .toString(), ReferenceUtils.update( request.getResourceRef(), request).toString(), request.isEntityAvailable()); } catch (IOException ioe) { getLogger().log(Level.WARNING, "Unable to create the HTTP client call", ioe); } return result; }
/** * Creates a low-level HTTP client call from a high-level uniform call. * * @param request * The high-level request. * @return A low-level HTTP client call. */ @Override public ClientCall create(Request request) { ClientCall result = null; try { result = new HttpUrlConnectionCall(this, request.getMethod() .toString(), ReferenceUtils.update( request.getResourceRef(), request).toString(), request.isEntityAvailable()); } catch (IOException ioe) { getLogger().log(Level.WARNING, "Unable to create the HTTP client call", ioe); } return result; }
/** * Creates a low-level HTTP client call from a high-level uniform call. * * @param request * The high-level request. * @return A low-level HTTP client call. */ @Override public ClientCall create(Request request) { ClientCall result = null; try { result = new HttpMethodCall(this, request.getMethod().toString(), ReferenceUtils.update(request.getResourceRef(), request) .toString(), request.isEntityAvailable()); } catch (IOException ioe) { getLogger().log(Level.WARNING, "Unable to create the HTTP client call", ioe); } return result; }
/** * Creates a low-level HTTP client call from a high-level uniform call. * * @param request * The high-level request. * @return A low-level HTTP client call. */ @Override public ClientCall create(Request request) { ClientCall result = null; try { result = new HttpUrlConnectionCall(this, request.getMethod() .toString(), ReferenceUtils.update( request.getResourceRef(), request).toString(), request.isEntityAvailable()); } catch (IOException ioe) { getLogger().log(Level.WARNING, "Unable to create the HTTP client call", ioe); } return result; }
@Override public Object getParamValue() { if (form == null && this.tlContext.get().getRequest().isEntityAvailable()) { form = new Form(this.tlContext.get().getRequest().getEntity(), false); } if (form == null) { return null; } final String paramName = this.formParam.value(); try { return super.getParamValue(form, paramName); } catch (ConvertParameterException e) { throw new ConvertQueryParamException(e); } } }
Representation entity = request.isEntityAvailable() ? request.getEntity() : null;
if (request.isEntityAvailable()) { Representation entity = request.getEntity();
if (request.isEntityAvailable()) { Representation entity = request.getEntity();
if (request.isEntityAvailable()) { Representation entity = request.getEntity();
/** * @see org.restlet.ext.jaxrs.internal.wrappers.params.ParameterList.ParamGetter#getValue() */ public Object getValue() throws InvocationTargetException, ConvertRepresentationException, WebApplicationException { try { final Request request = Request.getCurrent(); if (!request.isEntityAvailable() || request.getEntity().getSize() == 0) { return null; } final Representation entity = request.getEntity(); if ((entity == null)/* || (entity is not empty) */) { return null; } return createInstance(entity); } catch (IllegalArgumentException e) { throw ConvertRepresentationException.object(getReprClass(), "the message body", e); } catch (InstantiationException e) { throw ConvertRepresentationException.object(getReprClass(), "the message body", e); } catch (IllegalAccessException e) { throw ConvertRepresentationException.object(getReprClass(), "the message body", e); } } }