Created
June 9, 2012 02:40
-
-
Save carlosspohr/2899170 to your computer and use it in GitHub Desktop.
Web service Java com VRaptor para gerar o stream dos jaspers para o Jacad3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#algum diretório seguro. | |
reports.builded.dir=/home/carlos/reports-temp/ | |
#um hash aleatório. | |
reports.hash=032rh204nacm9f4-2d3k-9f53-kkc994jn4n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.wp.carlos4web.services.controllers; | |
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.net.URLConnection; | |
import java.util.Properties; | |
import br.com.caelum.vraptor.Get; | |
import br.com.caelum.vraptor.Resource; | |
import br.com.caelum.vraptor.interceptor.download.Download; | |
import br.com.caelum.vraptor.interceptor.download.FileDownload; | |
@Resource | |
public class ReportServiceController { | |
@Get("/services/reports-builded/{report}/{hash}/") | |
public Download download(String report, String hash){ | |
Properties conf = getConfigProperties(); | |
if(conf.getProperty("reports.hash").equals(hash)){ | |
String path = conf.getProperty("reports.builded.dir") + report; | |
File jasper = new File(path); | |
String mime = URLConnection.guessContentTypeFromName(jasper.getAbsolutePath()); | |
return new FileDownload(jasper, mime, jasper.getName(), true); | |
} | |
else{ | |
throw new IllegalArgumentException("Hash de segurança incorreto."); | |
} | |
} | |
private Properties getConfigProperties() { | |
Properties properties = new Properties(); | |
try { | |
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("conf.properties"); | |
properties.load(in); | |
return properties; | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
return null; | |
} catch (IOException e) { | |
e.printStackTrace(); | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment