use of org.codelibs.core.exception.IORuntimeException in project fess by codelibs.
the class AdminBackupAction method upload.
@Execute
public HtmlResponse upload(final UploadForm form) {
validate(form, messages -> {
}, () -> asListHtml());
verifyToken(() -> asListHtml());
asyncManager.async(() -> {
final String fileName = form.bulkFile.getFileName();
if (fileName.startsWith("system") && fileName.endsWith(".properties")) {
try (final InputStream in = form.bulkFile.getInputStream()) {
ComponentUtil.getSystemProperties().load(in);
} catch (final IOException e) {
logger.warn("Failed to process system.properties file: " + form.bulkFile.getFileName(), e);
}
} else {
try (CurlResponse response = Curl.post(ResourceUtil.getElasticsearchHttpUrl() + "/_bulk").header("Content-Type", "application/json").onConnect((req, con) -> {
con.setDoOutput(true);
try (InputStream in = form.bulkFile.getInputStream();
OutputStream out = con.getOutputStream()) {
CopyUtil.copy(in, out);
} catch (IOException e) {
throw new IORuntimeException(e);
}
}).execute()) {
if (logger.isDebugEnabled()) {
logger.debug("Bulk Response:\n" + response.getContentAsString());
}
systemHelper.reloadConfiguration();
} catch (final Exception e) {
logger.warn("Failed to process bulk file: " + form.bulkFile.getFileName(), e);
}
}
});
saveInfo(messages -> messages.addSuccessBulkProcessStarted(GLOBAL));
// no-op
return redirect(getClass());
}
use of org.codelibs.core.exception.IORuntimeException in project fess by codelibs.
the class BaseApiManager method write.
public static void write(final String text, final String contentType, final String encoding) {
final StringBuilder buf = new StringBuilder(50);
if (contentType == null) {
buf.append("text/plain");
} else {
buf.append(contentType);
}
buf.append("; charset=");
final String enc;
if (encoding == null) {
if (LaRequestUtil.getRequest().getCharacterEncoding() == null) {
enc = Constants.UTF_8;
} else {
enc = LaRequestUtil.getRequest().getCharacterEncoding();
}
} else {
enc = encoding;
}
buf.append(enc);
final HttpServletResponse response = LaResponseUtil.getResponse();
response.setContentType(buf.toString());
try (PrintWriter out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), enc))) {
out.print(text);
} catch (final IOException e) {
throw new IORuntimeException(e);
}
}
Aggregations