Example usage for java.lang Exception getClass

List of usage examples for java.lang Exception getClass

Introduction

In this page you can find the example usage for java.lang Exception getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:net.pandoragames.far.ui.FileSearchThread.java

/**
 * Executes {@link net.pandoragames.far.FileSelector#listFiles(Pattern, File) FileSelector.listFiles()}.
 *///from w  w w.java  2  s. com
public void run() {
    if (threadLog.isInfoEnabled()) {
        StringBuilder buffer = new StringBuilder();
        buffer.append("Searching for ");
        buffer.append(criteria.getFileNamePattern().getPattern());
        if (criteria.getFileNamePattern().isRegex())
            buffer.append(" (regex)");
        buffer.append(" at ").append(criteria.getBaseDirectory().getPath());
        if (criteria.isIncludeSubDirs()) {
            buffer.append(" and subdirectories");
            if (criteria.getDirectoryPattern() != null) {
                buffer.append(" (");
                if (criteria.getFileNamePattern().isRegex())
                    buffer.append("regex: ");
                buffer.append(criteria.getDirectoryPattern().getPattern());
                if (criteria.isExcludeMatchingDirectories())
                    buffer.append(" excluded");
                buffer.append(")");
            }
        }
        threadLog.info(buffer.toString());
    }
    fileSelector.setMaxSearchDepth(criteria.isIncludeSubDirs() ? criteria.getMaxDepth() : 0);
    Pattern directoryPattern = null;
    if (criteria.getDirectoryPattern() != null) {
        if (criteria.isExcludeMatchingDirectories()) {
            fileSelector.setDirectoriesExcluded(criteria.getDirectoryPattern().toRegexPattern());
        } else {
            directoryPattern = criteria.getDirectoryPattern().toRegexPattern();
            fileSelector.setDirectoriesExcluded(null);
        }
    } else {
        fileSelector.setDirectoriesExcluded(null);
    }
    try {
        Pattern pattern = criteria.getFileNamePattern().toRegexPattern();
        fileSet = fileSelector.listFiles(pattern, criteria.getBaseDirectory(), criteria.getAfter(),
                criteria.getBefore(), directoryPattern);
        threadLog.info(fileSet.size() + " files found");
    } catch (Exception x) {
        threadLog.error(x.getClass().getName() + ": " + x.getMessage(), x);
        messageBox.error(x.getMessage());
        fileSet = new HashSet<File>();
    }
}

From source file:Commands.readFileCommand.java

@Override
public String executeCommand(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String UPLOAD_DIRECTORY = "C:\\Users\\USER\\Downloads\\Movies";
    String forwardToJsp = "";
    HttpSession session = request.getSession(true);
    if (ServletFileUpload.isMultipartContent(request)) {
        try {/*  w  w  w. j  ava2s.  c  o m*/
            ArrayList<FileItem> multiparts = (ArrayList<FileItem>) new ServletFileUpload(
                    new DiskFileItemFactory()).parseRequest(request);
            FileItem item = multiparts.get(0);
            if (!item.getName().isEmpty()) {
                String name = new File(item.getName()).getName();
                String filename = UPLOAD_DIRECTORY + File.separator + name;
                File f = new File(filename);
                boolean exists = f.exists();
                //if (!exists) {
                if (!item.isFormField()) {
                    item.write(f);

                    //                        if (fm.readFile(f)) {
                    //                            forwardToJsp = "Movie.jsp";
                    //                            session.setAttribute("filename", filename);
                    //                            session.setAttribute("allGenre", fm.allGenre());
                    //                            session.setAttribute("allMovie", fm.allMovie());
                    //                            session.setAttribute("most", fm.displayMost());
                    //                            session.setAttribute("score", fm.scoreInGroup());
                    //                            session.setAttribute("avgScore", fm.displayAverage());
                    //                            session.setAttribute("scoreOrder", fm.scoreOrder());
                    //                        } else {
                    //                            session.setAttribute("message", "fail to read file");
                    //                        }
                }
                // } else {
                //    session.setAttribute("message", "File already exists");
                //     forwardToJsp = "index.jsp";
                //}
            } else {
                session.setAttribute("message", "No File Choosen");
            }
        } catch (Exception ex) {
            session.setAttribute("message", ex.getMessage() + ex.getClass());
        }
    } else {
        session.setAttribute("message", "Sorry this Servlet only handles file upload request");
    }
    return forwardToJsp;
}

From source file:de.hybris.platform.ycommercewebservices.v2.controller.BaseController.java

@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody//from   w w w . ja  v a 2s.c  om
@ExceptionHandler({ ModelNotFoundException.class })
public ErrorListWsDTO handleModelNotFoundException(final Exception ex) {
    LOG.info(
            "Handling Exception for this request - " + ex.getClass().getSimpleName() + " - " + ex.getMessage());
    if (LOG.isDebugEnabled()) {
        LOG.debug(ex);
    }
    final ErrorListWsDTO errorListDto = handleErrorInternal(UnknownIdentifierException.class.getSimpleName(),
            ex.getMessage());
    return errorListDto;
}

From source file:de.dfki.owlsmx.gui.ShowResultVisualization.java

private void saveActionPerformed(java.awt.event.ActionEvent event) {//GEN-FIRST:event_saveActionPerformed
    try {/*from   w w w .  ja va2  s.c  o  m*/
        if (event.getSource().equals(save)) {
            if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
                if (fc.getFileFilter().getClass().equals((new PNGFilter()).getClass()))
                    if (fc.getSelectedFile().getAbsolutePath().toLowerCase().endsWith(".png"))
                        ChartUtilities.saveChartAsPNG(fc.getSelectedFile(), chart,
                                ResultVisualization.graphPrintWidth, ResultVisualization.graphPrintHeight);
                    else
                        ChartUtilities.saveChartAsPNG(new File(fc.getSelectedFile().getAbsolutePath() + ".png"),
                                chart, ResultVisualization.graphPrintWidth,
                                ResultVisualization.graphPrintHeight);

                else if (fc.getFileFilter().getClass().equals((new JPGFilter()).getClass()))
                    if (fc.getSelectedFile().getAbsolutePath().toLowerCase().endsWith(".png"))
                        ChartUtilities.saveChartAsJPEG(fc.getSelectedFile(), chart,
                                ResultVisualization.graphPrintWidth, ResultVisualization.graphPrintHeight);
                    else
                        ChartUtilities.saveChartAsJPEG(
                                new File(fc.getSelectedFile().getAbsolutePath() + ".png"), chart,
                                ResultVisualization.graphPrintWidth, ResultVisualization.graphPrintHeight);

                else if (fc.getFileFilter().getClass().equals((new PDFFilter()).getClass()))
                    if (fc.getSelectedFile().getAbsolutePath().toLowerCase().endsWith(".pdf"))
                        Converter.convertToPdf(chart, ResultVisualization.graphPrintWidth,
                                ResultVisualization.graphPrintHeight, fc.getSelectedFile().getAbsolutePath());
                    else
                        Converter.convertToPdf(chart, ResultVisualization.graphPrintWidth,
                                ResultVisualization.graphPrintHeight,
                                fc.getSelectedFile().getAbsolutePath() + ".pdf");
                else if (fc.getFileFilter().getClass().equals((new EPSFilter()).getClass()))
                    printGraphics2DtoEPS(fc.getSelectedFile().getAbsolutePath());
            }
        }
    } catch (Exception e) {
        GUIState.displayWarning(e.getClass().toString(),
                "Couldn't save file " + fc.getSelectedFile().getAbsolutePath());
        e.printStackTrace();
    }
}

From source file:cz.muni.fi.mir.controllers.ExceptionHandlingController.java

private ModelMap prepareModelMap(Exception e, String stacktraceOutput) {
    ModelMap mm = new ModelMap();
    mm.addAttribute("exception", e.getClass().getSimpleName());
    mm.addAttribute("message", e.getMessage());
    mm.addAttribute("stackTrace", stacktraceOutput);

    return mm;/* w  ww  . j a  v a2s.co m*/
}

From source file:io.getlime.security.powerauth.rest.api.spring.controller.SecureVaultController.java

/**
 * Request the vault unlock key./*from w  ww. j a  v a  2  s .c  o m*/
 * @param signatureHeader PowerAuth signature HTTP header.
 * @return PowerAuth RESTful response with {@link VaultUnlockResponse} payload.
 * @throws PowerAuthAuthenticationException In case authentication fails.
 */
@RequestMapping(value = "unlock", method = RequestMethod.POST)
public @ResponseBody PowerAuthApiResponse<VaultUnlockResponse> unlockVault(
        @RequestHeader(value = PowerAuthHttpHeader.HEADER_NAME, defaultValue = "unknown") String signatureHeader)
        throws PowerAuthAuthenticationException, PowerAuthSecureVaultException {

    try {
        Map<String, String> map = PowerAuthHttpHeader.parsePowerAuthSignatureHTTPHeader(signatureHeader);
        String activationId = map.get(PowerAuthHttpHeader.ACTIVATION_ID);
        String applicationId = map.get(PowerAuthHttpHeader.APPLICATION_ID);
        String signature = map.get(PowerAuthHttpHeader.SIGNATURE);
        String signatureType = map.get(PowerAuthHttpHeader.SIGNATURE_TYPE);
        String nonce = map.get(PowerAuthHttpHeader.NONCE);

        String data = PowerAuthHttpBody.getSignatureBaseString("POST", "/pa/vault/unlock",
                BaseEncoding.base64().decode(nonce), null);

        io.getlime.powerauth.soap.VaultUnlockResponse soapResponse = powerAuthClient.unlockVault(activationId,
                applicationId, data, signature, signatureType);

        if (!soapResponse.isSignatureValid()) {
            throw new PowerAuthAuthenticationException();
        }

        VaultUnlockResponse response = new VaultUnlockResponse();
        response.setActivationId(soapResponse.getActivationId());
        response.setEncryptedVaultEncryptionKey(soapResponse.getEncryptedVaultEncryptionKey());

        return new PowerAuthApiResponse<>(PowerAuthApiResponse.Status.OK, response);
    } catch (Exception ex) {
        if (PowerAuthAuthenticationException.class.equals(ex.getClass())) {
            throw ex;
        } else {
            throw new PowerAuthSecureVaultException();
        }
    }
}

From source file:gumga.framework.presentation.exceptionhandler.ErrorMessageHandlerExceptionResolver.java

@SuppressWarnings("unchecked")
@Override/* ww w .j  a  va2 s .c  o m*/
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response,
        Object handler, Exception ex) {
    ErrorMessageFactory errorMessageFactory = errorMessageFactories.get(ex.getClass());
    if (errorMessageFactory != null) {
        response.setStatus(errorMessageFactory.getResponseCode());
        ErrorMessage errorMessage = errorMessageFactory.getErrorMessage(ex);
        ServletWebRequest webRequest = new ServletWebRequest(request, response);
        try {
            return handleResponseBody(errorMessage, webRequest);
        } catch (Exception handlerException) {
            logger.warn("Handling of [" + ex.getClass().getName() + "] resulted in Exception",
                    handlerException);
        }
    }
    return null;
}

From source file:org.ct.amq.jdbc.security.JdbcAuthenticationPluginTest.java

public void testConnectionStartWithUnknownUserThrowsJMSSecurityException() throws Exception {

    Connection connection = factory.createConnection("badUser", "password");
    try {// w  w  w.  j a v  a  2s.c o m
        connection.start();
        fail("Should throw JMSSecurityException");
    } catch (JMSSecurityException jmsEx) {
    } catch (Exception e) {
        LOG.info("Expected JMSSecurityException but was: {}", e.getClass());
        fail("Should throw JMSSecurityException");
    }
}

From source file:org.ct.amq.jdbc.security.JdbcAuthenticationPluginTest.java

public void testConnectionStartWithDisabledUserThrowsJMSSecurityException() throws Exception {

    Connection connection = factory.createConnection("disableduser", "password");
    try {/*w  ww .  j  ava 2  s.  c om*/
        connection.start();
        fail("Should throw JMSSecurityException");
    } catch (JMSSecurityException jmsEx) {
    } catch (Exception e) {
        LOG.info("Expected JMSSecurityException but was: {}", e.getClass());
        fail("Should throw JMSSecurityException");
    }
}