use of javax.servlet.ServletOutputStream in project opennms by OpenNMS.
the class MattermostNotificationStrategyTestServlet method squawk.
@SuppressWarnings("unchecked")
private void squawk(final HttpServletResponse resp, String reason) throws IOException {
JSONObject errorJson = new JSONObject();
errorJson.put("message", reason);
errorJson.put("detailed_error", "");
errorJson.put("request_id", "deadbeefcafebabe");
errorJson.put("status_code", 500);
errorJson.put("isoauth", false);
final String responseText = errorJson.toJSONString();
final ServletOutputStream os = resp.getOutputStream();
os.print(responseText);
os.close();
resp.setContentType("application/json");
resp.setContentLength(responseText.length());
resp.setStatus(500);
}
use of javax.servlet.ServletOutputStream in project OpenAM by OpenRock.
the class ConfigureGoogleAppsCompleteViewBean method handleButtonDownloadCertRequest.
/**
* Handles Verification Certificate download button request.
* Sends Verification Certificate to the ServletResponse output stream.
* @param event Request invocation event
*/
public void handleButtonDownloadCertRequest(RequestInvocationEvent event) throws ModelControlException {
RequestContext reqContext = event.getRequestContext();
HttpServletResponse resp = reqContext.getResponse();
String cert = (String) psModel.getValue("PubKey");
ServletOutputStream op = null;
try {
int length = 0;
op = resp.getOutputStream();
// Set the response
resp.setContentType("application/octet-stream");
resp.setContentLength(cert.length());
resp.setHeader("Content-Disposition", "attachment; filename=\"" + "OpenSSOCert.txt" + "\"");
// Stream to the requester.
int BUFSIZE = cert.length();
byte[] bbuf = new byte[BUFSIZE];
InputStream is = new ByteArrayInputStream(cert.getBytes());
DataInputStream in = new DataInputStream(is);
while ((in != null) && ((length = in.read(bbuf)) != -1)) {
op.write(bbuf, 0, length);
}
in.close();
op.flush();
} catch (IOException ex) {
debug.error("ConfigureGoogleAppsCompleteViewBean.uploadCert", ex);
setInlineAlertMessage(CCAlert.TYPE_ERROR, "configure.google.apps.complete.certificate.download.error", ex.getMessage());
} finally {
if (op != null) {
try {
op.close();
} catch (IOException ex) {
debug.error("ConfigureGoogleAppsCompleteViewBean.uploadCert", ex);
setInlineAlertMessage(CCAlert.TYPE_ERROR, "configure.google.apps.complete.certificate.download.error", ex.getMessage());
}
}
}
}
use of javax.servlet.ServletOutputStream in project OpenAM by OpenRock.
the class PLLRequestServlet method doGet.
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, java.io.IOException {
ServletOutputStream out = res.getOutputStream();
out.print("OpenSSO");
out.flush();
}
use of javax.servlet.ServletOutputStream in project alluxio by Alluxio.
the class WebInterfaceDownloadLocalServlet method downloadLogFile.
/**
* This function prepares for downloading a log file on the local filesystem.
*
* @param file the local log file to download
* @param request the {@link HttpServletRequest} object
* @param response the {@link HttpServletResponse} object
* @throws IOException if an I/O error occurs
*/
private void downloadLogFile(File file, HttpServletRequest request, HttpServletResponse response) throws IOException {
long len = file.length();
String fileName = file.getName();
response.setContentType("application/octet-stream");
if (len <= Integer.MAX_VALUE) {
response.setContentLength((int) len);
} else {
response.addHeader("Content-Length", Long.toString(len));
}
response.addHeader("Content-Disposition", "attachment;filename=" + fileName);
try (InputStream is = new FileInputStream(file)) {
ServletOutputStream out = response.getOutputStream();
try {
ByteStreams.copy(is, out);
} finally {
try {
out.flush();
} finally {
out.close();
}
}
}
}
use of javax.servlet.ServletOutputStream in project atmosphere by Atmosphere.
the class AtmosphereResourceTest method testCloseResponseOutputStream.
@Test
public void testCloseResponseOutputStream() throws IOException {
AtmosphereResponse response = AtmosphereResponseImpl.newInstance();
AsyncIOWriter writer = mock(AsyncIOWriter.class);
AsyncIOWriter wswriter = mock(WebSocket.class);
response.asyncIOWriter(writer);
ServletOutputStream sos = response.getOutputStream();
sos.close();
verify(writer, times(1)).close(response);
reset(writer);
response.asyncIOWriter(wswriter);
sos = response.getOutputStream();
sos.close();
verify(wswriter, times(0)).close(response);
}
Aggregations