use of javax.servlet.ServletOutputStream in project nifi by apache.
the class AtlasAPIV2ServerEmulator method respondWithJson.
private static void respondWithJson(HttpServletResponse resp, Object entity, int statusCode) throws IOException {
resp.setContentType("application/json");
resp.setStatus(statusCode);
final ServletOutputStream out = resp.getOutputStream();
new ObjectMapper().writer().writeValue(out, entity);
out.flush();
}
use of javax.servlet.ServletOutputStream in project nifi by apache.
the class TestHttpClient method respondWithJson.
private static void respondWithJson(HttpServletResponse resp, Object entity, int statusCode) throws IOException {
resp.setContentType("application/json");
resp.setStatus(statusCode);
final ServletOutputStream out = resp.getOutputStream();
new ObjectMapper().writer().writeValue(out, entity);
out.flush();
}
use of javax.servlet.ServletOutputStream in project nifi by apache.
the class TestHttpClient method respondWithText.
private static void respondWithText(HttpServletResponse resp, String result, int statusCode) throws IOException {
resp.setContentType("text/plain");
resp.setStatus(statusCode);
final ServletOutputStream out = resp.getOutputStream();
out.write(result.getBytes());
out.flush();
}
use of javax.servlet.ServletOutputStream in project jphp by jphp-compiler.
the class PHttpDownloadFileHandler method __invoke.
@Signature
public boolean __invoke(Environment env, PHttpServerRequest request, PHttpServerResponse response) throws Throwable {
HttpServletResponse res = response.getResponse();
if (!file.isFile()) {
response.write(StringMemory.valueOf("File (" + fileName + ") not found."));
res.setStatus(404);
return false;
}
res.setStatus(200);
res.setContentType(contentType);
res.setContentLengthLong(file.length());
if (fileName.isEmpty()) {
res.addHeader("Content-Disposition", "attachment");
} else {
res.addHeader("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(fileName, env.getDefaultCharset().name()) + "\"");
}
ServletOutputStream outputStream = res.getOutputStream();
InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
byte[] buffer = new byte[128 * 1024];
while (true) {
int bytesRead = inputStream.read(buffer);
if (bytesRead < 0) {
break;
}
outputStream.write(buffer, 0, bytesRead);
}
inputStream.close();
outputStream.close();
request.end();
return true;
}
use of javax.servlet.ServletOutputStream in project support-core-plugin by jenkinsci.
the class SupportAction method doGenerateAllBundles.
@RequirePOST
public void doGenerateAllBundles(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException {
final Jenkins instance = Jenkins.getInstance();
instance.getAuthorizationStrategy().getACL(instance).checkPermission(CREATE_BUNDLE);
JSONObject json = req.getSubmittedForm();
if (!json.has("components")) {
rsp.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
logger.fine("Parsing request...");
Set<String> remove = new HashSet<String>();
for (Selection s : req.bindJSONToList(Selection.class, json.get("components"))) {
if (!s.isSelected()) {
logger.log(Level.FINER, "Excluding ''{0}'' from list of components to include", s.getName());
remove.add(s.getName());
}
}
logger.fine("Selecting components...");
final List<Component> components = new ArrayList<Component>(getComponents());
for (Iterator<Component> iterator = components.iterator(); iterator.hasNext(); ) {
Component c = iterator.next();
if (remove.contains(c.getId()) || !c.isEnabled()) {
iterator.remove();
}
}
final SupportPlugin supportPlugin = SupportPlugin.getInstance();
if (supportPlugin != null) {
supportPlugin.setExcludedComponents(remove);
}
logger.fine("Preparing response...");
rsp.setContentType("application/zip");
rsp.addHeader("Content-Disposition", "inline; filename=" + SupportPlugin.getBundleFileName() + ";");
final ServletOutputStream servletOutputStream = rsp.getOutputStream();
try {
SupportPlugin.setRequesterAuthentication(Jenkins.getAuthentication());
try {
SecurityContext old = ACL.impersonate(ACL.SYSTEM);
try {
SupportPlugin.writeBundle(servletOutputStream, components);
} catch (IOException e) {
logger.log(Level.FINE, e.getMessage(), e);
} finally {
SecurityContextHolder.setContext(old);
}
} finally {
SupportPlugin.clearRequesterAuthentication();
}
} finally {
logger.fine("Response completed");
}
}
Aggregations