Search in sources :

Example 1 with IORuntimeException

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());
}
Also used : IORuntimeException(org.codelibs.core.exception.IORuntimeException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AsyncManager(org.lastaflute.core.magic.async.AsyncManager) LocalDateTime(java.time.LocalDateTime) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) Curl(org.codelibs.elasticsearch.runner.net.Curl) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) ArrayList(java.util.ArrayList) ResourceUtil(org.codelibs.fess.util.ResourceUtil) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) StreamResponse(org.lastaflute.web.response.StreamResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) Map(java.util.Map) OutputStreamWriter(java.io.OutputStreamWriter) FavoriteLogBhv(org.codelibs.fess.es.log.exbhv.FavoriteLogBhv) CurlResponse(org.codelibs.elasticsearch.runner.net.CurlResponse) CopyUtil(org.codelibs.core.io.CopyUtil) HtmlResponse(org.lastaflute.web.response.HtmlResponse) OutputStream(java.io.OutputStream) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) Logger(org.slf4j.Logger) UserInfoBhv(org.codelibs.fess.es.log.exbhv.UserInfoBhv) BufferedWriter(java.io.BufferedWriter) ClickLogBhv(org.codelibs.fess.es.log.exbhv.ClickLogBhv) SearchFieldLogBhv(org.codelibs.fess.es.log.exbhv.SearchFieldLogBhv) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) CsvWriter(com.orangesignal.csv.CsvWriter) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) RuntimeIOException(com.healthmarketscience.jackcess.RuntimeIOException) CsvConfig(com.orangesignal.csv.CsvConfig) ActionResponse(org.lastaflute.web.response.ActionResponse) List(java.util.List) SearchLogBhv(org.codelibs.fess.es.log.exbhv.SearchLogBhv) ComponentUtil(org.codelibs.fess.util.ComponentUtil) DateTimeFormatter(java.time.format.DateTimeFormatter) Execute(org.lastaflute.web.Execute) InputStream(java.io.InputStream) IORuntimeException(org.codelibs.core.exception.IORuntimeException) CurlResponse(org.codelibs.elasticsearch.runner.net.CurlResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) RuntimeIOException(com.healthmarketscience.jackcess.RuntimeIOException) IORuntimeException(org.codelibs.core.exception.IORuntimeException) IOException(java.io.IOException) RuntimeIOException(com.healthmarketscience.jackcess.RuntimeIOException) Execute(org.lastaflute.web.Execute)

Example 2 with IORuntimeException

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);
    }
}
Also used : IORuntimeException(org.codelibs.core.exception.IORuntimeException) HttpServletResponse(javax.servlet.http.HttpServletResponse) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Aggregations

IOException (java.io.IOException)2 OutputStreamWriter (java.io.OutputStreamWriter)2 IORuntimeException (org.codelibs.core.exception.IORuntimeException)2 RuntimeIOException (com.healthmarketscience.jackcess.RuntimeIOException)1 CsvConfig (com.orangesignal.csv.CsvConfig)1 CsvWriter (com.orangesignal.csv.CsvWriter)1 BufferedWriter (java.io.BufferedWriter)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 PrintWriter (java.io.PrintWriter)1 LocalDateTime (java.time.LocalDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1