Example usage for javax.servlet ServletException ServletException

List of usage examples for javax.servlet ServletException ServletException

Introduction

In this page you can find the example usage for javax.servlet ServletException ServletException.

Prototype


public ServletException() 

Source Link

Document

Constructs a new servlet exception.

Usage

From source file:org.jasig.cas.web.LicenceFilter.java

public void init(FilterConfig config) throws ServletException {
    //licence//from   w  w w  .  ja  v a  2s . c om
    String liurl = config.getInitParameter("liurl");
    if (liurl == null || liurl.isEmpty()) {
        throw new ServletException();
    }
    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpGet httpGet = new HttpGet(liurl);
    httpGet.addHeader("accept", "application/json");
    CloseableHttpResponse response1 = null;
    try {
        response1 = httpclient.execute(httpGet);
        if (response1.getStatusLine().getStatusCode() != 200) {
            System.out.println("licence ");
            throw new ServletException();
        }
        HttpEntity entity1 = response1.getEntity();
        BufferedReader br = new BufferedReader(new InputStreamReader((entity1.getContent())));
        String output;
        StringBuilder sb = new StringBuilder();
        while ((output = br.readLine()) != null) {
            sb.append(output);
        }
        JSONObject jsonObject = new JSONObject(sb.toString());
        String error = jsonObject.getString("code");
        if (!error.equals("S_OK")) {
            System.out.println("licence ");
            throw new ServletException();
        }
        String strexprietime = jsonObject.getJSONObject("var").getJSONObject("licInfo").getString("expireTime");
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        this.expiretime = df.parse(strexprietime).getTime();
        EntityUtils.consume(entity1);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            response1.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

From source file:net.mymam.upload.UploadMultipartRequestWrapper.java

public UploadMultipartRequestWrapper(HttpServletRequest request, ServletFileUpload upload)
        throws ServletException {
    super(request);
    try {//w w w  .ja  va 2s.  co  m
        List fileItems = upload.parseRequest(request);
        for (int i = 0; i < fileItems.size(); i++) {
            FileItem item = (FileItem) fileItems.get(i);
            if (item.isFormField()) {
                addParameter(item.getFieldName(), item.getString(), formParameters);
            } else {
                addParameter(item.getFieldName(), item, fileParameters);
            }
        }
    } catch (FileUploadException e) {
        // Request timed out
        ServletException servletException = new ServletException();
        servletException.initCause(e);
        throw servletException;
    }
}

From source file:ar.com.easytech.faces.filters.MultipartRequest.java

@SuppressWarnings("unchecked")
public MultipartRequest(HttpServletRequest request, String path) throws Exception {
    super(request);
    DiskFileItemFactory factory = new DiskFileItemFactory();

    if (path != null)
        factory.setRepository(new File(path));

    ServletFileUpload upload = new ServletFileUpload(factory);
    parameterMap.put("path", path);

    try {/* w ww.ja v a 2  s.  c  o m*/
        List<FileItem> items = (List<FileItem>) upload.parseRequest(request);

        for (FileItem item : items) {

            String str = item.getString();
            if (item.isFormField())
                parameterMap.put(item.getFieldName(), str);
            else {
                if (item.getName() != null) {
                    parameterMap.put("fileName", item.getName());
                }
                request.setAttribute(item.getFieldName(), item);
            }
        }

    } catch (FileUploadException ex) {
        ServletException servletEx = new ServletException();
        servletEx.initCause(ex);
        throw new Exception(ex.getLocalizedMessage());
    }
}

From source file:com.alfaariss.oa.util.web.SharedSecretFilter.java

/**
 * Initializes the <code>RemoteAddrFilter</code>.
 * //w  w  w  .j a v  a  2s. c  o  m
 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
 */
public void init(FilterConfig oFilterConfig) throws ServletException {
    try {
        //Get filter name
        _sFilterName = oFilterConfig.getFilterName();
        if (_sFilterName == null)
            _sFilterName = SharedSecretFilter.class.getSimpleName();

        //Read shared secret parameter
        _sharedSecret = oFilterConfig.getInitParameter("shared_secret");
        if (_sharedSecret == null || _sharedSecret.length() <= 0) {
            _logger.error("No 'shared_secret' init parameter found in filter configuration");
            throw new OAException(SystemErrors.ERROR_INIT);
        }
        _logger.info(_sFilterName + " started.");
    } catch (OAException e) {
        _logger.fatal(_sFilterName + " start failed", e);
        throw new ServletException();
    } catch (Exception e) {
        _logger.fatal(_sFilterName + " start failed due to internal error", e);
        throw new ServletException();
    }
}

From source file:com.alfaariss.oa.util.web.RemoteAddrFilter.java

/**
 * Initializes the <code>RemoteAddrFilter</code>.
 * /*from  www  .  j  a v  a 2s .com*/
 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
 */
public void init(FilterConfig oFilterConfig) throws ServletException {
    try {
        //Get filter name
        _sFilterName = oFilterConfig.getFilterName();
        if (_sFilterName == null)
            _sFilterName = RemoteAddrFilter.class.getSimpleName();

        //Read allowed IP from parameter
        _sIP = oFilterConfig.getInitParameter("allow");
        if (_sIP == null) {
            _logger.error("No 'allow' init parameter found in filter configuration");
            throw new OAException(SystemErrors.ERROR_INIT);
        }

        _sIP = _sIP.trim();

        StringTokenizer st = new StringTokenizer(_sIP, ",");
        if (st.countTokens() < 1) {
            _logger.error("Invalid 'allow' init parameter found in filter configuration");
            throw new OAException(SystemErrors.ERROR_INIT);
        }
        _logger.info("Only allowing requests from: " + _sIP);

        _logger.info(_sFilterName + " started");
    } catch (OAException e) {
        _logger.fatal(_sFilterName + " start failed", e);
        throw new ServletException();
    } catch (Exception e) {
        _logger.fatal(_sFilterName + " start failed due to internal error", e);
        throw new ServletException();
    }
}

From source file:com.corejsf.UploadFilter.java

public void init(FilterConfig config) throws ServletException {
    repositoryPath = ServerConfigurationService.getString("samigo.answerUploadRepositoryPath",
            "${sakai.home}/samigo/answerUploadRepositoryPath/");

    try {//from  www  .  jav  a2s  .co  m
        String paramValue = ServerConfigurationService.getString("samigo.sizeThreshold", "1024");
        if (paramValue != null)
            sizeThreshold = Integer.parseInt(paramValue);

        paramValue = ServerConfigurationService.getString("samigo.sizeMax", "40960");
        if (paramValue != null)
            sizeMax = Long.parseLong(paramValue);

        paramValue = ServerConfigurationService.getString("samigo.saveMediaToDb", "true");
        if (paramValue != null)
            saveMediaToDb = paramValue;

        //System.out.println("**** repositoryPath="+repositoryPath);
        //System.out.println("**** sabeMediaToDb="+saveMediaToDb);
        //System.out.println("**** sizeThreshold="+sizeThreshold);
        //System.out.println("**** sizeMax="+sizeMax);
    } catch (NumberFormatException ex) {
        ServletException servletEx = new ServletException();
        servletEx.initCause(ex);
        throw servletEx;
    }
    ServletContext context = config.getServletContext();
    context.setAttribute("FILEUPLOAD_REPOSITORY_PATH", repositoryPath);
    context.setAttribute("FILEUPLOAD_SIZE_THRESHOLD", Integer.valueOf(sizeThreshold));
    context.setAttribute("FILEUPLOAD_SIZE_MAX", Long.valueOf(sizeMax));
    context.setAttribute("FILEUPLOAD_SAVE_MEDIA_TO_DB", saveMediaToDb);
}