/** * Returns the entity representation. * * @return The entity representation. */ @Override public Representation getEntity() { return getWrappedRequest().getEntity(); }
/** * Handles an upload using the EXTERNAL method. * * @param request * @throws IOException */ public static File handleEXTERNALUpload(Request request) throws IOException { //get the URL for this file to upload final InputStream inStream=request.getEntity().getStream(); final String stringURL=IOUtils.getStringFromStream(inStream); final URL fileURL=new URL(stringURL); final File inputFile= IOUtils.URLToFile(fileURL); if(inputFile!=null && inputFile.exists() && inputFile.canRead()) { return inputFile; } return null; }
@Override protected int beforeHandle(Request request, Response response) { if (getMode() == MODE_REQUEST) { request.setEntity(transform(request.getEntity())); } return CONTINUE; }
@Override protected int beforeHandle(Request request, Response response) { if (getMode() == MODE_REQUEST) { request.setEntity(transform(request.getEntity())); } return CONTINUE; }
final InputStream inStream=request.getEntity().getStream(); final String stringURL=IOUtils.getStringFromStream(inStream); final URL fileURL=new URL(stringURL);
protected TileLayer deserializeAndCheckLayer(Request req, Response resp, boolean isPut) throws RestletException, IOException { // TODO UTF-8 may not always be right here String layerName = ServletUtils.URLDecode((String) req.getAttributes().get("layer"), "UTF-8"); String formatExtension = (String) req.getAttributes().get("extension"); InputStream is = req.getEntity().getStream(); // If appropriate, check whether this layer exists if (!isPut) { findTileLayer(layerName, layerDispatcher); } return deserializeAndCheckLayerInternal(layerName, formatExtension, is); }
/** * Method responsible for handling incoming POSTs. It will parse the XML document and * deserialize it into a SeedRequest, then create a SeedTask and forward it to the thread pool * executor. */ public void doPost(Request req, Response resp) throws RestletException, IOException { String formatExtension = (String) req.getAttributes().get("extension"); SeedRequest sr = null; XStream xs = xmlConfig.getConfiguredXStream(new XStream(new DomDriver())); if (formatExtension.equalsIgnoreCase("xml")) { sr = (SeedRequest) xs.fromXML(req.getEntity().getStream()); } else if (formatExtension.equalsIgnoreCase("json")) { sr = (SeedRequest) xs.fromXML(convertJson(req.getEntity().getText())); } else { throw new RestletException("Format extension unknown or not specified: " + formatExtension, Status.CLIENT_ERROR_BAD_REQUEST); } String layerName = null; try { layerName = URLDecoder.decode((String) req.getAttributes().get("layer"), "UTF-8"); } catch (UnsupportedEncodingException uee) { } try { seeder.seed(layerName, sr); } catch (IllegalArgumentException e) { throw new RestletException(e.getMessage(), Status.CLIENT_ERROR_BAD_REQUEST); } catch (GeoWebCacheException e) { throw new RestletException(e.getMessage(), Status.SERVER_ERROR_INTERNAL); } }
/** * Reads content from the body of a request and writes it to a file. * * @param fileName The name of the file to write out. * @param directory The directory to write the file to. * @param deleteDirectoryContent Delete directory content if the file already exists. * @param request The request. * * @return The file object representing the newly written file. * * @throws IOException Any I/O errors that occur. * * TODO: move this to IOUtils. */ public static File handleBinUpload(String fileName, File directory, boolean deleteDirectoryContent, Request request) throws IOException { final File newFile = new File(directory, fileName); if (deleteDirectoryContent && newFile.exists()) { FileUtils.cleanDirectory(directory); } final ReadableByteChannel source =request.getEntity().getChannel(); final FileChannel outputChannel = IOUtils.getOuputChannel(newFile); IOUtils.copyChannel(1024*1024, source,outputChannel ); IOUtils.closeQuietly(source); IOUtils.closeQuietly(outputChannel); return newFile; }
/** * Handles a POST call by invoking the * {@link #acceptRepresentation(Representation)} method. It also logs a * trace if there is no entity posted. */ @Override public void handlePost() { if (!getRequest().isEntityAvailable()) { getLogger() .fine( "POST request received without any entity. Continuing processing."); } post(getRequest().getEntity()); }
private File doFileUpload() { try { getResponse().setStatus(Status.SUCCESS_ACCEPTED); File directory = catalog.getResourceLoader().findOrCreateDirectory(getDirectoryPath(getRequest())); if (LOGGER.isLoggable(Level.INFO)) { MediaType mediaType = getRequest().getEntity().getMediaType(); LOGGER.info("PUT file: mimetype=" + mediaType + ", path=" + directory.getAbsolutePath()); } return RESTUtils.handleBinUpload(getAttribute("template") + "." + MEDIATYPE_FTL_EXTENSION, directory, false, getRequest()); } catch (IOException e) { throw new RestletException(e.getMessage(), Status.SERVER_ERROR_INTERNAL, e); } }
/** * Handles a request using the PUT method. * <p> * This method operates by de-serializing the map representation of the target object and * then calling {@link #putMap(Map)}. * </p> */ @Override public void handlePut() { DataFormat format = getFormatPostOrPut(); Map map = (Map) format.toObject(getRequest().getEntity()); try { putMap(map); } catch (Exception e) { throw new RestletException( "", Status.SERVER_ERROR_INTERNAL, e ); } }
/** * Handles a request using the POST method. * <p> * This method operates by de-serializing the map representation of the target object and * then calling {@link #postMap(Map)}. * </p> */ @Override public void handlePost() { DataFormat format = getFormatPostOrPut(); Map map = (Map) format.toObject(getRequest().getEntity()); try { postMap(map); } catch (Exception e) { throw new RestletException( "", Status.SERVER_ERROR_INTERNAL, e ); } }
/** * Handles a PUT request by de-serializing the content of the request into an instance * of the target object. * <p> * This method operates by: * <ol> * <li>Determining the serialization format from {@link #getFormatPostOrPut()} * <li>De-serializing to an instance of the target object. * <li>Passing the target object to {@link #handleObjectPut(Object)} * </ol> * </p> * * @see #handleObjectPost(Object) */ @Override public final void handlePut() { DataFormat format = getFormatPostOrPut(); Object object = format.toObject( getRequest().getEntity() ); try { handleObjectPut(object); } catch (Exception e) { handleException(e); } }
MediaType type = getRequest().getEntity().getMediaType(); if ( type != null ) {
public final void handlePost() { DataFormat format = getFormatPostOrPut(); Object object = format.toObject( getRequest().getEntity() ); String location = null; try {
@Override public Object upload(Context context, Request request, Response response, List<FileItem> files) throws ResourceException { // NEXUS-4151: Do not accept upload/deploy requests with media type (Content-Type) of // "application/x-www-form-urlencoded", since ad 1, it's wrong, ad 2, we do know // Jetty's Request object "eats" up it's body to parse request parameters, invoked // way earlier in security filters if (request.isEntityAvailable()) { MediaType mt = request.getEntity().getMediaType(); if (mt != null && MediaType.APPLICATION_WWW_FORM.isCompatible(mt)) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Content-type of \"" + mt.toString() + "\" is not acceptable for uploads!"); } } try { final ResourceStoreRequest req = getResourceStoreRequest(request); for (FileItem fileItem : files) { getResourceStore(request).storeItem(req, fileItem.getInputStream(), null); } } catch (Exception t) { handleException(request, response, t); } return null; }
MediaType mt = request.getEntity().getMediaType();
put(getRequest().getEntity());
final Representation entity = request.getEntity();