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.bstek.dorado.view.resolver.ViewServiceResolver.java

/**
 * @param jsonBuilder/* w  ww  .j  a v a 2 s .  com*/
 * @param e
 */
protected void outputException(JsonBuilder jsonBuilder, Throwable throwable) {
    while (throwable.getCause() != null) {
        throwable = throwable.getCause();
    }

    String message = throwable.getMessage();
    if (message == null) {
        message = throwable.getClass().getSimpleName();
    }

    try {
        jsonBuilder.object(); // TODO: ?JSONBuilder?
        jsonBuilder.key("exceptionType").value("JavaException").key("message").value(message).key("stackTrace");
        jsonBuilder.array();
        StackTraceElement[] stackTrace = throwable.getStackTrace();
        for (StackTraceElement stackTraceElement : stackTrace) {
            jsonBuilder.value(stackTraceElement.getClassName() + '.' + stackTraceElement.getMethodName() + '('
                    + stackTraceElement.getFileName() + ':' + stackTraceElement.getLineNumber() + ')');
        }
        jsonBuilder.endArray();
        jsonBuilder.endObject();
    } catch (Exception e) {
        // ignore e!!!
        throwable.printStackTrace();
    }
}

From source file:com.alliander.osgp.acceptancetests.deviceinstallation.AddDeviceSteps.java

@DomainStep("the add device request is received")
public void whenTheAddDeviceRequestIsReceived() {
    LOGGER.info("WHEN: \"the add device request is received\".");

    try {//  w  w  w.j a  v a  2  s.c  om
        this.response = this.deviceInstallationEndpoint.addDevice(this.organisation, this.request);
    } catch (final Throwable t) {
        if (t instanceof ValidationException) {
            LOGGER.error("Exception: {}", ((ValidationException) t).toString());
        } else {
            LOGGER.error("Exception: {}", t.getClass().getSimpleName());
        }

        this.throwable = t;
    }
}

From source file:com.alliander.osgp.acceptancetests.schedulemanagement.SetTariffScheduleSteps.java

@DomainStep("the get set tariff schedule response request should return a set schedule response with result (.*) and description (.*)")
public boolean thenTheGetSetTariffScheduleResultRequestShouldReturnAGetSetScheduleResultResponseWithResult(
        final String result, final String description) {
    LOGGER.info(//from w  w w. j a  v  a 2  s  .c o m
            "THEN: \"the get set tariff schedule result request should return a get set schedule response with result {} and description {}\".",
            result, description);

    try {
        if ("NOT_OK".equals(result)) {
            Assert.assertNull("Set Schedule Response should be null", this.response);
            Assert.assertNotNull("Throwable should not be null", this.throwable);
            Assert.assertTrue("Throwable should contain a validation exception",
                    this.throwable.getCause() instanceof ValidationException);
        } else {

            Assert.assertNotNull("Response should not be null", this.response);

            final String expectedResult = result.equals("NULL") ? null : result;
            final String actualResult = this.response.getResult().toString();

            Assert.assertTrue("Invalid result, found: " + actualResult + " , expected: " + expectedResult,
                    (actualResult == null && expectedResult == null) || actualResult.equals(expectedResult));
        }
    } catch (final Throwable t) {
        LOGGER.error("Exception [{}]: {}", t.getClass().getSimpleName(), t.getMessage());
        return false;
    }
    return true;
}

From source file:edu.internet2.middleware.shibboleth.common.config.BaseService.java

/**
 * Loads the service context.//www. j ava2  s  . c  o  m
 * 
 * @throws ServiceException thrown if the configuration for this service could not be loaded
 */
protected void loadContext() throws ServiceException {
    log.info("Loading new configuration for service {}", getId());

    if (serviceConfigurations == null || serviceConfigurations.isEmpty()) {
        setInitialized(true);
        return;
    }

    GenericApplicationContext newServiceContext = new GenericApplicationContext(getApplicationContext());
    newServiceContext.setDisplayName("ApplicationContext:" + getId());
    Lock writeLock = getReadWriteLock().writeLock();
    writeLock.lock();
    try {
        SpringConfigurationUtils.populateRegistry(newServiceContext, getServiceConfigurations());
        newServiceContext.refresh();

        GenericApplicationContext replacedServiceContext = serviceContext;
        onNewContextCreated(newServiceContext);
        setServiceContext(newServiceContext);
        setInitialized(true);
        if (replacedServiceContext != null) {
            replacedServiceContext.close();
        }
        log.info("{} service loaded new configuration", getId());
    } catch (Throwable e) {
        // Here we catch all the other exceptions thrown by Spring when it starts up the context
        setInitialized(false);
        Throwable rootCause = e;
        while (rootCause.getCause() != null) {
            rootCause = rootCause.getCause();
        }
        log.error("Configuration was not loaded for " + getId()
                + " service, error creating components.  The root cause of this error was: "
                + rootCause.getClass().getCanonicalName() + ": " + rootCause.getMessage());
        log.trace("Full stacktrace is: ", e);
        throw new ServiceException(
                "Configuration was not loaded for " + getId() + " service, error creating components.",
                rootCause);
    } finally {
        writeLock.unlock();
    }
}

From source file:com.flexive.shared.exceptions.FxApplicationException.java

/**
 * Assign a message from another Exception
 *
 * @param cause the cause to assign the message to this exception
 */// w  w  w.j  a v  a  2s .co m
private void assignMessage(Throwable cause) {
    if (cause instanceof FxApplicationException)
        this.message = ((FxApplicationException) cause).message;
    else
        this.message = new FxExceptionMessage("ex.native", cause.getClass().getName(), cause.getMessage());
}

From source file:com.haulmont.cuba.web.app.ui.jmxcontrol.inspect.operation.OperationResultWindow.java

protected String getExceptionMessage(Throwable exception) {
    if (exception instanceof UndeclaredThrowableException)
        exception = exception.getCause();

    if (exception instanceof JmxControlException) {
        exception = exception.getCause();

        if (exception instanceof MBeanException) {
            exception = exception.getCause();
        }/* ww w  . j  a  v a  2s .co  m*/
    }

    String msg;
    if (exception != null) {
        msg = String.format("%s: \n%s\n%s", exception.getClass().getName(), exception.getMessage(),
                ExceptionUtils.getFullStackTrace(exception));
    } else {
        msg = "";
    }
    return msg;
}

From source file:com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor.java

public Object callMethod(Map context, Object target, String name, Object[] objects)
        throws MethodFailedException {
    CompoundRoot root = (CompoundRoot) target;

    if ("describe".equals(name)) {
        Object v;//from  w  w  w .ja  v  a2s. com
        if (objects != null && objects.length == 1) {
            v = objects[0];
        } else {
            v = root.get(0);
        }

        if (v instanceof Collection || v instanceof Map || v.getClass().isArray()) {
            return v.toString();
        }

        try {
            Map<String, PropertyDescriptor> descriptors = OgnlRuntime.getPropertyDescriptors(v.getClass());

            int maxSize = 0;
            for (String pdName : descriptors.keySet()) {
                if (pdName.length() > maxSize) {
                    maxSize = pdName.length();
                }
            }

            SortedSet<String> set = new TreeSet<String>();
            StringBuffer sb = new StringBuffer();
            for (PropertyDescriptor pd : descriptors.values()) {

                sb.append(pd.getName()).append(": ");
                int padding = maxSize - pd.getName().length();
                for (int i = 0; i < padding; i++) {
                    sb.append(" ");
                }
                sb.append(pd.getPropertyType().getName());
                set.add(sb.toString());

                sb = new StringBuffer();
            }

            sb = new StringBuffer();
            for (Object aSet : set) {
                String s = (String) aSet;
                sb.append(s).append("\n");
            }

            return sb.toString();
        } catch (IntrospectionException e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Got exception in callMethod", e);
            }
        } catch (OgnlException e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Got exception in callMethod", e);
            }
        }

        return null;
    }

    for (Object o : root) {
        if (o == null) {
            continue;
        }

        Class clazz = o.getClass();
        Class[] argTypes = getArgTypes(objects);

        MethodCall mc = null;

        if (argTypes != null) {
            mc = new MethodCall(clazz, name, argTypes);
        }

        if ((argTypes == null) || !invalidMethods.containsKey(mc)) {
            try {
                Object value = OgnlRuntime.callMethod((OgnlContext) context, o, name, objects);

                if (value != null) {
                    return value;
                }
            } catch (OgnlException e) {
                // try the next one
                Throwable reason = e.getReason();

                if (!context.containsKey(OgnlValueStack.THROW_EXCEPTION_ON_FAILURE) && (mc != null)
                        && (reason != null) && (reason.getClass() == NoSuchMethodException.class)) {
                    invalidMethods.put(mc, Boolean.TRUE);
                } else if (reason != null) {
                    throw new MethodFailedException(o, name, e.getReason());
                }
            }
        }
    }

    return null;
}

From source file:com.alliander.osgp.acceptancetests.devicemanagement.SetEventNotificationsSteps.java

@DomainStep("a set event notifications oslp message is sent to device (.*) should be (.*)")
public boolean thenASetEventNotificationsOslpMessageShouldBeSent(final String device,
        final Boolean isMessageSent) {
    LOGGER.info("THEN: \"a set event notifications oslp message is sent to device [{}] should be [{}]\".",
            device, isMessageSent);/*  www  .  ja  v  a2 s. c om*/

    final int count = isMessageSent ? 1 : 0;

    try {
        final ArgumentCaptor<OslpEnvelope> argument = ArgumentCaptor.forClass(OslpEnvelope.class);
        verify(this.channelMock, timeout(10000).times(count)).write(argument.capture());

        if (isMessageSent) {
            this.oslpResponse = argument.getValue();

            Assert.assertTrue("Message should contain set event notifications request.",
                    this.oslpResponse.getPayloadMessage().hasSetEventNotificationsRequest());
        }
    } catch (final Throwable t) {
        LOGGER.error("Exception [{}]: {}", t.getClass().getSimpleName(), t.getMessage());
        return false;
    }
    return true;
}

From source file:com.alliander.osgp.acceptancetests.devicemanagement.SetEventNotificationsSteps.java

@DomainStep("an ovl set event notifications result message with result (.*) and description (.*) should be sent to the ovl out queue")
public boolean thenAnOvlSetEventNotificationsResultMessageShouldBeSentToTheOvlOutQueue(final String result,
        final String description) {
    LOGGER.info(//from w w  w  .  j  av a 2 s .  co  m
            "THEN: \"an ovl set event notifications result message with result [{}] and description [{}] should be sent to the ovl out queue\".",
            result, description);

    try {
        final ArgumentCaptor<ResponseMessage> argument = ArgumentCaptor.forClass(ResponseMessage.class);

        verify(this.webServiceResponseMessageSenderMock, timeout(10000).times(1)).send(argument.capture());

        final String expected = result.equals("NULL") ? null : result;
        final String actual = argument.getValue().getResult().getValue();

        Assert.assertTrue("Invalid result, found: " + actual + " , expected: " + expected,
                actual.equals(expected));

    } catch (final Throwable t) {
        LOGGER.error("Exception [{}]: {}", t.getClass().getSimpleName(), t.getMessage());
        return false;
    }
    return true;
}

From source file:com.alliander.osgp.acceptancetests.schedulemanagement.SetScheduleSteps.java

@DomainStep("the get set schedule response request is received")
public void whenTheGetSetScheduleResultReqeustIsReceived() {
    LOGGER.info("WHEN: \"the set schedule request is received\".");

    try {//  w ww .ja  v a2  s  .  com
        this.response = this.scheduleManagementEndpoint.getSetLightScheduleResponse(ORGANISATION_ID,
                this.setScheduleAsyncRequest);
    } catch (final Throwable t) {
        LOGGER.error("Exception [{}]: {}", t.getClass().getSimpleName(), t.getMessage());
        this.throwable = t;
    }
}