@Override protected void afterHandle(Request request, Response response) { if (response.isEntityAvailable() && response.getEntity().getEncodings().contains( Encoding.FREEMARKER)) { final TemplateRepresentation representation = new TemplateRepresentation( response.getEntity(), this.configuration, response .getEntity().getMediaType()); if (this.dataModel == null) { representation.setDataModel(request, response); } else { representation.setDataModel(this.dataModel); } response.setEntity(representation); } }
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); }
/** * This implementation throws IllegalStateException if attempting to read * the underlying stream multiple times. */ public InputStream getInputStream() throws IOException, IllegalStateException { if (this.read && this.representation.isTransient()) { throw new IllegalStateException( "Representation has already been read and is transient."); } this.read = true; return this.representation.getStream(); }
/** * Exhauts the content of the representation by reading it and silently * discarding anything read. * * @return The number of bytes consumed or -1 if unknown. */ public long exhaust() throws IOException { long result = -1L; if (isAvailable()) { result = ByteUtils.exhaust(getStream()); } return result; }
/** * Converts the representation to a string value. Be careful when using this * method as the conversion of large content to a string fully stored in * memory can result in OutOfMemoryErrors being thrown. * * @return The representation as a string value. */ public String getText() throws IOException { String result = null; if (isAvailable()) { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); write(baos); if (getCharacterSet() != null) { result = baos.toString(getCharacterSet().getName()); } else { result = baos.toString(); } } return result; }
&& (this.request.getEntity().getCharacterSet() != null)) { result = this.request.getEntity().getCharacterSet() .getName(); && (!this.request.getEntity().getEncodings() .isEmpty())) { .getEncodings().size(); i++) { if (i > 0) { value.append(", "); .getEncodings().get(i).getName()); .getExpirationDate() != null)) { result = DateUtils.format(this.request.getEntity() .getExpirationDate(), DateUtils.FORMAT_RFC_1123.get(0)); && (!this.request.getEntity().getLanguages() .isEmpty())) { .getLanguages().size(); i++) { if (i > 0) { value.append(", "); .getLanguages().get(i).getName()); .getModificationDate() != null)) { result = DateUtils.format(this.request.getEntity()
final Request request = new Request(); request.setResourceRef(url.toString()); request.setMethod(method); if (representation != null) { request.getClientInfo().getAcceptedMediaTypes().add( new Preference<MediaType>(representation.getMediaType()));
/** * Use {@link #getResourceFromText(String)} instead. */ @Deprecated public RepositoryRouteResource getResourceFromResponse(Response response) throws IOException { String responseString = response.getEntity().getText(); LOG.debug("responseText: " + responseString); Assert.assertTrue(response.getStatus() + "\n" + responseString, response.getStatus().isSuccess()); return getResourceFromText(responseString); }
public static File downloadFile( URL url, String targetFile ) throws IOException { OutputStream out = null; InputStream in = null; File downloadedFile = new File( targetFile ); try { Response response = sendMessage( url, Method.GET, null ); if ( !response.getStatus().isSuccess() ) { throw new FileNotFoundException( response.getStatus() + " - " + url ); } // if this is null then someone was getting really creative with the tests, but hey, we will let them... if ( downloadedFile.getParentFile() != null ) { downloadedFile.getParentFile().mkdirs(); } in = response.getEntity().getStream(); out = new BufferedOutputStream( new FileOutputStream( downloadedFile ) ); IOUtil.copy( in, out, 1024 ); } finally { IOUtil.close( in ); IOUtil.close( out ); } return downloadedFile; }
public void doPost(Request req, Response resp) throws RestletException, IOException { String filterName = (String) req.getAttributes().get("filterName"); String updateType = (String) req.getAttributes().get("updateType"); InputStream input = req.getEntity().getStream(); XmlFilterUpdate fu = XMLConfiguration.parseXMLFilterUpdate(input); ZipFilterUpdate fu = new ZipFilterUpdate(req.getEntity().getStream()); resp.setEntity("Filter update completed, no problems encountered.\n", MediaType.TEXT_PLAIN); resp.setStatus(Status.SUCCESS_OK);
getResponse().setStatus(Status.SUCCESS_ACCEPTED); MediaType mediaType = getRequest().getEntity().getMediaType(); if(LOGGER.isLoggable(Level.INFO)) LOGGER.info("PUT file, mimetype: " + mediaType ); String method = (String) getRequest().getResourceRef().getLastSegment(); if (method != null && method.toLowerCase().startsWith("file.")) { uploadedFile = RESTUtils.handleBinUpload(store + "." + format, directory, getRequest());
AccessDeniedException, ResourceException String resPath = parsePathFromUri(req.getResourceRef().toString()); res.redirectPermanent(createRedirectReference(req).getTargetRef().toString() + "/"); if (Method.HEAD.equals(req.getMethod())) { return renderHeadResponseItem(context, req, res, variant, store, coll.getResourceStoreRequest(), coll); Representation result = serialize(context, req, variant, response); result.setModificationDate(new Date(coll.getModified()));
/** * 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); } }
final Response response = this.context.getClientDispatcher() .get(targetUri); if (response.getStatus().isSuccess() && response.isEntityAvailable()) { try { result = new StreamSource(response.getEntity() .getStream()); result.setSystemId(targetUri);
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); } }
@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; }
public Response get(Reference uri, MediaType accepts) throws NotSuccessException, MediaTypeException { Response response = request(Method.GET, uri, null, null, accepts); MediaType mediaType = response.getEntity().getMediaType(); if (!accepts.includes(mediaType)) { throw new MediaTypeException(accepts, mediaType); } return response; }
public static SyndFeed getFeed( String feedId ) throws IllegalArgumentException, MalformedURLException, FeedException, IOException { SyndFeedInput input = new SyndFeedInput(); Response response = RequestFacade.sendMessage( FEED_URL_PART + feedId, Method.GET ); Assert.assertTrue( "Expected content", response.getEntity().isAvailable()); SyndFeed feed = input.build( new XmlReader( response.getEntity().getStream() ) ); // sort it by date sortSyndEntryOrderByPublishedDate( feed ); return feed; }