Example usage for java.lang Throwable getClass

List of usage examples for java.lang Throwable getClass

Introduction

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

Prototype

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

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.visual_tools.nubomedia.nuboEarJava.NuboEarJavaHandler.java

private void start(final WebSocketSession session, JsonObject jsonMessage) {
    try {//from ww  w.  ja  v  a  2  s. c  o  m

        String sessionId = session.getId();
        UserSession user = new UserSession(sessionId);
        users.put(sessionId, user);
        webRtcEndpoint = user.getWebRtcEndpoint();

        //Ice Candidate
        webRtcEndpoint.addOnIceCandidateListener(new EventListener<OnIceCandidateEvent>() {
            @Override
            public void onEvent(OnIceCandidateEvent event) {
                JsonObject response = new JsonObject();
                response.addProperty("id", "iceCandidate");
                response.add("candidate", JsonUtils.toJsonObject(event.getCandidate()));
                sendMessage(session, new TextMessage(response.toString()));
            }
        });

        /******** Media Logic ********/
        ear = new NuboEarDetector.Builder(user.getMediaPipeline()).build();

        webRtcEndpoint.connect(ear);
        ear.connect(webRtcEndpoint);
        ear.activateServerEvents(1, 3000);
        addEarListener();
        // SDP negotiation (offer and answer)
        String sdpOffer = jsonMessage.get("sdpOffer").getAsString();
        String sdpAnswer = webRtcEndpoint.processOffer(sdpOffer);

        // Sending response back to client
        JsonObject response = new JsonObject();
        response.addProperty("id", "startResponse");
        response.addProperty("sdpAnswer", sdpAnswer);

        synchronized (session) {
            sendMessage(session, new TextMessage(response.toString()));
        }
        webRtcEndpoint.gatherCandidates();

    } catch (NotEnoughResourcesException e) {
        log.warn("Not enough resources", e);
        notEnoughResources(session);
    } catch (Throwable t) {
        log.error("Exception starting session", t);
        error(session, t.getClass().getSimpleName() + ": " + t.getMessage());
    }
}

From source file:ca.uhn.fhir.rest.server.interceptor.ExceptionHandlingInterceptor.java

private void populateDetails(FhirContext theCtx, Throwable theException, IBaseOperationOutcome theOo) {
    if (myReturnStackTracesForExceptionTypes != null) {
        for (Class<?> next : myReturnStackTracesForExceptionTypes) {
            if (next.isAssignableFrom(theException.getClass())) {
                String detailsValue = theException.getMessage() + "\n\n"
                        + ExceptionUtils.getStackTrace(theException);
                OperationOutcomeUtil.addIssue(theCtx, theOo, "error", detailsValue, null, PROCESSING);
                return;
            }//from   w w  w  .j a  v  a 2  s .  co  m
        }
    }

    OperationOutcomeUtil.addIssue(theCtx, theOo, "error", theException.getMessage(), null, PROCESSING);
}

From source file:de.decoit.visa.http.ajax.handlers.QueuedModifyComponentNameHandler.java

@Override
public void handle(HttpExchange he) throws IOException {
    log.info(he.getRequestURI().toString());

    // Get the URI of the request and extract the query string from it
    QueryString queryParameters = new QueryString(he.getRequestURI());

    // Create StringBuilder for the response
    String response = null;//from   w w  w. j  a v a  2 s. c o m

    // Check if the query parameters are valid for this handler
    if (this.checkQueryParameters(queryParameters)) {
        // Any exception thrown during object creation will cause
        // failure of the AJAX request
        try {
            JSONObject rv = new JSONObject();

            ModificationQueue mq = TEBackend.getModificationQueue(queryParameters.get("queueID").get());
            mq.addModification(ModificationTarget.COMPONENT, queryParameters.get("compID").get(),
                    ModificationTargetAttribute.COMPONENT_NAME, queryParameters.get("name").get());

            rv.put("status", AJAXServer.AJAX_SUCCESS);

            response = rv.toString();
        } catch (Throwable ex) {
            TEBackend.logException(ex, log);

            try {
                JSONObject rv = new JSONObject();
                rv.put("status", AJAXServer.AJAX_ERROR_EXCEPTION);
                rv.put("type", ex.getClass().getSimpleName());
                rv.put("message", ex.getMessage());
                response = rv.toString();
            } catch (JSONException e) {
                /* Ignore */
            }
        }

    } else {
        // Missing or malformed query string, set response to error code
        JSONObject rv = new JSONObject();
        try {
            rv.put("status", AJAXServer.AJAX_ERROR_MISSING_ARGS);
        } catch (JSONException exc) {
            /* Ignore */
        }

        response = rv.toString();
    }

    // Send the response
    sendResponse(he, response);
}

From source file:de.decoit.visa.http.ajax.handlers.QueuedModifyInterfaceIPHandler.java

@Override
public void handle(HttpExchange he) throws IOException {
    log.info(he.getRequestURI().toString());

    // Get the URI of the request and extract the query string from it
    QueryString queryParameters = new QueryString(he.getRequestURI());

    // Create StringBuilder for the response
    String response = null;/*from w  w w.j a v  a 2 s  .c  o m*/

    // Check if the query parameters are valid for this handler
    if (this.checkQueryParameters(queryParameters)) {
        // Any exception thrown during object creation will cause
        // failure of the AJAX request
        try {
            JSONObject rv = new JSONObject();

            ModificationQueue mq = TEBackend.getModificationQueue(queryParameters.get("queueID").get());
            mq.addModification(ModificationTarget.INTERFACE, queryParameters.get("ifID").get(),
                    ModificationTargetAttribute.INTERFACE_NETWORK, queryParameters.get("net").get());

            rv.put("status", AJAXServer.AJAX_SUCCESS);

            response = rv.toString();
        } catch (Throwable ex) {
            TEBackend.logException(ex, log);

            try {
                JSONObject rv = new JSONObject();
                rv.put("status", AJAXServer.AJAX_ERROR_EXCEPTION);
                rv.put("type", ex.getClass().getSimpleName());
                rv.put("message", ex.getMessage());
                response = rv.toString();
            } catch (JSONException e) {
                /* Ignore */
            }
        }

    } else {
        // Missing or malformed query string, set response to error code
        JSONObject rv = new JSONObject();
        try {
            rv.put("status", AJAXServer.AJAX_ERROR_MISSING_ARGS);
        } catch (JSONException exc) {
            /* Ignore */
        }

        response = rv.toString();
    }

    // Send the response
    sendResponse(he, response);
}

From source file:de.decoit.visa.http.ajax.handlers.QueuedModifyInterfaceOrientationHandler.java

@Override
public void handle(HttpExchange he) throws IOException {
    log.info(he.getRequestURI().toString());

    // Get the URI of the request and extract the query string from it
    QueryString queryParameters = new QueryString(he.getRequestURI());

    // Create StringBuilder for the response
    String response = null;//www .j a  va 2s. c om

    // Check if the query parameters are valid for this handler
    if (this.checkQueryParameters(queryParameters)) {
        // Any exception thrown during object creation will cause
        // failure of the AJAX request
        try {
            JSONObject rv = new JSONObject();

            ModificationQueue mq = TEBackend.getModificationQueue(queryParameters.get("queueID").get());
            mq.addModification(ModificationTarget.INTERFACE, queryParameters.get("ifID").get(),
                    ModificationTargetAttribute.INTERFACE_ORIENTATION, queryParameters.get("ori").get());

            rv.put("status", AJAXServer.AJAX_SUCCESS);

            response = rv.toString();
        } catch (Throwable ex) {
            TEBackend.logException(ex, log);

            try {
                JSONObject rv = new JSONObject();
                rv.put("status", AJAXServer.AJAX_ERROR_EXCEPTION);
                rv.put("type", ex.getClass().getSimpleName());
                rv.put("message", ex.getMessage());
                response = rv.toString();
            } catch (JSONException e) {
                /* Ignore */
            }
        }

    } else {
        // Missing or malformed query string, set response to error code
        JSONObject rv = new JSONObject();
        try {
            rv.put("status", AJAXServer.AJAX_ERROR_MISSING_ARGS);
        } catch (JSONException exc) {
            /* Ignore */
        }

        response = rv.toString();
    }

    // Send the response
    sendResponse(he, response);
}

From source file:info.magnolia.ui.admincentral.AdmincentralErrorHandler.java

private void addMessageDetails(Message message, Throwable e) {
    if (e != null) {

        // message details
        String content = message.getMessage();
        if (content == null) {
            content = "";
        } else {//from w  w  w.j a  va  2s .  com
            content += "\ncaused by ";
        }
        content += e.getClass().getSimpleName();
        if (StringUtils.isNotBlank(e.getMessage())) {
            content += ": " + e.getMessage();

            // message subject
            message.setSubject(e.getMessage());
        }
        message.setMessage(content);
    }
}

From source file:de.decoit.visa.http.ajax.handlers.IOToolDropTopologyHandler.java

@Override
public void handle(HttpExchange he) throws IOException {
    log.info(he.getRequestURI().toString());

    // Get the URI of the request and extract the query string from it
    QueryString queryParameters = new QueryString(he.getRequestURI());

    // Create String for the response
    String response = null;/*from  w w  w.j  a  v  a2s . co  m*/

    // Check if the query parameters are valid for this handler
    if (this.checkQueryParameters(queryParameters)) {
        // Any exception thrown during object creation will
        // cause failure of the AJAX request
        try {
            // Execute the request to the IO-Tool
            IOToolRequestStatus status = TEBackend.getIOConnector()
                    .dropTopology(queryParameters.get("id").get());

            JSONObject rv = new JSONObject();
            if (status == IOToolRequestStatus.SUCCESS) {
                rv.put("status", AJAXServer.AJAX_SUCCESS);
            } else if (status == IOToolRequestStatus.IOTOOL_BUSY) {
                rv.put("status", AJAXServer.AJAX_ERROR_IOTOOL_BUSY);
            } else {
                rv.put("status", AJAXServer.AJAX_ERROR_GENERAL);
            }

            rv.put("returncode", TEBackend.getIOConnector().getLastReturnCode());
            rv.put("message", TEBackend.getIOConnector().getLastReturnMsg());
            response = rv.toString();
        } catch (Throwable ex) {
            TEBackend.logException(ex, log);

            JSONObject rv = new JSONObject();
            try {
                rv.put("status", AJAXServer.AJAX_ERROR_EXCEPTION);
                rv.put("type", ex.getClass().getSimpleName());
                rv.put("message", ex.getMessage());
            } catch (JSONException exc) {
                /* Ignore */
            }

            response = rv.toString();
        }
    } else {
        JSONObject rv = new JSONObject();
        try {
            // Missing or malformed query string, set response to error code
            rv.put("status", AJAXServer.AJAX_ERROR_MISSING_ARGS);
        } catch (JSONException exc) {
            /* Ignore */
        }

        response = rv.toString();
    }

    // Send the response
    sendResponse(he, response);
}

From source file:fitnesse.slim.StatementExecutor.java

private String exceptionToString(Throwable exception) {
    StringWriter stringWriter = new StringWriter();
    PrintWriter pw = new PrintWriter(stringWriter);
    exception.printStackTrace(pw);//from  www. j  av a2s  .  c  o  m
    if (exception.getClass().toString().contains("StopTest")) {
        stopRequested = true;
        return SlimServer.EXCEPTION_STOP_TEST_TAG + stringWriter.toString();
    } else {
        return SlimServer.EXCEPTION_TAG + stringWriter.toString();
    }
}

From source file:com.jigsforjava.web.controller.MultiActionController.java

/**
 * Determine the exception handler method for the given exception. Can
 * return null if not found.//  ww w.  j a v a 2  s. c om
 * 
 * @param exception From which its type will be deduced.
 * @return a handler for the given exception type, or <code>null</code>
 */
private Method getExceptionHandler(Throwable exception) {
    Class<?> exceptionClass = exception.getClass();
    Method handler = (Method) getExceptionHandlerMap().get(exceptionClass);
    while ((handler == null) && (!exceptionClass.equals(Throwable.class))) {
        exceptionClass = exceptionClass.getSuperclass();
        handler = (Method) getExceptionHandlerMap().get(exceptionClass);
    }
    return handler;
}

From source file:com.google.sampling.experiential.server.reports.ReportsBackendServlet.java

@Override
protected void doGet(final HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    final String requestorEmail = getRequestorEmail(req);
    final ReportRequest reportRequestObj = new ReportRequest(req, requestorEmail, REPORT_WORKER);
    final String jobId = getJobId(reportRequestObj);
    final ReportJobStatusManager statusMgr = new ReportJobStatusManager();
    statusMgr.startReport(requestorEmail, jobId);

    final ClassLoader cl = getClass().getClassLoader();
    final Thread thread2 = ThreadManager.createBackgroundThread(new Runnable() {
        @Override/*from ww  w .ja va2s. co  m*/
        public void run() {

            log.info("ReportsBackend running");
            Thread.currentThread().setContextClassLoader(cl);
            try {
                String key = runReport(reportRequestObj, jobId);
                if (key != null) {
                    statusMgr.completeReport(requestorEmail, jobId, key);
                } else {
                    statusMgr.failReport(requestorEmail, jobId, "Check server logs for stacktrace");
                }
            } catch (Throwable e) {
                final String fullStack = getStackTraceAsString(e);
                final String string = fullStack.length() > 700 ? fullStack.substring(0, 700) : fullStack;
                statusMgr.failReport(requestorEmail, jobId,
                        e.getClass() + "." + e.getMessage() + "\n" + string);
                log.severe("Could not run migration job: " + e.getMessage());
                log.severe("stacktrace: " + fullStack);
            }
        }
    });
    thread2.start();
    log.info("Leaving reports backend");
    resp.setContentType("text/plain;charset=UTF-8");
    resp.getWriter().println(jobId);
}