Search in sources :

Example 6 with PwmResponse

use of password.pwm.http.PwmResponse in project pwm by pwm-project.

the class ConfigManagerLocalDBServlet method doExportLocalDB.

private void doExportLocalDB(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
    final PwmResponse resp = pwmRequest.getPwmResponse();
    final Instant startTime = Instant.now();
    resp.setHeader(HttpHeader.ContentDisposition, "attachment;filename=" + PwmConstants.PWM_APP_NAME + "-LocalDB.bak");
    resp.setContentType(HttpContentType.octetstream);
    resp.setHeader(HttpHeader.ContentTransferEncoding, "binary");
    final LocalDBUtility localDBUtility = new LocalDBUtility(pwmRequest.getPwmApplication().getLocalDB());
    try {
        final int bufferSize = Integer.parseInt(pwmRequest.getConfig().readAppProperty(AppProperty.HTTP_DOWNLOAD_BUFFER_SIZE));
        final OutputStream bos = new BufferedOutputStream(resp.getOutputStream(), bufferSize);
        localDBUtility.exportLocalDB(bos, LOGGER.asAppendable(PwmLogLevel.DEBUG, pwmRequest.getSessionLabel()), true);
        LOGGER.debug(pwmRequest, "completed localDBExport process in " + TimeDuration.fromCurrent(startTime).asCompactString());
    } catch (Exception e) {
        LOGGER.error(pwmRequest, "error downloading export localdb: " + e.getMessage());
    }
}
Also used : LocalDBUtility(password.pwm.util.localdb.LocalDBUtility) PwmResponse(password.pwm.http.PwmResponse) Instant(java.time.Instant) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) BufferedOutputStream(java.io.BufferedOutputStream) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException)

Aggregations

PwmResponse (password.pwm.http.PwmResponse)6 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)4 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)3 IOException (java.io.IOException)3 ServletException (javax.servlet.ServletException)3 PwmException (password.pwm.error.PwmException)3 PwmSession (password.pwm.http.PwmSession)3 OutputStream (java.io.OutputStream)2 ZipOutputStream (java.util.zip.ZipOutputStream)2 PwmApplication (password.pwm.PwmApplication)2 LocalSessionStateBean (password.pwm.bean.LocalSessionStateBean)2 Configuration (password.pwm.config.Configuration)2 BufferedOutputStream (java.io.BufferedOutputStream)1 Instant (java.time.Instant)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 SessionVerificationMode (password.pwm.config.option.SessionVerificationMode)1 StoredConfigurationImpl (password.pwm.config.stored.StoredConfigurationImpl)1 ErrorInformation (password.pwm.error.ErrorInformation)1 PwmOperationalException (password.pwm.error.PwmOperationalException)1 PwmURL (password.pwm.http.PwmURL)1