use of com.cloudbees.jenkins.support.api.ComponentVisitor in project support-core-plugin by jenkinsci.
the class SupportObjectAction method doGenerateAndDownload.
@RequirePOST
// used by Stapler
@SuppressWarnings("unused")
public final void doGenerateAndDownload(StaplerRequest req, StaplerResponse rsp) throws ServletException, IOException, Descriptor.FormException {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
LOGGER.fine("Preparing response...");
rsp.setContentType("application/zip");
JSONObject json = req.getSubmittedForm();
if (json == null || !json.has("components")) {
rsp.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
LOGGER.fine("Parsing request...");
List<ObjectComponent<T>> components = new ArrayList<>(parseRequest(req));
rsp.addHeader("Content-Disposition", "inline; filename=" + BundleFileName.generate(getBundleNameQualifier()) + ";");
try {
SupportPlugin.setRequesterAuthentication(Jenkins.getAuthentication());
try (ACLContext old = ACL.as(ACL.SYSTEM)) {
SupportPlugin.writeBundle(rsp.getOutputStream(), components, new ComponentVisitor() {
@Override
public <C extends Component> void visit(Container container, C component) {
((ObjectComponent<T>) component).addContents(container, object);
}
});
} catch (IOException e) {
LOGGER.log(Level.WARNING, e.getMessage(), e);
} finally {
SupportPlugin.clearRequesterAuthentication();
}
} finally {
LOGGER.fine("Response completed");
}
}
Aggregations