@Override public Representation getRepresentation(MediaType defaultMediaType, int timeToLive) { return new FileRepresentation(getFile(), defaultMediaType, timeToLive); }
/** This resource returns the swagger.json */ @Get("json") public String listResources() { final ServletContext servlet = (ServletContext) getContext().getAttributes().get("org.restlet.ext.servlet.ServletContext"); final String realPath = servlet.getRealPath("/"); final JacksonRepresentation<ApiDeclaration> result = new JacksonRepresentation<ApiDeclaration>( new FileRepresentation(realPath + "swagger.json", MediaType.APPLICATION_JSON), ApiDeclaration.class); try { return result.getText(); } catch (final IOException e) { LOGGER.warn("Error building swagger json", e); } return "Not Found: swagger.json"; } }
@Get public Representation getKMLLayer() { try { String layerId = ( String ) getRequest().getAttributes().get( "layer" ); int kmlId = Integer.parseInt( ( String) getRequest().getAttributes().get("kmlId")); String fileName = ( String ) getRequest().getAttributes().get("kmlFile"); JSONObject layer = _service.getLayerJSON(layerId); JSONObject kmlDef = layer.getJSONObject("public").getJSONArray("kml").getJSONObject(kmlId); String path = new File(new File(kmlDef.getString("dir")), fileName).getPath(); File kmlFile = new File(getClass().getClassLoader().getResource(path).toURI()); return new FileRepresentation(kmlFile, MediaType.APPLICATION_KML); } catch (Exception e) { throw new ResourceException( Status.SERVER_ERROR_INTERNAL, "Unable to load desired kml file", e ); } } }
@Override protected Representation get() throws ResourceException { // Data String identity = ensureRequestAttribute( PARAM_IDENTITY, String.class, Status.CLIENT_ERROR_BAD_REQUEST ); // Context X509Context x509Context = newRootContext().x509Context( identity ); // Interaction EscrowedKeyPair ekp = x509Context.recover(); // Representation return new FileRepresentation( ekp.attachedFile(), MediaType.TEXT_PLAIN ); }
@Override protected Representation get() throws ResourceException { // Data String identity = ensureRequestAttribute( PARAM_IDENTITY, String.class, Status.CLIENT_ERROR_BAD_REQUEST ); // Context EscrowedKeyPairContext ekpCtx = newRootContext().escrowedKeyPairContext( identity ); // Interaction EscrowedKeyPair ekp = ekpCtx.escrowedKeyPair(); // Representation return new FileRepresentation( ekp.attachedFile(), MediaType.TEXT_PLAIN ); }
if (UmlgProperties.INSTANCE.isLoadUiResourcesFromFile()) { File umlgui2 = new File("./runtime/runtime-ui/src/main/webapp/resources/org/umlg/ui/umlgui2.html"); FileRepresentation fileRepresentation = new FileRepresentation(umlgui2, MediaType.APPLICATION_XHTML); return new TemplateRepresentation(fileRepresentation, dataModel, MediaType.TEXT_HTML); } else {
@Override protected Representation get() throws ResourceException { // Data String caIdentity = ensureRequestAttribute( PARAM_IDENTITY, String.class, Status.CLIENT_ERROR_BAD_REQUEST ); // Context RootContext rootCtx = newRootContext(); CAContext caCtx = rootCtx.caContext( caIdentity ); // Interaction CRL crl = caCtx.ca().crl().get(); // Representation return new FileRepresentation( crl.attachedFile(), MediaType.TEXT_PLAIN ); }
@Override public ResponseEntity uploadOctetStream(String urn, java.io.File file, MediaType mediaType) throws ServiceException { ResponseEntity response; FileRepresentation fileRepresentation = new FileRepresentation(file, mediaType); fileRepresentation.setMediaType(MediaType.APPLICATION_OCTET_STREAM); ClientResource service = createClient(FileEndpoints.uploadContentsAsOctetStream(urn)); service.accept(MediaType.APPLICATION_JSON); try { Representation result = service.post(fileRepresentation); JsonRepresentation jsonRepresentation = new JsonRepresentation(result); JSONObject jsonResult = jsonRepresentation.getJsonObject(); response = JsonUtil.fromJson(jsonResult, ResponseEntity.class); if (service.getStatus().equals(Status.SUCCESS_OK)) { LOGGER.info("Successfully uploaded file to path {}", FileEndpoints.uploadContentsAsMultipart(urn)); } else { LOGGER.error("Unexpected HTTP status code returned: {}", service.getStatus().getCode()); throw new ServiceException(response); } } catch (JSONException | IOException e) { LOGGER.error("Unexpected Exception", e); throw new ServiceException(e); } return response; }
FileRepresentation FRepre = new FileRepresentation(file, MediaType.TEXT_CSV); FRepre.getDisposition().setType(Disposition.TYPE_ATTACHMENT); FRepre.getDisposition().setFilename(file.getName());
FileRepresentation fileRepresentation = new FileRepresentation(file, mediaType);
MediaType.TEXT_PLAIN)); } else if (source instanceof File) { result = new FileRepresentation((File) source, MediaType.getMostSpecific(target.getMediaType(), MediaType.APPLICATION_OCTET_STREAM));