Java 类org.springframework.core.NestedRuntimeException 实例源码

项目:Equella    文件:RemoteInterceptor.java   
@Override
protected Object invoke(final RemoteInvocation invocation, final Object targetObject)
    throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
{
    Throwable unwrapped = null;
    try
    {
        Object rval = super.invoke(invocation, targetObject);
        rval = initialiser.unwrapHibernate(rval);
        rval = initialiser.initialise(rval, new RemoteSimplifier());
        return rval;
    }
    catch( InvocationTargetException e )
    {
        unwrapped = e.getTargetException();
        Throwable t2 = unwrapped;
        // We want to determine if hibernate exception is thrown at any
        // point
        while( t2 != null )
        {
            if( t2 instanceof NestedRuntimeException )
            {
                logger.error(unwrapped.getMessage(), unwrapped);
                throw new RuntimeApplicationException(unwrapped.getMessage());
            }
            t2 = t2.getCause();
        }
        logger.error("Error invoking " + invocation.getMethodName(), unwrapped);
        throw e;
    }
}
项目:spring4-understanding    文件:ComposablePointcutTests.java   
@Test
public void testFilterByClass() throws NoSuchMethodException {
    ComposablePointcut pc = new ComposablePointcut();

    assertTrue(pc.getClassFilter().matches(Object.class));

    ClassFilter cf = new RootClassFilter(Exception.class);
    pc.intersection(cf);
    assertFalse(pc.getClassFilter().matches(Object.class));
    assertTrue(pc.getClassFilter().matches(Exception.class));
    pc.intersection(new RootClassFilter(NestedRuntimeException.class));
    assertFalse(pc.getClassFilter().matches(Exception.class));
    assertTrue(pc.getClassFilter().matches(NestedRuntimeException.class));
    assertFalse(pc.getClassFilter().matches(String.class));
    pc.union(new RootClassFilter(String.class));
    assertFalse(pc.getClassFilter().matches(Exception.class));
    assertTrue(pc.getClassFilter().matches(String.class));
    assertTrue(pc.getClassFilter().matches(NestedRuntimeException.class));
}
项目:Wilma    文件:SystemExceptionSelector.java   
/**
 * Selecting {@link SystemException} from {@link BeanCreationException} causes if exists to be able to return with user-readable exception message.
 * @param e is the catched exception
 * @return with {@link SystemException} if causes contains {@link SystemException} else null
 */
public SystemException getSystemException(final Exception e) {
    SystemException result = null;
    if (e instanceof BeanCreationException) {
        if (((NestedRuntimeException) e).getMostSpecificCause() != null) {
            Throwable ex = e;
            boolean found = false;
            while (ex.getCause() != null && !found) {
                if (ex.getCause() instanceof SystemException) {
                    found = true;
                    result = (SystemException) ex.getCause();
                }
                ex = ex.getCause();
            }
        }
    }
    return result;
}
项目:class-guard    文件:ComposablePointcutTests.java   
@Test
public void testFilterByClass() throws NoSuchMethodException {
    ComposablePointcut pc = new ComposablePointcut();

    assertTrue(pc.getClassFilter().matches(Object.class));

    ClassFilter cf = new RootClassFilter(Exception.class);
    pc.intersection(cf);
    assertFalse(pc.getClassFilter().matches(Object.class));
    assertTrue(pc.getClassFilter().matches(Exception.class));
    pc.intersection(new RootClassFilter(NestedRuntimeException.class));
    assertFalse(pc.getClassFilter().matches(Exception.class));
    assertTrue(pc.getClassFilter().matches(NestedRuntimeException.class));
    assertFalse(pc.getClassFilter().matches(String.class));
    pc.union(new RootClassFilter(String.class));
    assertFalse(pc.getClassFilter().matches(Exception.class));
    assertTrue(pc.getClassFilter().matches(String.class));
    assertTrue(pc.getClassFilter().matches(NestedRuntimeException.class));
}
项目:secure-data-service    文件:EntityPersistHandler.java   
boolean update(String collectionName, Entity entity, List<Entity> failed, AbstractMessageReport report,
        ReportStats reportStats, Source nrSource) {
    boolean res = false;

    try {
        res = entityRepository.updateWithRetries(collectionName, entity, totalRetries);
        if (!res) {
            failed.add(entity);
        }
    } catch (MongoException e) {
        NestedRuntimeException wrapper = new NestedRuntimeException("Mongo Exception", e) {
            private static final long serialVersionUID = 1L;
        };
        reportWarnings(wrapper.getMostSpecificCause().getMessage(), collectionName,
                ((SimpleEntity) entity).getSourceFile(), report, reportStats, nrSource);
    }

    return res;
}
项目:lams    文件:BeanCreationException.java   
@Override
public boolean contains(Class<?> exClass) {
    if (super.contains(exClass)) {
        return true;
    }
    if (this.relatedCauses != null) {
        for (Throwable relatedCause : this.relatedCauses) {
            if (relatedCause instanceof NestedRuntimeException &&
                    ((NestedRuntimeException) relatedCause).contains(exClass)) {
                return true;
            }
        }
    }
    return false;
}
项目:iotplatform    文件:DefaultMailService.java   
protected IoTPException handleException(Exception exception) {
  String message;
  if (exception instanceof NestedRuntimeException) {
    message = ((NestedRuntimeException) exception).getMostSpecificCause().getMessage();
  } else {
    message = exception.getMessage();
  }
  return new IoTPException(String.format("Unable to send mail: %s", message), IoTPErrorCode.GENERAL);
}
项目:spring4-understanding    文件:ClassFiltersTests.java   
@Test
public void testIntersection() {
    assertTrue(exceptionFilter.matches(RuntimeException.class));
    assertTrue(hasRootCauseFilter.matches(NestedRuntimeException.class));
    ClassFilter intersection = ClassFilters.intersection(exceptionFilter, hasRootCauseFilter);
    assertFalse(intersection.matches(RuntimeException.class));
    assertFalse(intersection.matches(TestBean.class));
    assertTrue(intersection.matches(NestedRuntimeException.class));
}
项目:spring4-understanding    文件:GroovyScriptFactoryTests.java   
@Test
public void testScriptCompilationException() throws Exception {
    try {
        new ClassPathXmlApplicationContext("org/springframework/scripting/groovy/groovyBrokenContext.xml");
        fail("Should throw exception for broken script file");
    }
    catch (NestedRuntimeException ex) {
        assertTrue("Wrong root cause: " + ex, ex.contains(ScriptCompilationException.class));
    }
}
项目:spring4-understanding    文件:BshScriptFactoryTests.java   
@Test
public void scriptCompilationException() throws Exception {
    try {
        new ClassPathXmlApplicationContext("org/springframework/scripting/bsh/bshBrokenContext.xml");
        fail("Must throw exception for broken script file");
    }
    catch (NestedRuntimeException ex) {
        assertTrue(ex.contains(ScriptCompilationException.class));
    }
}
项目:spring4-understanding    文件:BeanCreationException.java   
@Override
public boolean contains(Class<?> exClass) {
    if (super.contains(exClass)) {
        return true;
    }
    if (this.relatedCauses != null) {
        for (Throwable relatedCause : this.relatedCauses) {
            if (relatedCause instanceof NestedRuntimeException &&
                    ((NestedRuntimeException) relatedCause).contains(exClass)) {
                return true;
            }
        }
    }
    return false;
}
项目:beyondj    文件:SpringHelper.java   
/**
 * Looks up a Spring managed bean from an Application Context. First looks for a bean
 * with name specified. If no such bean exists, looks for a bean by type. If there is
 * only one bean of the appropriate type, it is returned. If zero or more than one bean
 * of the correct type exists, an exception is thrown.
 *
 * @param ctx the Spring Application Context
 * @param name the name of the spring bean to look for
 * @param type the type of bean to look for
 * @param allowFindByType true to indicate that finding a bean by type is acceptable
 *        if find by name fails.
 * @exception RuntimeException various subclasses of RuntimeException are thrown if it
 *            is not possible to find a unique matching bean in the spring context given
 *            the constraints supplied.
 */
public static Object findSpringBean(ApplicationContext ctx,
                                       String name,
                                       Class<?> type,
                                       boolean allowFindByType) {
    // First try to lookup using the name provided
    try {
        Object bean = ctx.getBean(name, type);
        if (bean != null) {
            log.debug("Found spring bean with name [", name, "] and type [", bean.getClass()
                    .getName(), "]");
        }
        return bean;
    }
    catch (NestedRuntimeException nre) {
        if (!allowFindByType) throw nre;
    }

    // If we got here then we didn't find a bean yet, try by type
    String[] beanNames = ctx.getBeanNamesForType(type);
    if (beanNames.length == 0) {
        throw new StripesRuntimeException(
            "Unable to find SpringBean with name [" + name + "] or type [" +
            type.getName() + "] in the Spring application context.");
    }
    else if (beanNames.length > 1) {
        throw new StripesRuntimeException(
            "Unable to find SpringBean with name [" + name + "] or unique bean with type [" +
            type.getName() + "] in the Spring application context. Found " + beanNames.length +
            "beans of matching type.");
    }
    else {
        log.debug("Found unique SpringBean with type [" + type.getName() + "]. Matching on ",
                 "type is a little risky so watch out!");
        return ctx.getBean(beanNames[0], type);
    }
}
项目:spring-vault    文件:ClientCertificateAuthenticationIntegrationTests.java   
@Test(expected = NestedRuntimeException.class)
public void loginShouldFail() {

    ClientHttpRequestFactory clientHttpRequestFactory = ClientHttpRequestFactoryFactory
            .create(new ClientOptions(), Settings.createSslConfiguration());
    RestTemplate restTemplate = VaultClients.createRestTemplate(
            TestRestTemplateFactory.TEST_VAULT_ENDPOINT, clientHttpRequestFactory);

    new ClientCertificateAuthentication(restTemplate).login();
}
项目:spring-vault    文件:ClientCertificateAuthenticationStepsIntegrationTests.java   
@Test(expected = NestedRuntimeException.class)
public void authenticationStepsLoginShouldFail() {

    ClientHttpRequestFactory clientHttpRequestFactory = ClientHttpRequestFactoryFactory
            .create(new ClientOptions(), Settings.createSslConfiguration());
    RestTemplate restTemplate = VaultClients.createRestTemplate(
            TestRestTemplateFactory.TEST_VAULT_ENDPOINT, clientHttpRequestFactory);

    new AuthenticationStepsExecutor(
            ClientCertificateAuthentication.createAuthenticationSteps(), restTemplate)
            .login();
}
项目:spring    文件:BeanCreationException.java   
@Override
public boolean contains(Class<?> exClass) {
    if (super.contains(exClass)) {
        return true;
    }
    if (this.relatedCauses != null) {
        for (Throwable relatedCause : this.relatedCauses) {
            if (relatedCause instanceof NestedRuntimeException &&
                    ((NestedRuntimeException) relatedCause).contains(exClass)) {
                return true;
            }
        }
    }
    return false;
}
项目:thingsboard    文件:DefaultMailService.java   
protected ThingsboardException handleException(Exception exception) {
    String message;
    if (exception instanceof NestedRuntimeException) {
        message = ((NestedRuntimeException)exception).getMostSpecificCause().getMessage();
    } else {
        message = exception.getMessage();
    }
    return new ThingsboardException(String.format("Unable to send mail: %s", message),
            ThingsboardErrorCode.GENERAL);
}
项目:taxii-log-adapter    文件:BindExceptionHandlerTest.java   
@Test
public void invalidPollEndpoint() throws Exception {
    try (AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext()) {
        ctx.register(SettingsConfiguration.class);
        ctx.getEnvironment().getPropertySources().addFirst(exclude(validProperties(), "taxiiService.pollEndpoint"));
        ctx.refresh();
        fail("The context creation must fail because of invalid configuration.");
    } catch (NestedRuntimeException e) {
        BindException be = (BindException) e.getRootCause();
        handler.handle(be);
        verify(err).println(contains("pollEndpoint has illegal value"));
    }
}
项目:taxii-log-adapter    文件:SettingsConfigurationTest.java   
@Test
public void refuseMissingConfiguration() throws Exception {
    try (AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SettingsConfiguration.class)) {
        fail("The context creation must fail because of missing configuration.");
    } catch (NestedRuntimeException e) {
        BindException be = (BindException) e.getRootCause();
        assertThat(be.getFieldErrors(), is(not(emptyCollectionOf(FieldError.class))));
    }
}
项目:taxii-log-adapter    文件:SettingsConfigurationTest.java   
@Test
public void resfuseMissingPollEndpoint() throws Exception {
    try (ConfigurableApplicationContext ctx = context(exclude(validProperties(), "taxiiService.pollEndpoint"))) {
        fail("The context creation must fail because of invalid configuration.");
    } catch (NestedRuntimeException e) {
        BindException be = (BindException) e.getRootCause();
        assertThat(be.getFieldErrors(), hasSize(1));
        assertThat(be.getFieldError().getObjectName(), is("taxiiService"));
        assertThat(be.getFieldError().getField(), is("pollEndpoint"));
        assertThat(be.getFieldError().getRejectedValue(), is(nullValue()));
        assertThat(be.getFieldError().getDefaultMessage(), is("may not be null"));
    }
}
项目:YodaQA-Android    文件:YodaErrorHandler.java   
@Override
public void onRestClientExceptionThrown(final NestedRuntimeException e) {
    Handler mainHandler = new Handler(ctx.getMainLooper());
    mainHandler.post(new Runnable() {
        @Override
        public void run() {
            //Toast.makeText(ctx, e.getMessage(), Toast.LENGTH_LONG).show();
            bus.post(new ResponseChangedAction(null));
        }
    });
    throw e;
}
项目:spring-cloud-commons    文件:EnableDiscoveryClientMissingImplTests.java   
@Test
public void testContextFails() {
    try (ConfigurableApplicationContext context = new SpringApplicationBuilder()
            .sources(App.class).web(false).run(new String[0]);) {
    }
    catch (NestedRuntimeException e) {
        Throwable rootCause = e.getRootCause();
        assertTrue(rootCause instanceof IllegalStateException);
        assertTrue(rootCause.getMessage().contains("no implementations"));
    }
}
项目:class-guard    文件:ClassFiltersTests.java   
@Test
public void testIntersection() {
    assertTrue(exceptionFilter.matches(RuntimeException.class));
    assertTrue(hasRootCauseFilter.matches(NestedRuntimeException.class));
    ClassFilter intersection = ClassFilters.intersection(exceptionFilter, hasRootCauseFilter);
    assertFalse(intersection.matches(RuntimeException.class));
    assertFalse(intersection.matches(TestBean.class));
    assertTrue(intersection.matches(NestedRuntimeException.class));
}
项目:class-guard    文件:GroovyScriptFactoryTests.java   
@Test
public void testScriptCompilationException() throws Exception {
    try {
        new ClassPathXmlApplicationContext("org/springframework/scripting/groovy/groovyBrokenContext.xml");
        fail("Should throw exception for broken script file");
    }
    catch (NestedRuntimeException ex) {
        assertTrue("Wrong root cause: " + ex, ex.contains(ScriptCompilationException.class));
    }
}
项目:class-guard    文件:BshScriptFactoryTests.java   
public void testScriptCompilationException() throws Exception {
    try {
        new ClassPathXmlApplicationContext("org/springframework/scripting/bsh/bshBrokenContext.xml");
        fail("Must throw exception for broken script file");
    }
    catch (NestedRuntimeException ex) {
        assertTrue(ex.contains(ScriptCompilationException.class));
    }
}
项目:class-guard    文件:BeanCreationException.java   
@Override
public boolean contains(Class exClass) {
    if (super.contains(exClass)) {
        return true;
    }
    if (this.relatedCauses != null) {
        for (Throwable relatedCause : this.relatedCauses) {
            if (relatedCause instanceof NestedRuntimeException &&
                    ((NestedRuntimeException) relatedCause).contains(exClass)) {
                return true;
            }
        }
    }
    return false;
}
项目:Produce-Price-Checker    文件:DataLoader.java   
@AfterInject
protected void afterInject() {
    client.setRestErrorHandler(new RestErrorHandler() {
        @Override
        public void onRestClientExceptionThrown(NestedRuntimeException e) {
            //show Toast and Reload button
            loadClientData();
        }
    });
}
项目:stripes    文件:SpringHelper.java   
/**
 * Looks up a Spring managed bean from an Application Context. First looks for a bean
 * with name specified. If no such bean exists, looks for a bean by type. If there is
 * only one bean of the appropriate type, it is returned. If zero or more than one bean
 * of the correct type exists, an exception is thrown.
 *
 * @param ctx the Spring Application Context
 * @param name the name of the spring bean to look for
 * @param type the type of bean to look for
 * @param allowFindByType true to indicate that finding a bean by type is acceptable
 *        if find by name fails.
 * @exception RuntimeException various subclasses of RuntimeException are thrown if it
 *            is not possible to find a unique matching bean in the spring context given
 *            the constraints supplied.
 */
public static Object findSpringBean(ApplicationContext ctx,
                                       String name,
                                       Class<?> type,
                                       boolean allowFindByType) {
    // First try to lookup using the name provided
    try {
        Object bean = ctx.getBean(name, type);
        if (bean != null) {
            log.debug("Found spring bean with name [", name, "] and type [", bean.getClass()
                    .getName(), "]");
        }
        return bean;
    }
    catch (NestedRuntimeException nre) {
        if (!allowFindByType) throw nre;
    }

    // If we got here then we didn't find a bean yet, try by type
    String[] beanNames = ctx.getBeanNamesForType(type);
    if (beanNames.length == 0) {
        throw new StripesRuntimeException(
            "Unable to find SpringBean with name [" + name + "] or type [" +
            type.getName() + "] in the Spring application context.");
    }
    else if (beanNames.length > 1) {
        throw new StripesRuntimeException(
            "Unable to find SpringBean with name [" + name + "] or unique bean with type [" +
            type.getName() + "] in the Spring application context. Found " + beanNames.length +
            "beans of matching type.");
    }
    else {
        log.debug("Found unique SpringBean with type [" + type.getName() + "]. Matching on ",
                 "type is a little risky so watch out!");
        return ctx.getBean(beanNames[0], type);
    }
}
项目:stripesframework    文件:SpringHelper.java   
/**
 * Looks up a Spring managed bean from an Application Context. First looks for a bean
 * with name specified. If no such bean exists, looks for a bean by type. If there is
 * only one bean of the appropriate type, it is returned. If zero or more than one bean
 * of the correct type exists, an exception is thrown.
 *
 * @param ctx the Spring Application Context
 * @param name the name of the spring bean to look for
 * @param type the type of bean to look for
 * @param allowFindByType true to indicate that finding a bean by type is acceptable
 *        if find by name fails.
 * @exception RuntimeException various subclasses of RuntimeException are thrown if it
 *            is not possible to find a unique matching bean in the spring context given
 *            the constraints supplied.
 */
public static Object findSpringBean(ApplicationContext ctx,
                                       String name,
                                       Class<?> type,
                                       boolean allowFindByType) {
    // First try to lookup using the name provided
    try {
        Object bean = ctx.getBean(name, type);
        if (bean != null) {
            log.debug("Found spring bean with name [", name, "] and type [", bean.getClass()
                    .getName(), "]");
        }
        return bean;
    }
    catch (NestedRuntimeException nre) {
        if (!allowFindByType) throw nre;
    }

    // If we got here then we didn't find a bean yet, try by type
    String[] beanNames = ctx.getBeanNamesForType(type);
    if (beanNames.length == 0) {
        throw new StripesRuntimeException(
            "Unable to find SpringBean with name [" + name + "] or type [" +
            type.getName() + "] in the Spring application context.");
    }
    else if (beanNames.length > 1) {
        throw new StripesRuntimeException(
            "Unable to find SpringBean with name [" + name + "] or unique bean with type [" +
            type.getName() + "] in the Spring application context. Found " + beanNames.length +
            "beans of matching type.");
    }
    else {
        log.debug("Found unique SpringBean with type [" + type.getName() + "]. Matching on ",
                 "type is a little risky so watch out!");
        return ctx.getBean(beanNames[0], type);
    }
}
项目:DHK-Recollection    文件:BaseRestClientErrorHandling.java   
@Override
public void onRestClientExceptionThrown(NestedRuntimeException e) {
  Log.d("REST", e.toString());
  showError();
}
项目:phr-api    文件:AccountServiceImpl.java   
private boolean checkEmailViolationException(NestedRuntimeException exception) {
    String exceptionMessage = exception.getRootCause().getMessage();
    return exception.contains(ConstraintViolationException.class) &&
            org.apache.commons.lang3.StringUtils.startsWithIgnoreCase(exceptionMessage, "Duplicate entry") &&
            org.apache.commons.lang3.StringUtils.containsIgnoreCase(exceptionMessage, Patient.EMAIL_IDX);
}
项目:moserp    文件:RestErrorHandlerImpl.java   
@Override
@UiThread
public void onRestClientExceptionThrown(NestedRuntimeException e) {
    Log.d("RestErrorHandler", "Error! " + e);
    Toast.makeText(context, R.string.toast_backend_error, Toast.LENGTH_SHORT).show();
}
项目:carewebframework-core    文件:ExceptionController.java   
/**
 * Populate the display with information from the current execution.
 */
@Override
public void afterInitialized(BaseComponent comp) {
    //ClientUtil.busy(null, null);
    root = comp.getAncestor(Window.class);
    HttpServletRequest req = RequestUtil.getRequest();

    if (root == null || req == null) {
        return;
    }

    Class<?> errClass = (Class<?>) req.getAttribute(WebUtils.ERROR_EXCEPTION_TYPE_ATTRIBUTE);
    String errMsg = (String) req.getAttribute(WebUtils.ERROR_MESSAGE_ATTRIBUTE);
    Throwable err = (Throwable) req.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE);

    String errReqURI = (String) req.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE);
    String errServletName = (String) req.getAttribute(WebUtils.ERROR_SERVLET_NAME_ATTRIBUTE);
    Integer errStatusCode = (Integer) req.getAttribute(WebUtils.ERROR_STATUS_CODE_ATTRIBUTE);

    String throwableContext = null;

    if (err != null) {
        if (err instanceof IThrowableContext) {
            throwableContext = ((IThrowableContext) err).getThrowableContext();
        }

        //stack trace info
        if (err instanceof NestedCheckedException) {
            err = ((NestedCheckedException) err).getMostSpecificCause();
        } else if (err instanceof NestedRuntimeException) {
            err = ((NestedRuntimeException) err).getMostSpecificCause();
        }
    }
    if (err != null) {
        errClass = errClass == null ? err.getClass() : errClass;
        errMsg = StringUtils.trimToNull(errMsg) == null ? err.getMessage() : errMsg;
    }

    StringBuffer buffer = new StringBuffer();
    //generic exception info
    buffer.append("\nException class: ").append(errClass);
    buffer.append("\nMessage: ").append(errMsg);
    buffer.append("\nStatusCode: ").append(errStatusCode);
    buffer.append("\nServletName: ").append(errServletName);
    buffer.append("\nReqURI: ").append(errReqURI);

    Map<String, Object> browserInfo = ExecutionContext.getPage().getBrowserInfo();
    buffer.append(browserInfo);

    buffer.append("\nThrowableContext: " + throwableContext);
    buffer.append("\nStackTrace: ");
    appendStackTrace(err);

    log.error(buffer, err);
    this.lblExceptionClass.setLabel(String.valueOf(errClass));
    this.lblMessage.setLabel(errMsg);
    this.lblStatusCode.setLabel(String.valueOf(errStatusCode));

    if (SecurityUtil.isGrantedAny(StrUtil.getLabel("cwf.error.dialog.expanded"))) {
        setDetail(true);
    }
}