use of javax.servlet.ServletOutputStream in project async-http-client by AsyncHttpClient.
the class NonAsciiContentLengthTest method setUpGlobal.
@BeforeClass(alwaysRun = true)
public void setUpGlobal() throws Exception {
server = new Server();
ServerConnector connector = addHttpConnector(server);
server.setHandler(new AbstractHandler() {
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
// Can only handle bodies of up to 1024 bytes.
int MAX_BODY_SIZE = 1024;
byte[] b = new byte[MAX_BODY_SIZE];
int offset = 0;
int numBytesRead;
try (ServletInputStream is = request.getInputStream()) {
while ((numBytesRead = is.read(b, offset, MAX_BODY_SIZE - offset)) != -1) {
offset += numBytesRead;
}
}
assertEquals(request.getContentLength(), offset);
response.setStatus(200);
response.setCharacterEncoding(request.getCharacterEncoding());
response.setContentLength(request.getContentLength());
try (ServletOutputStream os = response.getOutputStream()) {
os.write(b, 0, offset);
}
}
});
server.start();
port1 = connector.getLocalPort();
}
use of javax.servlet.ServletOutputStream in project bamboobsc by billchen198318.
the class JReportUtils method fillReportToResponse.
public static void fillReportToResponse(String reportId, Map<String, Object> paramMap, HttpServletResponse response) throws ServiceException, Exception {
if (StringUtils.isBlank(reportId)) {
throw new java.lang.IllegalArgumentException("error, reportId is blank");
}
TbSysJreport sysJreport = new TbSysJreport();
sysJreport.setReportId(reportId);
DefaultResult<TbSysJreport> result = sysJreportService.findEntityByUK(sysJreport);
if (result.getValue() == null) {
throw new ServiceException(result.getSystemMessage().getValue());
}
sysJreport = result.getValue();
String jasperFileFullPath = Constants.getDeployJasperReportDir() + "/" + sysJreport.getReportId() + "/" + sysJreport.getReportId() + ".jasper";
File jasperFile = new File(jasperFileFullPath);
if (!jasperFile.exists()) {
jasperFile = null;
throw new Exception("error, Files are missing : " + jasperFileFullPath);
}
InputStream reportSource = new FileInputStream(jasperFile);
Connection conn = null;
try {
conn = DataUtils.getConnection();
ServletOutputStream ouputStream = response.getOutputStream();
JasperPrint jasperPrint = JasperFillManager.fillReport(reportSource, paramMap, conn);
response.setContentType("application/pdf");
response.setHeader("Content-disposition", "inline; filename=" + sysJreport.getReportId() + ".pdf");
JRPdfExporter jrPdfExporter = new JRPdfExporter();
jrPdfExporter.setExporterInput(new SimpleExporterInput(jasperPrint));
jrPdfExporter.setExporterOutput(new SimpleOutputStreamExporterOutput(ouputStream));
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
jrPdfExporter.setConfiguration(configuration);
configuration.setOwnerPassword(Constants.getEncryptorKey1());
jrPdfExporter.exportReport();
ouputStream.flush();
ouputStream.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
DataUtils.doReleaseConnection(conn);
if (null != reportSource) {
try {
reportSource.close();
} catch (IOException e) {
e.printStackTrace();
}
}
reportSource = null;
jasperFile = null;
}
}
use of javax.servlet.ServletOutputStream in project opennms by OpenNMS.
the class MonkeyServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// super.doGet(req, resp);
String responseText = "You are reading this from a servlet!\n";
ServletOutputStream os = resp.getOutputStream();
os.print(responseText);
os.close();
resp.setContentType("text/plain");
resp.setContentLength(responseText.length());
}
use of javax.servlet.ServletOutputStream in project Lucee by lucee.
the class CFMLWriterImpl method getOutputStream.
private OutputStream getOutputStream(boolean allowCompression) throws IOException {
if (allowCompression) {
String encodings = ReqRspUtil.getHeader(request, "Accept-Encoding", "");
if (encodings.indexOf("gzip") != -1) {
boolean inline = HttpServletResponseWrap.get();
if (!inline) {
ServletOutputStream os = response.getOutputStream();
response.setHeader("Content-Encoding", "gzip");
return new GZIPOutputStream(os);
}
}
}
return response.getOutputStream();
}
use of javax.servlet.ServletOutputStream in project alf.io by alfio-event.
the class EventApiController method downloadSponsorScanExport.
@RequestMapping("/events/{eventName}/sponsor-scan/export.csv")
public void downloadSponsorScanExport(@PathVariable("eventName") String eventName, HttpServletResponse response, Principal principal) throws IOException {
Event event = loadEvent(eventName, principal);
List<TicketFieldConfiguration> fields = ticketFieldRepository.findAdditionalFieldsForEvent(event.getId());
response.setContentType("text/csv;charset=UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=" + eventName + "-sponsor-scan.csv");
try (ServletOutputStream out = response.getOutputStream();
CSVWriter writer = new CSVWriter(new OutputStreamWriter(out))) {
for (int marker : BOM_MARKERS) {
out.write(marker);
}
List<String> header = new ArrayList<>();
header.add("Username");
header.add("Timestamp");
header.add("Full name");
header.add("Email");
header.addAll(fields.stream().map(TicketFieldConfiguration::getName).collect(toList()));
writer.writeNext(header.toArray(new String[header.size()]));
userManager.findAllEnabledUsers(principal.getName()).stream().map(u -> Pair.of(u, userManager.getUserRole(u))).filter(p -> p.getRight() == Role.SPONSOR).flatMap(p -> sponsorScanRepository.loadSponsorData(event.getId(), p.getKey().getId(), SponsorScanRepository.DEFAULT_TIMESTAMP).stream().map(v -> Pair.of(v, ticketFieldRepository.findAllValuesForTicketId(v.getTicket().getId())))).map(p -> {
DetailedScanData data = p.getLeft();
Map<String, String> descriptions = p.getRight();
return Pair.of(data, fields.stream().map(x -> descriptions.getOrDefault(x.getName(), "")).collect(toList()));
}).map(p -> {
List<String> line = new ArrayList<>();
Ticket ticket = p.getLeft().getTicket();
SponsorScan sponsorScan = p.getLeft().getSponsorScan();
line.add(userManager.findUser(sponsorScan.getUserId()).getUsername());
line.add(sponsorScan.getTimestamp().toString());
line.add(ticket.getFullName());
line.add(ticket.getEmail());
line.addAll(p.getRight());
return line.toArray(new String[line.size()]);
}).forEachOrdered(writer::writeNext);
writer.flush();
out.flush();
}
}
Aggregations