org.springframework.beans.InvalidPropertyException Java Examples

The following examples show how to use org.springframework.beans.InvalidPropertyException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DataBinderTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testAutoGrowBeyondCustomLimit() {
	TestBean testBean = new TestBean();
	DataBinder binder = new DataBinder(testBean, "testBean");
	binder.setAutoGrowCollectionLimit(10);

	MutablePropertyValues mpvs = new MutablePropertyValues();
	mpvs.add("friends[16]", "");
	try {
		binder.bind(mpvs);
		fail("Should have thrown InvalidPropertyException");
	}
	catch (InvalidPropertyException ex) {
		// expected
		assertTrue(ex.getRootCause() instanceof IndexOutOfBoundsException);
	}
}
 
Example #2
Source File: DataBinderTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testAutoGrowBeyondDefaultLimit() {
	TestBean testBean = new TestBean();
	DataBinder binder = new DataBinder(testBean, "testBean");

	MutablePropertyValues mpvs = new MutablePropertyValues();
	mpvs.add("friends[256]", "");
	try {
		binder.bind(mpvs);
		fail("Should have thrown InvalidPropertyException");
	}
	catch (InvalidPropertyException ex) {
		// expected
		assertTrue(ex.getRootCause() instanceof IndexOutOfBoundsException);
	}
}
 
Example #3
Source File: DataBinderTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testAutoGrowBeyondCustomLimit() {
	TestBean testBean = new TestBean();
	DataBinder binder = new DataBinder(testBean, "testBean");
	binder.setAutoGrowCollectionLimit(10);

	MutablePropertyValues mpvs = new MutablePropertyValues();
	mpvs.add("friends[16]", "");
	try {
		binder.bind(mpvs);
		fail("Should have thrown InvalidPropertyException");
	}
	catch (InvalidPropertyException ex) {
		// expected
		assertTrue(ex.getRootCause() instanceof IndexOutOfBoundsException);
	}
}
 
Example #4
Source File: GrpcClientBeanPostProcessor.java    From grpc-spring-boot-starter with MIT License 6 votes vote down vote up
/**
 * Creates the instance to be injected for the given member.
 *
 * @param <T> The type of the instance to be injected.
 * @param name The name that was used to create the channel.
 * @param injectionTarget The target member for the injection.
 * @param injectionType The class that should injected.
 * @param channel The channel that should be used to create the instance.
 * @return The value that matches the type of the given field.
 * @throws BeansException If the value of the field could not be created or the type of the field is unsupported.
 */
protected <T> T valueForMember(final String name, final Member injectionTarget,
        final Class<T> injectionType,
        final Channel channel) throws BeansException {
    if (Channel.class.equals(injectionType)) {
        return injectionType.cast(channel);
    } else if (AbstractStub.class.isAssignableFrom(injectionType)) {

        @SuppressWarnings("unchecked") // Eclipse incorrectly marks this as not required
        AbstractStub<?> stub = createStub(injectionType.asSubclass(AbstractStub.class), channel);
        for (final StubTransformer stubTransformer : getStubTransformers()) {
            stub = stubTransformer.transform(name, stub);
        }
        return injectionType.cast(stub);
    } else {
        throw new InvalidPropertyException(injectionTarget.getDeclaringClass(), injectionTarget.getName(),
                "Unsupported type " + injectionType.getName());
    }
}
 
Example #5
Source File: DataBinderTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testAutoGrowBeyondDefaultLimit() throws Exception {
	TestBean testBean = new TestBean();
	DataBinder binder = new DataBinder(testBean, "testBean");

	MutablePropertyValues mpvs = new MutablePropertyValues();
	mpvs.add("friends[256]", "");
	try {
		binder.bind(mpvs);
		fail("Should have thrown InvalidPropertyException");
	}
	catch (InvalidPropertyException ex) {
		// expected
		assertTrue(ex.getRootCause() instanceof IndexOutOfBoundsException);
	}
}
 
Example #6
Source File: DataBinderTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testAutoGrowBeyondCustomLimit() throws Exception {
	TestBean testBean = new TestBean();
	DataBinder binder = new DataBinder(testBean, "testBean");
	binder.setAutoGrowCollectionLimit(10);

	MutablePropertyValues mpvs = new MutablePropertyValues();
	mpvs.add("friends[16]", "");
	try {
		binder.bind(mpvs);
		fail("Should have thrown InvalidPropertyException");
	}
	catch (InvalidPropertyException ex) {
		// expected
		assertTrue(ex.getRootCause() instanceof IndexOutOfBoundsException);
	}
}
 
Example #7
Source File: GrpcClientBeanPostProcessor.java    From grpc-spring-boot-starter with MIT License 6 votes vote down vote up
/**
 * Creates the instance to be injected for the given member.
 *
 * @param <T> The type of the instance to be injected.
 * @param name The name that was used to create the channel.
 * @param injectionTarget The target member for the injection.
 * @param injectionType The class that should injected.
 * @param channel The channel that should be used to create the instance.
 * @return The value that matches the type of the given field.
 * @throws BeansException If the value of the field could not be created or the type of the field is unsupported.
 */
protected <T> T valueForMember(final String name, final Member injectionTarget,
        final Class<T> injectionType,
        final Channel channel) throws BeansException {
    if (Channel.class.equals(injectionType)) {
        return injectionType.cast(channel);
    } else if (AbstractStub.class.isAssignableFrom(injectionType)) {

        @SuppressWarnings("unchecked") // Eclipse incorrectly marks this as not required
        AbstractStub<?> stub = createStub(injectionType.asSubclass(AbstractStub.class), channel);
        for (final StubTransformer stubTransformer : getStubTransformers()) {
            stub = stubTransformer.transform(name, stub);
        }
        return injectionType.cast(stub);
    } else {
        throw new InvalidPropertyException(injectionTarget.getDeclaringClass(), injectionTarget.getName(),
                "Unsupported type " + injectionType.getName());
    }
}
 
Example #8
Source File: DataBinderTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testAutoGrowBeyondDefaultLimit() {
	TestBean testBean = new TestBean();
	DataBinder binder = new DataBinder(testBean, "testBean");

	MutablePropertyValues mpvs = new MutablePropertyValues();
	mpvs.add("friends[256]", "");
	try {
		binder.bind(mpvs);
		fail("Should have thrown InvalidPropertyException");
	}
	catch (InvalidPropertyException ex) {
		// expected
		assertTrue(ex.getRootCause() instanceof IndexOutOfBoundsException);
	}
}
 
Example #9
Source File: UifBeanWrapper.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * Returns the value for the given property growing nested paths depending on the parameter.
 *
 * @param propertyName name of the property to get value for
 * @param autoGrowNestedPaths whether nested paths should be grown (initialized if null)
 * @return value for property
 */
protected Object getPropertyValue(String propertyName, boolean autoGrowNestedPaths) {
    setAutoGrowNestedPaths(autoGrowNestedPaths);

    Object value = null;
    try {
        value = super.getPropertyValue(propertyName);
    } catch (NullValueInNestedPathException e) {
        // swallow null values in path and return null as the value
    } catch (InvalidPropertyException e1) {
        if (!(e1.getRootCause() instanceof NullValueInNestedPathException)) {
            throw e1;
        }
    }

    return value;
}
 
Example #10
Source File: BeanUtils.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * Set property, without trowing exceptions on errors
 * @param bean bean name
 * @param name name
 * @param value value
 */
public static void setProperty(Object bean, String name, Object value) {
	try  {
		BeanWrapper wrapper = new BeanWrapperImpl(bean);
		wrapper.setPropertyValue(new PropertyValue(name, value));
	} catch (InvalidPropertyException ipe) {
		log.debug("Bean has no property: " + name);
	} catch (PropertyAccessException pae) {
		log.debug("Access Error on property: " + name);
	}
}
 
Example #11
Source File: DirectFieldAccessor.java    From jdal with Apache License 2.0 5 votes vote down vote up
@Override
public Object getPropertyValue(String propertyName) throws BeansException {
	Field field = this.fieldMap.get(propertyName);
	if (field == null) {
		throw new NotReadablePropertyException(
				this.target.getClass(), propertyName, "Field '" + propertyName + "' does not exist");
	}
	try {
		ReflectionUtils.makeAccessible(field);
		return field.get(this.target);
	}
	catch (IllegalAccessException ex) {
		throw new InvalidPropertyException(this.target.getClass(), propertyName, "Field is not accessible", ex);
	}
}
 
Example #12
Source File: MyExceptionHandler.java    From disconf with Apache License 2.0 5 votes vote down vote up
/**
 * 参数转换出错
 *
 * @param e
 *
 * @return
 */
private ModelAndView getParamErrors(InvalidPropertyException e) {

    Map<String, String> errorMap = new HashMap<String, String>();
    errorMap.put(e.getPropertyName(), " parameter cannot find");
    JsonObjectBase jsonObject = JsonObjectUtils.buildFieldError(errorMap, ErrorCode.TYPE_MIS_MATCH);
    return JsonObjectUtils.JsonObjectError2ModelView((JsonObjectError) jsonObject);
}
 
Example #13
Source File: DictionaryObjectAttributeValueReader.java    From rice with Educational Community License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <X> X getValue(String attrName) throws AttributeValidationException {
    X attributeValue = null;

    Exception e = null;
    try {
        attributeValue = (X) beanWrapper.getPropertyValue(attrName);
    } catch (IllegalArgumentException iae) {
        e = iae;
    } catch (InvalidPropertyException ipe) {
        //just return null
    }

    if (e != null) {
        throw new AttributeValidationException(
                "Unable to lookup attribute value by name (" + attrName + ") using introspection", e);
    }

    //			JLR : KS has code to handle dynamic attributes -- not sure whether this is really needed anymore if we're actually relying on types
    //            // Extract dynamic attributes
    //            if(DYNAMIC_ATTRIBUTE.equals(propName)) {
    //                dataMap.putAll((Map<String, String>)value);
    //            } else {
    //				dataMap.put(propName, value);
    //            }

    return attributeValue;
}
 
Example #14
Source File: MyExceptionHandler.java    From disconf with Apache License 2.0 5 votes vote down vote up
/**
 * 参数转换出错
 *
 * @param e
 *
 * @return
 */
private ModelAndView getParamErrors(InvalidPropertyException e) {

    Map<String, String> errorMap = new HashMap<String, String>();
    errorMap.put(e.getPropertyName(), " parameter cannot find");
    JsonObjectBase jsonObject = JsonObjectUtils.buildFieldError(errorMap, ErrorCode.TYPE_MIS_MATCH);
    return JsonObjectUtils.JsonObjectError2ModelView((JsonObjectError) jsonObject);
}
 
Example #15
Source File: DataObjectWrapperBase.java    From rice with Educational Community License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public PropertyDescriptor getPropertyDescriptor(String propertyName) throws InvalidPropertyException {
    return wrapper.getPropertyDescriptor(propertyName);
}
 
Example #16
Source File: MyExceptionHandler.java    From disconf with Apache License 2.0 4 votes vote down vote up
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object o,
                                     Exception e) {

    LOG.warn(request.getRequestURI() + " ExceptionHandler FOUND. " + e.toString() + "\t" + e.getCause());

    // PathVariable 出错
    if (e instanceof TypeMismatchException) {
        return getParamErrors((TypeMismatchException) e);

        // Bean 参数无法映射错误
    } else if (e instanceof InvalidPropertyException) {
        return getParamErrors((InvalidPropertyException) e);

        // @Valid 出错
    } else if (e instanceof BindException) {
        return ParamValidateUtils.getParamErrors((BindException) e);

        // 业务校验处理
    } else if (e instanceof FieldException) {
        return getParamErrors((FieldException) e);

    } else if (e instanceof DocumentNotFoundException) {

        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        try {
            FileUtils.closeWriter(response.getWriter());
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        return null;

        // 用户没有请求方法的访问权限
    } else if (e instanceof AccessDeniedException) {
        LOG.warn("details: " + ((AccessDeniedException) e).getErrorMessage());
        return buildError("auth.access.denied", ErrorCode.ACCESS_NOAUTH_ERROR);

    } else if (e instanceof HttpRequestMethodNotSupportedException) {

        return buildError("syserror.httpmethod", ErrorCode.HttpRequestMethodNotSupportedException);

    } else if (e instanceof MissingServletRequestParameterException) {

        return buildError("syserror.param.miss", ErrorCode.MissingServletRequestParameterException);

    } else if (e instanceof GlobalExceptionAware) {

        LOG.error("details: ", e);
        GlobalExceptionAware g = (GlobalExceptionAware) e;
        return buildError(g.getErrorMessage(), g.getErrorCode());

    } else {

        LOG.warn("details: ", e);
        return buildError("syserror.inner", ErrorCode.GLOBAL_ERROR);
    }
}
 
Example #17
Source File: MyExceptionHandler.java    From disconf with Apache License 2.0 4 votes vote down vote up
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object o,
                                     Exception e) {

    LOG.warn(request.getRequestURI() + " ExceptionHandler FOUND. " + e.toString() + "\t" + e.getCause());

    // PathVariable 出错
    if (e instanceof TypeMismatchException) {
        return getParamErrors((TypeMismatchException) e);

        // Bean 参数无法映射错误
    } else if (e instanceof InvalidPropertyException) {
        return getParamErrors((InvalidPropertyException) e);

        // @Valid 出错
    } else if (e instanceof BindException) {
        return ParamValidateUtils.getParamErrors((BindException) e);

        // 业务校验处理
    } else if (e instanceof FieldException) {
        return getParamErrors((FieldException) e);

    } else if (e instanceof DocumentNotFoundException) {

        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        try {
            FileUtils.closeWriter(response.getWriter());
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        return null;

        // 用户没有请求方法的访问权限
    } else if (e instanceof AccessDeniedException) {
        LOG.warn("details: " + ((AccessDeniedException) e).getErrorMessage());
        return buildError("auth.access.denied", ErrorCode.ACCESS_NOAUTH_ERROR);

    } else if (e instanceof HttpRequestMethodNotSupportedException) {

        return buildError("syserror.httpmethod", ErrorCode.HttpRequestMethodNotSupportedException);

    } else if (e instanceof MissingServletRequestParameterException) {

        return buildError("syserror.param.miss", ErrorCode.MissingServletRequestParameterException);

    } else if (e instanceof GlobalExceptionAware) {

        LOG.error("details: ", e);
        GlobalExceptionAware g = (GlobalExceptionAware) e;
        return buildError(g.getErrorMessage(), g.getErrorCode());

    } else {

        LOG.warn("details: ", e);
        return buildError("syserror.inner", ErrorCode.GLOBAL_ERROR);
    }
}