diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b650aecc..5d42ebcdb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,71 @@ =========================== +## [2.3.2](https://github.com/buession/buessionframework/releases/tag/v2.3.2) (2023-12-27) + +### 🔨依赖升级 + +- [依赖库版本升级和安全漏洞修复](https://github.com/buession/buession-parent/releases/tag/v2.3.2) + + +### ⭐ 新特性 + +- **buession-core:** ClassUtils、MethodUtils、FieldUtils 增加检测是否含义任意注解的方法 +- **buession-core:** AnnotationUtils 增加检测属性是否含义任意注解的方法 +- **buession-core:** 断言 Assert 可指定异常 +- **buession-core:** 新增对象工具类 ObjectUtils +- **buession-core:** AbstractBeanConverter 新增支持 String 转枚举 +- **buession-core:** 新增反射工具类 ReflectionUtils +- **buession-aop:** 新增注解处理器支持解析注解属性中的变量 +- **buession-json:** 注解 @Sensitive 增加支持邮箱脱敏 +- **buession-httpclient:** OKHTTP client 增加可设置 maxRequests +- **buession-velocity:** 新增验证工具 ValidateTool +- **buession-web:** 新增注解处理器支持解析注解属性中的变量 + + +### 🔔 变化 + +- **buession-core:** 废弃 JsonSerializer 和 JsonDeserializer +- **buession-core:** ListConverter、SetConverter、MapConverter 默认返回原始类型 +- **buession-core:** 移除 spring-beans 依赖 +- **buession-json:** 注解 @Sensitive 内容替换策略,替换符可通过属性 replacement 设置 + + +### 🐞 Bug 修复 + +- **buession-core:** 修改错误的类名 BuesssionFrameworkVersion 为 BuessionFrameworkVersion +- **buession-beans:** 修复 NumberPropertyConverter 字符串转换为数字时异常的 BUG +- **buession-beans:** 修复 Map 转换为 bean 时字段为 null 值的 BUG +- **buession-beans:** 修复 Map 转换为 bean 或 bean 转换为 map 时缓存导致的异常 +- **buession-dao:** 修复分页插件 PaginationInterceptor 当页码大于等于 2 时,无法返回数据的 BUG +- **buession-dao:** 修复分页对象下一页值错误的 BUG +- **buession-git:** 修复无法解析 git 信息时,空指针异常 +- **buession-web:** 修复分页对象下一页值错误的 BUG + + +### ⏪ 优化 + +- **buession-beans:** 代码优化 +- **buession-httpclient:** 代码优化 +- **buession-redis:** 代码优化 +- **buession-redis:** 优化 RedisAccessor 多次调用 afterPropertiesSet 时,重复初始化 RedisConnectionFactory +- **buession-geoip:** 优化 GeoIPResolverFactoryBean 多次调用 afterPropertiesSet 时,重复初始化 DatabaseResolver +- **buession-thesaurus:** 优化 ThesaurusFactoryBean 多次调用 afterPropertiesSet 时,重复初始化 Parser +- **buession-velocity:** 优化 VelocityEngineFactoryBean 多次调用 afterPropertiesSet 时,重复初始化 VelocityEngine + + +### 📔 文档 + +- **buession-aop:** 完善注释 +- **buession-httpclient:** 完善注释 +- **buession-redis:** 完善注释 +- **buession-velocity:** 完善注释 +- **buession-web:** 完善注释 + + +--- + + ## [2.3.1](https://github.com/buession/buessionframework/releases/tag/v2.3.1) (2023-11-17) ### 🔨依赖升级 diff --git a/buession-aop/pom.xml b/buession-aop/pom.xml index 79a97c450..e6ef5ada9 100644 --- a/buession-aop/pom.xml +++ b/buession-aop/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.1 + 2.3.2 buession-aop http://www.buession.com/ diff --git a/buession-aop/src/main/java/com/buession/aop/aspectj/AbstractAspectjAnnotationsMethodInterceptor.java b/buession-aop/src/main/java/com/buession/aop/aspectj/AbstractAspectjAnnotationsMethodInterceptor.java index adf9b29dd..709f4909c 100644 --- a/buession-aop/src/main/java/com/buession/aop/aspectj/AbstractAspectjAnnotationsMethodInterceptor.java +++ b/buession-aop/src/main/java/com/buession/aop/aspectj/AbstractAspectjAnnotationsMethodInterceptor.java @@ -46,6 +46,15 @@ public AbstractAspectjAnnotationsMethodInterceptor() { super(); } + /** + * 切点方法之前执行 + * + * @param joinPoint + * {@link JoinPoint} + * + * @throws Throwable + * 异常 + */ public void performBeforeInterception(JoinPoint joinPoint) throws Throwable { if(logger.isDebugEnabled()){ performInterceptionDebug(joinPoint); @@ -57,6 +66,15 @@ public void performBeforeInterception(JoinPoint joinPoint) throws Throwable { super.invoke(mi); } + /** + * 切点方法之后执行 + * + * @param joinPoint + * {@link JoinPoint} + * + * @throws Throwable + * 异常 + */ public void performAfterInterception(JoinPoint joinPoint) throws Throwable { if(logger.isDebugEnabled()){ performInterceptionDebug(joinPoint); @@ -69,6 +87,13 @@ public void performAfterInterception(JoinPoint joinPoint) throws Throwable { } /** + * 切点方法的返回值并进行增强 + * + * @param joinPoint + * {@link JoinPoint} + * + * @throws Throwable + * 异常 * @since 2.3.0 */ public void performAfterReturningInterception(JoinPoint joinPoint) throws Throwable { @@ -84,6 +109,13 @@ public void performAfterReturningInterception(JoinPoint joinPoint) throws Throwa } /** + * 切点方法的返回值后执行 + * + * @param joinPoint + * {@link JoinPoint} + * + * @throws Throwable + * 异常 * @since 2.3.0 */ public void performAfterThrowingInterception(JoinPoint joinPoint) throws Throwable { @@ -99,6 +131,8 @@ public void performAfterThrowingInterception(JoinPoint joinPoint) throws Throwab } /** + * 点方法抛出异常时会执行 + * * @since 2.3.0 */ public void performAroundInterception(JoinPoint joinPoint) throws Throwable { diff --git a/buession-aop/src/main/java/com/buession/aop/handler/AbstractAnnotationHandler.java b/buession-aop/src/main/java/com/buession/aop/handler/AbstractAnnotationHandler.java index 2a3587901..e1af7cc42 100644 --- a/buession-aop/src/main/java/com/buession/aop/handler/AbstractAnnotationHandler.java +++ b/buession-aop/src/main/java/com/buession/aop/handler/AbstractAnnotationHandler.java @@ -19,12 +19,13 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.aop.handler; import com.buession.core.utils.Assert; +import org.springframework.util.StringValueResolver; import java.lang.annotation.Annotation; @@ -43,23 +44,46 @@ public abstract class AbstractAnnotationHandler implements */ protected Class annotationClass; + /** + * 占位符解析器 + * + * @since 2.3.2 + */ + protected StringValueResolver stringValueResolver; + + /** + * 构造函数 + * + * @param annotationClass + * 注解类 + */ + @Deprecated + public AbstractAnnotationHandler(Class annotationClass) { + setAnnotationClass(annotationClass); + } + /** * 构造函数 * * @param annotationClass * 注解类 + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 */ - public AbstractAnnotationHandler(Class annotationClass){ + public AbstractAnnotationHandler(Class annotationClass, StringValueResolver stringValueResolver) { setAnnotationClass(annotationClass); + this.stringValueResolver = stringValueResolver; } @Override - public Class getAnnotationClass(){ + public Class getAnnotationClass() { return annotationClass; } @Override - public void setAnnotationClass(Class annotationClass){ + public void setAnnotationClass(Class annotationClass) { Assert.isNull(annotationClass, "Annotation class argument could not be null"); this.annotationClass = annotationClass; } diff --git a/buession-aop/src/main/java/com/buession/aop/interceptor/AbstractAttributeSourceAdvisor.java b/buession-aop/src/main/java/com/buession/aop/interceptor/AbstractAttributeSourceAdvisor.java index 6879eede4..3e085e90d 100644 --- a/buession-aop/src/main/java/com/buession/aop/interceptor/AbstractAttributeSourceAdvisor.java +++ b/buession-aop/src/main/java/com/buession/aop/interceptor/AbstractAttributeSourceAdvisor.java @@ -19,14 +19,14 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.aop.interceptor; +import com.buession.core.utils.AnnotationUtils; import com.buession.core.utils.Assert; import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor; -import org.springframework.core.annotation.AnnotationUtils; import java.lang.annotation.Annotation; import java.lang.reflect.Method; @@ -42,7 +42,7 @@ public abstract class AbstractAttributeSourceAdvisor extends StaticMethodMatcher private final Class[] annotations; public AbstractAttributeSourceAdvisor(final AnnotationsMethodInterceptor annotationsMethodInterceptor, - final Class[] annotations){ + final Class[] annotations) { Assert.isNull(annotationsMethodInterceptor, "AnnotationsMethodInterceptor cloud not be null."); Assert.isNull(annotations, "Annotations cloud not be null."); @@ -51,7 +51,7 @@ public AbstractAttributeSourceAdvisor(final AnnotationsMethodInterceptor annotat } @Override - public boolean matches(Method method, Class targetClass){ + public boolean matches(Method method, Class targetClass) { Method m = method; if(isAnnotationPresent(m)){ @@ -70,26 +70,12 @@ public boolean matches(Method method, Class targetClass){ return false; } - private boolean isAnnotationPresent(final Class targetClazz){ - for(Class annotationClass : annotations){ - Annotation annotation = AnnotationUtils.findAnnotation(targetClazz, annotationClass); - if(annotation != null){ - return true; - } - } - - return false; + private boolean isAnnotationPresent(final Class targetClazz) { + return AnnotationUtils.hasClassAnnotationPresent(targetClazz, annotations); } - private boolean isAnnotationPresent(final Method method){ - for(Class annotationClass : annotations){ - Annotation annotation = AnnotationUtils.findAnnotation(method, annotationClass); - if(annotation != null){ - return true; - } - } - - return false; + private boolean isAnnotationPresent(final Method method) { + return AnnotationUtils.hasMethodAnnotationPresent(method, annotations); } } diff --git a/buession-beans/pom.xml b/buession-beans/pom.xml index 99b019973..b47040d35 100644 --- a/buession-beans/pom.xml +++ b/buession-beans/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.1 + 2.3.2 buession-beans http://www.buession.com/ diff --git a/buession-beans/src/main/java/com/buession/beans/AbstractBeanConverter.java b/buession-beans/src/main/java/com/buession/beans/AbstractBeanConverter.java index b951ac292..97cc4d971 100644 --- a/buession-beans/src/main/java/com/buession/beans/AbstractBeanConverter.java +++ b/buession-beans/src/main/java/com/buession/beans/AbstractBeanConverter.java @@ -26,11 +26,10 @@ import com.buession.beans.converters.*; import com.buession.core.utils.Assert; +import com.buession.core.utils.EnumUtils; import com.buession.core.utils.FieldUtils; import com.buession.core.utils.StringUtils; import com.buession.lang.Primitive; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.cglib.beans.BeanCopier; import org.springframework.cglib.beans.BeanMap; @@ -58,12 +57,8 @@ public abstract class AbstractBeanConverter implements BeanConverter { private final static Map BEAN_COPIERS = new ConcurrentHashMap<>(32); - private final static Map BEAN_MAPS = new ConcurrentHashMap<>(32); - private final static Map, BeanPropertyConverter> converters = new ConcurrentHashMap<>(24); - private final static Logger logger = LoggerFactory.getLogger(AbstractBeanConverter.class); - /** * 构造函数 */ @@ -109,6 +104,24 @@ public T convert(final S source, final T target) { return beanToBean(source, target); } + @SuppressWarnings({"rawtypes", "unchecked"}) + protected static Object convertValue(final Object value, final Class targetType) { + if(value == null){ + return null; + }else if(targetType.isEnum()){ + return EnumUtils.getEnumIgnoreCase((Class) targetType, value.toString()); + }else{ + final Class targetWrapperType = Primitive.primitiveToWrapper(targetType); + + if(targetWrapperType == value.getClass()){ + return value; + }else{ + final BeanPropertyConverter propertyConverter = converters.get(targetWrapperType); + return propertyConverter == null ? value : propertyConverter.convert(value); + } + } + } + @SuppressWarnings({"unchecked"}) protected T mapToMap(final S source, final T target) { Map sourceMap = (Map) source; @@ -122,8 +135,7 @@ protected T mapToMap(final S source, final T target) { @SuppressWarnings({"unchecked"}) protected T mapToBean(final S source, final T target) { final Map sourceMap = (Map) source; - final String cacheKey = buildCacheKey(source, target); - final BeanMap beanMap = BEAN_MAPS.computeIfAbsent(cacheKey, (key)->BeanMap.create(target)); + final BeanMap beanMap = BeanMap.create(target); sourceMap.forEach((key, value)->{ if(key instanceof CharSequence){ @@ -152,21 +164,7 @@ protected T mapToBean(final S source, final T target) { Field field = FieldUtils.getField(target.getClass(), propertyName, true); if(field != null){ - Class fieldType = field.getType(); - final BeanPropertyConverter propertyConverter = converters.get( - Primitive.primitiveToWrapper(fieldType)); - - try{ - if(propertyConverter == null){ - beanMap.put(propertyName, value); - }else{ - beanMap.put(propertyName, propertyConverter.convert(value)); - } - }catch(Exception e){ - if(logger.isWarnEnabled()){ - logger.warn(e.getMessage()); - } - } + beanMap.put(propertyName, convertValue(value, field.getType())); } } }); @@ -176,8 +174,7 @@ protected T mapToBean(final S source, final T target) { @SuppressWarnings({"unchecked"}) protected T beanToMap(final S source, final T target) { - final String cacheKey = buildCacheKey(source, target); - final BeanMap beanMap = BEAN_MAPS.computeIfAbsent(cacheKey, (key)->BeanMap.create(source)); + final BeanMap beanMap = BeanMap.create(source); final Map targetMap = (Map) target; targetMap.putAll(beanMap); @@ -185,28 +182,13 @@ protected T beanToMap(final S source, final T target) { return target; } - @SuppressWarnings({"unchecked", "rawtype"}) + @SuppressWarnings({"rawtype"}) protected T beanToBean(final S source, final T target) { final String cacheKey = buildCacheKey(source, target); final BeanCopier beanCopier = BEAN_COPIERS.computeIfAbsent(cacheKey, (key)->BeanCopier.create(source.getClass(), target.getClass(), true)); - beanCopier.copy(source, target, (value, targetType, setter)->{ - if(value == null){ - return null; - }else if(targetType.equals(value.getClass())){ - return value; - }else{ - final BeanPropertyConverter propertyConverter = converters.get( - Primitive.primitiveToWrapper(targetType)); - - if(propertyConverter == null){ - return value; - }else{ - return propertyConverter.convert(value); - } - } - }); + beanCopier.copy(source, target, (value, targetType, setter)->convertValue(value, targetType)); return target; } diff --git a/buession-beans/src/main/java/com/buession/beans/AbstractPropertyConverter.java b/buession-beans/src/main/java/com/buession/beans/AbstractPropertyConverter.java index 451e25ac4..3ea16cf9c 100644 --- a/buession-beans/src/main/java/com/buession/beans/AbstractPropertyConverter.java +++ b/buession-beans/src/main/java/com/buession/beans/AbstractPropertyConverter.java @@ -71,9 +71,7 @@ protected ConversionException conversionException(final Class sourceTYpe, fin @SuppressWarnings("unchecked") private Class getType() { - final Class clazz = - (Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; - return clazz; + return (Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; } protected static String toString(final Class type) { diff --git a/buession-beans/src/main/java/com/buession/beans/converters/BigDecimalPropertyConverter.java b/buession-beans/src/main/java/com/buession/beans/converters/BigDecimalPropertyConverter.java index dbd367733..cdf49bad9 100644 --- a/buession-beans/src/main/java/com/buession/beans/converters/BigDecimalPropertyConverter.java +++ b/buession-beans/src/main/java/com/buession/beans/converters/BigDecimalPropertyConverter.java @@ -42,10 +42,16 @@ protected BigDecimal toNumber(final Class sourceType, final Class }else if(value instanceof BigInteger){ return new BigDecimal((BigInteger) value); }else if(value instanceof BigDecimal){ - return new BigDecimal(value.toString()); + return (BigDecimal) value; }else{ return BigDecimal.valueOf(value.longValue()); } } + @Override + protected BigDecimal strToNumber(final Class sourceType, final Class targetType, + final String value) { + return new BigDecimal(value); + } + } diff --git a/buession-beans/src/main/java/com/buession/beans/converters/BigIntegerPropertyConverter.java b/buession-beans/src/main/java/com/buession/beans/converters/BigIntegerPropertyConverter.java index cb1d6d8f1..9144de939 100644 --- a/buession-beans/src/main/java/com/buession/beans/converters/BigIntegerPropertyConverter.java +++ b/buession-beans/src/main/java/com/buession/beans/converters/BigIntegerPropertyConverter.java @@ -45,4 +45,10 @@ protected BigInteger toNumber(final Class sourceType, final Class } } + @Override + protected BigInteger strToNumber(final Class sourceType, final Class targetType, + final String value) { + return new BigInteger(value); + } + } diff --git a/buession-beans/src/main/java/com/buession/beans/converters/BytePropertyConverter.java b/buession-beans/src/main/java/com/buession/beans/converters/BytePropertyConverter.java index c122d7572..9de2864e7 100644 --- a/buession-beans/src/main/java/com/buession/beans/converters/BytePropertyConverter.java +++ b/buession-beans/src/main/java/com/buession/beans/converters/BytePropertyConverter.java @@ -50,4 +50,13 @@ protected Byte toNumber(final Class sourceType, final Class targetType, return value.byteValue(); } + @Override + protected Byte strToNumber(final Class sourceType, final Class targetType, final String value) { + try{ + return Byte.parseByte(value); + }catch(NumberFormatException e){ + throw conversionException(sourceType, value, Byte.class); + } + } + } diff --git a/buession-beans/src/main/java/com/buession/beans/converters/DoublePropertyConverter.java b/buession-beans/src/main/java/com/buession/beans/converters/DoublePropertyConverter.java index 9938a0e1a..bdd9aa501 100644 --- a/buession-beans/src/main/java/com/buession/beans/converters/DoublePropertyConverter.java +++ b/buession-beans/src/main/java/com/buession/beans/converters/DoublePropertyConverter.java @@ -37,4 +37,13 @@ protected Double toNumber(final Class sourceType, final Class targetT return value.doubleValue(); } + @Override + protected Double strToNumber(final Class sourceType, final Class targetType, final String value) { + try{ + return Double.parseDouble(value); + }catch(NumberFormatException e){ + throw conversionException(sourceType, value, Double.class); + } + } + } diff --git a/buession-beans/src/main/java/com/buession/beans/converters/FloatPropertyConverter.java b/buession-beans/src/main/java/com/buession/beans/converters/FloatPropertyConverter.java index c5a453a87..b01711e4c 100644 --- a/buession-beans/src/main/java/com/buession/beans/converters/FloatPropertyConverter.java +++ b/buession-beans/src/main/java/com/buession/beans/converters/FloatPropertyConverter.java @@ -37,4 +37,13 @@ protected Float toNumber(final Class sourceType, final Class targetTyp return value.floatValue(); } + @Override + protected Float strToNumber(final Class sourceType, final Class targetType, final String value) { + try{ + return Float.parseFloat(value); + }catch(NumberFormatException e){ + throw conversionException(sourceType, value, Float.class); + } + } + } diff --git a/buession-beans/src/main/java/com/buession/beans/converters/IntegerPropertyConverter.java b/buession-beans/src/main/java/com/buession/beans/converters/IntegerPropertyConverter.java index 792cf6bba..24117b5e7 100644 --- a/buession-beans/src/main/java/com/buession/beans/converters/IntegerPropertyConverter.java +++ b/buession-beans/src/main/java/com/buession/beans/converters/IntegerPropertyConverter.java @@ -37,4 +37,13 @@ protected Integer toNumber(final Class sourceType, final Class targe return value.intValue(); } + @Override + protected Integer strToNumber(final Class sourceType, final Class targetType, final String value) { + try{ + return Integer.parseInt(value); + }catch(NumberFormatException e){ + throw conversionException(sourceType, value, Integer.class); + } + } + } diff --git a/buession-beans/src/main/java/com/buession/beans/converters/LongPropertyConverter.java b/buession-beans/src/main/java/com/buession/beans/converters/LongPropertyConverter.java index 4c33dfbc4..e1fafc7af 100644 --- a/buession-beans/src/main/java/com/buession/beans/converters/LongPropertyConverter.java +++ b/buession-beans/src/main/java/com/buession/beans/converters/LongPropertyConverter.java @@ -37,4 +37,13 @@ protected Long toNumber(final Class sourceType, final Class targetType, return value.longValue(); } + @Override + protected Long strToNumber(final Class sourceType, final Class targetType, final String value) { + try{ + return Long.parseLong(value); + }catch(NumberFormatException e){ + throw conversionException(sourceType, value, Long.class); + } + } + } diff --git a/buession-beans/src/main/java/com/buession/beans/converters/NumberPropertyConverter.java b/buession-beans/src/main/java/com/buession/beans/converters/NumberPropertyConverter.java index 713ff7bed..8d20cbb5c 100644 --- a/buession-beans/src/main/java/com/buession/beans/converters/NumberPropertyConverter.java +++ b/buession-beans/src/main/java/com/buession/beans/converters/NumberPropertyConverter.java @@ -94,9 +94,16 @@ protected T convertToType(final Class sourceType, final Object value, final C return targetType.cast(((Instant) value).toEpochMilli()); } + // Handle CharSequence --> Long + if(value instanceof CharSequence){ + return targetType.cast(strToNumber(sourceType, targetType, value.toString())); + } + return null; } protected abstract T toNumber(final Class sourceType, final Class targetType, final Number value); + protected abstract T strToNumber(final Class sourceType, final Class targetType, final String value); + } diff --git a/buession-beans/src/main/java/com/buession/beans/converters/ShortPropertyConverter.java b/buession-beans/src/main/java/com/buession/beans/converters/ShortPropertyConverter.java index fd8032402..cb665e45a 100644 --- a/buession-beans/src/main/java/com/buession/beans/converters/ShortPropertyConverter.java +++ b/buession-beans/src/main/java/com/buession/beans/converters/ShortPropertyConverter.java @@ -37,4 +37,13 @@ protected Short toNumber(final Class sourceType, final Class targetTyp return value.shortValue(); } + @Override + protected Short strToNumber(final Class sourceType, final Class targetType, final String value) { + try{ + return Short.parseShort(value); + }catch(NumberFormatException e){ + throw conversionException(sourceType, value, Short.class); + } + } + } diff --git a/buession-core/pom.xml b/buession-core/pom.xml index 9aa97c3a9..d364d2723 100644 --- a/buession-core/pom.xml +++ b/buession-core/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.1 + 2.3.2 buession-core http://www.buession.com/ @@ -62,10 +62,6 @@ org.springframework spring-core - - org.springframework - spring-beans - org.springframework spring-context @@ -77,6 +73,13 @@ test + + org.jetbrains.kotlin + kotlin-reflect + provided + true + + org.apache.commons commons-lang3 @@ -130,14 +133,6 @@ org.mapstruct mapstruct - - org.mapstruct - mapstruct-jdk8 - - - org.mapstruct - mapstruct-processor - org.slf4j diff --git a/buession-core/src/main/java/com/buession/core/BuessionFrameworkVersion.java b/buession-core/src/main/java/com/buession/core/BuessionFrameworkVersion.java new file mode 100644 index 000000000..457dc2f86 --- /dev/null +++ b/buession-core/src/main/java/com/buession/core/BuessionFrameworkVersion.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2021 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.core; + +import com.buession.core.utils.VersionUtils; + +/** + * Buession Framework 版本 + * + * @author Yong.Teng + * @since 2.3.2 + */ +public final class BuessionFrameworkVersion { + + private BuessionFrameworkVersion() { + + } + + public static String getVersion() { + return VersionUtils.determineClassVersion(BuessionFrameworkVersion.class); + } + +} diff --git a/buession-core/src/main/java/com/buession/core/BuesssionFrameworkVersion.java b/buession-core/src/main/java/com/buession/core/BuesssionFrameworkVersion.java index 4160ce4e1..10c6fd5d6 100644 --- a/buession-core/src/main/java/com/buession/core/BuesssionFrameworkVersion.java +++ b/buession-core/src/main/java/com/buession/core/BuesssionFrameworkVersion.java @@ -19,24 +19,23 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core; -import com.buession.core.utils.VersionUtils; - /** * @author Yong.Teng */ +@Deprecated public final class BuesssionFrameworkVersion { - private BuesssionFrameworkVersion(){ + private BuesssionFrameworkVersion() { } - public static String getVersion(){ - return VersionUtils.determineClassVersion(BuesssionFrameworkVersion.class); + public static String getVersion() { + return BuessionFrameworkVersion.getVersion(); } } diff --git a/buession-core/src/main/java/com/buession/core/Framework.java b/buession-core/src/main/java/com/buession/core/Framework.java index 9a01eae78..83c8462d0 100644 --- a/buession-core/src/main/java/com/buession/core/Framework.java +++ b/buession-core/src/main/java/com/buession/core/Framework.java @@ -21,7 +21,7 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.core; @@ -39,6 +39,6 @@ public final class Framework { /** * 框架版本 */ - public final static String VERSION = BuesssionFrameworkVersion.getVersion(); + public final static String VERSION = BuessionFrameworkVersion.getVersion(); } diff --git a/buession-core/src/main/java/com/buession/core/codec/Message.java b/buession-core/src/main/java/com/buession/core/codec/Message.java index e4d0aa194..e3b4e3248 100644 --- a/buession-core/src/main/java/com/buession/core/codec/Message.java +++ b/buession-core/src/main/java/com/buession/core/codec/Message.java @@ -21,7 +21,7 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2019 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.core.codec; @@ -39,23 +39,25 @@ * * @author Yong.Teng */ -@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) +@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface Message { - String DEFAULT_CODE_FIELD = "code"; + String DEFAULT_CODE_FIELD = "code"; - String DEFAULT_TEXT_FIELD = "message"; + String DEFAULT_TEXT_FIELD = "message"; - @AliasFor("value") String name() default ""; + @AliasFor("value") + String name() default ""; - @AliasFor("name") String value() default ""; + @AliasFor("name") + String value() default ""; - boolean required() default true; + boolean required() default true; - String codeField() default DEFAULT_CODE_FIELD; + String codeField() default DEFAULT_CODE_FIELD; - String textField() default DEFAULT_TEXT_FIELD; + String textField() default DEFAULT_TEXT_FIELD; } diff --git a/buession-core/src/main/java/com/buession/core/codec/MessageObject.java b/buession-core/src/main/java/com/buession/core/codec/MessageObject.java index 167c822b5..fb790b81d 100644 --- a/buession-core/src/main/java/com/buession/core/codec/MessageObject.java +++ b/buession-core/src/main/java/com/buession/core/codec/MessageObject.java @@ -38,41 +38,80 @@ public class MessageObject implements Serializable { private final static long serialVersionUID = -5074627895618171892L; + /** + * 错误码 + */ private int code; + /** + * 错误文本 + */ private String text; - public MessageObject(){ + /** + * 构造函数 + */ + public MessageObject() { } - public MessageObject(int code, String text){ + /** + * 构造函数 + * + * @param code + * 错误码 + * @param text + * 错误文本 + */ + public MessageObject(int code, String text) { this.code = code; this.text = text; } - public int getCode(){ + /** + * 返回错误码 + * + * @return 错误码 + */ + public int getCode() { return code; } - public void setCode(int code){ + /** + * 设置错误码 + * + * @param code + * 错误码 + */ + public void setCode(int code) { this.code = code; } - public String getText(){ + /** + * 返回错误文本 + * + * @return 错误文本 + */ + public String getText() { return text; } - public void setText(String text){ + /** + * 设置错误文本 + * + * @param text + * 错误文本 + */ + public void setText(String text) { this.text = text; } @Override - public int hashCode(){ + public int hashCode() { return Objects.hash(code, text); } @Override - public boolean equals(Object obj){ + public boolean equals(Object obj) { if(this == obj){ return true; } diff --git a/buession-core/src/main/java/com/buession/core/codec/MessagePropertyBeanPostProcessor.java b/buession-core/src/main/java/com/buession/core/codec/MessagePropertyBeanPostProcessor.java index a8ad1e69d..22dd8d2a4 100644 --- a/buession-core/src/main/java/com/buession/core/codec/MessagePropertyBeanPostProcessor.java +++ b/buession-core/src/main/java/com/buession/core/codec/MessagePropertyBeanPostProcessor.java @@ -26,6 +26,7 @@ */ package com.buession.core.codec; +import com.buession.core.utils.Assert; import com.buession.core.utils.ClassUtils; import com.buession.core.utils.FieldUtils; import org.slf4j.Logger; @@ -50,24 +51,24 @@ public class MessagePropertyBeanPostProcessor implements BeanPostProcessor { private final static Logger logger = LoggerFactory.getLogger(MessagePropertyBeanPostProcessor.class); - public MessagePropertyBeanPostProcessor(){ + public MessagePropertyBeanPostProcessor() { } - public MessagePropertyBeanPostProcessor(Environment environment){ + public MessagePropertyBeanPostProcessor(Environment environment) { this.environment = environment; } - public Environment getEnvironment(){ + public Environment getEnvironment() { return environment; } - public void setEnvironment(Environment environment){ + public void setEnvironment(Environment environment) { this.environment = environment; } @Nullable @Override - public Object postProcessAfterInitialization(Object bean, @Nullable String beanName) throws BeansException{ + public Object postProcessAfterInitialization(Object bean, @Nullable String beanName) throws BeansException { Class clazz = bean.getClass(); Field[] fields = ClassUtils.getAllFields(clazz); Message message; @@ -91,15 +92,13 @@ public Object postProcessAfterInitialization(Object bean, @Nullable String beanN } private void handleMessageInjected(final Class clazz, final Object bean, final String beanName, - final Field field, final Message message) throws BeansException{ + final Field field, final Message message) throws BeansException { final String key = message.value(); final String text = getEnvironment().getProperty(buildProperty(key, message.textField())); - if(message.required() && text == null){ - throw new IllegalArgumentException( - "Could not resolve placeholder '" + key + "' in value \"${" + key + "}\", on: " + beanName + "(" + - bean.getClass().getName() + ")."); - } + Assert.isTrue(message.required() && text == null, + "Could not resolve placeholder '" + key + "' in value \"${" + key + "}\", on: " + beanName + "(" + + bean.getClass().getName() + ")."); final Integer code = getEnvironment().getProperty(buildProperty(key, message.codeField()), Integer.class); @@ -117,7 +116,7 @@ private void handleMessageInjected(final Class clazz, final Object bean, fina logger.debug("Parse message '{}', code: {}, text: {}", key, code, text); } - private static Object getCglibProxyTargetObject(Object proxy) throws Exception{ + private static Object getCglibProxyTargetObject(Object proxy) throws Exception { Field field = proxy.getClass().getDeclaredField("CGLIB$CALLBACK_0"); field.setAccessible(true); @@ -129,7 +128,7 @@ private static Object getCglibProxyTargetObject(Object proxy) throws Exception{ return ((AdvisedSupport) advised.get(dynamicAdvisedInterceptor)).getTargetSource().getTarget(); } - private static String buildProperty(final String prefix, final String value){ + private static String buildProperty(final String prefix, final String value) { return prefix + '.' + value; } diff --git a/buession-core/src/main/java/com/buession/core/collect/Arrays.java b/buession-core/src/main/java/com/buession/core/collect/Arrays.java index 14ccd83c2..1771032db 100644 --- a/buession-core/src/main/java/com/buession/core/collect/Arrays.java +++ b/buession-core/src/main/java/com/buession/core/collect/Arrays.java @@ -34,7 +34,6 @@ import java.util.List; import java.util.Set; import java.util.function.Function; -import java.util.stream.Collectors; /** * 数组工具类 @@ -1822,16 +1821,7 @@ public static String toString(final byte[] a, final String glue) { }else if(a.length == 0){ return Constants.EMPTY_STRING; }else{ - StringBuilder sb = new StringBuilder(); - - for(int i = 0; i < a.length; i++){ - if(i > 0){ - sb.append(glue); - } - sb.append(a[i]); - } - - return sb.toString(); + return StringUtils.join(a, glue); } } @@ -1863,16 +1853,7 @@ public static String toString(final char[] a, final String glue) { }else if(a.length == 0){ return Constants.EMPTY_STRING; }else{ - StringBuilder sb = new StringBuilder(); - - for(int i = 0; i < a.length; i++){ - if(i > 0){ - sb.append(glue); - } - sb.append(a[i]); - } - - return sb.toString(); + return StringUtils.join(a, glue); } } @@ -1904,16 +1885,7 @@ public static String toString(final short[] a, final String glue) { }else if(a.length == 0){ return Constants.EMPTY_STRING; }else{ - StringBuilder sb = new StringBuilder(); - - for(int i = 0; i < a.length; i++){ - if(i > 0){ - sb.append(glue); - } - sb.append(a[i]); - } - - return sb.toString(); + return StringUtils.join(a, glue); } } @@ -1945,16 +1917,7 @@ public static String toString(final int[] a, final String glue) { }else if(a.length == 0){ return Constants.EMPTY_STRING; }else{ - StringBuilder sb = new StringBuilder(); - - for(int i = 0; i < a.length; i++){ - if(i > 0){ - sb.append(glue); - } - sb.append(a[i]); - } - - return sb.toString(); + return StringUtils.join(a, glue); } } @@ -1986,17 +1949,7 @@ public static String toString(final long[] a, final String glue) { }else if(a.length == 0){ return Constants.EMPTY_STRING; }else{ - StringUtils.join(a, glue); - StringBuilder sb = new StringBuilder(); - - for(int i = 0; i < a.length; i++){ - if(i > 0){ - sb.append(glue); - } - sb.append(a[i]); - } - - return sb.toString(); + return StringUtils.join(a, glue); } } @@ -2028,16 +1981,7 @@ public static String toString(final float[] a, final String glue) { }else if(a.length == 0){ return Constants.EMPTY_STRING; }else{ - StringBuilder sb = new StringBuilder(); - - for(int i = 0; i < a.length; i++){ - if(i > 0){ - sb.append(glue); - } - sb.append(a[i]); - } - - return sb.toString(); + return StringUtils.join(a, glue); } } @@ -2069,16 +2013,7 @@ public static String toString(final double[] a, final String glue) { }else if(a.length == 0){ return Constants.EMPTY_STRING; }else{ - StringBuilder sb = new StringBuilder(); - - for(int i = 0; i < a.length; i++){ - if(i > 0){ - sb.append(glue); - } - sb.append(a[i]); - } - - return sb.toString(); + return StringUtils.join(a, glue); } } @@ -2110,16 +2045,7 @@ public static String toString(final boolean[] a, final String glue) { }else if(a.length == 0){ return Constants.EMPTY_STRING; }else{ - StringBuilder sb = new StringBuilder(); - - for(int i = 0; i < a.length; i++){ - if(i > 0){ - sb.append(glue); - } - sb.append(a[i]); - } - - return sb.toString(); + return StringUtils.join(a, glue); } } diff --git a/buession-core/src/main/java/com/buession/core/converter/BooleanStatusConverter.java b/buession-core/src/main/java/com/buession/core/converter/BooleanStatusConverter.java index 126884fa8..8dd6742e1 100644 --- a/buession-core/src/main/java/com/buession/core/converter/BooleanStatusConverter.java +++ b/buession-core/src/main/java/com/buession/core/converter/BooleanStatusConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.converter; @@ -27,6 +27,8 @@ import com.buession.core.utils.StatusUtils; import com.buession.lang.Status; +import java.util.Objects; + /** * 布尔值 {@link Boolean} 到 {@link Status} 转换器 * @@ -36,8 +38,8 @@ public class BooleanStatusConverter implements Converter { @Override - public Status convert(final Boolean source){ - return source == null ? Status.FAILURE : StatusUtils.valueOf(source); + public Status convert(final Boolean source) { + return StatusUtils.valueOf(Objects.equals(source, Boolean.TRUE)); } } diff --git a/buession-core/src/main/java/com/buession/core/converter/ListConverter.java b/buession-core/src/main/java/com/buession/core/converter/ListConverter.java index d23e3fd66..1ce76240f 100644 --- a/buession-core/src/main/java/com/buession/core/converter/ListConverter.java +++ b/buession-core/src/main/java/com/buession/core/converter/ListConverter.java @@ -24,10 +24,11 @@ */ package com.buession.core.converter; -import java.util.ArrayList; -import java.util.LinkedList; +import org.springframework.beans.BeanUtils; + import java.util.List; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * List 转换器 @@ -53,17 +54,24 @@ public class ListConverter implements Converter, List> { * @param itemConverter * List item 转换器 */ - public ListConverter(final Converter itemConverter){ + public ListConverter(final Converter itemConverter) { this.itemConverter = itemConverter; } + @SuppressWarnings({"unchecked"}) @Override - public List convert(final List source){ + public List convert(final List source) { if(source == null){ return null; }else{ - return source.stream().map(itemConverter::convert) - .collect(Collectors.toCollection(source instanceof LinkedList ? LinkedList::new : ArrayList::new)); + Stream stream = source.stream().map(itemConverter::convert); + + try{ + return stream.collect( + Collectors.toCollection(()->(List) BeanUtils.instantiateClass(source.getClass()))); + }catch(Exception e){ + return stream.collect(Collectors.toList()); + } } } diff --git a/buession-core/src/main/java/com/buession/core/converter/MapConverter.java b/buession-core/src/main/java/com/buession/core/converter/MapConverter.java index c5a736be7..ef06094dd 100644 --- a/buession-core/src/main/java/com/buession/core/converter/MapConverter.java +++ b/buession-core/src/main/java/com/buession/core/converter/MapConverter.java @@ -24,10 +24,12 @@ */ package com.buession.core.converter; +import org.springframework.beans.BeanUtils; + import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.Map; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * Map 转换器 @@ -64,19 +66,27 @@ public class MapConverter implements Converter, Map< * @param valueConverter * Map value 转换器 */ - public MapConverter(final Converter keyConverter, final Converter valueConverter){ + public MapConverter(final Converter keyConverter, final Converter valueConverter) { this.keyConverter = keyConverter; this.valueConverter = valueConverter; } + @SuppressWarnings({"unchecked"}) @Override - public Map convert(final Map source){ + public Map convert(final Map source) { if(source == null){ return null; }else{ - return source.entrySet().stream().collect(Collectors.toMap(e->keyConverter.convert(e.getKey()), - e->valueConverter.convert(e.getValue()), (a, b)->a, source instanceof LinkedHashMap ? - LinkedHashMap::new : HashMap::new)); + Stream> stream = source.entrySet().stream(); + + try{ + return stream.collect(Collectors.toMap(entry->keyConverter.convert(entry.getKey()), + entry->valueConverter.convert(entry.getValue()), (a, b)->a, + ()->BeanUtils.instantiateClass(source.getClass()))); + }catch(Exception e){ + return stream.collect(Collectors.toMap(entry->keyConverter.convert(entry.getKey()), + entry->valueConverter.convert(entry.getValue()), (a, b)->a, HashMap::new)); + } } } diff --git a/buession-core/src/main/java/com/buession/core/converter/SetConverter.java b/buession-core/src/main/java/com/buession/core/converter/SetConverter.java index fdcd6db0c..5dda7d539 100644 --- a/buession-core/src/main/java/com/buession/core/converter/SetConverter.java +++ b/buession-core/src/main/java/com/buession/core/converter/SetConverter.java @@ -19,15 +19,16 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.converter; -import java.util.HashSet; -import java.util.LinkedHashSet; +import org.springframework.beans.BeanUtils; + import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * Set 转换器 @@ -53,16 +54,24 @@ public class SetConverter implements Converter, Set> { * @param itemConverter * Set item 转换器 */ - public SetConverter(final Converter itemConverter){ + public SetConverter(final Converter itemConverter) { this.itemConverter = itemConverter; } + @SuppressWarnings({"unchecked"}) @Override - public Set convert(final Set source){ + public Set convert(final Set source) { if(source == null){ return null; }else{ - return source.stream().map(itemConverter::convert).collect(Collectors.toCollection(source instanceof LinkedHashSet ? LinkedHashSet::new : HashSet::new)); + Stream stream = source.stream().map(itemConverter::convert); + + try{ + return stream.collect( + Collectors.toCollection(()->(Set) BeanUtils.instantiateClass(source.getClass()))); + }catch(Exception e){ + return stream.collect(Collectors.toSet()); + } } } diff --git a/buession-core/src/main/java/com/buession/core/converter/mapper/Mapper.java b/buession-core/src/main/java/com/buession/core/converter/mapper/Mapper.java index 8b91e0892..d51ecfe44 100644 --- a/buession-core/src/main/java/com/buession/core/converter/mapper/Mapper.java +++ b/buession-core/src/main/java/com/buession/core/converter/mapper/Mapper.java @@ -19,11 +19,12 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.converter.mapper; +import java.util.Collection; import java.util.List; import java.util.Set; @@ -60,6 +61,18 @@ public interface Mapper { */ T[] mapping(S[] object); + /** + * 将源 Collection 对象映射到目标 Collection 对象 + * + * @param object + * 源 Collection 对象 + * + * @return 目标对象 Collection 实例 + * + * @since 2.3.2 + */ + Collection mapping(Collection object); + /** * 将源 list 对象映射到目标 list 对象 * diff --git a/buession-core/src/main/java/com/buession/core/datetime/TimeZone.java b/buession-core/src/main/java/com/buession/core/datetime/TimeZone.java new file mode 100644 index 000000000..e3188bbc4 --- /dev/null +++ b/buession-core/src/main/java/com/buession/core/datetime/TimeZone.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2023 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.core.datetime; + +/** + * 时区 + * + * @author Yong.Teng + * @since 2.3.2 + */ +public class TimeZone { + + /** + * 格林威治平时 + */ + public final static java.util.TimeZone GMT = java.util.TimeZone.getTimeZone("GMT"); + + /** + * 世界标准时间 + */ + public final static java.util.TimeZone UTC = java.util.TimeZone.getTimeZone("UTC"); + +} diff --git a/buession-core/src/main/java/com/buession/core/deserializer/AbstractJsonDeserializer.java b/buession-core/src/main/java/com/buession/core/deserializer/AbstractJsonDeserializer.java index 54fe466f5..ad4179821 100644 --- a/buession-core/src/main/java/com/buession/core/deserializer/AbstractJsonDeserializer.java +++ b/buession-core/src/main/java/com/buession/core/deserializer/AbstractJsonDeserializer.java @@ -32,25 +32,26 @@ * @author Yong.Teng * @since 2.3.0 */ +@Deprecated public abstract class AbstractJsonDeserializer extends AbstractDeserializer implements JsonDeserializer { @Override - public V deserialize(final String str, final String charsetName) throws DeserializerException{ + public V deserialize(final String str, final String charsetName) throws DeserializerException { return deserialize(str); } @Override - public V deserialize(final String str, final Charset charset) throws DeserializerException{ + public V deserialize(final String str, final Charset charset) throws DeserializerException { return deserialize(str); } @Override - public V deserialize(final byte[] bytes, final String charsetName) throws DeserializerException{ + public V deserialize(final byte[] bytes, final String charsetName) throws DeserializerException { return deserialize(bytes); } @Override - public V deserialize(final byte[] bytes, final Charset charset) throws DeserializerException{ + public V deserialize(final byte[] bytes, final Charset charset) throws DeserializerException { return deserialize(bytes); } diff --git a/buession-core/src/main/java/com/buession/core/deserializer/FastJsonJsonDeserializer.java b/buession-core/src/main/java/com/buession/core/deserializer/FastJsonJsonDeserializer.java index 61549087b..276029c35 100644 --- a/buession-core/src/main/java/com/buession/core/deserializer/FastJsonJsonDeserializer.java +++ b/buession-core/src/main/java/com/buession/core/deserializer/FastJsonJsonDeserializer.java @@ -34,10 +34,11 @@ * @author Yong.Teng * @since 2.3.0 */ +@Deprecated public class FastJsonJsonDeserializer extends AbstractJsonDeserializer { @Override - public V deserialize(final String str) throws DeserializerException{ + public V deserialize(final String str) throws DeserializerException { Assert.isNull(str, "String cloud not be null."); return JSON.parseObject(str, new com.alibaba.fastjson.TypeReference() { @@ -45,19 +46,19 @@ public V deserialize(final String str) throws DeserializerException{ } @Override - public V deserialize(final String str, final Class clazz) throws DeserializerException{ + public V deserialize(final String str, final Class clazz) throws DeserializerException { Assert.isNull(str, "String cloud not be null."); return JSON.parseObject(str, clazz); } @Override - public V deserialize(final String str, final TypeReference type) throws DeserializerException{ + public V deserialize(final String str, final TypeReference type) throws DeserializerException { Assert.isNull(str, "String cloud not be null."); return JSON.parseObject(str, type.getType()); } @Override - public V deserialize(final byte[] bytes) throws DeserializerException{ + public V deserialize(final byte[] bytes) throws DeserializerException { Assert.isNull(bytes, "Bytes cloud not be null."); return JSON.parseObject(new String(bytes), new com.alibaba.fastjson.TypeReference() { @@ -65,13 +66,13 @@ public V deserialize(final byte[] bytes) throws DeserializerException{ } @Override - public V deserialize(byte[] bytes, Class clazz) throws DeserializerException{ + public V deserialize(byte[] bytes, Class clazz) throws DeserializerException { Assert.isNull(bytes, "Bytes cloud not be null."); return JSON.parseObject(bytes, clazz); } @Override - public V deserialize(final byte[] bytes, final TypeReference type) throws DeserializerException{ + public V deserialize(final byte[] bytes, final TypeReference type) throws DeserializerException { Assert.isNull(bytes, "Bytes cloud not be null."); return deserialize(new String(bytes), type); } diff --git a/buession-core/src/main/java/com/buession/core/deserializer/GsonJsonDeserializer.java b/buession-core/src/main/java/com/buession/core/deserializer/GsonJsonDeserializer.java index b19792a96..0aa72980d 100644 --- a/buession-core/src/main/java/com/buession/core/deserializer/GsonJsonDeserializer.java +++ b/buession-core/src/main/java/com/buession/core/deserializer/GsonJsonDeserializer.java @@ -34,10 +34,11 @@ * @author Yong.Teng * @since 2.3.0 */ +@Deprecated public class GsonJsonDeserializer extends AbstractJsonDeserializer { @Override - public V deserialize(final String str) throws DeserializerException{ + public V deserialize(final String str) throws DeserializerException { Gson gson = new Gson(); return gson.fromJson(str, new TypeReference() { @@ -45,7 +46,7 @@ public V deserialize(final String str) throws DeserializerException{ } @Override - public V deserialize(final String str, final Class clazz) throws DeserializerException{ + public V deserialize(final String str, final Class clazz) throws DeserializerException { Assert.isNull(str, "String cloud not be null."); Gson gson = new Gson(); @@ -53,7 +54,7 @@ public V deserialize(final String str, final Class clazz) throws Deserial } @Override - public V deserialize(String str, TypeReference type) throws DeserializerException{ + public V deserialize(String str, TypeReference type) throws DeserializerException { Assert.isNull(str, "String cloud not be null."); Gson gson = new Gson(); @@ -61,19 +62,19 @@ public V deserialize(String str, TypeReference type) throws DeserializerE } @Override - public V deserialize(final byte[] bytes) throws DeserializerException{ + public V deserialize(final byte[] bytes) throws DeserializerException { Assert.isNull(bytes, "Bytes cloud not be null."); return deserialize(new String(bytes)); } @Override - public V deserialize(byte[] bytes, Class clazz) throws DeserializerException{ + public V deserialize(byte[] bytes, Class clazz) throws DeserializerException { Assert.isNull(bytes, "Bytes cloud not be null."); return deserialize(new String(bytes), clazz); } @Override - public V deserialize(byte[] bytes, TypeReference type) throws DeserializerException{ + public V deserialize(byte[] bytes, TypeReference type) throws DeserializerException { Assert.isNull(bytes, "Bytes cloud not be null."); return deserialize(new String(bytes), type); } diff --git a/buession-core/src/main/java/com/buession/core/deserializer/JacksonJsonDeserializer.java b/buession-core/src/main/java/com/buession/core/deserializer/JacksonJsonDeserializer.java index d4b35124d..11a476b84 100644 --- a/buession-core/src/main/java/com/buession/core/deserializer/JacksonJsonDeserializer.java +++ b/buession-core/src/main/java/com/buession/core/deserializer/JacksonJsonDeserializer.java @@ -28,6 +28,7 @@ import com.buession.core.utils.Assert; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; import java.io.IOException; import java.lang.reflect.Type; @@ -39,10 +40,11 @@ * @author Yong.Teng * @since 2.3.0 */ +@Deprecated public class JacksonJsonDeserializer extends AbstractJsonDeserializer { @Override - public V deserialize(final String str) throws DeserializerException{ + public V deserialize(final String str) throws DeserializerException { Assert.isNull(str, "String cloud not be null."); try{ @@ -55,7 +57,7 @@ public V deserialize(final String str) throws DeserializerException{ } @Override - public V deserialize(final String str, final Class clazz) throws DeserializerException{ + public V deserialize(final String str, final Class clazz) throws DeserializerException { Assert.isNull(str, "String cloud not be null."); try{ @@ -67,14 +69,14 @@ public V deserialize(final String str, final Class clazz) throws Deserial } @Override - public V deserialize(final String str, final TypeReference type) throws DeserializerException{ + public V deserialize(final String str, final TypeReference type) throws DeserializerException { Assert.isNull(str, "String cloud not be null."); try{ return getObjectMapper().readValue(str, new com.fasterxml.jackson.core.type.TypeReference() { @Override - public Type getType(){ + public Type getType() { return type.getType(); } @@ -86,7 +88,7 @@ public Type getType(){ } @Override - public V deserialize(final byte[] bytes) throws DeserializerException{ + public V deserialize(final byte[] bytes) throws DeserializerException { Assert.isNull(bytes, "Bytes cloud not be null."); try{ @@ -99,7 +101,7 @@ public V deserialize(final byte[] bytes) throws DeserializerException{ } @Override - public V deserialize(final byte[] bytes, final Class clazz) throws DeserializerException{ + public V deserialize(final byte[] bytes, final Class clazz) throws DeserializerException { Assert.isNull(bytes, "Bytes cloud not be null."); try{ @@ -112,14 +114,14 @@ public V deserialize(final byte[] bytes, final Class clazz) throws Deseri } @Override - public V deserialize(final byte[] bytes, final TypeReference type) throws DeserializerException{ + public V deserialize(final byte[] bytes, final TypeReference type) throws DeserializerException { Assert.isNull(bytes, "Bytes cloud not be null."); try{ return getObjectMapper().readValue(bytes, new com.fasterxml.jackson.core.type.TypeReference() { @Override - public Type getType(){ + public Type getType() { return type.getType(); } @@ -131,10 +133,11 @@ public Type getType(){ } } - protected static ObjectMapper getObjectMapper(){ + protected static ObjectMapper getObjectMapper() { ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS) + .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); return objectMapper; } diff --git a/buession-core/src/main/java/com/buession/core/deserializer/JsonDeserializer.java b/buession-core/src/main/java/com/buession/core/deserializer/JsonDeserializer.java index 9e6b34790..688cae392 100644 --- a/buession-core/src/main/java/com/buession/core/deserializer/JsonDeserializer.java +++ b/buession-core/src/main/java/com/buession/core/deserializer/JsonDeserializer.java @@ -32,6 +32,7 @@ * @author Yong.Teng * @since 2.3.0 */ +@Deprecated public interface JsonDeserializer extends Deserializer { /** @@ -117,7 +118,7 @@ public interface JsonDeserializer extends Deserializer { * @throws DeserializerException * 反序列化异常 */ - default V unserialize(final String str, final Class clazz) throws DeserializerException{ + default V unserialize(final String str, final Class clazz) throws DeserializerException { return deserialize(str, clazz); } @@ -136,7 +137,7 @@ default V unserialize(final String str, final Class clazz) throws Deseria * @throws DeserializerException * 反序列化异常 */ - default V unserialize(final String str, final TypeReference type) throws DeserializerException{ + default V unserialize(final String str, final TypeReference type) throws DeserializerException { return deserialize(str, type); } @@ -155,7 +156,7 @@ default V unserialize(final String str, final TypeReference type) throws * @throws DeserializerException * 反序列化异常 */ - default V unserialize(final byte[] bytes, final Class clazz) throws DeserializerException{ + default V unserialize(final byte[] bytes, final Class clazz) throws DeserializerException { return deserialize(bytes, clazz); } @@ -174,7 +175,7 @@ default V unserialize(final byte[] bytes, final Class clazz) throws Deser * @throws DeserializerException * 反序列化异常 */ - default V unserialize(final byte[] bytes, final TypeReference type) throws DeserializerException{ + default V unserialize(final byte[] bytes, final TypeReference type) throws DeserializerException { return deserialize(bytes, type); } diff --git a/buession-core/src/main/java/com/buession/core/hashing/Md5Hashing.java b/buession-core/src/main/java/com/buession/core/hashing/Md5Hashing.java index c4d26e762..b3d2375eb 100644 --- a/buession-core/src/main/java/com/buession/core/hashing/Md5Hashing.java +++ b/buession-core/src/main/java/com/buession/core/hashing/Md5Hashing.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2020 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.hashing; @@ -35,12 +35,13 @@ public class Md5Hashing extends AbstractHashing { private final static ThreadLocal MD5_HOLDER = new ThreadLocal<>(); @Override - public long hash(byte[] key){ + public long hash(byte[] key) { try{ if(MD5_HOLDER.get() == null){ MD5_HOLDER.set(MessageDigest.getInstance("MD5")); } }catch(NoSuchAlgorithmException e){ + MD5_HOLDER.remove(); throw new IllegalStateException("++++ no md5 algorithm found"); } @@ -50,7 +51,8 @@ public long hash(byte[] key){ md5.update(key); byte[] bKey = md5.digest(); - return ((long) (bKey[3] & 0xFF) << 24) | ((long) (bKey[2] & 0xFF) << 16) | ((long) (bKey[1] & 0xFF) << 8) | (long) (bKey[0] & 0xFF); + return ((long) (bKey[3] & 0xFF) << 24) | ((long) (bKey[2] & 0xFF) << 16) | ((long) (bKey[1] & 0xFF) << 8) | + (long) (bKey[0] & 0xFF); } } diff --git a/buession-core/src/main/java/com/buession/core/id/IdGenerator.java b/buession-core/src/main/java/com/buession/core/id/IdGenerator.java index 46797a149..bae8f4b03 100644 --- a/buession-core/src/main/java/com/buession/core/id/IdGenerator.java +++ b/buession-core/src/main/java/com/buession/core/id/IdGenerator.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.id; @@ -33,6 +33,7 @@ * @author Yong.Teng * @since 1.3.1 */ +@FunctionalInterface public interface IdGenerator { /** diff --git a/buession-core/src/main/java/com/buession/core/id/NanoIDIdGenerator.java b/buession-core/src/main/java/com/buession/core/id/NanoIDIdGenerator.java index c58ee5b0f..337853511 100644 --- a/buession-core/src/main/java/com/buession/core/id/NanoIDIdGenerator.java +++ b/buession-core/src/main/java/com/buession/core/id/NanoIDIdGenerator.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.id; @@ -72,7 +72,7 @@ public class NanoIDIdGenerator implements IdGenerator { /** * 构造函数 */ - public NanoIDIdGenerator(){ + public NanoIDIdGenerator() { } /** @@ -81,7 +81,7 @@ public NanoIDIdGenerator(){ * @param random * 随机生成器 */ - public NanoIDIdGenerator(final Random random){ + public NanoIDIdGenerator(final Random random) { setRandom(random); } @@ -91,7 +91,7 @@ public NanoIDIdGenerator(final Random random){ * @param alphabet * 字符 */ - public NanoIDIdGenerator(final char[] alphabet){ + public NanoIDIdGenerator(final char[] alphabet) { setAlphabet(alphabet); } @@ -101,7 +101,7 @@ public NanoIDIdGenerator(final char[] alphabet){ * @param length * 生成长度 */ - public NanoIDIdGenerator(final int length){ + public NanoIDIdGenerator(final int length) { setLength(length); } @@ -113,7 +113,7 @@ public NanoIDIdGenerator(final int length){ * @param alphabet * 字符 */ - public NanoIDIdGenerator(final Random random, final char[] alphabet){ + public NanoIDIdGenerator(final Random random, final char[] alphabet) { this(random); setAlphabet(alphabet); } @@ -126,7 +126,7 @@ public NanoIDIdGenerator(final Random random, final char[] alphabet){ * @param length * 生成长度 */ - public NanoIDIdGenerator(final Random random, final int length){ + public NanoIDIdGenerator(final Random random, final int length) { this(random); setLength(length); } @@ -139,7 +139,7 @@ public NanoIDIdGenerator(final Random random, final int length){ * @param length * 生成长度 */ - public NanoIDIdGenerator(final char[] alphabet, final int length){ + public NanoIDIdGenerator(final char[] alphabet, final int length) { this(alphabet); setLength(length); } @@ -154,13 +154,13 @@ public NanoIDIdGenerator(final char[] alphabet, final int length){ * @param length * 生成长度 */ - public NanoIDIdGenerator(final Random random, final char[] alphabet, final int length){ + public NanoIDIdGenerator(final Random random, final char[] alphabet, final int length) { this(random, alphabet); setLength(length); } @Override - public String nextId(){ + public String nextId() { int mask = (2 << (int) Math.floor(Math.log((alphabet.length - 1)) / Math.log(2.0D))) - 1; int step = (int) Math.ceil(1.6D * (double) mask * (double) length / (double) alphabet.length); StringBuilder idBuilder = new StringBuilder(); @@ -182,22 +182,20 @@ public String nextId(){ } } - private void setRandom(final Random random){ + private void setRandom(final Random random) { Assert.isNull(random, "Random cloud not be null."); this.random = random; } - private void setAlphabet(final char[] alphabet){ + private void setAlphabet(final char[] alphabet) { Assert.isNull(alphabet, "Alphabet cloud not be null."); - - if(alphabet.length <= 0 || alphabet.length > 255){ - throw new IllegalArgumentException("Alphabet must contain between 1 and 255 symbols."); - } + Assert.isTrue(alphabet.length <= 0 || alphabet.length > 255, + "Alphabet must contain between 1 and 255 symbols."); this.alphabet = alphabet; } - private void setLength(final int length){ + private void setLength(final int length) { Assert.isZeroNegative(length, "Size must be greater than zero."); this.length = length; } diff --git a/buession-core/src/main/java/com/buession/core/serializer/AbstractJsonSerializer.java b/buession-core/src/main/java/com/buession/core/serializer/AbstractJsonSerializer.java index ca93a56a7..d49b6d807 100644 --- a/buession-core/src/main/java/com/buession/core/serializer/AbstractJsonSerializer.java +++ b/buession-core/src/main/java/com/buession/core/serializer/AbstractJsonSerializer.java @@ -31,49 +31,50 @@ * * @author Yong.Teng */ +@Deprecated public abstract class AbstractJsonSerializer extends AbstractSerializer implements JsonSerializer { @Override - public String serialize(final V object, final String charsetName) throws SerializerException{ + public String serialize(final V object, final String charsetName) throws SerializerException { return serialize(object); } @Override - public String serialize(final V object, final Charset charset) throws SerializerException{ + public String serialize(final V object, final Charset charset) throws SerializerException { return serialize(object); } @Override - public byte[] serializeAsBytes(final V object, final String charsetName) throws SerializerException{ + public byte[] serializeAsBytes(final V object, final String charsetName) throws SerializerException { return serializeAsBytes(object); } @Override - public byte[] serializeAsBytes(final V object, final Charset charset) throws SerializerException{ + public byte[] serializeAsBytes(final V object, final Charset charset) throws SerializerException { return serializeAsBytes(object); } @Deprecated @Override - public V deserialize(final String str, final String charsetName) throws SerializerException{ + public V deserialize(final String str, final String charsetName) throws SerializerException { return deserialize(str); } @Deprecated @Override - public V deserialize(final String str, final Charset charset) throws SerializerException{ + public V deserialize(final String str, final Charset charset) throws SerializerException { return deserialize(str); } @Deprecated @Override - public V deserialize(final byte[] bytes, final String charsetName) throws SerializerException{ + public V deserialize(final byte[] bytes, final String charsetName) throws SerializerException { return deserialize(bytes); } @Deprecated @Override - public V deserialize(final byte[] bytes, final Charset charset) throws SerializerException{ + public V deserialize(final byte[] bytes, final Charset charset) throws SerializerException { return deserialize(bytes); } diff --git a/buession-core/src/main/java/com/buession/core/serializer/FastJsonJsonSerializer.java b/buession-core/src/main/java/com/buession/core/serializer/FastJsonJsonSerializer.java index 43ec72b0c..7c9884028 100644 --- a/buession-core/src/main/java/com/buession/core/serializer/FastJsonJsonSerializer.java +++ b/buession-core/src/main/java/com/buession/core/serializer/FastJsonJsonSerializer.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.serializer; @@ -39,27 +39,28 @@ * * @author Yong.Teng */ +@Deprecated public class FastJsonJsonSerializer extends AbstractJsonSerializer { @Override - public String serialize(final V object) throws SerializerException{ + public String serialize(final V object) throws SerializerException { Assert.isNull(object, "Object cloud not be null."); return JSON.toJSONString(object); } @Override - public byte[] serializeAsBytes(final V object) throws SerializerException{ + public byte[] serializeAsBytes(final V object) throws SerializerException { Assert.isNull(object, "Object cloud not be null."); return JSON.toJSONBytes(object); } @Override - public byte[] serializeAsBytes(final V object, final String charsetName) throws SerializerException{ + public byte[] serializeAsBytes(final V object, final String charsetName) throws SerializerException { return serializeAsBytes(object, Charset.forName(charsetName)); } @Override - public byte[] serializeAsBytes(final V object, final Charset charset) throws SerializerException{ + public byte[] serializeAsBytes(final V object, final Charset charset) throws SerializerException { Assert.isNull(object, "Object cloud not be null."); return JSON.toJSONBytes(charset, object, SerializeConfig.globalInstance, new SerializeFilter[0], null, JSON .DEFAULT_GENERATE_FEATURE); @@ -67,7 +68,7 @@ public byte[] serializeAsBytes(final V object, final Charset charset) throws @Deprecated @Override - public V deserialize(final String str) throws SerializerException{ + public V deserialize(final String str) throws SerializerException { FastJsonJsonDeserializer deserializer = new FastJsonJsonDeserializer(); try{ return deserializer.deserialize(str); @@ -78,7 +79,7 @@ public V deserialize(final String str) throws SerializerException{ @Deprecated @Override - public V deserialize(final String str, final Class clazz) throws SerializerException{ + public V deserialize(final String str, final Class clazz) throws SerializerException { FastJsonJsonDeserializer deserializer = new FastJsonJsonDeserializer(); try{ return deserializer.deserialize(str, clazz); @@ -89,7 +90,7 @@ public V deserialize(final String str, final Class clazz) throws Serializ @Deprecated @Override - public V deserialize(final String str, final TypeReference type) throws SerializerException{ + public V deserialize(final String str, final TypeReference type) throws SerializerException { FastJsonJsonDeserializer deserializer = new FastJsonJsonDeserializer(); try{ return deserializer.deserialize(str, type); @@ -100,7 +101,7 @@ public V deserialize(final String str, final TypeReference type) throws S @Deprecated @Override - public V deserialize(final byte[] bytes) throws SerializerException{ + public V deserialize(final byte[] bytes) throws SerializerException { FastJsonJsonDeserializer deserializer = new FastJsonJsonDeserializer(); try{ return deserializer.deserialize(bytes); @@ -111,7 +112,7 @@ public V deserialize(final byte[] bytes) throws SerializerException{ @Deprecated @Override - public V deserialize(byte[] bytes, Class clazz) throws SerializerException{ + public V deserialize(byte[] bytes, Class clazz) throws SerializerException { FastJsonJsonDeserializer deserializer = new FastJsonJsonDeserializer(); try{ return deserializer.deserialize(bytes, clazz); @@ -122,7 +123,7 @@ public V deserialize(byte[] bytes, Class clazz) throws SerializerExceptio @Deprecated @Override - public V deserialize(final byte[] bytes, final TypeReference type) throws SerializerException{ + public V deserialize(final byte[] bytes, final TypeReference type) throws SerializerException { FastJsonJsonDeserializer deserializer = new FastJsonJsonDeserializer(); try{ return deserializer.deserialize(bytes, type); diff --git a/buession-core/src/main/java/com/buession/core/serializer/GsonJsonSerializer.java b/buession-core/src/main/java/com/buession/core/serializer/GsonJsonSerializer.java index 3048ecf3e..b74495673 100644 --- a/buession-core/src/main/java/com/buession/core/serializer/GsonJsonSerializer.java +++ b/buession-core/src/main/java/com/buession/core/serializer/GsonJsonSerializer.java @@ -37,10 +37,11 @@ * * @author Yong.Teng */ +@Deprecated public class GsonJsonSerializer extends AbstractJsonSerializer { @Override - public String serialize(final V object) throws SerializerException{ + public String serialize(final V object) throws SerializerException { Assert.isNull(object, "Object cloud not be null."); Gson gson = new Gson(); @@ -48,18 +49,18 @@ public String serialize(final V object) throws SerializerException{ } @Override - public byte[] serializeAsBytes(final V object) throws SerializerException{ + public byte[] serializeAsBytes(final V object) throws SerializerException { return serializeAsBytes(object, Charset.defaultCharset()); } @Override - public byte[] serializeAsBytes(final V object, final Charset charset) throws SerializerException{ + public byte[] serializeAsBytes(final V object, final Charset charset) throws SerializerException { return serialize(object).getBytes(charset); } @Deprecated @Override - public V deserialize(final String str) throws SerializerException{ + public V deserialize(final String str) throws SerializerException { GsonJsonDeserializer deserializer = new GsonJsonDeserializer(); try{ return deserializer.deserialize(str); @@ -70,7 +71,7 @@ public V deserialize(final String str) throws SerializerException{ @Deprecated @Override - public V deserialize(final String str, final Class clazz) throws SerializerException{ + public V deserialize(final String str, final Class clazz) throws SerializerException { GsonJsonDeserializer deserializer = new GsonJsonDeserializer(); try{ return deserializer.deserialize(str, clazz); @@ -81,7 +82,7 @@ public V deserialize(final String str, final Class clazz) throws Serializ @Deprecated @Override - public V deserialize(String str, TypeReference type) throws SerializerException{ + public V deserialize(String str, TypeReference type) throws SerializerException { GsonJsonDeserializer deserializer = new GsonJsonDeserializer(); try{ return deserializer.deserialize(str, type); @@ -92,7 +93,7 @@ public V deserialize(String str, TypeReference type) throws SerializerExc @Deprecated @Override - public V deserialize(final byte[] bytes) throws SerializerException{ + public V deserialize(final byte[] bytes) throws SerializerException { GsonJsonDeserializer deserializer = new GsonJsonDeserializer(); try{ return deserializer.deserialize(bytes); @@ -103,7 +104,7 @@ public V deserialize(final byte[] bytes) throws SerializerException{ @Deprecated @Override - public V deserialize(byte[] bytes, Class clazz) throws SerializerException{ + public V deserialize(byte[] bytes, Class clazz) throws SerializerException { GsonJsonDeserializer deserializer = new GsonJsonDeserializer(); try{ return deserializer.deserialize(bytes, clazz); @@ -114,7 +115,7 @@ public V deserialize(byte[] bytes, Class clazz) throws SerializerExceptio @Deprecated @Override - public V deserialize(byte[] bytes, TypeReference type) throws SerializerException{ + public V deserialize(byte[] bytes, TypeReference type) throws SerializerException { GsonJsonDeserializer deserializer = new GsonJsonDeserializer(); try{ return deserializer.deserialize(bytes, type); diff --git a/buession-core/src/main/java/com/buession/core/serializer/JacksonJsonSerializer.java b/buession-core/src/main/java/com/buession/core/serializer/JacksonJsonSerializer.java index 7fc87010a..e626957ac 100644 --- a/buession-core/src/main/java/com/buession/core/serializer/JacksonJsonSerializer.java +++ b/buession-core/src/main/java/com/buession/core/serializer/JacksonJsonSerializer.java @@ -29,18 +29,19 @@ import com.buession.core.type.TypeReference; import com.buession.core.utils.Assert; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; /** * Jackson JSON 序列化 * * @author Yong.Teng */ +@Deprecated public class JacksonJsonSerializer extends AbstractJsonSerializer { @Override - public String serialize(final V object) throws SerializerException{ + public String serialize(final V object) throws SerializerException { Assert.isNull(object, "Object cloud not be null."); try{ @@ -51,7 +52,7 @@ public String serialize(final V object) throws SerializerException{ } @Override - public byte[] serializeAsBytes(final V object) throws SerializerException{ + public byte[] serializeAsBytes(final V object) throws SerializerException { Assert.isNull(object, "Object cloud not be null."); try{ @@ -62,7 +63,7 @@ public byte[] serializeAsBytes(final V object) throws SerializerException{ } @Override - public V deserialize(final String str) throws SerializerException{ + public V deserialize(final String str) throws SerializerException { JacksonJsonDeserializer deserializer = new JacksonJsonDeserializer(); try{ return deserializer.deserialize(str); @@ -72,7 +73,7 @@ public V deserialize(final String str) throws SerializerException{ } @Override - public V deserialize(final String str, final Class clazz) throws SerializerException{ + public V deserialize(final String str, final Class clazz) throws SerializerException { JacksonJsonDeserializer deserializer = new JacksonJsonDeserializer(); try{ return deserializer.deserialize(str, clazz); @@ -82,7 +83,7 @@ public V deserialize(final String str, final Class clazz) throws Serializ } @Override - public V deserialize(final String str, final TypeReference type) throws SerializerException{ + public V deserialize(final String str, final TypeReference type) throws SerializerException { JacksonJsonDeserializer deserializer = new JacksonJsonDeserializer(); try{ return deserializer.deserialize(str, type); @@ -92,7 +93,7 @@ public V deserialize(final String str, final TypeReference type) throws S } @Override - public V deserialize(final byte[] bytes) throws SerializerException{ + public V deserialize(final byte[] bytes) throws SerializerException { JacksonJsonDeserializer deserializer = new JacksonJsonDeserializer(); try{ return deserializer.deserialize(bytes); @@ -102,7 +103,7 @@ public V deserialize(final byte[] bytes) throws SerializerException{ } @Override - public V deserialize(final byte[] bytes, final Class clazz) throws SerializerException{ + public V deserialize(final byte[] bytes, final Class clazz) throws SerializerException { JacksonJsonDeserializer deserializer = new JacksonJsonDeserializer(); try{ return deserializer.deserialize(bytes, clazz); @@ -112,7 +113,7 @@ public V deserialize(final byte[] bytes, final Class clazz) throws Serial } @Override - public V deserialize(final byte[] bytes, final TypeReference type) throws SerializerException{ + public V deserialize(final byte[] bytes, final TypeReference type) throws SerializerException { JacksonJsonDeserializer deserializer = new JacksonJsonDeserializer(); try{ return deserializer.deserialize(bytes, type); @@ -121,10 +122,10 @@ public V deserialize(final byte[] bytes, final TypeReference type) throws } } - protected static ObjectMapper getObjectMapper(){ + protected static ObjectMapper getObjectMapper() { ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); return objectMapper; } diff --git a/buession-core/src/main/java/com/buession/core/serializer/JsonSerializer.java b/buession-core/src/main/java/com/buession/core/serializer/JsonSerializer.java index f068ade2b..38cc8a38e 100644 --- a/buession-core/src/main/java/com/buession/core/serializer/JsonSerializer.java +++ b/buession-core/src/main/java/com/buession/core/serializer/JsonSerializer.java @@ -31,6 +31,7 @@ * * @author Yong.Teng */ +@Deprecated public interface JsonSerializer extends Serializer { /** @@ -121,7 +122,7 @@ public interface JsonSerializer extends Serializer { * 反序列化异常 */ @Deprecated - default V unserialize(final String str, final Class clazz) throws SerializerException{ + default V unserialize(final String str, final Class clazz) throws SerializerException { return deserialize(str, clazz); } @@ -141,7 +142,7 @@ default V unserialize(final String str, final Class clazz) throws Seriali * 反序列化异常 */ @Deprecated - default V unserialize(final String str, final TypeReference type) throws SerializerException{ + default V unserialize(final String str, final TypeReference type) throws SerializerException { return deserialize(str, type); } @@ -161,7 +162,7 @@ default V unserialize(final String str, final TypeReference type) throws * 反序列化异常 */ @Deprecated - default V unserialize(final byte[] bytes, final Class clazz) throws SerializerException{ + default V unserialize(final byte[] bytes, final Class clazz) throws SerializerException { return deserialize(bytes, clazz); } @@ -181,7 +182,7 @@ default V unserialize(final byte[] bytes, final Class clazz) throws Seria * 反序列化异常 */ @Deprecated - default V unserialize(final byte[] bytes, final TypeReference type) throws SerializerException{ + default V unserialize(final byte[] bytes, final TypeReference type) throws SerializerException { return deserialize(bytes, type); } diff --git a/buession-core/src/main/java/com/buession/core/utils/AnnotationUtils.java b/buession-core/src/main/java/com/buession/core/utils/AnnotationUtils.java index 367a55325..986b9dd26 100644 --- a/buession-core/src/main/java/com/buession/core/utils/AnnotationUtils.java +++ b/buession-core/src/main/java/com/buession/core/utils/AnnotationUtils.java @@ -19,15 +19,16 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.utils; -import com.buession.core.validator.Validate; - import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.util.Arrays; /** * 注解工具类 @@ -49,19 +50,10 @@ public class AnnotationUtils extends org.springframework.core.annotation.Annotat * @return 类包含有 annotations 中的任意一个注解返回 true;否则返回 false */ public static boolean hasClassAnnotationPresent(final Class clazz, - final Class[] annotations){ + final Class[] annotations) { Assert.isNull(clazz, "Find annotation class cloud not be null."); - - if(Validate.isNotEmpty(annotations)){ - for(Class annotationClazz : annotations){ - Annotation annotation = findAnnotation(clazz, annotationClazz); - if(annotation != null){ - return true; - } - } - } - - return false; + return annotations != null && + Arrays.stream(annotations).anyMatch((annotation)->findAnnotation(clazz, annotation) != null); } /** @@ -74,19 +66,49 @@ public static boolean hasClassAnnotationPresent(final Class clazz, * * @return 方法包含有 annotations 中的任意一个注解返回 true;否则返回 false */ - public static boolean hasMethodAnnotationPresent(Method method, final Class[] annotations){ + public static boolean hasMethodAnnotationPresent(final Method method, + final Class[] annotations) { Assert.isNull(method, "Find annotation method cloud not be null."); + return annotations != null && + Arrays.stream(annotations).anyMatch((annotation)->findAnnotation(method, annotation) != null); + } - if(Validate.isNotEmpty(annotations)){ - for(Class annotationClazz : annotations){ - Annotation annotation = findAnnotation(method, annotationClazz); - if(annotation != null){ - return true; - } - } - } + /** + * 检测一个属性是否含有 annotations 中的任意一个注解 + * + * @param field + * 待验证的属性 + * @param annotations + * 检测是否含有的注解 + * + * @return 属性包含有 annotations 中的任意一个注解返回 true;否则返回 false + * + * @since 2.3.2 + */ + public static boolean hasFieldAnnotationPresent(final Field field, + final Class[] annotations) { + Assert.isNull(field, "Find annotation field cloud not be null."); + return annotations != null && + Arrays.stream(annotations).anyMatch((annotation)->findAnnotation(field, annotation) != null); + } - return false; + /** + * 检测一个 {@link AnnotatedElement} 是否含有 annotations 中的任意一个注解 + * + * @param annotatedElement + * 待验证的 {@link AnnotatedElement} + * @param annotations + * 检测是否含有的注解 + * + * @return {@link AnnotatedElement} 包含有 annotations 中的任意一个注解返回 true;否则返回 false + * + * @since 2.3.2 + */ + public static boolean hasAnnotatedElementAnnotationPresent(final AnnotatedElement annotatedElement, + final Class[] annotations) { + Assert.isNull(annotatedElement, "AnnotatedElement cloud not be null."); + return annotations != null && Arrays.stream(annotations) + .anyMatch((annotation)->findAnnotation(annotatedElement, annotation) != null); } } diff --git a/buession-core/src/main/java/com/buession/core/utils/Assert.java b/buession-core/src/main/java/com/buession/core/utils/Assert.java index 537c23e18..9d41a521a 100644 --- a/buession-core/src/main/java/com/buession/core/utils/Assert.java +++ b/buession-core/src/main/java/com/buession/core/utils/Assert.java @@ -30,6 +30,8 @@ import java.util.Enumeration; import java.util.Iterator; import java.util.Map; +import java.util.Objects; +import java.util.function.Supplier; /** * 断言 @@ -38,7 +40,7 @@ */ public class Assert { - private Assert(){ + private Assert() { } @@ -50,12 +52,28 @@ private Assert(){ * @param message * 异常信息 */ - public static void isTrue(final boolean expression, final String message){ + public static void isTrue(final boolean expression, final String message) { if(expression){ throw new IllegalArgumentException(message); } } + /** + * 如果表达式 expression 为 true,抛出参数 exceptionSupplier 返回的异常 + * + * @param expression + * 表达式 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isTrue(final boolean expression, final Supplier exceptionSupplier) { + if(expression){ + throw exceptionSupplier.get(); + } + } + /** * 如果表达式 expression 为 false,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -64,12 +82,28 @@ public static void isTrue(final boolean expression, final String message){ * @param message * 异常信息 */ - public static void isFalse(final boolean expression, final String message){ + public static void isFalse(final boolean expression, final String message) { if(expression == false){ throw new IllegalArgumentException(message); } } + /** + * 如果表达式 expression 为 false,抛出参数 exceptionSupplier 返回的异常 + * + * @param expression + * 表达式 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isFalse(final boolean expression, final Supplier exceptionSupplier) { + if(expression == false){ + throw exceptionSupplier.get(); + } + } + /** * 如果对象 object 为 null,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -78,12 +112,28 @@ public static void isFalse(final boolean expression, final String message){ * @param message * 异常信息 */ - public static void isNull(final Object object, final String message){ + public static void isNull(final Object object, final String message) { if(object == null){ throw new IllegalArgumentException(message); } } + /** + * 如果对象 object 为 null,抛出参数 exceptionSupplier 返回的异常 + * + * @param object + * 对象 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isNull(final Object object, final Supplier exceptionSupplier) { + if(object == null){ + throw exceptionSupplier.get(); + } + } + /** * 如果对象 object 不为 null,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -92,12 +142,28 @@ public static void isNull(final Object object, final String message){ * @param message * 异常信息 */ - public static void notNull(final Object object, final String message){ + public static void notNull(final Object object, final String message) { if(object != null){ throw new IllegalArgumentException(message); } } + /** + * 如果对象 object 不为 null,抛出参数 exceptionSupplier 返回的异常 + * + * @param object + * 对象 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void notNull(final Object object, final Supplier exceptionSupplier) { + if(object != null){ + throw exceptionSupplier.get(); + } + } + /** * 如果 shor 数组对象 objects 为 null 或为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -108,12 +174,28 @@ public static void notNull(final Object object, final String message){ * * @since 2.2.0 */ - public static void isEmpty(final short[] objects, final String message){ + public static void isEmpty(final short[] objects, final String message) { if(Validate.isEmpty(objects)){ throw new IllegalArgumentException(message); } } + /** + * 如果 shor 数组对象 objects 为 null 或为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param objects + * 数组对象 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isEmpty(final short[] objects, final Supplier exceptionSupplier) { + if(Validate.isEmpty(objects)){ + throw exceptionSupplier.get(); + } + } + /** * 如果 int 数组对象 objects 为 null 或为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -124,12 +206,28 @@ public static void isEmpty(final short[] objects, final String message){ * * @since 2.2.0 */ - public static void isEmpty(final int[] objects, final String message){ + public static void isEmpty(final int[] objects, final String message) { if(Validate.isEmpty(objects)){ throw new IllegalArgumentException(message); } } + /** + * 如果 int 数组对象 objects 为 null 或为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param objects + * 数组对象 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isEmpty(final int[] objects, final Supplier exceptionSupplier) { + if(Validate.isEmpty(objects)){ + throw exceptionSupplier.get(); + } + } + /** * 如果 long 数组对象 objects 为 null 或为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -140,12 +238,28 @@ public static void isEmpty(final int[] objects, final String message){ * * @since 2.2.0 */ - public static void isEmpty(final long[] objects, final String message){ + public static void isEmpty(final long[] objects, final String message) { if(Validate.isEmpty(objects)){ throw new IllegalArgumentException(message); } } + /** + * 如果 long 数组对象 objects 为 null 或为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param objects + * 数组对象 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isEmpty(final long[] objects, final Supplier exceptionSupplier) { + if(Validate.isEmpty(objects)){ + throw exceptionSupplier.get(); + } + } + /** * 如果 float 数组对象 objects 为 null 或为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -156,12 +270,28 @@ public static void isEmpty(final long[] objects, final String message){ * * @since 2.2.0 */ - public static void isEmpty(final float[] objects, final String message){ + public static void isEmpty(final float[] objects, final String message) { if(Validate.isEmpty(objects)){ throw new IllegalArgumentException(message); } } + /** + * 如果 float 数组对象 objects 为 null 或为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param objects + * 数组对象 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isEmpty(final float[] objects, final Supplier exceptionSupplier) { + if(Validate.isEmpty(objects)){ + throw exceptionSupplier.get(); + } + } + /** * 如果 double 数组对象 objects 为 null 或为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -172,12 +302,28 @@ public static void isEmpty(final float[] objects, final String message){ * * @since 2.2.0 */ - public static void isEmpty(final double[] objects, final String message){ + public static void isEmpty(final double[] objects, final String message) { if(Validate.isEmpty(objects)){ throw new IllegalArgumentException(message); } } + /** + * 如果 double 数组对象 objects 为 null 或为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param objects + * 数组对象 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isEmpty(final double[] objects, final Supplier exceptionSupplier) { + if(Validate.isEmpty(objects)){ + throw exceptionSupplier.get(); + } + } + /** * 如果 boolean 数组对象 objects 为 null 或为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -188,12 +334,28 @@ public static void isEmpty(final double[] objects, final String message){ * * @since 2.2.0 */ - public static void isEmpty(final boolean[] objects, final String message){ + public static void isEmpty(final boolean[] objects, final String message) { if(Validate.isEmpty(objects)){ throw new IllegalArgumentException(message); } } + /** + * 如果 boolean 数组对象 objects 为 null 或为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param objects + * 数组对象 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isEmpty(final boolean[] objects, final Supplier exceptionSupplier) { + if(Validate.isEmpty(objects)){ + throw exceptionSupplier.get(); + } + } + /** * 如果 byte 数组对象 objects 为 null 或为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -204,12 +366,28 @@ public static void isEmpty(final boolean[] objects, final String message){ * * @since 2.2.0 */ - public static void isEmpty(final byte[] objects, final String message){ + public static void isEmpty(final byte[] objects, final String message) { if(Validate.isEmpty(objects)){ throw new IllegalArgumentException(message); } } + /** + * 如果 byte 数组对象 objects 为 null 或为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param objects + * 数组对象 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isEmpty(final byte[] objects, final Supplier exceptionSupplier) { + if(Validate.isEmpty(objects)){ + throw exceptionSupplier.get(); + } + } + /** * 如果 char 数组对象 objects 为 null 或为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -220,12 +398,28 @@ public static void isEmpty(final byte[] objects, final String message){ * * @since 2.2.0 */ - public static void isEmpty(final char[] objects, final String message){ + public static void isEmpty(final char[] objects, final String message) { if(Validate.isEmpty(objects)){ throw new IllegalArgumentException(message); } } + /** + * 如果 char 数组对象 objects 为 null 或为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param objects + * 数组对象 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isEmpty(final char[] objects, final Supplier exceptionSupplier) { + if(Validate.isEmpty(objects)){ + throw exceptionSupplier.get(); + } + } + /** * 如果数组对象 objects 为 null 或为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -234,12 +428,28 @@ public static void isEmpty(final char[] objects, final String message){ * @param message * 异常信息 */ - public static void isEmpty(final Object[] objects, final String message){ + public static void isEmpty(final Object[] objects, final String message) { if(Validate.isEmpty(objects)){ throw new IllegalArgumentException(message); } } + /** + * 如果 objects 数组对象 objects 为 null 或为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param objects + * 数组对象 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isEmpty(final Object[] objects, final Supplier exceptionSupplier) { + if(Validate.isEmpty(objects)){ + throw exceptionSupplier.get(); + } + } + /** * 如果集合对象 collection 为 null 或为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -248,12 +458,28 @@ public static void isEmpty(final Object[] objects, final String message){ * @param message * 异常信息 */ - public static void isEmpty(final Collection collection, final String message){ + public static void isEmpty(final Collection collection, final String message) { if(Validate.isEmpty(collection)){ throw new IllegalArgumentException(message); } } + /** + * 如果集合对象 collection 为 null 或为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param collection + * 集合 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isEmpty(final Collection collection, final Supplier exceptionSupplier) { + if(Validate.isEmpty(collection)){ + throw exceptionSupplier.get(); + } + } + /** * 如果 Map 对象 map 为 null 或为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -262,12 +488,28 @@ public static void isEmpty(final Collection collection, final String message) * @param message * 异常信息 */ - public static void isEmpty(final Map map, final String message){ + public static void isEmpty(final Map map, final String message) { if(Validate.isEmpty(map)){ throw new IllegalArgumentException(message); } } + /** + * 如果 Map 对象 map 为 null 或为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param map + * Map 对象 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isEmpty(final Map map, final Supplier exceptionSupplier) { + if(Validate.isEmpty(map)){ + throw exceptionSupplier.get(); + } + } + /** * 如果迭代器 iterator 为 null 或为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -276,12 +518,28 @@ public static void isEmpty(final Map map, final String message){ * @param message * 异常信息 */ - public static void isEmpty(final Iterator iterator, final String message){ + public static void isEmpty(final Iterator iterator, final String message) { if(Validate.isEmpty(iterator)){ throw new IllegalArgumentException(message); } } + /** + * 如果迭代器 iterator 为 null 或为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param iterator + * 迭代器 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isEmpty(final Iterator iterator, final Supplier exceptionSupplier) { + if(Validate.isEmpty(iterator)){ + throw exceptionSupplier.get(); + } + } + /** * 如果枚举 enumeration 为 null 或为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -290,12 +548,28 @@ public static void isEmpty(final Iterator iterator, final String message){ * @param message * 异常信息 */ - public static void isEmpty(final Enumeration enumeration, final String message){ + public static void isEmpty(final Enumeration enumeration, final String message) { if(Validate.isEmpty(enumeration)){ throw new IllegalArgumentException(message); } } + /** + * 如果枚举 enumeration 为 null 或为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param enumeration + * 枚举 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isEmpty(final Enumeration enumeration, final Supplier exceptionSupplier) { + if(Validate.isEmpty(enumeration)){ + throw exceptionSupplier.get(); + } + } + /** * 如果 short 数组对象 objects 不为 null 且不为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -304,12 +578,28 @@ public static void isEmpty(final Enumeration enumeration, final String messag * @param message * 异常信息 */ - public static void notEmpty(final short[] objects, final String message){ + public static void notEmpty(final short[] objects, final String message) { if(Validate.isNotEmpty(objects)){ throw new IllegalArgumentException(message); } } + /** + * 如果 short 数组对象 objects 不为 null 且不为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param objects + * 数组对象 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void notEmpty(final short[] objects, final Supplier exceptionSupplier) { + if(Validate.isNotEmpty(objects)){ + throw exceptionSupplier.get(); + } + } + /** * 如果 int 数组对象 objects 不为 null 且不为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -318,12 +608,28 @@ public static void notEmpty(final short[] objects, final String message){ * @param message * 异常信息 */ - public static void notEmpty(final int[] objects, final String message){ + public static void notEmpty(final int[] objects, final String message) { if(Validate.isNotEmpty(objects)){ throw new IllegalArgumentException(message); } } + /** + * 如果 int 数组对象 objects 不为 null 且不为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param objects + * 数组对象 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void notEmpty(final int[] objects, final Supplier exceptionSupplier) { + if(Validate.isNotEmpty(objects)){ + throw exceptionSupplier.get(); + } + } + /** * 如果 long 数组对象 objects 不为 null 且不为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -332,12 +638,28 @@ public static void notEmpty(final int[] objects, final String message){ * @param message * 异常信息 */ - public static void notEmpty(final long[] objects, final String message){ + public static void notEmpty(final long[] objects, final String message) { if(Validate.isNotEmpty(objects)){ throw new IllegalArgumentException(message); } } + /** + * 如果 long 数组对象 objects 不为 null 且不为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param objects + * 数组对象 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void notEmpty(final long[] objects, final Supplier exceptionSupplier) { + if(Validate.isNotEmpty(objects)){ + throw exceptionSupplier.get(); + } + } + /** * 如果 float 数组对象 objects 不为 null 且不为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -346,12 +668,28 @@ public static void notEmpty(final long[] objects, final String message){ * @param message * 异常信息 */ - public static void notEmpty(final float[] objects, final String message){ + public static void notEmpty(final float[] objects, final String message) { if(Validate.isNotEmpty(objects)){ throw new IllegalArgumentException(message); } } + /** + * 如果 float 数组对象 objects 不为 null 且不为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param objects + * 数组对象 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void notEmpty(final float[] objects, final Supplier exceptionSupplier) { + if(Validate.isNotEmpty(objects)){ + throw exceptionSupplier.get(); + } + } + /** * 如果 double 数组对象 objects 不为 null 且不为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -360,12 +698,28 @@ public static void notEmpty(final float[] objects, final String message){ * @param message * 异常信息 */ - public static void notEmpty(final double[] objects, final String message){ + public static void notEmpty(final double[] objects, final String message) { if(Validate.isNotEmpty(objects)){ throw new IllegalArgumentException(message); } } + /** + * 如果 double 数组对象 objects 不为 null 且不为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param objects + * 数组对象 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void notEmpty(final double[] objects, final Supplier exceptionSupplier) { + if(Validate.isNotEmpty(objects)){ + throw exceptionSupplier.get(); + } + } + /** * 如果 boolean 数组对象 objects 不为 null 且不为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -374,12 +728,28 @@ public static void notEmpty(final double[] objects, final String message){ * @param message * 异常信息 */ - public static void notEmpty(final boolean[] objects, final String message){ + public static void notEmpty(final boolean[] objects, final String message) { if(Validate.isNotEmpty(objects)){ throw new IllegalArgumentException(message); } } + /** + * 如果 boolean 数组对象 objects 不为 null 且不为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param objects + * 数组对象 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void notEmpty(final boolean[] objects, final Supplier exceptionSupplier) { + if(Validate.isNotEmpty(objects)){ + throw exceptionSupplier.get(); + } + } + /** * 如果 byte 数组对象 objects 不为 null 且不为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -388,12 +758,28 @@ public static void notEmpty(final boolean[] objects, final String message){ * @param message * 异常信息 */ - public static void notEmpty(final byte[] objects, final String message){ + public static void notEmpty(final byte[] objects, final String message) { if(Validate.isNotEmpty(objects)){ throw new IllegalArgumentException(message); } } + /** + * 如果 byte 数组对象 objects 不为 null 且不为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param objects + * 数组对象 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void notEmpty(final byte[] objects, final Supplier exceptionSupplier) { + if(Validate.isNotEmpty(objects)){ + throw exceptionSupplier.get(); + } + } + /** * 如果 char 数组对象 objects 不为 null 且不为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -402,12 +788,28 @@ public static void notEmpty(final byte[] objects, final String message){ * @param message * 异常信息 */ - public static void notEmpty(final char[] objects, final String message){ + public static void notEmpty(final char[] objects, final String message) { if(Validate.isNotEmpty(objects)){ throw new IllegalArgumentException(message); } } + /** + * 如果 char 数组对象 objects 不为 null 且不为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param objects + * 数组对象 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void notEmpty(final char[] objects, final Supplier exceptionSupplier) { + if(Validate.isNotEmpty(objects)){ + throw exceptionSupplier.get(); + } + } + /** * 如果数组对象 objects 不为 null 且不为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -416,12 +818,28 @@ public static void notEmpty(final char[] objects, final String message){ * @param message * 异常信息 */ - public static void notEmpty(final Object[] objects, final String message){ + public static void notEmpty(final Object[] objects, final String message) { if(Validate.isNotEmpty(objects)){ throw new IllegalArgumentException(message); } } + /** + * 如果数组对象 objects 不为 null 且不为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param objects + * 数组对象 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void notEmpty(final Object[] objects, final Supplier exceptionSupplier) { + if(Validate.isNotEmpty(objects)){ + throw exceptionSupplier.get(); + } + } + /** * 如果集合对象 collection 不为 null 且不为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -430,12 +848,28 @@ public static void notEmpty(final Object[] objects, final String message){ * @param message * 异常信息 */ - public static void notEmpty(final Collection collection, final String message){ + public static void notEmpty(final Collection collection, final String message) { if(Validate.isNotEmpty(collection)){ throw new IllegalArgumentException(message); } } + /** + * 如果集合对象 collection 不为 null 且不为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param collection + * 集合 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void notEmpty(final Collection collection, final Supplier exceptionSupplier) { + if(Validate.isNotEmpty(collection)){ + throw exceptionSupplier.get(); + } + } + /** * 如果 Map 对象 map 不为 null 且不为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -444,12 +878,28 @@ public static void notEmpty(final Collection collection, final String message * @param message * 异常信息 */ - public static void notEmpty(final Map map, final String message){ + public static void notEmpty(final Map map, final String message) { if(Validate.isNotEmpty(map)){ throw new IllegalArgumentException(message); } } + /** + * 如果 Map 对象 map 不为 null 且不为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param map + * Map 对象 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void notEmpty(final Map map, final Supplier exceptionSupplier) { + if(Validate.isNotEmpty(map)){ + throw exceptionSupplier.get(); + } + } + /** * 如果迭代器 iterator 不为 null 且不为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -458,12 +908,28 @@ public static void notEmpty(final Map map, final String message){ * @param message * 异常信息 */ - public static void notEmpty(final Iterator iterator, final String message){ + public static void notEmpty(final Iterator iterator, final String message) { if(Validate.isNotEmpty(iterator)){ throw new IllegalArgumentException(message); } } + /** + * 如果迭代器 iterator 不为 null 且不为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param iterator + * 迭代器 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void notEmpty(final Iterator iterator, final Supplier exceptionSupplier) { + if(Validate.isNotEmpty(iterator)){ + throw exceptionSupplier.get(); + } + } + /** * 如果枚举 enumeration 不为 null 且不为空,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -472,12 +938,28 @@ public static void notEmpty(final Iterator iterator, final String message){ * @param message * 异常信息 */ - public static void notEmpty(final Enumeration enumeration, final String message){ + public static void notEmpty(final Enumeration enumeration, final String message) { if(Validate.isNotEmpty(enumeration)){ throw new IllegalArgumentException(message); } } + /** + * 如果枚举 enumeration 不为 null 且不为空,抛出参数 exceptionSupplier 返回的异常 + * + * @param enumeration + * 枚举 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void notEmpty(final Enumeration enumeration, final Supplier exceptionSupplier) { + if(Validate.isNotEmpty(enumeration)){ + throw exceptionSupplier.get(); + } + } + /** * 如果字符串 str 为 null 或为空字符串或空白字符串,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -486,12 +968,28 @@ public static void notEmpty(final Enumeration enumeration, final String messa * @param message * 异常信息 */ - public static void isBlank(final String str, final String message){ + public static void isBlank(final String str, final String message) { if(Validate.isBlank(str)){ throw new IllegalArgumentException(message); } } + /** + * 如果字符串 str 为 null 或为空字符串或空白字符串,抛出参数 exceptionSupplier 返回的异常 + * + * @param str + * 字符串 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isBlank(final String str, final Supplier exceptionSupplier) { + if(Validate.isBlank(str)){ + throw exceptionSupplier.get(); + } + } + /** * 如果字符串 str 不为 null 且不为空字符串且不为空白字符串,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -500,12 +998,28 @@ public static void isBlank(final String str, final String message){ * @param message * 异常信息 */ - public static void notBlank(final String str, final String message){ + public static void notBlank(final String str, final String message) { if(Validate.hasText(str)){ throw new IllegalArgumentException(message); } } + /** + * 如果字符串 str 不为 null 且不为空字符串且不为空白字符串,抛出参数 exceptionSupplier 返回的异常 + * + * @param str + * 字符串 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void notBlank(final String str, final Supplier exceptionSupplier) { + if(Validate.hasText(str)){ + throw exceptionSupplier.get(); + } + } + /** * 如果 Short 值为 null 或小于 0,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -514,12 +1028,28 @@ public static void notBlank(final String str, final String message){ * @param message * 异常信息 */ - public static void isNegative(final Short value, final String message){ + public static void isNegative(final Short value, final String message) { if(value == null || value < 0){ throw new IllegalArgumentException(message); } } + /** + * 如果 Short 值为 null 或小于 0,抛出参数 exceptionSupplier 返回的异常 + * + * @param value + * Short 值 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isNegative(final Short value, final Supplier exceptionSupplier) { + if(value == null || value < 0){ + throw exceptionSupplier.get(); + } + } + /** * 如果 Integer 值为 null 或小于 0,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -528,12 +1058,28 @@ public static void isNegative(final Short value, final String message){ * @param message * 异常信息 */ - public static void isNegative(final Integer value, final String message){ + public static void isNegative(final Integer value, final String message) { if(value == null || value < 0){ throw new IllegalArgumentException(message); } } + /** + * 如果 Integer 值为 null 或小于 0,抛出参数 exceptionSupplier 返回的异常 + * + * @param value + * Integer 值 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isNegative(final Integer value, final Supplier exceptionSupplier) { + if(value == null || value < 0){ + throw exceptionSupplier.get(); + } + } + /** * 如果 Long 值为 null 或小于 0,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -542,12 +1088,28 @@ public static void isNegative(final Integer value, final String message){ * @param message * 异常信息 */ - public static void isNegative(final Long value, final String message){ + public static void isNegative(final Long value, final String message) { if(value == null || value < 0){ throw new IllegalArgumentException(message); } } + /** + * 如果 Long 值为 null 或小于 0,抛出参数 exceptionSupplier 返回的异常 + * + * @param value + * Long 值 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isNegative(final Long value, final Supplier exceptionSupplier) { + if(value == null || value < 0){ + throw exceptionSupplier.get(); + } + } + /** * 如果 Double 值为 null 或小于 0,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -556,12 +1118,28 @@ public static void isNegative(final Long value, final String message){ * @param message * 异常信息 */ - public static void isNegative(final Double value, final String message){ + public static void isNegative(final Double value, final String message) { if(value == null || value < 0){ throw new IllegalArgumentException(message); } } + /** + * 如果 Double 值为 null 或小于 0,抛出参数 exceptionSupplier 返回的异常 + * + * @param value + * Double 值 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isNegative(final Double value, final Supplier exceptionSupplier) { + if(value == null || value < 0){ + throw exceptionSupplier.get(); + } + } + /** * 如果 Float 值为 null 或小于 0,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -570,12 +1148,28 @@ public static void isNegative(final Double value, final String message){ * @param message * 异常信息 */ - public static void isNegative(final Float value, final String message){ + public static void isNegative(final Float value, final String message) { if(value == null || value < 0){ throw new IllegalArgumentException(message); } } + /** + * 如果 Float 值为 null 或小于 0,抛出参数 exceptionSupplier 返回的异常 + * + * @param value + * Float 值 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isNegative(final Float value, final Supplier exceptionSupplier) { + if(value == null || value < 0){ + throw exceptionSupplier.get(); + } + } + /** * 如果 Short 值为 null 或小于等于 0,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -584,12 +1178,28 @@ public static void isNegative(final Float value, final String message){ * @param message * 异常信息 */ - public static void isZeroNegative(final Short value, final String message){ + public static void isZeroNegative(final Short value, final String message) { if(value == null || value <= 0){ throw new IllegalArgumentException(message); } } + /** + * 如果 Short 值为 null 或小于等于 0,抛出参数 exceptionSupplier 返回的异常 + * + * @param value + * Short 值 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isZeroNegative(final Short value, final Supplier exceptionSupplier) { + if(value == null || value <= 0){ + throw exceptionSupplier.get(); + } + } + /** * 如果 Integer 值为 null 或小于等于 0,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -598,12 +1208,28 @@ public static void isZeroNegative(final Short value, final String message){ * @param message * 异常信息 */ - public static void isZeroNegative(final Integer value, final String message){ + public static void isZeroNegative(final Integer value, final String message) { if(value == null || value <= 0){ throw new IllegalArgumentException(message); } } + /** + * 如果 Integer 值为 null 或小于等于 0,抛出参数 exceptionSupplier 返回的异常 + * + * @param value + * Integer 值 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isZeroNegative(final Integer value, final Supplier exceptionSupplier) { + if(value == null || value <= 0){ + throw exceptionSupplier.get(); + } + } + /** * 如果 Long 值为 null 或小于等于 0,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -612,12 +1238,28 @@ public static void isZeroNegative(final Integer value, final String message){ * @param message * 异常信息 */ - public static void isZeroNegative(final Long value, final String message){ + public static void isZeroNegative(final Long value, final String message) { if(value == null || value <= 0){ throw new IllegalArgumentException(message); } } + /** + * 如果 Long 值为 null 或小于等于 0,抛出参数 exceptionSupplier 返回的异常 + * + * @param value + * Long 值 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isZeroNegative(final Long value, final Supplier exceptionSupplier) { + if(value == null || value <= 0){ + throw exceptionSupplier.get(); + } + } + /** * 如果 Double 值为 null 或小于等于 0,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -626,12 +1268,28 @@ public static void isZeroNegative(final Long value, final String message){ * @param message * 异常信息 */ - public static void isZeroNegative(final Double value, final String message){ + public static void isZeroNegative(final Double value, final String message) { if(value == null || value <= 0){ throw new IllegalArgumentException(message); } } + /** + * 如果 Double 值为 null 或小于等于 0,抛出参数 exceptionSupplier 返回的异常 + * + * @param value + * Double 值 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isZeroNegative(final Double value, final Supplier exceptionSupplier) { + if(value == null || value <= 0){ + throw exceptionSupplier.get(); + } + } + /** * 如果 Float 值为 null 或小于等于 0,抛出信息为 message 的 {@link IllegalArgumentException} 异常 * @@ -640,10 +1298,26 @@ public static void isZeroNegative(final Double value, final String message){ * @param message * 异常信息 */ - public static void isZeroNegative(final Float value, final String message){ + public static void isZeroNegative(final Float value, final String message) { if(value == null || value <= 0){ throw new IllegalArgumentException(message); } } + /** + * 如果 Float 值为 null 或小于等于 0,抛出参数 exceptionSupplier 返回的异常 + * + * @param value + * Float 值 + * @param exceptionSupplier + * 异常信息 {@link Supplier} + * + * @since 2.3.2 + */ + public static void isZeroNegative(final Float value, final Supplier exceptionSupplier) { + if(value == null || value <= 0){ + throw exceptionSupplier.get(); + } + } + } diff --git a/buession-core/src/main/java/com/buession/core/utils/ClassUtils.java b/buession-core/src/main/java/com/buession/core/utils/ClassUtils.java index 84476d623..eeec43037 100644 --- a/buession-core/src/main/java/com/buession/core/utils/ClassUtils.java +++ b/buession-core/src/main/java/com/buession/core/utils/ClassUtils.java @@ -28,7 +28,10 @@ import com.buession.core.exception.ClassInstantiationException; import com.buession.lang.Primitive; +import org.springframework.core.KotlinDetector; +import org.springframework.lang.Nullable; +import java.lang.annotation.Annotation; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -36,7 +39,16 @@ import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; + +import kotlin.jvm.JvmClassMappingKt; +import kotlin.reflect.KFunction; +import kotlin.reflect.KParameter; +import kotlin.reflect.full.KClasses; +import kotlin.reflect.jvm.KCallablesJvm; +import kotlin.reflect.jvm.ReflectJvmMapping; /** * 类工具类 @@ -49,47 +61,119 @@ public class ClassUtils extends org.apache.commons.lang3.ClassUtils { public static T instantiate(Class clazz, Object... args) throws ClassInstantiationException { Assert.isNull(clazz, "Class cloud not be null"); - - if(clazz.isInterface()){ - throw new ClassInstantiationException(clazz, "Specified class is an interface"); - } + Assert.isTrue(clazz.isInterface(), + ()->new ClassInstantiationException(clazz, "Specified class is an interface")); try{ - Constructor constructor = clazz.getDeclaredConstructor(); - - if((Modifier.isPublic(constructor.getModifiers()) == false || - Modifier.isPublic(constructor.getDeclaringClass().getModifiers()) == false) && - constructor.isAccessible() == false){ - constructor.setAccessible(true); - } + if(args == null){ + return instantiate(clazz.getDeclaredConstructor()); + }else{ + Class[] ctorTypes = new Class[args.length]; - Class[] parameterTypes = constructor.getParameterTypes(); - Assert.isTrue(args.length < parameterTypes.length, - "Can't specify more arguments than constructor parameters"); - - Object[] argsWithDefaultValues = new Object[args.length]; - for(int i = 0; i < args.length; i++){ - if(args[i] == null){ - Class parameterType = parameterTypes[i]; - argsWithDefaultValues[i] = (parameterType.isPrimitive() ? Primitive.DEFAULT_TYPE_VALUES.get( - parameterType) : null); - }else{ - argsWithDefaultValues[i] = args[i]; + for(int i = 0; i < args.length; i++){ + if(args[i] == null){ + // + }else{ + ctorTypes[i] = args[i].getClass(); + } } - } - return constructor.newInstance(argsWithDefaultValues); + return instantiate(clazz.getDeclaredConstructor(ctorTypes), args); + } }catch(NoSuchMethodException e){ + Constructor ctor = findPrimaryConstructor(clazz); + if(ctor != null){ + return instantiate(ctor); + } throw new ClassInstantiationException(clazz, "No default constructor found", e); }catch(LinkageError err){ throw new ClassInstantiationException(clazz, "Unresolvable class definition", err); - }catch(InvocationTargetException e){ - throw new ClassInstantiationException(clazz, "Constructor threw exception", e.getTargetException()); + } + } + + /** + * Convenience method to instantiate a class using the given constructor. + *
headers, Callback callback) throws IOException, RequestException{ + public void get(URI uri, List
headers, Callback callback) throws IOException, RequestException { get(uri, null, headers, callback); } @Override - public void get(URL url, List
headers, Callback callback) throws IOException, RequestException{ + public void get(URL url, List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->get(URL2URI(url), null, headers, callback)); } @Override public void get(URL url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->get(URL2URI(url), parameters, headers, callback)); } @Override - public void get(URI uri, int readTimeout, Callback callback) throws IOException, RequestException{ + public void get(URI uri, int readTimeout, Callback callback) throws IOException, RequestException { get(uri, readTimeout, null, null, callback); } @Override - public void get(URL url, int readTimeout, Callback callback) throws IOException, RequestException{ + public void get(URL url, int readTimeout, Callback callback) throws IOException, RequestException { asyncExecute(()->get(URL2URI(url), readTimeout, null, null, callback)); } @Override public void get(URI uri, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { get(uri, readTimeout, parameters, null, callback); } @Override public void get(URL url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->get(URL2URI(url), readTimeout, parameters, null, callback)); } @Override public void get(URI uri, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { get(uri, readTimeout, null, headers, callback); } @Override public void get(URL url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->get(URL2URI(url), readTimeout, null, headers, callback)); } @Override public void get(URL url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->get(URL2URI(url), readTimeout, parameters, headers, callback)); } @Override - public void post(URI uri, Callback callback) throws IOException, RequestException{ + public void post(URI uri, Callback callback) throws IOException, RequestException { post(uri, null, null, null, callback); } @Override - public void post(URL url, Callback callback) throws IOException, RequestException{ + public void post(URL url, Callback callback) throws IOException, RequestException { asyncExecute(()->post(URL2URI(url), null, null, null, callback)); } @Override - public void post(URI uri, Map parameters, Callback callback) throws IOException, RequestException{ + public void post(URI uri, Map parameters, Callback callback) throws IOException, RequestException { post(uri, null, parameters, null, callback); } @Override - public void post(URL url, Map parameters, Callback callback) throws IOException, RequestException{ + public void post(URL url, Map parameters, Callback callback) throws IOException, RequestException { asyncExecute(()->post(URL2URI(url), null, parameters, null, callback)); } @Override - public void post(URI uri, List
headers, Callback callback) throws IOException, RequestException{ + public void post(URI uri, List
headers, Callback callback) throws IOException, RequestException { post(uri, null, null, headers, callback); } @Override - public void post(URL url, List
headers, Callback callback) throws IOException, RequestException{ + public void post(URL url, List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->post(URL2URI(url), null, null, headers, callback)); } @Override public void post(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { post(uri, null, parameters, headers, callback); } @Override public void post(URL url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->post(URL2URI(url), null, parameters, headers, callback)); } @Override - public void post(URI uri, RequestBody data, Callback callback) throws IOException, RequestException{ + public void post(URI uri, RequestBody data, Callback callback) throws IOException, RequestException { post(uri, data, null, null, callback); } @Override - public void post(URL url, RequestBody data, Callback callback) throws IOException, RequestException{ + public void post(URL url, RequestBody data, Callback callback) throws IOException, RequestException { asyncExecute(()->post(URL2URI(url), data, null, null, callback)); } @Override public void post(URI uri, RequestBody data, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { post(uri, data, parameters, null, callback); } @Override public void post(URL url, RequestBody data, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->post(URL2URI(url), data, parameters, null, callback)); } @Override public void post(URI uri, RequestBody data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { post(uri, data, null, headers, callback); } @Override public void post(URL url, RequestBody data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->post(URL2URI(url), data, null, headers, callback)); } @Override public void post(URL url, RequestBody data, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->post(URL2URI(url), data, parameters, headers, callback)); } @Override - public void post(URI uri, int readTimeout, Callback callback) throws IOException, RequestException{ + public void post(URI uri, int readTimeout, Callback callback) throws IOException, RequestException { post(uri, readTimeout, null, null, null, callback); } @Override - public void post(URL url, int readTimeout, Callback callback) throws IOException, RequestException{ + public void post(URL url, int readTimeout, Callback callback) throws IOException, RequestException { asyncExecute(()->post(URL2URI(url), readTimeout, null, null, null, callback)); } @Override public void post(URI uri, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { post(uri, readTimeout, null, parameters, null, callback); } @Override public void post(URL url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->post(URL2URI(url), readTimeout, null, parameters, null, callback)); } @Override public void post(URI uri, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { post(uri, readTimeout, null, null, headers, callback); } @Override public void post(URL url, int readTimeout, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->post(URL2URI(url), readTimeout, null, null, headers, callback)); } @Override public void post(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { post(uri, readTimeout, null, parameters, headers, callback); } @Override public void post(URL url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->post(URL2URI(url), readTimeout, null, parameters, headers, callback)); } @Override public void post(URI uri, int readTimeout, RequestBody data, Callback callback) throws IOException, - RequestException{ + RequestException { post(uri, readTimeout, data, null, null, callback); } @Override public void post(URL url, int readTimeout, RequestBody data, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->post(URL2URI(url), readTimeout, data, null, null, callback)); } @Override public void post(URI uri, int readTimeout, RequestBody data, Map parameters, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { post(uri, readTimeout, data, parameters, null, callback); } @Override public void post(URL url, int readTimeout, RequestBody data, Map parameters, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->post(URL2URI(url), readTimeout, data, parameters, null, callback)); } @Override public void post(URI uri, int readTimeout, RequestBody data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { post(uri, readTimeout, data, null, headers, callback); } @Override public void post(URL url, int readTimeout, RequestBody data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->post(URL2URI(url), readTimeout, data, null, headers, callback)); } @Override public void post(URL url, int readTimeout, RequestBody data, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->post(URL2URI(url), readTimeout, data, parameters, headers, callback)); } @Override - public void put(URI uri, Callback callback) throws IOException, RequestException{ + public void put(URI uri, Callback callback) throws IOException, RequestException { put(uri, null, null, null, callback); } @Override - public void put(URL url, Callback callback) throws IOException, RequestException{ + public void put(URL url, Callback callback) throws IOException, RequestException { asyncExecute(()->put(URL2URI(url), null, null, null, callback)); } @Override - public void put(URI uri, Map parameters, Callback callback) throws IOException, RequestException{ + public void put(URI uri, Map parameters, Callback callback) throws IOException, RequestException { put(uri, null, parameters, null, callback); } @Override - public void put(URL url, Map parameters, Callback callback) throws IOException, RequestException{ + public void put(URL url, Map parameters, Callback callback) throws IOException, RequestException { asyncExecute(()->put(URL2URI(url), null, parameters, null, callback)); } @Override - public void put(URI uri, List
headers, Callback callback) throws IOException, RequestException{ + public void put(URI uri, List
headers, Callback callback) throws IOException, RequestException { put(uri, null, null, headers, callback); } @Override - public void put(URL url, List
headers, Callback callback) throws IOException, RequestException{ + public void put(URL url, List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->put(URL2URI(url), null, null, headers, callback)); } @Override public void put(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { put(uri, null, parameters, headers, callback); } @Override public void put(URL url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->put(URL2URI(url), null, parameters, headers, callback)); } @Override - public void put(URI uri, RequestBody data, Callback callback) throws IOException, RequestException{ + public void put(URI uri, RequestBody data, Callback callback) throws IOException, RequestException { put(uri, data, null, null, callback); } @Override - public void put(URL url, RequestBody data, Callback callback) throws IOException, RequestException{ + public void put(URL url, RequestBody data, Callback callback) throws IOException, RequestException { asyncExecute(()->put(URL2URI(url), data, null, null, callback)); } @Override public void put(URI uri, RequestBody data, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { put(uri, data, parameters, null, callback); } @Override public void put(URL url, RequestBody data, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->put(URL2URI(url), data, parameters, null, callback)); } @Override public void put(URI uri, RequestBody data, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { put(uri, data, null, headers, callback); } @Override public void put(URL url, RequestBody data, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->put(URL2URI(url), data, null, headers, callback)); } @Override public void put(URL url, RequestBody data, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->put(URL2URI(url), data, parameters, headers, callback)); } @Override - public void put(URI uri, int readTimeout, Callback callback) throws IOException, RequestException{ + public void put(URI uri, int readTimeout, Callback callback) throws IOException, RequestException { put(uri, readTimeout, null, null, null, callback); } @Override - public void put(URL url, int readTimeout, Callback callback) throws IOException, RequestException{ + public void put(URL url, int readTimeout, Callback callback) throws IOException, RequestException { asyncExecute(()->put(URL2URI(url), readTimeout, null, null, null, callback)); } @Override public void put(URI uri, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { put(uri, readTimeout, null, parameters, null, callback); } @Override public void put(URL url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->put(URL2URI(url), readTimeout, null, parameters, null, callback)); } @Override public void put(URI uri, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { put(uri, readTimeout, null, null, headers, callback); } @Override public void put(URL url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->put(URL2URI(url), readTimeout, null, null, headers, callback)); } @Override public void put(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { put(uri, readTimeout, parameters, headers, callback); } @Override public void put(URL url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->put(URL2URI(url), readTimeout, parameters, headers, callback)); } @Override public void put(URI uri, int readTimeout, RequestBody data, Callback callback) throws IOException, - RequestException{ + RequestException { put(uri, readTimeout, data, null, null, callback); } @Override public void put(URL url, int readTimeout, RequestBody data, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->put(URL2URI(url), readTimeout, data, null, null, callback)); } @Override public void put(URI uri, int readTimeout, RequestBody data, Map parameters, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { put(uri, readTimeout, data, parameters, null, callback); } @Override public void put(URL url, int readTimeout, RequestBody data, Map parameters, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->put(URL2URI(url), readTimeout, data, parameters, null, callback)); } @Override public void put(URI uri, int readTimeout, RequestBody data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { put(uri, readTimeout, data, null, headers, callback); } @Override public void put(URL url, int readTimeout, RequestBody data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->put(URL2URI(url), readTimeout, data, null, headers, callback)); } @Override public void put(URL url, int readTimeout, RequestBody data, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->put(URL2URI(url), readTimeout, data, parameters, headers, callback)); } @Override - public void patch(URI uri, Callback callback) throws IOException, RequestException{ + public void patch(URI uri, Callback callback) throws IOException, RequestException { patch(uri, null, null, null, callback); } @Override - public void patch(URL url, Callback callback) throws IOException, RequestException{ + public void patch(URL url, Callback callback) throws IOException, RequestException { asyncExecute(()->patch(URL2URI(url), null, null, null, callback)); } @Override - public void patch(URI uri, Map parameters, Callback callback) throws IOException, RequestException{ + public void patch(URI uri, Map parameters, Callback callback) throws IOException, RequestException { patch(uri, null, parameters, null, callback); } @Override - public void patch(URL url, Map parameters, Callback callback) throws IOException, RequestException{ + public void patch(URL url, Map parameters, Callback callback) throws IOException, RequestException { asyncExecute(()->patch(URL2URI(url), null, parameters, null, callback)); } @Override - public void patch(URI uri, List
headers, Callback callback) throws IOException, RequestException{ + public void patch(URI uri, List
headers, Callback callback) throws IOException, RequestException { patch(uri, null, null, headers, callback); } @Override - public void patch(URL url, List
headers, Callback callback) throws IOException, RequestException{ + public void patch(URL url, List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->patch(URL2URI(url), null, null, headers, callback)); } @Override public void patch(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { patch(uri, null, parameters, headers, callback); } @Override public void patch(URL url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->patch(URL2URI(url), null, parameters, headers, callback)); } @Override - public void patch(URI uri, RequestBody data, Callback callback) throws IOException, RequestException{ + public void patch(URI uri, RequestBody data, Callback callback) throws IOException, RequestException { patch(uri, data, null, null, callback); } @Override - public void patch(URL url, RequestBody data, Callback callback) throws IOException, RequestException{ + public void patch(URL url, RequestBody data, Callback callback) throws IOException, RequestException { asyncExecute(()->patch(URL2URI(url), data, null, null, callback)); } @Override public void patch(URI uri, RequestBody data, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { patch(uri, data, parameters, null, callback); } @Override public void patch(URL url, RequestBody data, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->patch(URL2URI(url), data, parameters, null, callback)); } @Override public void patch(URI uri, RequestBody data, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { patch(uri, data, null, headers, callback); } @Override public void patch(URL url, RequestBody data, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->patch(URL2URI(url), data, null, headers, callback)); } @Override public void patch(URL url, RequestBody data, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->patch(URL2URI(url), data, parameters, headers, callback)); } @Override - public void patch(URI uri, int readTimeout, Callback callback) throws IOException, RequestException{ + public void patch(URI uri, int readTimeout, Callback callback) throws IOException, RequestException { patch(uri, readTimeout, null, null, null, callback); } @Override - public void patch(URL url, int readTimeout, Callback callback) throws IOException, RequestException{ + public void patch(URL url, int readTimeout, Callback callback) throws IOException, RequestException { asyncExecute(()->patch(URL2URI(url), readTimeout, null, null, null, callback)); } @Override public void patch(URI uri, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { patch(uri, readTimeout, null, parameters, null, callback); } @Override public void patch(URL url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->patch(URL2URI(url), readTimeout, null, parameters, null, callback)); } @Override public void patch(URI uri, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { patch(uri, readTimeout, null, null, headers, callback); } @Override public void patch(URL url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->patch(URL2URI(url), readTimeout, null, null, headers, callback)); } @Override public void patch(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { patch(uri, readTimeout, null, parameters, headers, callback); } @Override public void patch(URL url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->patch(URL2URI(url), readTimeout, null, parameters, headers, callback)); } @Override public void patch(URI uri, int readTimeout, RequestBody data, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { patch(uri, readTimeout, data, null, null, callback); } @Override public void patch(URL url, int readTimeout, RequestBody data, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->patch(URL2URI(url), readTimeout, data, null, null, callback)); } @Override public void patch(URI uri, int readTimeout, RequestBody data, Map parameters, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { patch(uri, readTimeout, data, parameters, null, callback); } @Override public void patch(URL url, int readTimeout, RequestBody data, Map parameters, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->patch(URL2URI(url), readTimeout, data, parameters, null, callback)); } @Override public void patch(URI uri, int readTimeout, RequestBody data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { patch(uri, readTimeout, data, null, headers, callback); } @Override public void patch(URL url, int readTimeout, RequestBody data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->patch(URL2URI(url), readTimeout, data, null, headers, callback)); } @Override public void patch(URL url, int readTimeout, RequestBody data, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->patch(URL2URI(url), readTimeout, data, parameters, headers, callback)); } @Override - public void delete(URI uri, Callback callback) throws IOException, RequestException{ + public void delete(URI uri, Callback callback) throws IOException, RequestException { delete(uri, null, null, callback); } @Override - public void delete(URL url, Callback callback) throws IOException, RequestException{ + public void delete(URL url, Callback callback) throws IOException, RequestException { asyncExecute(()->delete(URL2URI(url), null, null, callback)); } @Override - public void delete(URI uri, Map parameters, Callback callback) throws IOException, RequestException{ + public void delete(URI uri, Map parameters, Callback callback) + throws IOException, RequestException { delete(uri, parameters, null, callback); } @Override - public void delete(URL url, Map parameters, Callback callback) throws IOException, RequestException{ + public void delete(URL url, Map parameters, Callback callback) + throws IOException, RequestException { asyncExecute(()->delete(URL2URI(url), parameters, null, callback)); } @Override - public void delete(URI uri, List
headers, Callback callback) throws IOException, RequestException{ + public void delete(URI uri, List
headers, Callback callback) throws IOException, RequestException { delete(uri, null, headers, callback); } @Override - public void delete(URL url, List
headers, Callback callback) throws IOException, RequestException{ + public void delete(URL url, List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->delete(URL2URI(url), null, headers, callback)); } @Override public void delete(URL url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->delete(URL2URI(url), parameters, headers, callback)); } @Override - public void delete(URI uri, int readTimeout, Callback callback) throws IOException, RequestException{ + public void delete(URI uri, int readTimeout, Callback callback) throws IOException, RequestException { delete(uri, readTimeout, null, null, callback); } @Override - public void delete(URL url, int readTimeout, Callback callback) throws IOException, RequestException{ + public void delete(URL url, int readTimeout, Callback callback) throws IOException, RequestException { asyncExecute(()->delete(URL2URI(url), readTimeout, null, null, callback)); } @Override public void delete(URI uri, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { delete(uri, readTimeout, parameters, null, callback); } @Override public void delete(URL url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->delete(URL2URI(url), readTimeout, parameters, null, callback)); } @Override public void delete(URI uri, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { delete(uri, readTimeout, null, headers, callback); } @Override public void delete(URL url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->delete(URL2URI(url), readTimeout, null, headers, callback)); } @Override public void delete(URL url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->delete(URL2URI(url), readTimeout, parameters, headers, callback)); } @Override - public void connect(URI uri, Callback callback) throws IOException, RequestException{ + public void connect(URI uri, Callback callback) throws IOException, RequestException { connect(uri, null, null, callback); } @Override - public void connect(URL url, Callback callback) throws IOException, RequestException{ + public void connect(URL url, Callback callback) throws IOException, RequestException { asyncExecute(()->connect(URL2URI(url), null, null, callback)); } @Override public void connect(URI uri, Map parameters, Callback callback) throws IOException, - RequestException{ + RequestException { connect(uri, parameters, null, callback); } @Override public void connect(URL url, Map parameters, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->connect(URL2URI(url), parameters, null, callback)); } @Override - public void connect(URI uri, List
headers, Callback callback) throws IOException, RequestException{ + public void connect(URI uri, List
headers, Callback callback) throws IOException, RequestException { connect(uri, null, headers, callback); } @Override - public void connect(URL url, List
headers, Callback callback) throws IOException, RequestException{ + public void connect(URL url, List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->connect(URL2URI(url), null, headers, callback)); } @Override public void connect(URL url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->connect(URL2URI(url), parameters, headers, callback)); } @Override - public void connect(URI uri, int readTimeout, Callback callback) throws IOException, RequestException{ + public void connect(URI uri, int readTimeout, Callback callback) throws IOException, RequestException { connect(uri, readTimeout, null, null, callback); } @Override - public void connect(URL url, int readTimeout, Callback callback) throws IOException, RequestException{ + public void connect(URL url, int readTimeout, Callback callback) throws IOException, RequestException { asyncExecute(()->connect(URL2URI(url), readTimeout, null, null, callback)); } @Override public void connect(URI uri, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { connect(uri, readTimeout, parameters, null, callback); } @Override public void connect(URL url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->connect(URL2URI(url), readTimeout, parameters, null, callback)); } @Override public void connect(URI uri, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { connect(uri, readTimeout, null, headers, callback); } @Override public void connect(URL url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->connect(URL2URI(url), readTimeout, null, headers, callback)); } @Override public void connect(URL url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->connect(URL2URI(url), readTimeout, parameters, headers, callback)); } @Override - public void trace(URI uri, Callback callback) throws IOException, RequestException{ + public void trace(URI uri, Callback callback) throws IOException, RequestException { trace(uri, null, null, callback); } @Override - public void trace(URL url, Callback callback) throws IOException, RequestException{ + public void trace(URL url, Callback callback) throws IOException, RequestException { asyncExecute(()->trace(URL2URI(url), null, null, callback)); } @Override - public void trace(URI uri, Map parameters, Callback callback) throws IOException, RequestException{ + public void trace(URI uri, Map parameters, Callback callback) throws IOException, RequestException { trace(uri, parameters, null, callback); } @Override - public void trace(URL url, Map parameters, Callback callback) throws IOException, RequestException{ + public void trace(URL url, Map parameters, Callback callback) throws IOException, RequestException { asyncExecute(()->trace(URL2URI(url), parameters, null, callback)); } @Override - public void trace(URI uri, List
headers, Callback callback) throws IOException, RequestException{ + public void trace(URI uri, List
headers, Callback callback) throws IOException, RequestException { trace(uri, null, headers, callback); } @Override - public void trace(URL url, List
headers, Callback callback) throws IOException, RequestException{ + public void trace(URL url, List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->trace(URL2URI(url), null, headers, callback)); } @Override public void trace(URL url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->trace(URL2URI(url), parameters, headers, callback)); } @Override - public void trace(URI uri, int readTimeout, Callback callback) throws IOException, RequestException{ + public void trace(URI uri, int readTimeout, Callback callback) throws IOException, RequestException { trace(uri, readTimeout, null, null, callback); } @Override - public void trace(URL url, int readTimeout, Callback callback) throws IOException, RequestException{ + public void trace(URL url, int readTimeout, Callback callback) throws IOException, RequestException { asyncExecute(()->trace(URL2URI(url), readTimeout, null, null, callback)); } @Override public void trace(URI uri, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { trace(uri, readTimeout, parameters, null, callback); } @Override public void trace(URL url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->trace(URL2URI(url), readTimeout, parameters, null, callback)); } @Override public void trace(URI uri, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { trace(uri, readTimeout, null, headers, callback); } @Override public void trace(URL url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->trace(URL2URI(url), readTimeout, null, headers, callback)); } @Override public void trace(URL url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->trace(URL2URI(url), readTimeout, parameters, headers, callback)); } @Override - public void copy(URI uri, Callback callback) throws IOException, RequestException{ + public void copy(URI uri, Callback callback) throws IOException, RequestException { copy(uri, null, null, callback); } @Override - public void copy(URL url, Callback callback) throws IOException, RequestException{ + public void copy(URL url, Callback callback) throws IOException, RequestException { asyncExecute(()->copy(URL2URI(url), null, null, callback)); } @Override - public void copy(URI uri, Map parameters, Callback callback) throws IOException, RequestException{ + public void copy(URI uri, Map parameters, Callback callback) throws IOException, RequestException { copy(uri, parameters, null, callback); } @Override - public void copy(URL url, Map parameters, Callback callback) throws IOException, RequestException{ + public void copy(URL url, Map parameters, Callback callback) throws IOException, RequestException { asyncExecute(()->copy(URL2URI(url), parameters, null, callback)); } @Override - public void copy(URI uri, List
headers, Callback callback) throws IOException, RequestException{ + public void copy(URI uri, List
headers, Callback callback) throws IOException, RequestException { copy(uri, null, headers, callback); } @Override - public void copy(URL url, List
headers, Callback callback) throws IOException, RequestException{ + public void copy(URL url, List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->copy(URL2URI(url), null, headers, callback)); } @Override public void copy(URL url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->copy(URL2URI(url), parameters, headers, callback)); } @Override - public void copy(URI uri, int readTimeout, Callback callback) throws IOException, RequestException{ + public void copy(URI uri, int readTimeout, Callback callback) throws IOException, RequestException { copy(uri, readTimeout, null, null, callback); } @Override - public void copy(URL url, int readTimeout, Callback callback) throws IOException, RequestException{ + public void copy(URL url, int readTimeout, Callback callback) throws IOException, RequestException { asyncExecute(()->copy(URL2URI(url), readTimeout, null, null, callback)); } @Override public void copy(URI uri, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { copy(uri, readTimeout, parameters, null, callback); } @Override public void copy(URL url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->copy(URL2URI(url), readTimeout, parameters, null, callback)); } @Override public void copy(URI uri, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { copy(uri, readTimeout, null, headers, callback); } @Override public void copy(URL url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->copy(URL2URI(url), readTimeout, null, headers, callback)); } @Override public void copy(URL url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->copy(URL2URI(url), readTimeout, parameters, headers, callback)); } @Override - public void move(URI uri, Callback callback) throws IOException, RequestException{ + public void move(URI uri, Callback callback) throws IOException, RequestException { move(uri, null, null, callback); } @Override - public void move(URL url, Callback callback) throws IOException, RequestException{ + public void move(URL url, Callback callback) throws IOException, RequestException { asyncExecute(()->move(URL2URI(url), null, null, callback)); } @Override - public void move(URI uri, Map parameters, Callback callback) throws IOException, RequestException{ + public void move(URI uri, Map parameters, Callback callback) throws IOException, RequestException { move(uri, parameters, null, callback); } @Override - public void move(URL url, Map parameters, Callback callback) throws IOException, RequestException{ + public void move(URL url, Map parameters, Callback callback) throws IOException, RequestException { asyncExecute(()->move(URL2URI(url), parameters, null, callback)); } @Override - public void move(URI uri, List
headers, Callback callback) throws IOException, RequestException{ + public void move(URI uri, List
headers, Callback callback) throws IOException, RequestException { move(uri, null, headers, callback); } @Override - public void move(URL url, List
headers, Callback callback) throws IOException, RequestException{ + public void move(URL url, List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->move(URL2URI(url), null, headers, callback)); } @Override public void move(URL url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->move(URL2URI(url), parameters, headers, callback)); } @Override - public void move(URI uri, int readTimeout, Callback callback) throws IOException, RequestException{ + public void move(URI uri, int readTimeout, Callback callback) throws IOException, RequestException { move(uri, readTimeout, null, null, callback); } @Override - public void move(URL url, int readTimeout, Callback callback) throws IOException, RequestException{ + public void move(URL url, int readTimeout, Callback callback) throws IOException, RequestException { asyncExecute(()->move(URL2URI(url), readTimeout, null, null, callback)); } @Override public void move(URI uri, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { move(uri, readTimeout, parameters, null, callback); } @Override public void move(URL url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->move(URL2URI(url), readTimeout, parameters, null, callback)); } @Override public void move(URI uri, int readTimeout, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { move(uri, readTimeout, null, headers, callback); } @Override public void move(URL url, int readTimeout, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->move(URL2URI(url), readTimeout, null, headers, callback)); } @Override public void move(URL url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->move(URL2URI(url), readTimeout, parameters, headers, callback)); } @Override - public void head(URI uri, Callback callback) throws IOException, RequestException{ + public void head(URI uri, Callback callback) throws IOException, RequestException { head(uri, null, null, callback); } @Override - public void head(URL url, Callback callback) throws IOException, RequestException{ + public void head(URL url, Callback callback) throws IOException, RequestException { asyncExecute(()->head(URL2URI(url), null, null, callback)); } @Override - public void head(URI uri, Map parameters, Callback callback) throws IOException, RequestException{ + public void head(URI uri, Map parameters, Callback callback) throws IOException, RequestException { head(uri, parameters, null, callback); } @Override - public void head(URL url, Map parameters, Callback callback) throws IOException, RequestException{ + public void head(URL url, Map parameters, Callback callback) throws IOException, RequestException { asyncExecute(()->head(URL2URI(url), parameters, null, callback)); } @Override - public void head(URI uri, List
headers, Callback callback) throws IOException, RequestException{ + public void head(URI uri, List
headers, Callback callback) throws IOException, RequestException { head(uri, null, headers, callback); } @Override - public void head(URL url, List
headers, Callback callback) throws IOException, RequestException{ + public void head(URL url, List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->head(URL2URI(url), null, headers, callback)); } @Override public void head(URL url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->head(URL2URI(url), parameters, headers, callback)); } @Override - public void head(URI uri, int readTimeout, Callback callback) throws IOException, RequestException{ + public void head(URI uri, int readTimeout, Callback callback) throws IOException, RequestException { head(uri, readTimeout, null, null, callback); } @Override - public void head(URL url, int readTimeout, Callback callback) throws IOException, RequestException{ + public void head(URL url, int readTimeout, Callback callback) throws IOException, RequestException { asyncExecute(()->head(URL2URI(url), readTimeout, null, null, callback)); } @Override public void head(URI uri, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { head(uri, readTimeout, parameters, null, callback); } @Override public void head(URL url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->head(URL2URI(url), readTimeout, parameters, null, callback)); } @Override public void head(URI uri, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { head(uri, readTimeout, null, headers, callback); } @Override public void head(URL url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->head(URL2URI(url), readTimeout, null, headers, callback)); } @Override public void head(URL url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->head(URL2URI(url), readTimeout, parameters, headers, callback)); } @Override - public void options(URI uri, Callback callback) throws IOException, RequestException{ + public void options(URI uri, Callback callback) throws IOException, RequestException { options(uri, null, null, callback); } @Override - public void options(URL url, Callback callback) throws IOException, RequestException{ + public void options(URL url, Callback callback) throws IOException, RequestException { asyncExecute(()->options(URL2URI(url), null, null, callback)); } @Override public void options(URI uri, Map parameters, Callback callback) throws IOException, - RequestException{ + RequestException { options(uri, parameters, null, callback); } @Override public void options(URL url, Map parameters, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->options(URL2URI(url), parameters, null, callback)); } @Override - public void options(URI uri, List
headers, Callback callback) throws IOException, RequestException{ + public void options(URI uri, List
headers, Callback callback) throws IOException, RequestException { options(uri, null, headers, callback); } @Override - public void options(URL url, List
headers, Callback callback) throws IOException, RequestException{ + public void options(URL url, List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->options(URL2URI(url), null, headers, callback)); } @Override public void options(URL url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->options(URL2URI(url), parameters, headers, callback)); } @Override - public void options(URI uri, int readTimeout, Callback callback) throws IOException, RequestException{ + public void options(URI uri, int readTimeout, Callback callback) throws IOException, RequestException { options(uri, readTimeout, null, null, callback); } @Override - public void options(URL url, int readTimeout, Callback callback) throws IOException, RequestException{ + public void options(URL url, int readTimeout, Callback callback) throws IOException, RequestException { asyncExecute(()->options(URL2URI(url), readTimeout, null, null, callback)); } @Override public void options(URI uri, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { options(uri, readTimeout, parameters, null, callback); } @Override public void options(URL url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->options(URL2URI(url), readTimeout, parameters, null, callback)); } @Override public void options(URI uri, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { options(uri, readTimeout, null, headers, callback); } @Override public void options(URL url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->options(URL2URI(url), readTimeout, null, headers, callback)); } @Override public void options(URL url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->options(URL2URI(url), readTimeout, parameters, headers, callback)); } @Override - public void link(URI uri, Callback callback) throws IOException, RequestException{ + public void link(URI uri, Callback callback) throws IOException, RequestException { link(uri, null, null, callback); } @Override - public void link(URL url, Callback callback) throws IOException, RequestException{ + public void link(URL url, Callback callback) throws IOException, RequestException { asyncExecute(()->link(URL2URI(url), null, null, callback)); } @Override - public void link(URI uri, Map parameters, Callback callback) throws IOException, RequestException{ + public void link(URI uri, Map parameters, Callback callback) throws IOException, RequestException { link(uri, parameters, null, callback); } @Override - public void link(URL url, Map parameters, Callback callback) throws IOException, RequestException{ + public void link(URL url, Map parameters, Callback callback) throws IOException, RequestException { asyncExecute(()->link(URL2URI(url), parameters, null, callback)); } @Override - public void link(URI uri, List
headers, Callback callback) throws IOException, RequestException{ + public void link(URI uri, List
headers, Callback callback) throws IOException, RequestException { link(uri, null, headers, callback); } @Override - public void link(URL url, List
headers, Callback callback) throws IOException, RequestException{ + public void link(URL url, List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->link(URL2URI(url), null, headers, callback)); } @Override public void link(URL url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->link(URL2URI(url), parameters, headers, callback)); } @Override - public void link(URI uri, int readTimeout, Callback callback) throws IOException, RequestException{ + public void link(URI uri, int readTimeout, Callback callback) throws IOException, RequestException { link(uri, readTimeout, null, null, callback); } @Override - public void link(URL url, int readTimeout, Callback callback) throws IOException, RequestException{ + public void link(URL url, int readTimeout, Callback callback) throws IOException, RequestException { asyncExecute(()->link(URL2URI(url), readTimeout, null, null, callback)); } @Override public void link(URI uri, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { link(uri, readTimeout, parameters, null, callback); } @Override public void link(URL url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->link(URL2URI(url), readTimeout, parameters, null, callback)); } @Override public void link(URI uri, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { link(uri, readTimeout, null, headers, callback); } @Override public void link(URL url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->link(URL2URI(url), readTimeout, null, headers, callback)); } @Override public void link(URL url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->link(URL2URI(url), readTimeout, parameters, headers, callback)); } @Override - public void unlink(URI uri, Callback callback) throws IOException, RequestException{ + public void unlink(URI uri, Callback callback) throws IOException, RequestException { unlink(uri, null, null, callback); } @Override - public void unlink(URL url, Callback callback) throws IOException, RequestException{ + public void unlink(URL url, Callback callback) throws IOException, RequestException { asyncExecute(()->unlink(URL2URI(url), null, null, callback)); } @Override - public void unlink(URI uri, Map parameters, Callback callback) throws IOException, RequestException{ + public void unlink(URI uri, Map parameters, Callback callback) + throws IOException, RequestException { unlink(uri, parameters, null, callback); } @Override - public void unlink(URL url, Map parameters, Callback callback) throws IOException, RequestException{ + public void unlink(URL url, Map parameters, Callback callback) + throws IOException, RequestException { asyncExecute(()->unlink(URL2URI(url), parameters, null, callback)); } @Override - public void unlink(URI uri, List
headers, Callback callback) throws IOException, RequestException{ + public void unlink(URI uri, List
headers, Callback callback) throws IOException, RequestException { unlink(uri, null, headers, callback); } @Override - public void unlink(URL url, List
headers, Callback callback) throws IOException, RequestException{ + public void unlink(URL url, List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->unlink(URL2URI(url), null, headers, callback)); } @Override public void unlink(URL url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->unlink(URL2URI(url), parameters, headers, callback)); } @Override - public void unlink(URI uri, int readTimeout, Callback callback) throws IOException, RequestException{ + public void unlink(URI uri, int readTimeout, Callback callback) throws IOException, RequestException { unlink(uri, readTimeout, null, null, callback); } @Override - public void unlink(URL url, int readTimeout, Callback callback) throws IOException, RequestException{ + public void unlink(URL url, int readTimeout, Callback callback) throws IOException, RequestException { asyncExecute(()->unlink(URL2URI(url), readTimeout, null, null, callback)); } @Override public void unlink(URI uri, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { unlink(uri, readTimeout, parameters, null, callback); } @Override public void unlink(URL url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->unlink(URL2URI(url), readTimeout, parameters, null, callback)); } @Override public void unlink(URI uri, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { unlink(uri, readTimeout, null, headers, callback); } @Override public void unlink(URL url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->unlink(URL2URI(url), readTimeout, null, headers, callback)); } @Override public void unlink(URL url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->unlink(URL2URI(url), readTimeout, parameters, headers, callback)); } @Override - public void purge(URI uri, Callback callback) throws IOException, RequestException{ + public void purge(URI uri, Callback callback) throws IOException, RequestException { purge(uri, null, null, callback); } @Override - public void purge(URL url, Callback callback) throws IOException, RequestException{ + public void purge(URL url, Callback callback) throws IOException, RequestException { asyncExecute(()->purge(URL2URI(url), null, null, callback)); } @Override - public void purge(URI uri, Map parameters, Callback callback) throws IOException, RequestException{ + public void purge(URI uri, Map parameters, Callback callback) throws IOException, RequestException { purge(uri, parameters, null, callback); } @Override - public void purge(URL url, Map parameters, Callback callback) throws IOException, RequestException{ + public void purge(URL url, Map parameters, Callback callback) throws IOException, RequestException { asyncExecute(()->purge(URL2URI(url), parameters, null, callback)); } @Override - public void purge(URI uri, List
headers, Callback callback) throws IOException, RequestException{ + public void purge(URI uri, List
headers, Callback callback) throws IOException, RequestException { purge(uri, null, headers, callback); } @Override - public void purge(URL url, List
headers, Callback callback) throws IOException, RequestException{ + public void purge(URL url, List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->purge(URL2URI(url), null, headers, callback)); } @Override public void purge(URL url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->purge(URL2URI(url), parameters, headers, callback)); } @Override - public void purge(URI uri, int readTimeout, Callback callback) throws IOException, RequestException{ + public void purge(URI uri, int readTimeout, Callback callback) throws IOException, RequestException { purge(uri, readTimeout, null, null, callback); } @Override - public void purge(URL url, int readTimeout, Callback callback) throws IOException, RequestException{ + public void purge(URL url, int readTimeout, Callback callback) throws IOException, RequestException { asyncExecute(()->purge(URL2URI(url), readTimeout, null, null, callback)); } @Override public void purge(URI uri, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { purge(uri, readTimeout, parameters, null, callback); } @Override public void purge(URL url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->purge(URL2URI(url), readTimeout, parameters, null, callback)); } @Override public void purge(URI uri, int readTimeout, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { purge(uri, readTimeout, null, headers, callback); } @Override public void purge(URL url, int readTimeout, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->purge(URL2URI(url), readTimeout, null, headers, callback)); } @Override public void purge(URL url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->purge(URL2URI(url), readTimeout, parameters, headers, callback)); } @Override - public void lock(URI uri, Callback callback) throws IOException, RequestException{ + public void lock(URI uri, Callback callback) throws IOException, RequestException { lock(uri, null, null, callback); } @Override - public void lock(URL url, Callback callback) throws IOException, RequestException{ + public void lock(URL url, Callback callback) throws IOException, RequestException { asyncExecute(()->lock(URL2URI(url), null, null, callback)); } @Override - public void lock(URI uri, Map parameters, Callback callback) throws IOException, RequestException{ + public void lock(URI uri, Map parameters, Callback callback) throws IOException, RequestException { lock(uri, parameters, null, callback); } @Override - public void lock(URL url, Map parameters, Callback callback) throws IOException, RequestException{ + public void lock(URL url, Map parameters, Callback callback) throws IOException, RequestException { asyncExecute(()->lock(URL2URI(url), parameters, null, callback)); } @Override - public void lock(URI uri, List
headers, Callback callback) throws IOException, RequestException{ + public void lock(URI uri, List
headers, Callback callback) throws IOException, RequestException { lock(uri, null, headers, callback); } @Override - public void lock(URL url, List
headers, Callback callback) throws IOException, RequestException{ + public void lock(URL url, List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->lock(URL2URI(url), null, headers, callback)); } @Override public void lock(URL url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->lock(URL2URI(url), parameters, headers, callback)); } @Override - public void lock(URI uri, int readTimeout, Callback callback) throws IOException, RequestException{ + public void lock(URI uri, int readTimeout, Callback callback) throws IOException, RequestException { lock(uri, readTimeout, null, null, callback); } @Override - public void lock(URL url, int readTimeout, Callback callback) throws IOException, RequestException{ + public void lock(URL url, int readTimeout, Callback callback) throws IOException, RequestException { asyncExecute(()->lock(URL2URI(url), readTimeout, null, null, callback)); } @Override public void lock(URI uri, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { lock(uri, readTimeout, parameters, null, callback); } @Override public void lock(URL url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->lock(URL2URI(url), readTimeout, parameters, null, callback)); } @Override public void lock(URI uri, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { lock(uri, readTimeout, null, headers, callback); } @Override public void lock(URL url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->lock(URL2URI(url), readTimeout, null, headers, callback)); } @Override public void lock(URL url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->lock(URL2URI(url), readTimeout, parameters, headers, callback)); } @Override - public void unlock(URI uri, Callback callback) throws IOException, RequestException{ + public void unlock(URI uri, Callback callback) throws IOException, RequestException { unlock(uri, null, null, callback); } @Override - public void unlock(URL url, Callback callback) throws IOException, RequestException{ + public void unlock(URL url, Callback callback) throws IOException, RequestException { asyncExecute(()->unlock(URL2URI(url), null, null, callback)); } @Override - public void unlock(URI uri, Map parameters, Callback callback) throws IOException, RequestException{ + public void unlock(URI uri, Map parameters, Callback callback) + throws IOException, RequestException { unlock(uri, parameters, null, callback); } @Override - public void unlock(URL url, Map parameters, Callback callback) throws IOException, RequestException{ + public void unlock(URL url, Map parameters, Callback callback) + throws IOException, RequestException { asyncExecute(()->unlock(URL2URI(url), parameters, null, callback)); } @Override - public void unlock(URI uri, List
headers, Callback callback) throws IOException, RequestException{ + public void unlock(URI uri, List
headers, Callback callback) throws IOException, RequestException { unlock(uri, null, headers, callback); } @Override - public void unlock(URL url, List
headers, Callback callback) throws IOException, RequestException{ + public void unlock(URL url, List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->unlock(URL2URI(url), null, headers, callback)); } @Override public void unlock(URL url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->unlock(URL2URI(url), parameters, headers, callback)); } @Override - public void unlock(URI uri, int readTimeout, Callback callback) throws IOException, RequestException{ + public void unlock(URI uri, int readTimeout, Callback callback) throws IOException, RequestException { unlock(uri, readTimeout, null, null, callback); } @Override - public void unlock(URL url, int readTimeout, Callback callback) throws IOException, RequestException{ + public void unlock(URL url, int readTimeout, Callback callback) throws IOException, RequestException { asyncExecute(()->unlock(URL2URI(url), readTimeout, null, null, callback)); } @Override public void unlock(URI uri, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { unlock(uri, readTimeout, parameters, null, callback); } @Override public void unlock(URL url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->unlock(URL2URI(url), readTimeout, parameters, null, callback)); } @Override public void unlock(URI uri, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { unlock(uri, readTimeout, null, headers, callback); } @Override public void unlock(URL url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->unlock(URL2URI(url), readTimeout, null, headers, callback)); } @Override public void unlock(URL url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->unlock(URL2URI(url), readTimeout, parameters, headers, callback)); } @Override - public void propfind(URI uri, Callback callback) throws IOException, RequestException{ + public void propfind(URI uri, Callback callback) throws IOException, RequestException { propfind(uri, null, null, callback); } @Override - public void propfind(URL url, Callback callback) throws IOException, RequestException{ + public void propfind(URL url, Callback callback) throws IOException, RequestException { asyncExecute(()->propfind(URL2URI(url), null, null, callback)); } @Override public void propfind(URI uri, Map parameters, Callback callback) throws IOException, - RequestException{ + RequestException { propfind(uri, parameters, null, callback); } @Override public void propfind(URL url, Map parameters, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->propfind(URL2URI(url), parameters, null, callback)); } @Override - public void propfind(URI uri, List
headers, Callback callback) throws IOException, RequestException{ + public void propfind(URI uri, List
headers, Callback callback) throws IOException, RequestException { propfind(uri, null, headers, callback); } @Override - public void propfind(URL url, List
headers, Callback callback) throws IOException, RequestException{ + public void propfind(URL url, List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->propfind(URL2URI(url), null, headers, callback)); } @Override public void propfind(URL url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->propfind(URL2URI(url), parameters, headers, callback)); } @Override - public void propfind(URI uri, int readTimeout, Callback callback) throws IOException, RequestException{ + public void propfind(URI uri, int readTimeout, Callback callback) throws IOException, RequestException { propfind(uri, readTimeout, null, null, callback); } @Override - public void propfind(URL url, int readTimeout, Callback callback) throws IOException, RequestException{ + public void propfind(URL url, int readTimeout, Callback callback) throws IOException, RequestException { asyncExecute(()->propfind(URL2URI(url), readTimeout, null, null, callback)); } @Override public void propfind(URI uri, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { propfind(uri, readTimeout, parameters, null, callback); } @Override public void propfind(URL url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->propfind(URL2URI(url), readTimeout, parameters, null, callback)); } @Override public void propfind(URI uri, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { propfind(uri, readTimeout, null, headers, callback); } @Override public void propfind(URL url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->propfind(URL2URI(url), readTimeout, null, headers, callback)); } @Override public void propfind(URL url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->propfind(URL2URI(url), readTimeout, parameters, headers, callback)); } @Override - public void proppatch(URI uri, Callback callback) throws IOException, RequestException{ + public void proppatch(URI uri, Callback callback) throws IOException, RequestException { proppatch(uri, null, null, null, callback); } @Override - public void proppatch(URL url, Callback callback) throws IOException, RequestException{ + public void proppatch(URL url, Callback callback) throws IOException, RequestException { asyncExecute(()->proppatch(URL2URI(url), null, null, null, callback)); } @Override public void proppatch(URI uri, Map parameters, Callback callback) throws IOException, - RequestException{ + RequestException { proppatch(uri, null, parameters, null, callback); } @Override public void proppatch(URL url, Map parameters, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->proppatch(URL2URI(url), null, parameters, null, callback)); } @Override - public void proppatch(URI uri, List
headers, Callback callback) throws IOException, RequestException{ + public void proppatch(URI uri, List
headers, Callback callback) throws IOException, RequestException { proppatch(uri, null, null, headers, callback); } @Override - public void proppatch(URL url, List
headers, Callback callback) throws IOException, RequestException{ + public void proppatch(URL url, List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->proppatch(URL2URI(url), null, null, headers, callback)); } @Override public void proppatch(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { proppatch(uri, null, parameters, headers, callback); } @Override public void proppatch(URL url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->proppatch(URL2URI(url), null, parameters, headers, callback)); } @Override - public void proppatch(URI uri, RequestBody data, Callback callback) throws IOException, RequestException{ + public void proppatch(URI uri, RequestBody data, Callback callback) throws IOException, RequestException { proppatch(uri, data, null, null, callback); } @Override - public void proppatch(URL url, RequestBody data, Callback callback) throws IOException, RequestException{ + public void proppatch(URL url, RequestBody data, Callback callback) throws IOException, RequestException { asyncExecute(()->proppatch(URL2URI(url), data, null, null, callback)); } @Override public void proppatch(URI uri, RequestBody data, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { proppatch(uri, data, parameters, null, callback); } @Override public void proppatch(URL url, RequestBody data, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->proppatch(URL2URI(url), data, parameters, null, callback)); } @Override public void proppatch(URI uri, RequestBody data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { proppatch(uri, data, null, headers, callback); } @Override public void proppatch(URL url, RequestBody data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->proppatch(URL2URI(url), data, null, headers, callback)); } @Override public void proppatch(URL url, RequestBody data, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->proppatch(URL2URI(url), data, parameters, headers, callback)); } @Override - public void proppatch(URI uri, int readTimeout, Callback callback) throws IOException, RequestException{ + public void proppatch(URI uri, int readTimeout, Callback callback) throws IOException, RequestException { proppatch(uri, readTimeout, null, null, null, callback); } @Override - public void proppatch(URL url, int readTimeout, Callback callback) throws IOException, RequestException{ + public void proppatch(URL url, int readTimeout, Callback callback) throws IOException, RequestException { asyncExecute(()->proppatch(URL2URI(url), readTimeout, null, null, null, callback)); } @Override public void proppatch(URI uri, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { proppatch(uri, readTimeout, null, parameters, null, callback); } @Override public void proppatch(URL url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->proppatch(URL2URI(url), readTimeout, null, parameters, null, callback)); } @Override public void proppatch(URI uri, int readTimeout, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { proppatch(uri, readTimeout, null, null, headers, callback); } @Override public void proppatch(URL url, int readTimeout, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->proppatch(URL2URI(url), readTimeout, null, null, headers, callback)); } @Override public void proppatch(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { proppatch(uri, readTimeout, null, parameters, headers, callback); } @Override public void proppatch(URL url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->proppatch(URL2URI(url), readTimeout, null, parameters, headers, callback)); } @Override public void proppatch(URI uri, int readTimeout, RequestBody data, Callback callback) throws IOException, - RequestException{ + RequestException { proppatch(uri, readTimeout, data, null, null, callback); } @Override public void proppatch(URL url, int readTimeout, RequestBody data, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->proppatch(URL2URI(url), readTimeout, data, null, null, callback)); } @Override public void proppatch(URI uri, int readTimeout, RequestBody data, Map parameters, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { proppatch(uri, readTimeout, data, parameters, null, callback); } @Override public void proppatch(URL url, int readTimeout, RequestBody data, Map parameters, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->proppatch(URL2URI(url), readTimeout, data, parameters, null, callback)); } @Override public void proppatch(URI uri, int readTimeout, RequestBody data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { proppatch(uri, readTimeout, data, null, headers, callback); } @Override public void proppatch(URL url, int readTimeout, RequestBody data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->proppatch(URL2URI(url), readTimeout, data, null, headers, callback)); } @Override public void proppatch(URL url, int readTimeout, RequestBody data, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->proppatch(URL2URI(url), readTimeout, data, parameters, headers, callback)); } @Override - public void report(URI uri, Callback callback) throws IOException, RequestException{ + public void report(URI uri, Callback callback) throws IOException, RequestException { report(uri, null, null, null, callback); } @Override - public void report(URL url, Callback callback) throws IOException, RequestException{ + public void report(URL url, Callback callback) throws IOException, RequestException { asyncExecute(()->report(URL2URI(url), null, null, null, callback)); } @Override - public void report(URI uri, Map parameters, Callback callback) throws IOException, RequestException{ + public void report(URI uri, Map parameters, Callback callback) + throws IOException, RequestException { report(uri, null, parameters, null, callback); } @Override - public void report(URL url, Map parameters, Callback callback) throws IOException, RequestException{ + public void report(URL url, Map parameters, Callback callback) + throws IOException, RequestException { asyncExecute(()->report(URL2URI(url), null, parameters, null, callback)); } @Override - public void report(URI uri, List
headers, Callback callback) throws IOException, RequestException{ + public void report(URI uri, List
headers, Callback callback) throws IOException, RequestException { report(uri, null, null, headers, callback); } @Override - public void report(URL url, List
headers, Callback callback) throws IOException, RequestException{ + public void report(URL url, List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->report(URL2URI(url), null, null, headers, callback)); } @Override public void report(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { report(uri, null, parameters, headers, callback); } @Override public void report(URL url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->report(URL2URI(url), null, parameters, headers, callback)); } @Override - public void report(URI uri, RequestBody data, Callback callback) throws IOException, RequestException{ + public void report(URI uri, RequestBody data, Callback callback) throws IOException, RequestException { report(uri, data, null, null, callback); } @Override - public void report(URL url, RequestBody data, Callback callback) throws IOException, RequestException{ + public void report(URL url, RequestBody data, Callback callback) throws IOException, RequestException { asyncExecute(()->report(URL2URI(url), data, null, null, callback)); } @Override public void report(URI uri, RequestBody data, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { report(uri, data, parameters, null, callback); } @Override public void report(URL url, RequestBody data, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->report(URL2URI(url), data, parameters, null, callback)); } @Override public void report(URI uri, RequestBody data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { report(uri, data, null, headers, callback); } @Override public void report(URL url, RequestBody data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->report(URL2URI(url), data, null, headers, callback)); } @Override public void report(URL url, RequestBody data, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->report(URL2URI(url), data, parameters, headers, callback)); } @Override - public void report(URI uri, int readTimeout, Callback callback) throws IOException, RequestException{ + public void report(URI uri, int readTimeout, Callback callback) throws IOException, RequestException { report(uri, readTimeout, null, null, null, callback); } @Override - public void report(URL url, int readTimeout, Callback callback) throws IOException, RequestException{ + public void report(URL url, int readTimeout, Callback callback) throws IOException, RequestException { asyncExecute(()->report(URL2URI(url), readTimeout, null, null, null, callback)); } @Override public void report(URI uri, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { report(uri, readTimeout, null, parameters, null, callback); } @Override public void report(URL url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->report(URL2URI(url), readTimeout, null, parameters, null, callback)); } @Override public void report(URI uri, int readTimeout, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { report(uri, readTimeout, null, null, headers, callback); } @Override public void report(URL url, int readTimeout, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->report(URL2URI(url), readTimeout, null, null, headers, callback)); } @Override public void report(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { report(uri, readTimeout, parameters, headers, callback); } @Override public void report(URL url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->report(URL2URI(url), readTimeout, parameters, headers, callback)); } @Override public void report(URI uri, int readTimeout, RequestBody data, Callback callback) throws IOException, - RequestException{ + RequestException { report(uri, readTimeout, data, null, null, callback); } @Override public void report(URL url, int readTimeout, RequestBody data, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->report(URL2URI(url), readTimeout, data, null, null, callback)); } @Override public void report(URI uri, int readTimeout, RequestBody data, Map parameters, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { report(uri, readTimeout, data, parameters, null, callback); } @Override public void report(URL url, int readTimeout, RequestBody data, Map parameters, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->report(URL2URI(url), readTimeout, data, parameters, null, callback)); } @Override public void report(URI uri, int readTimeout, RequestBody data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { report(uri, readTimeout, data, null, headers, callback); } @Override public void report(URL url, int readTimeout, RequestBody data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->report(URL2URI(url), readTimeout, data, null, headers, callback)); } @Override public void report(URL url, int readTimeout, RequestBody data, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->report(URL2URI(url), readTimeout, data, parameters, headers, callback)); } @Override - public void view(URI uri, Callback callback) throws IOException, RequestException{ + public void view(URI uri, Callback callback) throws IOException, RequestException { view(uri, null, null, callback); } @Override - public void view(URL url, Callback callback) throws IOException, RequestException{ + public void view(URL url, Callback callback) throws IOException, RequestException { asyncExecute(()->view(URL2URI(url), null, null, callback)); } @Override - public void view(URI uri, Map parameters, Callback callback) throws IOException, RequestException{ + public void view(URI uri, Map parameters, Callback callback) throws IOException, RequestException { view(uri, parameters, null, callback); } @Override - public void view(URL url, Map parameters, Callback callback) throws IOException, RequestException{ + public void view(URL url, Map parameters, Callback callback) throws IOException, RequestException { asyncExecute(()->view(URL2URI(url), parameters, null, callback)); } @Override - public void view(URI uri, List
headers, Callback callback) throws IOException, RequestException{ + public void view(URI uri, List
headers, Callback callback) throws IOException, RequestException { view(uri, null, headers, callback); } @Override - public void view(URL url, List
headers, Callback callback) throws IOException, RequestException{ + public void view(URL url, List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->view(URL2URI(url), null, headers, callback)); } @Override public void view(URL url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->view(URL2URI(url), parameters, headers, callback)); } @Override - public void view(URI uri, int readTimeout, Callback callback) throws IOException, RequestException{ + public void view(URI uri, int readTimeout, Callback callback) throws IOException, RequestException { view(uri, readTimeout, null, null, callback); } @Override - public void view(URL url, int readTimeout, Callback callback) throws IOException, RequestException{ + public void view(URL url, int readTimeout, Callback callback) throws IOException, RequestException { asyncExecute(()->view(URL2URI(url), readTimeout, null, null, callback)); } @Override public void view(URI uri, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { view(uri, readTimeout, parameters, null, callback); } @Override public void view(URL url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->view(URL2URI(url), readTimeout, parameters, null, callback)); } @Override public void view(URI uri, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { view(uri, readTimeout, null, headers, callback); } @Override public void view(URL url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->view(URL2URI(url), readTimeout, null, headers, callback)); } @Override public void view(URL url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->view(URL2URI(url), readTimeout, parameters, headers, callback)); } @Override - public void wrapped(URI uri, Callback callback) throws IOException, RequestException{ + public void wrapped(URI uri, Callback callback) throws IOException, RequestException { wrapped(uri, null, null, callback); } @Override - public void wrapped(URL url, Callback callback) throws IOException, RequestException{ + public void wrapped(URL url, Callback callback) throws IOException, RequestException { asyncExecute(()->wrapped(URL2URI(url), null, null, callback)); } @Override public void wrapped(URI uri, Map parameters, Callback callback) throws IOException, - RequestException{ + RequestException { wrapped(uri, parameters, null, callback); } @Override public void wrapped(URL url, Map parameters, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->wrapped(URL2URI(url), parameters, null, callback)); } @Override - public void wrapped(URI uri, List
headers, Callback callback) throws IOException, RequestException{ + public void wrapped(URI uri, List
headers, Callback callback) throws IOException, RequestException { wrapped(uri, null, headers, callback); } @Override - public void wrapped(URL url, List
headers, Callback callback) throws IOException, RequestException{ + public void wrapped(URL url, List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->wrapped(URL2URI(url), null, headers, callback)); } @Override public void wrapped(URL url, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->wrapped(URL2URI(url), parameters, headers, callback)); } @Override - public void wrapped(URI uri, int readTimeout, Callback callback) throws IOException, RequestException{ + public void wrapped(URI uri, int readTimeout, Callback callback) throws IOException, RequestException { wrapped(uri, readTimeout, null, null, callback); } @Override - public void wrapped(URL url, int readTimeout, Callback callback) throws IOException, RequestException{ + public void wrapped(URL url, int readTimeout, Callback callback) throws IOException, RequestException { asyncExecute(()->wrapped(URL2URI(url), readTimeout, null, null, callback)); } @Override public void wrapped(URI uri, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { wrapped(uri, readTimeout, parameters, null, callback); } @Override public void wrapped(URL url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->wrapped(URL2URI(url), readTimeout, parameters, null, callback)); } @Override public void wrapped(URI uri, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { wrapped(uri, readTimeout, null, headers, callback); } @Override public void wrapped(URL url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { asyncExecute(()->wrapped(URL2URI(url), readTimeout, null, headers, callback)); } @Override public void wrapped(URL url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->wrapped(URL2URI(url), readTimeout, parameters, headers, callback)); } @Override - public void request(URI uri, RequestMethod requestMethod, Callback callback) throws IOException, RequestException{ + public void request(URI uri, RequestMethod requestMethod, Callback callback) throws IOException, RequestException { request(uri, requestMethod, null, null, null, callback); } @Override - public void request(URL url, RequestMethod requestMethod, Callback callback) throws IOException, RequestException{ + public void request(URL url, RequestMethod requestMethod, Callback callback) throws IOException, RequestException { asyncExecute(()->request(URL2URI(url), requestMethod, callback)); } @Override public void request(URI uri, RequestMethod requestMethod, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { request(uri, requestMethod, null, parameters, null, callback); } @Override public void request(URL url, RequestMethod requestMethod, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->request(URL2URI(url), requestMethod, parameters, callback)); } @Override public void request(URI uri, RequestMethod requestMethod, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { request(uri, requestMethod, null, null, headers, callback); } @Override public void request(URL url, RequestMethod requestMethod, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->request(URL2URI(url), requestMethod, headers, callback)); } @Override public void request(URI uri, RequestMethod requestMethod, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { request(uri, requestMethod, null, parameters, headers, callback); } @Override public void request(URL url, RequestMethod requestMethod, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->request(URL2URI(url), requestMethod, parameters, headers, callback)); } @Override public void request(URI uri, RequestMethod requestMethod, RequestBody data, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { request(uri, requestMethod, data, null, null, callback); } @Override public void request(URL url, RequestMethod requestMethod, RequestBody data, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->request(URL2URI(url), requestMethod, data, callback)); } @Override public void request(URI uri, RequestMethod requestMethod, RequestBody data, Map parameters, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { request(uri, requestMethod, data, parameters, null, callback); } @Override public void request(URL url, RequestMethod requestMethod, RequestBody data, Map parameters, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->request(URL2URI(url), requestMethod, data, parameters, callback)); } @Override public void request(URI uri, RequestMethod requestMethod, RequestBody data, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { request(uri, requestMethod, data, null, headers, callback); } @Override public void request(URL url, RequestMethod requestMethod, RequestBody data, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->request(URL2URI(url), requestMethod, data, headers, callback)); } @Override public void request(URI uri, RequestMethod requestMethod, RequestBody data, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { Assert.isNull(requestMethod, "Request method could not be null."); switch(requestMethod){ @@ -2274,98 +2283,98 @@ public void request(URI uri, RequestMethod requestMethod, RequestBody data, M @Override public void request(URL url, RequestMethod requestMethod, RequestBody data, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->request(URL2URI(url), requestMethod, data, parameters, headers, callback)); } @Override public void request(URI uri, RequestMethod requestMethod, int readTimeout, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { request(uri, requestMethod, readTimeout, null, null, null, callback); } @Override public void request(URL url, RequestMethod requestMethod, int readTimeout, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->request(URL2URI(url), requestMethod, readTimeout, callback)); } @Override public void request(URI uri, RequestMethod requestMethod, int readTimeout, Map parameters, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { request(uri, requestMethod, readTimeout, null, parameters, null, callback); } @Override public void request(URL url, RequestMethod requestMethod, int readTimeout, Map parameters, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->request(URL2URI(url), requestMethod, readTimeout, parameters, callback)); } @Override public void request(URI uri, RequestMethod requestMethod, int readTimeout, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { request(uri, requestMethod, readTimeout, null, null, headers, callback); } @Override public void request(URL url, RequestMethod requestMethod, int readTimeout, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->request(URL2URI(url), requestMethod, readTimeout, headers, callback)); } @Override public void request(URI uri, RequestMethod requestMethod, int readTimeout, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { request(uri, requestMethod, readTimeout, null, parameters, headers, callback); } @Override public void request(URL url, RequestMethod requestMethod, int readTimeout, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->request(URL2URI(url), requestMethod, readTimeout, parameters, headers, callback)); } @Override public void request(URI uri, RequestMethod requestMethod, int readTimeout, RequestBody data, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { request(uri, requestMethod, readTimeout, data, null, null, callback); } @Override public void request(URL url, RequestMethod requestMethod, int readTimeout, RequestBody data, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { asyncExecute(()->request(URL2URI(url), requestMethod, readTimeout, data, callback)); } @Override public void request(URI uri, RequestMethod requestMethod, int readTimeout, RequestBody data, - Map parameters, Callback callback) throws IOException, RequestException{ + Map parameters, Callback callback) throws IOException, RequestException { request(uri, requestMethod, readTimeout, data, parameters, null, callback); } @Override public void request(URL url, RequestMethod requestMethod, int readTimeout, RequestBody data, - Map parameters, Callback callback) throws IOException, RequestException{ + Map parameters, Callback callback) throws IOException, RequestException { asyncExecute(()->request(URL2URI(url), requestMethod, readTimeout, data, parameters, callback)); } @Override public void request(URI uri, RequestMethod requestMethod, int readTimeout, RequestBody data, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { request(uri, requestMethod, readTimeout, data, null, headers, callback); } @Override public void request(URL url, RequestMethod requestMethod, int readTimeout, RequestBody data, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { asyncExecute(()->request(URL2URI(url), requestMethod, readTimeout, data, headers, callback)); } @Override public void request(URI uri, RequestMethod requestMethod, int readTimeout, RequestBody data, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { Assert.isNull(requestMethod, "Request method could not be null."); switch(requestMethod){ @@ -2417,8 +2426,23 @@ public void request(URI uri, RequestMethod requestMethod, int readTimeout, Reque @Override public void request(URL url, RequestMethod requestMethod, int readTimeout, RequestBody data, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { asyncExecute(()->request(URL2URI(url), requestMethod, readTimeout, data, parameters, headers, callback)); } + protected static void asyncExecute(final AsyncExecute execute) throws IOException, RequestException { + try{ + execute.exec(); + }catch(URISyntaxException e){ + throw new IllegalArgumentException(e.getMessage(), e); + } + } + + @FunctionalInterface + protected interface AsyncExecute { + + void exec() throws URISyntaxException, IOException, RequestException; + + } + } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/AbstractHttpClient.java b/buession-httpclient/src/main/java/com/buession/httpclient/AbstractHttpClient.java index fee0faf49..e7b43647d 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/AbstractHttpClient.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/AbstractHttpClient.java @@ -27,7 +27,6 @@ import com.buession.core.utils.Assert; import com.buession.httpclient.conn.ConnectionManager; import com.buession.httpclient.core.Header; -import com.buession.httpclient.core.ProtocolVersion; import com.buession.httpclient.core.RequestBody; import com.buession.httpclient.core.RequestMethod; import com.buession.httpclient.core.Response; @@ -35,6 +34,7 @@ import java.io.IOException; import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.util.List; import java.util.Map; @@ -49,7 +49,7 @@ public abstract class AbstractHttpClient extends AbstractBaseHttpClient implemen /** * 构造函数 */ - public AbstractHttpClient(){ + public AbstractHttpClient() { super(); } @@ -59,2082 +59,2095 @@ public AbstractHttpClient(){ * @param connectionManager * 连接管理器 */ - public AbstractHttpClient(ConnectionManager connectionManager){ + public AbstractHttpClient(ConnectionManager connectionManager) { super(connectionManager); } @Override - public Response get(URI uri) throws IOException, RequestException{ + public Response get(URI uri) throws IOException, RequestException { return get(uri, null, null); } @Override - public Response get(URL url) throws IOException, RequestException{ + public Response get(URL url) throws IOException, RequestException { return execute(()->get(URL2URI(url))); } @Override - public Response get(URI uri, Map parameters) throws IOException, RequestException{ + public Response get(URI uri, Map parameters) throws IOException, RequestException { return get(uri, parameters, null); } @Override - public Response get(URL url, Map parameters) throws IOException, RequestException{ + public Response get(URL url, Map parameters) throws IOException, RequestException { return execute(()->get(URL2URI(url), parameters)); } @Override - public Response get(URI uri, List
headers) throws IOException, RequestException{ + public Response get(URI uri, List
headers) throws IOException, RequestException { return get(uri, null, headers); } @Override - public Response get(URL url, List
headers) throws IOException, RequestException{ + public Response get(URL url, List
headers) throws IOException, RequestException { return execute(()->get(URL2URI(url), headers)); } @Override public Response get(URL url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->get(URL2URI(url), parameters, headers)); } @Override - public Response get(URI uri, int readTimeout) throws IOException, RequestException{ + public Response get(URI uri, int readTimeout) throws IOException, RequestException { return get(uri, readTimeout, null, null); } @Override - public Response get(URL url, int readTimeout) throws IOException, RequestException{ + public Response get(URL url, int readTimeout) throws IOException, RequestException { return execute(()->get(URL2URI(url), readTimeout)); } @Override - public Response get(URI uri, int readTimeout, Map parameters) throws IOException, RequestException{ + public Response get(URI uri, int readTimeout, Map parameters) throws IOException, RequestException { return get(uri, readTimeout, parameters, null); } @Override - public Response get(URL url, int readTimeout, Map parameters) throws IOException, RequestException{ + public Response get(URL url, int readTimeout, Map parameters) throws IOException, RequestException { return execute(()->get(URL2URI(url), readTimeout, parameters)); } @Override - public Response get(URI uri, int readTimeout, List
headers) throws IOException, RequestException{ + public Response get(URI uri, int readTimeout, List
headers) throws IOException, RequestException { return get(uri, readTimeout, null, headers); } @Override - public Response get(URL url, int readTimeout, List
headers) throws IOException, RequestException{ + public Response get(URL url, int readTimeout, List
headers) throws IOException, RequestException { return execute(()->get(URL2URI(url), readTimeout, headers)); } @Override public Response get(URL url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->get(URL2URI(url), readTimeout, parameters, headers)); } @Override - public Response post(URI uri) throws IOException, RequestException{ + public Response post(URI uri) throws IOException, RequestException { return post(uri, null, null, null); } @Override - public Response post(URL url) throws IOException, RequestException{ + public Response post(URL url) throws IOException, RequestException { return execute(()->post(URL2URI(url))); } @Override - public Response post(URI uri, Map parameters) throws IOException, RequestException{ + public Response post(URI uri, Map parameters) throws IOException, RequestException { return post(uri, null, parameters, null); } @Override - public Response post(URL url, Map parameters) throws IOException, RequestException{ + public Response post(URL url, Map parameters) throws IOException, RequestException { return execute(()->post(URL2URI(url), parameters)); } @Override - public Response post(URI uri, List
headers) throws IOException, RequestException{ + public Response post(URI uri, List
headers) throws IOException, RequestException { return post(uri, null, null, headers); } @Override - public Response post(URL url, List
headers) throws IOException, RequestException{ + public Response post(URL url, List
headers) throws IOException, RequestException { return execute(()->post(URL2URI(url), headers)); } @Override public Response post(URI uri, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return post(uri, null, parameters, headers); } @Override public Response post(URL url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->post(URL2URI(url), parameters, headers)); } @Override - public Response post(URI uri, RequestBody data) throws IOException, RequestException{ + public Response post(URI uri, RequestBody data) throws IOException, RequestException { return post(uri, data, null, null); } @Override - public Response post(URL url, RequestBody data) throws IOException, RequestException{ + public Response post(URL url, RequestBody data) throws IOException, RequestException { return execute(()->post(URL2URI(url), data)); } @Override public Response post(URI uri, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return post(uri, data, parameters, null); } @Override public Response post(URL url, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->post(URL2URI(url), data, parameters)); } @Override - public Response post(URI uri, RequestBody data, List
headers) throws IOException, RequestException{ + public Response post(URI uri, RequestBody data, List
headers) throws IOException, RequestException { return post(uri, data, null, headers); } @Override - public Response post(URL url, RequestBody data, List
headers) throws IOException, RequestException{ + public Response post(URL url, RequestBody data, List
headers) throws IOException, RequestException { return execute(()->post(URL2URI(url), data, headers)); } @Override public Response post(URL url, RequestBody data, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->post(URL2URI(url), data, parameters, headers)); } @Override - public Response post(URI uri, int readTimeout) throws IOException, RequestException{ + public Response post(URI uri, int readTimeout) throws IOException, RequestException { return post(uri, readTimeout, null, null, null); } @Override - public Response post(URL url, int readTimeout) throws IOException, RequestException{ + public Response post(URL url, int readTimeout) throws IOException, RequestException { return execute(()->post(URL2URI(url), readTimeout)); } @Override - public Response post(URI uri, int readTimeout, Map parameters) throws IOException, RequestException{ + public Response post(URI uri, int readTimeout, Map parameters) + throws IOException, RequestException { return post(uri, readTimeout, null, parameters, null); } @Override public Response post(URL url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->post(URL2URI(url), readTimeout, parameters)); } @Override - public Response post(URI uri, int readTimeout, List
headers) throws IOException, RequestException{ + public Response post(URI uri, int readTimeout, List
headers) throws IOException, RequestException { return post(uri, readTimeout, null, null, headers); } @Override - public Response post(URL url, int readTimeout, List
headers) throws IOException, RequestException{ + public Response post(URL url, int readTimeout, List
headers) throws IOException, RequestException { return execute(()->post(URL2URI(url), readTimeout, headers)); } @Override public Response post(URI uri, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return post(uri, readTimeout, null, parameters, headers); } @Override public Response post(URL url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->post(URL2URI(url), readTimeout, parameters, headers)); } @Override - public Response post(URI uri, int readTimeout, RequestBody data) throws IOException, RequestException{ + public Response post(URI uri, int readTimeout, RequestBody data) throws IOException, RequestException { return post(uri, readTimeout, data, null, null); } @Override - public Response post(URL url, int readTimeout, RequestBody data) throws IOException, RequestException{ + public Response post(URL url, int readTimeout, RequestBody data) throws IOException, RequestException { return execute(()->post(URL2URI(url), readTimeout, data)); } @Override public Response post(URI uri, int readTimeout, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return post(uri, readTimeout, data, parameters, null); } @Override public Response post(URL url, int readTimeout, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->post(URL2URI(url), readTimeout, data, parameters)); } @Override public Response post(URI uri, int readTimeout, RequestBody data, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return post(uri, readTimeout, data, null, headers); } @Override public Response post(URL url, int readTimeout, RequestBody data, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->post(URL2URI(url), readTimeout, data, headers)); } @Override public Response post(URL url, int readTimeout, RequestBody data, Map parameters, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return execute(()->post(URL2URI(url), readTimeout, data, parameters, headers)); } @Override - public Response put(URI uri) throws IOException, RequestException{ + public Response put(URI uri) throws IOException, RequestException { return put(uri, null, null, null); } @Override - public Response put(URL url) throws IOException, RequestException{ + public Response put(URL url) throws IOException, RequestException { return execute(()->put(URL2URI(url))); } @Override - public Response put(URI uri, Map parameters) throws IOException, RequestException{ + public Response put(URI uri, Map parameters) throws IOException, RequestException { return put(uri, null, parameters, null); } @Override - public Response put(URL url, Map parameters) throws IOException, RequestException{ + public Response put(URL url, Map parameters) throws IOException, RequestException { return execute(()->put(URL2URI(url), parameters)); } @Override - public Response put(URI uri, List
headers) throws IOException, RequestException{ + public Response put(URI uri, List
headers) throws IOException, RequestException { return put(uri, null, null, headers); } @Override - public Response put(URL url, List
headers) throws IOException, RequestException{ + public Response put(URL url, List
headers) throws IOException, RequestException { return execute(()->put(URL2URI(url), headers)); } @Override public Response put(URI uri, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return put(uri, null, parameters, headers); } @Override public Response put(URL url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->put(URL2URI(url), parameters, headers)); } @Override - public Response put(URI uri, RequestBody data) throws IOException, RequestException{ + public Response put(URI uri, RequestBody data) throws IOException, RequestException { return put(uri, data, null, null); } @Override - public Response put(URL url, RequestBody data) throws IOException, RequestException{ + public Response put(URL url, RequestBody data) throws IOException, RequestException { return execute(()->put(URL2URI(url), data)); } @Override public Response put(URI uri, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return put(uri, data, parameters, null); } @Override public Response put(URL url, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->put(URL2URI(url), data, parameters)); } @Override - public Response put(URI uri, RequestBody data, List
headers) throws IOException, RequestException{ + public Response put(URI uri, RequestBody data, List
headers) throws IOException, RequestException { return put(uri, data, null, headers); } @Override - public Response put(URL url, RequestBody data, List
headers) throws IOException, RequestException{ + public Response put(URL url, RequestBody data, List
headers) throws IOException, RequestException { return execute(()->put(URL2URI(url), data, headers)); } @Override public Response put(URL url, RequestBody data, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->put(URL2URI(url), data, parameters, headers)); } @Override - public Response put(URI uri, int readTimeout) throws IOException, RequestException{ + public Response put(URI uri, int readTimeout) throws IOException, RequestException { return put(uri, readTimeout, null, null, null); } @Override - public Response put(URL url, int readTimeout) throws IOException, RequestException{ + public Response put(URL url, int readTimeout) throws IOException, RequestException { return execute(()->put(URL2URI(url), readTimeout)); } @Override - public Response put(URI uri, int readTimeout, Map parameters) throws IOException, RequestException{ + public Response put(URI uri, int readTimeout, Map parameters) throws IOException, RequestException { return put(uri, readTimeout, null, parameters, null); } @Override - public Response put(URL url, int readTimeout, Map parameters) throws IOException, RequestException{ + public Response put(URL url, int readTimeout, Map parameters) throws IOException, RequestException { return execute(()->put(URL2URI(url), readTimeout, parameters)); } @Override - public Response put(URI uri, int readTimeout, List
headers) throws IOException, RequestException{ + public Response put(URI uri, int readTimeout, List
headers) throws IOException, RequestException { return put(uri, readTimeout, null, null, headers); } @Override - public Response put(URL url, int readTimeout, List
headers) throws IOException, RequestException{ + public Response put(URL url, int readTimeout, List
headers) throws IOException, RequestException { return execute(()->put(URL2URI(url), readTimeout, headers)); } @Override public Response put(URI uri, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return put(uri, readTimeout, null, parameters, headers); } @Override public Response put(URL url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->put(URL2URI(url), readTimeout, parameters, headers)); } @Override - public Response put(URI uri, int readTimeout, RequestBody data) throws IOException, RequestException{ + public Response put(URI uri, int readTimeout, RequestBody data) throws IOException, RequestException { return put(uri, readTimeout, data, null, null); } @Override - public Response put(URL url, int readTimeout, RequestBody data) throws IOException, RequestException{ + public Response put(URL url, int readTimeout, RequestBody data) throws IOException, RequestException { return execute(()->put(URL2URI(url), readTimeout, data)); } @Override public Response put(URI uri, int readTimeout, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return put(uri, readTimeout, data, parameters, null); } @Override public Response put(URL url, int readTimeout, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->put(URL2URI(url), readTimeout, data, parameters)); } @Override public Response put(URI uri, int readTimeout, RequestBody data, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return put(uri, readTimeout, data, null, headers); } @Override public Response put(URL url, int readTimeout, RequestBody data, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->put(URL2URI(url), readTimeout, data, headers)); } @Override public Response put(URL url, int readTimeout, RequestBody data, Map parameters, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return execute(()->put(URL2URI(url), readTimeout, data, parameters, headers)); } @Override - public Response patch(URI uri) throws IOException, RequestException{ + public Response patch(URI uri) throws IOException, RequestException { return patch(uri, null, null, null); } @Override - public Response patch(URL url) throws IOException, RequestException{ + public Response patch(URL url) throws IOException, RequestException { return execute(()->patch(URL2URI(url))); } @Override - public Response patch(URI uri, Map parameters) throws IOException, RequestException{ + public Response patch(URI uri, Map parameters) throws IOException, RequestException { return patch(uri, null, parameters, null); } @Override - public Response patch(URL url, Map parameters) throws IOException, RequestException{ + public Response patch(URL url, Map parameters) throws IOException, RequestException { return execute(()->patch(URL2URI(url), parameters)); } @Override - public Response patch(URI uri, List
headers) throws IOException, RequestException{ + public Response patch(URI uri, List
headers) throws IOException, RequestException { return patch(uri, null, null, headers); } @Override - public Response patch(URL url, List
headers) throws IOException, RequestException{ + public Response patch(URL url, List
headers) throws IOException, RequestException { return execute(()->patch(URL2URI(url), headers)); } @Override public Response patch(URI uri, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return patch(uri, null, parameters, headers); } @Override public Response patch(URL url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->patch(URL2URI(url), parameters, headers)); } @Override - public Response patch(URI uri, RequestBody data) throws IOException, RequestException{ + public Response patch(URI uri, RequestBody data) throws IOException, RequestException { return patch(uri, data, null, null); } @Override - public Response patch(URL url, RequestBody data) throws IOException, RequestException{ + public Response patch(URL url, RequestBody data) throws IOException, RequestException { return execute(()->patch(URL2URI(url), data)); } @Override public Response patch(URI uri, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return patch(uri, data, parameters, null); } @Override public Response patch(URL url, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->patch(URL2URI(url), data, parameters)); } @Override - public Response patch(URI uri, RequestBody data, List
headers) throws IOException, RequestException{ + public Response patch(URI uri, RequestBody data, List
headers) throws IOException, RequestException { return patch(uri, data, null, headers); } @Override - public Response patch(URL url, RequestBody data, List
headers) throws IOException, RequestException{ + public Response patch(URL url, RequestBody data, List
headers) throws IOException, RequestException { return execute(()->patch(URL2URI(url), data, headers)); } @Override public Response patch(URL url, RequestBody data, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->patch(URL2URI(url), data, parameters, headers)); } @Override - public Response patch(URI uri, int readTimeout) throws IOException, RequestException{ + public Response patch(URI uri, int readTimeout) throws IOException, RequestException { return patch(uri, readTimeout, null, null, null); } @Override - public Response patch(URL url, int readTimeout) throws IOException, RequestException{ + public Response patch(URL url, int readTimeout) throws IOException, RequestException { return execute(()->patch(URL2URI(url), readTimeout)); } @Override public Response patch(URI uri, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return patch(uri, readTimeout, null, parameters, null); } @Override public Response patch(URL url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->patch(URL2URI(url), readTimeout, parameters)); } @Override - public Response patch(URI uri, int readTimeout, List
headers) throws IOException, RequestException{ + public Response patch(URI uri, int readTimeout, List
headers) throws IOException, RequestException { return patch(uri, readTimeout, null, null, headers); } @Override - public Response patch(URL url, int readTimeout, List
headers) throws IOException, RequestException{ + public Response patch(URL url, int readTimeout, List
headers) throws IOException, RequestException { return execute(()->patch(URL2URI(url), readTimeout, headers)); } @Override public Response patch(URI uri, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return patch(uri, readTimeout, null, parameters, headers); } @Override public Response patch(URL url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->patch(URL2URI(url), readTimeout, parameters, headers)); } @Override - public Response patch(URI uri, int readTimeout, RequestBody data) throws IOException, RequestException{ + public Response patch(URI uri, int readTimeout, RequestBody data) throws IOException, RequestException { return patch(uri, readTimeout, data, null, null); } @Override - public Response patch(URL url, int readTimeout, RequestBody data) throws IOException, RequestException{ + public Response patch(URL url, int readTimeout, RequestBody data) throws IOException, RequestException { return execute(()->patch(URL2URI(url), readTimeout, data)); } @Override public Response patch(URI uri, int readTimeout, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return patch(uri, readTimeout, data, parameters, null); } @Override public Response patch(URL url, int readTimeout, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->patch(URL2URI(url), readTimeout, data, parameters)); } @Override public Response patch(URI uri, int readTimeout, RequestBody data, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return patch(uri, readTimeout, data, null, headers); } @Override public Response patch(URL url, int readTimeout, RequestBody data, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->patch(URL2URI(url), readTimeout, data, headers)); } @Override public Response patch(URL url, int readTimeout, RequestBody data, Map parameters, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return execute(()->patch(URL2URI(url), readTimeout, data, parameters, headers)); } @Override - public Response delete(URI uri) throws IOException, RequestException{ + public Response delete(URI uri) throws IOException, RequestException { return delete(uri, null, null); } @Override - public Response delete(URI uri, Map parameters) throws IOException, RequestException{ + public Response delete(URI uri, Map parameters) throws IOException, RequestException { return delete(uri, parameters, null); } @Override - public Response delete(URL url) throws IOException, RequestException{ + public Response delete(URL url) throws IOException, RequestException { return execute(()->delete(URL2URI(url))); } @Override - public Response delete(URL url, Map parameters) throws IOException, RequestException{ + public Response delete(URL url, Map parameters) throws IOException, RequestException { return execute(()->delete(URL2URI(url), parameters)); } @Override - public Response delete(URI uri, List
headers) throws IOException, RequestException{ + public Response delete(URI uri, List
headers) throws IOException, RequestException { return delete(uri, null, headers); } @Override - public Response delete(URL url, List
headers) throws IOException, RequestException{ + public Response delete(URL url, List
headers) throws IOException, RequestException { return execute(()->delete(URL2URI(url), headers)); } @Override public Response delete(URL url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->delete(URL2URI(url), parameters, headers)); } @Override - public Response delete(URI uri, int readTimeout) throws IOException, RequestException{ + public Response delete(URI uri, int readTimeout) throws IOException, RequestException { return delete(uri, readTimeout, null, null); } @Override public Response delete(URI uri, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return delete(uri, readTimeout, parameters, null); } @Override - public Response delete(URL url, int readTimeout) throws IOException, RequestException{ + public Response delete(URL url, int readTimeout) throws IOException, RequestException { return execute(()->delete(URL2URI(url), readTimeout)); } @Override public Response delete(URL url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->delete(URL2URI(url), readTimeout, parameters)); } @Override - public Response delete(URI uri, int readTimeout, List
headers) throws IOException, RequestException{ + public Response delete(URI uri, int readTimeout, List
headers) throws IOException, RequestException { return delete(uri, readTimeout, null, headers); } @Override - public Response delete(URL url, int readTimeout, List
headers) throws IOException, RequestException{ + public Response delete(URL url, int readTimeout, List
headers) throws IOException, RequestException { return execute(()->delete(URL2URI(url), readTimeout, headers)); } @Override public Response delete(URL url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->delete(URL2URI(url), readTimeout, parameters, headers)); } @Override - public Response connect(URI uri) throws IOException, RequestException{ + public Response connect(URI uri) throws IOException, RequestException { return connect(uri, null, null); } @Override - public Response connect(URL url) throws IOException, RequestException{ + public Response connect(URL url) throws IOException, RequestException { return execute(()->connect(URL2URI(url))); } @Override - public Response connect(URI uri, Map parameters) throws IOException, RequestException{ + public Response connect(URI uri, Map parameters) throws IOException, RequestException { return connect(uri, parameters, null); } @Override - public Response connect(URL url, Map parameters) throws IOException, RequestException{ + public Response connect(URL url, Map parameters) throws IOException, RequestException { return execute(()->connect(URL2URI(url), parameters)); } @Override - public Response connect(URI uri, List
headers) throws IOException, RequestException{ + public Response connect(URI uri, List
headers) throws IOException, RequestException { return connect(uri, null, headers); } @Override - public Response connect(URL url, List
headers) throws IOException, RequestException{ + public Response connect(URL url, List
headers) throws IOException, RequestException { return execute(()->connect(URL2URI(url), headers)); } @Override public Response connect(URL url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->connect(URL2URI(url), parameters, headers)); } @Override - public Response connect(URI uri, int readTimeout) throws IOException, RequestException{ + public Response connect(URI uri, int readTimeout) throws IOException, RequestException { return connect(uri, readTimeout, null, null); } @Override - public Response connect(URL url, int readTimeout) throws IOException, RequestException{ + public Response connect(URL url, int readTimeout) throws IOException, RequestException { return execute(()->connect(URL2URI(url), readTimeout)); } @Override public Response connect(URI uri, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return connect(uri, readTimeout, parameters, null); } @Override public Response connect(URL url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->connect(URL2URI(url), readTimeout, parameters)); } @Override - public Response connect(URI uri, int readTimeout, List
headers) throws IOException, RequestException{ + public Response connect(URI uri, int readTimeout, List
headers) throws IOException, RequestException { return connect(uri, readTimeout, null, headers); } @Override - public Response connect(URL url, int readTimeout, List
headers) throws IOException, RequestException{ + public Response connect(URL url, int readTimeout, List
headers) throws IOException, RequestException { return execute(()->connect(URL2URI(url), readTimeout, headers)); } @Override public Response connect(URL url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->connect(URL2URI(url), readTimeout, parameters, headers)); } @Override - public Response trace(URI uri) throws IOException, RequestException{ + public Response trace(URI uri) throws IOException, RequestException { return trace(uri, null, null); } @Override - public Response trace(URL url) throws IOException, RequestException{ + public Response trace(URL url) throws IOException, RequestException { return execute(()->trace(URL2URI(url))); } @Override - public Response trace(URI uri, Map parameters) throws IOException, RequestException{ + public Response trace(URI uri, Map parameters) throws IOException, RequestException { return trace(uri, parameters, null); } @Override - public Response trace(URL url, Map parameters) throws IOException, RequestException{ + public Response trace(URL url, Map parameters) throws IOException, RequestException { return execute(()->trace(URL2URI(url), parameters)); } @Override - public Response trace(URI uri, List
headers) throws IOException, RequestException{ + public Response trace(URI uri, List
headers) throws IOException, RequestException { return trace(uri, null, headers); } @Override - public Response trace(URL url, List
headers) throws IOException, RequestException{ + public Response trace(URL url, List
headers) throws IOException, RequestException { return execute(()->trace(URL2URI(url), headers)); } @Override public Response trace(URL url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->trace(URL2URI(url), parameters, headers)); } @Override - public Response trace(URI uri, int readTimeout) throws IOException, RequestException{ + public Response trace(URI uri, int readTimeout) throws IOException, RequestException { return trace(uri, readTimeout, null, null); } @Override - public Response trace(URL url, int readTimeout) throws IOException, RequestException{ + public Response trace(URL url, int readTimeout) throws IOException, RequestException { return execute(()->trace(URL2URI(url), readTimeout)); } @Override public Response trace(URI uri, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return trace(uri, readTimeout, parameters, null); } @Override public Response trace(URL url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->trace(URL2URI(url), readTimeout, parameters)); } @Override - public Response trace(URI uri, int readTimeout, List
headers) throws IOException, RequestException{ + public Response trace(URI uri, int readTimeout, List
headers) throws IOException, RequestException { return trace(uri, readTimeout, null, headers); } @Override - public Response trace(URL url, int readTimeout, List
headers) throws IOException, RequestException{ + public Response trace(URL url, int readTimeout, List
headers) throws IOException, RequestException { return execute(()->trace(URL2URI(url), readTimeout, headers)); } @Override public Response trace(URL url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->trace(URL2URI(url), readTimeout, parameters, headers)); } @Override - public Response copy(URI uri) throws IOException, RequestException{ + public Response copy(URI uri) throws IOException, RequestException { return copy(uri, null, null); } @Override - public Response copy(URL url) throws IOException, RequestException{ + public Response copy(URL url) throws IOException, RequestException { return execute(()->copy(URL2URI(url))); } @Override - public Response copy(URI uri, Map parameters) throws IOException, RequestException{ + public Response copy(URI uri, Map parameters) throws IOException, RequestException { return copy(uri, parameters, null); } @Override - public Response copy(URL url, Map parameters) throws IOException, RequestException{ + public Response copy(URL url, Map parameters) throws IOException, RequestException { return execute(()->copy(URL2URI(url), parameters)); } @Override - public Response copy(URI uri, List
headers) throws IOException, RequestException{ + public Response copy(URI uri, List
headers) throws IOException, RequestException { return copy(uri, null, headers); } @Override - public Response copy(URL url, List
headers) throws IOException, RequestException{ + public Response copy(URL url, List
headers) throws IOException, RequestException { return execute(()->copy(URL2URI(url), headers)); } @Override public Response copy(URL url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->copy(URL2URI(url), parameters, headers)); } @Override - public Response copy(URI uri, int readTimeout) throws IOException, RequestException{ + public Response copy(URI uri, int readTimeout) throws IOException, RequestException { return copy(uri, readTimeout, null, null); } @Override - public Response copy(URL url, int readTimeout) throws IOException, RequestException{ + public Response copy(URL url, int readTimeout) throws IOException, RequestException { return execute(()->copy(URL2URI(url), readTimeout)); } @Override - public Response copy(URI uri, int readTimeout, Map parameters) throws IOException, RequestException{ + public Response copy(URI uri, int readTimeout, Map parameters) + throws IOException, RequestException { return copy(uri, readTimeout, parameters, null); } @Override - public Response copy(URL url, int readTimeout, Map parameters) throws IOException, RequestException{ + public Response copy(URL url, int readTimeout, Map parameters) + throws IOException, RequestException { return execute(()->copy(URL2URI(url), readTimeout, parameters)); } @Override - public Response copy(URI uri, int readTimeout, List
headers) throws IOException, RequestException{ + public Response copy(URI uri, int readTimeout, List
headers) throws IOException, RequestException { return copy(uri, readTimeout, null, headers); } @Override - public Response copy(URL url, int readTimeout, List
headers) throws IOException, RequestException{ + public Response copy(URL url, int readTimeout, List
headers) throws IOException, RequestException { return execute(()->copy(URL2URI(url), readTimeout, headers)); } @Override public Response copy(URL url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->copy(URL2URI(url), readTimeout, parameters, headers)); } @Override - public Response move(URI uri) throws IOException, RequestException{ + public Response move(URI uri) throws IOException, RequestException { return move(uri, null, null); } @Override - public Response move(URL url) throws IOException, RequestException{ + public Response move(URL url) throws IOException, RequestException { return execute(()->move(URL2URI(url))); } @Override - public Response move(URI uri, Map parameters) throws IOException, RequestException{ + public Response move(URI uri, Map parameters) throws IOException, RequestException { return move(uri, parameters, null); } @Override - public Response move(URL url, Map parameters) throws IOException, RequestException{ + public Response move(URL url, Map parameters) throws IOException, RequestException { return execute(()->move(URL2URI(url), parameters)); } @Override - public Response move(URI uri, List
headers) throws IOException, RequestException{ + public Response move(URI uri, List
headers) throws IOException, RequestException { return move(uri, null, headers); } @Override - public Response move(URL url, List
headers) throws IOException, RequestException{ + public Response move(URL url, List
headers) throws IOException, RequestException { return execute(()->move(URL2URI(url), headers)); } @Override public Response move(URL url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->move(URL2URI(url), parameters, headers)); } @Override - public Response move(URI uri, int readTimeout) throws IOException, RequestException{ + public Response move(URI uri, int readTimeout) throws IOException, RequestException { return move(uri, readTimeout, null, null); } @Override - public Response move(URL url, int readTimeout) throws IOException, RequestException{ + public Response move(URL url, int readTimeout) throws IOException, RequestException { return execute(()->move(URL2URI(url), readTimeout)); } @Override - public Response move(URI uri, int readTimeout, Map parameters) throws IOException, RequestException{ + public Response move(URI uri, int readTimeout, Map parameters) + throws IOException, RequestException { return move(uri, readTimeout, parameters, null); } @Override - public Response move(URL url, int readTimeout, Map parameters) throws IOException, RequestException{ + public Response move(URL url, int readTimeout, Map parameters) + throws IOException, RequestException { return execute(()->move(URL2URI(url), readTimeout, parameters)); } @Override - public Response move(URI uri, int readTimeout, List
headers) throws IOException, RequestException{ + public Response move(URI uri, int readTimeout, List
headers) throws IOException, RequestException { return move(uri, readTimeout, null, headers); } @Override - public Response move(URL url, int readTimeout, List
headers) throws IOException, RequestException{ + public Response move(URL url, int readTimeout, List
headers) throws IOException, RequestException { return execute(()->move(URL2URI(url), readTimeout, headers)); } @Override public Response move(URL url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->move(URL2URI(url), readTimeout, parameters, headers)); } @Override - public Response head(URI uri) throws IOException, RequestException{ + public Response head(URI uri) throws IOException, RequestException { return head(uri, null, null); } @Override - public Response head(URL url) throws IOException, RequestException{ + public Response head(URL url) throws IOException, RequestException { return execute(()->head(URL2URI(url))); } @Override - public Response head(URI uri, Map parameters) throws IOException, RequestException{ + public Response head(URI uri, Map parameters) throws IOException, RequestException { return head(uri, parameters, null); } @Override - public Response head(URL url, Map parameters) throws IOException, RequestException{ + public Response head(URL url, Map parameters) throws IOException, RequestException { return execute(()->head(URL2URI(url), parameters)); } @Override - public Response head(URI uri, List
headers) throws IOException, RequestException{ + public Response head(URI uri, List
headers) throws IOException, RequestException { return head(uri, null, headers); } @Override - public Response head(URL url, List
headers) throws IOException, RequestException{ + public Response head(URL url, List
headers) throws IOException, RequestException { return execute(()->head(URL2URI(url), headers)); } @Override public Response head(URL url, Map parameters, List
headers) throws IOException, - RequestException{ + RequestException { return execute(()->head(URL2URI(url), parameters, headers)); } @Override - public Response head(URI uri, int readTimeout) throws IOException, RequestException{ + public Response head(URI uri, int readTimeout) throws IOException, RequestException { return head(uri, readTimeout, null, null); } @Override - public Response head(URL url, int readTimeout) throws IOException, RequestException{ + public Response head(URL url, int readTimeout) throws IOException, RequestException { return execute(()->head(URL2URI(url), readTimeout)); } @Override - public Response head(URI uri, int readTimeout, Map parameters) throws IOException, RequestException{ + public Response head(URI uri, int readTimeout, Map parameters) + throws IOException, RequestException { return head(uri, readTimeout, parameters, null); } @Override - public Response head(URL url, int readTimeout, Map parameters) throws IOException, RequestException{ + public Response head(URL url, int readTimeout, Map parameters) + throws IOException, RequestException { return execute(()->head(URL2URI(url), readTimeout, parameters)); } @Override - public Response head(URI uri, int readTimeout, List
headers) throws IOException, RequestException{ + public Response head(URI uri, int readTimeout, List
headers) throws IOException, RequestException { return head(uri, readTimeout, null, headers); } @Override - public Response head(URL url, int readTimeout, List
headers) throws IOException, RequestException{ + public Response head(URL url, int readTimeout, List
headers) throws IOException, RequestException { return execute(()->head(URL2URI(url), readTimeout, headers)); } @Override public Response head(URL url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->head(URL2URI(url), readTimeout, parameters, headers)); } @Override - public Response options(URI uri) throws IOException, RequestException{ + public Response options(URI uri) throws IOException, RequestException { return options(uri, null, null); } @Override - public Response options(URL url) throws IOException, RequestException{ + public Response options(URL url) throws IOException, RequestException { return execute(()->options(URL2URI(url))); } @Override - public Response options(URI uri, Map parameters) throws IOException, RequestException{ + public Response options(URI uri, Map parameters) throws IOException, RequestException { return options(uri, parameters, null); } @Override - public Response options(URL url, Map parameters) throws IOException, RequestException{ + public Response options(URL url, Map parameters) throws IOException, RequestException { return execute(()->options(URL2URI(url), parameters)); } @Override - public Response options(URI uri, List
headers) throws IOException, RequestException{ + public Response options(URI uri, List
headers) throws IOException, RequestException { return options(uri, null, headers); } @Override - public Response options(URL url, List
headers) throws IOException, RequestException{ + public Response options(URL url, List
headers) throws IOException, RequestException { return execute(()->options(URL2URI(url), headers)); } @Override public Response options(URL url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->options(URL2URI(url), parameters, headers)); } @Override - public Response options(URI uri, int readTimeout) throws IOException, RequestException{ + public Response options(URI uri, int readTimeout) throws IOException, RequestException { return options(uri, null, null); } @Override - public Response options(URL url, int readTimeout) throws IOException, RequestException{ + public Response options(URL url, int readTimeout) throws IOException, RequestException { return execute(()->options(URL2URI(url), readTimeout)); } @Override public Response options(URI uri, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return options(uri, readTimeout, parameters, null); } @Override public Response options(URL url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->options(URL2URI(url), readTimeout, parameters)); } @Override - public Response options(URI uri, int readTimeout, List
headers) throws IOException, RequestException{ + public Response options(URI uri, int readTimeout, List
headers) throws IOException, RequestException { return options(uri, readTimeout, null, headers); } @Override - public Response options(URL url, int readTimeout, List
headers) throws IOException, RequestException{ + public Response options(URL url, int readTimeout, List
headers) throws IOException, RequestException { return execute(()->options(URL2URI(url), readTimeout, headers)); } @Override public Response options(URL url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->options(URL2URI(url), readTimeout, parameters, headers)); } @Override - public Response link(URI uri) throws IOException, RequestException{ + public Response link(URI uri) throws IOException, RequestException { return link(uri, null, null); } @Override - public Response link(URL url) throws IOException, RequestException{ + public Response link(URL url) throws IOException, RequestException { return execute(()->link(URL2URI(url))); } @Override - public Response link(URI uri, Map parameters) throws IOException, RequestException{ + public Response link(URI uri, Map parameters) throws IOException, RequestException { return link(uri, parameters, null); } @Override - public Response link(URL url, Map parameters) throws IOException, RequestException{ + public Response link(URL url, Map parameters) throws IOException, RequestException { return execute(()->link(URL2URI(url), parameters)); } @Override - public Response link(URI uri, List
headers) throws IOException, RequestException{ + public Response link(URI uri, List
headers) throws IOException, RequestException { return link(uri, null, headers); } @Override - public Response link(URL url, List
headers) throws IOException, RequestException{ + public Response link(URL url, List
headers) throws IOException, RequestException { return execute(()->link(URL2URI(url), headers)); } @Override public Response link(URL url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->link(URL2URI(url), parameters, headers)); } @Override - public Response link(URI uri, int readTimeout) throws IOException, RequestException{ + public Response link(URI uri, int readTimeout) throws IOException, RequestException { return link(uri, readTimeout, null, null); } @Override - public Response link(URL url, int readTimeout) throws IOException, RequestException{ + public Response link(URL url, int readTimeout) throws IOException, RequestException { return execute(()->link(URL2URI(url), readTimeout)); } @Override - public Response link(URI uri, int readTimeout, Map parameters) throws IOException, RequestException{ + public Response link(URI uri, int readTimeout, Map parameters) + throws IOException, RequestException { return link(uri, readTimeout, parameters, null); } @Override - public Response link(URL url, int readTimeout, Map parameters) throws IOException, RequestException{ + public Response link(URL url, int readTimeout, Map parameters) + throws IOException, RequestException { return execute(()->link(URL2URI(url), readTimeout, parameters)); } @Override - public Response link(URI uri, int readTimeout, List
headers) throws IOException, RequestException{ + public Response link(URI uri, int readTimeout, List
headers) throws IOException, RequestException { return link(uri, readTimeout, null, headers); } @Override - public Response link(URL url, int readTimeout, List
headers) throws IOException, RequestException{ + public Response link(URL url, int readTimeout, List
headers) throws IOException, RequestException { return execute(()->link(URL2URI(url), readTimeout, headers)); } @Override public Response link(URL url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->link(URL2URI(url), readTimeout, parameters, headers)); } @Override - public Response unlink(URI uri) throws IOException, RequestException{ + public Response unlink(URI uri) throws IOException, RequestException { return unlink(uri, null, null); } @Override - public Response unlink(URL url) throws IOException, RequestException{ + public Response unlink(URL url) throws IOException, RequestException { return execute(()->unlink(URL2URI(url))); } @Override - public Response unlink(URI uri, Map parameters) throws IOException, RequestException{ + public Response unlink(URI uri, Map parameters) throws IOException, RequestException { return unlink(uri, parameters, null); } @Override - public Response unlink(URL url, Map parameters) throws IOException, RequestException{ + public Response unlink(URL url, Map parameters) throws IOException, RequestException { return execute(()->unlink(URL2URI(url), parameters)); } @Override - public Response unlink(URI uri, List
headers) throws IOException, RequestException{ + public Response unlink(URI uri, List
headers) throws IOException, RequestException { return unlink(uri, null, headers); } @Override - public Response unlink(URL url, List
headers) throws IOException, RequestException{ + public Response unlink(URL url, List
headers) throws IOException, RequestException { return execute(()->unlink(URL2URI(url), headers)); } @Override public Response unlink(URL url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->unlink(URL2URI(url), parameters, headers)); } @Override - public Response unlink(URI uri, int readTimeout) throws IOException, RequestException{ + public Response unlink(URI uri, int readTimeout) throws IOException, RequestException { return unlink(uri, readTimeout, null, null); } @Override - public Response unlink(URL url, int readTimeout) throws IOException, RequestException{ + public Response unlink(URL url, int readTimeout) throws IOException, RequestException { return execute(()->unlink(URL2URI(url), readTimeout)); } @Override public Response unlink(URI uri, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return unlink(uri, readTimeout, parameters, null); } @Override public Response unlink(URL url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->unlink(URL2URI(url), readTimeout, parameters)); } @Override - public Response unlink(URI uri, int readTimeout, List
headers) throws IOException, RequestException{ + public Response unlink(URI uri, int readTimeout, List
headers) throws IOException, RequestException { return unlink(uri, readTimeout, null, headers); } @Override - public Response unlink(URL url, int readTimeout, List
headers) throws IOException, RequestException{ + public Response unlink(URL url, int readTimeout, List
headers) throws IOException, RequestException { return execute(()->unlink(URL2URI(url), readTimeout, headers)); } @Override public Response unlink(URL url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->unlink(URL2URI(url), readTimeout, parameters, headers)); } @Override - public Response purge(URI uri) throws IOException, RequestException{ + public Response purge(URI uri) throws IOException, RequestException { return purge(uri, null, null); } @Override - public Response purge(URL url) throws IOException, RequestException{ + public Response purge(URL url) throws IOException, RequestException { return execute(()->purge(URL2URI(url))); } @Override - public Response purge(URI uri, Map parameters) throws IOException, RequestException{ + public Response purge(URI uri, Map parameters) throws IOException, RequestException { return purge(uri, parameters, null); } @Override - public Response purge(URL url, Map parameters) throws IOException, RequestException{ + public Response purge(URL url, Map parameters) throws IOException, RequestException { return execute(()->purge(URL2URI(url), parameters)); } @Override - public Response purge(URI uri, List
headers) throws IOException, RequestException{ + public Response purge(URI uri, List
headers) throws IOException, RequestException { return purge(uri, null, headers); } @Override - public Response purge(URL url, List
headers) throws IOException, RequestException{ + public Response purge(URL url, List
headers) throws IOException, RequestException { return execute(()->purge(URL2URI(url), headers)); } @Override public Response purge(URL url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->purge(URL2URI(url), parameters, headers)); } @Override - public Response purge(URI uri, int readTimeout) throws IOException, RequestException{ + public Response purge(URI uri, int readTimeout) throws IOException, RequestException { return purge(uri, null, null); } @Override - public Response purge(URL url, int readTimeout) throws IOException, RequestException{ + public Response purge(URL url, int readTimeout) throws IOException, RequestException { return execute(()->purge(URL2URI(url), readTimeout)); } @Override public Response purge(URI uri, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return purge(uri, readTimeout, parameters, null); } @Override public Response purge(URL url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->purge(URL2URI(url), readTimeout, parameters)); } @Override - public Response purge(URI uri, int readTimeout, List
headers) throws IOException, RequestException{ + public Response purge(URI uri, int readTimeout, List
headers) throws IOException, RequestException { return purge(uri, readTimeout, null, headers); } @Override - public Response purge(URL url, int readTimeout, List
headers) throws IOException, RequestException{ + public Response purge(URL url, int readTimeout, List
headers) throws IOException, RequestException { return execute(()->purge(URL2URI(url), readTimeout, headers)); } @Override public Response purge(URL url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->purge(URL2URI(url), readTimeout, parameters, headers)); } @Override - public Response lock(URI uri) throws IOException, RequestException{ + public Response lock(URI uri) throws IOException, RequestException { return lock(uri, null, null); } @Override - public Response lock(URL url) throws IOException, RequestException{ + public Response lock(URL url) throws IOException, RequestException { return execute(()->lock(URL2URI(url))); } @Override - public Response lock(URI uri, Map parameters) throws IOException, RequestException{ + public Response lock(URI uri, Map parameters) throws IOException, RequestException { return lock(uri, parameters, null); } @Override - public Response lock(URL url, Map parameters) throws IOException, RequestException{ + public Response lock(URL url, Map parameters) throws IOException, RequestException { return execute(()->lock(URL2URI(url), parameters)); } @Override - public Response lock(URI uri, List
headers) throws IOException, RequestException{ + public Response lock(URI uri, List
headers) throws IOException, RequestException { return lock(uri, null, headers); } @Override - public Response lock(URL url, List
headers) throws IOException, RequestException{ + public Response lock(URL url, List
headers) throws IOException, RequestException { return execute(()->lock(URL2URI(url), headers)); } @Override public Response lock(URL url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->lock(URL2URI(url), parameters, headers)); } @Override - public Response lock(URI uri, int readTimeout) throws IOException, RequestException{ + public Response lock(URI uri, int readTimeout) throws IOException, RequestException { return lock(uri, readTimeout, null, null); } @Override - public Response lock(URL url, int readTimeout) throws IOException, RequestException{ + public Response lock(URL url, int readTimeout) throws IOException, RequestException { return execute(()->lock(URL2URI(url), readTimeout)); } @Override - public Response lock(URI uri, int readTimeout, Map parameters) throws IOException, RequestException{ + public Response lock(URI uri, int readTimeout, Map parameters) + throws IOException, RequestException { return lock(uri, readTimeout, parameters, null); } @Override - public Response lock(URL url, int readTimeout, Map parameters) throws IOException, RequestException{ + public Response lock(URL url, int readTimeout, Map parameters) + throws IOException, RequestException { return execute(()->lock(URL2URI(url), readTimeout, parameters)); } @Override - public Response lock(URI uri, int readTimeout, List
headers) throws IOException, RequestException{ + public Response lock(URI uri, int readTimeout, List
headers) throws IOException, RequestException { return lock(uri, readTimeout, null, headers); } @Override - public Response lock(URL url, int readTimeout, List
headers) throws IOException, RequestException{ + public Response lock(URL url, int readTimeout, List
headers) throws IOException, RequestException { return execute(()->lock(URL2URI(url), readTimeout, headers)); } @Override public Response lock(URL url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->lock(URL2URI(url), readTimeout, parameters, headers)); } @Override - public Response unlock(URI uri) throws IOException, RequestException{ + public Response unlock(URI uri) throws IOException, RequestException { return unlock(uri, null, null); } @Override - public Response unlock(URL url) throws IOException, RequestException{ + public Response unlock(URL url) throws IOException, RequestException { return execute(()->unlock(URL2URI(url))); } @Override - public Response unlock(URI uri, Map parameters) throws IOException, RequestException{ + public Response unlock(URI uri, Map parameters) throws IOException, RequestException { return unlock(uri, parameters, null); } @Override - public Response unlock(URL url, Map parameters) throws IOException, RequestException{ + public Response unlock(URL url, Map parameters) throws IOException, RequestException { return execute(()->unlock(URL2URI(url), parameters)); } @Override - public Response unlock(URI uri, List
headers) throws IOException, RequestException{ + public Response unlock(URI uri, List
headers) throws IOException, RequestException { return unlock(uri, null, headers); } @Override - public Response unlock(URL url, List
headers) throws IOException, RequestException{ + public Response unlock(URL url, List
headers) throws IOException, RequestException { return execute(()->unlock(URL2URI(url), headers)); } @Override public Response unlock(URL url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->unlock(URL2URI(url), parameters, headers)); } @Override - public Response unlock(URI uri, int readTimeout) throws IOException, RequestException{ + public Response unlock(URI uri, int readTimeout) throws IOException, RequestException { return unlock(uri, readTimeout, null, null); } @Override - public Response unlock(URL url, int readTimeout) throws IOException, RequestException{ + public Response unlock(URL url, int readTimeout) throws IOException, RequestException { return execute(()->unlock(URL2URI(url), readTimeout)); } @Override public Response unlock(URI uri, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return unlock(uri, readTimeout, parameters, null); } @Override public Response unlock(URL url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->unlock(URL2URI(url), readTimeout, parameters)); } @Override - public Response unlock(URI uri, int readTimeout, List
headers) throws IOException, RequestException{ + public Response unlock(URI uri, int readTimeout, List
headers) throws IOException, RequestException { return unlock(uri, readTimeout, null, headers); } @Override - public Response unlock(URL url, int readTimeout, List
headers) throws IOException, RequestException{ + public Response unlock(URL url, int readTimeout, List
headers) throws IOException, RequestException { return execute(()->unlock(URL2URI(url), readTimeout, headers)); } @Override public Response unlock(URL url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->unlock(URL2URI(url), readTimeout, parameters, headers)); } @Override - public Response propfind(URI uri) throws IOException, RequestException{ + public Response propfind(URI uri) throws IOException, RequestException { return propfind(uri, null, null); } @Override - public Response propfind(URL url) throws IOException, RequestException{ + public Response propfind(URL url) throws IOException, RequestException { return execute(()->propfind(URL2URI(url))); } @Override - public Response propfind(URI uri, Map parameters) throws IOException, RequestException{ + public Response propfind(URI uri, Map parameters) throws IOException, RequestException { return propfind(uri, parameters, null); } @Override - public Response propfind(URL url, Map parameters) throws IOException, RequestException{ + public Response propfind(URL url, Map parameters) throws IOException, RequestException { return execute(()->propfind(URL2URI(url), parameters)); } @Override - public Response propfind(URI uri, List
headers) throws IOException, RequestException{ + public Response propfind(URI uri, List
headers) throws IOException, RequestException { return propfind(uri, null, headers); } @Override - public Response propfind(URL url, List
headers) throws IOException, RequestException{ + public Response propfind(URL url, List
headers) throws IOException, RequestException { return execute(()->propfind(URL2URI(url), headers)); } @Override public Response propfind(URL url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->propfind(URL2URI(url), parameters, headers)); } @Override - public Response propfind(URI uri, int readTimeout) throws IOException, RequestException{ + public Response propfind(URI uri, int readTimeout) throws IOException, RequestException { return propfind(uri, readTimeout, null, null); } @Override - public Response propfind(URL url, int readTimeout) throws IOException, RequestException{ + public Response propfind(URL url, int readTimeout) throws IOException, RequestException { return execute(()->propfind(URL2URI(url), readTimeout)); } @Override public Response propfind(URI uri, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return propfind(uri, readTimeout, parameters, null); } @Override public Response propfind(URL url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->propfind(URL2URI(url), readTimeout, parameters)); } @Override - public Response propfind(URI uri, int readTimeout, List
headers) throws IOException, RequestException{ + public Response propfind(URI uri, int readTimeout, List
headers) throws IOException, RequestException { return propfind(uri, readTimeout, null, headers); } @Override - public Response propfind(URL url, int readTimeout, List
headers) throws IOException, RequestException{ + public Response propfind(URL url, int readTimeout, List
headers) throws IOException, RequestException { return execute(()->propfind(URL2URI(url), readTimeout, headers)); } @Override public Response propfind(URL url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->propfind(URL2URI(url), readTimeout, parameters, headers)); } @Override - public Response proppatch(URI uri) throws IOException, RequestException{ + public Response proppatch(URI uri) throws IOException, RequestException { return proppatch(uri, null, null, null); } @Override - public Response proppatch(URL url) throws IOException, RequestException{ + public Response proppatch(URL url) throws IOException, RequestException { return execute(()->proppatch(URL2URI(url))); } @Override - public Response proppatch(URI uri, Map parameters) throws IOException, RequestException{ + public Response proppatch(URI uri, Map parameters) throws IOException, RequestException { return proppatch(uri, null, parameters, null); } @Override - public Response proppatch(URL url, Map parameters) throws IOException, RequestException{ + public Response proppatch(URL url, Map parameters) throws IOException, RequestException { return execute(()->proppatch(URL2URI(url), parameters)); } @Override - public Response proppatch(URI uri, List
headers) throws IOException, RequestException{ + public Response proppatch(URI uri, List
headers) throws IOException, RequestException { return proppatch(uri, null, null, headers); } @Override - public Response proppatch(URL url, List
headers) throws IOException, RequestException{ + public Response proppatch(URL url, List
headers) throws IOException, RequestException { return execute(()->proppatch(URL2URI(url), headers)); } @Override public Response proppatch(URI uri, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return proppatch(uri, null, parameters, headers); } @Override public Response proppatch(URL url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->proppatch(URL2URI(url), parameters, headers)); } @Override - public Response proppatch(URI uri, RequestBody data) throws IOException, RequestException{ + public Response proppatch(URI uri, RequestBody data) throws IOException, RequestException { return proppatch(uri, data, null, null); } @Override - public Response proppatch(URL url, RequestBody data) throws IOException, RequestException{ + public Response proppatch(URL url, RequestBody data) throws IOException, RequestException { return execute(()->proppatch(URL2URI(url), data)); } @Override public Response proppatch(URI uri, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return proppatch(uri, data, parameters, null); } @Override public Response proppatch(URL url, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->proppatch(URL2URI(url), data, parameters)); } @Override - public Response proppatch(URI uri, RequestBody data, List
headers) throws IOException, RequestException{ + public Response proppatch(URI uri, RequestBody data, List
headers) throws IOException, RequestException { return proppatch(uri, data, null, headers); } @Override - public Response proppatch(URL url, RequestBody data, List
headers) throws IOException, RequestException{ + public Response proppatch(URL url, RequestBody data, List
headers) throws IOException, RequestException { return execute(()->proppatch(URL2URI(url), data, headers)); } @Override public Response proppatch(URL url, RequestBody data, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->proppatch(URL2URI(url), data, parameters, headers)); } @Override - public Response proppatch(URI uri, int readTimeout) throws IOException, RequestException{ + public Response proppatch(URI uri, int readTimeout) throws IOException, RequestException { return proppatch(uri, readTimeout, null, null, null); } @Override - public Response proppatch(URL url, int readTimeout) throws IOException, RequestException{ + public Response proppatch(URL url, int readTimeout) throws IOException, RequestException { return execute(()->proppatch(URL2URI(url), readTimeout)); } @Override public Response proppatch(URI uri, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return proppatch(uri, readTimeout, null, parameters, null); } @Override public Response proppatch(URL url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->proppatch(URL2URI(url), readTimeout, parameters)); } @Override - public Response proppatch(URI uri, int readTimeout, List
headers) throws IOException, RequestException{ + public Response proppatch(URI uri, int readTimeout, List
headers) throws IOException, RequestException { return proppatch(uri, readTimeout, null, null, headers); } @Override - public Response proppatch(URL url, int readTimeout, List
headers) throws IOException, RequestException{ + public Response proppatch(URL url, int readTimeout, List
headers) throws IOException, RequestException { return execute(()->proppatch(URL2URI(url), readTimeout, headers)); } @Override public Response proppatch(URI uri, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return proppatch(uri, readTimeout, null, parameters, headers); } @Override public Response proppatch(URL url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->proppatch(URL2URI(url), readTimeout, parameters, headers)); } @Override - public Response proppatch(URI uri, int readTimeout, RequestBody data) throws IOException, RequestException{ + public Response proppatch(URI uri, int readTimeout, RequestBody data) throws IOException, RequestException { return proppatch(uri, readTimeout, data, null, null); } @Override - public Response proppatch(URL url, int readTimeout, RequestBody data) throws IOException, RequestException{ + public Response proppatch(URL url, int readTimeout, RequestBody data) throws IOException, RequestException { return execute(()->proppatch(URL2URI(url), readTimeout, data)); } @Override public Response proppatch(URI uri, int readTimeout, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return proppatch(uri, readTimeout, data, parameters, null); } @Override public Response proppatch(URL url, int readTimeout, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->proppatch(URL2URI(url), readTimeout, data, parameters)); } @Override public Response proppatch(URI uri, int readTimeout, RequestBody data, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return proppatch(uri, readTimeout, data, null, headers); } @Override public Response proppatch(URL url, int readTimeout, RequestBody data, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->proppatch(URL2URI(url), readTimeout, data, headers)); } @Override public Response proppatch(URL url, int readTimeout, RequestBody data, Map parameters, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return execute(()->proppatch(URL2URI(url), readTimeout, data, parameters, headers)); } @Override - public Response report(URI uri) throws IOException, RequestException{ + public Response report(URI uri) throws IOException, RequestException { return report(uri, null, null, null); } @Override - public Response report(URL url) throws IOException, RequestException{ + public Response report(URL url) throws IOException, RequestException { return execute(()->report(URL2URI(url))); } @Override - public Response report(URI uri, Map parameters) throws IOException, RequestException{ + public Response report(URI uri, Map parameters) throws IOException, RequestException { return report(uri, null, parameters, null); } @Override - public Response report(URL url, Map parameters) throws IOException, RequestException{ + public Response report(URL url, Map parameters) throws IOException, RequestException { return execute(()->report(URL2URI(url), parameters)); } @Override - public Response report(URI uri, List
headers) throws IOException, RequestException{ + public Response report(URI uri, List
headers) throws IOException, RequestException { return report(uri, null, null, headers); } @Override - public Response report(URL url, List
headers) throws IOException, RequestException{ + public Response report(URL url, List
headers) throws IOException, RequestException { return execute(()->report(URL2URI(url), headers)); } @Override public Response report(URI uri, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return report(uri, null, parameters, headers); } @Override public Response report(URL url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->report(URL2URI(url), parameters, headers)); } @Override - public Response report(URI uri, RequestBody data) throws IOException, RequestException{ + public Response report(URI uri, RequestBody data) throws IOException, RequestException { return report(uri, data, null, null); } @Override - public Response report(URL url, RequestBody data) throws IOException, RequestException{ + public Response report(URL url, RequestBody data) throws IOException, RequestException { return execute(()->report(URL2URI(url), data)); } @Override public Response report(URI uri, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return report(uri, data, parameters, null); } @Override public Response report(URL url, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->report(URL2URI(url), data, parameters)); } @Override - public Response report(URI uri, RequestBody data, List
headers) throws IOException, RequestException{ + public Response report(URI uri, RequestBody data, List
headers) throws IOException, RequestException { return report(uri, data, null, headers); } @Override - public Response report(URL url, RequestBody data, List
headers) throws IOException, RequestException{ + public Response report(URL url, RequestBody data, List
headers) throws IOException, RequestException { return execute(()->report(URL2URI(url), data, headers)); } @Override public Response report(URL url, RequestBody data, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->report(URL2URI(url), data, parameters, headers)); } @Override - public Response report(URI uri, int readTimeout) throws IOException, RequestException{ + public Response report(URI uri, int readTimeout) throws IOException, RequestException { return report(uri, readTimeout, null, null, null); } @Override - public Response report(URL url, int readTimeout) throws IOException, RequestException{ + public Response report(URL url, int readTimeout) throws IOException, RequestException { return execute(()->report(URL2URI(url), readTimeout)); } @Override public Response report(URI uri, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return report(uri, readTimeout, null, parameters, null); } @Override public Response report(URL url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->report(URL2URI(url), readTimeout, parameters)); } @Override - public Response report(URI uri, int readTimeout, List
headers) throws IOException, RequestException{ + public Response report(URI uri, int readTimeout, List
headers) throws IOException, RequestException { return report(uri, readTimeout, null, null, headers); } @Override - public Response report(URL url, int readTimeout, List
headers) throws IOException, RequestException{ + public Response report(URL url, int readTimeout, List
headers) throws IOException, RequestException { return execute(()->report(URL2URI(url), readTimeout, headers)); } @Override public Response report(URI uri, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return report(uri, readTimeout, null, parameters, headers); } @Override public Response report(URL url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->report(URL2URI(url), readTimeout, parameters, headers)); } @Override - public Response report(URI uri, int readTimeout, RequestBody data) throws IOException, RequestException{ + public Response report(URI uri, int readTimeout, RequestBody data) throws IOException, RequestException { return report(uri, readTimeout, data, null, null); } @Override - public Response report(URL url, int readTimeout, RequestBody data) throws IOException, RequestException{ + public Response report(URL url, int readTimeout, RequestBody data) throws IOException, RequestException { return execute(()->report(URL2URI(url), readTimeout, data)); } @Override public Response report(URI uri, int readTimeout, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return report(uri, readTimeout, data, parameters, null); } @Override public Response report(URL url, int readTimeout, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->report(URL2URI(url), readTimeout, data, parameters)); } @Override public Response report(URI uri, int readTimeout, RequestBody data, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return report(uri, readTimeout, data, null, headers); } @Override public Response report(URL url, int readTimeout, RequestBody data, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->report(URL2URI(url), readTimeout, data, headers)); } @Override public Response report(URL url, int readTimeout, RequestBody data, Map parameters, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return execute(()->report(URL2URI(url), readTimeout, data, parameters, headers)); } @Override - public Response view(URI uri) throws IOException, RequestException{ + public Response view(URI uri) throws IOException, RequestException { return view(uri, null, null); } @Override - public Response view(URL url) throws IOException, RequestException{ + public Response view(URL url) throws IOException, RequestException { return execute(()->view(URL2URI(url))); } @Override - public Response view(URI uri, Map parameters) throws IOException, RequestException{ + public Response view(URI uri, Map parameters) throws IOException, RequestException { return view(uri, parameters, null); } @Override - public Response view(URL url, Map parameters) throws IOException, RequestException{ + public Response view(URL url, Map parameters) throws IOException, RequestException { return execute(()->view(URL2URI(url), parameters)); } @Override - public Response view(URI uri, List
headers) throws IOException, RequestException{ + public Response view(URI uri, List
headers) throws IOException, RequestException { return view(uri, null, headers); } @Override - public Response view(URL url, List
headers) throws IOException, RequestException{ + public Response view(URL url, List
headers) throws IOException, RequestException { return execute(()->view(URL2URI(url), headers)); } @Override public Response view(URL url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->view(URL2URI(url), parameters, headers)); } @Override - public Response view(URI uri, int readTimeout) throws IOException, RequestException{ + public Response view(URI uri, int readTimeout) throws IOException, RequestException { return view(uri, readTimeout, null, null); } @Override - public Response view(URL url, int readTimeout) throws IOException, RequestException{ + public Response view(URL url, int readTimeout) throws IOException, RequestException { return execute(()->view(URL2URI(url), readTimeout)); } @Override - public Response view(URI uri, int readTimeout, Map parameters) throws IOException, RequestException{ + public Response view(URI uri, int readTimeout, Map parameters) + throws IOException, RequestException { return view(uri, readTimeout, parameters, null); } @Override - public Response view(URL url, int readTimeout, Map parameters) throws IOException, RequestException{ + public Response view(URL url, int readTimeout, Map parameters) + throws IOException, RequestException { return execute(()->view(URL2URI(url), readTimeout, parameters)); } @Override - public Response view(URI uri, int readTimeout, List
headers) throws IOException, RequestException{ + public Response view(URI uri, int readTimeout, List
headers) throws IOException, RequestException { return view(uri, readTimeout, null, headers); } @Override - public Response view(URL url, int readTimeout, List
headers) throws IOException, RequestException{ + public Response view(URL url, int readTimeout, List
headers) throws IOException, RequestException { return execute(()->view(URL2URI(url), readTimeout, headers)); } @Override public Response view(URL url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->view(URL2URI(url), readTimeout, parameters, headers)); } @Override - public Response wrapped(URI uri) throws IOException, RequestException{ + public Response wrapped(URI uri) throws IOException, RequestException { return wrapped(uri, null, null); } @Override - public Response wrapped(URL url) throws IOException, RequestException{ + public Response wrapped(URL url) throws IOException, RequestException { return execute(()->wrapped(URL2URI(url))); } @Override - public Response wrapped(URI uri, Map parameters) throws IOException, RequestException{ + public Response wrapped(URI uri, Map parameters) throws IOException, RequestException { return wrapped(uri, parameters, null); } @Override - public Response wrapped(URL url, Map parameters) throws IOException, RequestException{ + public Response wrapped(URL url, Map parameters) throws IOException, RequestException { return execute(()->wrapped(URL2URI(url), parameters)); } @Override - public Response wrapped(URI uri, List
headers) throws IOException, RequestException{ + public Response wrapped(URI uri, List
headers) throws IOException, RequestException { return wrapped(uri, null, headers); } @Override - public Response wrapped(URL url, List
headers) throws IOException, RequestException{ + public Response wrapped(URL url, List
headers) throws IOException, RequestException { return execute(()->wrapped(URL2URI(url), headers)); } @Override public Response wrapped(URL url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->wrapped(URL2URI(url), parameters, headers)); } @Override - public Response wrapped(URI uri, int readTimeout) throws IOException, RequestException{ + public Response wrapped(URI uri, int readTimeout) throws IOException, RequestException { return wrapped(uri, readTimeout, null, null); } @Override - public Response wrapped(URL url, int readTimeout) throws IOException, RequestException{ + public Response wrapped(URL url, int readTimeout) throws IOException, RequestException { return execute(()->wrapped(URL2URI(url), readTimeout)); } @Override public Response wrapped(URI uri, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return wrapped(uri, readTimeout, parameters, null); } @Override public Response wrapped(URL url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->wrapped(URL2URI(url), readTimeout, parameters)); } @Override - public Response wrapped(URI uri, int readTimeout, List
headers) throws IOException, RequestException{ + public Response wrapped(URI uri, int readTimeout, List
headers) throws IOException, RequestException { return wrapped(uri, readTimeout, null, headers); } @Override - public Response wrapped(URL url, int readTimeout, List
headers) throws IOException, RequestException{ + public Response wrapped(URL url, int readTimeout, List
headers) throws IOException, RequestException { return execute(()->wrapped(URL2URI(url), readTimeout, headers)); } @Override public Response wrapped(URL url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->wrapped(URL2URI(url), readTimeout, parameters, headers)); } @Override - public Response request(URI uri, RequestMethod requestMethod) throws IOException, RequestException{ + public Response request(URI uri, RequestMethod requestMethod) throws IOException, RequestException { return request(uri, requestMethod, null, null, null); } @Override - public Response request(URL url, RequestMethod requestMethod) throws IOException, RequestException{ + public Response request(URL url, RequestMethod requestMethod) throws IOException, RequestException { return execute(()->request(URL2URI(url), requestMethod)); } @Override public Response request(URI uri, RequestMethod requestMethod, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return request(uri, requestMethod, null, parameters, null); } @Override public Response request(URL url, RequestMethod requestMethod, Map parameters) throws - IOException, RequestException{ + IOException, RequestException { return execute(()->request(URL2URI(url), requestMethod, parameters)); } @Override public Response request(URI uri, RequestMethod requestMethod, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return request(uri, requestMethod, null, null, headers); } @Override public Response request(URL url, RequestMethod requestMethod, List
headers) throws IOException, - RequestException{ + RequestException { return execute(()->request(URL2URI(url), requestMethod, headers)); } @Override public Response request(URI uri, RequestMethod requestMethod, Map parameters, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return request(uri, requestMethod, null, parameters, headers); } @Override public Response request(URL url, RequestMethod requestMethod, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->request(URL2URI(url), requestMethod, parameters, headers)); } @Override public Response request(URI uri, RequestMethod requestMethod, RequestBody data) - throws IOException, RequestException{ + throws IOException, RequestException { return request(uri, requestMethod, data, null, null); } @Override public Response request(URL url, RequestMethod requestMethod, RequestBody data) throws IOException, - RequestException{ + RequestException { return execute(()->request(URL2URI(url), requestMethod, data)); } @Override public Response request(URI uri, RequestMethod requestMethod, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return request(uri, requestMethod, data, parameters, null); } @Override public Response request(URL url, RequestMethod requestMethod, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->request(URL2URI(url), requestMethod, data, parameters)); } @Override public Response request(URI uri, RequestMethod requestMethod, RequestBody data, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return request(uri, requestMethod, data, null, headers); } @Override public Response request(URL url, RequestMethod requestMethod, RequestBody data, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->request(URL2URI(url), requestMethod, data, headers)); } @Override public Response request(URI uri, RequestMethod requestMethod, RequestBody data, Map parameters, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { Assert.isNull(requestMethod, "Request method could not be null."); switch(requestMethod){ @@ -2185,96 +2198,98 @@ public Response request(URI uri, RequestMethod requestMethod, RequestBody dat @Override public Response request(URL url, RequestMethod requestMethod, RequestBody data, Map parameters, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return execute(()->request(URL2URI(url), requestMethod, data, parameters, headers)); } @Override - public Response request(URI uri, RequestMethod requestMethod, int readTimeout) throws IOException, RequestException{ + public Response request(URI uri, RequestMethod requestMethod, int readTimeout) + throws IOException, RequestException { return request(uri, requestMethod, readTimeout, null, null, null); } @Override - public Response request(URL url, RequestMethod requestMethod, int readTimeout) throws IOException, RequestException{ + public Response request(URL url, RequestMethod requestMethod, int readTimeout) + throws IOException, RequestException { return execute(()->request(URL2URI(url), requestMethod, readTimeout)); } @Override public Response request(URI uri, RequestMethod requestMethod, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return request(uri, requestMethod, readTimeout, null, parameters, null); } @Override public Response request(URL url, RequestMethod requestMethod, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->request(URL2URI(url), requestMethod, readTimeout, parameters)); } @Override public Response request(URI uri, RequestMethod requestMethod, int readTimeout, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return request(uri, requestMethod, readTimeout, null, null, headers); } @Override public Response request(URL url, RequestMethod requestMethod, int readTimeout, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->request(URL2URI(url), requestMethod, readTimeout, headers)); } @Override public Response request(URI uri, RequestMethod requestMethod, int readTimeout, Map parameters, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return request(uri, requestMethod, readTimeout, null, parameters, headers); } @Override public Response request(URL url, RequestMethod requestMethod, int readTimeout, Map parameters, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return execute(()->request(URL2URI(url), requestMethod, readTimeout, parameters, headers)); } @Override public Response request(URI uri, RequestMethod requestMethod, int readTimeout, RequestBody data) - throws IOException, RequestException{ + throws IOException, RequestException { return request(uri, requestMethod, readTimeout, data, null, null); } @Override public Response request(URL url, RequestMethod requestMethod, int readTimeout, RequestBody data) - throws IOException, RequestException{ + throws IOException, RequestException { return execute(()->request(URL2URI(url), requestMethod, readTimeout, data)); } @Override public Response request(URI uri, RequestMethod requestMethod, int readTimeout, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return request(uri, requestMethod, readTimeout, data, parameters, null); } @Override public Response request(URL url, RequestMethod requestMethod, int readTimeout, RequestBody data, - Map parameters) throws IOException, RequestException{ + Map parameters) throws IOException, RequestException { return execute(()->request(URL2URI(url), requestMethod, readTimeout, data, parameters)); } @Override public Response request(URI uri, RequestMethod requestMethod, int readTimeout, RequestBody data, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return request(uri, requestMethod, readTimeout, data, null, headers); } @Override public Response request(URL url, RequestMethod requestMethod, int readTimeout, RequestBody data, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return execute(()->request(URL2URI(url), requestMethod, readTimeout, data, headers)); } @Override public Response request(URI uri, RequestMethod requestMethod, int readTimeout, RequestBody data, - Map parameters, List
headers) throws IOException, RequestException{ + Map parameters, List
headers) throws IOException, RequestException { Assert.isNull(requestMethod, "Request method could not be null."); switch(requestMethod){ @@ -2325,8 +2340,23 @@ public Response request(URI uri, RequestMethod requestMethod, int readTimeout, R @Override public Response request(URL url, RequestMethod requestMethod, int readTimeout, RequestBody data, - Map parameters, List
headers) throws IOException, RequestException{ + Map parameters, List
headers) throws IOException, RequestException { return execute(()->request(URL2URI(url), requestMethod, readTimeout, data, parameters, headers)); } + protected static T execute(final Execute execute) throws IOException, RequestException { + try{ + return execute.exec(); + }catch(URISyntaxException e){ + throw new IllegalArgumentException(e.getMessage(), e); + } + } + + @FunctionalInterface + protected interface Execute { + + T exec() throws URISyntaxException, IOException, RequestException; + + } + } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/ApacheHttpAsyncClient.java b/buession-httpclient/src/main/java/com/buession/httpclient/ApacheHttpAsyncClient.java index 2d7534f42..32dec4323 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/ApacheHttpAsyncClient.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/ApacheHttpAsyncClient.java @@ -24,6 +24,7 @@ */ package com.buession.httpclient; +import com.buession.core.converter.mapper.PropertyMapper; import com.buession.httpclient.apache.ApacheHttpAsyncClientBuilder; import com.buession.httpclient.apache.ApacheRequest; import com.buession.httpclient.apache.ApacheRequestBuilder; @@ -62,7 +63,7 @@ public class ApacheHttpAsyncClient extends AbstractHttpAsyncClient { /** * 构造函数 */ - public ApacheHttpAsyncClient(){ + public ApacheHttpAsyncClient() { super(); setConnectionManager(new ApacheNioClientConnectionManager()); } @@ -73,7 +74,7 @@ public ApacheHttpAsyncClient(){ * @param connectionManager * 连接管理器 */ - public ApacheHttpAsyncClient(ApacheNioClientConnectionManager connectionManager){ + public ApacheHttpAsyncClient(ApacheNioClientConnectionManager connectionManager) { super(connectionManager); } @@ -83,7 +84,7 @@ public ApacheHttpAsyncClient(ApacheNioClientConnectionManager connectionManager) * @param httpAsyncClient * {@link org.apache.http.nio.client.HttpAsyncClient} 实例 */ - public ApacheHttpAsyncClient(org.apache.http.nio.client.HttpAsyncClient httpAsyncClient){ + public ApacheHttpAsyncClient(org.apache.http.nio.client.HttpAsyncClient httpAsyncClient) { this.httpAsyncClient = httpAsyncClient; } @@ -96,15 +97,15 @@ public ApacheHttpAsyncClient(org.apache.http.nio.client.HttpAsyncClient httpAsyn * 请求配置 */ public ApacheHttpAsyncClient(org.apache.http.nio.client.HttpAsyncClient httpAsyncClient, - RequestConfig requestConfig){ + RequestConfig requestConfig) { this.httpAsyncClient = httpAsyncClient; this.requestConfig = requestConfig; } - public RequestConfig getRequestConfig(){ + public RequestConfig getRequestConfig() { if(requestConfig == null){ + final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); final Configuration configuration = getConnectionManager().getConfiguration(); - final RequestConfig.Builder builder = RequestConfig.custom() .setConnectTimeout(configuration.getConnectTimeout()) .setConnectionRequestTimeout(configuration.getConnectionRequestTimeout()) @@ -113,21 +114,10 @@ public RequestConfig getRequestConfig(){ .setContentCompressionEnabled(configuration.isContentCompressionEnabled()) .setNormalizeUri(configuration.isNormalizeUri()); - if(configuration.isAllowRedirects() != null){ - builder.setRedirectsEnabled(configuration.isAllowRedirects()); - } - - if(configuration.getMaxRedirects() != null){ - builder.setMaxRedirects(configuration.getMaxRedirects()); - } - - if(configuration.isCircularRedirectsAllowed() != null){ - builder.setCircularRedirectsAllowed(configuration.isCircularRedirectsAllowed()); - } - - if(configuration.isRelativeRedirectsAllowed() != null){ - builder.setRelativeRedirectsAllowed(configuration.isRelativeRedirectsAllowed()); - } + propertyMapper.from(configuration.isAllowRedirects()).to(builder::setRedirectsEnabled); + propertyMapper.from(configuration.getMaxRedirects()).to(builder::setMaxRedirects); + propertyMapper.from(configuration.isCircularRedirectsAllowed()).to(builder::setCircularRedirectsAllowed); + propertyMapper.from(configuration.isRelativeRedirectsAllowed()).to(builder::setRelativeRedirectsAllowed); requestConfig = builder.build(); } @@ -135,11 +125,11 @@ public RequestConfig getRequestConfig(){ return requestConfig; } - public void setRequestConfig(RequestConfig requestConfig){ + public void setRequestConfig(RequestConfig requestConfig) { this.requestConfig = requestConfig; } - public org.apache.http.nio.client.HttpAsyncClient getHttpClient(){ + public org.apache.http.nio.client.HttpAsyncClient getHttpClient() { if(httpAsyncClient == null){ final ApacheHttpAsyncClientBuilder httpAsyncClientBuilder = new ApacheHttpAsyncClientBuilder( (ApacheNioClientConnectionManager) getConnectionManager()); @@ -151,278 +141,278 @@ public org.apache.http.nio.client.HttpAsyncClient getHttpClient(){ return httpAsyncClient; } - public void setHttpClient(org.apache.http.nio.client.HttpAsyncClient httpAsyncClient){ + public void setHttpClient(org.apache.http.nio.client.HttpAsyncClient httpAsyncClient) { this.httpAsyncClient = httpAsyncClient; } @Override public void get(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).get(), callback); } @Override public void get(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).get(), readTimeout, callback); } @Override public void post(URI uri, RequestBody data, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).post(data), callback); } @Override public void post(URI uri, int readTimeout, RequestBody data, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).post(data), readTimeout, callback); } @Override public void put(URI uri, RequestBody data, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).put(data), callback); } @Override public void put(URI uri, int readTimeout, RequestBody data, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).put(data), readTimeout, callback); } @Override public void patch(URI uri, RequestBody data, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).patch(data), callback); } @Override public void patch(URI uri, int readTimeout, RequestBody data, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).patch(data), readTimeout, callback); } @Override public void delete(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).delete(), callback); } @Override public void delete(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).delete(), readTimeout, callback); } @Override public void connect(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).connect(), callback); } @Override public void connect(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).connect(), readTimeout, callback); } @Override public void trace(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).trace(), callback); } @Override public void trace(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).trace(), readTimeout, callback); } @Override public void copy(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).copy(), callback); } @Override public void copy(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).copy(), readTimeout, callback); } @Override public void move(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).move(), callback); } @Override public void move(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).move(), readTimeout, callback); } @Override public void head(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).head(), callback); } @Override public void head(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).head(), readTimeout, callback); } @Override public void options(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).options(), callback); } @Override public void options(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).options(), readTimeout, callback); } @Override public void link(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).link(), callback); } @Override public void link(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).link(), readTimeout, callback); } @Override public void unlink(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).unlink(), callback); } @Override public void unlink(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).unlink(), readTimeout, callback); } @Override public void purge(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).purge(), callback); } @Override public void purge(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).purge(), readTimeout, callback); } @Override public void lock(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).lock(), callback); } @Override public void lock(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).lock(), readTimeout, callback); } @Override public void unlock(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).unlock(), callback); } @Override public void unlock(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).unlock(), readTimeout, callback); } @Override public void propfind(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).propfind(), callback); } @Override public void propfind(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).propfind(), readTimeout, callback); } @Override public void proppatch(URI uri, RequestBody data, Map parameters, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).proppatch(data), callback); } @Override public void proppatch(URI uri, int readTimeout, RequestBody data, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).proppatch(data), readTimeout, callback); } @Override public void report(URI uri, RequestBody data, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).report(data), callback); } @Override public void report(URI uri, int readTimeout, RequestBody data, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).report(data), readTimeout, callback); } @Override public void view(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).view(), callback); } @Override public void view(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).view(), readTimeout, callback); } @Override public void wrapped(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).wrapped(), callback); } @Override public void wrapped(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(ApacheRequestBuilder.create(uri, parameters, headers).wrapped(), readTimeout, callback); } protected void doRequest(final ApacheRequestBuilder builder, final Callback callback) throws IOException, - RequestException{ + RequestException { doRequest(builder, getRequestConfig(), callback); } protected void doRequest(final ApacheRequestBuilder builder, final int readTimeout, final Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { final RequestConfig.Builder requestConfigBuilder = RequestConfig.copy(getRequestConfig()) .setSocketTimeout(readTimeout); doRequest(builder, requestConfigBuilder.build(), callback); } protected void doRequest(final ApacheRequestBuilder builder, final RequestConfig requestConfig, - final Callback callback) throws IOException, RequestException{ + final Callback callback) throws IOException, RequestException { final ApacheRequest request = builder.setRequestConfig(requestConfig) .setProtocolVersion(getHttpVersion()).build(); final HttpAsyncRequestProducer httpAsyncRequestProducer = HttpAsyncMethods.create( diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/ApacheHttpClient.java b/buession-httpclient/src/main/java/com/buession/httpclient/ApacheHttpClient.java index 749136e7b..dd16a18d4 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/ApacheHttpClient.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/ApacheHttpClient.java @@ -24,6 +24,7 @@ */ package com.buession.httpclient; +import com.buession.core.converter.mapper.PropertyMapper; import com.buession.httpclient.apache.ApacheHttpClientBuilder; import com.buession.httpclient.apache.ApacheRequest; import com.buession.httpclient.conn.ApacheClientConnectionManager; @@ -67,7 +68,7 @@ public class ApacheHttpClient extends AbstractHttpClient { /** * 构造函数 */ - public ApacheHttpClient(){ + public ApacheHttpClient() { super(); setConnectionManager(new ApacheClientConnectionManager()); } @@ -78,7 +79,7 @@ public ApacheHttpClient(){ * @param connectionManager * 连接管理器 */ - public ApacheHttpClient(ApacheClientConnectionManager connectionManager){ + public ApacheHttpClient(ApacheClientConnectionManager connectionManager) { super(connectionManager); } @@ -88,7 +89,7 @@ public ApacheHttpClient(ApacheClientConnectionManager connectionManager){ * @param httpClient * {@link org.apache.http.client.HttpClient} 实例 */ - public ApacheHttpClient(org.apache.http.client.HttpClient httpClient){ + public ApacheHttpClient(org.apache.http.client.HttpClient httpClient) { this.httpClient = httpClient; } @@ -100,16 +101,16 @@ public ApacheHttpClient(org.apache.http.client.HttpClient httpClient){ * @param requestConfig * 请求配置 */ - public ApacheHttpClient(org.apache.http.client.HttpClient httpClient, RequestConfig requestConfig){ + public ApacheHttpClient(org.apache.http.client.HttpClient httpClient, RequestConfig requestConfig) { this.httpClient = httpClient; this.requestConfig = requestConfig; } - public RequestConfig getRequestConfig(){ + public RequestConfig getRequestConfig() { if(requestConfig == null){ + final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); final Configuration configuration = getConnectionManager().getConfiguration(); - - RequestConfig.Builder builder = RequestConfig.custom() + final RequestConfig.Builder builder = RequestConfig.custom() .setConnectTimeout(configuration.getConnectTimeout()) .setConnectionRequestTimeout(configuration.getConnectionRequestTimeout()) .setSocketTimeout(configuration.getReadTimeout()) @@ -117,21 +118,10 @@ public RequestConfig getRequestConfig(){ .setContentCompressionEnabled(configuration.isContentCompressionEnabled()) .setNormalizeUri(configuration.isNormalizeUri()); - if(configuration.isAllowRedirects() != null){ - builder.setRedirectsEnabled(configuration.isAllowRedirects()); - } - - if(configuration.getMaxRedirects() != null){ - builder.setMaxRedirects(configuration.getMaxRedirects()); - } - - if(configuration.isCircularRedirectsAllowed() != null){ - builder.setCircularRedirectsAllowed(configuration.isCircularRedirectsAllowed()); - } - - if(configuration.isRelativeRedirectsAllowed() != null){ - builder.setRelativeRedirectsAllowed(configuration.isRelativeRedirectsAllowed()); - } + propertyMapper.from(configuration.isAllowRedirects()).to(builder::setRedirectsEnabled); + propertyMapper.from(configuration.getMaxRedirects()).to(builder::setMaxRedirects); + propertyMapper.from(configuration.isCircularRedirectsAllowed()).to(builder::setCircularRedirectsAllowed); + propertyMapper.from(configuration.isRelativeRedirectsAllowed()).to(builder::setRelativeRedirectsAllowed); requestConfig = builder.build(); } @@ -139,11 +129,11 @@ public RequestConfig getRequestConfig(){ return requestConfig; } - public void setRequestConfig(RequestConfig requestConfig){ + public void setRequestConfig(RequestConfig requestConfig) { this.requestConfig = requestConfig; } - public org.apache.http.client.HttpClient getHttpClient(){ + public org.apache.http.client.HttpClient getHttpClient() { if(httpClient == null){ final ApacheHttpClientBuilder httpClientBuilder = new ApacheHttpClientBuilder( (ApacheClientConnectionManager) getConnectionManager()); @@ -155,276 +145,276 @@ public org.apache.http.client.HttpClient getHttpClient(){ return httpClient; } - public void setHttpClient(org.apache.http.client.HttpClient httpClient){ + public void setHttpClient(org.apache.http.client.HttpClient httpClient) { this.httpClient = httpClient; } @Override public Response get(URI uri, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).get()); } @Override public Response get(URI uri, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).get(), readTimeout); } @Override public Response post(URI uri, RequestBody data, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).post(data)); } @Override public Response post(URI uri, int readTimeout, RequestBody data, Map parameters, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).post(data), readTimeout); } @Override public Response put(URI uri, RequestBody data, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).put(data)); } @Override public Response put(URI uri, int readTimeout, RequestBody data, Map parameters, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).put(data), readTimeout); } @Override public Response patch(URI uri, RequestBody data, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).patch(data)); } @Override public Response patch(URI uri, int readTimeout, RequestBody data, Map parameters, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).patch(data), readTimeout); } @Override public Response delete(URI uri, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).delete()); } @Override public Response delete(URI uri, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).delete(), readTimeout); } @Override public Response connect(URI uri, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).connect()); } @Override public Response connect(URI uri, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).connect(), readTimeout); } @Override public Response trace(URI uri, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).trace()); } @Override public Response trace(URI uri, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).trace(), readTimeout); } @Override public Response copy(URI uri, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).copy()); } @Override public Response copy(URI uri, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).copy(), readTimeout); } @Override public Response move(URI uri, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).move()); } @Override public Response move(URI uri, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).move(), readTimeout); } @Override public Response head(URI uri, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).head()); } @Override public Response head(URI uri, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).head(), readTimeout); } @Override public Response options(URI uri, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).options()); } @Override public Response options(URI uri, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).options(), readTimeout); } @Override public Response link(URI uri, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).link()); } @Override public Response link(URI uri, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).link(), readTimeout); } @Override public Response unlink(URI uri, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).unlink()); } @Override public Response unlink(URI uri, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).unlink(), readTimeout); } @Override public Response purge(URI uri, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).purge()); } @Override public Response purge(URI uri, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).purge(), readTimeout); } @Override public Response lock(URI uri, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).lock()); } @Override public Response lock(URI uri, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).lock(), readTimeout); } @Override public Response unlock(URI uri, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).unlock()); } @Override public Response unlock(URI uri, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).unlock(), readTimeout); } @Override public Response propfind(URI uri, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).propfind()); } @Override public Response propfind(URI uri, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).propfind(), readTimeout); } @Override public Response proppatch(URI uri, RequestBody data, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).proppatch(data)); } @Override public Response proppatch(URI uri, int readTimeout, RequestBody data, Map parameters, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).proppatch(data), readTimeout); } @Override public Response report(URI uri, RequestBody data, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).report(data)); } @Override public Response report(URI uri, int readTimeout, RequestBody data, Map parameters, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).report(data), readTimeout); } @Override public Response view(URI uri, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).view()); } @Override public Response view(URI uri, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).view(), readTimeout); } @Override public Response wrapped(URI uri, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).wrapped()); } @Override public Response wrapped(URI uri, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).wrapped(), readTimeout); } protected Response doRequest(final ApacheRequestBuilder builder) - throws IOException, RequestException{ + throws IOException, RequestException { return doRequest(builder, getRequestConfig()); } protected Response doRequest(final ApacheRequestBuilder builder, final int readTimeout) - throws IOException, RequestException{ + throws IOException, RequestException { final RequestConfig.Builder requestConfigBuilder = RequestConfig.copy(getRequestConfig()) .setSocketTimeout(readTimeout); return doRequest(builder, requestConfigBuilder.build()); } protected Response doRequest(final ApacheRequestBuilder builder, final RequestConfig requestConfig) - throws IOException, RequestException{ + throws IOException, RequestException { final ApacheRequest request = builder.setRequestConfig(requestConfig) .setProtocolVersion(getHttpVersion()).build(); final ApacheResponseBuilder apacheResponseBuilder = new ApacheResponseBuilder(); diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/ApacheRequestBodyConverter.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/ApacheRequestBodyConverter.java index 9fdbab147..a4dda51fb 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/ApacheRequestBodyConverter.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/ApacheRequestBodyConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.apache.convert; @@ -30,6 +30,7 @@ /** * @author Yong.Teng */ +@FunctionalInterface public interface ApacheRequestBodyConverter extends RequestBodyConverter { } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/conn/OkHttpClientConnectionManager.java b/buession-httpclient/src/main/java/com/buession/httpclient/conn/OkHttpClientConnectionManager.java index 3d3def370..10dc46833 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/conn/OkHttpClientConnectionManager.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/conn/OkHttpClientConnectionManager.java @@ -37,7 +37,7 @@ public class OkHttpClientConnectionManager extends OkHttpBaseClientConnectionMan /** * 构造函数,创建驱动默认连接管理器 */ - public OkHttpClientConnectionManager(){ + public OkHttpClientConnectionManager() { super(); } @@ -47,7 +47,7 @@ public OkHttpClientConnectionManager(){ * @param configuration * 连接对象 */ - public OkHttpClientConnectionManager(Configuration configuration){ + public OkHttpClientConnectionManager(Configuration configuration) { super(configuration); } @@ -57,7 +57,7 @@ public OkHttpClientConnectionManager(Configuration configuration){ * @param clientConnectionManager * 驱动连接管理器 */ - public OkHttpClientConnectionManager(HttpClientConnectionManager clientConnectionManager){ + public OkHttpClientConnectionManager(HttpClientConnectionManager clientConnectionManager) { super(clientConnectionManager); } @@ -70,7 +70,7 @@ public OkHttpClientConnectionManager(HttpClientConnectionManager clientConnectio * 驱动连接管理器 */ public OkHttpClientConnectionManager(Configuration configuration, - HttpClientConnectionManager clientConnectionManager){ + HttpClientConnectionManager clientConnectionManager) { super(configuration, clientConnectionManager); } @@ -80,13 +80,13 @@ public OkHttpClientConnectionManager(Configuration configuration, * @return 连接管理器 */ @Override - protected HttpClientConnectionManager createDefaultClientConnectionManager(){ + protected HttpClientConnectionManager createDefaultClientConnectionManager() { final HttpClientConnectionManager connectionManager = new HttpClientConnectionManager(); //最大连接数 connectionManager.setMaxConnections(getConfiguration().getMaxConnections()); // 默认的最大并发请求数量 - //connectionManager.setMaxRequests(getConfiguration().getMaxPerRoute()); + connectionManager.setMaxRequests(getConfiguration().getMaxRequests()); // 同时请求相同主机的请求数量最大值 connectionManager.setMaxRequestsPerHost(getConfiguration().getMaxPerRoute()); // 空闲连接存活时长 diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/core/Configuration.java b/buession-httpclient/src/main/java/com/buession/httpclient/core/Configuration.java index b0ed41370..33369daeb 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/core/Configuration.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/core/Configuration.java @@ -57,6 +57,13 @@ public class Configuration { */ private int maxPerRoute = 500; + /** + * 最大并发请求数量 + * + * @since 2.3.2 + */ + private int maxRequests; + /** * 空闲连接存活时长,单位:毫秒 */ @@ -208,6 +215,25 @@ public void setMaxPerRoute(int maxPerRoute) { this.maxPerRoute = maxPerRoute; } + /** + * 返回最大并发请求数量 + * + * @return 最大并发请求数量 + */ + public int getMaxRequests() { + return maxRequests; + } + + /** + * 设置最大并发请求数量 + * + * @param maxRequests + * 最大并发请求数量 + */ + public void setMaxRequests(int maxRequests) { + this.maxRequests = maxRequests; + } + /** * 获取空闲连接存活时长,单位:毫秒 * @@ -520,6 +546,7 @@ public String toString() { .add("retryOnConnectionFailure: " + retryOnConnectionFailure) .add("maxConnections: " + maxConnections) .add("maxPerRoute: " + maxPerRoute) + .add("maxRequests:" + maxRequests) .add("idleConnectionTime: " + idleConnectionTime) .add("connectTimeout: " + connectTimeout) .add("connectionRequestTimeout: " + connectionRequestTimeout) diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/core/ResponseBuilder.java b/buession-httpclient/src/main/java/com/buession/httpclient/core/ResponseBuilder.java index 8d80772fa..f8e7eecf0 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/core/ResponseBuilder.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/core/ResponseBuilder.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.core; @@ -33,6 +33,7 @@ * @author Yong.Teng * @since 2.0.0 */ +@FunctionalInterface public interface ResponseBuilder { /** diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/core/utils/HeadersBuilder.java b/buession-httpclient/src/main/java/com/buession/httpclient/core/utils/HeadersBuilder.java index ae0d39420..7450d9449 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/core/utils/HeadersBuilder.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/core/utils/HeadersBuilder.java @@ -25,17 +25,15 @@ package com.buession.httpclient.core.utils; import com.buession.core.builder.ListBuilder; +import com.buession.core.datetime.TimeZone; import com.buession.core.utils.Assert; import com.buession.httpclient.core.Header; -import java.text.SimpleDateFormat; import java.time.Instant; -import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.List; import java.util.Locale; -import java.util.TimeZone; /** * HTTP 头构建器 @@ -52,7 +50,7 @@ public class HeadersBuilder { /** * 构造函数 */ - public HeadersBuilder(){ + public HeadersBuilder() { } /** @@ -63,7 +61,7 @@ public HeadersBuilder(){ * @param value * HTTP 头值 */ - public HeadersBuilder(final String name, final String value){ + public HeadersBuilder(final String name, final String value) { add(name, value); } @@ -75,7 +73,7 @@ public HeadersBuilder(final String name, final String value){ * @param value * HTTP 头值 */ - public HeadersBuilder(final String name, final short value){ + public HeadersBuilder(final String name, final short value) { add(name, value); } @@ -87,7 +85,7 @@ public HeadersBuilder(final String name, final short value){ * @param value * HTTP 头值 */ - public HeadersBuilder(final String name, final int value){ + public HeadersBuilder(final String name, final int value) { add(name, value); } @@ -99,7 +97,7 @@ public HeadersBuilder(final String name, final int value){ * @param value * HTTP 头值 */ - public HeadersBuilder(final String name, final long value){ + public HeadersBuilder(final String name, final long value) { add(name, value); } @@ -111,7 +109,7 @@ public HeadersBuilder(final String name, final long value){ * @param value * HTTP 头值 */ - public HeadersBuilder(final String name, final Date value){ + public HeadersBuilder(final String name, final Date value) { add(name, value); } @@ -121,7 +119,7 @@ public HeadersBuilder(final String name, final Date value){ * @param headers * HTTP 头 */ - public HeadersBuilder(final List
headers){ + public HeadersBuilder(final List
headers) { add(headers); } @@ -135,7 +133,7 @@ public HeadersBuilder(final List
headers){ * * @return HTTP 头构建器 */ - public HeadersBuilder add(final String name, final String value){ + public HeadersBuilder add(final String name, final String value) { builder.add(new Header(name, value)); return this; } @@ -150,7 +148,7 @@ public HeadersBuilder add(final String name, final String value){ * * @return HTTP 头构建器 */ - public HeadersBuilder add(final String name, final short value){ + public HeadersBuilder add(final String name, final short value) { builder.add(new Header(name, Short.toString(value))); return this; } @@ -165,7 +163,7 @@ public HeadersBuilder add(final String name, final short value){ * * @return HTTP 头构建器 */ - public HeadersBuilder add(final String name, final int value){ + public HeadersBuilder add(final String name, final int value) { builder.add(new Header(name, Integer.toString(value))); return this; } @@ -180,7 +178,7 @@ public HeadersBuilder add(final String name, final int value){ * * @return HTTP 头构建器 */ - public HeadersBuilder add(final String name, final long value){ + public HeadersBuilder add(final String name, final long value) { builder.add(new Header(name, Long.toString(value))); return this; } @@ -195,7 +193,7 @@ public HeadersBuilder add(final String name, final long value){ * * @return HTTP 头构建器 */ - public HeadersBuilder add(final String name, final Date value){ + public HeadersBuilder add(final String name, final Date value) { Assert.isNull(value, "Date cloud not be null."); final Instant instant = Instant.ofEpochMilli(value.getTime()); @@ -210,7 +208,7 @@ public HeadersBuilder add(final String name, final Date value){ * * @return HTTP 头构建器 */ - public HeadersBuilder add(final List
headers){ + public HeadersBuilder add(final List
headers) { if(headers != null){ builder.addAll(headers); } @@ -223,15 +221,14 @@ public HeadersBuilder add(final List
headers){ * * @return HTTP 头 */ - public List
build(){ + public List
build() { return builder.build(); } - protected static DateTimeFormatter createDateTimeFormatter(){ + protected static DateTimeFormatter createDateTimeFormatter() { if(dateTimeFormatter == null){ dateTimeFormatter = DateTimeFormatter.ofPattern("EEE, d MMM yyyy HH:mm:ss GMT", Locale.US); - - dateTimeFormatter.withZone(TimeZone.getTimeZone("GMT").toZoneId()); + dateTimeFormatter.withZone(TimeZone.GMT.toZoneId()); } return dateTimeFormatter; diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/exception/ConnectTimeoutException.java b/buession-httpclient/src/main/java/com/buession/httpclient/exception/ConnectTimeoutException.java index 35d829cf3..37198ef2f 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/exception/ConnectTimeoutException.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/exception/ConnectTimeoutException.java @@ -27,16 +27,20 @@ import java.io.InterruptedIOException; /** + * 连接超时异常 + * * @author Yong.Teng */ public class ConnectTimeoutException extends InterruptedIOException { - public ConnectTimeoutException(){ - super(); - } + private final static long serialVersionUID = 8003120529375299301L; + + public ConnectTimeoutException() { + super(); + } - public ConnectTimeoutException(String message){ - super(message); - } + public ConnectTimeoutException(String message) { + super(message); + } } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/exception/ConnectionPoolTimeoutException.java b/buession-httpclient/src/main/java/com/buession/httpclient/exception/ConnectionPoolTimeoutException.java index 7701e6075..035dc7923 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/exception/ConnectionPoolTimeoutException.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/exception/ConnectionPoolTimeoutException.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2019 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.exception; @@ -27,15 +27,19 @@ import java.io.InterruptedIOException; /** + * 连接池超时异常 + * * @author Yong.Teng */ public class ConnectionPoolTimeoutException extends InterruptedIOException { - public ConnectionPoolTimeoutException(){ - super(); - } + private final static long serialVersionUID = 5297498371637450078L; + + public ConnectionPoolTimeoutException() { + super(); + } - public ConnectionPoolTimeoutException(String message){ - super(message); - } + public ConnectionPoolTimeoutException(String message) { + super(message); + } } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/exception/HttpPageNotFoundException.java b/buession-httpclient/src/main/java/com/buession/httpclient/exception/HttpPageNotFoundException.java index fd3e1edab..88a53a8bb 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/exception/HttpPageNotFoundException.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/exception/HttpPageNotFoundException.java @@ -19,35 +19,40 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2019 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.exception; /** + * 页面不存在异常 + * * @author Yong.Teng */ public class HttpPageNotFoundException extends RequestException { - public HttpPageNotFoundException(){ + private final static long serialVersionUID = 4933289098901209551L; + + public HttpPageNotFoundException() { super(); } - public HttpPageNotFoundException(String url){ + public HttpPageNotFoundException(String url) { super("The requested URL " + url + " was not found on this server."); } - public HttpPageNotFoundException(String url, Throwable cause){ + public HttpPageNotFoundException(String url, Throwable cause) { super("The requested URL " + url + " was not found on this server.", cause); } - public HttpPageNotFoundException(Throwable cause){ + public HttpPageNotFoundException(Throwable cause) { super(cause); } public HttpPageNotFoundException(String url, Throwable cause, boolean enableSuppression, boolean - writableStackTrace){ + writableStackTrace) { super("The requested URL " + url + " was not found on this server.", cause, enableSuppression, writableStackTrace); } + } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/exception/HttpResponseErrorException.java b/buession-httpclient/src/main/java/com/buession/httpclient/exception/HttpResponseErrorException.java index f7b4557eb..230940d2f 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/exception/HttpResponseErrorException.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/exception/HttpResponseErrorException.java @@ -19,12 +19,14 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.exception; /** + * 错误的 HTTP 响应异常 + * * @author Yong.Teng */ public class HttpResponseErrorException extends Exception { @@ -35,23 +37,23 @@ public class HttpResponseErrorException extends Exception { private final String text; - public HttpResponseErrorException(final int code, final String text){ + public HttpResponseErrorException(final int code, final String text) { super("HttpResponseError[code=" + code + ", text='" + text + "']"); this.code = code; this.text = text; } - public int getCode(){ + public int getCode() { return code; } - public String getText(){ + public String getText() { return text; } @Override - public String toString(){ - return "HttpResponseErrorException{" + "code=" + code + ", text='" + text + '\'' + '}'; + public String toString() { + return "Http Response Error: " + "code=" + code + ", text=" + text; } } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/exception/NetworkUnreachableException.java b/buession-httpclient/src/main/java/com/buession/httpclient/exception/NetworkUnreachableException.java index cb30bf021..3f49bc6e4 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/exception/NetworkUnreachableException.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/exception/NetworkUnreachableException.java @@ -19,34 +19,39 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2019 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.exception; /** + * 网络不可用异常 + * * @author Yong.Teng */ public class NetworkUnreachableException extends Exception { - public NetworkUnreachableException(){ + private final static long serialVersionUID = 65978971232751573L; + + public NetworkUnreachableException() { super(); } - public NetworkUnreachableException(String message){ + public NetworkUnreachableException(String message) { super(message); } - public NetworkUnreachableException(String message, Throwable cause){ + public NetworkUnreachableException(String message, Throwable cause) { super(message, cause); } - public NetworkUnreachableException(Throwable cause){ + public NetworkUnreachableException(Throwable cause) { super(cause); } public NetworkUnreachableException(String message, Throwable cause, boolean enableSuppression, boolean - writableStackTrace){ + writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } + } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/exception/ReadTimeoutException.java b/buession-httpclient/src/main/java/com/buession/httpclient/exception/ReadTimeoutException.java index e953a7318..d141e12ec 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/exception/ReadTimeoutException.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/exception/ReadTimeoutException.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2019 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.exception; @@ -27,16 +27,20 @@ import java.net.SocketTimeoutException; /** + * 读取超时异常 + * * @author Yong.Teng */ public class ReadTimeoutException extends SocketTimeoutException { - public ReadTimeoutException(){ - super(); - } + private final static long serialVersionUID = 5090592034901166376L; + + public ReadTimeoutException() { + super(); + } - public ReadTimeoutException(String message){ - super(message); - } + public ReadTimeoutException(String message) { + super(message); + } } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/exception/RequestAbortedException.java b/buession-httpclient/src/main/java/com/buession/httpclient/exception/RequestAbortedException.java index 57b8d7600..7b5b23155 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/exception/RequestAbortedException.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/exception/RequestAbortedException.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2019 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.exception; @@ -27,15 +27,19 @@ import java.io.InterruptedIOException; /** + * 请求终止异常 + * * @author Yong.Teng */ public class RequestAbortedException extends InterruptedIOException { - public RequestAbortedException(){ - super(); - } + private final static long serialVersionUID = 3374619693511102599L; + + public RequestAbortedException() { + super(); + } - public RequestAbortedException(String message){ - super(message); - } + public RequestAbortedException(String message) { + super(message); + } } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/exception/RequestException.java b/buession-httpclient/src/main/java/com/buession/httpclient/exception/RequestException.java index e24ac6f19..aefac834a 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/exception/RequestException.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/exception/RequestException.java @@ -19,33 +19,37 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2019 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.exception; /** + * 请求异常 + * * @author Yong.Teng */ public class RequestException extends Exception { - public RequestException(){ - super(); - } + private final static long serialVersionUID = 7886645715323998024L; + + public RequestException() { + super(); + } - public RequestException(String message){ - super(message); - } + public RequestException(String message) { + super(message); + } - public RequestException(String message, Throwable cause){ - super(message, cause); - } + public RequestException(String message, Throwable cause) { + super(message, cause); + } - public RequestException(Throwable cause){ - super(cause); - } + public RequestException(Throwable cause) { + super(cause); + } - public RequestException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace){ - super(message, cause, enableSuppression, writableStackTrace); - } + public RequestException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/exception/UnsupportedRequestMethodException.java b/buession-httpclient/src/main/java/com/buession/httpclient/exception/UnsupportedRequestMethodException.java index 6d13f8b1f..31d64f347 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/exception/UnsupportedRequestMethodException.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/exception/UnsupportedRequestMethodException.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2019 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.exception; @@ -27,35 +27,40 @@ import com.buession.httpclient.core.RequestMethod; /** + * 不支持的请求异常 + * * @author Yong.Teng */ public class UnsupportedRequestMethodException extends Exception { - public UnsupportedRequestMethodException(){ - } + private final static long serialVersionUID = 2627739916305092393L; + + public UnsupportedRequestMethodException() { + super(); + } - public UnsupportedRequestMethodException(String message){ - super(message); - } + public UnsupportedRequestMethodException(String message) { + super(message); + } - public UnsupportedRequestMethodException(String message, Throwable cause){ - super(message, cause); - } + public UnsupportedRequestMethodException(String message, Throwable cause) { + super(message, cause); + } - public UnsupportedRequestMethodException(RequestMethod method){ - this("Unsupported HTTP Method '" + method + "'."); - } + public UnsupportedRequestMethodException(RequestMethod method) { + this("Unsupported HTTP Method '" + method + "'."); + } - public UnsupportedRequestMethodException(Throwable cause){ - super(cause); - } + public UnsupportedRequestMethodException(Throwable cause) { + super(cause); + } - public UnsupportedRequestMethodException(RequestMethod method, Throwable cause){ - this("Unsupported HTTP Method '" + method + "'.", cause); - } + public UnsupportedRequestMethodException(RequestMethod method, Throwable cause) { + this("Unsupported HTTP Method '" + method + "'.", cause); + } - public UnsupportedRequestMethodException(String message, Throwable cause, boolean enableSuppression, boolean - writableStackTrace){ - super(message, cause, enableSuppression, writableStackTrace); - } + public UnsupportedRequestMethodException(String message, Throwable cause, boolean enableSuppression, boolean + writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/convert/OkHttpRequestBodyConverter.java b/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/convert/OkHttpRequestBodyConverter.java index 50b21d0fd..fca5e46f4 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/convert/OkHttpRequestBodyConverter.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/convert/OkHttpRequestBodyConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2020 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.okhttp.convert; @@ -30,6 +30,7 @@ /** * @author Yong.Teng */ +@FunctionalInterface public interface OkHttpRequestBodyConverter extends RequestBodyConverter { } diff --git a/buession-httpclient/src/main/java/okhttp3/HttpClientBuilder.java b/buession-httpclient/src/main/java/okhttp3/HttpClientBuilder.java index 8b4d0966e..26ba150dc 100644 --- a/buession-httpclient/src/main/java/okhttp3/HttpClientBuilder.java +++ b/buession-httpclient/src/main/java/okhttp3/HttpClientBuilder.java @@ -24,6 +24,8 @@ */ package okhttp3; +import com.buession.core.utils.ObjectUtils; + import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocketFactory; @@ -39,14 +41,14 @@ public class HttpClientBuilder { private HttpClientConnectionManager connectionManager; - protected HttpClientBuilder(){ + protected HttpClientBuilder() { } - public static HttpClientBuilder create(){ + public static HttpClientBuilder create() { return new HttpClientBuilder(); } - public HttpClientBuilder setRetryOnConnectionFailure(Boolean retryOnConnectionFailure){ + public HttpClientBuilder setRetryOnConnectionFailure(Boolean retryOnConnectionFailure) { if(retryOnConnectionFailure != null){ builder.retryOnConnectionFailure(retryOnConnectionFailure); } @@ -54,7 +56,7 @@ public HttpClientBuilder setRetryOnConnectionFailure(Boolean retryOnConnectionFa return this; } - public HttpClientBuilder setConnectTimeout(long connectTimeout){ + public HttpClientBuilder setConnectTimeout(long connectTimeout) { if(connectTimeout > -1){ builder.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS); } @@ -62,7 +64,7 @@ public HttpClientBuilder setConnectTimeout(long connectTimeout){ return this; } - public HttpClientBuilder setReadTimeout(long readTimeout){ + public HttpClientBuilder setReadTimeout(long readTimeout) { if(readTimeout > 0){ builder.readTimeout(readTimeout, TimeUnit.MILLISECONDS); } @@ -70,7 +72,7 @@ public HttpClientBuilder setReadTimeout(long readTimeout){ return this; } - public HttpClientBuilder setWriteTimeout(long writeTimeout){ + public HttpClientBuilder setWriteTimeout(long writeTimeout) { if(writeTimeout > 0){ builder.writeTimeout(writeTimeout, TimeUnit.MILLISECONDS); } @@ -78,7 +80,7 @@ public HttpClientBuilder setWriteTimeout(long writeTimeout){ return this; } - public HttpClientBuilder setFollowRedirects(Boolean followRedirects){ + public HttpClientBuilder setFollowRedirects(Boolean followRedirects) { if(followRedirects != null){ builder.followRedirects(followRedirects); } @@ -86,7 +88,7 @@ public HttpClientBuilder setFollowRedirects(Boolean followRedirects){ return this; } - public HttpClientBuilder setSSLSocketFactory(SSLSocketFactory sslSocketFactory){ + public HttpClientBuilder setSSLSocketFactory(SSLSocketFactory sslSocketFactory) { if(sslSocketFactory != null){ builder.sslSocketFactory(sslSocketFactory); } @@ -94,7 +96,7 @@ public HttpClientBuilder setSSLSocketFactory(SSLSocketFactory sslSocketFactory){ return this; } - public HttpClientBuilder setSSLHostnameVerifier(HostnameVerifier hostnameVerifier){ + public HttpClientBuilder setSSLHostnameVerifier(HostnameVerifier hostnameVerifier) { if(hostnameVerifier != null){ builder.hostnameVerifier(hostnameVerifier); } @@ -102,22 +104,21 @@ public HttpClientBuilder setSSLHostnameVerifier(HostnameVerifier hostnameVerifie return this; } - public HttpClientBuilder setSSLContext(SSLContext sslContext){ + public HttpClientBuilder setSSLContext(SSLContext sslContext) { if(sslContext != null){ } return this; } - public HttpClientBuilder setConnectionManager(HttpClientConnectionManager connectionManager){ + public HttpClientBuilder setConnectionManager(HttpClientConnectionManager connectionManager) { this.connectionManager = connectionManager; return this; } - public OkHttpClient build(){ - if(connectionManager != null){ - builder.connectionPool(connectionManager.getConnectionPool()); - } + public OkHttpClient build() { + ObjectUtils.invokeIfAvailable(connectionManager, + (connectionManager)->builder.connectionPool(connectionManager.getConnectionPool())); OkHttpClient client = builder.build(); diff --git a/buession-httpclient/src/main/java/okhttp3/HttpClientConnectionManager.java b/buession-httpclient/src/main/java/okhttp3/HttpClientConnectionManager.java index 0ad85b8e5..6f3dd1e9e 100644 --- a/buession-httpclient/src/main/java/okhttp3/HttpClientConnectionManager.java +++ b/buession-httpclient/src/main/java/okhttp3/HttpClientConnectionManager.java @@ -24,6 +24,8 @@ */ package okhttp3; +import com.buession.core.utils.ObjectUtils; + import java.io.Closeable; import java.io.IOException; import java.util.concurrent.TimeUnit; @@ -177,9 +179,7 @@ public void setMaxRequestsPerHost(int maxRequestsPerHost) { @Override public void close() throws IOException { - if(connectionPool != null){ - connectionPool.evictAll(); - } + ObjectUtils.invokeIfAvailable(connectionPool, ConnectionPool::evictAll); } } diff --git a/buession-io/pom.xml b/buession-io/pom.xml index 9774fa916..a410368d7 100644 --- a/buession-io/pom.xml +++ b/buession-io/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.1 + 2.3.2 buession-io http://www.buession.com/ diff --git a/buession-io/src/main/java/com/buession/io/file/DefaultMimeTypeDetector.java b/buession-io/src/main/java/com/buession/io/file/DefaultMimeTypeDetector.java index 0f6f59be2..0947b142d 100644 --- a/buession-io/src/main/java/com/buession/io/file/DefaultMimeTypeDetector.java +++ b/buession-io/src/main/java/com/buession/io/file/DefaultMimeTypeDetector.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.io.file; @@ -50,18 +50,18 @@ public class DefaultMimeTypeDetector extends AbstractMimeTypeDetector { /** * 构造函数 */ - public DefaultMimeTypeDetector(){ + public DefaultMimeTypeDetector() { initialize(); } @Override - protected void initialize(){ + protected void initialize() { } @Override - protected MimeType implProbeMimeType(final String path){ - if(Validate.hasText(path) == false){ + protected MimeType implProbeMimeType(final String path) { + if(Validate.isBlank(path)){ return null; } @@ -89,7 +89,7 @@ protected MimeType implProbeMimeType(final String path){ } @Override - protected MimeType implProbeMimeType(final Path path){ + protected MimeType implProbeMimeType(final Path path) { Path fn = path.getFileName(); if(fn == null){ @@ -99,7 +99,7 @@ protected MimeType implProbeMimeType(final Path path){ return implProbeMimeType(fn.toString()); } - private void loadMimetypes(){ + private void loadMimetypes() { if(initialized == false){ synchronized(this){ if(initialized == false){ @@ -150,7 +150,7 @@ private void loadMimetypes(){ } } - private void parseMimeEntry(String entry){ + private void parseMimeEntry(String entry) { entry = entry.trim(); if(entry.isEmpty() || entry.charAt(0) == '#'){ return; diff --git a/buession-io/src/main/java/com/buession/io/file/File.java b/buession-io/src/main/java/com/buession/io/file/File.java index 335ddd63a..dd4c3d413 100644 --- a/buession-io/src/main/java/com/buession/io/file/File.java +++ b/buession-io/src/main/java/com/buession/io/file/File.java @@ -61,7 +61,7 @@ public class File extends java.io.File { * @param child * 子文件 */ - public File(java.io.File parent, String child){ + public File(java.io.File parent, String child) { super(parent, child); } @@ -69,7 +69,7 @@ public File(java.io.File parent, String child){ * @param path * 文件路径 */ - public File(String path){ + public File(String path) { super(path); } @@ -77,7 +77,7 @@ public File(String path){ * @param file * java.io.File */ - public File(java.io.File file){ + public File(java.io.File file) { super(file.getPath()); } @@ -87,7 +87,7 @@ public File(java.io.File file){ * @param child * 子文件 */ - public File(String parent, String child){ + public File(String parent, String child) { super(parent, child); } @@ -95,7 +95,7 @@ public File(String parent, String child){ * @param uri * URI */ - public File(URI uri){ + public File(URI uri) { super(uri); } @@ -106,7 +106,7 @@ public File(URI uri){ * * @since 1.2.0 */ - public MimeType getMimeType(){ + public MimeType getMimeType() { if(mimeType == null){ if(mimeTypeDetector == null){ mimeTypeDetector = new DefaultMimeTypeDetector(); @@ -126,7 +126,7 @@ public MimeType getMimeType(){ * @throws IOException * IO 异常 */ - public byte[] read() throws IOException{ + public byte[] read() throws IOException { int size = 4096; BufferedInputStream bis = new FileBufferedInputStream(this); byte[] tempChars = new byte[size]; @@ -159,7 +159,7 @@ public byte[] read() throws IOException{ * @throws IOException * IO 异常 */ - public void write(final String str) throws IOException{ + public void write(final String str) throws IOException { write(str.getBytes()); } @@ -172,7 +172,7 @@ public void write(final String str) throws IOException{ * @throws IOException * IO 异常 */ - public void write(final char[] chars) throws IOException{ + public void write(final char[] chars) throws IOException { BufferedOutputStream bos = new FileBufferedOutputStream(this); for(char c : chars){ @@ -196,7 +196,7 @@ public void write(final char[] chars) throws IOException{ * @throws IOException * IO 异常 */ - public void write(final byte[] bytes) throws IOException{ + public void write(final byte[] bytes) throws IOException { BufferedOutputStream bos = new FileBufferedOutputStream(this); bos.write(bytes); @@ -216,7 +216,7 @@ public void write(final byte[] bytes) throws IOException{ * IO 异常 * @since 1.2.0 */ - public void write(final String str, boolean append) throws IOException{ + public void write(final String str, boolean append) throws IOException { write(str.getBytes(), append); } @@ -232,7 +232,7 @@ public void write(final String str, boolean append) throws IOException{ * IO 异常 * @since 1.2.0 */ - public void write(final char[] chars, boolean append) throws IOException{ + public void write(final char[] chars, boolean append) throws IOException { BufferedOutputStream bos = new FileBufferedOutputStream(this, append); for(char c : chars){ @@ -259,7 +259,7 @@ public void write(final char[] chars, boolean append) throws IOException{ * IO 异常 * @since 1.2.0 */ - public void write(final byte[] bytes, boolean append) throws IOException{ + public void write(final byte[] bytes, boolean append) throws IOException { BufferedOutputStream bos = new FileBufferedOutputStream(this, append); bos.write(bytes); @@ -278,7 +278,7 @@ public void write(final byte[] bytes, boolean append) throws IOException{ * IO 异常 * @since 1.2.0 */ - public String getMd5() throws IOException{ + public String getMd5() throws IOException { if(exists() == false){ throw new FileNotFoundException(getPath() + " not found."); } @@ -306,7 +306,7 @@ public String getMd5() throws IOException{ * IO 异常 * @since 1.2.0 */ - public String getSha1() throws IOException{ + public String getSha1() throws IOException { if(exists() == false){ throw new FileNotFoundException(getPath() + " not found."); } @@ -332,7 +332,7 @@ public String getSha1() throws IOException{ * IO 异常 * @since 1.2.0 */ - public String getExtension() throws IOException{ + public String getExtension() throws IOException { if(isFile() == false){ throw new IOException(getPath() + " is not a file."); } @@ -352,9 +352,23 @@ public String getExtension() throws IOException{ return extension; } + /** + * 重命名文件 + * + * @param newName + * 新文件名 + * + * @return true / false + * + * @since 2.3.2 + */ + public boolean rename(String newName) { + return super.renameTo(new File(this.getParent() + '/' + newName)); + } + private final static class FileBufferedInputStream extends BufferedInputStream { - public FileBufferedInputStream(java.io.File file) throws FileNotFoundException{ + public FileBufferedInputStream(java.io.File file) throws FileNotFoundException { super(new DataInputStream(new FileInputStream(file))); } @@ -362,11 +376,11 @@ public FileBufferedInputStream(java.io.File file) throws FileNotFoundException{ private final static class FileBufferedOutputStream extends BufferedOutputStream { - public FileBufferedOutputStream(java.io.File file) throws FileNotFoundException{ + public FileBufferedOutputStream(java.io.File file) throws FileNotFoundException { super(new DataOutputStream(new FileOutputStream(file))); } - public FileBufferedOutputStream(java.io.File file, boolean append) throws FileNotFoundException{ + public FileBufferedOutputStream(java.io.File file, boolean append) throws FileNotFoundException { super(new DataOutputStream(new FileOutputStream(file, append))); } diff --git a/buession-io/src/main/java/com/buession/io/json/deserializer/MimeTypeStringDeserializer.java b/buession-io/src/main/java/com/buession/io/json/deserializer/MimeTypeStringDeserializer.java index 8c08f8b63..07f435672 100644 --- a/buession-io/src/main/java/com/buession/io/json/deserializer/MimeTypeStringDeserializer.java +++ b/buession-io/src/main/java/com/buession/io/json/deserializer/MimeTypeStringDeserializer.java @@ -45,17 +45,19 @@ */ public class MimeTypeStringDeserializer extends StdScalarDeserializer implements ContextualDeserializer { - public MimeTypeStringDeserializer(){ + private final static long serialVersionUID = 2065725897002881112L; + + public MimeTypeStringDeserializer() { super(MimeType.class); } - public MimeTypeStringDeserializer(Class clazz){ + public MimeTypeStringDeserializer(Class clazz) { super(clazz); } @Override public MimeType deserialize(JsonParser jsonParser, DeserializationContext context) - throws IOException, JacksonException{ + throws IOException, JacksonException { Object currentValue = jsonParser.getCurrentValue(); Class clazz = currentValue.getClass(); @@ -75,7 +77,7 @@ public MimeType deserialize(JsonParser jsonParser, DeserializationContext contex @SuppressWarnings({"unchecked"}) @Override public JsonDeserializer createContextual(DeserializationContext context, BeanProperty property) - throws JsonMappingException{ + throws JsonMappingException { return new MimeTypeStringDeserializer((Class) property.getType().getRawClass()); } diff --git a/buession-io/src/main/java/com/buession/io/json/serializer/MimeTypeStringSerializer.java b/buession-io/src/main/java/com/buession/io/json/serializer/MimeTypeStringSerializer.java index b7fb2a94c..85f55d3d4 100644 --- a/buession-io/src/main/java/com/buession/io/json/serializer/MimeTypeStringSerializer.java +++ b/buession-io/src/main/java/com/buession/io/json/serializer/MimeTypeStringSerializer.java @@ -44,17 +44,19 @@ */ public class MimeTypeStringSerializer extends StdScalarSerializer implements ContextualSerializer { - public MimeTypeStringSerializer(){ + private final static long serialVersionUID = 6096763941152821826L; + + public MimeTypeStringSerializer() { super(MimeType.class, false); } - public MimeTypeStringSerializer(Class clazz){ + public MimeTypeStringSerializer(Class clazz) { super(clazz, false); } @Override public void serialize(MimeType value, JsonGenerator jsonGenerator, SerializerProvider serializers) - throws IOException{ + throws IOException { if(value == null){ jsonGenerator.writeNull(); }else{ @@ -65,7 +67,7 @@ public void serialize(MimeType value, JsonGenerator jsonGenerator, SerializerPro @SuppressWarnings({"unchecked"}) @Override public JsonSerializer createContextual(SerializerProvider provider, BeanProperty property) - throws JsonMappingException{ + throws JsonMappingException { JsonFormat.Value format = findFormatOverrides(provider, property, handledType()); if(format != null){ diff --git a/buession-jdbc/pom.xml b/buession-jdbc/pom.xml index 84709a542..ad08f6717 100644 --- a/buession-jdbc/pom.xml +++ b/buession-jdbc/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.1 + 2.3.2 buession-jdbc http://www.buession.com/ diff --git a/buession-json/pom.xml b/buession-json/pom.xml index 203dbb3da..19059fe45 100644 --- a/buession-json/pom.xml +++ b/buession-json/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.1 + 2.3.2 buession-json http://www.buession.com/ @@ -59,7 +59,7 @@ org.springframework - * + spring-context diff --git a/buession-json/src/main/java/com/buession/json/package-info.java b/buession-json/src/main/java/com/buession/json/package-info.java new file mode 100644 index 000000000..60845cc0c --- /dev/null +++ b/buession-json/src/main/java/com/buession/json/package-info.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2023 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + * @since 2.3.2 + */ +package com.buession.json; \ No newline at end of file diff --git a/buession-json/src/main/java/com/buession/json/serializer/SensitiveSerializer.java b/buession-json/src/main/java/com/buession/json/serializer/SensitiveSerializer.java index 7cf43288d..ca5f1831b 100644 --- a/buession-json/src/main/java/com/buession/json/serializer/SensitiveSerializer.java +++ b/buession-json/src/main/java/com/buession/json/serializer/SensitiveSerializer.java @@ -40,8 +40,10 @@ import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; import java.io.IOException; +import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; /** * @author Yong.Teng @@ -58,6 +60,9 @@ public class SensitiveSerializer extends StdScalarSerializer imple private String replacement; + private final static Map SENSITIVE_STRATEGY_CACHE = new ConcurrentHashMap<>( + 8); + public SensitiveSerializer() { super(CharSequence.class); } @@ -91,13 +96,21 @@ public JsonSerializer createContextual(SerializerProvider provider, BeanPrope if(Objects.nonNull(annotation) && CharSequence.class.isAssignableFrom(property.getType().getRawClass())){ this.format = annotation.format(); this.replacement = annotation.replacement(); + if(Validate.isEmpty(this.format)){ if(annotation.strategyType() != NoneSensitiveStrategy.class){ - this.strategy = ClassUtils.instantiate(annotation.strategyType()); + this.strategy = + SENSITIVE_STRATEGY_CACHE.computeIfAbsent( + annotation.strategyType().getName() + '@' + replacement, + (key)->ClassUtils.instantiate(annotation.strategyType(), replacement)); }else{ - this.strategy = ClassUtils.instantiate(annotation.strategy().getStrategy()); + this.strategy = + SENSITIVE_STRATEGY_CACHE.computeIfAbsent( + annotation.strategy().getStrategy().getName() + '@' + replacement, + (key)->ClassUtils.instantiate(annotation.strategy().getStrategy(), replacement)); } } + return this; } diff --git a/buession-json/src/main/java/com/buession/json/strategy/AbstractSensitiveStrategy.java b/buession-json/src/main/java/com/buession/json/strategy/AbstractSensitiveStrategy.java new file mode 100644 index 000000000..eef3ad981 --- /dev/null +++ b/buession-json/src/main/java/com/buession/json/strategy/AbstractSensitiveStrategy.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2023 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.json.strategy; + +import com.buession.core.validator.Validate; +import com.buession.json.annotation.Sensitive; + +/** + * 脱敏策略基类 + * + * @author Yong.Teng + * @since 2.3.2 + */ +public abstract class AbstractSensitiveStrategy implements ISensitiveStrategy { + + /** + * 脱敏替换内容 + */ + private final String replacement; + + /** + * 构造函数 + * + * @param replacement + * 脱敏替换内容 + */ + public AbstractSensitiveStrategy(final String replacement) { + this.replacement = Validate.hasText(replacement) ? replacement : Sensitive.DEFAULT_REPLACEMENT; + } + + protected String getReplacement() { + return replacement; + } + +} diff --git a/buession-json/src/main/java/com/buession/json/strategy/AddressSensitiveStrategy.java b/buession-json/src/main/java/com/buession/json/strategy/AddressSensitiveStrategy.java index c491ce8b1..9bcfd93a5 100644 --- a/buession-json/src/main/java/com/buession/json/strategy/AddressSensitiveStrategy.java +++ b/buession-json/src/main/java/com/buession/json/strategy/AddressSensitiveStrategy.java @@ -33,13 +33,23 @@ * @author Yong.Teng * @since 2.3.1 */ -public class AddressSensitiveStrategy implements ISensitiveStrategy { +public class AddressSensitiveStrategy extends AbstractSensitiveStrategy { private final static Pattern PATTERN = Pattern.compile("(\\S{3})\\S{2}(\\S*)\\S{2}"); + /** + * 构造函数 + * + * @param replacement + * 脱敏替换内容 + */ + public AddressSensitiveStrategy(final String replacement) { + super(replacement); + } + @Override public Function getFunction() { - return str->PATTERN.matcher(str).replaceAll("$1****$2****"); + return str->PATTERN.matcher(str).replaceAll("$1" + getReplacement() + "$2" + getReplacement()); } } diff --git a/buession-json/src/main/java/com/buession/json/strategy/EmailSensitiveStrategy.java b/buession-json/src/main/java/com/buession/json/strategy/EmailSensitiveStrategy.java new file mode 100644 index 000000000..ecf7b24fa --- /dev/null +++ b/buession-json/src/main/java/com/buession/json/strategy/EmailSensitiveStrategy.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2023 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.json.strategy; + +import java.util.function.Function; + +/** + * E-mail 脱敏策略 + * + * @author Yong.Teng + * @since 2.3.2 + */ +public class EmailSensitiveStrategy extends AbstractSensitiveStrategy { + + /** + * 构造函数 + * + * @param replacement + * 脱敏替换内容 + */ + public EmailSensitiveStrategy(final String replacement) { + super(replacement); + } + + @Override + public Function getFunction() { + return (str)->{ + int at = str.indexOf('@'); + if(at == -1){ + return str; + } + + return str.substring(0, Math.min(3, at)) + getReplacement() + str.substring(at); + }; + } + +} diff --git a/buession-json/src/main/java/com/buession/json/strategy/IdCardSensitiveStrategy.java b/buession-json/src/main/java/com/buession/json/strategy/IdCardSensitiveStrategy.java index 3c85950a8..dc8a9b589 100644 --- a/buession-json/src/main/java/com/buession/json/strategy/IdCardSensitiveStrategy.java +++ b/buession-json/src/main/java/com/buession/json/strategy/IdCardSensitiveStrategy.java @@ -33,13 +33,23 @@ * @author Yong.Teng * @since 2.3.1 */ -public class IdCardSensitiveStrategy implements ISensitiveStrategy { +public class IdCardSensitiveStrategy extends AbstractSensitiveStrategy { private final static Pattern PATTERN = Pattern.compile("(\\d{5})\\d{10}(\\d{4}[\\dX])"); + /** + * 构造函数 + * + * @param replacement + * 脱敏替换内容 + */ + public IdCardSensitiveStrategy(final String replacement) { + super(replacement); + } + @Override public Function getFunction() { - return str->PATTERN.matcher(str).replaceAll("$1****$2"); + return str->PATTERN.matcher(str).replaceAll("$1" + getReplacement() + "$2"); } } diff --git a/buession-json/src/main/java/com/buession/json/strategy/IpSensitiveStrategy.java b/buession-json/src/main/java/com/buession/json/strategy/IpSensitiveStrategy.java index 32e0bd92c..bb0b8aa0f 100644 --- a/buession-json/src/main/java/com/buession/json/strategy/IpSensitiveStrategy.java +++ b/buession-json/src/main/java/com/buession/json/strategy/IpSensitiveStrategy.java @@ -33,14 +33,24 @@ * @author Yong.Teng * @since 2.3.1 */ -public class IpSensitiveStrategy implements ISensitiveStrategy { +public class IpSensitiveStrategy extends AbstractSensitiveStrategy { private final static Pattern PATTERN = Pattern.compile( "((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})(\\.((2(5[0-5]|[0-4]\\d))|[0-1]?\\d{1,2})){3}"); + /** + * 构造函数 + * + * @param replacement + * 脱敏替换内容 + */ + public IpSensitiveStrategy(final String replacement) { + super(replacement); + } + @Override public Function getFunction() { - return str->PATTERN.matcher(str).replaceAll("$1.****.$2"); + return str->PATTERN.matcher(str).replaceAll("$1." + getReplacement() + ".$2"); } } diff --git a/buession-json/src/main/java/com/buession/json/strategy/MobileSensitiveStrategy.java b/buession-json/src/main/java/com/buession/json/strategy/MobileSensitiveStrategy.java index 4ff9bed93..a07a6e0a7 100644 --- a/buession-json/src/main/java/com/buession/json/strategy/MobileSensitiveStrategy.java +++ b/buession-json/src/main/java/com/buession/json/strategy/MobileSensitiveStrategy.java @@ -33,13 +33,23 @@ * @author Yong.Teng * @since 2.3.1 */ -public class MobileSensitiveStrategy implements ISensitiveStrategy { +public class MobileSensitiveStrategy extends AbstractSensitiveStrategy { private final static Pattern PATTERN = Pattern.compile("(1\\d{2})\\d{4}(\\d{4})"); + /** + * 构造函数 + * + * @param replacement + * 脱敏替换内容 + */ + public MobileSensitiveStrategy(final String replacement) { + super(replacement); + } + @Override public Function getFunction() { - return str->PATTERN.matcher(str).replaceAll("$1****$2"); + return str->PATTERN.matcher(str).replaceAll("$1" + getReplacement() + "$2"); } } diff --git a/buession-json/src/main/java/com/buession/json/strategy/NoneSensitiveStrategy.java b/buession-json/src/main/java/com/buession/json/strategy/NoneSensitiveStrategy.java index f8d064bb4..a8fe976d4 100644 --- a/buession-json/src/main/java/com/buession/json/strategy/NoneSensitiveStrategy.java +++ b/buession-json/src/main/java/com/buession/json/strategy/NoneSensitiveStrategy.java @@ -32,7 +32,17 @@ * @author Yong.Teng * @since 2.3.1 */ -public class NoneSensitiveStrategy implements ISensitiveStrategy { +public class NoneSensitiveStrategy extends AbstractSensitiveStrategy { + + /** + * 构造函数 + * + * @param replacement + * 脱敏替换内容 + */ + public NoneSensitiveStrategy(final String replacement) { + super(replacement); + } @Override public Function getFunction() { diff --git a/buession-json/src/main/java/com/buession/json/strategy/QqSensitiveStrategy.java b/buession-json/src/main/java/com/buession/json/strategy/QqSensitiveStrategy.java index bcf1e9a10..692d30157 100644 --- a/buession-json/src/main/java/com/buession/json/strategy/QqSensitiveStrategy.java +++ b/buession-json/src/main/java/com/buession/json/strategy/QqSensitiveStrategy.java @@ -33,13 +33,23 @@ * @author Yong.Teng * @since 2.3.1 */ -public class QqSensitiveStrategy implements ISensitiveStrategy { +public class QqSensitiveStrategy extends AbstractSensitiveStrategy { private final static Pattern PATTERN = Pattern.compile("(([1-9]\\d{2})\\d{2,5}(\\d{2}))|(([1-9]\\d)\\d{2,3}(\\d))"); + /** + * 构造函数 + * + * @param replacement + * 脱敏替换内容 + */ + public QqSensitiveStrategy(final String replacement) { + super(replacement); + } + @Override public Function getFunction() { - return str->PATTERN.matcher(str).replaceAll("$2$5****$3$6"); + return str->PATTERN.matcher(str).replaceAll("$2$5" + getReplacement() + "$3$6"); } } diff --git a/buession-json/src/main/java/com/buession/json/strategy/SensitiveStrategy.java b/buession-json/src/main/java/com/buession/json/strategy/SensitiveStrategy.java index 1b4f9f7e3..2fe0aaa58 100644 --- a/buession-json/src/main/java/com/buession/json/strategy/SensitiveStrategy.java +++ b/buession-json/src/main/java/com/buession/json/strategy/SensitiveStrategy.java @@ -57,6 +57,11 @@ public enum SensitiveStrategy { */ MOBILE(MobileSensitiveStrategy.class), + /** + * E-mail 脱敏策略 + */ + EMAIL(EmailSensitiveStrategy.class), + /** * QQ 号码脱敏策略 */ diff --git a/buession-json/src/main/java/com/buession/json/strategy/TelSensitiveStrategy.java b/buession-json/src/main/java/com/buession/json/strategy/TelSensitiveStrategy.java index 8cd815bf4..b15d51543 100644 --- a/buession-json/src/main/java/com/buession/json/strategy/TelSensitiveStrategy.java +++ b/buession-json/src/main/java/com/buession/json/strategy/TelSensitiveStrategy.java @@ -33,13 +33,23 @@ * @author Yong.Teng * @since 2.3.1 */ -public class TelSensitiveStrategy implements ISensitiveStrategy { +public class TelSensitiveStrategy extends AbstractSensitiveStrategy { private final static Pattern PATTERN = Pattern.compile("(\\d{3})\\d{2,3}(\\d{2})"); + /** + * 构造函数 + * + * @param replacement + * 脱敏替换内容 + */ + public TelSensitiveStrategy(final String replacement) { + super(replacement); + } + @Override public Function getFunction() { - return str->PATTERN.matcher(str).replaceAll("$1****$2"); + return str->PATTERN.matcher(str).replaceAll("$1" + getReplacement() + "$2"); } } diff --git a/buession-json/src/main/java/com/buession/json/strategy/UsernameSensitiveStrategy.java b/buession-json/src/main/java/com/buession/json/strategy/UsernameSensitiveStrategy.java index 6905f7dcd..af8503033 100644 --- a/buession-json/src/main/java/com/buession/json/strategy/UsernameSensitiveStrategy.java +++ b/buession-json/src/main/java/com/buession/json/strategy/UsernameSensitiveStrategy.java @@ -33,13 +33,23 @@ * @author Yong.Teng * @since 2.3.1 */ -public class UsernameSensitiveStrategy implements ISensitiveStrategy { +public class UsernameSensitiveStrategy extends AbstractSensitiveStrategy { private final static Pattern PATTERN = Pattern.compile("(\\S)\\S(\\S*)"); + /** + * 构造函数 + * + * @param replacement + * 脱敏替换内容 + */ + public UsernameSensitiveStrategy(final String replacement) { + super(replacement); + } + @Override public Function getFunction() { - return str->PATTERN.matcher(str).replaceAll("$1*$2"); + return str->PATTERN.matcher(str).replaceAll("$1" + getReplacement() + "$2"); } } diff --git a/buession-json/src/test/java/com/buession/json/SensitiveTest.java b/buession-json/src/test/java/com/buession/json/SensitiveTest.java index 9dcf4be1a..4ccda71fd 100644 --- a/buession-json/src/test/java/com/buession/json/SensitiveTest.java +++ b/buession-json/src/test/java/com/buession/json/SensitiveTest.java @@ -37,7 +37,7 @@ public class SensitiveTest { @Test - public void sensitive(){ + public void sensitive() { User user = new User(); user.setUsername("github"); @@ -50,6 +50,7 @@ public void sensitive(){ user.setAddress1(new StringBuilder("四川省成都市锦江区东大路")); user.setPrice(100); user.setFormat("eduosi@163.com"); + user.setEmail("ed@163.com"); user.setQq("10000"); user.setQq1("251329"); user.setQq2("2513290410"); @@ -67,7 +68,7 @@ private final static class User { @Sensitive(strategy = SensitiveStrategy.USERNAME) private String username; - @Sensitive(strategy = SensitiveStrategy.ID_CARD) + @Sensitive(strategy = SensitiveStrategy.ID_CARD, replacement = "----") private String idCard; @Sensitive(strategy = SensitiveStrategy.TEL) @@ -94,6 +95,9 @@ private final static class User { @Sensitive(format = "@", replacement = "at") private String format; + @Sensitive(strategy = SensitiveStrategy.EMAIL) + private String email; + @Sensitive(strategy = SensitiveStrategy.QQ) private String qq; @@ -103,107 +107,115 @@ private final static class User { @Sensitive(strategy = SensitiveStrategy.QQ) private String qq2; - public String getUsername(){ + public String getUsername() { return username; } - public void setUsername(String username){ + public void setUsername(String username) { this.username = username; } - public String getIdCard(){ + public String getIdCard() { return idCard; } - public void setIdCard(String idCard){ + public void setIdCard(String idCard) { this.idCard = idCard; } - public String getTel(){ + public String getTel() { return tel; } - public void setTel(String tel){ + public void setTel(String tel) { this.tel = tel; } - public String getMobile(){ + public String getMobile() { return mobile; } - public void setMobile(String mobile){ + public void setMobile(String mobile) { this.mobile = mobile; } - public String getIpV4(){ + public String getIpV4() { return ipV4; } - public void setIpV4(String ipV4){ + public void setIpV4(String ipV4) { this.ipV4 = ipV4; } - public String getIpV6(){ + public String getIpV6() { return ipV6; } - public void setIpV6(String ipV6){ + public void setIpV6(String ipV6) { this.ipV6 = ipV6; } - public String getAddress(){ + public String getAddress() { return address; } - public void setAddress(String address){ + public void setAddress(String address) { this.address = address; } - public StringBuilder getAddress1(){ + public StringBuilder getAddress1() { return address1; } - public void setAddress1(StringBuilder address1){ + public void setAddress1(StringBuilder address1) { this.address1 = address1; } - public Integer getPrice(){ + public Integer getPrice() { return price; } - public void setPrice(Integer price){ + public void setPrice(Integer price) { this.price = price; } - public String getFormat(){ + public String getFormat() { return format; } - public void setFormat(String format){ + public void setFormat(String format) { this.format = format; } - public String getQq(){ + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getQq() { return qq; } - public void setQq(String qq){ + public void setQq(String qq) { this.qq = qq; } - public String getQq1(){ + public String getQq1() { return qq1; } - public void setQq1(String qq1){ + public void setQq1(String qq1) { this.qq1 = qq1; } - public String getQq2(){ + public String getQq2() { return qq2; } - public void setQq2(String qq2){ + public void setQq2(String qq2) { this.qq2 = qq2; } } diff --git a/buession-lang/pom.xml b/buession-lang/pom.xml index 5f9ffa9c5..ee7580011 100644 --- a/buession-lang/pom.xml +++ b/buession-lang/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.1 + 2.3.2 buession-lang http://www.buession.com/ diff --git a/buession-net/pom.xml b/buession-net/pom.xml index e95f9db24..0b754f307 100644 --- a/buession-net/pom.xml +++ b/buession-net/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.1 + 2.3.2 buession-net http://www.buession.com/ diff --git a/buession-net/src/main/java/com/buession/net/UrlParameter.java b/buession-net/src/main/java/com/buession/net/UrlParameter.java index 7a1826c0f..0440359a6 100644 --- a/buession-net/src/main/java/com/buession/net/UrlParameter.java +++ b/buession-net/src/main/java/com/buession/net/UrlParameter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.net; @@ -55,7 +55,7 @@ public class UrlParameter { /** * 构造函数 */ - public UrlParameter(){ + public UrlParameter() { } /** @@ -66,7 +66,7 @@ public UrlParameter(){ * @param value * 参数值 */ - public UrlParameter(@NotNull final String name, final String value){ + public UrlParameter(@NotNull final String name, final String value) { setName(name); setValue(value); } @@ -81,7 +81,7 @@ public UrlParameter(@NotNull final String name, final String value){ * @param encode * 是否编码 */ - public UrlParameter(@NotNull final String name, final String value, final boolean encode){ + public UrlParameter(@NotNull final String name, final String value, final boolean encode) { setName(name); setValue(value, encode); } @@ -92,7 +92,7 @@ public UrlParameter(@NotNull final String name, final String value, final boolea * @param name * 参数名称 */ - public void setName(@NotNull final String name){ + public void setName(@NotNull final String name) { Assert.isBlank(name, "Parameter name cloud not be null or empty."); this.name = name; } @@ -103,7 +103,7 @@ public void setName(@NotNull final String name){ * @param value * 参数值 */ - public void setValue(final String value){ + public void setValue(final String value) { setValue(value, true); } @@ -115,7 +115,7 @@ public void setValue(final String value){ * @param encode * 是否编码 */ - public void setValue(final String value, final boolean encode){ + public void setValue(final String value, final boolean encode) { if(encode){ try{ this.value = value == null ? Constants.EMPTY_STRING : URLEncoder.encode(value, "UTF-8"); @@ -128,17 +128,12 @@ public void setValue(final String value, final boolean encode){ } @Override - public String toString(){ - return Validate.hasText(name) ? name + '=' + value : Constants.EMPTY_STRING; - } - - @Override - public int hashCode(){ + public int hashCode() { return Objects.hash(name, value); } @Override - public boolean equals(Object obj){ + public boolean equals(Object obj) { if(this == obj){ return true; } @@ -151,4 +146,9 @@ public boolean equals(Object obj){ return false; } + @Override + public String toString() { + return Validate.hasText(name) ? name + '=' + value : Constants.EMPTY_STRING; + } + } diff --git a/buession-parent/pom.xml b/buession-parent/pom.xml index 441fb133f..d566b47ca 100644 --- a/buession-parent/pom.xml +++ b/buession-parent/pom.xml @@ -7,13 +7,13 @@ com.buession parent - 2.3.1 + 2.3.2 com.buession buession-parent http://www.buession.com/ Buession Framework Parent - 2.3.1 + 2.3.2 pom diff --git a/buession-redis/pom.xml b/buession-redis/pom.xml index 04e27639d..7ae795ab2 100644 --- a/buession-redis/pom.xml +++ b/buession-redis/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.1 + 2.3.2 buession-redis http://www.buession.com/ diff --git a/buession-redis/src/main/java/com/buession/redis/Converter.java b/buession-redis/src/main/java/com/buession/redis/Converter.java index de6956647..1c0b63e91 100644 --- a/buession-redis/src/main/java/com/buession/redis/Converter.java +++ b/buession-redis/src/main/java/com/buession/redis/Converter.java @@ -54,71 +54,72 @@ abstract class AbstractConverter implements Converter { protected final Serializer serializer; - public AbstractConverter(final RedisAccessor accessor){ + public AbstractConverter(final RedisAccessor accessor) { this.index = RedisAccessor.index; this.serializer = accessor.serializer; } - protected static V addConverter(ThreadLocal index, Function function){ + protected static V addConverter(ThreadLocal index, Function function) { RedisAccessor.getTxConverters().put(index.get(), function); return null; } - protected static V addBinaryConverter(ThreadLocal index, Function function){ + protected static V addBinaryConverter(ThreadLocal index, Function function) { RedisAccessor.getTxConverters().put(index.get(), function); return null; } protected static List addListConverter(ThreadLocal index, - Function, List> function){ + Function, List> function) { RedisAccessor.getTxConverters().put(index.get(), function); return null; } protected static List addListBinaryConverter(ThreadLocal index, - Function, List> function){ + Function, List> function) { RedisAccessor.getTxConverters().put(index.get(), function); return null; } - protected static Set addSetConverter(ThreadLocal index, Function, Set> function){ + protected static Set addSetConverter(ThreadLocal index, + Function, Set> function) { RedisAccessor.getTxConverters().put(index.get(), function); return null; } protected static Set addSetBinaryConverter(ThreadLocal index, - Function, Set> function){ + Function, Set> function) { RedisAccessor.getTxConverters().put(index.get(), function); return null; } protected static Map addMapConverter(ThreadLocal index, - Function, Map> function){ + Function, Map> function) { RedisAccessor.getTxConverters().put(index.get(), function); return null; } protected static Map addMapBinaryConverter(ThreadLocal index, - Function, Map> function){ + Function, Map> function) { RedisAccessor.getTxConverters().put(index.get(), function); return null; } protected static ScanResult addScanResultConverter(ThreadLocal index, - Function, ScanResult> function){ + Function, ScanResult> function) { RedisAccessor.getTxConverters().put(index.get(), function); return null; } - protected boolean isTransaction(final RedisConnection connection){ + protected boolean isTransaction(final RedisConnection connection) { return connection.isTransaction(); } - protected boolean isPipeline(final RedisConnection connection){ + protected boolean isPipeline(final RedisConnection connection) { return connection.isPipeline(); } - protected boolean isTransactionOrPipeline(final RedisConnection connection){ + protected boolean isTransactionOrPipeline(final RedisConnection connection) { return isTransaction(connection) || isPipeline(connection); } @@ -126,7 +127,7 @@ protected boolean isTransactionOrPipeline(final RedisConnection connection){ abstract class AbstractStringConverter extends AbstractConverter { - public AbstractStringConverter(final RedisAccessor accessor){ + public AbstractStringConverter(final RedisAccessor accessor) { super(accessor); } @@ -134,7 +135,7 @@ public AbstractStringConverter(final RedisAccessor accessor){ abstract class AbstractBinaryConverter extends AbstractConverter { - public AbstractBinaryConverter(final RedisAccessor accessor){ + public AbstractBinaryConverter(final RedisAccessor accessor) { super(accessor); } @@ -142,12 +143,12 @@ public AbstractBinaryConverter(final RedisAccessor accessor){ final class SimpleStringConverter extends AbstractStringConverter { - public SimpleStringConverter(final RedisAccessor accessor){ + public SimpleStringConverter(final RedisAccessor accessor) { super(accessor); } @Override - public V convert(final RedisConnection connection, final String value){ + public V convert(final RedisConnection connection, final String value) { if(isTransactionOrPipeline(connection)){ return addConverter(index, serializer::deserialize); }else{ @@ -159,12 +160,12 @@ public V convert(final RedisConnection connection, final String value){ final class SimpleBinaryConverter extends AbstractBinaryConverter { - public SimpleBinaryConverter(final RedisAccessor accessor){ + public SimpleBinaryConverter(final RedisAccessor accessor) { super(accessor); } @Override - public V convert(final RedisConnection connection, final byte[] value){ + public V convert(final RedisConnection connection, final byte[] value) { if(isTransactionOrPipeline(connection)){ return addBinaryConverter(index, serializer::deserializeBytes); }else{ @@ -178,13 +179,13 @@ final class ClazzStringConverter extends AbstractStringConverter { private final Class clazz; - public ClazzStringConverter(final RedisAccessor accessor, final Class clazz){ + public ClazzStringConverter(final RedisAccessor accessor, final Class clazz) { super(accessor); this.clazz = clazz; } @Override - public V convert(final RedisConnection connection, final String value){ + public V convert(final RedisConnection connection, final String value) { if(isTransactionOrPipeline(connection)){ return addConverter(index, (val)->serializer.deserialize(val, clazz)); }else{ @@ -198,13 +199,13 @@ final class ClazzBinaryConverter extends AbstractBinaryConverter { private final Class clazz; - public ClazzBinaryConverter(final RedisAccessor accessor, final Class clazz){ + public ClazzBinaryConverter(final RedisAccessor accessor, final Class clazz) { super(accessor); this.clazz = clazz; } @Override - public V convert(final RedisConnection connection, final byte[] value){ + public V convert(final RedisConnection connection, final byte[] value) { if(isTransactionOrPipeline(connection)){ return addBinaryConverter(index, (val)->serializer.deserializeBytes(val, clazz)); }else{ @@ -218,13 +219,13 @@ final class TypeStringConverter extends AbstractStringConverter { private final TypeReference typeReference; - public TypeStringConverter(final RedisAccessor accessor, final TypeReference typeReference){ + public TypeStringConverter(final RedisAccessor accessor, final TypeReference typeReference) { super(accessor); this.typeReference = typeReference; } @Override - public V convert(final RedisConnection connection, final String value){ + public V convert(final RedisConnection connection, final String value) { if(isTransactionOrPipeline(connection)){ return addConverter(index, (val)->serializer.deserialize(val, typeReference)); }else{ @@ -238,13 +239,13 @@ final class TypeBinaryConverter extends AbstractBinaryConverter { private final TypeReference typeReference; - public TypeBinaryConverter(final RedisAccessor accessor, final TypeReference typeReference){ + public TypeBinaryConverter(final RedisAccessor accessor, final TypeReference typeReference) { super(accessor); this.typeReference = typeReference; } @Override - public V convert(final RedisConnection connection, final byte[] value){ + public V convert(final RedisConnection connection, final byte[] value) { if(isTransactionOrPipeline(connection)){ return addBinaryConverter(index, (val)->serializer.deserializeBytes(val, typeReference)); }else{ @@ -256,7 +257,7 @@ public V convert(final RedisConnection connection, final byte[] value){ abstract class AbstractListStringConverter extends AbstractConverter, List> { - public AbstractListStringConverter(final RedisAccessor accessor){ + public AbstractListStringConverter(final RedisAccessor accessor) { super(accessor); } @@ -264,7 +265,7 @@ public AbstractListStringConverter(final RedisAccessor accessor){ abstract class AbstractListBinaryConverter extends AbstractConverter, List> { - public AbstractListBinaryConverter(final RedisAccessor accessor){ + public AbstractListBinaryConverter(final RedisAccessor accessor) { super(accessor); } @@ -272,12 +273,12 @@ public AbstractListBinaryConverter(final RedisAccessor accessor){ final class SimpleListStringConverter extends AbstractListStringConverter { - public SimpleListStringConverter(final RedisAccessor accessor){ + public SimpleListStringConverter(final RedisAccessor accessor) { super(accessor); } @Override - public List convert(final RedisConnection connection, final List value){ + public List convert(final RedisConnection connection, final List value) { final Function, List> function = (data)->{ if(data != null){ final List result = new ArrayList<>(data.size()); @@ -303,12 +304,12 @@ public List convert(final RedisConnection connection, final List valu final class SimpleListBinaryConverter extends AbstractListBinaryConverter { - public SimpleListBinaryConverter(final RedisAccessor accessor){ + public SimpleListBinaryConverter(final RedisAccessor accessor) { super(accessor); } @Override - public List convert(final RedisConnection connection, final List value){ + public List convert(final RedisConnection connection, final List value) { final Function, List> function = (data)->{ if(data != null){ final List result = new ArrayList<>(data.size()); @@ -336,13 +337,13 @@ final class ClazzListStringConverter extends AbstractListStringConverter { private final Class clazz; - public ClazzListStringConverter(final RedisAccessor accessor, final Class clazz){ + public ClazzListStringConverter(final RedisAccessor accessor, final Class clazz) { super(accessor); this.clazz = clazz; } @Override - public List convert(final RedisConnection connection, final List value){ + public List convert(final RedisConnection connection, final List value) { final Function, List> function = (data)->data == null ? null : data.stream().map((val)->serializer.deserialize(val, clazz)).collect(Collectors.toList()); @@ -359,13 +360,13 @@ final class ClazzListBinaryConverter extends AbstractListBinaryConverter { private final Class clazz; - public ClazzListBinaryConverter(final RedisAccessor accessor, final Class clazz){ + public ClazzListBinaryConverter(final RedisAccessor accessor, final Class clazz) { super(accessor); this.clazz = clazz; } @Override - public List convert(final RedisConnection connection, final List value){ + public List convert(final RedisConnection connection, final List value) { final Function, List> function = (data)-> data == null ? null : data.stream().map((val)->serializer.deserializeBytes(val, clazz)) .collect(Collectors.toList()); @@ -383,13 +384,13 @@ final class TypeListStringConverter extends AbstractListStringConverter { private final TypeReference typeReference; - public TypeListStringConverter(final RedisAccessor accessor, final TypeReference typeReference){ + public TypeListStringConverter(final RedisAccessor accessor, final TypeReference typeReference) { super(accessor); this.typeReference = typeReference; } @Override - public List convert(final RedisConnection connection, final List value){ + public List convert(final RedisConnection connection, final List value) { final Function, List> function = (data)->data == null ? null : data.stream().map((val)->serializer.deserialize(val, typeReference)).collect(Collectors.toList()); @@ -406,13 +407,13 @@ final class TypeListBinaryConverter extends AbstractListBinaryConverter { private final TypeReference typeReference; - public TypeListBinaryConverter(final RedisAccessor accessor, final TypeReference typeReference){ + public TypeListBinaryConverter(final RedisAccessor accessor, final TypeReference typeReference) { super(accessor); this.typeReference = typeReference; } @Override - public List convert(final RedisConnection connection, final List value){ + public List convert(final RedisConnection connection, final List value) { final Function, List> function = (data)->data == null ? null : data.stream().map((val)->serializer.deserializeBytes(val, typeReference)) .collect(Collectors.toList()); @@ -428,7 +429,7 @@ public List convert(final RedisConnection connection, final List valu abstract class AbstractSetStringConverter extends AbstractConverter, Set> { - public AbstractSetStringConverter(final RedisAccessor accessor){ + public AbstractSetStringConverter(final RedisAccessor accessor) { super(accessor); } @@ -436,7 +437,7 @@ public AbstractSetStringConverter(final RedisAccessor accessor){ abstract class AbstractSetBinaryConverter extends AbstractConverter, Set> { - public AbstractSetBinaryConverter(final RedisAccessor accessor){ + public AbstractSetBinaryConverter(final RedisAccessor accessor) { super(accessor); } @@ -444,12 +445,12 @@ public AbstractSetBinaryConverter(final RedisAccessor accessor){ final class SimpleSetStringConverter extends AbstractSetStringConverter { - public SimpleSetStringConverter(final RedisAccessor accessor){ + public SimpleSetStringConverter(final RedisAccessor accessor) { super(accessor); } @Override - public Set convert(final RedisConnection connection, final Set value){ + public Set convert(final RedisConnection connection, final Set value) { final Function, Set> function = (data)->{ if(data != null){ final Set result = new LinkedHashSet<>(data.size()); @@ -475,12 +476,12 @@ public Set convert(final RedisConnection connection, final Set value) final class SimpleSetBinaryConverter extends AbstractSetBinaryConverter { - public SimpleSetBinaryConverter(final RedisAccessor accessor){ + public SimpleSetBinaryConverter(final RedisAccessor accessor) { super(accessor); } @Override - public Set convert(final RedisConnection connection, final Set value){ + public Set convert(final RedisConnection connection, final Set value) { final Function, Set> function = (data)->{ if(data != null){ final Set result = new LinkedHashSet<>(data.size()); @@ -508,13 +509,13 @@ final class ClazzSetStringConverter extends AbstractSetStringConverter { private final Class clazz; - public ClazzSetStringConverter(final RedisAccessor accessor, final Class clazz){ + public ClazzSetStringConverter(final RedisAccessor accessor, final Class clazz) { super(accessor); this.clazz = clazz; } @Override - public Set convert(final RedisConnection connection, final Set value){ + public Set convert(final RedisConnection connection, final Set value) { final Function, Set> function = (data)->data == null ? null : data.stream().map((val)->serializer.deserialize(val, clazz)) .collect(Collectors.toCollection(LinkedHashSet::new)); @@ -532,13 +533,13 @@ final class ClazzSetBinaryConverter extends AbstractSetBinaryConverter { private final Class clazz; - public ClazzSetBinaryConverter(final RedisAccessor accessor, final Class clazz){ + public ClazzSetBinaryConverter(final RedisAccessor accessor, final Class clazz) { super(accessor); this.clazz = clazz; } @Override - public Set convert(final RedisConnection connection, final Set value){ + public Set convert(final RedisConnection connection, final Set value) { final Function, Set> function = (data)->data == null ? null : data.stream().map((val)->serializer.deserializeBytes(val, clazz)) .collect(Collectors.toCollection(LinkedHashSet::new)); @@ -556,13 +557,13 @@ final class TypeSetStringConverter extends AbstractSetStringConverter { private final TypeReference typeReference; - public TypeSetStringConverter(final RedisAccessor accessor, final TypeReference typeReference){ + public TypeSetStringConverter(final RedisAccessor accessor, final TypeReference typeReference) { super(accessor); this.typeReference = typeReference; } @Override - public Set convert(final RedisConnection connection, final Set value){ + public Set convert(final RedisConnection connection, final Set value) { final Function, Set> function = (data)->data == null ? null : data.stream().map((val)->serializer.deserialize(val, typeReference)) .collect(Collectors.toCollection(LinkedHashSet::new)); @@ -580,13 +581,13 @@ final class TypeSetBinaryConverter extends AbstractSetBinaryConverter { private final TypeReference typeReference; - public TypeSetBinaryConverter(final RedisAccessor accessor, final TypeReference typeReference){ + public TypeSetBinaryConverter(final RedisAccessor accessor, final TypeReference typeReference) { super(accessor); this.typeReference = typeReference; } @Override - public Set convert(final RedisConnection connection, final Set value){ + public Set convert(final RedisConnection connection, final Set value) { final Function, Set> function = (data)->data == null ? null : data.stream().map((val)->serializer.deserializeBytes(val, typeReference)) .collect(Collectors.toCollection(LinkedHashSet::new)); @@ -602,7 +603,7 @@ public Set convert(final RedisConnection connection, final Set value) abstract class AbstractMapStringConverter extends AbstractConverter, Map> { - public AbstractMapStringConverter(final RedisAccessor accessor){ + public AbstractMapStringConverter(final RedisAccessor accessor) { super(accessor); } @@ -610,7 +611,7 @@ public AbstractMapStringConverter(final RedisAccessor accessor){ abstract class AbstractMapBinaryConverter extends AbstractConverter, Map> { - public AbstractMapBinaryConverter(final RedisAccessor accessor){ + public AbstractMapBinaryConverter(final RedisAccessor accessor) { super(accessor); } @@ -618,12 +619,12 @@ public AbstractMapBinaryConverter(final RedisAccessor accessor){ final class SimpleMapStringConverter extends AbstractMapStringConverter { - public SimpleMapStringConverter(final RedisAccessor accessor){ + public SimpleMapStringConverter(final RedisAccessor accessor) { super(accessor); } @Override - public Map convert(final RedisConnection connection, final Map value){ + public Map convert(final RedisConnection connection, final Map value) { final Function, Map> function = (data)->data == null ? null : Maps.map(data, (key)->key, serializer::deserialize); @@ -638,12 +639,12 @@ public Map convert(final RedisConnection connection, final Map extends AbstractMapBinaryConverter { - public SimpleMapBinaryConverter(final RedisAccessor accessor){ + public SimpleMapBinaryConverter(final RedisAccessor accessor) { super(accessor); } @Override - public Map convert(final RedisConnection connection, final Map value){ + public Map convert(final RedisConnection connection, final Map value) { final Function, Map> function = (data)->data == null ? null : Maps.map(data, (key)->key, serializer::deserializeBytes); @@ -660,13 +661,13 @@ final class ClazzMapStringConverter extends AbstractMapStringConverter { private final Class clazz; - public ClazzMapStringConverter(final RedisAccessor accessor, final Class clazz){ + public ClazzMapStringConverter(final RedisAccessor accessor, final Class clazz) { super(accessor); this.clazz = clazz; } @Override - public Map convert(final RedisConnection connection, final Map value){ + public Map convert(final RedisConnection connection, final Map value) { final Function, Map> function = (data)->data == null ? null : Maps.map(data, (key)->key, (val)->serializer.deserialize(val, clazz)); @@ -683,13 +684,13 @@ final class ClazzMapBinaryConverter extends AbstractMapBinaryConverter { private final Class clazz; - public ClazzMapBinaryConverter(final RedisAccessor accessor, final Class clazz){ + public ClazzMapBinaryConverter(final RedisAccessor accessor, final Class clazz) { super(accessor); this.clazz = clazz; } @Override - public Map convert(final RedisConnection connection, final Map value){ + public Map convert(final RedisConnection connection, final Map value) { final Function, Map> function = (data)->data == null ? null : Maps.map(data, (key)->key, (val)->serializer.deserializeBytes(val, clazz)); @@ -706,13 +707,13 @@ final class TypeMapStringConverter extends AbstractMapStringConverter { private final TypeReference typeReference; - public TypeMapStringConverter(final RedisAccessor accessor, final TypeReference typeReference){ + public TypeMapStringConverter(final RedisAccessor accessor, final TypeReference typeReference) { super(accessor); this.typeReference = typeReference; } @Override - public Map convert(final RedisConnection connection, final Map value){ + public Map convert(final RedisConnection connection, final Map value) { final Function, Map> function = (data)->data == null ? null : Maps.map(data, (key)->key, (val)->serializer.deserialize(val, typeReference)); @@ -729,13 +730,13 @@ final class TypeMapBinaryConverter extends AbstractMapBinaryConverter { private final TypeReference typeReference; - public TypeMapBinaryConverter(final RedisAccessor accessor, final TypeReference typeReference){ + public TypeMapBinaryConverter(final RedisAccessor accessor, final TypeReference typeReference) { super(accessor); this.typeReference = typeReference; } @Override - public Map convert(final RedisConnection connection, final Map value){ + public Map convert(final RedisConnection connection, final Map value) { final Function, Map> function = (data)->data == null ? null : Maps.map(data, (key)->key, (val)->serializer.deserializeBytes(val, typeReference)); @@ -750,7 +751,7 @@ public Map convert(final RedisConnection connection, final Map extends AbstractConverter, ScanResult> { - public AbstractScanResultConverter(final RedisAccessor accessor){ + public AbstractScanResultConverter(final RedisAccessor accessor) { super(accessor); } @@ -759,7 +760,7 @@ public AbstractScanResultConverter(final RedisAccessor accessor){ abstract class AbstractScanResultMapStringConverter extends AbstractScanResultConverter, Map> { - public AbstractScanResultMapStringConverter(final RedisAccessor accessor){ + public AbstractScanResultMapStringConverter(final RedisAccessor accessor) { super(accessor); } @@ -767,7 +768,7 @@ public AbstractScanResultMapStringConverter(final RedisAccessor accessor){ abstract class AbstractScanResultListStringConverter extends AbstractScanResultConverter, List> { - public AbstractScanResultListStringConverter(final RedisAccessor accessor){ + public AbstractScanResultListStringConverter(final RedisAccessor accessor) { super(accessor); } @@ -775,7 +776,7 @@ public AbstractScanResultListStringConverter(final RedisAccessor accessor){ abstract class AbstractScanResultListBinaryConverter extends AbstractScanResultConverter, List> { - public AbstractScanResultListBinaryConverter(final RedisAccessor accessor){ + public AbstractScanResultListBinaryConverter(final RedisAccessor accessor) { super(accessor); } @@ -783,12 +784,12 @@ public AbstractScanResultListBinaryConverter(final RedisAccessor accessor){ final class SimpleScanResultListStringConverter extends AbstractScanResultListStringConverter { - public SimpleScanResultListStringConverter(final RedisAccessor accessor){ + public SimpleScanResultListStringConverter(final RedisAccessor accessor) { super(accessor); } @Override - public ScanResult> convert(final RedisConnection connection, final ScanResult> value){ + public ScanResult> convert(final RedisConnection connection, final ScanResult> value) { final Function>, ScanResult>> function = (scanResult)->{ if(scanResult.getResults() == null){ return new ScanResult<>(scanResult.getCursor(), null); @@ -814,12 +815,12 @@ public ScanResult> convert(final RedisConnection connection, final ScanR final class SimpleScanResultListBinaryConverter extends AbstractScanResultListBinaryConverter { - public SimpleScanResultListBinaryConverter(final RedisAccessor accessor){ + public SimpleScanResultListBinaryConverter(final RedisAccessor accessor) { super(accessor); } @Override - public ScanResult> convert(final RedisConnection connection, final ScanResult> value){ + public ScanResult> convert(final RedisConnection connection, final ScanResult> value) { final Function>, ScanResult>> function = (scanResult)->{ if(scanResult.getResults() == null){ return new ScanResult<>(scanResult.getCursor(), null); @@ -847,13 +848,13 @@ final class ClazzScanResultListStringConverter extends AbstractScanResultList private final Class clazz; - public ClazzScanResultListStringConverter(final RedisAccessor accessor, final Class clazz){ + public ClazzScanResultListStringConverter(final RedisAccessor accessor, final Class clazz) { super(accessor); this.clazz = clazz; } @Override - public ScanResult> convert(final RedisConnection connection, final ScanResult> value){ + public ScanResult> convert(final RedisConnection connection, final ScanResult> value) { final Function>, ScanResult>> function = (scanResult)->{ final List result = value.getResults() == null ? null : value.getResults().stream() .map((val)->serializer.deserialize(val, clazz)).collect(Collectors.toList()); @@ -873,13 +874,13 @@ final class ClazzScanResultListBinaryConverter extends AbstractScanResultList private final Class clazz; - public ClazzScanResultListBinaryConverter(final RedisAccessor accessor, final Class clazz){ + public ClazzScanResultListBinaryConverter(final RedisAccessor accessor, final Class clazz) { super(accessor); this.clazz = clazz; } @Override - public ScanResult> convert(final RedisConnection connection, final ScanResult> value){ + public ScanResult> convert(final RedisConnection connection, final ScanResult> value) { final Function>, ScanResult>> function = (scanResult)->{ final List result = value.getResults() == null ? null : value.getResults().stream() .map((val)->serializer.deserializeBytes(val, clazz)).collect(Collectors.toList()); @@ -899,13 +900,13 @@ final class TypeScanResultListStringConverter extends AbstractScanResultListS private final TypeReference typeReference; - public TypeScanResultListStringConverter(final RedisAccessor accessor, final TypeReference typeReference){ + public TypeScanResultListStringConverter(final RedisAccessor accessor, final TypeReference typeReference) { super(accessor); this.typeReference = typeReference; } @Override - public ScanResult> convert(final RedisConnection connection, final ScanResult> value){ + public ScanResult> convert(final RedisConnection connection, final ScanResult> value) { final Function>, ScanResult>> function = (scanResult)->{ final List result = value.getResults() == null ? null : value.getResults().stream() .map((val)->serializer.deserialize(val, typeReference)).collect(Collectors.toList()); @@ -925,13 +926,13 @@ final class TypeScanResultListBinaryConverter extends AbstractScanResultListB private final TypeReference typeReference; - public TypeScanResultListBinaryConverter(final RedisAccessor accessor, final TypeReference typeReference){ + public TypeScanResultListBinaryConverter(final RedisAccessor accessor, final TypeReference typeReference) { super(accessor); this.typeReference = typeReference; } @Override - public ScanResult> convert(final RedisConnection connection, final ScanResult> value){ + public ScanResult> convert(final RedisConnection connection, final ScanResult> value) { final Function>, ScanResult>> function = (scanResult)->{ final List result = value.getResults() == null ? null : value.getResults().stream() .map((val)->serializer.deserializeBytes(val, typeReference)).collect(Collectors.toList()); @@ -950,7 +951,7 @@ public ScanResult> convert(final RedisConnection connection, final ScanR abstract class AbstractScanResultMapBinaryConverter extends AbstractScanResultConverter, Map> { - public AbstractScanResultMapBinaryConverter(final RedisAccessor accessor){ + public AbstractScanResultMapBinaryConverter(final RedisAccessor accessor) { super(accessor); } @@ -958,13 +959,13 @@ public AbstractScanResultMapBinaryConverter(final RedisAccessor accessor){ final class SimpleScanResultMapStringConverter extends AbstractScanResultMapStringConverter { - public SimpleScanResultMapStringConverter(final RedisAccessor accessor){ + public SimpleScanResultMapStringConverter(final RedisAccessor accessor) { super(accessor); } @Override public ScanResult> convert(final RedisConnection connection, - final ScanResult> value){ + final ScanResult> value) { final Function>, ScanResult>> function = (scanResult)->{ if(scanResult.getResults() == null){ return new ScanResult<>(scanResult.getCursor(), null); @@ -990,13 +991,13 @@ public ScanResult> convert(final RedisConnection connection, final class SimpleScanResultMapBinaryConverter extends AbstractScanResultMapBinaryConverter { - public SimpleScanResultMapBinaryConverter(final RedisAccessor accessor){ + public SimpleScanResultMapBinaryConverter(final RedisAccessor accessor) { super(accessor); } @Override public ScanResult> convert(final RedisConnection connection, - final ScanResult> value){ + final ScanResult> value) { final Function>, ScanResult>> function = (scanResult)->{ if(scanResult.getResults() == null){ return new ScanResult<>(scanResult.getCursor(), null); @@ -1024,14 +1025,14 @@ final class ClazzScanResultMapStringConverter extends AbstractScanResultMapSt private final Class clazz; - public ClazzScanResultMapStringConverter(final RedisAccessor accessor, final Class clazz){ + public ClazzScanResultMapStringConverter(final RedisAccessor accessor, final Class clazz) { super(accessor); this.clazz = clazz; } @Override public ScanResult> convert(final RedisConnection connection, - final ScanResult> value){ + final ScanResult> value) { final Function>, ScanResult>> function = (scanResult)->{ final Map result = scanResult.getResults() == null ? null : Maps.map(value.getResults(), (key)->key, (val)->serializer.deserialize(val, clazz)); @@ -1051,14 +1052,14 @@ final class ClazzScanResultMapBinaryConverter extends AbstractScanResultMapBi private final Class clazz; - public ClazzScanResultMapBinaryConverter(final RedisAccessor accessor, final Class clazz){ + public ClazzScanResultMapBinaryConverter(final RedisAccessor accessor, final Class clazz) { super(accessor); this.clazz = clazz; } @Override public ScanResult> convert(final RedisConnection connection, - final ScanResult> value){ + final ScanResult> value) { final Function>, ScanResult>> function = (scanResult)->{ final Map result = scanResult.getResults() == null ? null : Maps.map(value.getResults(), (key)->key, (val)->serializer.deserializeBytes(val, clazz)); @@ -1078,14 +1079,14 @@ final class TypeScanResultMapStringConverter extends AbstractScanResultMapStr private final TypeReference typeReference; - public TypeScanResultMapStringConverter(final RedisAccessor accessor, final TypeReference typeReference){ + public TypeScanResultMapStringConverter(final RedisAccessor accessor, final TypeReference typeReference) { super(accessor); this.typeReference = typeReference; } @Override public ScanResult> convert(final RedisConnection connection, - final ScanResult> value){ + final ScanResult> value) { final Function>, ScanResult>> function = (scanResult)->{ final Map result = scanResult.getResults() == null ? null : Maps.map(value.getResults(), (key)->key, (val)->serializer.deserialize(val, typeReference)); @@ -1105,14 +1106,14 @@ final class TypeScanResultMapBinaryConverter extends AbstractScanResultMapBin private final TypeReference typeReference; - public TypeScanResultMapBinaryConverter(final RedisAccessor accessor, final TypeReference typeReference){ + public TypeScanResultMapBinaryConverter(final RedisAccessor accessor, final TypeReference typeReference) { super(accessor); this.typeReference = typeReference; } @Override public ScanResult> convert(final RedisConnection connection, - final ScanResult> value){ + final ScanResult> value) { final Function>, ScanResult>> function = (scanResult)->{ final Map result = scanResult.getResults() == null ? null : Maps.map(value.getResults(), (key)->key, (val)->serializer.deserializeBytes(val, typeReference)); diff --git a/buession-redis/src/main/java/com/buession/redis/RedisAccessor.java b/buession-redis/src/main/java/com/buession/redis/RedisAccessor.java index 34425ccb1..a58763c99 100644 --- a/buession-redis/src/main/java/com/buession/redis/RedisAccessor.java +++ b/buession-redis/src/main/java/com/buession/redis/RedisAccessor.java @@ -81,7 +81,7 @@ public abstract class RedisAccessor implements InitializingBean, AutoCloseable { protected final static ThreadLocal index = new ThreadLocal<>(); - static{ + static { DEFAULT_OPTIONS.setSerializer(DEFAULT_SERIALIZER); index.set(-1); } @@ -89,7 +89,7 @@ public abstract class RedisAccessor implements InitializingBean, AutoCloseable { /** * 构造函数 */ - public RedisAccessor(){ + public RedisAccessor() { } /** @@ -98,34 +98,34 @@ public RedisAccessor(){ * @param dataSource * 数据源 */ - public RedisAccessor(DataSource dataSource){ + public RedisAccessor(DataSource dataSource) { setDataSource(dataSource); } - public Options getOptions(){ + public Options getOptions() { return options; } - public void setOptions(Options options){ + public void setOptions(Options options) { this.options = options; } @Nullable - public RedisConnectionFactory getConnectionFactory(){ + public RedisConnectionFactory getConnectionFactory() { return connectionFactory; } @Nullable - public DataSource getDataSource(){ + public DataSource getDataSource() { return dataSource; } - public void setDataSource(DataSource dataSource){ + public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; } @Override - public void afterPropertiesSet() throws RedisException{ + public void afterPropertiesSet() throws RedisException { Assert.isNull(getDataSource(), "DataSource is required"); Options options = getOptions(); @@ -137,10 +137,12 @@ public void afterPropertiesSet() throws RedisException{ serializer = DEFAULT_SERIALIZER; } - connectionFactory = new RedisConnectionFactory(getDataSource()); + if(connectionFactory == null){ + connectionFactory = new RedisConnectionFactory(getDataSource()); + } } - public void pipeline(){ + public void pipeline() { RedisConnection connection = fetchConnection(); RedisClient client = doGetRedisClient(); @@ -148,24 +150,24 @@ public void pipeline(){ client.execute(new Command() { @Override - public ProtocolCommand getCommand(){ + public ProtocolCommand getCommand() { return null; } @Override - public Pipeline execute() throws RedisException{ + public Pipeline execute() throws RedisException { return client.getConnection().openPipeline(); } @Override - public Pipeline run(final CommandArguments arguments) throws RedisException{ + public Pipeline run(final CommandArguments arguments) throws RedisException { return client.getConnection().openPipeline(); } }); } - public R execute(final SessionCallback callback) throws RedisException{ + public R execute(final SessionCallback callback) throws RedisException { Assert.isNull(callback, "callback cloud not be null."); checkInitialized(); @@ -188,7 +190,7 @@ public R execute(final SessionCallback callback) throws RedisException{ } public TR execute(final SessionCallback callback, final Converter converter) - throws RedisException{ + throws RedisException { Assert.isNull(callback, "callback cloud not be null."); checkInitialized(); @@ -211,11 +213,11 @@ public TR execute(final SessionCallback callback, final Converternew RedisException( + "RedisConnectionFactory is not initialized. You can call the afterPropertiesSet method for initialize.")); } - protected boolean isTransaction(final RedisConnection connection){ + protected boolean isTransaction(final RedisConnection connection) { return connection.isTransaction(); } - protected boolean isPipeline(final RedisConnection connection){ + protected boolean isPipeline(final RedisConnection connection) { return connection.isPipeline(); } - protected boolean isTransactionOrPipeline(final RedisConnection connection){ + protected boolean isTransactionOrPipeline(final RedisConnection connection) { return isTransaction(connection) || isPipeline(connection); } - protected static Map> getTxConverters(){ + protected static Map> getTxConverters() { Map> txResult = txConverters.get(); if(txResult == null){ @@ -266,7 +266,7 @@ protected boolean isTransactionOrPipeline(final RedisConnection connection){ return txResult; } - protected void resetTransactionOrPipeline(){ + protected void resetTransactionOrPipeline() { index.remove(); txConverters.remove(); } diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/PoolConfigConverter.java b/buession-redis/src/main/java/com/buession/redis/client/connection/PoolConfigConverter.java index 36311fbc6..04415ee78 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/connection/PoolConfigConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/PoolConfigConverter.java @@ -34,40 +34,20 @@ * @author Yong.Teng * @since 2.3.0 */ +@Deprecated public class PoolConfigConverter implements Converter> { private final GenericObjectPoolConfig poolConfig; - public PoolConfigConverter(final GenericObjectPoolConfig poolConfig){ + public PoolConfigConverter(final GenericObjectPoolConfig poolConfig) { Assert.isNull(poolConfig, "GenericObjectPoolConfig cloud not be null."); this.poolConfig = poolConfig; } @Nullable @Override - public GenericObjectPoolConfig convert(PoolConfig config){ - poolConfig.setLifo(config.getLifo()); - poolConfig.setFairness(config.getFairness()); - poolConfig.setMaxWait(config.getMaxWait()); - poolConfig.setMinEvictableIdleTime(config.getMinEvictableIdleTime()); - poolConfig.setSoftMinEvictableIdleTime(config.getSoftMinEvictableIdleTime()); - poolConfig.setEvictionPolicyClassName(config.getEvictionPolicyClassName()); - poolConfig.setEvictorShutdownTimeout(config.getEvictorShutdownTimeout()); - poolConfig.setNumTestsPerEvictionRun(config.getNumTestsPerEvictionRun()); - poolConfig.setTestOnCreate(config.getTestOnCreate()); - poolConfig.setTestOnBorrow(config.getTestOnBorrow()); - poolConfig.setTestOnReturn(config.getTestOnReturn()); - poolConfig.setTestWhileIdle(config.getTestWhileIdle()); - poolConfig.setTimeBetweenEvictionRuns(config.getTimeBetweenEvictionRuns()); - poolConfig.setBlockWhenExhausted(config.getBlockWhenExhausted()); - poolConfig.setJmxEnabled(config.getJmxEnabled()); - poolConfig.setJmxNamePrefix(config.getJmxNamePrefix()); - poolConfig.setJmxNameBase(config.getJmxNameBase()); - poolConfig.setMaxTotal(config.getMaxTotal()); - poolConfig.setMinIdle(config.getMinIdle()); - poolConfig.setMaxIdle(config.getMaxIdle()); - - return poolConfig; + public GenericObjectPoolConfig convert(PoolConfig config) { + return config.toGenericObjectPoolConfig(poolConfig); } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/RedisClusterConnection.java b/buession-redis/src/main/java/com/buession/redis/client/connection/RedisClusterConnection.java index 1e7254582..06b2e82ac 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/connection/RedisClusterConnection.java +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/RedisClusterConnection.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.connection; @@ -72,27 +72,27 @@ public interface RedisClusterConnection extends RedisConnection { void setMaxTotalRetriesDuration(int maxTotalRetriesDuration); @Override - default Pipeline openPipeline(){ + default Pipeline openPipeline() { throw new NotSupportedCommandException("Pipeline is currently not supported for JedisClusterConnection."); } @Override - default void closePipeline(){ + default void closePipeline() { throw new NotSupportedCommandException("Pipeline is currently not supported for JedisClusterConnection."); } @Override - default Transaction multi(){ + default Transaction multi() { throw new NotSupportedCommandException(RedisMode.CLUSTER, ProtocolCommand.MULTI); } @Override - default List exec() throws RedisException{ + default List exec() throws RedisException { throw new NotSupportedCommandException(RedisMode.CLUSTER, ProtocolCommand.EXEC); } @Override - default void discard() throws RedisException{ + default void discard() throws RedisException { throw new NotSupportedCommandException(RedisMode.CLUSTER, ProtocolCommand.DISCARD); } diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisClusterDataSource.java b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisClusterDataSource.java index 310a69ae7..d6f707a81 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisClusterDataSource.java +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisClusterDataSource.java @@ -24,21 +24,19 @@ */ package com.buession.redis.client.connection.datasource.jedis; -import com.buession.redis.client.connection.PoolConfigConverter; import com.buession.redis.client.connection.RedisConnection; import com.buession.redis.client.connection.datasource.ClusterDataSource; import com.buession.redis.client.connection.jedis.JedisClusterConnection; import com.buession.redis.core.RedisNode; import com.buession.redis.core.internal.jedis.JedisClientConfigBuilder; -import redis.clients.jedis.Connection; import redis.clients.jedis.ConnectionPoolConfig; import redis.clients.jedis.HostAndPort; import redis.clients.jedis.JedisCluster; import java.time.Duration; -import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; /** * Jedis 集群模式数据源 @@ -69,37 +67,37 @@ public class JedisClusterDataSource extends AbstractJedisDataSource implements C private JedisCluster cluster; @Override - public List getNodes(){ + public List getNodes() { return nodes; } @Override - public void setNodes(List nodes){ + public void setNodes(List nodes) { this.nodes = nodes; } @Override - public int getMaxRedirects(){ + public int getMaxRedirects() { return maxRedirects; } @Override - public void setMaxRedirects(int maxRedirects){ + public void setMaxRedirects(int maxRedirects) { this.maxRedirects = maxRedirects; } @Override - public int getMaxTotalRetriesDuration(){ + public int getMaxTotalRetriesDuration() { return maxTotalRetriesDuration; } @Override - public void setMaxTotalRetriesDuration(int maxTotalRetriesDuration){ + public void setMaxTotalRetriesDuration(int maxTotalRetriesDuration) { this.maxTotalRetriesDuration = maxTotalRetriesDuration; } @Override - public RedisConnection getConnection(){ + public RedisConnection getConnection() { if(cluster == null){ cluster = createJedisCluster(); } @@ -108,16 +106,14 @@ public RedisConnection getConnection(){ getMaxRedirects(), getMaxTotalRetriesDuration(), getSslConfiguration()); } - protected JedisCluster createJedisCluster(){ + protected JedisCluster createJedisCluster() { int maxRedirects = getMaxRedirects() < 0 ? DEFAULT_MAX_REDIRECTS : getMaxRedirects(); final JedisClientConfigBuilder builder = JedisClientConfigBuilder.create(this, getSslConfiguration()); if(isUsePool()){ final ConnectionPoolConfig connectionPoolConfig = new ConnectionPoolConfig(); - final PoolConfigConverter poolConfigConverter = new PoolConfigConverter<>( - connectionPoolConfig); - poolConfigConverter.convert(getPoolConfig()); + getPoolConfig().toGenericObjectPoolConfig(connectionPoolConfig); if(getMaxTotalRetriesDuration() > 0){ cluster = new JedisCluster(createHostAndPorts(), builder.build(), maxRedirects, @@ -137,15 +133,11 @@ protected JedisCluster createJedisCluster(){ return cluster; } - private Set createHostAndPorts(){ - final Set hostAndPorts = new HashSet<>(getNodes().size()); - - for(RedisNode node : getNodes()){ + private Set createHostAndPorts() { + return getNodes().stream().map((node)->{ int port = node.getPort() == 0 ? RedisNode.DEFAULT_PORT : node.getPort(); - hostAndPorts.add(new HostAndPort(node.getHost(), port)); - } - - return hostAndPorts; + return new HostAndPort(node.getHost(), port); + }).collect(Collectors.toSet()); } } \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisDataSource.java b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisDataSource.java index 18d4f142b..955c934ad 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisDataSource.java +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisDataSource.java @@ -26,14 +26,12 @@ import com.buession.lang.Constants; import com.buession.net.ssl.SslConfiguration; -import com.buession.redis.client.connection.PoolConfigConverter; import com.buession.redis.client.connection.RedisConnection; import com.buession.redis.client.connection.datasource.StandaloneDataSource; import com.buession.redis.client.connection.jedis.JedisConnection; import com.buession.redis.core.RedisNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; @@ -64,37 +62,37 @@ public class JedisDataSource extends AbstractJedisDataSource implements Standalo private final static Logger logger = LoggerFactory.getLogger(JedisDataSource.class); @Override - public String getHost(){ + public String getHost() { return host; } @Override - public void setHost(String host){ + public void setHost(String host) { this.host = host; } @Override - public int getPort(){ + public int getPort() { return port; } @Override - public void setPort(int port){ + public void setPort(int port) { this.port = port; } @Override - public int getDatabase(){ + public int getDatabase() { return database; } @Override - public void setDatabase(int database){ + public void setDatabase(int database) { this.database = database; } @Override - public RedisConnection getConnection(){ + public RedisConnection getConnection() { if(isUsePool()){ if(pool == null){ pool = createPool(); @@ -105,13 +103,11 @@ public RedisConnection getConnection(){ getSslConfiguration()); } - protected JedisPool createPool(){ + protected JedisPool createPool() { final SslConfiguration sslConfiguration = getSslConfiguration(); final JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); - final PoolConfigConverter poolConfigConverter = new PoolConfigConverter<>( - jedisPoolConfig); - poolConfigConverter.convert(getPoolConfig()); + getPoolConfig().toGenericObjectPoolConfig(jedisPoolConfig); final String password = Constants.EMPTY_STRING.equals(getPassword()) ? null : getPassword(); if(sslConfiguration == null){ diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisSentinelDataSource.java b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisSentinelDataSource.java index 214a95134..9e4bf6f16 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisSentinelDataSource.java +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisSentinelDataSource.java @@ -25,7 +25,6 @@ package com.buession.redis.client.connection.datasource.jedis; import com.buession.core.validator.Validate; -import com.buession.redis.client.connection.PoolConfigConverter; import com.buession.redis.client.connection.RedisConnection; import com.buession.redis.client.connection.datasource.SentinelDataSource; import com.buession.redis.client.connection.jedis.JedisSentinelConnection; @@ -33,15 +32,15 @@ import com.buession.redis.core.RedisNode; import com.buession.redis.core.internal.jedis.JedisClientConfigBuilder; import redis.clients.jedis.HostAndPort; -import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPoolConfig; import redis.clients.jedis.JedisSentinelPool; import java.util.Collection; import java.util.Collections; -import java.util.LinkedHashSet; import java.util.List; +import java.util.Objects; import java.util.Set; +import java.util.stream.Collectors; /** * Jedis 哨兵模式数据源 @@ -84,67 +83,67 @@ public class JedisSentinelDataSource extends AbstractJedisDataSource implements private JedisSentinelPool pool; @Override - public int getDatabase(){ + public int getDatabase() { return database; } @Override - public void setDatabase(int database){ + public void setDatabase(int database) { this.database = database; } @Override - public int getSentinelConnectTimeout(){ + public int getSentinelConnectTimeout() { return sentinelConnectTimeout; } @Override - public void setSentinelConnectTimeout(int sentinelConnectTimeout){ + public void setSentinelConnectTimeout(int sentinelConnectTimeout) { this.sentinelConnectTimeout = sentinelConnectTimeout; } @Override - public int getSentinelSoTimeout(){ + public int getSentinelSoTimeout() { return sentinelSoTimeout; } @Override - public void setSentinelSoTimeout(int sentinelSoTimeout){ + public void setSentinelSoTimeout(int sentinelSoTimeout) { this.sentinelSoTimeout = sentinelSoTimeout; } @Override - public String getSentinelClientName(){ + public String getSentinelClientName() { return sentinelClientName; } @Override - public void setSentinelClientName(String sentinelClientName){ + public void setSentinelClientName(String sentinelClientName) { this.sentinelClientName = sentinelClientName; } @Override - public String getMasterName(){ + public String getMasterName() { return masterName; } @Override - public void setMasterName(String masterName){ + public void setMasterName(String masterName) { this.masterName = masterName; } @Override - public List getSentinels(){ + public List getSentinels() { return sentinels; } @Override - public void setSentinels(List sentinels){ + public void setSentinels(List sentinels) { this.sentinels = sentinels; } @Override - public RedisConnection getConnection(){ + public RedisConnection getConnection() { if(isUsePool()){ if(pool == null){ pool = createPool(); @@ -155,37 +154,30 @@ public RedisConnection getConnection(){ getInfiniteSoTimeout(), getSentinelConnectTimeout(), getSentinelSoTimeout(), getSslConfiguration()); } - protected JedisSentinelPool createPool(){ + protected JedisSentinelPool createPool() { final Set sentinels = convertToJedisSentinelSet(getSentinels()); final JedisClientConfigBuilder builder = JedisClientConfigBuilder.create(this, getSslConfiguration()); final JedisClientConfigBuilder sentinelBuilder = JedisClientConfigBuilder.create(this, getSslConfiguration()); final JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); - final PoolConfigConverter poolConfigConverter = new PoolConfigConverter<>(jedisPoolConfig); builder.database(getDatabase()); - poolConfigConverter.convert(getPoolConfig()); + getPoolConfig().toGenericObjectPoolConfig(jedisPoolConfig); return new JedisSentinelPool(getMasterName(), sentinels, jedisPoolConfig, builder.build(), sentinelBuilder.build()); } - private Set convertToJedisSentinelSet(Collection sentinelNodes){ + private Set convertToJedisSentinelSet(Collection sentinelNodes) { if(Validate.isEmpty(sentinelNodes)){ return Collections.emptySet(); } - Set convertedNodes = new LinkedHashSet<>(sentinelNodes.size()); - - for(RedisNode node : sentinelNodes){ - if(node != null){ - int port = node.getPort() == 0 ? RedisNode.DEFAULT_SENTINEL_PORT : node.getPort(); - convertedNodes.add(new HostAndPort(node.getHost(), port)); - } - } - - return convertedNodes; + return sentinelNodes.stream().filter(Objects::nonNull).map(node->{ + int port = node.getPort() == 0 ? RedisNode.DEFAULT_SENTINEL_PORT : node.getPort(); + return new HostAndPort(node.getHost(), port); + }).collect(Collectors.toSet()); } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/JedisClusterConnection.java b/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/JedisClusterConnection.java index c877f90db..b333f0cf9 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/JedisClusterConnection.java +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/JedisClusterConnection.java @@ -62,7 +62,7 @@ public class JedisClusterConnection extends AbstractJedisRedisConnection impleme /** * 构造函数 */ - public JedisClusterConnection(){ + public JedisClusterConnection() { super(); } @@ -72,7 +72,7 @@ public JedisClusterConnection(){ * @param dataSource * Redis 数据源 */ - public JedisClusterConnection(JedisClusterDataSource dataSource){ + public JedisClusterConnection(JedisClusterDataSource dataSource) { super(dataSource); } @@ -86,7 +86,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource){ * @param soTimeout * 读取超时(单位:毫秒) */ - public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTimeout, int soTimeout){ + public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTimeout, int soTimeout) { super(dataSource, connectTimeout, soTimeout); } @@ -103,7 +103,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTime * Infinite 读取超时(单位:毫秒) */ public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTimeout, int soTimeout, - int infiniteSoTimeout){ + int infiniteSoTimeout) { super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); } @@ -122,7 +122,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTime * 最大重定向次数 */ public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTimeout, int soTimeout, - int infiniteSoTimeout, int maxRedirects){ + int infiniteSoTimeout, int maxRedirects) { super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); this.maxRedirects = maxRedirects; } @@ -144,7 +144,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTime * 最大重试时长(单位:毫秒) */ public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTimeout, int soTimeout, - int infiniteSoTimeout, int maxRedirects, int maxTotalRetriesDuration){ + int infiniteSoTimeout, int maxRedirects, int maxTotalRetriesDuration) { this(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, maxRedirects); this.maxTotalRetriesDuration = maxTotalRetriesDuration; } @@ -157,7 +157,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTime * @param sslConfiguration * SSL 配置 */ - public JedisClusterConnection(JedisClusterDataSource dataSource, SslConfiguration sslConfiguration){ + public JedisClusterConnection(JedisClusterDataSource dataSource, SslConfiguration sslConfiguration) { super(dataSource, sslConfiguration); } @@ -174,7 +174,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, SslConfiguratio * SSL 配置 */ public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTimeout, int soTimeout, - SslConfiguration sslConfiguration){ + SslConfiguration sslConfiguration) { super(dataSource, connectTimeout, soTimeout, sslConfiguration); } @@ -193,7 +193,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTime * SSL 配置 */ public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTimeout, int soTimeout, - int infiniteSoTimeout, SslConfiguration sslConfiguration){ + int infiniteSoTimeout, SslConfiguration sslConfiguration) { super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); } @@ -205,7 +205,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTime * @param cluster * {@link JedisCluster} */ - public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster){ + public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster) { super(dataSource); this.cluster = cluster; } @@ -223,7 +223,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cl * 读取超时(单位:毫秒) */ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, - int soTimeout){ + int soTimeout) { super(dataSource, connectTimeout, soTimeout); this.cluster = cluster; } @@ -243,7 +243,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cl * Infinite 读取超时(单位:毫秒) */ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, - int soTimeout, int infiniteSoTimeout){ + int soTimeout, int infiniteSoTimeout) { super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); this.cluster = cluster; } @@ -259,7 +259,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cl * SSL 配置 */ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, - SslConfiguration sslConfiguration){ + SslConfiguration sslConfiguration) { super(dataSource, sslConfiguration); this.cluster = cluster; } @@ -279,7 +279,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cl * SSL 配置 */ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, - int soTimeout, SslConfiguration sslConfiguration){ + int soTimeout, SslConfiguration sslConfiguration) { super(dataSource, connectTimeout, soTimeout, sslConfiguration); this.cluster = cluster; } @@ -301,7 +301,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cl * SSL 配置 */ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, - int soTimeout, int infiniteSoTimeout, SslConfiguration sslConfiguration){ + int soTimeout, int infiniteSoTimeout, SslConfiguration sslConfiguration) { super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); this.cluster = cluster; } @@ -314,7 +314,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cl * @param maxRedirects * 最大重试次数 */ - public JedisClusterConnection(JedisClusterDataSource dataSource, int maxRedirects){ + public JedisClusterConnection(JedisClusterDataSource dataSource, int maxRedirects) { super(dataSource); this.maxRedirects = maxRedirects; } @@ -330,7 +330,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, int maxRedirect * SSL 配置 */ public JedisClusterConnection(JedisClusterDataSource dataSource, int maxRedirects, - SslConfiguration sslConfiguration){ + SslConfiguration sslConfiguration) { this(dataSource, sslConfiguration); this.maxRedirects = maxRedirects; } @@ -345,7 +345,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, int maxRedirect * @param maxRedirects * 最大重试次数 */ - public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int maxRedirects){ + public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int maxRedirects) { this(dataSource, cluster); this.maxRedirects = maxRedirects; } @@ -363,7 +363,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cl * SSL 配置 */ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int maxRedirects, - SslConfiguration sslConfiguration){ + SslConfiguration sslConfiguration) { this(dataSource, cluster, sslConfiguration); this.maxRedirects = maxRedirects; } @@ -385,7 +385,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cl * 最大重试时长(单位:毫秒) */ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, - int soTimeout, int maxRedirects, int maxTotalRetriesDuration){ + int soTimeout, int maxRedirects, int maxTotalRetriesDuration) { this(dataSource, cluster, connectTimeout, soTimeout); this.maxRedirects = maxRedirects; this.maxTotalRetriesDuration = maxTotalRetriesDuration; @@ -411,7 +411,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cl */ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, int soTimeout, int maxRedirects, int maxTotalRetriesDuration, - SslConfiguration sslConfiguration){ + SslConfiguration sslConfiguration) { this(dataSource, cluster, connectTimeout, soTimeout, sslConfiguration); this.maxRedirects = maxRedirects; this.maxTotalRetriesDuration = maxTotalRetriesDuration; @@ -436,7 +436,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cl * 最大重试时长(单位:毫秒) */ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, - int soTimeout, int infiniteSoTimeout, int maxRedirects, int maxTotalRetriesDuration){ + int soTimeout, int infiniteSoTimeout, int maxRedirects, int maxTotalRetriesDuration) { this(dataSource, cluster, connectTimeout, soTimeout, infiniteSoTimeout); this.maxRedirects = maxRedirects; this.maxTotalRetriesDuration = maxTotalRetriesDuration; @@ -464,66 +464,65 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cl */ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, int soTimeout, int infiniteSoTimeout, int maxRedirects, int maxTotalRetriesDuration, - SslConfiguration sslConfiguration){ + SslConfiguration sslConfiguration) { this(dataSource, cluster, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); this.maxRedirects = maxRedirects; this.maxTotalRetriesDuration = maxTotalRetriesDuration; } @Override - public int getMaxRedirects(){ + public int getMaxRedirects() { return maxRedirects; } @Override - public void setMaxRedirects(int maxRedirects){ + public void setMaxRedirects(int maxRedirects) { this.maxRedirects = maxRedirects; } @Override - public int getMaxTotalRetriesDuration(){ + public int getMaxTotalRetriesDuration() { return maxTotalRetriesDuration; } @Override - public void setMaxTotalRetriesDuration(int maxTotalRetriesDuration){ + public void setMaxTotalRetriesDuration(int maxTotalRetriesDuration) { this.maxTotalRetriesDuration = maxTotalRetriesDuration; } - public JedisCluster getCluster(){ + public JedisCluster getCluster() { return cluster; } @Override - protected void internalInit(){ + protected void internalInit() { if(cluster == null){ throw new IllegalStateException("JedisCluster cloud not be initialized."); } } @Override - protected void doConnect() throws RedisConnectionFailureException{ + protected void doConnect() throws RedisConnectionFailureException { } @Override - public boolean isConnect(){ + public boolean isConnect() { return cluster != null; } @Override - public boolean isClosed(){ + public boolean isClosed() { return cluster == null; } @Override - protected void doDestroy() throws IOException{ + protected void doDestroy() throws IOException { super.doDestroy(); - logger.info("Jedis cluster destroy."); } @Override - protected void doClose() throws IOException{ + protected void doClose() throws IOException { super.doClose(); logger.info("Jedis cluster close."); diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractStreamOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractStreamOperations.java index 4e75b3fa7..a7055950c 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractStreamOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractStreamOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -40,9 +40,9 @@ import com.buession.redis.core.internal.convert.Converters; import com.buession.redis.utils.SafeEncoder; -import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * Jedis Stream 命令操作抽象类 @@ -56,17 +56,17 @@ public abstract class AbstractStreamOperations extends AbstractJedisRedisOperations implements StreamOperations { - public AbstractStreamOperations(final C client){ + public AbstractStreamOperations(final C client) { super(client); } @Override - public Long xAck(final byte[] key, final byte[] groupName, final StreamEntryId... ids){ + public Long xAck(final byte[] key, final byte[] groupName, final StreamEntryId... ids) { return xAck(SafeEncoder.encode(key), SafeEncoder.encode(groupName), ids); } @Override - public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash){ + public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash) { return xAdd(SafeEncoder.encode(key), id, Converters.BINARY_MAP_TO_STRING_MAP_CONVERTER.convert(hash)); } @@ -74,7 +74,7 @@ public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map> xAutoClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, final int minIdleTime, - final StreamEntryId start, final long count){ + final StreamEntryId start, final long count) { return xAutoClaim(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), minIdleTime, start, count); } @@ -82,7 +82,7 @@ public Map> xAutoClaim(final byte[] key, final @Override public Map> xAutoClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, final int minIdleTime, - final StreamEntryId start){ + final StreamEntryId start) { return xAutoClaim(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), minIdleTime, start); } @@ -90,7 +90,7 @@ public Map> xAutoClaim(final byte[] key, final @Override public Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, final int minIdleTime, - final StreamEntryId start){ + final StreamEntryId start) { return xAutoClaimJustId(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), minIdleTime, start); } @@ -98,14 +98,14 @@ public Map> xAutoClaimJustId(final byte[] key @Override public Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, final int minIdleTime, - final StreamEntryId start, final long count){ + final StreamEntryId start, final long count) { return xAutoClaimJustId(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), minIdleTime, start, count); } @Override public List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, - final int minIdleTime, final StreamEntryId... ids){ + final int minIdleTime, final StreamEntryId... ids) { return xClaim(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), minIdleTime, ids); } @@ -113,14 +113,14 @@ public List xClaim(final byte[] key, final byte[] groupName, final @Override public List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, final int minIdleTime, final StreamEntryId[] ids, - final XClaimArgument xClaimArgument){ + final XClaimArgument xClaimArgument) { return xClaim(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), minIdleTime, ids, xClaimArgument); } @Override public List xClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, - final int minIdleTime, final StreamEntryId... ids){ + final int minIdleTime, final StreamEntryId... ids) { return xClaimJustId(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), minIdleTime, ids); } @@ -128,89 +128,89 @@ public List xClaimJustId(final byte[] key, final byte[] groupName @Override public List xClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, final int minIdleTime, final StreamEntryId[] ids, - final XClaimArgument xClaimArgument){ + final XClaimArgument xClaimArgument) { return xClaimJustId(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), minIdleTime, ids, xClaimArgument); } @Override - public Long xDel(final byte[] key, final StreamEntryId... ids){ + public Long xDel(final byte[] key, final StreamEntryId... ids) { return xDel(SafeEncoder.encode(key), ids); } @Override public Status xGroupCreate(final byte[] key, final byte[] groupName, final StreamEntryId id, - final boolean makeStream){ + final boolean makeStream) { return xGroupCreate(SafeEncoder.encode(key), SafeEncoder.encode(groupName), id, makeStream); } @Override - public Status xGroupSetId(final byte[] key, final byte[] groupName, final StreamEntryId id){ + public Status xGroupSetId(final byte[] key, final byte[] groupName, final StreamEntryId id) { return xGroupSetId(SafeEncoder.encode(key), SafeEncoder.encode(groupName), id); } @Override - public List xInfoConsumers(final byte[] key, final byte[] groupName){ + public List xInfoConsumers(final byte[] key, final byte[] groupName) { return xInfoConsumers(SafeEncoder.encode(key), SafeEncoder.encode(groupName)); } @Override - public List xInfoGroups(final byte[] key){ + public List xInfoGroups(final byte[] key) { return xInfoGroups(SafeEncoder.encode(key)); } @Override - public Stream xInfoStream(final byte[] key){ + public Stream xInfoStream(final byte[] key) { return xInfoStream(SafeEncoder.encode(key)); } @Override - public StreamFull xInfoStream(final byte[] key, final boolean full){ + public StreamFull xInfoStream(final byte[] key, final boolean full) { return xInfoStream(SafeEncoder.encode(key), full); } @Override - public StreamFull xInfoStream(final byte[] key, final boolean full, final long count){ + public StreamFull xInfoStream(final byte[] key, final boolean full, final long count) { return xInfoStream(SafeEncoder.encode(key), full, count); } @Override - public StreamPendingSummary xPending(final byte[] key, final byte[] groupName){ + public StreamPendingSummary xPending(final byte[] key, final byte[] groupName) { return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName)); } @Override - public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime){ + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime) { return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), minIdleTime); } @Override public List xPending(final byte[] key, final byte[] groupName, final StreamEntryId start, - final StreamEntryId end, final long count){ + final StreamEntryId end, final long count) { return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), start, end, count); } @Override - public List xPending(final byte[] key, final byte[] groupName, final byte[] consumerName){ + public List xPending(final byte[] key, final byte[] groupName, final byte[] consumerName) { return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName)); } @Override public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, - final StreamEntryId start, final StreamEntryId end, final long count){ + final StreamEntryId start, final StreamEntryId end, final long count) { return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), minIdleTime, start, end, count); } @Override public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, - final byte[] consumerName){ + final byte[] consumerName) { return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), minIdleTime, SafeEncoder.encode(consumerName)); } @Override public List xPending(final byte[] key, final byte[] groupName, final StreamEntryId start, - final StreamEntryId end, final long count, final byte[] consumerName){ + final StreamEntryId end, final long count, final byte[] consumerName) { return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), start, end, count, SafeEncoder.encode(consumerName)); } @@ -218,25 +218,25 @@ public List xPending(final byte[] key, final byte[] groupName, fi @Override public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, final StreamEntryId start, final StreamEntryId end, final long count, - final byte[] consumerName){ + final byte[] consumerName) { return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), minIdleTime, start, end, count, SafeEncoder.encode(consumerName)); } @Override - public List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end){ + public List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end) { return xRange(SafeEncoder.encode(key), start, end); } @Override public List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end, - final long count){ + final long count) { return xRange(SafeEncoder.encode(key), start, end, count); } @Override public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, - final Map streams){ + final Map streams) { if(streams == null){ return afterBianryXReadGroup( xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), null)); @@ -249,7 +249,7 @@ public List>> xReadGroup(final byte[] groupName, f @Override public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, - final long count, final Map streams){ + final long count, final Map streams) { if(streams == null){ return afterBianryXReadGroup( xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), count, null)); @@ -262,7 +262,7 @@ public List>> xReadGroup(final byte[] groupName, f @Override public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, - final int block, final Map streams){ + final int block, final Map streams) { if(streams == null){ return afterBianryXReadGroup( xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), block, null)); @@ -276,7 +276,7 @@ public List>> xReadGroup(final byte[] groupName, f @Override public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, final boolean isNoAck, - final Map streams){ + final Map streams) { if(streams == null){ return afterBianryXReadGroup( xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), isNoAck, null)); @@ -290,7 +290,7 @@ public List>> xReadGroup(final byte[] groupName, f @Override public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, final long count, final int block, - final Map streams){ + final Map streams) { if(streams == null){ return afterBianryXReadGroup( xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), count, block, null)); @@ -305,7 +305,7 @@ public List>> xReadGroup(final byte[] groupName, f @Override public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, final long count, final boolean isNoAck, - final Map streams){ + final Map streams) { if(streams == null){ return afterBianryXReadGroup( xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), count, isNoAck, null)); @@ -320,7 +320,7 @@ public List>> xReadGroup(final byte[] groupName, f @Override public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, final int block, final boolean isNoAck, - final Map streams){ + final Map streams) { if(streams == null){ return afterBianryXReadGroup( xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), block, isNoAck, null)); @@ -335,7 +335,7 @@ public List>> xReadGroup(final byte[] groupName, f @Override public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, final long count, final int block, final boolean isNoAck, - final Map streams){ + final Map streams) { if(streams == null){ return afterBianryXReadGroup( xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), count, block, isNoAck, @@ -349,30 +349,24 @@ public List>> xReadGroup(final byte[] groupName, f } @Override - public List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start){ + public List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start) { return xRevRange(SafeEncoder.encode(key), end, start); } @Override public List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start, - final long count){ + final long count) { return xRevRange(SafeEncoder.encode(key), end, start, count); } protected static List>> afterBianryXReadGroup( - final List>> data){ + final List>> data) { if(data == null){ return null; }else{ - final List>> result = new ArrayList<>(data.size()); final MapConverter, byte[], List> converter = new MapConverter<>( SafeEncoder::encode, (value)->value); - - for(Map> item : data){ - result.add(converter.convert(item)); - } - - return result; + return data.stream().map(converter::convert).collect(Collectors.toList()); } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterGeoOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterGeoOperations.java index aca729bf8..99d16fe1f 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterGeoOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterGeoOperations.java @@ -49,12 +49,12 @@ */ public final class JedisClusterGeoOperations extends AbstractGeoOperations { - public JedisClusterGeoOperations(final JedisClusterClient client){ + public JedisClusterGeoOperations(final JedisClusterClient client) { super(client); } @Override - public Long geoAdd(final String key, final String member, final double longitude, final double latitude){ + public Long geoAdd(final String key, final String member, final double longitude, final double latitude) { final CommandArguments args = CommandArguments.create("key", key).put("member", member) .put("longitude", longitude).put("latitude", latitude); return new JedisClusterCommand(client, ProtocolCommand.GEOADD) @@ -65,7 +65,7 @@ public Long geoAdd(final String key, final String member, final double longitude } @Override - public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude){ + public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude) { final CommandArguments args = CommandArguments.create("key", key).put("member", member) .put("longitude", longitude).put("latitude", latitude); return new JedisClusterCommand(client, ProtocolCommand.GEOADD) @@ -76,7 +76,7 @@ public Long geoAdd(final byte[] key, final byte[] member, final double longitude } @Override - public Long geoAdd(final String key, final Map memberCoordinates){ + public Long geoAdd(final String key, final Map memberCoordinates) { final CommandArguments args = CommandArguments.create("key", key).put("memberCoordinates", memberCoordinates); final Map geoCoordinates = GeoConverter.STRING_MAP_CONVERTER.convert( memberCoordinates); @@ -88,7 +88,7 @@ public Long geoAdd(final String key, final Map memberCoordinates){ } @Override - public Long geoAdd(final byte[] key, final Map memberCoordinates){ + public Long geoAdd(final byte[] key, final Map memberCoordinates) { final CommandArguments args = CommandArguments.create("key", key).put("memberCoordinates", memberCoordinates); final Map geoCoordinates = GeoConverter.BINARY_MAP_CONVERTER.convert( memberCoordinates); @@ -100,7 +100,7 @@ public Long geoAdd(final byte[] key, final Map memberCoordinates){ } @Override - public List geoHash(final String key, final String... members){ + public List geoHash(final String key, final String... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); return new JedisClusterCommand>(client, ProtocolCommand.GEOHASH) .general((cmd)->cmd.geohash(key, members)) @@ -110,7 +110,7 @@ public List geoHash(final String key, final String... members){ } @Override - public List geoHash(final byte[] key, final byte[]... members){ + public List geoHash(final byte[] key, final byte[]... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); return new JedisClusterCommand>(client, ProtocolCommand.GEOHASH) .general((cmd)->cmd.geohash(key, members)) @@ -120,7 +120,7 @@ public List geoHash(final byte[] key, final byte[]... members){ } @Override - public List geoPos(final String key, final String... members){ + public List geoPos(final String key, final String... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); return new JedisClusterCommand>(client, ProtocolCommand.GEOPOS) .general((cmd)->cmd.geopos(key, members), GeoCoordinateConverter.LIST_CONVERTER) @@ -130,7 +130,7 @@ public List geoPos(final String key, final String... members){ } @Override - public List geoPos(final byte[] key, final byte[]... members){ + public List geoPos(final byte[] key, final byte[]... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); return new JedisClusterCommand>(client, ProtocolCommand.GEOPOS) .general((cmd)->cmd.geopos(key, members), GeoCoordinateConverter.LIST_CONVERTER) @@ -140,7 +140,7 @@ public List geoPos(final byte[] key, final byte[]... members){ } @Override - public Double geoDist(final String key, final String member1, final String member2){ + public Double geoDist(final String key, final String member1, final String member2) { final CommandArguments args = CommandArguments.create("key", key).put("member1", member1) .put("member2", member2); return new JedisClusterCommand(client, ProtocolCommand.GEODIST) @@ -151,7 +151,7 @@ public Double geoDist(final String key, final String member1, final String membe } @Override - public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2){ + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2) { final CommandArguments args = CommandArguments.create("key", key).put("member1", member1) .put("member2", member2); return new JedisClusterCommand(client, ProtocolCommand.GEODIST) @@ -162,7 +162,7 @@ public Double geoDist(final byte[] key, final byte[] member1, final byte[] membe } @Override - public Double geoDist(final String key, final String member1, final String member2, final GeoUnit unit){ + public Double geoDist(final String key, final String member1, final String member2, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member1", member1) .put("member2", member2).put("unit", unit); final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); @@ -174,7 +174,7 @@ public Double geoDist(final String key, final String member1, final String membe } @Override - public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoUnit unit){ + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member1", member1) .put("member2", member2).put("unit", unit); final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); @@ -187,7 +187,7 @@ public Double geoDist(final byte[] key, final byte[] member1, final byte[] membe @Override public List geoRadius(final String key, final double longitude, final double latitude, - final double radius, final GeoUnit unit){ + final double radius, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit); final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); @@ -203,7 +203,7 @@ public List geoRadius(final String key, final double longitude, final @Override public List geoRadius(final byte[] key, final double longitude, final double latitude, - final double radius, final GeoUnit unit){ + final double radius, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit); final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); @@ -220,7 +220,7 @@ public List geoRadius(final byte[] key, final double longitude, final @Override public List geoRadius(final String key, final double longitude, final double latitude, final double radius, final GeoUnit unit, - final GeoRadiusArgument geoRadiusArgument){ + final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit) .put("geoRadiusArgument", geoRadiusArgument); @@ -239,7 +239,7 @@ public List geoRadius(final String key, final double longitude, final @Override public List geoRadius(final byte[] key, final double longitude, final double latitude, final double radius, final GeoUnit unit, - final GeoRadiusArgument geoRadiusArgument){ + final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit) .put("geoRadiusArgument", geoRadiusArgument); @@ -257,7 +257,7 @@ public List geoRadius(final byte[] key, final double longitude, final @Override public List geoRadiusRo(final String key, final double longitude, final double latitude, - final double radius, final GeoUnit unit){ + final double radius, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit); final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); @@ -273,7 +273,7 @@ public List geoRadiusRo(final String key, final double longitude, fin @Override public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, - final double radius, final GeoUnit unit){ + final double radius, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit); final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); @@ -290,7 +290,7 @@ public List geoRadiusRo(final byte[] key, final double longitude, fin @Override public List geoRadiusRo(final String key, final double longitude, final double latitude, final double radius, final GeoUnit unit, - final GeoRadiusArgument geoRadiusArgument){ + final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit) .put("geoRadiusArgument", geoRadiusArgument); @@ -309,7 +309,7 @@ public List geoRadiusRo(final String key, final double longitude, fin @Override public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, final double radius, final GeoUnit unit, - final GeoRadiusArgument geoRadiusArgument){ + final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit) .put("geoRadiusArgument", geoRadiusArgument); @@ -327,7 +327,7 @@ public List geoRadiusRo(final byte[] key, final double longitude, fin @Override public List geoRadiusByMember(final String key, final String member, final double radius, - final GeoUnit unit){ + final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit); final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); @@ -343,7 +343,7 @@ public List geoRadiusByMember(final String key, final String member, @Override public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, - final GeoUnit unit){ + final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit); final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); @@ -359,7 +359,7 @@ public List geoRadiusByMember(final byte[] key, final byte[] member, @Override public List geoRadiusByMember(final String key, final String member, final double radius, - final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument){ + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); @@ -376,7 +376,7 @@ public List geoRadiusByMember(final String key, final String member, @Override public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, - final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument){ + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); @@ -393,7 +393,7 @@ public List geoRadiusByMember(final byte[] key, final byte[] member, @Override public List geoRadiusByMemberRo(final String key, final String member, final double radius, - final GeoUnit unit){ + final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit); final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); @@ -409,7 +409,7 @@ public List geoRadiusByMemberRo(final String key, final String member @Override public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, - final GeoUnit unit){ + final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit); final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); @@ -425,7 +425,7 @@ public List geoRadiusByMemberRo(final byte[] key, final byte[] member @Override public List geoRadiusByMemberRo(final String key, final String member, final double radius, - final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument){ + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); @@ -442,7 +442,7 @@ public List geoRadiusByMemberRo(final String key, final String member @Override public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, - final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument){ + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisRedisOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisRedisOperations.java index 27d1be1e5..f780adb39 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisRedisOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisRedisOperations.java @@ -26,6 +26,7 @@ import com.buession.core.Executor; import com.buession.core.converter.Converter; +import com.buession.redis.client.connection.RedisConnectionUtils; import com.buession.redis.client.connection.jedis.JedisClusterConnection; import com.buession.redis.client.connection.jedis.JedisConnection; import com.buession.redis.client.connection.jedis.JedisRedisConnection; @@ -39,6 +40,8 @@ import com.buession.redis.core.internal.AbstractRedisOperationsCommand; import com.buession.redis.core.internal.jedis.JedisResult; import com.buession.redis.exception.NotSupportedCommandException; +import com.buession.redis.exception.NotSupportedPipelineCommandException; +import com.buession.redis.exception.NotSupportedTransactionCommandException; import com.buession.redis.exception.RedisException; import com.buession.redis.pipeline.jedis.JedisPipeline; import com.buession.redis.transaction.jedis.JedisTransaction; @@ -58,51 +61,56 @@ public interface JedisRedisOperations extends RedisOperations { abstract class AbstractJedisCommand extends AbstractRedisOperationsCommand { - protected AbstractJedisCommand(final CLIENT client, final ProtocolCommand command){ + protected AbstractJedisCommand(final CLIENT client, final ProtocolCommand command) { super(client, command); } @Override - public R execute() throws RedisException{ + public R execute() throws RedisException { if(connection.isPipeline()){ if(pipelineRunner == null){ - throw throwNotSupportedCommandException(NotSupportedCommandException.Type.PIPELINE); + throw new NotSupportedPipelineCommandException( + RedisConnectionUtils.getRedisMode(client.getConnection()), getCommand()); }else{ try{ client.getTxResults().add(pipelineRunner.run()); }catch(Exception e){ - logger.error(e.getMessage()); + throw new RedisException(e.getMessage(), e); } } }else if(connection.isTransaction()){ if(transactionRunner == null){ - throw throwNotSupportedCommandException(NotSupportedCommandException.Type.TRANSACTION); + throw new NotSupportedTransactionCommandException( + RedisConnectionUtils.getRedisMode(client.getConnection()), getCommand()); }else{ try{ client.getTxResults().add(transactionRunner.run()); }catch(Exception e){ - logger.error(e.getMessage()); + throw new RedisException(e.getMessage(), e); } } }else{ if(runner == null){ - throw throwNotSupportedCommandException(NotSupportedCommandException.Type.NORMAL); + throw new NotSupportedCommandException( + RedisConnectionUtils.getRedisMode(client.getConnection()), + NotSupportedCommandException.Type.NORMAL, getCommand()); }else{ try{ return runner.run(); }catch(Exception e){ - logger.error(e.getMessage()); + throw new RedisException(e.getMessage(), e); } } } return null; } - protected Runner createPipelineRunner(final Executor> executor){ + protected Runner createPipelineRunner(final Executor> executor) { return new Runner() { + @SuppressWarnings({"unchecked"}) @Override - public JedisResult run() throws Exception{ + public JedisResult run() throws Exception { final redis.clients.jedis.Pipeline jedisPipeline = ((JedisPipeline) pipeline()).primitive(); return newJedisResult(executor.execute(jedisPipeline)); } @@ -111,11 +119,12 @@ public JedisResult run() throws Exception{ } protected Runner createPipelineRunner(final Executor> executor, - final Converter converter){ + final Converter converter) { return new Runner() { + @SuppressWarnings({"unchecked"}) @Override - public JedisResult run() throws Exception{ + public JedisResult run() throws Exception { final redis.clients.jedis.Pipeline jedisPipeline = ((JedisPipeline) pipeline()).primitive(); return newJedisResult(executor.execute(jedisPipeline), converter); } @@ -123,11 +132,12 @@ public JedisResult run() throws Exception{ }; } - protected Runner createTransactionRunner(final Executor> executor){ + protected Runner createTransactionRunner(final Executor> executor) { return new Runner() { + @SuppressWarnings({"unchecked"}) @Override - public JedisResult run() throws Exception{ + public JedisResult run() throws Exception { final redis.clients.jedis.Transaction transaction = ((JedisTransaction) transaction()).primitive(); return newJedisResult(executor.execute(transaction)); } @@ -136,11 +146,12 @@ public JedisResult run() throws Exception{ } protected Runner createTransactionRunner(final Executor> executor, - final Converter converter){ + final Converter converter) { return new Runner() { + @SuppressWarnings({"unchecked"}) @Override - public JedisResult run() throws Exception{ + public JedisResult run() throws Exception { final redis.clients.jedis.Transaction transaction = ((JedisTransaction) transaction()).primitive(); return newJedisResult(executor.execute(transaction), converter); } @@ -148,28 +159,29 @@ public JedisResult run() throws Exception{ }; } - protected JedisResult newJedisResult(final Response response){ - return JedisResult.Builder.forResponse(response).build(); + protected JedisResult newJedisResult(final Response response) { + return JedisResult.Builder.fromResponse(response).build(); } protected JedisResult newJedisResult(final Response response, - final Converter converter){ - return JedisResult.Builder.forResponse(response).mappedWith(converter).build(); + final Converter converter) { + return JedisResult.Builder.fromResponse(response).mappedWith(converter).build(); } } class JedisCommand extends AbstractJedisCommand { - public JedisCommand(final JedisStandaloneClient client, final ProtocolCommand command){ + public JedisCommand(final JedisStandaloneClient client, final ProtocolCommand command) { super(client, command); } - public JedisCommand general(final Executor executor){ + public JedisCommand general(final Executor executor) { this.runner = new Runner() { + @SuppressWarnings({"unchecked"}) @Override - public R run() throws Exception{ + public R run() throws Exception { return executor.execute(connection.getJedis()); } @@ -178,11 +190,12 @@ public R run() throws Exception{ return this; } - public JedisCommand general(final Executor executor, final Converter converter){ + public JedisCommand general(final Executor executor, final Converter converter) { this.runner = new Runner() { + @SuppressWarnings({"unchecked"}) @Override - public R run() throws Exception{ + public R run() throws Exception { return converter.convert(executor.execute(connection.getJedis())); } @@ -191,24 +204,24 @@ public R run() throws Exception{ return this; } - public JedisCommand pipeline(final Executor> executor){ + public JedisCommand pipeline(final Executor> executor) { this.pipelineRunner = createPipelineRunner(executor); return this; } public JedisCommand pipeline(final Executor> executor, - final Converter converter){ + final Converter converter) { this.pipelineRunner = createPipelineRunner(executor, converter); return this; } - public JedisCommand transaction(final Executor> executor){ + public JedisCommand transaction(final Executor> executor) { this.transactionRunner = createTransactionRunner(executor); return this; } public JedisCommand transaction(final Executor> executor, - final Converter converter){ + final Converter converter) { this.transactionRunner = createTransactionRunner(executor, converter); return this; } @@ -217,15 +230,16 @@ public JedisCommand transaction(final Executor class JedisSentinelCommand extends AbstractJedisCommand { - protected JedisSentinelCommand(final JedisSentinelClient client, final ProtocolCommand command){ + protected JedisSentinelCommand(final JedisSentinelClient client, final ProtocolCommand command) { super(client, command); } - public JedisSentinelCommand general(Executor executor){ + public JedisSentinelCommand general(Executor executor) { this.runner = new Runner() { + @SuppressWarnings({"unchecked"}) @Override - public R run() throws Exception{ + public R run() throws Exception { return executor.execute(connection.getJedis()); } @@ -235,11 +249,12 @@ public R run() throws Exception{ } public JedisSentinelCommand general(final Executor executor, - final Converter converter){ + final Converter converter) { this.runner = new Runner() { + @SuppressWarnings({"unchecked"}) @Override - public R run() throws Exception{ + public R run() throws Exception { return converter.convert(executor.execute(connection.getJedis())); } @@ -248,24 +263,24 @@ public R run() throws Exception{ return this; } - public JedisSentinelCommand pipeline(final Executor> executor){ + public JedisSentinelCommand pipeline(final Executor> executor) { this.pipelineRunner = createPipelineRunner(executor); return this; } public JedisSentinelCommand pipeline(final Executor> executor, - final Converter converter){ + final Converter converter) { this.pipelineRunner = createPipelineRunner(executor, converter); return this; } - public JedisSentinelCommand transaction(final Executor> executor){ + public JedisSentinelCommand transaction(final Executor> executor) { this.transactionRunner = createTransactionRunner(executor); return this; } public JedisSentinelCommand transaction(final Executor> executor, - final Converter converter){ + final Converter converter) { this.transactionRunner = createTransactionRunner(executor, converter); return this; } @@ -274,15 +289,16 @@ public JedisSentinelCommand transaction(final Executor extends AbstractJedisCommand { - protected JedisClusterCommand(final JedisClusterClient client, final ProtocolCommand command){ + protected JedisClusterCommand(final JedisClusterClient client, final ProtocolCommand command) { super(client, command); } - public JedisClusterCommand general(Executor executor){ + public JedisClusterCommand general(Executor executor) { this.runner = new Runner() { + @SuppressWarnings({"unchecked"}) @Override - public R run() throws Exception{ + public R run() throws Exception { return executor.execute(connection.getCluster()); } @@ -292,11 +308,12 @@ public R run() throws Exception{ } public JedisClusterCommand general(final Executor executor, - final Converter converter){ + final Converter converter) { this.runner = new Runner() { + @SuppressWarnings({"unchecked"}) @Override - public R run() throws Exception{ + public R run() throws Exception { return converter.convert(executor.execute(connection.getCluster())); } @@ -305,24 +322,24 @@ public R run() throws Exception{ return this; } - public JedisClusterCommand pipeline(final Executor> executor){ + public JedisClusterCommand pipeline(final Executor> executor) { this.pipelineRunner = createPipelineRunner(executor); return this; } public JedisClusterCommand pipeline(final Executor> executor, - final Converter converter){ + final Converter converter) { this.pipelineRunner = createPipelineRunner(executor, converter); return this; } - public JedisClusterCommand transaction(final Executor> executor){ + public JedisClusterCommand transaction(final Executor> executor) { this.transactionRunner = createTransactionRunner(executor); return this; } public JedisClusterCommand transaction(final Executor> executor, - final Converter converter){ + final Converter converter) { this.transactionRunner = createTransactionRunner(executor, converter); return this; } diff --git a/buession-redis/src/main/java/com/buession/redis/core/AbstractRedisCommand.java b/buession-redis/src/main/java/com/buession/redis/core/AbstractRedisCommand.java index a9190d52c..e7f97cac3 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/AbstractRedisCommand.java +++ b/buession-redis/src/main/java/com/buession/redis/core/AbstractRedisCommand.java @@ -25,10 +25,8 @@ package com.buession.redis.core; import com.buession.redis.client.RedisClient; -import com.buession.redis.client.connection.RedisConnectionUtils; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.exception.NotSupportedCommandException; import com.buession.redis.exception.RedisException; import com.buession.redis.pipeline.Pipeline; import com.buession.redis.transaction.Transaction; @@ -47,33 +45,27 @@ public abstract class AbstractRedisCommand implements protected final Logger logger = LoggerFactory.getLogger(getClass()); - protected AbstractRedisCommand(final C client, final ProtocolCommand command){ + protected AbstractRedisCommand(final C client, final ProtocolCommand command) { this.client = client; this.command = command; } @Override - public ProtocolCommand getCommand(){ + public ProtocolCommand getCommand() { return command; } @Override - public R run(final CommandArguments arguments) throws RedisException{ + public R run(final CommandArguments arguments) throws RedisException { return client.execute(this, arguments); } - protected Pipeline pipeline(){ + protected Pipeline pipeline() { return client.getConnection().openPipeline(); } - protected Transaction transaction(){ + protected Transaction transaction() { return client.getConnection().multi(); } - protected NotSupportedCommandException throwNotSupportedCommandException( - final NotSupportedCommandException.Type type){ - return new NotSupportedCommandException(RedisConnectionUtils.getRedisMode(client.getConnection()), - type, getCommand()); - } - } diff --git a/buession-redis/src/main/java/com/buession/redis/core/ClusterRedisNode.java b/buession-redis/src/main/java/com/buession/redis/core/ClusterRedisNode.java index d4794a88d..5ddbd5d75 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/ClusterRedisNode.java +++ b/buession-redis/src/main/java/com/buession/redis/core/ClusterRedisNode.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core; @@ -99,7 +99,7 @@ public class ClusterRedisNode extends RedisNode { */ public ClusterRedisNode(final String id, final String ip, final int port, final Set flags, final String masterId, final long pingSent, final long pongSent, final long configEpoch, - final LinkState linkState, final SlotRange slot){ + final LinkState linkState, final SlotRange slot) { super(ip, port); setId(id); this.ip = ip; @@ -117,7 +117,7 @@ public ClusterRedisNode(final String id, final String ip, final int port, final * * @return 客户端与节点通信使用的地址 */ - public String getIp(){ + public String getIp() { return ip; } @@ -126,7 +126,7 @@ public String getIp(){ * * @return 标记位 */ - public Set getFlags(){ + public Set getFlags() { return flags; } @@ -135,7 +135,7 @@ public Set getFlags(){ * * @return 最近一次发送 ping 的时间(unix 毫秒时间戳),0 代表没有发送过 */ - public long getPingSent(){ + public long getPingSent() { return pingSent; } @@ -144,7 +144,7 @@ public long getPingSent(){ * * @return 最近一次收到 pong 的时间(unix 毫秒时间戳),0 代表没有接收过 */ - public long getPongSent(){ + public long getPongSent() { return pongSent; } @@ -153,7 +153,7 @@ public long getPongSent(){ * * @return 节点的 epoch 值 */ - public long getConfigEpoch(){ + public long getConfigEpoch() { return configEpoch; } @@ -162,7 +162,7 @@ public long getConfigEpoch(){ * * @return node-to-node 集群总线使用的链接的状态 */ - public LinkState getLinkState(){ + public LinkState getLinkState() { return linkState; } @@ -171,12 +171,12 @@ public LinkState getLinkState(){ * * @return 哈希槽值或者一个哈希槽范围 */ - public SlotRange getSlot(){ + public SlotRange getSlot() { return slot; } @Override - public String toString(){ + public String toString() { return ObjectStringBuilder.create() .add("id", getId()) .add("host", getHost() + ":" + getPort()) @@ -236,16 +236,16 @@ public enum Flag { private final String value; - Flag(final String value){ + Flag(final String value) { this.value = value; } - public String getValue(){ + public String getValue() { return value; } @Override - public String toString(){ + public String toString() { return getValue(); } @@ -260,18 +260,18 @@ public enum LinkState { DISCONNECTED("disconnected"); - private String value; + private final String value; - LinkState(final String value){ + LinkState(final String value) { this.value = value; } - public String getValue(){ + public String getValue() { return value; } @Override - public String toString(){ + public String toString() { return getValue(); } diff --git a/buession-redis/src/main/java/com/buession/redis/core/Command.java b/buession-redis/src/main/java/com/buession/redis/core/Command.java index 5e63e6232..e3a4834f3 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/Command.java +++ b/buession-redis/src/main/java/com/buession/redis/core/Command.java @@ -64,7 +64,7 @@ public interface Command { * @throws RedisException * Redis 命令运行异常 */ - default R run() throws RedisException{ + default R run() throws RedisException { return run(null); } diff --git a/buession-redis/src/main/java/com/buession/redis/core/PoolConfig.java b/buession-redis/src/main/java/com/buession/redis/core/PoolConfig.java index af45031b3..5b0dd7b0a 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/PoolConfig.java +++ b/buession-redis/src/main/java/com/buession/redis/core/PoolConfig.java @@ -143,7 +143,7 @@ public class PoolConfig { * * @return 池模式,为 true 时,后进先出;为 false 时,先进先出 */ - public boolean getLifo(){ + public boolean getLifo() { return lifo; } @@ -153,7 +153,7 @@ public boolean getLifo(){ * @param lifo * 池模式,为 true 时,后进先出;为 false 时,先进先出 */ - public void setLifo(boolean lifo){ + public void setLifo(boolean lifo) { this.lifo = lifo; } @@ -162,7 +162,7 @@ public void setLifo(boolean lifo){ * * @return 当从池中获取资源或者将资源还回池中时,是否使用 {@link java.util.concurrent.locks.ReentrantLock} 的公平锁机制 */ - public boolean getFairness(){ + public boolean getFairness() { return fairness; } @@ -172,7 +172,7 @@ public boolean getFairness(){ * @param fairness * 当从池中获取资源或者将资源还回池中时,是否使用 {@link java.util.concurrent.locks.ReentrantLock} 的公平锁机制 */ - public void setFairness(boolean fairness){ + public void setFairness(boolean fairness) { this.fairness = fairness; } @@ -181,7 +181,7 @@ public void setFairness(boolean fairness){ * * @return 当连接池资源用尽后,调用者获取连接时的最大等待时间 */ - public Duration getMaxWait(){ + public Duration getMaxWait() { return maxWait; } @@ -191,7 +191,7 @@ public Duration getMaxWait(){ * @param maxWait * 当连接池资源用尽后,调用者获取连接时的最大等待时间 */ - public void setMaxWait(Duration maxWait){ + public void setMaxWait(Duration maxWait) { this.maxWait = maxWait; } @@ -200,7 +200,7 @@ public void setMaxWait(Duration maxWait){ * * @return 连接的最小空闲时间,达到此值后且已达最大空闲连接数该空闲连接可能会被移除 */ - public Duration getMinEvictableIdleTime(){ + public Duration getMinEvictableIdleTime() { return minEvictableIdleTime; } @@ -210,7 +210,7 @@ public Duration getMinEvictableIdleTime(){ * @param minEvictableIdleTime * 连接的最小空闲时间,达到此值后且已达最大空闲连接数该空闲连接可能会被移除 */ - public void setMinEvictableIdleTime(Duration minEvictableIdleTime){ + public void setMinEvictableIdleTime(Duration minEvictableIdleTime) { this.minEvictableIdleTime = minEvictableIdleTime; } @@ -219,7 +219,7 @@ public void setMinEvictableIdleTime(Duration minEvictableIdleTime){ * * @return 连接空闲的最小时间,达到此值后空闲链接将会被移除,且保留 minIdle 个空闲连接数 */ - public Duration getSoftMinEvictableIdleTime(){ + public Duration getSoftMinEvictableIdleTime() { return softMinEvictableIdleTime; } @@ -229,7 +229,7 @@ public Duration getSoftMinEvictableIdleTime(){ * @param softMinEvictableIdleTime * 连接空闲的最小时间,达到此值后空闲链接将会被移除,且保留 minIdle 个空闲连接数 */ - public void setSoftMinEvictableIdleTime(Duration softMinEvictableIdleTime){ + public void setSoftMinEvictableIdleTime(Duration softMinEvictableIdleTime) { this.softMinEvictableIdleTime = softMinEvictableIdleTime; } @@ -238,7 +238,7 @@ public void setSoftMinEvictableIdleTime(Duration softMinEvictableIdleTime){ * * @return 驱逐策略的类名 */ - public String getEvictionPolicyClassName(){ + public String getEvictionPolicyClassName() { return evictionPolicyClassName; } @@ -248,7 +248,7 @@ public String getEvictionPolicyClassName(){ * @param evictionPolicyClassName * 驱逐策略的类名 */ - public void setEvictionPolicyClassName(String evictionPolicyClassName){ + public void setEvictionPolicyClassName(String evictionPolicyClassName) { this.evictionPolicyClassName = evictionPolicyClassName; } @@ -257,7 +257,7 @@ public void setEvictionPolicyClassName(String evictionPolicyClassName){ * * @return 关闭驱逐线程的超时时间 */ - public Duration getEvictorShutdownTimeout(){ + public Duration getEvictorShutdownTimeout() { return evictorShutdownTimeout; } @@ -267,7 +267,7 @@ public Duration getEvictorShutdownTimeout(){ * @param evictorShutdownTimeout * 关闭驱逐线程的超时时间 */ - public void setEvictorShutdownTimeout(Duration evictorShutdownTimeout){ + public void setEvictorShutdownTimeout(Duration evictorShutdownTimeout) { this.evictorShutdownTimeout = evictorShutdownTimeout; } @@ -278,7 +278,7 @@ public void setEvictorShutdownTimeout(Duration evictorShutdownTimeout){ * 如果 numTestsPerEvictionRun >= 0, 则取 numTestsPerEvictionRun 和池内的连接数的较小值作为每次检测的连接数; * 如果 numTestsPerEvictionRun < 0,则每次检查的连接数是检查时池内连接的总数除以这个值的绝对值再向上取整的结果 */ - public int getNumTestsPerEvictionRun(){ + public int getNumTestsPerEvictionRun() { return numTestsPerEvictionRun; } @@ -288,7 +288,7 @@ public int getNumTestsPerEvictionRun(){ * @param numTestsPerEvictionRun * 检测空闲对象线程每次运行时检测的空闲对象的数量 */ - public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun){ + public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) { this.numTestsPerEvictionRun = numTestsPerEvictionRun; } @@ -297,7 +297,7 @@ public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun){ * * @return 在创建对象时检测对象是否有效 */ - public boolean isTestOnCreate(){ + public boolean isTestOnCreate() { return getTestOnCreate(); } @@ -306,7 +306,7 @@ public boolean isTestOnCreate(){ * * @return 在创建对象时检测对象是否有效 */ - public boolean getTestOnCreate(){ + public boolean getTestOnCreate() { return testOnCreate; } @@ -316,7 +316,7 @@ public boolean getTestOnCreate(){ * @param testOnCreate * 在创建对象时检测对象是否有效,配置 true 会降低性能 */ - public void setTestOnCreate(boolean testOnCreate){ + public void setTestOnCreate(boolean testOnCreate) { this.testOnCreate = testOnCreate; } @@ -325,7 +325,7 @@ public void setTestOnCreate(boolean testOnCreate){ * * @return 在从对象池获取对象时是否检测对象有效 */ - public boolean isTestOnBorrow(){ + public boolean isTestOnBorrow() { return getTestOnBorrow(); } @@ -334,7 +334,7 @@ public boolean isTestOnBorrow(){ * * @return 在从对象池获取对象时是否检测对象有效 */ - public boolean getTestOnBorrow(){ + public boolean getTestOnBorrow() { return testOnBorrow; } @@ -344,7 +344,7 @@ public boolean getTestOnBorrow(){ * @param testOnBorrow * 在从对象池获取对象时是否检测对象有效,配置 true 会降低性能 */ - public void setTestOnBorrow(boolean testOnBorrow){ + public void setTestOnBorrow(boolean testOnBorrow) { this.testOnBorrow = testOnBorrow; } @@ -353,7 +353,7 @@ public void setTestOnBorrow(boolean testOnBorrow){ * * @return 在向对象池中归还对象时是否检测对象有效 */ - public boolean isTestOnReturn(){ + public boolean isTestOnReturn() { return getTestOnReturn(); } @@ -362,7 +362,7 @@ public boolean isTestOnReturn(){ * * @return 在向对象池中归还对象时是否检测对象有效 */ - public boolean getTestOnReturn(){ + public boolean getTestOnReturn() { return testOnReturn; } @@ -372,7 +372,7 @@ public boolean getTestOnReturn(){ * @param testOnReturn * 在向对象池中归还对象时是否检测对象有效,配置 true 会降低性能 */ - public void setTestOnReturn(boolean testOnReturn){ + public void setTestOnReturn(boolean testOnReturn) { this.testOnReturn = testOnReturn; } @@ -381,7 +381,7 @@ public void setTestOnReturn(boolean testOnReturn){ * * @return 在检测空闲对象线程检测到对象不需要移除时,是否检测对象的有效性 */ - public boolean isTestWhileIdle(){ + public boolean isTestWhileIdle() { return getTestWhileIdle(); } @@ -390,7 +390,7 @@ public boolean isTestWhileIdle(){ * * @return 在检测空闲对象线程检测到对象不需要移除时,是否检测对象的有效性 */ - public boolean getTestWhileIdle(){ + public boolean getTestWhileIdle() { return testWhileIdle; } @@ -400,7 +400,7 @@ public boolean getTestWhileIdle(){ * @param testWhileIdle * 在检测空闲对象线程检测到对象不需要移除时,是否检测对象的有效性 */ - public void setTestWhileIdle(boolean testWhileIdle){ + public void setTestWhileIdle(boolean testWhileIdle) { this.testWhileIdle = testWhileIdle; } @@ -409,7 +409,7 @@ public void setTestWhileIdle(boolean testWhileIdle){ * * @return 空闲连接检测的周期,如果为负值,表示不运行检测线程 */ - public Duration getTimeBetweenEvictionRuns(){ + public Duration getTimeBetweenEvictionRuns() { return timeBetweenEvictionRuns; } @@ -419,7 +419,7 @@ public Duration getTimeBetweenEvictionRuns(){ * @param timeBetweenEvictionRuns * 空闲连接检测的周期 */ - public void setTimeBetweenEvictionRuns(Duration timeBetweenEvictionRuns){ + public void setTimeBetweenEvictionRuns(Duration timeBetweenEvictionRuns) { this.timeBetweenEvictionRuns = timeBetweenEvictionRuns; } @@ -428,7 +428,7 @@ public void setTimeBetweenEvictionRuns(Duration timeBetweenEvictionRuns){ * * @return 当对象池没有空闲对象时,新的获取对象的请求是否阻塞(true 阻塞,maxWaitMillis 才生效; false 连接池没有资源立马抛异常) */ - public boolean isBlockWhenExhausted(){ + public boolean isBlockWhenExhausted() { return getBlockWhenExhausted(); } @@ -437,7 +437,7 @@ public boolean isBlockWhenExhausted(){ * * @return 当对象池没有空闲对象时,新的获取对象的请求是否阻塞(true 阻塞,maxWaitMillis 才生效; false 连接池没有资源立马抛异常) */ - public boolean getBlockWhenExhausted(){ + public boolean getBlockWhenExhausted() { return blockWhenExhausted; } @@ -447,7 +447,7 @@ public boolean getBlockWhenExhausted(){ * @param blockWhenExhausted * 当对象池没有空闲对象时,新的获取对象的请求是否阻塞 */ - public void setBlockWhenExhausted(boolean blockWhenExhausted){ + public void setBlockWhenExhausted(boolean blockWhenExhausted) { this.blockWhenExhausted = blockWhenExhausted; } @@ -456,7 +456,7 @@ public void setBlockWhenExhausted(boolean blockWhenExhausted){ * * @return 是否注册 JMX */ - public boolean isJmxEnabled(){ + public boolean isJmxEnabled() { return getJmxEnabled(); } @@ -465,7 +465,7 @@ public boolean isJmxEnabled(){ * * @return 是否注册 JMX */ - public boolean getJmxEnabled(){ + public boolean getJmxEnabled() { return jmxEnabled; } @@ -475,7 +475,7 @@ public boolean getJmxEnabled(){ * @param jmxEnabled * 是否注册 JMX */ - public void setJmxEnabled(boolean jmxEnabled){ + public void setJmxEnabled(boolean jmxEnabled) { this.jmxEnabled = jmxEnabled; } @@ -484,7 +484,7 @@ public void setJmxEnabled(boolean jmxEnabled){ * * @return JMX 前缀 */ - public String getJmxNamePrefix(){ + public String getJmxNamePrefix() { return jmxNamePrefix; } @@ -494,15 +494,15 @@ public String getJmxNamePrefix(){ * @param jmxNamePrefix * JMX 前缀 */ - public void setJmxNamePrefix(String jmxNamePrefix){ + public void setJmxNamePrefix(String jmxNamePrefix) { this.jmxNamePrefix = jmxNamePrefix; } - public String getJmxNameBase(){ + public String getJmxNameBase() { return jmxNameBase; } - public void setJmxNameBase(String jmxNameBase){ + public void setJmxNameBase(String jmxNameBase) { this.jmxNameBase = jmxNameBase; } @@ -511,7 +511,7 @@ public void setJmxNameBase(String jmxNameBase){ * * @return 最大连接数 */ - public int getMaxTotal(){ + public int getMaxTotal() { return maxTotal; } @@ -521,7 +521,7 @@ public int getMaxTotal(){ * @param maxTotal * 最大连接数 */ - public void setMaxTotal(int maxTotal){ + public void setMaxTotal(int maxTotal) { this.maxTotal = maxTotal; } @@ -530,7 +530,7 @@ public void setMaxTotal(int maxTotal){ * * @return 最小空闲连接数 */ - public int getMinIdle(){ + public int getMinIdle() { return minIdle; } @@ -540,7 +540,7 @@ public int getMinIdle(){ * @param minIdle * 最小空闲连接数 */ - public void setMinIdle(int minIdle){ + public void setMinIdle(int minIdle) { this.minIdle = minIdle; } @@ -549,7 +549,7 @@ public void setMinIdle(int minIdle){ * * @return 最大空闲连接数 */ - public int getMaxIdle(){ + public int getMaxIdle() { return maxIdle; } @@ -559,8 +559,45 @@ public int getMaxIdle(){ * @param maxIdle * 最大空闲连接数 */ - public void setMaxIdle(int maxIdle){ + public void setMaxIdle(int maxIdle) { this.maxIdle = maxIdle; } + /** + * 转换为 jedis {@link GenericObjectPoolConfig} + * + * @param poolConfig + * {@link GenericObjectPoolConfig} 实例 + * @param + * {@link GenericObjectPoolConfig} 类型 + * + * @return {@link GenericObjectPoolConfig} 实例 + * + * @since 2.3.2 + */ + public GenericObjectPoolConfig toGenericObjectPoolConfig(final GenericObjectPoolConfig poolConfig) { + poolConfig.setLifo(getLifo()); + poolConfig.setFairness(getFairness()); + poolConfig.setMaxWait(getMaxWait()); + poolConfig.setMinEvictableIdleTime(getMinEvictableIdleTime()); + poolConfig.setSoftMinEvictableIdleTime(getSoftMinEvictableIdleTime()); + poolConfig.setEvictionPolicyClassName(getEvictionPolicyClassName()); + poolConfig.setEvictorShutdownTimeout(getEvictorShutdownTimeout()); + poolConfig.setNumTestsPerEvictionRun(getNumTestsPerEvictionRun()); + poolConfig.setTestOnCreate(getTestOnCreate()); + poolConfig.setTestOnBorrow(getTestOnBorrow()); + poolConfig.setTestOnReturn(getTestOnReturn()); + poolConfig.setTestWhileIdle(getTestWhileIdle()); + poolConfig.setTimeBetweenEvictionRuns(getTimeBetweenEvictionRuns()); + poolConfig.setBlockWhenExhausted(getBlockWhenExhausted()); + poolConfig.setJmxEnabled(getJmxEnabled()); + poolConfig.setJmxNamePrefix(getJmxNamePrefix()); + poolConfig.setJmxNameBase(getJmxNameBase()); + poolConfig.setMaxTotal(getMaxTotal()); + poolConfig.setMinIdle(getMinIdle()); + poolConfig.setMaxIdle(getMaxIdle()); + + return poolConfig; + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/RedisURI.java b/buession-redis/src/main/java/com/buession/redis/core/RedisURI.java index aebfa4e5a..3af7e8e74 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/RedisURI.java +++ b/buession-redis/src/main/java/com/buession/redis/core/RedisURI.java @@ -19,19 +19,18 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core; +import com.buession.core.builder.SetBuilder; import com.buession.core.utils.Assert; import com.buession.core.validator.Validate; import com.buession.net.AbstractUserInfoURI; import com.buession.net.AbstractUserInfoURIBuilder; import java.net.URI; -import java.util.Collections; -import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -56,7 +55,7 @@ public class RedisURI extends AbstractUserInfoURI { public final static String PARAMETER_NAME_TIMEOUT = "timeout"; - public final static Set ALLOWED_SCHEMES = new HashSet<>(); + public final static Set ALLOWED_SCHEMES = SetBuilder.create().add(REDIS).add(REDISS).build(); public final static int DEFAULT_TIMEOUT = 60; @@ -70,61 +69,57 @@ public class RedisURI extends AbstractUserInfoURI { private int timeout = DEFAULT_TIMEOUT; - static{ - Collections.addAll(ALLOWED_SCHEMES, REDIS, REDISS); - } - - public int getDatabase(){ + public int getDatabase() { return database; } - public void setDatabase(int database){ + public void setDatabase(int database) { this.database = database; } - public String getClientName(){ + public String getClientName() { return clientName; } - public void setClientName(String clientName){ + public void setClientName(String clientName) { this.clientName = clientName; } - public int getWeight(){ + public int getWeight() { return weight; } - public void setWeight(int weight){ + public void setWeight(int weight) { this.weight = weight; } - public int getTimeout(){ + public int getTimeout() { return timeout; } - public void setTimeout(int timeout){ + public void setTimeout(int timeout) { this.timeout = timeout; } @Override - public boolean isSsl(){ + public boolean isSsl() { return REDISS.equals(getScheme()); } - public boolean isUseSsl(){ + public boolean isUseSsl() { return isSsl(); } - public void setUseSsl(boolean useSsl){ + public void setUseSsl(boolean useSsl) { setUseSsl(useSsl); } - public static RedisURI create(String uri){ + public static RedisURI create(String uri) { Assert.isBlank(uri, "URI must not be null or empty."); return create(URI.create(uri)); } - public static RedisURI create(URI uri){ + public static RedisURI create(URI uri) { RedisURI redisURI = buildRedisUriFromUri(uri); redisURI.uri = uri; @@ -133,7 +128,7 @@ public static RedisURI create(URI uri){ } @Override - public String toString(){ + public String toString() { final StringBuilder sb = new StringBuilder(); sb.append(getClass().getSimpleName()); @@ -163,16 +158,15 @@ public String toString(){ } @Override - public URI toURI(){ + public URI toURI() { return this.uri; } - private static RedisURI buildRedisUriFromUri(URI uri){ + private static RedisURI buildRedisUriFromUri(URI uri) { Assert.isNull(uri, "URI must not be null"); - if(Validate.hasText(uri.getScheme()) && ALLOWED_SCHEMES.contains(uri.getScheme())){ - throw new IllegalArgumentException("Scheme " + uri.getScheme() + " not supported."); - } + Assert.isTrue(Validate.hasText(uri.getScheme()) && + ALLOWED_SCHEMES.contains(uri.getScheme()), "Scheme " + uri.getScheme() + " not supported."); Builder builder = Builder.getInstance(); @@ -221,29 +215,29 @@ public final static class Builder extends AbstractUserInfoURIBuilder { private String queryString; - private Builder(){ + private Builder() { super(); host(RedisNode.DEFAULT_HOST); port(RedisNode.DEFAULT_PORT); } - public static Builder getInstance(){ + public static Builder getInstance() { return new Builder(); } - public Builder database(final int database){ + public Builder database(final int database) { Assert.isNegative(database, "Invalid database number: " + database); this.database = database; return this; } - public Builder queryString(final String queryString){ + public Builder queryString(final String queryString) { this.queryString = queryString; return this; } @Override - public RedisURI build(){ + public RedisURI build() { RedisURI redisURI = new RedisURI(); redisURI.setHost(host); @@ -270,7 +264,7 @@ public RedisURI build(){ return redisURI; } - protected static void parseDatabase(final RedisURI redisURI, final String paramValue){ + private static void parseDatabase(final RedisURI redisURI, final String paramValue) { if(Validate.hasText(paramValue)){ int db = Integer.parseInt(paramValue); @@ -280,13 +274,13 @@ protected static void parseDatabase(final RedisURI redisURI, final String paramV } } - protected static void parseClientName(final RedisURI redisURI, final String paramValue){ + private static void parseClientName(final RedisURI redisURI, final String paramValue) { if(Validate.hasText(paramValue)){ redisURI.setClientName(paramValue); } } - protected static void parseWeight(final RedisURI redisURI, final String paramValue){ + private static void parseWeight(final RedisURI redisURI, final String paramValue) { if(Validate.hasText(paramValue)){ int weight = Integer.parseInt(paramValue); @@ -296,7 +290,7 @@ protected static void parseWeight(final RedisURI redisURI, final String paramVal } } - protected static void parseTimeout(final RedisURI redisURI, final String paramValue){ + private static void parseTimeout(final RedisURI redisURI, final String paramValue) { if(Validate.hasText(paramValue)){ int timeout = Integer.parseInt(paramValue); diff --git a/buession-redis/src/main/java/com/buession/redis/core/command/BitMapCommands.java b/buession-redis/src/main/java/com/buession/redis/core/command/BitMapCommands.java index 2f638bd3d..201340847 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/command/BitMapCommands.java +++ b/buession-redis/src/main/java/com/buession/redis/core/command/BitMapCommands.java @@ -398,7 +398,7 @@ public interface BitMapCommands extends RedisCommands { * @author Yong.Teng * @since 2.3.0 */ - class BitFieldArgument { + final class BitFieldArgument { private Op set; @@ -408,28 +408,28 @@ class BitFieldArgument { private Overflow overflow; - private BitFieldArgument(){ + private BitFieldArgument() { } - public Op getSet(){ + public Op getSet() { return set; } - public Op getGet(){ + public Op getGet() { return get; } - public Op getIncrBy(){ + public Op getIncrBy() { return incrBy; } - public Overflow getOverflow(){ + public Overflow getOverflow() { return overflow; } @Override - public String toString(){ + public String toString() { final StringBuilder builder = new StringBuilder(); if(set != null){ @@ -455,58 +455,58 @@ public static class Builder { private final BitFieldArgument bitFieldArgument = new BitFieldArgument(); - private Builder(){ + private Builder() { } - public static Builder create(){ + public static Builder create() { return new Builder(); } - public Builder set(BitFieldType bitFieldType, long value){ + public Builder set(BitFieldType bitFieldType, long value) { return set(bitFieldType, 0, value); } - public Builder set(BitFieldType bitFieldType, int offset, long value){ + public Builder set(BitFieldType bitFieldType, int offset, long value) { return set(bitFieldType, false, offset, value); } - public Builder set(BitFieldType bitFieldType, boolean bitOffset, int offset, long value){ + public Builder set(BitFieldType bitFieldType, boolean bitOffset, int offset, long value) { bitFieldArgument.set = new Op("SET", bitFieldType, bitOffset, offset, value); return this; } - public Builder get(BitFieldType bitFieldType, long value){ + public Builder get(BitFieldType bitFieldType, long value) { return get(bitFieldType, 0, value); } - public Builder get(BitFieldType bitFieldType, int offset, long value){ + public Builder get(BitFieldType bitFieldType, int offset, long value) { return get(bitFieldType, false, offset, value); } - public Builder get(BitFieldType bitFieldType, boolean bitOffset, int offset, long value){ + public Builder get(BitFieldType bitFieldType, boolean bitOffset, int offset, long value) { bitFieldArgument.get = new Op("GET", bitFieldType, bitOffset, offset, value); return this; } - public Builder incrBy(BitFieldType bitFieldType, long value){ + public Builder incrBy(BitFieldType bitFieldType, long value) { return incrBy(bitFieldType, 0, value); } - public Builder incrBy(BitFieldType bitFieldType, int offset, long value){ + public Builder incrBy(BitFieldType bitFieldType, int offset, long value) { return incrBy(bitFieldType, false, offset, value); } - public Builder incrBy(BitFieldType bitFieldType, boolean bitOffset, int offset, long value){ + public Builder incrBy(BitFieldType bitFieldType, boolean bitOffset, int offset, long value) { bitFieldArgument.get = new Op("INCRBY", bitFieldType, bitOffset, offset, value); return this; } - public Builder overflow(Overflow overflow){ + public Builder overflow(Overflow overflow) { bitFieldArgument.overflow = overflow; return this; } - public BitFieldArgument build(){ + public BitFieldArgument build() { return bitFieldArgument; } @@ -518,21 +518,21 @@ public final static class BitFieldType { private final int bits; - private BitFieldType(final boolean signed, final int bits){ + private BitFieldType(final boolean signed, final int bits) { this.signed = signed; this.bits = bits; } - public boolean isSigned(){ + public boolean isSigned() { return signed; } - public int getBits(){ + public int getBits() { return bits; } @Override - public String toString(){ + public String toString() { return (signed ? "i" : "u") + bits; } @@ -551,7 +551,7 @@ public final static class Op { private final long value; public Op(final String commandType, final BitFieldType bitFieldType, final boolean bitOffset, - final int offset, final long value){ + final int offset, final long value) { this.commandType = commandType; this.bitFieldType = bitFieldType; this.bitOffset = bitOffset; @@ -559,24 +559,24 @@ public Op(final String commandType, final BitFieldType bitFieldType, final boole this.value = value; } - public BitFieldType getBitFieldType(){ + public BitFieldType getBitFieldType() { return bitFieldType; } - public boolean isBitOffset(){ + public boolean isBitOffset() { return bitOffset; } - public int getOffset(){ + public int getOffset() { return offset; } - public long getValue(){ + public long getValue() { return value; } @Override - public String toString(){ + public String toString() { final StringBuilder sb = new StringBuilder(commandType); sb.append(" ").append(bitFieldType); diff --git a/buession-redis/src/main/java/com/buession/redis/core/command/ClusterCommands.java b/buession-redis/src/main/java/com/buession/redis/core/command/ClusterCommands.java index 77e6a9bbe..e66720904 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/command/ClusterCommands.java +++ b/buession-redis/src/main/java/com/buession/redis/core/command/ClusterCommands.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.command; diff --git a/buession-redis/src/main/java/com/buession/redis/core/command/CommandArguments.java b/buession-redis/src/main/java/com/buession/redis/core/command/CommandArguments.java index 6cdecb988..24adb4dee 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/command/CommandArguments.java +++ b/buession-redis/src/main/java/com/buession/redis/core/command/CommandArguments.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.command; @@ -30,58 +30,59 @@ import java.util.LinkedHashMap; import java.util.Map; +import java.util.Optional; /** * @author Yong.Teng */ -public class CommandArguments { +public final class CommandArguments { private final static String NIL = ""; private final Map parameters = new LinkedHashMap<>(); - private CommandArguments(){ + private CommandArguments() { } - private CommandArguments(final String key, final Object value){ + private CommandArguments(final String key, final Object value) { put(key, value); } - private CommandArguments(final String key, final Object... values){ + private CommandArguments(final String key, final Object... values) { put(key, values); } - public static CommandArguments create(){ + public static CommandArguments create() { return new CommandArguments(); } - public static CommandArguments create(final String key, final Object value){ + public static CommandArguments create(final String key, final Object value) { return new CommandArguments(key, value); } - public static CommandArguments create(final String key, final Object... values){ + public static CommandArguments create(final String key, final Object... values) { return new CommandArguments(key, values); } - public CommandArguments put(final String key, final Object value){ - parameters.put(key, value == null ? NIL : value.toString()); + public CommandArguments put(final String key, final Object value) { + parameters.put(key, Optional.ofNullable(value).orElse(NIL)); return this; } - public CommandArguments put(final String key, final Object... values){ + public CommandArguments put(final String key, final Object... values) { parameters.put(key, values == null ? NIL : Arrays.toString(values)); return this; } - public Map getParameters(){ + public Map getParameters() { return parameters; } - public Map build(){ + public Map build() { return getParameters(); } - public String asString(){ + public String asString() { if(Validate.isEmpty(getParameters())){ return Constants.EMPTY_STRING; }else{ @@ -100,7 +101,7 @@ public String asString(){ } @Override - public String toString(){ + public String toString() { return asString(); } diff --git a/buession-redis/src/main/java/com/buession/redis/core/command/ConnectionCommands.java b/buession-redis/src/main/java/com/buession/redis/core/command/ConnectionCommands.java index 177078491..e58fa8530 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/command/ConnectionCommands.java +++ b/buession-redis/src/main/java/com/buession/redis/core/command/ConnectionCommands.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.command; diff --git a/buession-redis/src/main/java/com/buession/redis/core/command/GeoCommands.java b/buession-redis/src/main/java/com/buession/redis/core/command/GeoCommands.java index 30bebca6a..938f31631 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/command/GeoCommands.java +++ b/buession-redis/src/main/java/com/buession/redis/core/command/GeoCommands.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.command; @@ -569,7 +569,7 @@ List geoRadiusByMemberRo(final byte[] key, final byte[] member, final /** * GEO 参数 */ - class GeoRadiusArgument { + final class GeoRadiusArgument { private Boolean withCoord; @@ -581,7 +581,7 @@ class GeoRadiusArgument { private Integer count; - private GeoRadiusArgument(){ + private GeoRadiusArgument() { } /** @@ -589,7 +589,7 @@ private GeoRadiusArgument(){ * * @return 是否将位置元素的经度和维度也一并返回 */ - public Boolean isWithCoord(){ + public Boolean isWithCoord() { return withCoord; } @@ -598,7 +598,7 @@ public Boolean isWithCoord(){ * * @return 是否在返回位置元素的同时,将位置元素与中心之间的距离也一并返回 */ - public Boolean isWithDist(){ + public Boolean isWithDist() { return withDist; } @@ -607,7 +607,7 @@ public Boolean isWithDist(){ * * @return 是否返回位置元素经过原始 geohash 编码的有序集合分值 */ - public Boolean isWithHash(){ + public Boolean isWithHash() { return withHash; } @@ -616,7 +616,7 @@ public Boolean isWithHash(){ * * @return 排序方式 */ - public Order getOrder(){ + public Order getOrder() { return order; } @@ -625,12 +625,12 @@ public Order getOrder(){ * * @return 返回数量 */ - public Integer getCount(){ + public Integer getCount() { return count; } @Override - public String toString(){ + public String toString() { return ObjectStringBuilder.create(). add("withCoord", withCoord). add("withDist", withDist). @@ -643,10 +643,10 @@ public static class Builder { private final GeoRadiusArgument geoRadiusArgument = new GeoRadiusArgument(); - private Builder(){ + private Builder() { } - public static Builder create(){ + public static Builder create() { return new Builder(); } @@ -655,7 +655,7 @@ public static Builder create(){ * * @return Builder */ - public Builder withCoord(){ + public Builder withCoord() { geoRadiusArgument.withCoord = true; return this; } @@ -665,7 +665,7 @@ public Builder withCoord(){ * * @return Builder */ - public Builder withDist(){ + public Builder withDist() { geoRadiusArgument.withDist = true; return this; } @@ -675,7 +675,7 @@ public Builder withDist(){ * * @return Builder */ - public Builder withHash(){ + public Builder withHash() { geoRadiusArgument.withHash = true; return this; } @@ -688,7 +688,7 @@ public Builder withHash(){ * * @return Builder */ - public Builder order(Order order){ + public Builder order(Order order) { geoRadiusArgument.order = order; return this; } @@ -701,12 +701,12 @@ public Builder order(Order order){ * * @return Builder */ - public Builder count(Integer count){ + public Builder count(Integer count) { geoRadiusArgument.count = count; return this; } - public GeoRadiusArgument build(){ + public GeoRadiusArgument build() { return geoRadiusArgument; } diff --git a/buession-redis/src/main/java/com/buession/redis/core/command/KeyCommands.java b/buession-redis/src/main/java/com/buession/redis/core/command/KeyCommands.java index 48d49a5ef..11287affe 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/command/KeyCommands.java +++ b/buession-redis/src/main/java/com/buession/redis/core/command/KeyCommands.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.command; @@ -1498,7 +1498,7 @@ class RestoreArgument { private Long frequency; - private RestoreArgument(){ + private RestoreArgument() { } /** @@ -1506,7 +1506,7 @@ private RestoreArgument(){ * * @return 是否替换已存在 key */ - public Boolean isReplace(){ + public Boolean isReplace() { return replace; } @@ -1517,20 +1517,20 @@ public Boolean isReplace(){ * @return If the ABSTTL modifier was used, * ttl should represent an absolute Unix timestamp (in milliseconds) in which the key will expire */ - public Boolean isAbsTtl(){ + public Boolean isAbsTtl() { return absTtl; } - public Long getIdleTime(){ + public Long getIdleTime() { return idleTime; } - public Long getFrequency(){ + public Long getFrequency() { return frequency; } @Override - public String toString(){ + public String toString() { return ObjectStringBuilder.create(). add("replace", replace). add("absTtl", absTtl). @@ -1542,34 +1542,34 @@ public static class Builder { private final RestoreArgument restoreArgument = new RestoreArgument(); - private Builder(){ + private Builder() { } - public static Builder create(){ + public static Builder create() { return new Builder(); } - public Builder replace(){ + public Builder replace() { restoreArgument.replace = true; return this; } - public Builder absTtl(){ + public Builder absTtl() { restoreArgument.absTtl = true; return this; } - public Builder idleTime(long idleTime){ + public Builder idleTime(long idleTime) { restoreArgument.idleTime = idleTime; return this; } - public Builder frequency(long frequency){ + public Builder frequency(long frequency) { restoreArgument.frequency = frequency; return this; } - public RestoreArgument build(){ + public RestoreArgument build() { return restoreArgument; } @@ -1582,7 +1582,7 @@ public RestoreArgument build(){ * * @author Yong.Teng */ - class SortArgument { + final class SortArgument { private byte[] by; @@ -1594,7 +1594,7 @@ class SortArgument { private Boolean alpha; - private SortArgument(){ + private SortArgument() { } /** @@ -1602,7 +1602,7 @@ private SortArgument(){ * * @return 可以让 uid 按其他键的元素来排序模式 */ - public byte[] getBy(){ + public byte[] getBy() { return by; } @@ -1611,7 +1611,7 @@ public byte[] getBy(){ * * @return 排序方式 */ - public Order getOrder(){ + public Order getOrder() { return order; } @@ -1620,7 +1620,7 @@ public Order getOrder(){ * * @return 返回结果限制 */ - public Limit getLimit(){ + public Limit getLimit() { return limit; } @@ -1629,7 +1629,7 @@ public Limit getLimit(){ * * @return 通过外部 key 排序模式 */ - public byte[][] getGetPatterns(){ + public byte[][] getGetPatterns() { return getPatterns; } @@ -1638,12 +1638,12 @@ public byte[][] getGetPatterns(){ * * @return 使用对字符串进行排序 */ - public Boolean isAlpha(){ + public Boolean isAlpha() { return alpha; } @Override - public String toString(){ + public String toString() { final ObjectStringBuilder builder = ObjectStringBuilder.create(); if(by != null){ @@ -1665,10 +1665,10 @@ public static class Builder { private final SortArgument sortArgument = new SortArgument(); - private Builder(){ + private Builder() { } - public static Builder create(){ + public static Builder create() { return new Builder(); } @@ -1680,7 +1680,7 @@ public static Builder create(){ * * @return Builder */ - public Builder by(String pattern){ + public Builder by(String pattern) { sortArgument.by = SafeEncoder.encode(pattern); return this; } @@ -1693,7 +1693,7 @@ public Builder by(String pattern){ * * @return Builder */ - public Builder by(byte[] pattern){ + public Builder by(byte[] pattern) { sortArgument.by = pattern; return this; } @@ -1703,7 +1703,7 @@ public Builder by(byte[] pattern){ * * @return Builder */ - public Builder asc(){ + public Builder asc() { sortArgument.order = Order.ASC; return this; } @@ -1713,7 +1713,7 @@ public Builder asc(){ * * @return Builder */ - public Builder desc(){ + public Builder desc() { sortArgument.order = Order.DESC; return this; } @@ -1726,7 +1726,7 @@ public Builder desc(){ * * @return Builder */ - public Builder order(Order order){ + public Builder order(Order order) { sortArgument.order = order; return this; } @@ -1741,7 +1741,7 @@ public Builder order(Order order){ * * @return Builder */ - public Builder limit(long offset, long count){ + public Builder limit(long offset, long count) { sortArgument.limit = new Limit(offset, count); return this; } @@ -1754,7 +1754,7 @@ public Builder limit(long offset, long count){ * * @return Builder */ - public Builder getPatterns(byte[]... patterns){ + public Builder getPatterns(byte[]... patterns) { sortArgument.getPatterns = patterns; return this; } @@ -1767,7 +1767,7 @@ public Builder getPatterns(byte[]... patterns){ * * @return Builder */ - public Builder getPatterns(String... patterns){ + public Builder getPatterns(String... patterns) { if(patterns != null){ sortArgument.getPatterns = new byte[patterns.length][]; @@ -1784,12 +1784,12 @@ public Builder getPatterns(String... patterns){ * * @return 使用对字符串进行排序 */ - public Builder alpha(){ + public Builder alpha() { sortArgument.alpha = true; return this; } - public SortArgument build(){ + public SortArgument build() { return sortArgument; } diff --git a/buession-redis/src/main/java/com/buession/redis/core/command/ListCommands.java b/buession-redis/src/main/java/com/buession/redis/core/command/ListCommands.java index a6222ea6a..6587602d7 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/command/ListCommands.java +++ b/buession-redis/src/main/java/com/buession/redis/core/command/ListCommands.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.command; @@ -732,25 +732,25 @@ public interface ListCommands extends RedisCommands { */ Long rPushX(final byte[] key, final byte[]... values); - class LPosArgument { + final class LPosArgument { private Integer rank; private Integer maxLen; - private LPosArgument(){ + private LPosArgument() { } - public Integer getRank(){ + public Integer getRank() { return rank; } - public Integer getMaxLen(){ + public Integer getMaxLen() { return maxLen; } @Override - public String toString(){ + public String toString() { return ObjectStringBuilder.create().add("rank", rank).add("maxLen", maxLen).build(); } @@ -758,24 +758,24 @@ public static class Builder { private final LPosArgument lPosArgument = new LPosArgument(); - private Builder(){ + private Builder() { } - public static Builder create(){ + public static Builder create() { return new Builder(); } - public Builder rank(int rank){ + public Builder rank(int rank) { lPosArgument.rank = rank; return this; } - public Builder maxLen(int maxLen){ + public Builder maxLen(int maxLen) { lPosArgument.maxLen = maxLen; return this; } - public LPosArgument build(){ + public LPosArgument build() { return lPosArgument; } diff --git a/buession-redis/src/main/java/com/buession/redis/core/command/ProtocolCommandGroup.java b/buession-redis/src/main/java/com/buession/redis/core/command/ProtocolCommandGroup.java index 1a849099c..31431f54e 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/command/ProtocolCommandGroup.java +++ b/buession-redis/src/main/java/com/buession/redis/core/command/ProtocolCommandGroup.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.command; @@ -31,50 +31,98 @@ */ public enum ProtocolCommandGroup { + /** + * 位图命令 + */ BITMAP("BitMap"), + /** + * 集群命令 + */ CLUSTER("Cluster"), + /** + * 连接命令 + */ CONNECTION("Connection"), + /** + * 地理位置命令 + */ GEO("Geo"), + /** + * 哈希命令 + */ HASH("Hash"), + /** + * HyperLogLog 命令 + */ HYPERLOGLOG("HyperLogLog"), + /** + * 键命令 + */ KEY("Key"), + /** + * 列表命令 + */ LIST("List"), + /** + * 发布订阅命令 + */ PUBSUB("PubSub"), + /** + * 脚本命令 + */ SCRIPTING("Scripting"), + /** + * 服务器命令 + */ SERVER("Server"), + /** + * 集合命令 + */ SET("Set"), + /** + * 有序集合命令 + */ SORTEDSET("Sorted Set"), + /** + * 流命令 + */ STREAM("Stream"), + /** + * 字符串命令 + */ STRING("String"), + /** + * 事务命令 + */ TRANSACTION("Transaction"); private final String value; - ProtocolCommandGroup(final String value){ + ProtocolCommandGroup(final String value) { this.value = value; } - public String getValue(){ + public String getValue() { return value; } @Override - public String toString(){ + public String toString() { return value; } diff --git a/buession-redis/src/main/java/com/buession/redis/core/command/SortedSetCommands.java b/buession-redis/src/main/java/com/buession/redis/core/command/SortedSetCommands.java index cba7a21fe..97389b1d2 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/command/SortedSetCommands.java +++ b/buession-redis/src/main/java/com/buession/redis/core/command/SortedSetCommands.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.command; diff --git a/buession-redis/src/main/java/com/buession/redis/core/command/StreamCommands.java b/buession-redis/src/main/java/com/buession/redis/core/command/StreamCommands.java index 3235d0eb9..b238b5286 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/command/StreamCommands.java +++ b/buession-redis/src/main/java/com/buession/redis/core/command/StreamCommands.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.command; @@ -173,8 +173,8 @@ StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map> xAutoClaim(final String key, final String groupName, - final String consumerName, - final int minIdleTime, final StreamEntryId start); + final String consumerName, final int minIdleTime, + final StreamEntryId start); /** * This command transfers ownership of pending stream entries that match the specified criteria @@ -195,8 +195,8 @@ Map> xAutoClaim(final String key, final String * @return {@link StreamEntryId} 和对应的 {@link StreamEntry} */ Map> xAutoClaim(final byte[] key, final byte[] groupName, - final byte[] consumerName, - final int minIdleTime, final StreamEntryId start); + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start); /** * This command transfers ownership of pending stream entries that match the specified criteria @@ -1772,7 +1772,7 @@ List>> xReadGroup(final byte[] groupName, final by */ Long xTrim(final byte[] key, final XTrimArgument xTrimArgument, final long limit); - class XAddArgument { + final class XAddArgument { private Long maxLen; @@ -1786,35 +1786,35 @@ class XAddArgument { private Long limit; - private XAddArgument(){ + private XAddArgument() { } - public Long getMaxLen(){ + public Long getMaxLen() { return maxLen; } - public Boolean isApproximateTrimming(){ + public Boolean isApproximateTrimming() { return approximateTrimming; } - public Boolean isExactTrimming(){ + public Boolean isExactTrimming() { return exactTrimming; } - public Boolean isNoMkStream(){ + public Boolean isNoMkStream() { return noMkStream; } - public String getMinId(){ + public String getMinId() { return minId; } - public Long getLimit(){ + public Long getLimit() { return limit; } @Override - public String toString(){ + public String toString() { return ObjectStringBuilder.create(). add("maxLen", maxLen). add("approximateTrimming", approximateTrimming). @@ -1828,44 +1828,44 @@ public static class Builder { private final XAddArgument xAddArgument = new XAddArgument(); - private Builder(){ + private Builder() { } - public static Builder create(){ + public static Builder create() { return new Builder(); } - public Builder maxLen(long maxLen){ + public Builder maxLen(long maxLen) { xAddArgument.maxLen = maxLen; return this; } - public Builder approximateTrimming(Boolean approximateTrimming){ + public Builder approximateTrimming(Boolean approximateTrimming) { xAddArgument.approximateTrimming = approximateTrimming; return this; } - public Builder exactTrimming(boolean exactTrimming){ + public Builder exactTrimming(boolean exactTrimming) { xAddArgument.exactTrimming = exactTrimming; return this; } - public Builder noMkStream(boolean noMkStream){ + public Builder noMkStream(boolean noMkStream) { xAddArgument.noMkStream = noMkStream; return this; } - public Builder minId(String minId){ + public Builder minId(String minId) { xAddArgument.minId = minId; return this; } - public Builder limit(Long limit){ + public Builder limit(Long limit) { xAddArgument.limit = limit; return this; } - public XAddArgument build(){ + public XAddArgument build() { return xAddArgument; } @@ -1873,7 +1873,7 @@ public XAddArgument build(){ } - class XClaimArgument { + final class XClaimArgument { private Long idleTime; @@ -1883,27 +1883,27 @@ class XClaimArgument { private Boolean force; - private XClaimArgument(){ + private XClaimArgument() { } - public Long getIdleTime(){ + public Long getIdleTime() { return idleTime; } - public Long getIdleUnixTime(){ + public Long getIdleUnixTime() { return idleUnixTime; } - public Integer getRetryCount(){ + public Integer getRetryCount() { return retryCount; } - public Boolean isForce(){ + public Boolean isForce() { return force; } @Override - public String toString(){ + public String toString() { return ObjectStringBuilder.create(). add("idleTime", idleTime). add("idleUnixTime", idleUnixTime). @@ -1915,34 +1915,34 @@ public final static class Builder { private final XClaimArgument xClaimArgument = new XClaimArgument(); - private Builder(){ + private Builder() { } - public static Builder create(){ + public static Builder create() { return new Builder(); } - public Builder idleTime(long idleTime){ + public Builder idleTime(long idleTime) { xClaimArgument.idleTime = idleTime; return this; } - public Builder idleUnixTime(long idleUnixTime){ + public Builder idleUnixTime(long idleUnixTime) { xClaimArgument.idleUnixTime = idleUnixTime; return this; } - public Builder retryCount(int retryCount){ + public Builder retryCount(int retryCount) { xClaimArgument.retryCount = retryCount; return this; } - public Builder force(boolean force){ + public Builder force(boolean force) { xClaimArgument.force = force; return this; } - public XClaimArgument build(){ + public XClaimArgument build() { return xClaimArgument; } @@ -1960,27 +1960,27 @@ class XTrimArgument { private String minId; - private XTrimArgument(){ + private XTrimArgument() { } - public Long getMaxLen(){ + public Long getMaxLen() { return maxLen; } - public Boolean isApproximateTrimming(){ + public Boolean isApproximateTrimming() { return approximateTrimming; } - public Boolean isExactTrimming(){ + public Boolean isExactTrimming() { return exactTrimming; } - public String getMinId(){ + public String getMinId() { return minId; } @Override - public String toString(){ + public String toString() { return ObjectStringBuilder.create(). add("maxLen", maxLen). add("approximateTrimming", approximateTrimming). @@ -1992,34 +1992,34 @@ public final static class Builder { private final XTrimArgument xTrimArgument = new XTrimArgument(); - private Builder(){ + private Builder() { } - public static Builder create(){ + public static Builder create() { return new Builder(); } - public Builder maxLen(long maxLen){ + public Builder maxLen(long maxLen) { xTrimArgument.maxLen = maxLen; return this; } - public Builder approximateTrimming(boolean approximateTrimming){ + public Builder approximateTrimming(boolean approximateTrimming) { xTrimArgument.approximateTrimming = approximateTrimming; return this; } - public Builder exactTrimming(boolean exactTrimming){ + public Builder exactTrimming(boolean exactTrimming) { xTrimArgument.exactTrimming = exactTrimming; return this; } - public Builder minId(String minId){ + public Builder minId(String minId) { xTrimArgument.minId = minId; return this; } - public XTrimArgument build(){ + public XTrimArgument build() { return xTrimArgument; } diff --git a/buession-redis/src/main/java/com/buession/redis/core/command/StringCommands.java b/buession-redis/src/main/java/com/buession/redis/core/command/StringCommands.java index 623cb126f..bbb2d230d 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/command/StringCommands.java +++ b/buession-redis/src/main/java/com/buession/redis/core/command/StringCommands.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.command; @@ -640,7 +640,7 @@ public interface StringCommands extends RedisCommands { */ byte[] substr(final byte[] key, final long start, final long end); - class SetArgument { + final class SetArgument { private Long ex; @@ -654,7 +654,7 @@ class SetArgument { private Boolean keepTtl; - private SetArgument(){ + private SetArgument() { } /** @@ -662,7 +662,7 @@ private SetArgument(){ * * @return 设置的键过期时间 */ - public Long getEx(){ + public Long getEx() { return ex; } @@ -671,7 +671,7 @@ public Long getEx(){ * * @return 设置的键过期时间戳 */ - public Long getExAt(){ + public Long getExAt() { return exAt; } @@ -680,7 +680,7 @@ public Long getExAt(){ * * @return 设置的键过期时间 */ - public Long getPx(){ + public Long getPx() { return px; } @@ -689,7 +689,7 @@ public Long getPx(){ * * @return 设置的键过期时间戳 */ - public Long getPxAt(){ + public Long getPxAt() { return pxAt; } @@ -698,7 +698,7 @@ public Long getPxAt(){ * * @return 设置键的条件 */ - public NxXx getNxXx(){ + public NxXx getNxXx() { return nxXx; } @@ -707,7 +707,7 @@ public NxXx getNxXx(){ * * @return the time to live associated with the key */ - public Boolean isKeepTtl(){ + public Boolean isKeepTtl() { return keepTtl; } @@ -715,10 +715,10 @@ public static class Builder { private final SetArgument setArgument = new SetArgument(); - private Builder(){ + private Builder() { } - public static Builder create(){ + public static Builder create() { return new Builder(); } @@ -730,7 +730,7 @@ public static Builder create(){ * * @return Builder */ - public Builder ex(long lifetime){ + public Builder ex(long lifetime) { setArgument.ex = lifetime; return this; } @@ -743,7 +743,7 @@ public Builder ex(long lifetime){ * * @return Builder */ - public Builder exAt(long seconds){ + public Builder exAt(long seconds) { setArgument.exAt = seconds; return this; } @@ -756,7 +756,7 @@ public Builder exAt(long seconds){ * * @return Builder */ - public Builder exAt(Date date){ + public Builder exAt(Date date) { if(date != null){ setArgument.exAt = date.getTime() / 1000; } @@ -772,7 +772,7 @@ public Builder exAt(Date date){ * * @return Builder */ - public Builder px(long lifetime){ + public Builder px(long lifetime) { setArgument.px = lifetime; return this; } @@ -785,7 +785,7 @@ public Builder px(long lifetime){ * * @return Builder */ - public Builder pxAt(long milliseconds){ + public Builder pxAt(long milliseconds) { setArgument.pxAt = milliseconds; return this; } @@ -798,7 +798,7 @@ public Builder pxAt(long milliseconds){ * * @return Builder */ - public Builder pxAt(Date date){ + public Builder pxAt(Date date) { if(date != null){ setArgument.exAt = date.getTime(); } @@ -814,7 +814,7 @@ public Builder pxAt(Date date){ * * @return Builder */ - public Builder nxXX(NxXx nxXx){ + public Builder nxXX(NxXx nxXx) { setArgument.nxXx = nxXx; return this; } @@ -822,12 +822,12 @@ public Builder nxXX(NxXx nxXx){ /** * @return Builder */ - public Builder keepTtl(){ + public Builder keepTtl() { setArgument.keepTtl = true; return this; } - public SetArgument build(){ + public SetArgument build() { return setArgument; } @@ -835,7 +835,7 @@ public SetArgument build(){ } - class GetExArgument { + final class GetExArgument { private Long ex; @@ -847,7 +847,7 @@ class GetExArgument { private Boolean persist; - private GetExArgument(){ + private GetExArgument() { } /** @@ -855,7 +855,7 @@ private GetExArgument(){ * * @return 设置的键过期时间 */ - public Long getEx(){ + public Long getEx() { return ex; } @@ -864,7 +864,7 @@ public Long getEx(){ * * @return 设置的键过期时间戳 */ - public Long getExAt(){ + public Long getExAt() { return exAt; } @@ -873,7 +873,7 @@ public Long getExAt(){ * * @return 设置的键过期时间 */ - public Long getPx(){ + public Long getPx() { return px; } @@ -882,7 +882,7 @@ public Long getPx(){ * * @return 设置的键过期时间戳 */ - public Long getPxAt(){ + public Long getPxAt() { return pxAt; } @@ -891,12 +891,12 @@ public Long getPxAt(){ * * @return 设置键是否持久化 */ - public Boolean isPersist(){ + public Boolean isPersist() { return persist; } @Override - public String toString(){ + public String toString() { return ObjectStringBuilder.create(). add("ex", ex). add("exAt", exAt). @@ -909,10 +909,10 @@ public static class Builder { private final GetExArgument getExArgument = new GetExArgument(); - private Builder(){ + private Builder() { } - public static Builder create(){ + public static Builder create() { return new Builder(); } @@ -924,7 +924,7 @@ public static Builder create(){ * * @return Builder */ - public Builder ex(long lifetime){ + public Builder ex(long lifetime) { getExArgument.ex = lifetime; return this; } @@ -937,7 +937,7 @@ public Builder ex(long lifetime){ * * @return Builder */ - public Builder exAt(long lifetime){ + public Builder exAt(long lifetime) { getExArgument.exAt = lifetime; return this; } @@ -950,7 +950,7 @@ public Builder exAt(long lifetime){ * * @return Builder */ - public Builder exAt(Date date){ + public Builder exAt(Date date) { if(date != null){ getExArgument.exAt = date.getTime() / 1000; } @@ -966,7 +966,7 @@ public Builder exAt(Date date){ * * @return Builder */ - public Builder px(long lifetime){ + public Builder px(long lifetime) { getExArgument.px = lifetime; return this; } @@ -979,7 +979,7 @@ public Builder px(long lifetime){ * * @return Builder */ - public Builder pxAt(long lifetime){ + public Builder pxAt(long lifetime) { getExArgument.pxAt = lifetime; return this; } @@ -992,7 +992,7 @@ public Builder pxAt(long lifetime){ * * @return Builder */ - public Builder pxAt(Date date){ + public Builder pxAt(Date date) { if(date != null){ getExArgument.pxAt = date.getTime(); } @@ -1008,12 +1008,12 @@ public Builder pxAt(Date date){ * * @return Builder */ - public Builder persist(Boolean persist){ + public Builder persist(Boolean persist) { getExArgument.persist = persist; return this; } - public GetExArgument build(){ + public GetExArgument build() { return getExArgument; } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/GetExArgumentConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/GetExArgumentConverter.java index 0d0a43641..e21393835 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/GetExArgumentConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/GetExArgumentConverter.java @@ -19,12 +19,13 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.params; import com.buession.core.converter.Converter; +import com.buession.core.converter.mapper.PropertyMapper; import com.buession.redis.core.command.StringCommands; import redis.clients.jedis.params.GetExParams; @@ -39,24 +40,14 @@ public final class GetExArgumentConverter implements Converter | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.params; import com.buession.core.converter.Converter; +import com.buession.core.converter.mapper.PropertyMapper; import com.buession.redis.core.command.ListCommands; import redis.clients.jedis.params.LPosParams; @@ -39,16 +40,12 @@ public final class LPosArgumentConverter implements Converter | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.params; import com.buession.core.converter.Converter; +import com.buession.core.converter.mapper.PropertyMapper; import com.buession.redis.core.command.KeyCommands; import redis.clients.jedis.params.RestoreParams; @@ -39,7 +40,8 @@ public final class RestoreArgumentConverter implements Converter | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.params; import com.buession.core.converter.Converter; +import com.buession.core.converter.mapper.PropertyMapper; import com.buession.lang.Order; import com.buession.redis.core.Limit; import com.buession.redis.core.command.KeyCommands; @@ -41,12 +42,12 @@ public final class SortArgumentConverter implements Converter | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.params; import com.buession.core.converter.Converter; +import com.buession.core.converter.mapper.PropertyMapper; import com.buession.redis.core.command.StreamCommands; import redis.clients.jedis.params.XAddParams; @@ -39,12 +40,13 @@ public final class XAddArgumentConverter implements Converter | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.params; import com.buession.core.converter.Converter; +import com.buession.core.converter.mapper.PropertyMapper; import com.buession.redis.core.command.StreamCommands; import redis.clients.jedis.params.XClaimParams; @@ -37,20 +38,13 @@ public final class XClaimArgumentConverter implements Converter | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.params; import com.buession.core.converter.Converter; +import com.buession.core.converter.mapper.PropertyMapper; import com.buession.redis.core.command.StreamCommands; import redis.clients.jedis.params.XTrimParams; @@ -39,12 +40,12 @@ public class XTrimArgumentConverter implements Converter | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; -import com.buession.beans.BeanUtils; +import com.buession.beans.BeanConverter; +import com.buession.beans.DefaultBeanConverter; import com.buession.core.converter.Converter; import com.buession.core.converter.ListConverter; import com.buession.redis.core.AclLog; @@ -45,10 +46,11 @@ public final class AccessControlLogEntryConverter implements Converter | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; @@ -48,7 +48,7 @@ public final class ClusterReplicasConverter implements Converter LIST_CONVERTER = new ListConverter<>(INSTANCE); @Override - public ClusterRedisNode convert(final String source){ + public ClusterRedisNode convert(final String source) { String[] values = StringUtils.split(source, " "); String[] hostAndPort = StringUtils.split(values[1], ":"); String host = hostAndPort[0]; @@ -64,7 +64,7 @@ public ClusterRedisNode convert(final String source){ SlotRange slotRange = null; if(values.length == 9){ - String[] slotRangeValues = StringUtils.split(values[8], "-"); + String[] slotRangeValues = StringUtils.split(values[8], '-'); slotRange = new SlotRange(Integer.parseInt(slotRangeValues[0]), Integer.parseInt(slotRangeValues[1])); } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/InfoConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/InfoConverter.java index 12e598133..6ac13d85d 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/InfoConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/InfoConverter.java @@ -37,7 +37,6 @@ import com.buession.redis.core.RedisMode; import com.buession.redis.core.RedisNode; import com.buession.redis.core.Role; -import com.buession.redis.utils.ResponseUtils; import org.springframework.lang.Nullable; import java.util.ArrayList; @@ -59,7 +58,7 @@ public class InfoConverter implements Converter { public final static InfoConverter INSTANCE = new InfoConverter(); @Override - public Info convert(final String source){ + public Info convert(final String source) { Info.Server server = null; Info.Clients clients = null; Info.Memory memory = null; @@ -119,14 +118,18 @@ private interface Parser { @Nullable V parse(final String str); + default String[] parseRows(final String str) { + return StringUtils.split(str, "\r\n"); + } + } private final static class ServerParser implements Parser { @Override - public Info.Server parse(final String str){ + public Info.Server parse(final String str) { Uptime uptime = new Uptime(); - String[] rows = ResponseUtils.parseRows(str); + String[] rows = parseRows(str); Properties properties = new Properties(); KeyValueParser keyValueParser; @@ -169,8 +172,8 @@ public Info.Server parse(final String str){ private final static class ClientsParser implements Parser { @Override - public Info.Clients parse(final String str){ - String[] rows = ResponseUtils.parseRows(str); + public Info.Clients parse(final String str) { + String[] rows = parseRows(str); Properties properties = new Properties(); KeyValueParser keyValueParser; @@ -187,8 +190,8 @@ public Info.Clients parse(final String str){ private final static class MemoryParser implements Parser { @Override - public Info.Memory parse(final String str){ - String[] rows = ResponseUtils.parseRows(str); + public Info.Memory parse(final String str) { + String[] rows = parseRows(str); Properties properties = new Properties(); KeyValueParser keyValueParser; @@ -211,8 +214,8 @@ public Info.Memory parse(final String str){ private final static class PersistenceParser implements Parser { @Override - public Info.Persistence parse(final String str){ - String[] rows = ResponseUtils.parseRows(str); + public Info.Persistence parse(final String str) { + String[] rows = parseRows(str); Properties properties = new Properties(); KeyValueParser keyValueParser; @@ -238,8 +241,8 @@ public Info.Persistence parse(final String str){ private final static class StatsParser implements Parser { @Override - public Info.Stats parse(final String str){ - String[] rows = ResponseUtils.parseRows(str); + public Info.Stats parse(final String str) { + String[] rows = parseRows(str); Properties properties = new Properties(); KeyValueParser keyValueParser; @@ -258,8 +261,8 @@ private final static class ReplicationParser implements Parser private final static Pattern SLAVE_PATTERN = Pattern.compile("slave\\d"); @Override - public Info.Replication parse(final String str){ - String[] rows = ResponseUtils.parseRows(str); + public Info.Replication parse(final String str) { + String[] rows = parseRows(str); Properties properties = new Properties(); Properties replBackLogProperties = null; String masterHost = null; @@ -331,7 +334,7 @@ public Info.Replication parse(final String str){ return new Info.Replication(properties); } - private static Info.Replication.Slave parseSlave(final String str){ + private static Info.Replication.Slave parseSlave(final String str) { String[] groups = StringUtils.splitByWholeSeparatorPreserveAllTokens(str, ","); Properties properties = new Properties(); KeyValueParser keyValueParser; @@ -355,8 +358,8 @@ private static Info.Replication.Slave parseSlave(final String str){ private final static class CpuParser implements Parser { @Override - public Info.Cpu parse(final String str){ - String[] rows = ResponseUtils.parseRows(str); + public Info.Cpu parse(final String str) { + String[] rows = parseRows(str); Properties properties = new Properties(); KeyValueParser keyValueParser; @@ -373,8 +376,8 @@ public Info.Cpu parse(final String str){ private final static class ClusterParser implements Parser { @Override - public Info.Cluster parse(final String str){ - String[] rows = ResponseUtils.parseRows(str); + public Info.Cluster parse(final String str) { + String[] rows = parseRows(str); Properties properties = new Properties(); KeyValueParser keyValueParser; @@ -393,8 +396,8 @@ private final static class SentinelParser implements Parser { private final static Pattern MASTER_PATTERN = Pattern.compile("master\\d"); @Override - public Info.Sentinel parse(final String str){ - String[] rows = ResponseUtils.parseRows(str); + public Info.Sentinel parse(final String str) { + String[] rows = parseRows(str); Properties properties = new Properties(); List masters = null; KeyValueParser keyValueParser; @@ -415,7 +418,7 @@ public Info.Sentinel parse(final String str){ return new Info.Sentinel(properties); } - private static Info.Sentinel.Master parseMaster(final String str){ + private static Info.Sentinel.Master parseMaster(final String str) { String[] groups = StringUtils.splitByWholeSeparatorPreserveAllTokens(str, ","); Properties properties = new Properties(); KeyValueParser keyValueParser; @@ -443,8 +446,8 @@ private static Info.Sentinel.Master parseMaster(final String str){ private final static class KeyspaceParser implements Parser> { @Override - public List parse(final String str){ - String[] rows = ResponseUtils.parseRows(str); + public List parse(final String str) { + String[] rows = parseRows(str); KeyValueParser paramKeyValueParser; Properties properties; List keyspaces = new ArrayList<>(rows.length); diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/ScanResultConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/ScanResultConverter.java index 5544c6bfd..1fda88570 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/ScanResultConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/ScanResultConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; @@ -40,6 +40,7 @@ * @author Yong.Teng * @since 2.0.0 */ +@FunctionalInterface public interface ScanResultConverter extends Converter, ScanResult> { /** @@ -55,7 +56,7 @@ final class ListScanResultConverter implements ScanResultConverter public final static ListScanResultConverter BINARY_LIST_CONVERTER = new ListScanResultConverter<>(); @Override - public ScanResult> convert(final redis.clients.jedis.resps.ScanResult source){ + public ScanResult> convert(final redis.clients.jedis.resps.ScanResult source) { return new ScanResult<>(source.getCursor(), source.getResult()); } @@ -74,7 +75,7 @@ final class ListTupleScanResultConverter @Override public ScanResult> convert( - final redis.clients.jedis.resps.ScanResult source){ + final redis.clients.jedis.resps.ScanResult source) { return new com.buession.redis.core.ScanResult<>(source.getCursor(), TupleConverter.LIST_CONVERTER.convert(source.getResult())); } @@ -100,7 +101,7 @@ final class MapScanResultConverter implements ScanResultConverter BINARY_MAP_CONVERTER = new MapScanResultConverter<>(); @Override - public ScanResult> convert(final redis.clients.jedis.resps.ScanResult> source){ + public ScanResult> convert(final redis.clients.jedis.resps.ScanResult> source) { final Map data = source.getResult().stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b)->a, LinkedHashMap::new)); return new ScanResult<>(source.getCursorAsBytes(), data); diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClusterInfoConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClusterInfoConverter.java index aa88e3e74..e6a2e7347 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClusterInfoConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClusterInfoConverter.java @@ -26,8 +26,8 @@ import com.buession.core.converter.Converter; import com.buession.core.utils.KeyValueParser; +import com.buession.core.utils.StringUtils; import com.buession.redis.core.ClusterInfo; -import com.buession.redis.utils.ResponseUtils; /** * Cluster Info 命令结果转换为 {@link ClusterInfo} @@ -40,8 +40,8 @@ public final class ClusterInfoConverter implements Converter convert(final String source){ - String[] rows = ResponseUtils.parseRows(source); + public List convert(final String source) { + String[] rows = StringUtils.split(source, "\r\n"); final List nodes = new ArrayList<>(rows.length); diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisFailoverParams.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisFailoverParams.java index 16edbd179..66f3a91ac 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisFailoverParams.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisFailoverParams.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.jedis; @@ -32,35 +32,35 @@ */ public final class JedisFailoverParams extends FailoverParams { - public JedisFailoverParams(final String host, final int port){ + public JedisFailoverParams(final String host, final int port) { super(); to(host, port); } - public JedisFailoverParams(final String host, final int port, final int timeout){ + public JedisFailoverParams(final String host, final int port, final int timeout) { this(host, port); timeout(timeout); } - public JedisFailoverParams(final String host, final int port, final boolean force){ + public JedisFailoverParams(final String host, final int port, final boolean force) { this(host, port); - - if(force){ - force(); - } + force(force); } - public JedisFailoverParams(final String host, final int port, final int timeout, final boolean force){ + public JedisFailoverParams(final String host, final int port, final int timeout, final boolean force) { this(host, port, timeout); - - if(force){ - force(); - } + force(force); } - public JedisFailoverParams(final int timeout){ + public JedisFailoverParams(final int timeout) { super(); timeout(timeout); } + private void force(boolean force) { + if(force){ + force(); + } + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisResult.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisResult.java index c195e6b68..6125073bd 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisResult.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisResult.java @@ -35,16 +35,16 @@ */ public class JedisResult extends FutureResult, SV, TV> { - public JedisResult(final Response resultHolder){ + public JedisResult(final Response resultHolder) { super(resultHolder); } - public JedisResult(final Response resultHolder, final Converter converter){ + public JedisResult(final Response resultHolder, final Converter converter) { super(resultHolder, converter); } @Override - public SV get(){ + public SV get() { return getHolder().get(); } @@ -54,22 +54,27 @@ public final static class Builder { private Converter converter; - private Builder(final Response response, final Converter converter){ + private Builder(final Response response, final Converter converter) { this.response = response; this.converter = converter; } + @Deprecated + public static Builder forResponse(Response response) { + return fromResponse(response); + } + @SuppressWarnings("unchecked") - public static Builder forResponse(Response response){ + public static Builder fromResponse(Response response) { return new Builder<>(response, (source)->(TV) source); } - public Builder mappedWith(Converter converter){ + public Builder mappedWith(Converter converter) { this.converter = converter; return this; } - public JedisResult build(){ + public JedisResult build() { return new JedisResult<>(response, converter); } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisZAddParams.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisZAddParams.java index 574e38806..7383ed68a 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisZAddParams.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisZAddParams.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.jedis; @@ -36,7 +36,7 @@ public final class JedisZAddParams extends redis.clients.jedis.params.ZAddParams /** * 构造函数 */ - public JedisZAddParams(){ + public JedisZAddParams() { super(); } @@ -46,7 +46,7 @@ public JedisZAddParams(){ * @param nxXx * 更新成员方式 */ - public JedisZAddParams(final NxXx nxXx){ + public JedisZAddParams(final NxXx nxXx) { super(); nxXx(nxXx); } @@ -57,7 +57,7 @@ public JedisZAddParams(final NxXx nxXx){ * @param gtLt * {@link GtLt} */ - public JedisZAddParams(final GtLt gtLt){ + public JedisZAddParams(final GtLt gtLt) { super(); gtLt(gtLt); } @@ -68,12 +68,9 @@ public JedisZAddParams(final GtLt gtLt){ * @param ch * 是否返回变更成员的数量 */ - public JedisZAddParams(final boolean ch){ + public JedisZAddParams(final boolean ch) { super(); - - if(ch){ - ch(); - } + ch(ch); } /** @@ -84,7 +81,7 @@ public JedisZAddParams(final boolean ch){ * @param gtLt * 更新新的分值方式 */ - public JedisZAddParams(final NxXx nxXx, final GtLt gtLt){ + public JedisZAddParams(final NxXx nxXx, final GtLt gtLt) { super(); nxXx(nxXx); gtLt(gtLt); @@ -98,13 +95,10 @@ public JedisZAddParams(final NxXx nxXx, final GtLt gtLt){ * @param ch * 是否返回变更成员的数量 */ - public JedisZAddParams(final NxXx nxXx, final boolean ch){ + public JedisZAddParams(final NxXx nxXx, final boolean ch) { super(); nxXx(nxXx); - - if(ch){ - ch(); - } + ch(ch); } /** @@ -115,13 +109,10 @@ public JedisZAddParams(final NxXx nxXx, final boolean ch){ * @param ch * 是否返回变更成员的数量 */ - public JedisZAddParams(final GtLt gtLt, final boolean ch){ + public JedisZAddParams(final GtLt gtLt, final boolean ch) { super(); gtLt(gtLt); - - if(ch){ - ch(); - } + ch(ch); } /** @@ -134,14 +125,11 @@ public JedisZAddParams(final GtLt gtLt, final boolean ch){ * @param ch * 是否返回变更成员的数量 */ - public JedisZAddParams(final NxXx nxXx, final GtLt gtLt, final boolean ch){ + public JedisZAddParams(final NxXx nxXx, final GtLt gtLt, final boolean ch) { super(); nxXx(nxXx); gtLt(gtLt); - - if(ch){ - ch(); - } + ch(ch); } /** @@ -150,7 +138,7 @@ public JedisZAddParams(final NxXx nxXx, final GtLt gtLt, final boolean ch){ * @param nxXx * 更新成员方式 */ - private void nxXx(final NxXx nxXx){ + private void nxXx(final NxXx nxXx) { switch(nxXx){ case NX: nx(); @@ -169,7 +157,7 @@ private void nxXx(final NxXx nxXx){ * @param gtLt * 更新新的分值方式 */ - private void gtLt(final GtLt gtLt){ + private void gtLt(final GtLt gtLt) { switch(gtLt){ case GT: gt(); @@ -182,4 +170,10 @@ private void gtLt(final GtLt gtLt){ } } + private void ch(boolean ch) { + if(ch){ + ch(); + } + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisZRangeParams.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisZRangeParams.java index d088982d4..fe8532c4c 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisZRangeParams.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisZRangeParams.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.jedis; @@ -34,89 +34,83 @@ */ public final class JedisZRangeParams extends ZRangeParams { - public JedisZRangeParams(final int min, final int max){ + public JedisZRangeParams(final int min, final int max) { super(min, max); } - public JedisZRangeParams(final long min, final long max){ + public JedisZRangeParams(final long min, final long max) { super((int) min, (int) max); } - public JedisZRangeParams(final ZRangeBy by, final int min, final int max){ + public JedisZRangeParams(final ZRangeBy by, final int min, final int max) { super(byKeyword(by), Integer.toString(min), Integer.toString(max)); } - public JedisZRangeParams(final ZRangeBy by, final long min, final long max){ + public JedisZRangeParams(final ZRangeBy by, final long min, final long max) { super(byKeyword(by), Long.toString(min), Long.toString(max)); } - public JedisZRangeParams(final ZRangeBy by, final int min, final int max, final boolean rev){ + public JedisZRangeParams(final ZRangeBy by, final int min, final int max, final boolean rev) { this(by, min, max); - - if(rev){ - rev(); - } + rev(rev); } - public JedisZRangeParams(final ZRangeBy by, final long min, final long max, final boolean rev){ + public JedisZRangeParams(final ZRangeBy by, final long min, final long max, final boolean rev) { this(by, (int) min, (int) max, rev); } - public JedisZRangeParams(final ZRangeBy by, final int min, final int max, final long offset, final long count){ + public JedisZRangeParams(final ZRangeBy by, final int min, final int max, final long offset, final long count) { this(by, min, max); limit((int) offset, (int) count); } - public JedisZRangeParams(final ZRangeBy by, final long min, final long max, final long offset, final long count){ + public JedisZRangeParams(final ZRangeBy by, final long min, final long max, final long offset, final long count) { this(by, min, max); limit((int) offset, (int) count); } - public JedisZRangeParams(final int min, final int max, final boolean rev){ + public JedisZRangeParams(final int min, final int max, final boolean rev) { this(min, max); - - if(rev){ - rev(); - } + rev(rev); } - public JedisZRangeParams(final long min, final long max, final boolean rev){ + public JedisZRangeParams(final long min, final long max, final boolean rev) { this((int) min, (int) max, rev); } - public JedisZRangeParams(final int min, final int max, final long offset, final long count){ + public JedisZRangeParams(final int min, final int max, final long offset, final long count) { this(min, max); limit((int) offset, (int) count); } - public JedisZRangeParams(final long min, final long max, final long offset, final long count){ + public JedisZRangeParams(final long min, final long max, final long offset, final long count) { this(min, max); limit((int) offset, (int) count); } - public JedisZRangeParams(final int min, final int max, final boolean rev, final long offset, final long count){ + public JedisZRangeParams(final int min, final int max, final boolean rev, final long offset, final long count) { this(min, max, rev); limit((int) offset, (int) count); } - public JedisZRangeParams(final long min, final long max, final boolean rev, final long offset, final long count){ + public JedisZRangeParams(final long min, final long max, final boolean rev, final long offset, final long count) { this(min, max, rev); limit((int) offset, (int) count); } public JedisZRangeParams(final ZRangeBy by, final int min, final int max, final boolean rev, final long offset, - final long count){ + final long count) { this(by, min, max, rev); limit((int) offset, (int) count); } public JedisZRangeParams(final ZRangeBy by, final long min, final long max, final boolean rev, final long offset, - final long count){ + final long count) { this(by, min, max, rev); limit((int) offset, (int) count); } - private static Protocol.Keyword byKeyword(final ZRangeBy by){ + private static Protocol.Keyword byKeyword(final ZRangeBy by) { switch(by){ case BYLEX: return Protocol.Keyword.BYLEX; @@ -127,4 +121,10 @@ private static Protocol.Keyword byKeyword(final ZRangeBy by){ } } + private void rev(boolean rev) { + if(rev){ + rev(); + } + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/exception/NotSupportedCommandException.java b/buession-redis/src/main/java/com/buession/redis/exception/NotSupportedCommandException.java index caa5fa686..cf0ac0bed 100644 --- a/buession-redis/src/main/java/com/buession/redis/exception/NotSupportedCommandException.java +++ b/buession-redis/src/main/java/com/buession/redis/exception/NotSupportedCommandException.java @@ -28,6 +28,8 @@ import com.buession.redis.core.command.ProtocolCommand; /** + * 命令不支持异常 + * * @author Yong.Teng */ public class NotSupportedCommandException extends RedisException { @@ -36,35 +38,35 @@ public class NotSupportedCommandException extends RedisException { private Type type; - public NotSupportedCommandException(){ + public NotSupportedCommandException() { super(); } - public NotSupportedCommandException(ProtocolCommand command){ + public NotSupportedCommandException(ProtocolCommand command) { super("Not supported command: " + command); } - public NotSupportedCommandException(Type type, ProtocolCommand command){ + public NotSupportedCommandException(Type type, ProtocolCommand command) { super("Not supported command: " + command + " in " + type); } - public NotSupportedCommandException(RedisMode mode, ProtocolCommand command){ + public NotSupportedCommandException(RedisMode mode, ProtocolCommand command) { super("Not supported command: " + command + " with " + mode + " mode"); } - public NotSupportedCommandException(RedisMode mode, Type type, ProtocolCommand command){ + public NotSupportedCommandException(RedisMode mode, Type type, ProtocolCommand command) { super("Not supported command: " + command + " in " + type + " with " + mode + " mode"); } - public NotSupportedCommandException(String message){ + public NotSupportedCommandException(String message) { super(message); } - public NotSupportedCommandException(String message, Throwable cause){ + public NotSupportedCommandException(String message, Throwable cause) { super(message, cause); } - public NotSupportedCommandException(Throwable cause){ + public NotSupportedCommandException(Throwable cause) { super(cause); } @@ -80,11 +82,11 @@ public enum Type { private final int code; - Type(final int code){ + Type(final int code) { this.code = code; } - public int getCode(){ + public int getCode() { return code; } diff --git a/buession-redis/src/main/java/com/buession/redis/exception/NotSupportedPipelineCommandException.java b/buession-redis/src/main/java/com/buession/redis/exception/NotSupportedPipelineCommandException.java index c9f1bbf6e..14c713765 100644 --- a/buession-redis/src/main/java/com/buession/redis/exception/NotSupportedPipelineCommandException.java +++ b/buession-redis/src/main/java/com/buession/redis/exception/NotSupportedPipelineCommandException.java @@ -24,32 +24,39 @@ */ package com.buession.redis.exception; +import com.buession.redis.core.RedisMode; import com.buession.redis.core.command.ProtocolCommand; /** + * 不支持管道异常 + * * @author Yong.Teng */ public class NotSupportedPipelineCommandException extends NotSupportedCommandException { private final static long serialVersionUID = -3574152755807717655L; - public NotSupportedPipelineCommandException(){ + public NotSupportedPipelineCommandException() { super(); } - public NotSupportedPipelineCommandException(ProtocolCommand command){ - super("Not supported command: " + command + " in pipeline."); + public NotSupportedPipelineCommandException(ProtocolCommand command) { + super(Type.PIPELINE, command); + } + + public NotSupportedPipelineCommandException(RedisMode mode, ProtocolCommand command) { + super(mode, command); } - public NotSupportedPipelineCommandException(String message){ + public NotSupportedPipelineCommandException(String message) { super(message); } - public NotSupportedPipelineCommandException(String message, Throwable cause){ + public NotSupportedPipelineCommandException(String message, Throwable cause) { super(message, cause); } - public NotSupportedPipelineCommandException(Throwable cause){ + public NotSupportedPipelineCommandException(Throwable cause) { super(cause); } diff --git a/buession-redis/src/main/java/com/buession/redis/exception/NotSupportedTransactionCommandException.java b/buession-redis/src/main/java/com/buession/redis/exception/NotSupportedTransactionCommandException.java index d945145c6..8a0c59ce1 100644 --- a/buession-redis/src/main/java/com/buession/redis/exception/NotSupportedTransactionCommandException.java +++ b/buession-redis/src/main/java/com/buession/redis/exception/NotSupportedTransactionCommandException.java @@ -24,31 +24,39 @@ */ package com.buession.redis.exception; +import com.buession.redis.core.RedisMode; import com.buession.redis.core.command.ProtocolCommand; /** + * 不支持事务异常 + * * @author Yong.Teng */ public class NotSupportedTransactionCommandException extends NotSupportedCommandException { private final static long serialVersionUID = -3940419124680209461L; - public NotSupportedTransactionCommandException(){ + public NotSupportedTransactionCommandException() { + super(); + } + + public NotSupportedTransactionCommandException(ProtocolCommand command) { + super(Type.TRANSACTION, command); } - public NotSupportedTransactionCommandException(ProtocolCommand command){ - super("Not supported command: " + command + " in transaction."); + public NotSupportedTransactionCommandException(RedisMode mode, ProtocolCommand command) { + super(mode, command); } - public NotSupportedTransactionCommandException(String message){ + public NotSupportedTransactionCommandException(String message) { super(message); } - public NotSupportedTransactionCommandException(String message, Throwable cause){ + public NotSupportedTransactionCommandException(String message, Throwable cause) { super(message, cause); } - public NotSupportedTransactionCommandException(Throwable cause){ + public NotSupportedTransactionCommandException(Throwable cause) { super(cause); } diff --git a/buession-redis/src/main/java/com/buession/redis/exception/PoolException.java b/buession-redis/src/main/java/com/buession/redis/exception/PoolException.java index d4c053a8c..6cd2b0b1d 100644 --- a/buession-redis/src/main/java/com/buession/redis/exception/PoolException.java +++ b/buession-redis/src/main/java/com/buession/redis/exception/PoolException.java @@ -25,29 +25,31 @@ package com.buession.redis.exception; /** + * 连接池异常 + * * @author Yong.Teng */ public class PoolException extends RedisConnectionFailureException { private final static long serialVersionUID = 6014038319970079646L; - public PoolException(){ + public PoolException() { super(); } - public PoolException(String message){ + public PoolException(String message) { super(message); } - public PoolException(String message, Throwable cause){ + public PoolException(String message, Throwable cause) { super(message, cause); } - public PoolException(Throwable cause){ + public PoolException(Throwable cause) { super(cause); } - public PoolException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace){ + public PoolException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } diff --git a/buession-redis/src/main/java/com/buession/redis/exception/RedisConnectionFailureException.java b/buession-redis/src/main/java/com/buession/redis/exception/RedisConnectionFailureException.java index 5fb444815..950b1a5be 100644 --- a/buession-redis/src/main/java/com/buession/redis/exception/RedisConnectionFailureException.java +++ b/buession-redis/src/main/java/com/buession/redis/exception/RedisConnectionFailureException.java @@ -19,34 +19,39 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2019 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.exception; /** + * Redis 连接失败异常 + * * @author Yong.Teng */ public class RedisConnectionFailureException extends RedisException { - public RedisConnectionFailureException(){ + private final static long serialVersionUID = 4668151372471360713L; + + public RedisConnectionFailureException() { super("Could not connect"); } - public RedisConnectionFailureException(String message){ + public RedisConnectionFailureException(String message) { super(message); } - public RedisConnectionFailureException(String message, Throwable cause){ + public RedisConnectionFailureException(String message, Throwable cause) { super(message, cause); } - public RedisConnectionFailureException(Throwable cause){ + public RedisConnectionFailureException(Throwable cause) { super(cause); } public RedisConnectionFailureException(String message, Throwable cause, boolean enableSuppression, boolean - writableStackTrace){ + writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } + } diff --git a/buession-redis/src/main/java/com/buession/redis/exception/RedisException.java b/buession-redis/src/main/java/com/buession/redis/exception/RedisException.java index 990b400d4..5efe28dbe 100644 --- a/buession-redis/src/main/java/com/buession/redis/exception/RedisException.java +++ b/buession-redis/src/main/java/com/buession/redis/exception/RedisException.java @@ -25,29 +25,31 @@ package com.buession.redis.exception; /** + * Redis 异常 + * * @author Yong.Teng */ public class RedisException extends RuntimeException { private final static long serialVersionUID = -2586895524061580852L; - public RedisException(){ + public RedisException() { super(); } - public RedisException(String message){ + public RedisException(String message) { super(message); } - public RedisException(String message, Throwable cause){ + public RedisException(String message, Throwable cause) { super(message, cause); } - public RedisException(Throwable cause){ + public RedisException(Throwable cause) { super(cause); } - public RedisException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace){ + public RedisException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } diff --git a/buession-redis/src/main/java/com/buession/redis/pipeline/jedis/JedisPipeline.java b/buession-redis/src/main/java/com/buession/redis/pipeline/jedis/JedisPipeline.java index 06ce85404..57a276df8 100644 --- a/buession-redis/src/main/java/com/buession/redis/pipeline/jedis/JedisPipeline.java +++ b/buession-redis/src/main/java/com/buession/redis/pipeline/jedis/JedisPipeline.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.pipeline.jedis; @@ -36,33 +36,33 @@ */ public class JedisPipeline implements Pipeline { - private redis.clients.jedis.Pipeline delegate; + private final redis.clients.jedis.Pipeline delegate; private final static Logger logger = LoggerFactory.getLogger(JedisPipeline.class); - public JedisPipeline(redis.clients.jedis.Pipeline pipeline){ + public JedisPipeline(redis.clients.jedis.Pipeline pipeline) { Assert.isNull(pipeline, "Redis Pipeline cloud not be null."); this.delegate = pipeline; } - public redis.clients.jedis.Pipeline primitive(){ + public redis.clients.jedis.Pipeline primitive() { return delegate; } @Override - public void sync(){ + public void sync() { logger.info("Redis pipeline sync."); delegate.sync(); } @Override - public List syncAndReturnAll(){ + public List syncAndReturnAll() { logger.info("Redis pipeline syncAndReturnAll."); return delegate.syncAndReturnAll(); } @Override - public void close(){ + public void close() { logger.info("Redis pipeline close."); delegate.close(); } diff --git a/buession-redis/src/main/java/com/buession/redis/pubsub/jedis/DefaultBinaryJedisPubSub.java b/buession-redis/src/main/java/com/buession/redis/pubsub/jedis/DefaultBinaryJedisPubSub.java index b143eaecc..bb289b911 100644 --- a/buession-redis/src/main/java/com/buession/redis/pubsub/jedis/DefaultBinaryJedisPubSub.java +++ b/buession-redis/src/main/java/com/buession/redis/pubsub/jedis/DefaultBinaryJedisPubSub.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.pubsub.jedis; @@ -33,40 +33,40 @@ */ public class DefaultBinaryJedisPubSub extends BinaryJedisPubSub { - private PubSubListener delegate; + private final PubSubListener delegate; - public DefaultBinaryJedisPubSub(PubSubListener pubSubListener){ + public DefaultBinaryJedisPubSub(PubSubListener pubSubListener) { Assert.isNull(pubSubListener, "Pubsub listener cloud not be null."); this.delegate = pubSubListener; } @Override - public void onMessage(byte[] channel, byte[] message){ + public void onMessage(byte[] channel, byte[] message) { delegate.onMessage(channel, message); } @Override - public void onPMessage(byte[] pattern, byte[] channel, byte[] message){ + public void onPMessage(byte[] pattern, byte[] channel, byte[] message) { delegate.onPMessage(pattern, channel, message); } @Override - public void onSubscribe(byte[] channel, int subscribedChannels){ + public void onSubscribe(byte[] channel, int subscribedChannels) { delegate.onSubscribe(channel, subscribedChannels); } @Override - public void onUnsubscribe(byte[] channel, int subscribedChannels){ + public void onUnsubscribe(byte[] channel, int subscribedChannels) { delegate.onUnsubscribe(channel, subscribedChannels); } @Override - public void onPUnsubscribe(byte[] pattern, int subscribedChannels){ + public void onPUnsubscribe(byte[] pattern, int subscribedChannels) { delegate.onPUnsubscribe(pattern, subscribedChannels); } @Override - public void onPSubscribe(byte[] pattern, int subscribedChannels){ + public void onPSubscribe(byte[] pattern, int subscribedChannels) { delegate.onPSubscribe(pattern, subscribedChannels); } diff --git a/buession-redis/src/main/java/com/buession/redis/pubsub/jedis/DefaultJedisPubSub.java b/buession-redis/src/main/java/com/buession/redis/pubsub/jedis/DefaultJedisPubSub.java index cdb9ba156..6b461d3b6 100644 --- a/buession-redis/src/main/java/com/buession/redis/pubsub/jedis/DefaultJedisPubSub.java +++ b/buession-redis/src/main/java/com/buession/redis/pubsub/jedis/DefaultJedisPubSub.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.pubsub.jedis; @@ -33,45 +33,45 @@ */ public class DefaultJedisPubSub extends JedisPubSub { - private PubSubListener delegate; + private final PubSubListener delegate; - public DefaultJedisPubSub(PubSubListener pubSubListener){ + public DefaultJedisPubSub(PubSubListener pubSubListener) { Assert.isNull(pubSubListener, "Pubsub listener cloud not be null."); this.delegate = pubSubListener; } @Override - public void onMessage(String channel, String message){ + public void onMessage(String channel, String message) { delegate.onMessage(channel, message); } @Override - public void onPMessage(String pattern, String channel, String message){ + public void onPMessage(String pattern, String channel, String message) { delegate.onPMessage(pattern, channel, message); } @Override - public void onSubscribe(String channel, int subscribedChannels){ + public void onSubscribe(String channel, int subscribedChannels) { delegate.onSubscribe(channel, subscribedChannels); } @Override - public void onUnsubscribe(String channel, int subscribedChannels){ + public void onUnsubscribe(String channel, int subscribedChannels) { delegate.onUnsubscribe(channel, subscribedChannels); } @Override - public void onPUnsubscribe(String pattern, int subscribedChannels){ + public void onPUnsubscribe(String pattern, int subscribedChannels) { delegate.onPUnsubscribe(pattern, subscribedChannels); } @Override - public void onPSubscribe(String pattern, int subscribedChannels){ + public void onPSubscribe(String pattern, int subscribedChannels) { delegate.onPSubscribe(pattern, subscribedChannels); } @Override - public void onPong(String pattern){ + public void onPong(String pattern) { delegate.onPong(pattern); } diff --git a/buession-redis/src/main/java/com/buession/redis/serializer/AbstractSerializer.java b/buession-redis/src/main/java/com/buession/redis/serializer/AbstractSerializer.java index eeaccac46..fbd42b25e 100644 --- a/buession-redis/src/main/java/com/buession/redis/serializer/AbstractSerializer.java +++ b/buession-redis/src/main/java/com/buession/redis/serializer/AbstractSerializer.java @@ -61,7 +61,7 @@ public abstract class AbstractSerializer String serialize(final V object){ + public String serialize(final V object) { if(object != null){ try{ return serializer.serialize(object); @@ -80,14 +80,14 @@ public String serialize(final V object){ return null; } - + @Override - public String[] serialize(final V... objects){ + public final String[] serialize(final V[] objects) { return Arrays.map(objects, String.class, this::serialize); } @Override - public byte[] serializeAsBytes(final V object){ + public byte[] serializeAsBytes(final V object) { if(object != null){ try{ return serializer.serializeAsBytes(object); @@ -100,12 +100,12 @@ public byte[] serializeAsBytes(final V object){ } @Override - public byte[][] serializeAsBytes(final V... objects){ + public byte[][] serializeAsBytes(final V[] objects) { return Arrays.map(objects, byte[].class, this::serializeAsBytes); } @Override - public V deserialize(final String str){ + public V deserialize(final String str) { if(str != null){ try{ return deserializer.deserialize(str); @@ -118,7 +118,7 @@ public V deserialize(final String str){ } @Override - public V deserializeBytes(final byte[] bytes){ + public V deserializeBytes(final byte[] bytes) { if(bytes != null){ try{ return deserializer.deserialize(bytes); diff --git a/buession-redis/src/main/java/com/buession/redis/serializer/Serializer.java b/buession-redis/src/main/java/com/buession/redis/serializer/Serializer.java index 258ed7845..6d2bc937c 100644 --- a/buession-redis/src/main/java/com/buession/redis/serializer/Serializer.java +++ b/buession-redis/src/main/java/com/buession/redis/serializer/Serializer.java @@ -57,7 +57,7 @@ public interface Serializer { * * @return 序列化后的字符串 */ - String[] serialize(final V... objects); + String[] serialize(final V[] objects); /** * 将任意对象序列化为字节 @@ -81,7 +81,7 @@ public interface Serializer { * * @return 序列化后的字节 */ - byte[][] serializeAsBytes(final V... objects); + byte[][] serializeAsBytes(final V[] objects); /** * 将字符串反序列化为对象 diff --git a/buession-redis/src/main/java/com/buession/redis/transaction/jedis/JedisTransaction.java b/buession-redis/src/main/java/com/buession/redis/transaction/jedis/JedisTransaction.java index 9def6199c..de9f3a76c 100644 --- a/buession-redis/src/main/java/com/buession/redis/transaction/jedis/JedisTransaction.java +++ b/buession-redis/src/main/java/com/buession/redis/transaction/jedis/JedisTransaction.java @@ -38,33 +38,33 @@ */ public class JedisTransaction implements Transaction { - private redis.clients.jedis.Transaction delegate; + private final redis.clients.jedis.Transaction delegate; private final static Logger logger = LoggerFactory.getLogger(JedisTransaction.class); - public JedisTransaction(redis.clients.jedis.Transaction transaction){ + public JedisTransaction(redis.clients.jedis.Transaction transaction) { Assert.isNull(transaction, "Redis Transaction cloud not be null."); this.delegate = transaction; } - public redis.clients.jedis.Transaction primitive(){ + public redis.clients.jedis.Transaction primitive() { return delegate; } @Override - public List exec(){ + public List exec() { logger.info("Redis transaction exec."); return delegate.exec(); } @Override - public String discard(){ + public String discard() { logger.info("Redis transaction discard."); return delegate.discard(); } @Override - public void close(){ + public void close() { logger.info("Redis transaction close."); delegate.close(); } diff --git a/buession-redis/src/main/java/com/buession/redis/utils/ResponseUtils.java b/buession-redis/src/main/java/com/buession/redis/utils/ResponseUtils.java index 657223a0e..0101a4399 100644 --- a/buession-redis/src/main/java/com/buession/redis/utils/ResponseUtils.java +++ b/buession-redis/src/main/java/com/buession/redis/utils/ResponseUtils.java @@ -30,12 +30,13 @@ * @author Yong.Teng * @since 2.0.0 */ +@Deprecated public class ResponseUtils { public final static String ROW_SEPARATOR = "\r\n"; - public static String[] parseRows(final String str){ - return StringUtils.split(str, ROW_SEPARATOR); + public static String[] parseRows(final String str) { + return StringUtils.split(str, "\r\n"); } } diff --git a/buession-session/pom.xml b/buession-session/pom.xml index cb8c425c8..fb7bafd5a 100644 --- a/buession-session/pom.xml +++ b/buession-session/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.1 + 2.3.2 buession-session http://www.buession.com/ diff --git a/buession-thesaurus/pom.xml b/buession-thesaurus/pom.xml index 12fad4b03..b5611291e 100644 --- a/buession-thesaurus/pom.xml +++ b/buession-thesaurus/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.1 + 2.3.2 buession-thesaurus http://www.buession.com/ diff --git a/buession-thesaurus/src/main/java/com/buession/thesaurus/SogouParser.java b/buession-thesaurus/src/main/java/com/buession/thesaurus/SogouParser.java index 823db8e56..9ce418b96 100644 --- a/buession-thesaurus/src/main/java/com/buession/thesaurus/SogouParser.java +++ b/buession-thesaurus/src/main/java/com/buession/thesaurus/SogouParser.java @@ -21,7 +21,7 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.thesaurus; @@ -55,15 +55,16 @@ public class SogouParser extends AbstractParser { private final static Logger logger = LoggerFactory.getLogger(SogouParser.class); @Override - public Type getType(){ + public Type getType() { return Type.SOGOU; } @Override - protected Set doParse(InputStream inputStream) throws IOException{ + protected Set doParse(InputStream inputStream) throws IOException { SogouScelModel model = read(inputStream); - logger.debug("words entry info is: name => {}, type => {}, description => {}, sample => {}.", model.getName(), model.getType(), model.getDescription(), model.getSample()); + logger.debug("words entry info is: name => {}, type => {}, description => {}, sample => {}.", model.getName(), + model.getType(), model.getDescription(), model.getSample()); Map> tempWords = model.getWordMap(); @@ -104,7 +105,7 @@ protected Set doParse(InputStream inputStream) throws IOException{ return words; } - private SogouScelModel read(InputStream inputStream) throws IOException{ + private SogouScelModel read(InputStream inputStream) throws IOException { SogouScelModel model = new SogouScelModel(); DataInputStream input = new DataInputStream(inputStream); byte[] bytes = new byte[4]; @@ -190,11 +191,7 @@ private SogouScelModel read(InputStream inputStream) throws IOException{ buffer.setLength(buffer.length() - 1); String pinyin = buffer.toString(); - Set list = wordMap.get(pinyin); - if(list == null){ - list = new LinkedHashSet<>(); - wordMap.put(pinyin, list); - } + Set list = wordMap.computeIfAbsent(pinyin, k->new LinkedHashSet<>()); for(int i = 0; i < size; i++){ count = readUnsignedShort(input); @@ -221,7 +218,7 @@ private SogouScelModel read(InputStream inputStream) throws IOException{ } } - protected final String readString(DataInputStream input, int pos, int[] reads) throws IOException{ + protected final String readString(DataInputStream input, int pos, int[] reads) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); int read = reads[0]; @@ -247,7 +244,7 @@ protected final String readString(DataInputStream input, int pos, int[] reads) t return new String(output.toByteArray(), ENCODING); } - protected static int readUnsignedShort(InputStream in) throws IOException{ + protected static int readUnsignedShort(InputStream in) throws IOException { int ch1 = in.read(); int ch2 = in.read(); @@ -268,43 +265,43 @@ private final static class SogouScelModel implements Serializable { private Map> wordMap; - public String getName(){ + public String getName() { return name; } - public void setName(String name){ + public void setName(String name) { this.name = name; } - public String getType(){ + public String getType() { return type; } - public void setType(String type){ + public void setType(String type) { this.type = type; } - public String getDescription(){ + public String getDescription() { return description; } - public void setDescription(String description){ + public void setDescription(String description) { this.description = description; } - public String getSample(){ + public String getSample() { return sample; } - public void setSample(String sample){ + public void setSample(String sample) { this.sample = sample; } - public Map> getWordMap(){ + public Map> getWordMap() { return wordMap; } - public void setWordMap(Map> wordMap){ + public void setWordMap(Map> wordMap) { this.wordMap = wordMap; } diff --git a/buession-thesaurus/src/main/java/com/buession/thesaurus/spring/ThesaurusFactoryBean.java b/buession-thesaurus/src/main/java/com/buession/thesaurus/spring/ThesaurusFactoryBean.java index 0f2596b72..41d56c8c4 100644 --- a/buession-thesaurus/src/main/java/com/buession/thesaurus/spring/ThesaurusFactoryBean.java +++ b/buession-thesaurus/src/main/java/com/buession/thesaurus/spring/ThesaurusFactoryBean.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.thesaurus.spring; @@ -28,8 +28,10 @@ import com.buession.thesaurus.Parser; import com.buession.thesaurus.core.Type; import com.buession.thesaurus.execption.ThesaurusTypeNotFoundException; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.ClassUtils; /** * @author Yong.Teng @@ -38,34 +40,39 @@ public class ThesaurusFactoryBean extends ThesaurusFactory implements FactoryBea private Parser parser; - private Class clazz; - - public ThesaurusFactoryBean(){ + public ThesaurusFactoryBean() { super(); } - public ThesaurusFactoryBean(Type type){ + public ThesaurusFactoryBean(Type type) { super(type); } - public ThesaurusFactoryBean(String type){ + public ThesaurusFactoryBean(String type) { super(type); } @Override - public Parser getObject() throws Exception{ + public Parser getObject() throws Exception { return parser; } @Override - public Class getObjectType(){ - return clazz; + public Class getObjectType() { + return parser.getClass(); } @Override - public void afterPropertiesSet() throws Exception{ + public void afterPropertiesSet() throws Exception { Assert.isNull(getType(), "Thesaurus key could not be null."); + if(parser == null){ + parser = createParser(); + } + } + + @SuppressWarnings({"unchecked"}) + private Parser createParser() throws ThesaurusTypeNotFoundException { char first = getType().getId().charAt(0); StringBuilder sb = new StringBuilder(64); @@ -82,8 +89,7 @@ public void afterPropertiesSet() throws Exception{ sb.append("Parser"); try{ - clazz = (Class) Class.forName(sb.toString()); - parser = clazz.newInstance(); + return BeanUtils.instantiateClass((Class) ClassUtils.forName(sb.toString(), null)); }catch(ClassNotFoundException e){ throw new ThesaurusTypeNotFoundException("The " + getType() + " thesaurus not be found."); } diff --git a/buession-velocity/pom.xml b/buession-velocity/pom.xml index 26870fa7a..a2e2a716b 100644 --- a/buession-velocity/pom.xml +++ b/buession-velocity/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.1 + 2.3.2 buession-velocity http://www.buession.com/ diff --git a/buession-velocity/src/main/java/com/buession/velocity/servlet/VelocityLayoutViewResolver.java b/buession-velocity/src/main/java/com/buession/velocity/servlet/VelocityLayoutViewResolver.java index 5b496c190..1cee05c2f 100644 --- a/buession-velocity/src/main/java/com/buession/velocity/servlet/VelocityLayoutViewResolver.java +++ b/buession-velocity/src/main/java/com/buession/velocity/servlet/VelocityLayoutViewResolver.java @@ -70,7 +70,7 @@ protected Class requiredViewClass() { @Override protected AbstractUrlBasedView buildView(String viewName) throws Exception { final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); - VelocityLayoutView view = (VelocityLayoutView) super.buildView(viewName); + final VelocityLayoutView view = (VelocityLayoutView) super.buildView(viewName); propertyMapper.from(layoutKey).to(view::setLayoutKey); propertyMapper.from(layoutUrl).to(view::setLayoutUrl); diff --git a/buession-velocity/src/main/java/com/buession/velocity/servlet/VelocityToolboxView.java b/buession-velocity/src/main/java/com/buession/velocity/servlet/VelocityToolboxView.java index 90613e006..94d7e0055 100644 --- a/buession-velocity/src/main/java/com/buession/velocity/servlet/VelocityToolboxView.java +++ b/buession-velocity/src/main/java/com/buession/velocity/servlet/VelocityToolboxView.java @@ -24,6 +24,7 @@ */ package com.buession.velocity.servlet; +import com.buession.core.utils.ObjectUtils; import org.apache.velocity.context.Context; import org.apache.velocity.tools.Scope; import org.apache.velocity.tools.ToolManager; @@ -80,9 +81,7 @@ protected Context createVelocityContext(Map model, HttpServletRe @Override protected void initTool(Object tool, Context velocityContext) throws Exception { Method initMethod = ClassUtils.getMethodIfAvailable(tool.getClass(), "init", Object.class); - if(initMethod != null){ - ReflectionUtils.invokeMethod(initMethod, tool, velocityContext); - } + ObjectUtils.invokeIfAvailable(initMethod, m->ReflectionUtils.invokeMethod(m, tool, velocityContext)); } protected static void addToolbox(final ViewToolContext velocityContext, final ToolboxFactory toolboxFactory, diff --git a/buession-velocity/src/main/java/com/buession/velocity/servlet/VelocityViewResolver.java b/buession-velocity/src/main/java/com/buession/velocity/servlet/VelocityViewResolver.java index 6899adea5..ef4f50165 100644 --- a/buession-velocity/src/main/java/com/buession/velocity/servlet/VelocityViewResolver.java +++ b/buession-velocity/src/main/java/com/buession/velocity/servlet/VelocityViewResolver.java @@ -21,11 +21,12 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.velocity.servlet; +import com.buession.core.utils.ObjectUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.servlet.view.AbstractTemplateViewResolver; @@ -46,49 +47,49 @@ public class VelocityViewResolver extends AbstractTemplateViewResolver { private final static Logger logger = LoggerFactory.getLogger(VelocityViewResolver.class); - public VelocityViewResolver(){ + public VelocityViewResolver() { setViewClass(requiredViewClass()); } - public String getEncoding(){ + public String getEncoding() { return encoding; } - public void setEncoding(String encoding){ + public void setEncoding(String encoding) { this.encoding = encoding; } - public String getToolboxConfigLocation(){ + public String getToolboxConfigLocation() { return toolboxConfigLocation; } - public void setToolboxConfigLocation(String toolboxConfigLocation){ + public void setToolboxConfigLocation(String toolboxConfigLocation) { this.toolboxConfigLocation = toolboxConfigLocation; } - public String getDateToolAttribute(){ + public String getDateToolAttribute() { return dateToolAttribute; } - public void setDateToolAttribute(String dateToolAttribute){ + public void setDateToolAttribute(String dateToolAttribute) { this.dateToolAttribute = dateToolAttribute; } - public String getNumberToolAttribute(){ + public String getNumberToolAttribute() { return numberToolAttribute; } - public void setNumberToolAttribute(String numberToolAttribute){ + public void setNumberToolAttribute(String numberToolAttribute) { this.numberToolAttribute = numberToolAttribute; } @Override - protected Class requiredViewClass(){ + protected Class requiredViewClass() { return VelocityView.class; } @Override - protected void initApplicationContext(){ + protected void initApplicationContext() { super.initApplicationContext(); if(toolboxConfigLocation == null){ @@ -109,15 +110,14 @@ protected void initApplicationContext(){ } @Override - protected AbstractUrlBasedView buildView(String viewName) throws Exception{ + protected AbstractUrlBasedView buildView(String viewName) throws Exception { VelocityView view = (VelocityView) super.buildView(viewName); view.setDateToolAttribute(dateToolAttribute); view.setNumberToolAttribute(numberToolAttribute); - if(toolboxConfigLocation != null){ - ((VelocityToolboxView) view).setToolboxConfigLocation(toolboxConfigLocation); - } + ObjectUtils.invokeIfAvailable(toolboxConfigLocation, + ((VelocityToolboxView) view)::setToolboxConfigLocation); return view; } diff --git a/buession-velocity/src/main/java/com/buession/velocity/spring/VelocityEngineFactoryBean.java b/buession-velocity/src/main/java/com/buession/velocity/spring/VelocityEngineFactoryBean.java index b7009f54e..e28af0d77 100644 --- a/buession-velocity/src/main/java/com/buession/velocity/spring/VelocityEngineFactoryBean.java +++ b/buession-velocity/src/main/java/com/buession/velocity/spring/VelocityEngineFactoryBean.java @@ -40,18 +40,20 @@ public class VelocityEngineFactoryBean extends VelocityEngineFactory implements private VelocityEngine velocityEngine; @Override - public VelocityEngine getObject(){ + public VelocityEngine getObject() { return velocityEngine; } @Override - public Class getObjectType(){ + public Class getObjectType() { return VelocityEngine.class; } @Override - public void afterPropertiesSet() throws IOException, VelocityException{ - this.velocityEngine = createVelocityEngine(); + public void afterPropertiesSet() throws IOException, VelocityException { + if(velocityEngine == null){ + velocityEngine = createVelocityEngine(); + } } } diff --git a/buession-velocity/src/main/java/com/buession/velocity/tools/JsonTool.java b/buession-velocity/src/main/java/com/buession/velocity/tools/JsonTool.java index 5e0a5d313..f549c7598 100644 --- a/buession-velocity/src/main/java/com/buession/velocity/tools/JsonTool.java +++ b/buession-velocity/src/main/java/com/buession/velocity/tools/JsonTool.java @@ -27,7 +27,6 @@ package com.buession.velocity.tools; import com.buession.core.validator.Validate; -import com.buession.lang.Constants; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.PrettyPrinter; @@ -44,6 +43,8 @@ import java.util.TimeZone; /** + * JSON 工具 + * * @author Yong.Teng */ @DefaultKey("json") @@ -269,37 +270,12 @@ public String encode(Object object, Boolean ignoreNullValue, String dateFormat, private static PrettyPrinter getPrettyPrinter() { if(prettyPrinter == null){ - prettyPrinter = new VelocityPrettyPrinter(); + final Separators separators = + DefaultPrettyPrinter.DEFAULT_SEPARATORS.withObjectFieldValueSpacing(Separators.Spacing.AFTER); + prettyPrinter = new DefaultPrettyPrinter(separators); } return prettyPrinter; } - private final static class VelocityPrettyPrinter extends DefaultPrettyPrinter { - - private final static long serialVersionUID = -2266232157759904063L; - - public VelocityPrettyPrinter() { - super(Constants.EMPTY_STRING); - } - - public VelocityPrettyPrinter(DefaultPrettyPrinter base) { - super(base); - } - - @Override - public DefaultPrettyPrinter withSeparators(Separators separators) { - _separators = separators; - _objectFieldValueSeparatorWithSpaces = - separators.getObjectFieldValueSeparator() + Constants.SPACING_STRING; - return this; - } - - @Override - public DefaultPrettyPrinter createInstance() { - return new VelocityPrettyPrinter(this); - } - - } - } diff --git a/buession-velocity/src/main/java/com/buession/velocity/tools/LocaleAwareDateTool.java b/buession-velocity/src/main/java/com/buession/velocity/tools/LocaleAwareDateTool.java index cf107c548..283a74539 100644 --- a/buession-velocity/src/main/java/com/buession/velocity/tools/LocaleAwareDateTool.java +++ b/buession-velocity/src/main/java/com/buession/velocity/tools/LocaleAwareDateTool.java @@ -30,12 +30,20 @@ import org.springframework.web.servlet.support.RequestContextUtils; import javax.servlet.http.HttpServletRequest; +import java.util.Calendar; +import java.util.Date; import java.util.Locale; import java.util.Optional; import java.util.TimeZone; /** + * Tool for working with {@link Date} and {@link Calendar} + * with request locale in Velocity templates. + * * @author Yong.Teng + * @see DateTool + * @see Locale + * @see HttpServletRequest */ public class LocaleAwareDateTool extends DateTool { diff --git a/buession-velocity/src/main/java/com/buession/velocity/tools/LocaleAwareNumberTool.java b/buession-velocity/src/main/java/com/buession/velocity/tools/LocaleAwareNumberTool.java index 3837f07f0..32b6940cc 100644 --- a/buession-velocity/src/main/java/com/buession/velocity/tools/LocaleAwareNumberTool.java +++ b/buession-velocity/src/main/java/com/buession/velocity/tools/LocaleAwareNumberTool.java @@ -21,7 +21,7 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2020 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.velocity.tools; @@ -33,7 +33,12 @@ import java.util.Locale; /** + * Tool for working with {@link Number} with request locale in Velocity templates. + * * @author Yong.Teng + * @see NumberTool + * @see Locale + * @see HttpServletRequest */ public class LocaleAwareNumberTool extends NumberTool { @@ -41,12 +46,12 @@ public class LocaleAwareNumberTool extends NumberTool { private final HttpServletRequest request; - public LocaleAwareNumberTool(HttpServletRequest request){ + public LocaleAwareNumberTool(HttpServletRequest request) { this.request = request; } @Override - public Locale getLocale(){ + public Locale getLocale() { return RequestContextUtils.getLocale(request); } diff --git a/buession-velocity/src/main/java/com/buession/velocity/tools/ValidateTool.java b/buession-velocity/src/main/java/com/buession/velocity/tools/ValidateTool.java new file mode 100644 index 000000000..9f59a184f --- /dev/null +++ b/buession-velocity/src/main/java/com/buession/velocity/tools/ValidateTool.java @@ -0,0 +1,903 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2023 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.velocity.tools; + +import com.buession.core.validator.Validate; +import com.buession.core.validator.routines.TelValidator; +import org.apache.velocity.tools.config.DefaultKey; +import org.apache.velocity.tools.generic.SafeConfig; + +import java.util.Collection; +import java.util.Date; +import java.util.Enumeration; +import java.util.Iterator; +import java.util.Map; + +/** + * 验证工具 + * + * @author Yong.Teng + * @since 2.3.2 + */ +@DefaultKey("validate") +public class ValidateTool extends SafeConfig { + + /** + * 验证是否为 NULL + * + * @param var + * 待验证的对象 + * + * @return 为 NULL 时,返回 TRUE;否则,返回 FALSE + */ + public boolean isNull(final Object var) { + return Validate.isNull(var); + } + + /** + * 验证是否不为 NULL + * + * @param var + * 待验证的对象 + * + * @return 不为 NULL 时,返回 TRUE;否则,返回 FALSE + */ + public boolean isNotNull(final Object var) { + return Validate.isNotNull(var); + } + + /** + * 验证一个有序字符集合是否为 null、或空字符串或者空白字符 + * + * @param charSequence + * 待验证的有序字符集合 + * + * @return 为 NULL 或长度为 0 或为空白字符串时,返回 TRUE;否则,返回 FALSE + */ + public boolean isBlank(final CharSequence charSequence) { + return Validate.isNotNull(charSequence); + } + + /** + * 验证一个有序字符集合是否不为 null、空字符串且不仅仅为空白字符串 + * + * @param charSequence + * 待验证的有序字符集合 + * + * @return 不为 null、空字符串且不仅仅为空白字符串时,返回 TRUE;否则,返回 FALSE + */ + public boolean isNotBlank(final CharSequence charSequence) { + return Validate.isNotBlank(charSequence); + } + + /** + * 验证一个有序字符集合是否为空 + * + * @param charSequence + * 待验证的有序字符集合 + * + * @return 为 NULL 或长度为 0 时,返回 TRUE;否则,返回 FALSE + */ + public boolean isEmpty(final CharSequence charSequence) { + return Validate.isEmpty(charSequence); + } + + /** + * 验证数组是否为空 + * + * @param array + * 待验证数组 + * + * @return 为 NULL 或长度为 0 时,返回 TRUE;否则,返回 FALSE + */ + public boolean isEmpty(final float[] array) { + return Validate.isEmpty(array); + } + + /** + * 验证数组是否为空 + * + * @param array + * 待验证数组 + * + * @return 为 NULL 或长度为 0 时,返回 TRUE;否则,返回 FALSE + */ + public boolean isEmpty(final double[] array) { + return Validate.isEmpty(array); + } + + /** + * 验证数组是否为空 + * + * @param array + * 待验证数组 + * + * @return 为 NULL 或长度为 0 时,返回 TRUE;否则,返回 FALSE + */ + public boolean isEmpty(final short[] array) { + return Validate.isEmpty(array); + } + + /** + * 验证数组是否为空 + * + * @param array + * 待验证数组 + * + * @return 为 NULL 或长度为 0 时,返回 TRUE;否则,返回 FALSE + */ + public boolean isEmpty(final int[] array) { + return Validate.isEmpty(array); + } + + /** + * 验证数组是否为空 + * + * @param array + * 待验证数组 + * + * @return 为 NULL 或长度为 0 时,返回 TRUE;否则,返回 FALSE + */ + public boolean isEmpty(final long[] array) { + return Validate.isEmpty(array); + } + + /** + * 验证数组是否为空 + * + * @param array + * 待验证数组 + * + * @return 为 NULL 或长度为 0 时,返回 TRUE;否则,返回 FALSE + */ + public boolean isEmpty(final byte[] array) { + return Validate.isEmpty(array); + } + + /** + * 验证数组是否为空 + * + * @param array + * 待验证数组 + * + * @return 为 NULL 或长度为 0 时,返回 TRUE;否则,返回 FALSE + */ + public boolean isEmpty(final char[] array) { + return Validate.isEmpty(array); + } + + /** + * 验证数组是否为空 + * + * @param array + * 待验证数组 + * + * @return 为 NULL 或长度为 0 时,返回 TRUE;否则,返回 FALSE + */ + public boolean isEmpty(final boolean[] array) { + return Validate.isEmpty(array); + } + + /** + * 验证数组是否为空 + * + * @param array + * 待验证数组 + * + * @return 为 NULL 或长度为 0 时,返回 TRUE;否则,返回 FALSE + */ + public boolean isEmpty(final Object[] array) { + return Validate.isEmpty(array); + } + + /** + * 验证一个容器是否为空 + * + * @param collection + * 待验证的容器 + * + * @return 为 NULL 或不含有元素时,返回 TRUE;否则,返回 FALSE + */ + public boolean isEmpty(final Collection collection) { + return Validate.isEmpty(collection); + } + + /** + * 验证一个 Map 是否为空 + * + * @param map + * 待验证的容器 + * + * @return 为 NULL 或不含有元素时,返回 TRUE;否则,返回 FALSE + */ + public boolean isEmpty(final Map map) { + return Validate.isEmpty(map); + } + + /** + * 验证一个迭代器是否为空 + * + * @param iterator + * 待验证的迭代器 + * + * @return 为 NULL 或不含有元素时,返回 TRUE;否则,返回 FALSE + */ + public boolean isEmpty(final Iterator iterator) { + return Validate.isEmpty(iterator); + } + + /** + * 验证一个 Enumeration 是否为空 + * + * @param enumeration + * 待验证的迭代器 + * + * @return 为 NULL 或不含有元素时,返回 TRUE;否则,返回 FALSE + */ + public boolean isEmpty(final Enumeration enumeration) { + return Validate.isEmpty(enumeration); + } + + /** + * 验证一个有序字符集合是否不为空 + * + * @param charSequence + * 待验证的有序字符集合 + * + * @return 不为 NULL 且长度大于 0 时,返回 TRUE;否则,返回 FALSE + */ + public boolean isNotEmpty(final CharSequence charSequence) { + return Validate.isNotEmpty(charSequence); + } + + /** + * 验证数组是否不为空 + * + * @param array + * 待验证数组 + * + * @return 不为 NULL 且长度大于 0 时,返回 TRUE;否则,返回 FALSE + */ + public boolean isNotEmpty(final float[] array) { + return Validate.isNotEmpty(array); + } + + /** + * 验证数组是否不为空 + * + * @param array + * 待验证数组 + * + * @return 不为 NULL 且长度大于 0 时,返回 TRUE;否则,返回 FALSE + */ + public boolean isNotEmpty(final double[] array) { + return Validate.isNotEmpty(array); + } + + /** + * 验证数组是否不为空 + * + * @param array + * 待验证数组 + * + * @return 不为 NULL 且长度大于 0 时,返回 TRUE;否则,返回 FALSE + */ + public boolean isNotEmpty(final short[] array) { + return Validate.isNotEmpty(array); + } + + /** + * 验证数组是否不为空 + * + * @param array + * 待验证数组 + * + * @return 不为 NULL 且长度大于 0 时,返回 TRUE;否则,返回 FALSE + */ + public boolean isNotEmpty(final int[] array) { + return Validate.isNotEmpty(array); + } + + /** + * 验证数组是否不为空 + * + * @param array + * 待验证数组 + * + * @return 不为 NULL 且长度大于 0 时,返回 TRUE;否则,返回 FALSE + */ + public boolean isNotEmpty(final long[] array) { + return Validate.isNotEmpty(array); + } + + /** + * 验证数组是否不为空 + * + * @param array + * 待验证数组 + * + * @return 不为 NULL 且长度大于 0 时,返回 TRUE;否则,返回 FALSE + */ + public boolean isNotEmpty(final byte[] array) { + return Validate.isNotEmpty(array); + } + + /** + * 验证数组是否不为空 + * + * @param array + * 待验证数组 + * + * @return 不为 NULL 且长度大于 0 时,返回 TRUE;否则,返回 FALSE + */ + public boolean isNotEmpty(final char[] array) { + return Validate.isNotEmpty(array); + } + + /** + * 验证数组是否不为空 + * + * @param array + * 待验证数组 + * + * @return 不为 NULL 且长度大于 0 时,返回 TRUE;否则,返回 FALSE + */ + public boolean isNotEmpty(final boolean[] array) { + return Validate.isNotEmpty(array); + } + + /** + * 验证数组是否不为空 + * + * @param array + * 待验证数组 + * + * @return 不为 NULL 且长度大于 0 时,返回 TRUE;否则,返回 FALSE + */ + public boolean isNotEmpty(final Object[] array) { + return Validate.isNotEmpty(array); + } + + /** + * 验证一个容器是否不为空 + * + * @param collection + * 待验证的容器 + * + * @return 不为 NULL 且含有元素时,返回 TRUE;否则,返回 FALSE + */ + public boolean isNotEmpty(final Collection collection) { + return Validate.isNotEmpty(collection); + } + + /** + * 验证一个 Map 是否不为空 + * + * @param map + * 待验证的容器 + * + * @return 不为 NULL 且含有元素时,返回 TRUE;否则,返回 FALSE + */ + public boolean isNotEmpty(final Map map) { + return Validate.isNotEmpty(map); + } + + /** + * 验证一个迭代器是否不为空 + * + * @param iterator + * 待验证的迭代器 + * + * @return 不为 NULL 且含有元素时,返回 TRUE;否则,返回 FALSE + */ + public boolean isNotEmpty(final Iterator iterator) { + return Validate.isNotEmpty(iterator); + } + + /** + * 验证一个 Enumeration 是否不为空 + * + * @param enumeration + * 待验证的迭代器 + * + * @return 不为 NULL 且含有元素时,返回 TRUE;否则,返回 FALSE + */ + public boolean isNotEmpty(final Enumeration enumeration) { + return Validate.isNotEmpty(enumeration); + } + + /** + * 验证一个有序字符集合是否不为 null、空字符串且不仅仅为空白字符串 + * + * @param charSequence + * 待验证的有序字符集合 + * + * @return 不为 null、空字符串且不仅仅为空白字符串时,返回 TRUE;否则,返回 FALSE + */ + public boolean hasText(final CharSequence charSequence) { + return Validate.hasText(charSequence); + } + + /** + * 验证一个 long 型数值,是否在两个值之间 + * + * @param value + * 待验证的数值 + * @param min + * 最小值 + * @param max + * 最大值 + * + * @return 在两个值之间时,返回 TRUE;否则,返回 FALSE + */ + public boolean isBetween(final long value, final long min, final long max) { + return Validate.isBetween(value, min, max); + } + + /** + * 验证一个 long 型数值,是否在两个值之间 + * + * @param value + * 待验证的数值 + * @param min + * 最小值 + * @param max + * 最大值 + * @param isContain + * 是否包含最小值或最大值 + * + * @return 在两个值之间时,返回 TRUE;否则,返回 FALSE + */ + public boolean isBetween(final long value, final long min, final long max, final boolean isContain) { + return Validate.isBetween(value, min, max, isContain); + } + + /** + * 验证一个 int 型数值,是否在两个值之间 + * + * @param value + * 待验证的数值 + * @param min + * 最小值 + * @param max + * 最大值 + * + * @return 在两个值之间时,返回 TRUE;否则,返回 FALSE + */ + public boolean isBetween(final int value, final int min, final int max) { + return Validate.isBetween(value, min, max); + } + + /** + * 验证一个 int 型数值,是否在两个值之间 + * + * @param value + * 待验证的数值 + * @param min + * 最小值 + * @param max + * 最大值 + * @param isContain + * 是否包含最小值或最大值 + * + * @return 在两个值之间时,返回 TRUE;否则,返回 FALSE + */ + public boolean isBetween(final int value, final int min, final int max, final boolean isContain) { + return Validate.isBetween(value, min, max, isContain); + } + + /** + * 验证一个 double 型数值,是否在两个值之间 + * + * @param value + * 待验证的数值 + * @param min + * 最小值 + * @param max + * 最大值 + * + * @return 在两个值之间时,返回 TRUE;否则,返回 FALSE + */ + public boolean isBetween(final double value, final double min, final double max) { + return Validate.isBetween(value, min, max); + } + + /** + * 验证一个 double 型数值,是否在两个值之间 + * + * @param value + * 待验证的数值 + * @param min + * 最小值 + * @param max + * 最大值 + * @param isContain + * 是否包含最小值或最大值 + * + * @return 在两个值之间时,返回 TRUE;否则,返回 FALSE + */ + public boolean isBetween(final double value, final double min, final double max, final boolean isContain) { + return Validate.isBetween(value, min, max, isContain); + } + + /** + * 验证一个 float 型数值,是否在两个值之间 + * + * @param value + * 待验证的数值 + * @param min + * 最小值 + * @param max + * 最大值 + * + * @return 在两个值之间时,返回 TRUE;否则,返回 FALSE + */ + public boolean isBetween(final float value, final float min, final float max) { + return Validate.isBetween(value, min, max); + } + + /** + * 验证一个 float 型数值,是否在两个值之间 + * + * @param value + * 待验证的数值 + * @param min + * 最小值 + * @param max + * 最大值 + * @param isContain + * 是否包含最小值或最大值 + * + * @return 在两个值之间时,返回 TRUE;否则,返回 FALSE + */ + public boolean isBetween(final float value, final float min, final float max, final boolean isContain) { + return Validate.isBetween(value, min, max, isContain); + } + + /** + * 验证是否为英文字符串 + * + * @param charSequence + * 待验证的字符串 + * + * @return Boolean + */ + public boolean isAlpha(final CharSequence charSequence) { + return Validate.isAlpha(charSequence); + } + + /** + * 验证是否为英文字符 + * + * @param ch + * 待验证的字符 + * + * @return Boolean + */ + public boolean isAlpha(final char ch) { + return Validate.isAlpha(ch); + } + + /** + * 验证是否为数字字符串 + * + * @param charSequence + * 待验证的字符串 + * + * @return Boolean + */ + public boolean isNumeric(final CharSequence charSequence) { + return Validate.isNumeric(charSequence); + } + + /** + * 验证是否为数字字符 + * + * @param ch + * 待验证的字符 + * + * @return Boolean + */ + public boolean isNumeric(final char ch) { + return Validate.isNumeric(ch); + } + + /** + * 验证是否为数字字符串 + * + * @param charSequence + * 待验证的字符串 + * + * @return Boolean + */ + public boolean isDigit(final CharSequence charSequence) { + return Validate.isDigit(charSequence); + } + + /** + * 验证是否为数字字符 + * + * @param ch + * 待验证的字符 + * + * @return Boolean + */ + public boolean isDigit(final char ch) { + return Validate.isDigit(ch); + } + + /** + * 验证是否为英文或数字字符串 + * + * @param charSequence + * 待验证的字符串 + * + * @return Boolean + */ + public boolean isAlnum(final CharSequence charSequence) { + return Validate.isAlnum(charSequence); + } + + /** + * 验证是否为英文或数字字符 + * + * @param ch + * 待验证的字符 + * + * @return Boolean + */ + public boolean isAlnum(final char ch) { + return Validate.isAlnum(ch); + } + + /** + * 验证是否为 16 进制字符串 + * + * @param charSequence + * 待验证的字符串 + * + * @return Boolean + */ + public boolean isXdigit(final CharSequence charSequence) { + return Validate.isXdigit(charSequence); + } + + /** + * 验证是否为 16 进制字符 + * + * @param ch + * 待验证的字符 + * + * @return Boolean + */ + public boolean isXdigit(final char ch) { + return Validate.isXdigit(ch); + } + + /** + * 验证是否为电话号码 + * + * @param charSequence + * 待验证的字符串 + * + * @return Boolean + */ + public boolean isTel(final CharSequence charSequence) { + return Validate.isTel(charSequence); + } + + /** + * 验证是否为电话号码 + * + * @param charSequence + * 待验证的字符串 + * @param areaCodeType + * 是否包含区号 + * + * @return Boolean + */ + public boolean isTel(final CharSequence charSequence, final TelValidator.AreaCodeType areaCodeType) { + return Validate.isTel(charSequence, areaCodeType); + } + + /** + * 验证是否为手机号码 + * + * @param charSequence + * 待验证的字符串 + * + * @return Boolean + */ + public boolean isMobile(final CharSequence charSequence) { + return Validate.isMobile(charSequence); + } + + /** + * 验证是否为邮政编码 + * + * @param charSequence + * 待验证的字符串 + * + * @return Boolean + */ + public boolean isPostCode(final CharSequence charSequence) { + return Validate.isPostCode(charSequence); + } + + /** + * 验证是否为域名 + * + * @param charSequence + * 待验证的字符串 + * + * @return Boolean + */ + public boolean isEmail(final CharSequence charSequence) { + return Validate.isEmail(charSequence); + } + + /** + * 验证是否为 QQValidator 号码 + * + * @param charSequence + * 待验证的字符串 + * + * @return Boolean + */ + public boolean isQQ(final CharSequence charSequence) { + return Validate.isQQ(charSequence); + } + + /** + * 验证是否为身份证号码(仅支持 18 位身份证号码) + * + * @param charSequence + * 待验证的字符串 + * + * @return Boolean + */ + public boolean isIDCard(final CharSequence charSequence) { + return Validate.isIDCard(charSequence); + } + + /** + * 验证是否为身份证号码(仅支持 18 位身份证号码) + * + * @param charSequence + * 待验证的字符串 + * @param strict + * 是否和生日严格匹配 + * @param birthday + * 生日日期 + * + * @return Boolean + */ + public boolean isIDCard(final CharSequence charSequence, final boolean strict, final Date birthday) { + return Validate.isIDCard(charSequence, strict, birthday); + } + + /** + * 验证字符串是否为 ISBNValidator 10 + * + * @param charSequence + * 待验证的字符串 + * @param separator + * ISBNValidator 分隔符 + * + * @return Boolean + */ + public boolean isIsbn10(final CharSequence charSequence, final char separator) { + return Validate.isIsbn10(charSequence, separator); + } + + /** + * 验证字符串是否为 ISBNValidator 13 + * + * @param charSequence + * 待验证的字符串 + * @param separator + * ISBNValidator 分隔符 + * + * @return Boolean + */ + public boolean isIsbn13(final CharSequence charSequence, final char separator) { + return Validate.isIsbn13(charSequence, separator); + } + + /** + * 验证字符串是否为 ISBN + * + * @param charSequence + * 待验证的字符串 + * @param separator + * ISBNValidator 分隔符 + * + * @return Boolean + */ + public boolean isIsbn(final CharSequence charSequence, final char separator) { + return Validate.isIsbn(charSequence, separator); + } + + /** + * 验证字符串是否为 IPv4 + * + * @param charSequence + * 待验证的字符串 + * + * @return Boolean + */ + public boolean isIpV4(final CharSequence charSequence) { + return Validate.isIpV4(charSequence); + } + + /** + * 验证字符串是否为 IPv6 + * + * @param charSequence + * 待验证的字符串 + * + * @return Boolean + */ + public boolean isIpV6(final CharSequence charSequence) { + return Validate.isIpV6(charSequence); + } + + /** + * 验证字符串是否为 IP + * + * @param charSequence + * 待验证的字符串 + * + * @return Boolean + */ + public boolean isIp(final CharSequence charSequence) { + return Validate.isIp(charSequence); + } + + /** + * 验证是否为合法的端口 + * + * @param port + * 端口号 + * + * @return Boolean + */ + public boolean isPort(final int port) { + return Validate.isPort(port); + } + + /** + * 验证字符串是否为合法的 MimeType + * + * @param charSequence + * 待验证的字符串 + * + * @return Boolean + */ + public boolean isMimeType(final CharSequence charSequence) { + return Validate.isMimeType(charSequence); + } + +} diff --git a/buession-velocity/src/main/java/com/buession/velocity/tools/package-info.java b/buession-velocity/src/main/java/com/buession/velocity/tools/package-info.java index 20c1ba4a2..0cd338020 100644 --- a/buession-velocity/src/main/java/com/buession/velocity/tools/package-info.java +++ b/buession-velocity/src/main/java/com/buession/velocity/tools/package-info.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2019 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ /** diff --git a/buession-velocity/src/test/java/com/buession/velocity/tools/User.java b/buession-velocity/src/test/java/com/buession/velocity/tools/User.java new file mode 100644 index 000000000..b095602dd --- /dev/null +++ b/buession-velocity/src/test/java/com/buession/velocity/tools/User.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2023 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.velocity.tools; + +import java.util.Date; +import java.util.List; + +/** + * @author Yong.Teng + * @since 2.3.2 + */ +public class User { + + private long id; + + private String username; + + private Date createdAt; + + private String createdIp; + + private List ips; + + private Boolean status; + + private boolean isDeleted; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public Date getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + + public String getCreatedIp() { + return createdIp; + } + + public void setCreatedIp(String createdIp) { + this.createdIp = createdIp; + } + + public List getIps() { + return ips; + } + + public void setIps(List ips) { + this.ips = ips; + } + + public Boolean getStatus() { + return status; + } + + public void setStatus(Boolean status) { + this.status = status; + } + + public boolean isDeleted() { + return isDeleted; + } + + public void setDeleted(boolean deleted) { + isDeleted = deleted; + } +} diff --git a/buession-web/pom.xml b/buession-web/pom.xml index dff3239cc..3ce530a4e 100644 --- a/buession-web/pom.xml +++ b/buession-web/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.1 + 2.3.2 buession-web http://www.buession.com/ diff --git a/buession-web/src/main/java/com/buession/web/aop/handler/AbstractContentTypeAnnotationHandler.java b/buession-web/src/main/java/com/buession/web/aop/handler/AbstractContentTypeAnnotationHandler.java index 006a76998..7803401e6 100644 --- a/buession-web/src/main/java/com/buession/web/aop/handler/AbstractContentTypeAnnotationHandler.java +++ b/buession-web/src/main/java/com/buession/web/aop/handler/AbstractContentTypeAnnotationHandler.java @@ -19,22 +19,41 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.aop.handler; import com.buession.aop.handler.AbstractAnnotationHandler; import com.buession.web.http.response.annotation.ContentType; +import org.springframework.util.StringValueResolver; /** + * 注解 {@link ContentType} 处理器抽象类 + * * @author Yong.Teng */ public abstract class AbstractContentTypeAnnotationHandler extends AbstractAnnotationHandler implements ContentTypeAnnotationHandler { - public AbstractContentTypeAnnotationHandler(){ + /** + * 构造函数 + */ + @Deprecated + public AbstractContentTypeAnnotationHandler() { super(ContentType.class); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public AbstractContentTypeAnnotationHandler(StringValueResolver stringValueResolver) { + super(ContentType.class, stringValueResolver); + } + } diff --git a/buession-web/src/main/java/com/buession/web/aop/handler/AbstractDocumentMetaDataAnnotationHandler.java b/buession-web/src/main/java/com/buession/web/aop/handler/AbstractDocumentMetaDataAnnotationHandler.java index 6c0b43ef6..591e6d58f 100644 --- a/buession-web/src/main/java/com/buession/web/aop/handler/AbstractDocumentMetaDataAnnotationHandler.java +++ b/buession-web/src/main/java/com/buession/web/aop/handler/AbstractDocumentMetaDataAnnotationHandler.java @@ -30,19 +30,38 @@ import com.buession.web.mvc.view.document.DocumentMetaData; import com.buession.web.mvc.view.document.MetaData; import org.springframework.ui.Model; +import org.springframework.util.StringValueResolver; /** + * 注解 {@link DocumentMetaData} 处理器抽象类 + * * @author Yong.Teng */ public abstract class AbstractDocumentMetaDataAnnotationHandler extends AbstractAnnotationHandler implements DocumentMetaDataAnnotationHandler { - public AbstractDocumentMetaDataAnnotationHandler(){ + /** + * 构造函数 + */ + @Deprecated + public AbstractDocumentMetaDataAnnotationHandler() { super(DocumentMetaData.class); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public AbstractDocumentMetaDataAnnotationHandler(StringValueResolver stringValueResolver) { + super(DocumentMetaData.class, stringValueResolver); + } + @Override - public void execute(MethodInvocation mi, DocumentMetaData documentMetaData){ + public void execute(MethodInvocation mi, DocumentMetaData documentMetaData) { if(Validate.isNotEmpty(mi.getArguments())){ for(Object argument : mi.getArguments()){ if(argument instanceof Model){ @@ -53,22 +72,32 @@ public void execute(MethodInvocation mi, DocumentMetaData documentMetaData){ } } - protected static void addModelAttribute(final Model model, final DocumentMetaData metaData){ + protected void addModelAttribute(final Model model, final DocumentMetaData metaData) { final String attrName = Validate.hasText(metaData.attrName()) ? metaData.attrName() : DocumentMetaData.DEFAULT_ATTR_NAME; model.addAttribute(attrName, metaDataConvert(metaData)); } - private static MetaData metaDataConvert(final DocumentMetaData documentMetaData){ + private MetaData metaDataConvert(final DocumentMetaData documentMetaData) { final MetaData metaData = new MetaData(); - metaData.setTitle(documentMetaData.title()); - metaData.setAuthor(documentMetaData.author()); - metaData.setCharset(documentMetaData.charset()); - metaData.setKeywords(documentMetaData.keywords()); - metaData.setDescription(documentMetaData.description()); - metaData.setAuthor(documentMetaData.author()); - metaData.setCopyright(documentMetaData.copyright()); + if(stringValueResolver == null){ + metaData.setTitle(documentMetaData.title()); + metaData.setAuthor(documentMetaData.author()); + metaData.setCharset(documentMetaData.charset()); + metaData.setKeywords(documentMetaData.keywords()); + metaData.setDescription(documentMetaData.description()); + metaData.setAuthor(documentMetaData.author()); + metaData.setCopyright(documentMetaData.copyright()); + }else{ + metaData.setTitle(stringValueResolver.resolveStringValue(documentMetaData.title())); + metaData.setAuthor(stringValueResolver.resolveStringValue(documentMetaData.author())); + metaData.setCharset(stringValueResolver.resolveStringValue(documentMetaData.charset())); + metaData.setKeywords(stringValueResolver.resolveStringValue(documentMetaData.keywords())); + metaData.setDescription(stringValueResolver.resolveStringValue(documentMetaData.description())); + metaData.setAuthor(stringValueResolver.resolveStringValue(documentMetaData.author())); + metaData.setCopyright(stringValueResolver.resolveStringValue(documentMetaData.copyright())); + } return metaData; } diff --git a/buession-web/src/main/java/com/buession/web/aop/handler/AbstractHttpCacheAnnotationHandler.java b/buession-web/src/main/java/com/buession/web/aop/handler/AbstractHttpCacheAnnotationHandler.java index 1c612e919..325cfdaa3 100644 --- a/buession-web/src/main/java/com/buession/web/aop/handler/AbstractHttpCacheAnnotationHandler.java +++ b/buession-web/src/main/java/com/buession/web/aop/handler/AbstractHttpCacheAnnotationHandler.java @@ -19,22 +19,41 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.aop.handler; import com.buession.aop.handler.AbstractAnnotationHandler; import com.buession.web.http.response.annotation.HttpCache; +import org.springframework.util.StringValueResolver; /** + * 注解 {@link HttpCache} 处理器抽象类 + * * @author Yong.Teng */ public abstract class AbstractHttpCacheAnnotationHandler extends AbstractAnnotationHandler implements HttpCacheAnnotationHandler { - public AbstractHttpCacheAnnotationHandler(){ + /** + * 构造函数 + */ + @Deprecated + public AbstractHttpCacheAnnotationHandler() { super(HttpCache.class); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public AbstractHttpCacheAnnotationHandler(StringValueResolver stringValueResolver) { + super(HttpCache.class, stringValueResolver); + } + } diff --git a/buession-web/src/main/java/com/buession/web/aop/handler/AbstractResponseHeaderAnnotationHandler.java b/buession-web/src/main/java/com/buession/web/aop/handler/AbstractResponseHeaderAnnotationHandler.java index f9d2f0448..53cf459d7 100644 --- a/buession-web/src/main/java/com/buession/web/aop/handler/AbstractResponseHeaderAnnotationHandler.java +++ b/buession-web/src/main/java/com/buession/web/aop/handler/AbstractResponseHeaderAnnotationHandler.java @@ -19,22 +19,41 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.aop.handler; import com.buession.aop.handler.AbstractAnnotationHandler; import com.buession.web.http.response.annotation.ResponseHeader; +import org.springframework.util.StringValueResolver; /** + * 注解 {@link ResponseHeader} 处理器抽象类 + * * @author Yong.Teng */ public abstract class AbstractResponseHeaderAnnotationHandler extends AbstractAnnotationHandler implements ResponseHeaderAnnotationHandler { - public AbstractResponseHeaderAnnotationHandler(){ + /** + * 构造函数 + */ + @Deprecated + public AbstractResponseHeaderAnnotationHandler() { super(ResponseHeader.class); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public AbstractResponseHeaderAnnotationHandler(StringValueResolver stringValueResolver) { + super(ResponseHeader.class, stringValueResolver); + } + } diff --git a/buession-web/src/main/java/com/buession/web/aop/handler/AbstractResponseHeadersAnnotationHandler.java b/buession-web/src/main/java/com/buession/web/aop/handler/AbstractResponseHeadersAnnotationHandler.java index 26c1f17ae..050bd51f9 100644 --- a/buession-web/src/main/java/com/buession/web/aop/handler/AbstractResponseHeadersAnnotationHandler.java +++ b/buession-web/src/main/java/com/buession/web/aop/handler/AbstractResponseHeadersAnnotationHandler.java @@ -19,22 +19,41 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.aop.handler; import com.buession.aop.handler.AbstractAnnotationHandler; import com.buession.web.http.response.annotation.ResponseHeaders; +import org.springframework.util.StringValueResolver; /** + * 注解 {@link ResponseHeaders} 处理器抽象类 + * * @author Yong.Teng */ public abstract class AbstractResponseHeadersAnnotationHandler extends AbstractAnnotationHandler implements ResponseHeadersAnnotationHandler { - public AbstractResponseHeadersAnnotationHandler(){ + /** + * 构造函数 + */ + @Deprecated + public AbstractResponseHeadersAnnotationHandler() { super(ResponseHeaders.class); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public AbstractResponseHeadersAnnotationHandler(StringValueResolver stringValueResolver) { + super(ResponseHeaders.class, stringValueResolver); + } + } diff --git a/buession-web/src/main/java/com/buession/web/aop/interceptor/AbstractHttpCacheAnnotationMethodInterceptor.java b/buession-web/src/main/java/com/buession/web/aop/interceptor/AbstractHttpCacheAnnotationMethodInterceptor.java index 35cbd457c..7681f11e5 100644 --- a/buession-web/src/main/java/com/buession/web/aop/interceptor/AbstractHttpCacheAnnotationMethodInterceptor.java +++ b/buession-web/src/main/java/com/buession/web/aop/interceptor/AbstractHttpCacheAnnotationMethodInterceptor.java @@ -39,12 +39,12 @@ public abstract class AbstractHttpCacheAnnotationMethodInterceptor extends AbstractAnnotationMethodInterceptor implements HttpCacheAnnotationMethodInterceptor { - public AbstractHttpCacheAnnotationMethodInterceptor(AnnotationHandler handler){ + public AbstractHttpCacheAnnotationMethodInterceptor(AnnotationHandler handler) { super(handler); } public AbstractHttpCacheAnnotationMethodInterceptor(AnnotationHandler handler, - AnnotationResolver resolver){ + AnnotationResolver resolver) { super(handler, resolver); } diff --git a/buession-web/src/main/java/com/buession/web/exception/PageNotFoundException.java b/buession-web/src/main/java/com/buession/web/exception/PageNotFoundException.java index e6c52cd64..6148412c9 100644 --- a/buession-web/src/main/java/com/buession/web/exception/PageNotFoundException.java +++ b/buession-web/src/main/java/com/buession/web/exception/PageNotFoundException.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2019 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.exception; @@ -29,24 +29,27 @@ */ public class PageNotFoundException extends Exception { - public PageNotFoundException(){ + private final static long serialVersionUID = -9088756918218101398L; + + public PageNotFoundException() { super(); } - public PageNotFoundException(String message){ + public PageNotFoundException(String message) { super(message); } - public PageNotFoundException(String message, Throwable cause){ + public PageNotFoundException(String message, Throwable cause) { super(message, cause); } - public PageNotFoundException(Throwable cause){ + public PageNotFoundException(Throwable cause) { super(cause); } public PageNotFoundException(String message, Throwable cause, boolean enableSuppression, boolean - writableStackTrace){ + writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); } + } diff --git a/buession-web/src/main/java/com/buession/web/http/request/annotation/RequestClientIpAnnotationUtils.java b/buession-web/src/main/java/com/buession/web/http/request/annotation/RequestClientIpAnnotationUtils.java index 3c1f526dd..98f99f1b4 100644 --- a/buession-web/src/main/java/com/buession/web/http/request/annotation/RequestClientIpAnnotationUtils.java +++ b/buession-web/src/main/java/com/buession/web/http/request/annotation/RequestClientIpAnnotationUtils.java @@ -28,6 +28,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.MethodParameter; +import org.springframework.lang.Nullable; import java.net.InetAddress; import java.net.UnknownHostException; @@ -41,11 +42,11 @@ public class RequestClientIpAnnotationUtils { private final static Logger logger = LoggerFactory.getLogger(RequestClientIpAnnotationUtils.class); - private RequestClientIpAnnotationUtils(){ + private RequestClientIpAnnotationUtils() { } - public static boolean checkSupports(final MethodParameter parameter){ + public static boolean checkSupports(final MethodParameter parameter) { if(parameter.hasParameterAnnotation(RequestClientIp.class) == false){ return false; } @@ -55,7 +56,9 @@ public static boolean checkSupports(final MethodParameter parameter){ InetAddress.class.isAssignableFrom(clazz); } - public static Object resolveNamedValue(final MethodParameter parameter, final Function fn){ + @Nullable + public static Object resolveNamedValue(final MethodParameter parameter, + final Function fn) { Class clazz = parameter.nestedIfOptional().getNestedParameterType(); if(Long.class.isAssignableFrom(clazz)){ diff --git a/buession-web/src/main/java/com/buession/web/mvc/Pagination.java b/buession-web/src/main/java/com/buession/web/mvc/Pagination.java index b6dd1d12b..4c722a7ea 100644 --- a/buession-web/src/main/java/com/buession/web/mvc/Pagination.java +++ b/buession-web/src/main/java/com/buession/web/mvc/Pagination.java @@ -49,6 +49,7 @@ public Pagination() { */ public Pagination(int page, int pagesize) { super(page, pagesize); + setNextPage(getPage() + 1); } /** @@ -63,6 +64,7 @@ public Pagination(int page, int pagesize) { */ public Pagination(int page, int pagesize, long totalRecords) { super(page, pagesize, totalRecords); + setNextPage(getPage() + 1); } } diff --git a/buession-web/src/main/java/com/buession/web/reactive/aop/aopalliance/interceptor/ReactiveAopAllianceAnnotationsMethodInterceptor.java b/buession-web/src/main/java/com/buession/web/reactive/aop/aopalliance/interceptor/ReactiveAopAllianceAnnotationsMethodInterceptor.java index 3a9c98997..3de3860a1 100644 --- a/buession-web/src/main/java/com/buession/web/reactive/aop/aopalliance/interceptor/ReactiveAopAllianceAnnotationsMethodInterceptor.java +++ b/buession-web/src/main/java/com/buession/web/reactive/aop/aopalliance/interceptor/ReactiveAopAllianceAnnotationsMethodInterceptor.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.reactive.aop.aopalliance.interceptor; @@ -28,6 +28,7 @@ import com.buession.aop.resolver.SpringAnnotationResolver; import com.buession.aop.aopalliance.AbstractAopAllianceAnnotationsMethodInterceptor; import com.buession.web.reactive.aop.interceptor.*; +import org.springframework.util.StringValueResolver; import java.util.ArrayDeque; import java.util.Collection; @@ -38,7 +39,11 @@ */ public class ReactiveAopAllianceAnnotationsMethodInterceptor extends AbstractAopAllianceAnnotationsMethodInterceptor { - public ReactiveAopAllianceAnnotationsMethodInterceptor(){ + /** + * 构造函数 + */ + @Deprecated + public ReactiveAopAllianceAnnotationsMethodInterceptor() { super(); final Collection methodInterceptors = new ArrayDeque<>(5); @@ -53,4 +58,32 @@ public ReactiveAopAllianceAnnotationsMethodInterceptor(){ setMethodInterceptors(methodInterceptors); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ReactiveAopAllianceAnnotationsMethodInterceptor(StringValueResolver stringValueResolver) { + super(); + + final Collection methodInterceptors = new ArrayDeque<>(5); + final SpringAnnotationResolver springAnnotationResolver = new SpringAnnotationResolver(); + + methodInterceptors.add( + new ReactiveContentTypeAnnotationMethodInterceptor(springAnnotationResolver, stringValueResolver)); + methodInterceptors.add( + new ReactiveDocumentMetaDataAnnotationMethodInterceptor(springAnnotationResolver, stringValueResolver)); + methodInterceptors.add( + new ReactiveHttpCacheAnnotationMethodInterceptor(springAnnotationResolver, stringValueResolver)); + methodInterceptors.add( + new ReactiveResponseHeaderAnnotationMethodInterceptor(springAnnotationResolver, stringValueResolver)); + methodInterceptors.add( + new ReactiveResponseHeadersAnnotationMethodInterceptor(springAnnotationResolver, stringValueResolver)); + + setMethodInterceptors(methodInterceptors); + } + } diff --git a/buession-web/src/main/java/com/buession/web/reactive/aop/aopalliance/interceptor/ReactiveHttpAttributeSourcePointcutAdvisor.java b/buession-web/src/main/java/com/buession/web/reactive/aop/aopalliance/interceptor/ReactiveHttpAttributeSourcePointcutAdvisor.java index a6bf0af38..883b8eb6a 100644 --- a/buession-web/src/main/java/com/buession/web/reactive/aop/aopalliance/interceptor/ReactiveHttpAttributeSourcePointcutAdvisor.java +++ b/buession-web/src/main/java/com/buession/web/reactive/aop/aopalliance/interceptor/ReactiveHttpAttributeSourcePointcutAdvisor.java @@ -19,12 +19,13 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.reactive.aop.aopalliance.interceptor; import com.buession.web.aop.aopalliance.AbstractWebAttributeSourcePointcutAdvisor; +import org.springframework.util.StringValueResolver; /** * @author Yong.Teng @@ -34,8 +35,24 @@ public class ReactiveHttpAttributeSourcePointcutAdvisor extends AbstractWebAttri private final static long serialVersionUID = 8267117305963633132L; - public ReactiveHttpAttributeSourcePointcutAdvisor(){ + /** + * 构造函数 + */ + @Deprecated + public ReactiveHttpAttributeSourcePointcutAdvisor() { super(new ReactiveAopAllianceAnnotationsMethodInterceptor()); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ReactiveHttpAttributeSourcePointcutAdvisor(StringValueResolver stringValueResolver) { + super(new ReactiveAopAllianceAnnotationsMethodInterceptor(stringValueResolver)); + } + } diff --git a/buession-web/src/main/java/com/buession/web/reactive/aop/aspect/interceptor/ReactiveWebAspectAnnotationsMethodInterceptor.java b/buession-web/src/main/java/com/buession/web/reactive/aop/aspect/interceptor/ReactiveWebAspectAnnotationsMethodInterceptor.java index 07824252d..7eca62e11 100644 --- a/buession-web/src/main/java/com/buession/web/reactive/aop/aspect/interceptor/ReactiveWebAspectAnnotationsMethodInterceptor.java +++ b/buession-web/src/main/java/com/buession/web/reactive/aop/aspect/interceptor/ReactiveWebAspectAnnotationsMethodInterceptor.java @@ -31,6 +31,7 @@ import com.buession.web.reactive.aop.interceptor.ReactiveHttpCacheAnnotationMethodInterceptor; import com.buession.web.reactive.aop.interceptor.ReactiveResponseHeaderAnnotationMethodInterceptor; import com.buession.web.reactive.aop.interceptor.ReactiveResponseHeadersAnnotationMethodInterceptor; +import org.springframework.util.StringValueResolver; import java.util.ArrayDeque; import java.util.Collection; @@ -41,7 +42,11 @@ */ public class ReactiveWebAspectAnnotationsMethodInterceptor extends AbstractAspectjAnnotationsMethodInterceptor { - public ReactiveWebAspectAnnotationsMethodInterceptor(){ + /** + * 构造函数 + */ + @Deprecated + public ReactiveWebAspectAnnotationsMethodInterceptor() { super(); final Collection methodInterceptors = new ArrayDeque<>(5); @@ -55,4 +60,26 @@ public ReactiveWebAspectAnnotationsMethodInterceptor(){ setMethodInterceptors(methodInterceptors); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ReactiveWebAspectAnnotationsMethodInterceptor(StringValueResolver stringValueResolver) { + super(); + + final Collection methodInterceptors = new ArrayDeque<>(5); + + methodInterceptors.add(new ReactiveContentTypeAnnotationMethodInterceptor(stringValueResolver)); + methodInterceptors.add(new ReactiveDocumentMetaDataAnnotationMethodInterceptor(stringValueResolver)); + methodInterceptors.add(new ReactiveHttpCacheAnnotationMethodInterceptor(stringValueResolver)); + methodInterceptors.add(new ReactiveResponseHeaderAnnotationMethodInterceptor(stringValueResolver)); + methodInterceptors.add(new ReactiveResponseHeadersAnnotationMethodInterceptor(stringValueResolver)); + + setMethodInterceptors(methodInterceptors); + } + } diff --git a/buession-web/src/main/java/com/buession/web/reactive/aop/handler/ReactiveContentTypeAnnotationHandler.java b/buession-web/src/main/java/com/buession/web/reactive/aop/handler/ReactiveContentTypeAnnotationHandler.java index ee6cd6367..b3b640c63 100644 --- a/buession-web/src/main/java/com/buession/web/reactive/aop/handler/ReactiveContentTypeAnnotationHandler.java +++ b/buession-web/src/main/java/com/buession/web/reactive/aop/handler/ReactiveContentTypeAnnotationHandler.java @@ -32,20 +32,39 @@ import org.slf4j.LoggerFactory; import org.springframework.http.MediaType; import org.springframework.http.server.reactive.ServerHttpResponse; +import org.springframework.util.StringValueResolver; import java.nio.charset.Charset; /** + * Reactive 模式注解 {@link ContentType} 处理器 + * * @author Yong.Teng */ public class ReactiveContentTypeAnnotationHandler extends AbstractContentTypeAnnotationHandler { private final static Logger logger = LoggerFactory.getLogger(ReactiveContentTypeAnnotationHandler.class); + /** + * 构造函数 + */ + @Deprecated public ReactiveContentTypeAnnotationHandler() { super(); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ReactiveContentTypeAnnotationHandler(StringValueResolver stringValueResolver) { + super(stringValueResolver); + } + @Override public void execute(MethodInvocation mi, ContentType contentType) { ServerHttpResponse response = RequestUtils.getResponse(); @@ -54,9 +73,12 @@ public void execute(MethodInvocation mi, ContentType contentType) { return; } - String mime = contentType.mime(); + String mime = stringValueResolver == null ? contentType.mime() : stringValueResolver.resolveStringValue( + contentType.mime()); int i = mime.indexOf('/'); - Charset charset = Charset.forName(contentType.charset()); + Charset charset = Charset.forName( + stringValueResolver == null ? contentType.charset() : stringValueResolver.resolveStringValue( + contentType.charset())); String type = mime.substring(0, i - 1); String subType = mime.substring(i); diff --git a/buession-web/src/main/java/com/buession/web/reactive/aop/handler/ReactiveDocumentMetaDataAnnotationHandler.java b/buession-web/src/main/java/com/buession/web/reactive/aop/handler/ReactiveDocumentMetaDataAnnotationHandler.java index 62f0f6a16..a23dedc67 100644 --- a/buession-web/src/main/java/com/buession/web/reactive/aop/handler/ReactiveDocumentMetaDataAnnotationHandler.java +++ b/buession-web/src/main/java/com/buession/web/reactive/aop/handler/ReactiveDocumentMetaDataAnnotationHandler.java @@ -19,20 +19,40 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.reactive.aop.handler; import com.buession.web.aop.handler.AbstractDocumentMetaDataAnnotationHandler; +import com.buession.web.mvc.view.document.DocumentMetaData; +import org.springframework.util.StringValueResolver; /** + * Reactive 模式注解 {@link DocumentMetaData} 处理器 + * * @author Yong.Teng */ public class ReactiveDocumentMetaDataAnnotationHandler extends AbstractDocumentMetaDataAnnotationHandler { - public ReactiveDocumentMetaDataAnnotationHandler(){ + /** + * 构造函数 + */ + @Deprecated + public ReactiveDocumentMetaDataAnnotationHandler() { super(); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ReactiveDocumentMetaDataAnnotationHandler(StringValueResolver stringValueResolver) { + super(stringValueResolver); + } + } diff --git a/buession-web/src/main/java/com/buession/web/reactive/aop/handler/ReactiveHttpCacheAnnotationHandler.java b/buession-web/src/main/java/com/buession/web/reactive/aop/handler/ReactiveHttpCacheAnnotationHandler.java index baa681ba6..c8b3a4b99 100644 --- a/buession-web/src/main/java/com/buession/web/reactive/aop/handler/ReactiveHttpCacheAnnotationHandler.java +++ b/buession-web/src/main/java/com/buession/web/reactive/aop/handler/ReactiveHttpCacheAnnotationHandler.java @@ -33,18 +33,37 @@ import org.slf4j.LoggerFactory; import org.springframework.http.HttpHeaders; import org.springframework.http.server.reactive.ServerHttpResponse; +import org.springframework.util.StringValueResolver; /** + * Reactive 模式注解 {@link HttpCache} 处理器 + * * @author Yong.Teng */ public class ReactiveHttpCacheAnnotationHandler extends AbstractHttpCacheAnnotationHandler { private final static Logger logger = LoggerFactory.getLogger(ReactiveHttpCacheAnnotationHandler.class); + /** + * 构造函数 + */ + @Deprecated public ReactiveHttpCacheAnnotationHandler() { super(); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ReactiveHttpCacheAnnotationHandler(StringValueResolver stringValueResolver) { + super(stringValueResolver); + } + @Override public void execute(MethodInvocation mi, HttpCache httpCache) { ServerHttpResponse response = RequestUtils.getResponse(); @@ -57,20 +76,33 @@ public void execute(MethodInvocation mi, HttpCache httpCache) { boolean isSetCacheControl = false; if(Validate.hasText(httpCache.cacheControl())){ - httpHeaders.setCacheControl(httpCache.cacheControl()); + if(stringValueResolver == null){ + httpHeaders.setCacheControl(httpCache.cacheControl()); + }else{ + httpHeaders.setCacheControl(stringValueResolver.resolveStringValue(httpCache.cacheControl())); + } isSetCacheControl = true; } - if(Validate.hasText(httpCache.expires()) && Validate.isNumeric(httpCache.expires())){ - httpHeaders.setExpires(Long.parseLong(httpCache.expires())); + if(Validate.hasText(httpCache.expires())){ + String expires = stringValueResolver == null ? httpCache.expires() : + stringValueResolver.resolveStringValue(httpCache.expires()); + + if(Validate.isNumeric(expires)){ + httpHeaders.setExpires(Long.parseLong(expires)); - if(isSetCacheControl == false){ - httpHeaders.setCacheControl("max-age=" + httpCache.expires()); + if(isSetCacheControl == false){ + httpHeaders.setCacheControl("max-age=" + expires); + } } } if(Validate.hasText(httpCache.pragma())){ - httpHeaders.setPragma(httpCache.pragma()); + if(stringValueResolver == null){ + httpHeaders.setPragma(httpCache.pragma()); + }else{ + httpHeaders.setPragma(stringValueResolver.resolveStringValue(httpCache.pragma())); + } } } diff --git a/buession-web/src/main/java/com/buession/web/reactive/aop/handler/ReactiveResponseHeaderAnnotationHandler.java b/buession-web/src/main/java/com/buession/web/reactive/aop/handler/ReactiveResponseHeaderAnnotationHandler.java index b0d7ad91e..b8b526327 100644 --- a/buession-web/src/main/java/com/buession/web/reactive/aop/handler/ReactiveResponseHeaderAnnotationHandler.java +++ b/buession-web/src/main/java/com/buession/web/reactive/aop/handler/ReactiveResponseHeaderAnnotationHandler.java @@ -34,18 +34,37 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.server.reactive.ServerHttpResponse; +import org.springframework.util.StringValueResolver; /** + * Reactive 模式注解 {@link ResponseHeader} 处理器 + * * @author Yong.Teng */ public class ReactiveResponseHeaderAnnotationHandler extends AbstractResponseHeaderAnnotationHandler { private final static Logger logger = LoggerFactory.getLogger(ReactiveResponseHeaderAnnotationHandler.class); + /** + * 构造函数 + */ + @Deprecated public ReactiveResponseHeaderAnnotationHandler() { super(); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ReactiveResponseHeaderAnnotationHandler(StringValueResolver stringValueResolver) { + super(stringValueResolver); + } + @Override public void execute(MethodInvocation mi, ResponseHeader responseHeader) { ServerHttpResponse response = RequestUtils.getResponse(); @@ -57,6 +76,10 @@ public void execute(MethodInvocation mi, ResponseHeader responseHeader) { final boolean isExpires = HttpHeader.EXPIRES.getValue().equalsIgnoreCase(responseHeader.name()); for(String value : responseHeader.value()){ + if(stringValueResolver != null){ + value = stringValueResolver.resolveStringValue(value); + } + if(isExpires){ if(Validate.isNumeric(value)){ ResponseUtils.httpCache(response, Integer.parseInt(value)); diff --git a/buession-web/src/main/java/com/buession/web/reactive/aop/handler/ReactiveResponseHeadersAnnotationHandler.java b/buession-web/src/main/java/com/buession/web/reactive/aop/handler/ReactiveResponseHeadersAnnotationHandler.java index c6eb57872..bf4a7d7ed 100644 --- a/buession-web/src/main/java/com/buession/web/reactive/aop/handler/ReactiveResponseHeadersAnnotationHandler.java +++ b/buession-web/src/main/java/com/buession/web/reactive/aop/handler/ReactiveResponseHeadersAnnotationHandler.java @@ -36,18 +36,37 @@ import org.slf4j.LoggerFactory; import org.springframework.http.HttpHeaders; import org.springframework.http.server.reactive.ServerHttpResponse; +import org.springframework.util.StringValueResolver; /** + * Reactive 模式注解 {@link ResponseHeaders} 处理器 + * * @author Yong.Teng */ public class ReactiveResponseHeadersAnnotationHandler extends AbstractResponseHeadersAnnotationHandler { private final static Logger logger = LoggerFactory.getLogger(ReactiveResponseHeadersAnnotationHandler.class); + /** + * 构造函数 + */ + @Deprecated public ReactiveResponseHeadersAnnotationHandler() { super(); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ReactiveResponseHeadersAnnotationHandler(StringValueResolver stringValueResolver) { + super(stringValueResolver); + } + @Override public void execute(MethodInvocation mi, ResponseHeaders responseHeaders) { ServerHttpResponse response = RequestUtils.getResponse(); @@ -65,6 +84,10 @@ public void execute(MethodInvocation mi, ResponseHeaders responseHeaders) { final boolean isExpires = HttpHeader.EXPIRES.getValue().equalsIgnoreCase(header.name()); for(String value : header.value()){ + if(stringValueResolver != null){ + value = stringValueResolver.resolveStringValue(value); + } + if(isExpires){ if(Validate.isNumeric(value)){ ResponseUtils.httpCache(response, Integer.parseInt(value)); diff --git a/buession-web/src/main/java/com/buession/web/reactive/aop/interceptor/ReactiveContentTypeAnnotationMethodInterceptor.java b/buession-web/src/main/java/com/buession/web/reactive/aop/interceptor/ReactiveContentTypeAnnotationMethodInterceptor.java index ba57a12ba..f062f423b 100644 --- a/buession-web/src/main/java/com/buession/web/reactive/aop/interceptor/ReactiveContentTypeAnnotationMethodInterceptor.java +++ b/buession-web/src/main/java/com/buession/web/reactive/aop/interceptor/ReactiveContentTypeAnnotationMethodInterceptor.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.reactive.aop.interceptor; @@ -28,6 +28,7 @@ import com.buession.web.aop.interceptor.AbstractContentTypeAnnotationMethodInterceptor; import com.buession.web.http.response.annotation.ContentType; import com.buession.web.reactive.aop.handler.ReactiveContentTypeAnnotationHandler; +import org.springframework.util.StringValueResolver; /** * {@link ContentType} 注解拦截器 @@ -37,12 +38,50 @@ */ public class ReactiveContentTypeAnnotationMethodInterceptor extends AbstractContentTypeAnnotationMethodInterceptor { - public ReactiveContentTypeAnnotationMethodInterceptor(){ + /** + * 构造函数 + */ + @Deprecated + public ReactiveContentTypeAnnotationMethodInterceptor() { super(new ReactiveContentTypeAnnotationHandler()); } - public ReactiveContentTypeAnnotationMethodInterceptor(AnnotationResolver resolver){ + /** + * 构造函数 + * + * @param resolver + * 注解解析器 + */ + @Deprecated + public ReactiveContentTypeAnnotationMethodInterceptor(AnnotationResolver resolver) { super(new ReactiveContentTypeAnnotationHandler(), resolver); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ReactiveContentTypeAnnotationMethodInterceptor(StringValueResolver stringValueResolver) { + super(new ReactiveContentTypeAnnotationHandler(stringValueResolver)); + } + + /** + * 构造函数 + * + * @param resolver + * 注解解析器 + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ReactiveContentTypeAnnotationMethodInterceptor(AnnotationResolver resolver, + StringValueResolver stringValueResolver) { + super(new ReactiveContentTypeAnnotationHandler(stringValueResolver), resolver); + } + } diff --git a/buession-web/src/main/java/com/buession/web/reactive/aop/interceptor/ReactiveDocumentMetaDataAnnotationMethodInterceptor.java b/buession-web/src/main/java/com/buession/web/reactive/aop/interceptor/ReactiveDocumentMetaDataAnnotationMethodInterceptor.java index 594fa8200..b8871b4fb 100644 --- a/buession-web/src/main/java/com/buession/web/reactive/aop/interceptor/ReactiveDocumentMetaDataAnnotationMethodInterceptor.java +++ b/buession-web/src/main/java/com/buession/web/reactive/aop/interceptor/ReactiveDocumentMetaDataAnnotationMethodInterceptor.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.reactive.aop.interceptor; @@ -28,6 +28,7 @@ import com.buession.web.aop.interceptor.AbstractDocumentMetaDataAnnotationMethodInterceptor; import com.buession.web.mvc.view.document.DocumentMetaData; import com.buession.web.reactive.aop.handler.ReactiveDocumentMetaDataAnnotationHandler; +import org.springframework.util.StringValueResolver; /** * {@link DocumentMetaData} 注解拦截器 @@ -38,12 +39,50 @@ public class ReactiveDocumentMetaDataAnnotationMethodInterceptor extends AbstractDocumentMetaDataAnnotationMethodInterceptor { - public ReactiveDocumentMetaDataAnnotationMethodInterceptor(){ + /** + * 构造函数 + */ + @Deprecated + public ReactiveDocumentMetaDataAnnotationMethodInterceptor() { super(new ReactiveDocumentMetaDataAnnotationHandler()); } - public ReactiveDocumentMetaDataAnnotationMethodInterceptor(AnnotationResolver resolver){ + /** + * 构造函数 + * + * @param resolver + * 注解解析器 + */ + @Deprecated + public ReactiveDocumentMetaDataAnnotationMethodInterceptor(AnnotationResolver resolver) { super(new ReactiveDocumentMetaDataAnnotationHandler(), resolver); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ReactiveDocumentMetaDataAnnotationMethodInterceptor(StringValueResolver stringValueResolver) { + super(new ReactiveDocumentMetaDataAnnotationHandler(stringValueResolver)); + } + + /** + * 构造函数 + * + * @param resolver + * 注解解析器 + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ReactiveDocumentMetaDataAnnotationMethodInterceptor(AnnotationResolver resolver, + StringValueResolver stringValueResolver) { + super(new ReactiveDocumentMetaDataAnnotationHandler(stringValueResolver), resolver); + } + } diff --git a/buession-web/src/main/java/com/buession/web/reactive/aop/interceptor/ReactiveHttpCacheAnnotationMethodInterceptor.java b/buession-web/src/main/java/com/buession/web/reactive/aop/interceptor/ReactiveHttpCacheAnnotationMethodInterceptor.java index 60e7b9edd..df1c71098 100644 --- a/buession-web/src/main/java/com/buession/web/reactive/aop/interceptor/ReactiveHttpCacheAnnotationMethodInterceptor.java +++ b/buession-web/src/main/java/com/buession/web/reactive/aop/interceptor/ReactiveHttpCacheAnnotationMethodInterceptor.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.reactive.aop.interceptor; @@ -28,6 +28,7 @@ import com.buession.web.aop.interceptor.AbstractHttpCacheAnnotationMethodInterceptor; import com.buession.web.http.response.annotation.HttpCache; import com.buession.web.reactive.aop.handler.ReactiveHttpCacheAnnotationHandler; +import org.springframework.util.StringValueResolver; /** * {@link HttpCache} 注解拦截器 @@ -37,12 +38,50 @@ */ public class ReactiveHttpCacheAnnotationMethodInterceptor extends AbstractHttpCacheAnnotationMethodInterceptor { - public ReactiveHttpCacheAnnotationMethodInterceptor(){ + /** + * 构造函数 + */ + @Deprecated + public ReactiveHttpCacheAnnotationMethodInterceptor() { super(new ReactiveHttpCacheAnnotationHandler()); } - public ReactiveHttpCacheAnnotationMethodInterceptor(AnnotationResolver resolver){ + /** + * 构造函数 + * + * @param resolver + * 注解解析器 + */ + @Deprecated + public ReactiveHttpCacheAnnotationMethodInterceptor(AnnotationResolver resolver) { super(new ReactiveHttpCacheAnnotationHandler(), resolver); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ReactiveHttpCacheAnnotationMethodInterceptor(StringValueResolver stringValueResolver) { + super(new ReactiveHttpCacheAnnotationHandler(stringValueResolver)); + } + + /** + * 构造函数 + * + * @param resolver + * 注解解析器 + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ReactiveHttpCacheAnnotationMethodInterceptor(AnnotationResolver resolver, + StringValueResolver stringValueResolver) { + super(new ReactiveHttpCacheAnnotationHandler(stringValueResolver), resolver); + } + } diff --git a/buession-web/src/main/java/com/buession/web/reactive/aop/interceptor/ReactiveResponseHeaderAnnotationMethodInterceptor.java b/buession-web/src/main/java/com/buession/web/reactive/aop/interceptor/ReactiveResponseHeaderAnnotationMethodInterceptor.java index 92b89f702..dd9159f05 100644 --- a/buession-web/src/main/java/com/buession/web/reactive/aop/interceptor/ReactiveResponseHeaderAnnotationMethodInterceptor.java +++ b/buession-web/src/main/java/com/buession/web/reactive/aop/interceptor/ReactiveResponseHeaderAnnotationMethodInterceptor.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.reactive.aop.interceptor; @@ -28,6 +28,7 @@ import com.buession.web.aop.interceptor.AbstractResponseHeaderAnnotationMethodInterceptor; import com.buession.web.http.response.annotation.ResponseHeader; import com.buession.web.reactive.aop.handler.ReactiveResponseHeaderAnnotationHandler; +import org.springframework.util.StringValueResolver; /** * {@link ResponseHeader} 注解拦截器 @@ -38,12 +39,50 @@ public class ReactiveResponseHeaderAnnotationMethodInterceptor extends AbstractResponseHeaderAnnotationMethodInterceptor { - public ReactiveResponseHeaderAnnotationMethodInterceptor(){ + /** + * 构造函数 + */ + @Deprecated + public ReactiveResponseHeaderAnnotationMethodInterceptor() { super(new ReactiveResponseHeaderAnnotationHandler()); } - public ReactiveResponseHeaderAnnotationMethodInterceptor(AnnotationResolver resolver){ + /** + * 构造函数 + * + * @param resolver + * 注解解析器 + */ + @Deprecated + public ReactiveResponseHeaderAnnotationMethodInterceptor(AnnotationResolver resolver) { super(new ReactiveResponseHeaderAnnotationHandler(), resolver); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ReactiveResponseHeaderAnnotationMethodInterceptor(StringValueResolver stringValueResolver) { + super(new ReactiveResponseHeaderAnnotationHandler(stringValueResolver)); + } + + /** + * 构造函数 + * + * @param resolver + * 注解解析器 + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ReactiveResponseHeaderAnnotationMethodInterceptor(AnnotationResolver resolver, + StringValueResolver stringValueResolver) { + super(new ReactiveResponseHeaderAnnotationHandler(stringValueResolver), resolver); + } + } diff --git a/buession-web/src/main/java/com/buession/web/reactive/aop/interceptor/ReactiveResponseHeadersAnnotationMethodInterceptor.java b/buession-web/src/main/java/com/buession/web/reactive/aop/interceptor/ReactiveResponseHeadersAnnotationMethodInterceptor.java index 89c291500..e12737a34 100644 --- a/buession-web/src/main/java/com/buession/web/reactive/aop/interceptor/ReactiveResponseHeadersAnnotationMethodInterceptor.java +++ b/buession-web/src/main/java/com/buession/web/reactive/aop/interceptor/ReactiveResponseHeadersAnnotationMethodInterceptor.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.reactive.aop.interceptor; @@ -28,6 +28,7 @@ import com.buession.web.aop.interceptor.AbstractResponseHeadersAnnotationMethodInterceptor; import com.buession.web.http.response.annotation.ResponseHeaders; import com.buession.web.reactive.aop.handler.ReactiveResponseHeadersAnnotationHandler; +import org.springframework.util.StringValueResolver; /** * {@link ResponseHeaders} 注解拦截器 @@ -38,12 +39,50 @@ public class ReactiveResponseHeadersAnnotationMethodInterceptor extends AbstractResponseHeadersAnnotationMethodInterceptor { - public ReactiveResponseHeadersAnnotationMethodInterceptor(){ + /** + * 构造函数 + */ + @Deprecated + public ReactiveResponseHeadersAnnotationMethodInterceptor() { super(new ReactiveResponseHeadersAnnotationHandler()); } - public ReactiveResponseHeadersAnnotationMethodInterceptor(AnnotationResolver resolver){ + /** + * 构造函数 + * + * @param resolver + * 注解解析器 + */ + @Deprecated + public ReactiveResponseHeadersAnnotationMethodInterceptor(AnnotationResolver resolver) { super(new ReactiveResponseHeadersAnnotationHandler(), resolver); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ReactiveResponseHeadersAnnotationMethodInterceptor(StringValueResolver stringValueResolver) { + super(new ReactiveResponseHeadersAnnotationHandler()); + } + + /** + * 构造函数 + * + * @param resolver + * 注解解析器 + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ReactiveResponseHeadersAnnotationMethodInterceptor(AnnotationResolver resolver, + StringValueResolver stringValueResolver) { + super(new ReactiveResponseHeadersAnnotationHandler(stringValueResolver), resolver); + } + } diff --git a/buession-web/src/main/java/com/buession/web/reactive/config/WebFluxAnnotationProcessorConfiguration.java b/buession-web/src/main/java/com/buession/web/reactive/config/WebFluxAnnotationProcessorConfiguration.java index 5106152da..b34b4e609 100644 --- a/buession-web/src/main/java/com/buession/web/reactive/config/WebFluxAnnotationProcessorConfiguration.java +++ b/buession-web/src/main/java/com/buession/web/reactive/config/WebFluxAnnotationProcessorConfiguration.java @@ -19,13 +19,16 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.reactive.config; import com.buession.web.reactive.OnWebFluxCondition; import com.buession.web.reactive.aop.aopalliance.interceptor.ReactiveHttpAttributeSourcePointcutAdvisor; +import org.springframework.beans.factory.ObjectProvider; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.beans.factory.config.EmbeddedValueResolver; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; @@ -41,8 +44,10 @@ public class WebFluxAnnotationProcessorConfiguration { @Bean - public ReactiveHttpAttributeSourcePointcutAdvisor httpAttributeSourcePointcutAdvisor(){ - return new ReactiveHttpAttributeSourcePointcutAdvisor(); + public ReactiveHttpAttributeSourcePointcutAdvisor httpAttributeSourcePointcutAdvisor( + ObjectProvider configurableBeanFactory) { + return new ReactiveHttpAttributeSourcePointcutAdvisor( + new EmbeddedValueResolver(configurableBeanFactory.getIfAvailable())); } } diff --git a/buession-web/src/main/java/com/buession/web/reactive/http/response/ResponseUtils.java b/buession-web/src/main/java/com/buession/web/reactive/http/response/ResponseUtils.java index 086eb5b0e..efebd1229 100644 --- a/buession-web/src/main/java/com/buession/web/reactive/http/response/ResponseUtils.java +++ b/buession-web/src/main/java/com/buession/web/reactive/http/response/ResponseUtils.java @@ -19,11 +19,12 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.reactive.http.response; +import com.buession.core.utils.ObjectUtils; import org.springframework.http.HttpHeaders; import org.springframework.http.server.reactive.ServerHttpResponse; @@ -34,31 +35,29 @@ */ public class ResponseUtils { - private ResponseUtils(){ + private ResponseUtils() { } - public static void httpCache(final ServerHttpResponse response, final String value){ - if(response != null){ - response.getHeaders().setCacheControl(value); - } + public static void httpCache(final ServerHttpResponse response, final String value) { + ObjectUtils.invokeIfAvailable(response, res->res.getHeaders().setCacheControl(value)); } - public static void httpCache(final ServerHttpResponse response, final int lifetime){ - if(response != null){ + public static void httpCache(final ServerHttpResponse response, final int lifetime) { + ObjectUtils.invokeIfAvailable(response, res->{ long expiresAt = System.currentTimeMillis() + lifetime * 1000L; - httpCache(response, lifetime, expiresAt); - } + httpCache(res, lifetime, expiresAt); + }); } - public static void httpCache(final ServerHttpResponse response, final Date date){ - if(response != null){ + public static void httpCache(final ServerHttpResponse response, final Date date) { + ObjectUtils.invokeIfAvailable(response, res->{ long maxAge = date.getTime() - System.currentTimeMillis(); - httpCache(response, maxAge, date.getTime()); - } + httpCache(res, maxAge, date.getTime()); + }); } - private static void httpCache(final ServerHttpResponse response, final long maxAge, final long expires){ + private static void httpCache(final ServerHttpResponse response, final long maxAge, final long expires) { HttpHeaders httpHeaders = response.getHeaders(); httpHeaders.setCacheControl(maxAge < 0 ? "no-cache" : "max-age=" + maxAge); httpHeaders.setExpires(expires); diff --git a/buession-web/src/main/java/com/buession/web/servlet/aop/aopalliance/interceptor/ServletAopAllianceAnnotationsMethodInterceptor.java b/buession-web/src/main/java/com/buession/web/servlet/aop/aopalliance/interceptor/ServletAopAllianceAnnotationsMethodInterceptor.java index 07d078dba..3a88de21b 100644 --- a/buession-web/src/main/java/com/buession/web/servlet/aop/aopalliance/interceptor/ServletAopAllianceAnnotationsMethodInterceptor.java +++ b/buession-web/src/main/java/com/buession/web/servlet/aop/aopalliance/interceptor/ServletAopAllianceAnnotationsMethodInterceptor.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.servlet.aop.aopalliance.interceptor; @@ -28,6 +28,7 @@ import com.buession.aop.resolver.SpringAnnotationResolver; import com.buession.aop.aopalliance.AbstractAopAllianceAnnotationsMethodInterceptor; import com.buession.web.servlet.aop.interceptor.*; +import org.springframework.util.StringValueResolver; import java.util.ArrayDeque; import java.util.Collection; @@ -38,7 +39,11 @@ */ public class ServletAopAllianceAnnotationsMethodInterceptor extends AbstractAopAllianceAnnotationsMethodInterceptor { - public ServletAopAllianceAnnotationsMethodInterceptor(){ + /** + * 构造函数 + */ + @Deprecated + public ServletAopAllianceAnnotationsMethodInterceptor() { super(); final Collection methodInterceptors = new ArrayDeque<>(5); @@ -53,4 +58,32 @@ public ServletAopAllianceAnnotationsMethodInterceptor(){ setMethodInterceptors(methodInterceptors); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ServletAopAllianceAnnotationsMethodInterceptor(StringValueResolver stringValueResolver) { + super(); + + final Collection methodInterceptors = new ArrayDeque<>(5); + final SpringAnnotationResolver springAnnotationResolver = new SpringAnnotationResolver(); + + methodInterceptors.add( + new ServletContentTypeAnnotationMethodInterceptor(springAnnotationResolver, stringValueResolver)); + methodInterceptors.add( + new ServletDocumentMetaDataAnnotationMethodInterceptor(springAnnotationResolver, stringValueResolver)); + methodInterceptors.add( + new ServletHttpCacheAnnotationMethodInterceptor(springAnnotationResolver, stringValueResolver)); + methodInterceptors.add( + new ServletResponseHeaderAnnotationMethodInterceptor(springAnnotationResolver, stringValueResolver)); + methodInterceptors.add( + new ServletResponseHeadersAnnotationMethodInterceptor(springAnnotationResolver, stringValueResolver)); + + setMethodInterceptors(methodInterceptors); + } + } diff --git a/buession-web/src/main/java/com/buession/web/servlet/aop/aopalliance/interceptor/ServletHttpAttributeSourcePointcutAdvisor.java b/buession-web/src/main/java/com/buession/web/servlet/aop/aopalliance/interceptor/ServletHttpAttributeSourcePointcutAdvisor.java index f1da23172..9a20be09f 100644 --- a/buession-web/src/main/java/com/buession/web/servlet/aop/aopalliance/interceptor/ServletHttpAttributeSourcePointcutAdvisor.java +++ b/buession-web/src/main/java/com/buession/web/servlet/aop/aopalliance/interceptor/ServletHttpAttributeSourcePointcutAdvisor.java @@ -25,6 +25,7 @@ package com.buession.web.servlet.aop.aopalliance.interceptor; import com.buession.web.aop.aopalliance.AbstractWebAttributeSourcePointcutAdvisor; +import org.springframework.util.StringValueResolver; /** * @author Yong.Teng @@ -34,8 +35,20 @@ public class ServletHttpAttributeSourcePointcutAdvisor extends AbstractWebAttrib private final static long serialVersionUID = 8267117305963633132L; - public ServletHttpAttributeSourcePointcutAdvisor(){ + public ServletHttpAttributeSourcePointcutAdvisor() { super(new ServletAopAllianceAnnotationsMethodInterceptor()); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ServletHttpAttributeSourcePointcutAdvisor(StringValueResolver stringValueResolver) { + super(new ServletAopAllianceAnnotationsMethodInterceptor(stringValueResolver)); + } + } diff --git a/buession-web/src/main/java/com/buession/web/servlet/aop/aspect/interceptor/ServletWebAspectAnnotationsMethodInterceptor.java b/buession-web/src/main/java/com/buession/web/servlet/aop/aspect/interceptor/ServletWebAspectAnnotationsMethodInterceptor.java index 53cffb484..994ed206d 100644 --- a/buession-web/src/main/java/com/buession/web/servlet/aop/aspect/interceptor/ServletWebAspectAnnotationsMethodInterceptor.java +++ b/buession-web/src/main/java/com/buession/web/servlet/aop/aspect/interceptor/ServletWebAspectAnnotationsMethodInterceptor.java @@ -31,6 +31,7 @@ import com.buession.web.servlet.aop.interceptor.ServletHttpCacheAnnotationMethodInterceptor; import com.buession.web.servlet.aop.interceptor.ServletResponseHeaderAnnotationMethodInterceptor; import com.buession.web.servlet.aop.interceptor.ServletResponseHeadersAnnotationMethodInterceptor; +import org.springframework.util.StringValueResolver; import java.util.ArrayDeque; import java.util.Collection; @@ -41,7 +42,11 @@ */ public class ServletWebAspectAnnotationsMethodInterceptor extends AbstractAspectjAnnotationsMethodInterceptor { - public ServletWebAspectAnnotationsMethodInterceptor(){ + /** + * 构造函数 + */ + @Deprecated + public ServletWebAspectAnnotationsMethodInterceptor() { super(); final Collection methodInterceptors = new ArrayDeque<>(5); @@ -55,4 +60,26 @@ public ServletWebAspectAnnotationsMethodInterceptor(){ setMethodInterceptors(methodInterceptors); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ServletWebAspectAnnotationsMethodInterceptor(StringValueResolver stringValueResolver) { + super(); + + final Collection methodInterceptors = new ArrayDeque<>(5); + + methodInterceptors.add(new ServletContentTypeAnnotationMethodInterceptor(stringValueResolver)); + methodInterceptors.add(new ServletDocumentMetaDataAnnotationMethodInterceptor(stringValueResolver)); + methodInterceptors.add(new ServletHttpCacheAnnotationMethodInterceptor(stringValueResolver)); + methodInterceptors.add(new ServletResponseHeaderAnnotationMethodInterceptor(stringValueResolver)); + methodInterceptors.add(new ServletResponseHeadersAnnotationMethodInterceptor(stringValueResolver)); + + setMethodInterceptors(methodInterceptors); + } + } diff --git a/buession-web/src/main/java/com/buession/web/servlet/aop/handler/ServletContentTypeAnnotationHandler.java b/buession-web/src/main/java/com/buession/web/servlet/aop/handler/ServletContentTypeAnnotationHandler.java index 29dbd5e42..9a61b9b35 100644 --- a/buession-web/src/main/java/com/buession/web/servlet/aop/handler/ServletContentTypeAnnotationHandler.java +++ b/buession-web/src/main/java/com/buession/web/servlet/aop/handler/ServletContentTypeAnnotationHandler.java @@ -32,20 +32,39 @@ import com.buession.web.servlet.http.request.RequestUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.util.StringValueResolver; import javax.servlet.http.HttpServletResponse; /** + * Servlet 模式注解 {@link ContentType} 处理器 + * * @author Yong.Teng */ public class ServletContentTypeAnnotationHandler extends AbstractContentTypeAnnotationHandler { private final static Logger logger = LoggerFactory.getLogger(ServletContentTypeAnnotationHandler.class); + /** + * 构造函数 + */ + @Deprecated public ServletContentTypeAnnotationHandler() { super(); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ServletContentTypeAnnotationHandler(StringValueResolver stringValueResolver) { + super(stringValueResolver); + } + @Override public void execute(MethodInvocation mi, ContentType contentType) { HttpServletResponse response = RequestUtils.getResponse(); @@ -56,10 +75,19 @@ public void execute(MethodInvocation mi, ContentType contentType) { StringBuilder sb = new StringBuilder(contentType.mime().length() + 24); - sb.append(contentType.mime()); + if(stringValueResolver == null){ + sb.append(contentType.mime()); + }else{ + sb.append(stringValueResolver.resolveStringValue(contentType.mime())); + } if(Validate.isNotEmpty(contentType.encoding())){ - sb.append("; charset=").append(contentType.encoding()); + sb.append("; charset="); + if(stringValueResolver == null){ + sb.append(contentType.encoding()); + }else{ + sb.append(stringValueResolver.resolveStringValue(contentType.encoding())); + } } response.addHeader(HttpHeader.CONTENT_TYPE.getValue(), sb.toString()); diff --git a/buession-web/src/main/java/com/buession/web/servlet/aop/handler/ServletDocumentMetaDataAnnotationHandler.java b/buession-web/src/main/java/com/buession/web/servlet/aop/handler/ServletDocumentMetaDataAnnotationHandler.java index e338d8a40..3bf1af436 100644 --- a/buession-web/src/main/java/com/buession/web/servlet/aop/handler/ServletDocumentMetaDataAnnotationHandler.java +++ b/buession-web/src/main/java/com/buession/web/servlet/aop/handler/ServletDocumentMetaDataAnnotationHandler.java @@ -25,14 +25,34 @@ package com.buession.web.servlet.aop.handler; import com.buession.web.aop.handler.AbstractDocumentMetaDataAnnotationHandler; +import com.buession.web.mvc.view.document.DocumentMetaData; +import org.springframework.util.StringValueResolver; /** + * Servlet 模式注解 {@link DocumentMetaData} 处理器 + * * @author Yong.Teng */ public class ServletDocumentMetaDataAnnotationHandler extends AbstractDocumentMetaDataAnnotationHandler { - public ServletDocumentMetaDataAnnotationHandler(){ + /** + * 构造函数 + */ + @Deprecated + public ServletDocumentMetaDataAnnotationHandler() { super(); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ServletDocumentMetaDataAnnotationHandler(StringValueResolver stringValueResolver) { + super(stringValueResolver); + } + } diff --git a/buession-web/src/main/java/com/buession/web/servlet/aop/handler/ServletHttpCacheAnnotationHandler.java b/buession-web/src/main/java/com/buession/web/servlet/aop/handler/ServletHttpCacheAnnotationHandler.java index a3b19927c..e898f1c9d 100644 --- a/buession-web/src/main/java/com/buession/web/servlet/aop/handler/ServletHttpCacheAnnotationHandler.java +++ b/buession-web/src/main/java/com/buession/web/servlet/aop/handler/ServletHttpCacheAnnotationHandler.java @@ -32,20 +32,39 @@ import com.buession.web.servlet.http.request.RequestUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.util.StringValueResolver; import javax.servlet.http.HttpServletResponse; /** + * Servlet 模式注解 {@link HttpCache} 处理器 + * * @author Yong.Teng */ public class ServletHttpCacheAnnotationHandler extends AbstractHttpCacheAnnotationHandler { private final static Logger logger = LoggerFactory.getLogger(ServletHttpCacheAnnotationHandler.class); + /** + * 构造函数 + */ + @Deprecated public ServletHttpCacheAnnotationHandler() { super(); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ServletHttpCacheAnnotationHandler(StringValueResolver stringValueResolver) { + super(stringValueResolver); + } + @Override public void execute(MethodInvocation mi, HttpCache httpCache) { HttpServletResponse response = RequestUtils.getResponse(); @@ -57,20 +76,35 @@ public void execute(MethodInvocation mi, HttpCache httpCache) { boolean isSetCacheControl = false; if(Validate.hasText(httpCache.cacheControl())){ - response.setHeader(HttpHeader.CACHE_CONTROL.getValue(), httpCache.cacheControl()); + if(stringValueResolver == null){ + response.setHeader(HttpHeader.CACHE_CONTROL.getValue(), httpCache.cacheControl()); + }else{ + response.setHeader(HttpHeader.CACHE_CONTROL.getValue(), + stringValueResolver.resolveStringValue(httpCache.cacheControl())); + } isSetCacheControl = true; } - if(Validate.hasText(httpCache.expires()) && Validate.isNumeric(httpCache.expires())){ - response.setHeader(HttpHeader.EXPIRES.getValue(), httpCache.expires()); + if(Validate.hasText(httpCache.expires())){ + String expires = stringValueResolver == null ? httpCache.expires() : + stringValueResolver.resolveStringValue(httpCache.expires()); + + if(Validate.isNumeric(expires)){ + response.setHeader(HttpHeader.EXPIRES.getValue(), expires); - if(isSetCacheControl == false){ - response.setHeader(HttpHeader.CACHE_CONTROL.getValue(), "max-age=" + httpCache.expires()); + if(isSetCacheControl == false){ + response.setHeader(HttpHeader.CACHE_CONTROL.getValue(), "max-age=" + expires); + } } } if(Validate.hasText(httpCache.pragma())){ - response.setHeader(HttpHeader.PRAGMA.getValue(), httpCache.pragma()); + if(stringValueResolver == null){ + response.setHeader(HttpHeader.PRAGMA.getValue(), httpCache.pragma()); + }else{ + response.setHeader(HttpHeader.PRAGMA.getValue(), + stringValueResolver.resolveStringValue(httpCache.pragma())); + } } } diff --git a/buession-web/src/main/java/com/buession/web/servlet/aop/handler/ServletResponseHeaderAnnotationHandler.java b/buession-web/src/main/java/com/buession/web/servlet/aop/handler/ServletResponseHeaderAnnotationHandler.java index 9e3ebd995..f17bbb89f 100644 --- a/buession-web/src/main/java/com/buession/web/servlet/aop/handler/ServletResponseHeaderAnnotationHandler.java +++ b/buession-web/src/main/java/com/buession/web/servlet/aop/handler/ServletResponseHeaderAnnotationHandler.java @@ -33,20 +33,39 @@ import com.buession.web.servlet.http.response.ResponseUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.util.StringValueResolver; import javax.servlet.http.HttpServletResponse; /** + * Servlet 模式注解 {@link ResponseHeader} 处理器 + * * @author Yong.Teng */ public class ServletResponseHeaderAnnotationHandler extends AbstractResponseHeaderAnnotationHandler { private final static Logger logger = LoggerFactory.getLogger(ServletResponseHeaderAnnotationHandler.class); + /** + * 构造函数 + */ + @Deprecated public ServletResponseHeaderAnnotationHandler() { super(); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ServletResponseHeaderAnnotationHandler(StringValueResolver stringValueResolver) { + super(stringValueResolver); + } + @Override public void execute(MethodInvocation mi, ResponseHeader responseHeader) { HttpServletResponse response = RequestUtils.getResponse(); @@ -59,6 +78,10 @@ public void execute(MethodInvocation mi, ResponseHeader responseHeader) { for(String value : responseHeader.value()){ if(isExpires){ + if(stringValueResolver != null){ + value = stringValueResolver.resolveStringValue(value); + } + if(Validate.isNumeric(value)){ ResponseUtils.httpCache(response, Integer.parseInt(value)); }else{ diff --git a/buession-web/src/main/java/com/buession/web/servlet/aop/handler/ServletResponseHeadersAnnotationHandler.java b/buession-web/src/main/java/com/buession/web/servlet/aop/handler/ServletResponseHeadersAnnotationHandler.java index e7199b8a2..b80239d9c 100644 --- a/buession-web/src/main/java/com/buession/web/servlet/aop/handler/ServletResponseHeadersAnnotationHandler.java +++ b/buession-web/src/main/java/com/buession/web/servlet/aop/handler/ServletResponseHeadersAnnotationHandler.java @@ -34,20 +34,39 @@ import com.buession.web.servlet.http.response.ResponseUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.util.StringValueResolver; import javax.servlet.http.HttpServletResponse; /** + * Servlet 模式注解 {@link ResponseHeaders} 处理器 + * * @author Yong.Teng */ public class ServletResponseHeadersAnnotationHandler extends AbstractResponseHeadersAnnotationHandler { private final static Logger logger = LoggerFactory.getLogger(ServletResponseHeadersAnnotationHandler.class); + /** + * 构造函数 + */ + @Deprecated public ServletResponseHeadersAnnotationHandler() { super(); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ServletResponseHeadersAnnotationHandler(StringValueResolver stringValueResolver) { + super(stringValueResolver); + } + @Override public void execute(MethodInvocation mi, ResponseHeaders responseHeaders) { ResponseHeader[] headers = responseHeaders.value(); @@ -65,6 +84,10 @@ public void execute(MethodInvocation mi, ResponseHeaders responseHeaders) { final boolean isExpires = HttpHeader.EXPIRES.getValue().equalsIgnoreCase(header.name()); for(String value : header.value()){ + if(stringValueResolver != null){ + value = stringValueResolver.resolveStringValue(value); + } + if(isExpires){ if(Validate.isNumeric(value)){ ResponseUtils.httpCache(response, Integer.parseInt(value)); diff --git a/buession-web/src/main/java/com/buession/web/servlet/aop/interceptor/ServletContentTypeAnnotationMethodInterceptor.java b/buession-web/src/main/java/com/buession/web/servlet/aop/interceptor/ServletContentTypeAnnotationMethodInterceptor.java index 68b25c52f..31584e577 100644 --- a/buession-web/src/main/java/com/buession/web/servlet/aop/interceptor/ServletContentTypeAnnotationMethodInterceptor.java +++ b/buession-web/src/main/java/com/buession/web/servlet/aop/interceptor/ServletContentTypeAnnotationMethodInterceptor.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.servlet.aop.interceptor; @@ -28,6 +28,7 @@ import com.buession.web.aop.interceptor.AbstractContentTypeAnnotationMethodInterceptor; import com.buession.web.http.response.annotation.ContentType; import com.buession.web.servlet.aop.handler.ServletContentTypeAnnotationHandler; +import org.springframework.util.StringValueResolver; /** * {@link ContentType} 注解拦截器 @@ -37,12 +38,50 @@ */ public class ServletContentTypeAnnotationMethodInterceptor extends AbstractContentTypeAnnotationMethodInterceptor { - public ServletContentTypeAnnotationMethodInterceptor(){ + /** + * 构造函数 + */ + @Deprecated + public ServletContentTypeAnnotationMethodInterceptor() { super(new ServletContentTypeAnnotationHandler()); } - public ServletContentTypeAnnotationMethodInterceptor(AnnotationResolver resolver){ + /** + * 构造函数 + * + * @param resolver + * 注解解析器 + */ + @Deprecated + public ServletContentTypeAnnotationMethodInterceptor(AnnotationResolver resolver) { super(new ServletContentTypeAnnotationHandler(), resolver); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ServletContentTypeAnnotationMethodInterceptor(StringValueResolver stringValueResolver) { + super(new ServletContentTypeAnnotationHandler(stringValueResolver)); + } + + /** + * 构造函数 + * + * @param resolver + * 注解解析器 + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ServletContentTypeAnnotationMethodInterceptor(AnnotationResolver resolver, + StringValueResolver stringValueResolver) { + super(new ServletContentTypeAnnotationHandler(stringValueResolver), resolver); + } + } diff --git a/buession-web/src/main/java/com/buession/web/servlet/aop/interceptor/ServletDocumentMetaDataAnnotationMethodInterceptor.java b/buession-web/src/main/java/com/buession/web/servlet/aop/interceptor/ServletDocumentMetaDataAnnotationMethodInterceptor.java index fb34b4591..d8636b1f4 100644 --- a/buession-web/src/main/java/com/buession/web/servlet/aop/interceptor/ServletDocumentMetaDataAnnotationMethodInterceptor.java +++ b/buession-web/src/main/java/com/buession/web/servlet/aop/interceptor/ServletDocumentMetaDataAnnotationMethodInterceptor.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.servlet.aop.interceptor; @@ -28,6 +28,7 @@ import com.buession.web.aop.interceptor.AbstractDocumentMetaDataAnnotationMethodInterceptor; import com.buession.web.mvc.view.document.DocumentMetaData; import com.buession.web.servlet.aop.handler.ServletDocumentMetaDataAnnotationHandler; +import org.springframework.util.StringValueResolver; /** * {@link DocumentMetaData} 注解拦截器 @@ -38,12 +39,50 @@ public class ServletDocumentMetaDataAnnotationMethodInterceptor extends AbstractDocumentMetaDataAnnotationMethodInterceptor { - public ServletDocumentMetaDataAnnotationMethodInterceptor(){ + /** + * 构造函数 + */ + @Deprecated + public ServletDocumentMetaDataAnnotationMethodInterceptor() { super(new ServletDocumentMetaDataAnnotationHandler()); } - public ServletDocumentMetaDataAnnotationMethodInterceptor(AnnotationResolver resolver){ + /** + * 构造函数 + * + * @param resolver + * 注解解析器 + */ + @Deprecated + public ServletDocumentMetaDataAnnotationMethodInterceptor(AnnotationResolver resolver) { super(new ServletDocumentMetaDataAnnotationHandler(), resolver); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ServletDocumentMetaDataAnnotationMethodInterceptor(StringValueResolver stringValueResolver) { + super(new ServletDocumentMetaDataAnnotationHandler(stringValueResolver)); + } + + /** + * 构造函数 + * + * @param resolver + * 注解解析器 + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ServletDocumentMetaDataAnnotationMethodInterceptor(AnnotationResolver resolver, + StringValueResolver stringValueResolver) { + super(new ServletDocumentMetaDataAnnotationHandler(stringValueResolver), resolver); + } + } diff --git a/buession-web/src/main/java/com/buession/web/servlet/aop/interceptor/ServletHttpCacheAnnotationMethodInterceptor.java b/buession-web/src/main/java/com/buession/web/servlet/aop/interceptor/ServletHttpCacheAnnotationMethodInterceptor.java index 927965da2..1d7589ffc 100644 --- a/buession-web/src/main/java/com/buession/web/servlet/aop/interceptor/ServletHttpCacheAnnotationMethodInterceptor.java +++ b/buession-web/src/main/java/com/buession/web/servlet/aop/interceptor/ServletHttpCacheAnnotationMethodInterceptor.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.servlet.aop.interceptor; @@ -28,6 +28,7 @@ import com.buession.web.aop.interceptor.AbstractHttpCacheAnnotationMethodInterceptor; import com.buession.web.http.response.annotation.HttpCache; import com.buession.web.servlet.aop.handler.ServletHttpCacheAnnotationHandler; +import org.springframework.util.StringValueResolver; /** * {@link HttpCache} 注解拦截器 @@ -37,12 +38,50 @@ */ public class ServletHttpCacheAnnotationMethodInterceptor extends AbstractHttpCacheAnnotationMethodInterceptor { - public ServletHttpCacheAnnotationMethodInterceptor(){ + /** + * 构造函数 + */ + @Deprecated + public ServletHttpCacheAnnotationMethodInterceptor() { super(new ServletHttpCacheAnnotationHandler()); } - public ServletHttpCacheAnnotationMethodInterceptor(AnnotationResolver resolver){ + /** + * 构造函数 + * + * @param resolver + * 注解解析器 + */ + @Deprecated + public ServletHttpCacheAnnotationMethodInterceptor(AnnotationResolver resolver) { super(new ServletHttpCacheAnnotationHandler(), resolver); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ServletHttpCacheAnnotationMethodInterceptor(StringValueResolver stringValueResolver) { + super(new ServletHttpCacheAnnotationHandler(stringValueResolver)); + } + + /** + * 构造函数 + * + * @param resolver + * 注解解析器 + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ServletHttpCacheAnnotationMethodInterceptor(AnnotationResolver resolver, + StringValueResolver stringValueResolver) { + super(new ServletHttpCacheAnnotationHandler(stringValueResolver), resolver); + } + } diff --git a/buession-web/src/main/java/com/buession/web/servlet/aop/interceptor/ServletResponseHeaderAnnotationMethodInterceptor.java b/buession-web/src/main/java/com/buession/web/servlet/aop/interceptor/ServletResponseHeaderAnnotationMethodInterceptor.java index ca70fc152..f8717dfd9 100644 --- a/buession-web/src/main/java/com/buession/web/servlet/aop/interceptor/ServletResponseHeaderAnnotationMethodInterceptor.java +++ b/buession-web/src/main/java/com/buession/web/servlet/aop/interceptor/ServletResponseHeaderAnnotationMethodInterceptor.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.servlet.aop.interceptor; @@ -28,6 +28,7 @@ import com.buession.web.aop.interceptor.AbstractResponseHeaderAnnotationMethodInterceptor; import com.buession.web.http.response.annotation.ResponseHeader; import com.buession.web.servlet.aop.handler.ServletResponseHeaderAnnotationHandler; +import org.springframework.util.StringValueResolver; /** * {@link ResponseHeader} 注解拦截器 @@ -38,12 +39,50 @@ public class ServletResponseHeaderAnnotationMethodInterceptor extends AbstractResponseHeaderAnnotationMethodInterceptor { - public ServletResponseHeaderAnnotationMethodInterceptor(){ + /** + * 构造函数 + */ + @Deprecated + public ServletResponseHeaderAnnotationMethodInterceptor() { super(new ServletResponseHeaderAnnotationHandler()); } - public ServletResponseHeaderAnnotationMethodInterceptor(AnnotationResolver resolver){ + /** + * 构造函数 + * + * @param resolver + * 注解解析器 + */ + @Deprecated + public ServletResponseHeaderAnnotationMethodInterceptor(AnnotationResolver resolver) { super(new ServletResponseHeaderAnnotationHandler(), resolver); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ServletResponseHeaderAnnotationMethodInterceptor(StringValueResolver stringValueResolver) { + super(new ServletResponseHeaderAnnotationHandler(stringValueResolver)); + } + + /** + * 构造函数 + * + * @param resolver + * 注解解析器 + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ServletResponseHeaderAnnotationMethodInterceptor(AnnotationResolver resolver, + StringValueResolver stringValueResolver) { + super(new ServletResponseHeaderAnnotationHandler(stringValueResolver), resolver); + } + } diff --git a/buession-web/src/main/java/com/buession/web/servlet/aop/interceptor/ServletResponseHeadersAnnotationMethodInterceptor.java b/buession-web/src/main/java/com/buession/web/servlet/aop/interceptor/ServletResponseHeadersAnnotationMethodInterceptor.java index 86e51b5fd..02b91d6bd 100644 --- a/buession-web/src/main/java/com/buession/web/servlet/aop/interceptor/ServletResponseHeadersAnnotationMethodInterceptor.java +++ b/buession-web/src/main/java/com/buession/web/servlet/aop/interceptor/ServletResponseHeadersAnnotationMethodInterceptor.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.servlet.aop.interceptor; @@ -28,6 +28,7 @@ import com.buession.web.aop.interceptor.AbstractResponseHeadersAnnotationMethodInterceptor; import com.buession.web.http.response.annotation.ResponseHeaders; import com.buession.web.servlet.aop.handler.ServletResponseHeadersAnnotationHandler; +import org.springframework.util.StringValueResolver; /** * {@link ResponseHeaders} 注解拦截器 @@ -38,12 +39,50 @@ public class ServletResponseHeadersAnnotationMethodInterceptor extends AbstractResponseHeadersAnnotationMethodInterceptor { - public ServletResponseHeadersAnnotationMethodInterceptor(){ + /** + * 构造函数 + */ + @Deprecated + public ServletResponseHeadersAnnotationMethodInterceptor() { super(new ServletResponseHeadersAnnotationHandler()); } - public ServletResponseHeadersAnnotationMethodInterceptor(AnnotationResolver resolver){ + /** + * 构造函数 + * + * @param resolver + * 注解解析器 + */ + @Deprecated + public ServletResponseHeadersAnnotationMethodInterceptor(AnnotationResolver resolver) { super(new ServletResponseHeadersAnnotationHandler(), resolver); } + /** + * 构造函数 + * + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ServletResponseHeadersAnnotationMethodInterceptor(StringValueResolver stringValueResolver) { + super(new ServletResponseHeadersAnnotationHandler(stringValueResolver)); + } + + /** + * 构造函数 + * + * @param resolver + * 注解解析器 + * @param stringValueResolver + * 占位符解析器 + * + * @since 2.3.2 + */ + public ServletResponseHeadersAnnotationMethodInterceptor(AnnotationResolver resolver, + StringValueResolver stringValueResolver) { + super(new ServletResponseHeadersAnnotationHandler(stringValueResolver), resolver); + } + } diff --git a/buession-web/src/main/java/com/buession/web/servlet/config/ServletAnnotationProcessorConfiguration.java b/buession-web/src/main/java/com/buession/web/servlet/config/ServletAnnotationProcessorConfiguration.java index ed261b5ef..6e3f0ddaf 100644 --- a/buession-web/src/main/java/com/buession/web/servlet/config/ServletAnnotationProcessorConfiguration.java +++ b/buession-web/src/main/java/com/buession/web/servlet/config/ServletAnnotationProcessorConfiguration.java @@ -19,13 +19,16 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.servlet.config; import com.buession.web.servlet.OnServletCondition; import com.buession.web.servlet.aop.aopalliance.interceptor.ServletHttpAttributeSourcePointcutAdvisor; +import org.springframework.beans.factory.ObjectProvider; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.beans.factory.config.EmbeddedValueResolver; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; @@ -41,8 +44,10 @@ public class ServletAnnotationProcessorConfiguration { @Bean - public ServletHttpAttributeSourcePointcutAdvisor httpAttributeSourcePointcutAdvisor(){ - return new ServletHttpAttributeSourcePointcutAdvisor(); + public ServletHttpAttributeSourcePointcutAdvisor httpAttributeSourcePointcutAdvisor( + ObjectProvider configurableBeanFactory) { + return new ServletHttpAttributeSourcePointcutAdvisor( + new EmbeddedValueResolver(configurableBeanFactory.getIfAvailable())); } } diff --git a/buession-web/src/main/java/com/buession/web/servlet/filter/PrintUrlFilter.java b/buession-web/src/main/java/com/buession/web/servlet/filter/PrintUrlFilter.java index 26d80aea8..86bcde61f 100644 --- a/buession-web/src/main/java/com/buession/web/servlet/filter/PrintUrlFilter.java +++ b/buession-web/src/main/java/com/buession/web/servlet/filter/PrintUrlFilter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.servlet.filter; @@ -46,7 +46,7 @@ public class PrintUrlFilter extends OncePerRequestFilter { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) - throws ServletException, IOException{ + throws ServletException, IOException { if(logger.isInfoEnabled()){ String url = parseFullUrl(request); @@ -58,18 +58,18 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse filterChain.doFilter(request, response); } - protected String parseUrl(final HttpServletRequest request){ + protected String parseUrl(final HttpServletRequest request) { return request.getRequestURL().toString(); } - protected String parseFullUrl(final HttpServletRequest request){ + protected String parseFullUrl(final HttpServletRequest request) { String url = parseUrl(request); if(Validate.hasText(url)){ String queryString = request.getQueryString(); if(Validate.hasText(queryString)){ - url += "?" + queryString; + url += '?' + queryString; } } diff --git a/buession-web/src/main/java/com/buession/web/servlet/http/response/ResponseUtils.java b/buession-web/src/main/java/com/buession/web/servlet/http/response/ResponseUtils.java index fd0544f18..db33de0a1 100644 --- a/buession-web/src/main/java/com/buession/web/servlet/http/response/ResponseUtils.java +++ b/buession-web/src/main/java/com/buession/web/servlet/http/response/ResponseUtils.java @@ -21,11 +21,12 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.web.servlet.http.response; +import com.buession.core.utils.ObjectUtils; import com.buession.web.http.HttpHeader; import javax.servlet.http.HttpServletResponse; @@ -36,31 +37,29 @@ */ public class ResponseUtils { - private ResponseUtils(){ + private ResponseUtils() { } - public static void httpCache(final HttpServletResponse response, final String value){ - if(response != null){ - response.setHeader(HttpHeader.CACHE_CONTROL.getValue(), value); - } + public static void httpCache(final HttpServletResponse response, final String value) { + ObjectUtils.invokeIfAvailable(response, res->res.setHeader(HttpHeader.CACHE_CONTROL.getValue(), value)); } - public static void httpCache(final HttpServletResponse response, final int lifetime){ - if(response != null){ + public static void httpCache(final HttpServletResponse response, final int lifetime) { + ObjectUtils.invokeIfAvailable(response, res->{ Date date = new Date(System.currentTimeMillis() + lifetime * 1000L); - httpCache(response, lifetime, date); - } + httpCache(res, lifetime, date); + }); } - public static void httpCache(final HttpServletResponse response, final Date date){ - if(response != null){ + public static void httpCache(final HttpServletResponse response, final Date date) { + ObjectUtils.invokeIfAvailable(response, res->{ long maxAge = date.getTime() - System.currentTimeMillis(); - httpCache(response, maxAge, date); - } + httpCache(res, maxAge, date); + }); } - private static void httpCache(final HttpServletResponse response, final long maxAge, final Date expires){ + private static void httpCache(final HttpServletResponse response, final long maxAge, final Date expires) { response.setHeader(HttpHeader.CACHE_CONTROL.getValue(), maxAge < 0 ? "no-cache" : "max-age=" + maxAge); response.setDateHeader(HttpHeader.EXPIRES.getValue(), expires.getTime()); response.setHeader(HttpHeader.PRAGMA.getValue(), maxAge > 0 ? null : "no-cache");

Note that this method tries to set the constructor accessible if given a + * non-accessible (that is, non-public) constructor, and supports Kotlin classes + * with optional parameters and default values. + * + * @param ctor + * the constructor to instantiate + * @param args + * the constructor arguments to apply (use {@code null} for an unspecified parameter, + * Kotlin optional parameters and Java primitive types are supported) + * @param + * 实例类型 + * + * @return The new instance + * + * @throws ClassInstantiationException + * if the bean cannot be instantiated + * @see Constructor#newInstance + * @since 2.3.2 + */ + public static T instantiate(Constructor ctor, Object... args) throws ClassInstantiationException { + Assert.isNull(ctor, "Constructor cloud not be null"); + + try{ + ReflectionUtils.makeAccessible(ctor); + + if(KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(ctor.getDeclaringClass())){ + return KotlinDelegate.instantiateClass(ctor, args); + }else{ + Class[] parameterTypes = ctor.getParameterTypes(); + Assert.isFalse(args.length <= parameterTypes.length, + "Can't specify more arguments than constructor parameters"); + Object[] argsWithDefaultValues = new Object[args.length]; + + for(int i = 0; i < args.length; i++){ + if(args[i] == null){ + Class parameterType = parameterTypes[i]; + argsWithDefaultValues[i] = parameterType.isPrimitive() ? Primitive.DEFAULT_TYPE_VALUES.get( + parameterType) : null; + }else{ + argsWithDefaultValues[i] = args[i]; + } + } + + return ctor.newInstance(argsWithDefaultValues); + } }catch(InstantiationException e){ - throw new ClassInstantiationException(clazz, "Is it an abstract class?", e); + throw new ClassInstantiationException(ctor, "Is it an abstract class?", e); }catch(IllegalAccessException e){ - throw new ClassInstantiationException(clazz, "Is the constructor accessible?", e); + throw new ClassInstantiationException(ctor, "Is the constructor accessible?", e); + }catch(IllegalArgumentException e){ + throw new ClassInstantiationException(ctor, "Illegal arguments for constructor", e); + }catch(InvocationTargetException e){ + throw new ClassInstantiationException(ctor, "Constructor threw exception", e.getTargetException()); + } + } + + /** + * Return the primary constructor of the provided class. For Kotlin classes, this + * returns the Java constructor corresponding to the Kotlin primary constructor + * (as defined in the Kotlin specification). Otherwise, in particular for non-Kotlin + * classes, this simply returns {@code null}. + * + * @param clazz + * the class to check + * @param + * 实例类型 + * + * @return The primary constructor of the provided class + * + * @see Kotlin docs + * @since 2.3.2 + */ + @Nullable + public static Constructor findPrimaryConstructor(Class clazz) { + Assert.isNull(clazz, "Class must not be null"); + + if(KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(clazz)){ + return KotlinDelegate.findPrimaryConstructor(clazz); } + + return null; } /** @@ -126,6 +210,22 @@ public static Field[] getAllFields(final Class clazz) { return allFields.toArray(new Field[]{}); } + /** + * 检测一个类是否含有 annotations 中的任意一个注解 + * + * @param clazz + * 待验证的类 + * @param annotations + * 检测是否含有的注解 + * + * @return 类包含有 annotations 中的任意一个注解返回 true;否则返回 false + * + * @since 2.3.2 + */ + public static boolean hasAnnotation(final Class clazz, final Class[] annotations) { + return AnnotationUtils.hasClassAnnotationPresent(clazz, annotations); + } + /** * 调用类方法 * @@ -178,4 +278,76 @@ public static Object invoke(final Object object, final Method method, final Obje return method.invoke(object, arguments); } + /** + * Inner class to avoid a hard dependency on Kotlin at runtime. + * + * @since 2.3.2 + */ + private final static class KotlinDelegate { + + /** + * Retrieve the Java constructor corresponding to the Kotlin primary constructor, if any. + * + * @param clazz + * the {@link Class} of the Kotlin class + * + * @see + * https://kotlinlang.org/docs/reference/classes.html#constructors + */ + @Nullable + public static Constructor findPrimaryConstructor(Class clazz) { + try{ + KFunction primaryCtor = KClasses.getPrimaryConstructor(JvmClassMappingKt.getKotlinClass(clazz)); + if(primaryCtor == null){ + return null; + } + Constructor constructor = ReflectJvmMapping.getJavaConstructor(primaryCtor); + Assert.isNull(constructor, ()->new IllegalStateException( + "Failed to find Java constructor for Kotlin primary constructor: " + clazz.getName())); + return constructor; + }catch(UnsupportedOperationException e){ + return null; + } + } + + /** + * Instantiate a Kotlin class using the provided constructor. + * + * @param ctor + * the constructor of the Kotlin class to instantiate + * @param args + * the constructor arguments to apply + * (use {@code null} for unspecified parameter if needed) + */ + public static T instantiateClass(Constructor ctor, Object... args) + throws IllegalAccessException, InvocationTargetException, InstantiationException { + KFunction kotlinConstructor = ReflectJvmMapping.getKotlinFunction(ctor); + + if(kotlinConstructor == null){ + return ctor.newInstance(args); + } + + if(Modifier.isPublic(ctor.getModifiers()) == false || + Modifier.isPublic(ctor.getDeclaringClass().getModifiers()) == false){ + KCallablesJvm.setAccessible(kotlinConstructor, true); + } + + List parameters = kotlinConstructor.getParameters(); + + Assert.isFalse(args.length <= parameters.size(), + "Number of provided arguments should be less of equals than number of constructor parameters"); + + Map argParameters = new HashMap<>(parameters.size()); + + for(int i = 0; i < args.length; i++){ + if(!(parameters.get(i).isOptional() && args[i] == null)){ + argParameters.put(parameters.get(i), args[i]); + } + } + + return kotlinConstructor.callBy(argParameters); + } + + } + } diff --git a/buession-core/src/main/java/com/buession/core/utils/FieldUtils.java b/buession-core/src/main/java/com/buession/core/utils/FieldUtils.java index 517a78162..de2234268 100644 --- a/buession-core/src/main/java/com/buession/core/utils/FieldUtils.java +++ b/buession-core/src/main/java/com/buession/core/utils/FieldUtils.java @@ -26,7 +26,9 @@ */ package com.buession.core.utils; +import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.lang.reflect.Modifier; /** @@ -65,4 +67,20 @@ public static void setAccessible(Field field) { } } + /** + * 检测一个属性是否含有 annotations 中的任意一个注解 + * + * @param field + * 待验证的属性 + * @param annotations + * 检测是否含有的注解 + * + * @return 属性包含有 annotations 中的任意一个注解返回 true;否则返回 false + * + * @since 2.3.2 + */ + public static boolean hasAnnotation(final Field field, final Class[] annotations) { + return AnnotationUtils.hasFieldAnnotationPresent(field, annotations); + } + } diff --git a/buession-core/src/main/java/com/buession/core/utils/KeyValueParser.java b/buession-core/src/main/java/com/buession/core/utils/KeyValueParser.java index 0027f6317..23ca4e7e9 100644 --- a/buession-core/src/main/java/com/buession/core/utils/KeyValueParser.java +++ b/buession-core/src/main/java/com/buession/core/utils/KeyValueParser.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.utils; @@ -39,12 +39,12 @@ public class KeyValueParser { /** * 键 */ - private String key; + private final String key; /** * 字符串值 */ - private String value; + private final String value; /** * Float 类型值 @@ -89,7 +89,7 @@ public class KeyValueParser { * @param delimiter * 分隔符 */ - public KeyValueParser(final String str, final String delimiter){ + public KeyValueParser(final String str, final String delimiter) { int i = str.indexOf(delimiter); this.key = str.substring(0, i); this.value = str.substring(i + 1); @@ -103,7 +103,7 @@ public KeyValueParser(final String str, final String delimiter){ * @param delimiter * 分隔符 */ - public KeyValueParser(final String str, final char delimiter){ + public KeyValueParser(final String str, final char delimiter) { int i = str.indexOf(delimiter); this.key = str.substring(0, i); this.value = str.substring(i + 1); @@ -117,7 +117,7 @@ public KeyValueParser(final String str, final char delimiter){ * * @return 键为 s 时,返回 true;否则,返回 false */ - public boolean isKey(String s){ + public boolean isKey(String s) { return Objects.equals(s, key); } @@ -129,7 +129,7 @@ public boolean isKey(String s){ * * @return 键是否匹配模式 pattern 时,返回 true;否则,返回 false */ - public boolean isKey(Pattern pattern){ + public boolean isKey(Pattern pattern) { return pattern != null && pattern.matcher(key).matches(); } @@ -138,7 +138,7 @@ public boolean isKey(Pattern pattern){ * * @return 键 */ - public String getKey(){ + public String getKey() { return key; } @@ -147,7 +147,7 @@ public String getKey(){ * * @return 值 */ - public String getValue(){ + public String getValue() { return value; } @@ -156,7 +156,7 @@ public String getValue(){ * * @return Float 类型的值 */ - public Float getFloatValue(){ + public Float getFloatValue() { if(floatValue == null){ floatValue = Float.parseFloat(value); } @@ -169,7 +169,7 @@ public Float getFloatValue(){ * * @return Double 类型的值 */ - public Double getDoubleValue(){ + public Double getDoubleValue() { if(doubleValue == null){ doubleValue = Double.parseDouble(value); } @@ -182,7 +182,7 @@ public Double getDoubleValue(){ * * @return Short 类型的值 */ - public Short getShortValue(){ + public Short getShortValue() { if(shortValue == null){ shortValue = Short.parseShort(value); } @@ -195,7 +195,7 @@ public Short getShortValue(){ * * @return Integer 类型的值 */ - public Integer getIntegerValue(){ + public Integer getIntegerValue() { if(intValue == null){ intValue = Integer.parseInt(value); } @@ -208,7 +208,7 @@ public Integer getIntegerValue(){ * * @return Integer 类型的值 */ - public Integer getIntValue(){ + public Integer getIntValue() { return getIntegerValue(); } @@ -217,7 +217,7 @@ public Integer getIntValue(){ * * @return Long 类型的值 */ - public Long getLongValue(){ + public Long getLongValue() { if(longValue == null){ longValue = Long.parseLong(value); } @@ -230,7 +230,7 @@ public Long getLongValue(){ * * @return Boolean 类型的值,当 value 为 1 或不区分大小写为 true 时,返回 true;否则,返回 false */ - public Boolean getBooleanValue(){ + public Boolean getBooleanValue() { if(boolValue == null){ boolValue = Boolean.parseBoolean(value) || "1".equals(value); } @@ -243,7 +243,7 @@ public Boolean getBooleanValue(){ * * @see #getBooleanValue() */ - public Boolean getBoolValue(){ + public Boolean getBoolValue() { return getBooleanValue(); } @@ -254,7 +254,7 @@ public Boolean getBoolValue(){ * * @see Status */ - public Status getStatusValue(){ + public Status getStatusValue() { if(statusValue == null){ statusValue = StatusUtils.valueOf("OK".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value) || @@ -276,7 +276,7 @@ public Status getStatusValue(){ * * @see EnumUtils#getEnumIgnoreCase(Class, String) */ - public > E getEnumValue(Class clazz){ + public > E getEnumValue(Class clazz) { return EnumUtils.getEnumIgnoreCase(clazz, value); } diff --git a/buession-core/src/main/java/com/buession/core/utils/MethodUtils.java b/buession-core/src/main/java/com/buession/core/utils/MethodUtils.java index 36be9c8f0..a3a0cb262 100644 --- a/buession-core/src/main/java/com/buession/core/utils/MethodUtils.java +++ b/buession-core/src/main/java/com/buession/core/utils/MethodUtils.java @@ -21,11 +21,12 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.core.utils; +import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -64,4 +65,20 @@ public static void setAccessible(Method method) { } } + /** + * 检测一个方法是否含有 annotations 中的任意一个注解 + * + * @param method + * 待验证的方法 + * @param annotations + * 检测是否含有的注解 + * + * @return 方法包含有 annotations 中的任意一个注解返回 true;否则返回 false + * + * @since 2.3.2 + */ + public static boolean hasAnnotation(final Method method, final Class[] annotations) { + return AnnotationUtils.hasMethodAnnotationPresent(method, annotations); + } + } diff --git a/buession-core/src/main/java/com/buession/core/utils/ObjectUtils.java b/buession-core/src/main/java/com/buession/core/utils/ObjectUtils.java new file mode 100644 index 000000000..60685ab8c --- /dev/null +++ b/buession-core/src/main/java/com/buession/core/utils/ObjectUtils.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2023 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.core.utils; + +import java.util.function.Consumer; + +/** + * 对象工具类 + * + * @author Yong.Teng + * @since 2.3.2 + */ +public class ObjectUtils { + + private ObjectUtils() { + + } + + /** + * 当对象不为 null 时,执行方法 + * + * @param object + * 对象 + * @param consumer + * {@link Consumer} + * @param + * 对象引用类型 + */ + public static void invokeIfAvailable(final T object, final Consumer consumer) { + if(object != null){ + consumer.accept(object); + } + } + +} diff --git a/buession-core/src/main/java/com/buession/core/utils/PinyinUtils.java b/buession-core/src/main/java/com/buession/core/utils/PinyinUtils.java index 42e8d39cb..d104fb6ed 100644 --- a/buession-core/src/main/java/com/buession/core/utils/PinyinUtils.java +++ b/buession-core/src/main/java/com/buession/core/utils/PinyinUtils.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.utils; @@ -50,7 +50,7 @@ public class PinyinUtils { * @throws BadHanyuPinyinOutputFormatCombination * 异常 */ - public static String getPinyin(final String str) throws BadHanyuPinyinOutputFormatCombination{ + public static String getPinyin(final String str) throws BadHanyuPinyinOutputFormatCombination { return getPinyin(str, false, CaseType.LOWERCASE); } @@ -69,7 +69,8 @@ public static String getPinyin(final String str) throws BadHanyuPinyinOutputForm * @throws net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination * 异常 */ - public static String getPinyin(final String str, final boolean hasTone, final CaseType caseType) throws BadHanyuPinyinOutputFormatCombination{ + public static String getPinyin(final String str, final boolean hasTone, final CaseType caseType) + throws BadHanyuPinyinOutputFormatCombination { if(Validate.isEmpty(str)){ return str; } @@ -89,7 +90,7 @@ public static String getPinyin(final String str, final boolean hasTone, final Ca StringBuilder sb = new StringBuilder(str.length()); try{ - char chars[] = str.toCharArray(); + char[] chars = str.toCharArray(); for(char c : chars){ // 如果包含有中文标点除号,需要使用正则表达式 @@ -114,12 +115,12 @@ public static String getPinyin(final String str, final boolean hasTone, final Ca * * @return 拼音首字母集合 */ - public static String getPinYinFirstChar(final String str){ + public static String getPinYinFirstChar(final String str) { if(Validate.isEmpty(str)){ return str; } - char chars[] = str.toCharArray(); + char[] chars = str.toCharArray(); String[] pinyinArray; StringBuilder sb = new StringBuilder(chars.length); diff --git a/buession-core/src/main/java/com/buession/core/utils/RandomUtils.java b/buession-core/src/main/java/com/buession/core/utils/RandomUtils.java index 6020e1a3b..3c7b95d39 100644 --- a/buession-core/src/main/java/com/buession/core/utils/RandomUtils.java +++ b/buession-core/src/main/java/com/buession/core/utils/RandomUtils.java @@ -24,6 +24,7 @@ */ package com.buession.core.utils; +import java.util.Objects; import java.util.Random; /** @@ -36,7 +37,7 @@ public class RandomUtils { private final static Random RANDOM = new Random(); - private RandomUtils(){ + private RandomUtils() { } /** @@ -46,7 +47,7 @@ private RandomUtils(){ * * @since 1.2.0 */ - public static boolean nextBoolean(){ + public static boolean nextBoolean() { return RANDOM.nextBoolean(); } @@ -60,7 +61,7 @@ public static boolean nextBoolean(){ * * @since 1.2.0 */ - public static byte[] nextBytes(final int count){ + public static byte[] nextBytes(final int count) { Assert.isZeroNegative(count, "Count cannot be negative."); final byte[] result = new byte[count]; @@ -75,7 +76,7 @@ public static byte[] nextBytes(final int count){ * * @since 1.2.0 */ - public static int nextInt(){ + public static int nextInt() { return nextInt(0, Integer.MAX_VALUE); } @@ -89,7 +90,7 @@ public static int nextInt(){ * * @since 1.2.0 */ - public static int nextInt(final int bound){ + public static int nextInt(final int bound) { return RANDOM.nextInt(bound); } @@ -105,7 +106,7 @@ public static int nextInt(final int bound){ * * @since 1.2.0 */ - public static int nextInt(final int start, final int end){ + public static int nextInt(final int start, final int end) { Assert.isTrue(start < 0, "Both range values must be non-negative."); if(start == end){ @@ -123,7 +124,7 @@ public static int nextInt(final int start, final int end){ * * @since 1.2.0 */ - public static long nextLong(){ + public static long nextLong() { return nextLong(0L, Long.MAX_VALUE); } @@ -137,7 +138,7 @@ public static long nextLong(){ * * @since 1.2.0 */ - public static long nextLong(final long bound){ + public static long nextLong(final long bound) { return nextLong(0, bound - 1L); } @@ -153,7 +154,7 @@ public static long nextLong(final long bound){ * * @since 1.2.0 */ - public static long nextLong(final long start, final long end){ + public static long nextLong(final long start, final long end) { Assert.isTrue(start < 0, "Both range values must be non-negative."); if(start == end){ @@ -171,7 +172,7 @@ public static long nextLong(final long start, final long end){ * * @since 1.2.0 */ - public static float nextFloat(){ + public static float nextFloat() { return nextFloat(0L, Float.MAX_VALUE); } @@ -185,7 +186,7 @@ public static float nextFloat(){ * * @since 1.2.0 */ - public static float nextFloat(final float bound){ + public static float nextFloat(final float bound) { return nextFloat(0, bound - 1F); } @@ -201,10 +202,10 @@ public static float nextFloat(final float bound){ * * @since 1.2.0 */ - public static float nextFloat(final float start, final float end){ + public static float nextFloat(final float start, final float end) { Assert.isTrue(start < 0, "Both range values must be non-negative."); - if(start == end){ + if(Objects.equals(start, end)){ return start; } @@ -219,7 +220,7 @@ public static float nextFloat(final float start, final float end){ * * @since 1.2.0 */ - public static double nextDouble(){ + public static double nextDouble() { return nextDouble(0L, Double.MAX_VALUE); } @@ -233,7 +234,7 @@ public static double nextDouble(){ * * @since 1.2.0 */ - public static double nextDouble(final double bound){ + public static double nextDouble(final double bound) { return nextDouble(0, bound - 1); } @@ -249,10 +250,10 @@ public static double nextDouble(final double bound){ * * @since 1.2.0 */ - public static double nextDouble(final double start, final double end){ + public static double nextDouble(final double start, final double end) { Assert.isTrue(start < 0, "Both range values must be non-negative."); - if(start == end){ + if(Objects.equals(start, end)){ return start; } diff --git a/buession-core/src/main/java/com/buession/core/utils/ReflectionUtils.java b/buession-core/src/main/java/com/buession/core/utils/ReflectionUtils.java new file mode 100644 index 000000000..2b3118d73 --- /dev/null +++ b/buession-core/src/main/java/com/buession/core/utils/ReflectionUtils.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2023 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.core.utils; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +/** + * 反射工具 + * + * @author Yong.Teng + * @since 2.3.2 + */ +public class ReflectionUtils { + + private ReflectionUtils() { + + } + + /** + * Make the given constructor accessible, explicitly setting it accessible + * if necessary. The {@code setAccessible(true)} method is only called + * when actually necessary, to avoid unnecessary conflicts with a JVM + * SecurityManager (if active). + * + * @param ctor + * the constructor to make accessible + * + * @see java.lang.reflect.Constructor#setAccessible + */ + public static void makeAccessible(Constructor ctor) { + if((Modifier.isPublic(ctor.getModifiers()) == false || + Modifier.isPublic(ctor.getDeclaringClass().getModifiers()) == false) && ctor.isAccessible() == false){ + ctor.setAccessible(true); + } + } + +} diff --git a/buession-core/src/main/java/com/buession/core/utils/StringUtils.java b/buession-core/src/main/java/com/buession/core/utils/StringUtils.java index bb6dfe43a..f09dd0e69 100755 --- a/buession-core/src/main/java/com/buession/core/utils/StringUtils.java +++ b/buession-core/src/main/java/com/buession/core/utils/StringUtils.java @@ -482,6 +482,28 @@ public static String[] toUpperCase(String[] sources, Locale locale) { } } + /** + * 取前 N 个字符,如字符总数大于 N,则会在字符末尾添加省略号 + * + * @param str + * 原始字符串 + * @param length + * 截取长度 + * + * @return 截取后的字符串 + * + * @since 2.3.2 + */ + public static String formatEllipsis(String str, int length) { + if(str != null){ + if(str.length() > length){ + return str.substring(0, length) + "..."; + } + } + + return str; + } + public static boolean regionMatches(final CharSequence cs, final boolean ignoreCase, final int thisStart, final CharSequence substring, final int start, final int length) { if(cs instanceof String && substring instanceof String){ diff --git a/buession-core/src/main/java/com/buession/core/utils/SystemPropertyUtils.java b/buession-core/src/main/java/com/buession/core/utils/SystemPropertyUtils.java index 7b07b9830..b4e0e0f2c 100644 --- a/buession-core/src/main/java/com/buession/core/utils/SystemPropertyUtils.java +++ b/buession-core/src/main/java/com/buession/core/utils/SystemPropertyUtils.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.utils; @@ -44,7 +44,7 @@ public class SystemPropertyUtils { * * @return short 类型字符串值 */ - public static String setProperty(final String name, final short value){ + public static String setProperty(final String name, final short value) { return setProperty(name, Short.toString(value)); } @@ -58,7 +58,7 @@ public static String setProperty(final String name, final short value){ * * @return int 类型字符串值 */ - public static String setProperty(final String name, final int value){ + public static String setProperty(final String name, final int value) { return setProperty(name, Integer.toString(value)); } @@ -72,7 +72,7 @@ public static String setProperty(final String name, final int value){ * * @return long 类型字符串值 */ - public static String setProperty(final String name, final long value){ + public static String setProperty(final String name, final long value) { return setProperty(name, Long.toString(value)); } @@ -86,7 +86,7 @@ public static String setProperty(final String name, final long value){ * * @return 布尔型字符串值 */ - public static String setProperty(final String name, final boolean value){ + public static String setProperty(final String name, final boolean value) { return setProperty(name, Boolean.toString(value)); } @@ -100,7 +100,7 @@ public static String setProperty(final String name, final boolean value){ * * @return char 类型字符串值 */ - public static String setProperty(final String name, final char value){ + public static String setProperty(final String name, final char value) { return setProperty(name, Character.toString(value)); } @@ -114,7 +114,7 @@ public static String setProperty(final String name, final char value){ * * @return 属性值 */ - public static String setProperty(final String name, final String value){ + public static String setProperty(final String name, final String value) { return System.setProperty(name, value); } @@ -128,7 +128,7 @@ public static String setProperty(final String name, final String value){ * * @return 属性值 */ - public static String setPropertyIfPresent(final String name, final String value){ + public static String setPropertyIfPresent(final String name, final String value) { if(value != null){ return System.setProperty(name, value); } @@ -144,14 +144,14 @@ public static String setPropertyIfPresent(final String name, final String value) * * @return 属性值 */ - public static String getProperty(final String name){ + public static String getProperty(final String name) { String value = System.getProperty(name); - if(Validate.hasText(value) == false){ - value = System.getenv(name); + if(Validate.hasText(value)){ + return value; } - return value; + return System.getenv(name); } } diff --git a/buession-core/src/main/java/com/buession/core/validator/routines/DomainValidator.java b/buession-core/src/main/java/com/buession/core/validator/routines/DomainValidator.java index 8d3b3428a..e450f70ce 100644 --- a/buession-core/src/main/java/com/buession/core/validator/routines/DomainValidator.java +++ b/buession-core/src/main/java/com/buession/core/validator/routines/DomainValidator.java @@ -51,10 +51,12 @@ public class DomainValidator { // Also widely used as localhost.localdomain "localdomain"}; - private DomainValidator(){ + private final static Pattern DOMAIN_NAME_REGEX_PATTERN = Pattern.compile(DOMAIN_NAME_REGEX); + + private DomainValidator() { } - public static boolean isValid(final CharSequence charSequence){ + public static boolean isValid(final CharSequence charSequence) { if(charSequence == null){ return false; } @@ -65,11 +67,11 @@ public static boolean isValid(final CharSequence charSequence){ } } - Matcher matcher = Pattern.compile(DOMAIN_NAME_REGEX).matcher(charSequence); + Matcher matcher = DOMAIN_NAME_REGEX_PATTERN.matcher(charSequence); return matcher.matches() && isValidTld(matcher.group(1)); } - private static boolean isValidTld(final String tld){ + private static boolean isValidTld(final String tld) { try{ return EnumUtils.getEnumIgnoreCase(DomainTLD.class, chompLeadingDot(tld.toLowerCase())) != null; }catch(IllegalArgumentException e){ @@ -77,7 +79,7 @@ private static boolean isValidTld(final String tld){ } } - private static String chompLeadingDot(final String str){ + private static String chompLeadingDot(final String str) { return str.startsWith(".") ? str.substring(1) : str; } diff --git a/buession-core/src/main/java/com/buession/core/validator/routines/IDCardValidator.java b/buession-core/src/main/java/com/buession/core/validator/routines/IDCardValidator.java index 72efa1e21..fe56dabbf 100644 --- a/buession-core/src/main/java/com/buession/core/validator/routines/IDCardValidator.java +++ b/buession-core/src/main/java/com/buession/core/validator/routines/IDCardValidator.java @@ -21,7 +21,7 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.core.validator.routines; @@ -41,10 +41,10 @@ public class IDCardValidator { private final static char[] CHECK_CODES = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'}; - private IDCardValidator(){ + private IDCardValidator() { } - public static boolean isValid(final CharSequence charSequence, final boolean strict, final Date birthday){ + public static boolean isValid(final CharSequence charSequence, final boolean strict, final Date birthday) { if(charSequence == null || charSequence.length() != IDCARD_LENGTH){ return false; }else if(strict && birthday == null){ @@ -63,9 +63,9 @@ public static boolean isValid(final CharSequence charSequence, final boolean str } SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd"); - char check_code = CHECK_CODES[sum % 11]; + char checkCode = CHECK_CODES[sum % 11]; - if(check_code == charSequence.charAt(IDCARD_LENGTH - 1)){ + if(checkCode == charSequence.charAt(IDCARD_LENGTH - 1)){ if(strict){ String s = charSequence.subSequence(6, 14).toString(); diff --git a/buession-core/src/main/java/com/buession/core/validator/routines/ISBNValidator.java b/buession-core/src/main/java/com/buession/core/validator/routines/ISBNValidator.java index 704d7c0a5..9c0631940 100644 --- a/buession-core/src/main/java/com/buession/core/validator/routines/ISBNValidator.java +++ b/buession-core/src/main/java/com/buession/core/validator/routines/ISBNValidator.java @@ -21,7 +21,7 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.core.validator.routines; @@ -36,14 +36,14 @@ */ public class ISBNValidator { - private ISBNValidator(){ + private ISBNValidator() { } - public static boolean isValid(final CharSequence charSequence, final char separator){ + public static boolean isValid(final CharSequence charSequence, final char separator) { return isIsbn10(charSequence, separator) || isIsbn13(charSequence, separator); } - public static boolean isValid(final CharSequence charSequence, final char separator, final ISBNType type){ + public static boolean isValid(final CharSequence charSequence, final char separator, final ISBNType type) { if(ISBNType.ISBN_TYPE_10.equals(type)){ return isIsbn10(charSequence, separator); }else if(ISBNType.ISBN_TYPE_13.equals(type)){ @@ -53,7 +53,7 @@ public static boolean isValid(final CharSequence charSequence, final char separa } } - public static boolean isIsbn10(final CharSequence charSequence, final char separator){ + public static boolean isIsbn10(final CharSequence charSequence, final char separator) { if(charSequence == null || validSeparator(separator) == false){ return false; } @@ -98,7 +98,6 @@ public static boolean isIsbn10(final CharSequence charSequence, final char separ ++sl; gl = 0; - continue; }else if(c < '0' || c > '9'){ return false; }else{ @@ -144,7 +143,7 @@ public static boolean isIsbn10(final CharSequence charSequence, final char separ return ch == lash_ch; } - public static boolean isIsbn13(final CharSequence charSequence, final char separator){ + public static boolean isIsbn13(final CharSequence charSequence, final char separator) { if(charSequence == null || validSeparator(separator) == false){ return false; } @@ -185,7 +184,6 @@ public static boolean isIsbn13(final CharSequence charSequence, final char separ ++sl; gl = 0; - continue; }else if(c < '0' || c > '9'){ return false; }else{ @@ -219,11 +217,11 @@ public static boolean isIsbn13(final CharSequence charSequence, final char separ return (checksum == 10 ? '0' : checksum + '0') == lash_ch; } - private static boolean validSeparator(final char separator){ + private static boolean validSeparator(final char separator) { return separator == '\0' || separator == '-' || separator == ' '; } - private static boolean validLastCharacter(final char ch){ + private static boolean validLastCharacter(final char ch) { return (ch < '0' || ch > '9') && ch != 'X'; } diff --git a/buession-core/src/main/java/com/buession/core/validator/routines/IpValidator.java b/buession-core/src/main/java/com/buession/core/validator/routines/IpValidator.java index 28559604f..d3ab01b4c 100644 --- a/buession-core/src/main/java/com/buession/core/validator/routines/IpValidator.java +++ b/buession-core/src/main/java/com/buession/core/validator/routines/IpValidator.java @@ -21,7 +21,7 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://buession.buession.com.cn/LICENSE | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.core.validator.routines; @@ -44,10 +44,10 @@ public class IpValidator { private final static int IPV6_MAX_GROUP_SIZE = 8; - private IpValidator(){ + private IpValidator() { } - public static boolean isValid(final CharSequence charSequence){ + public static boolean isValid(final CharSequence charSequence) { if(charSequence == null || charSequence.length() == 0){ return false; } @@ -56,7 +56,7 @@ public static boolean isValid(final CharSequence charSequence){ return isIpv4(str) || isIpv6(str); } - public static boolean isValid(final CharSequence charSequence, final IpType type){ + public static boolean isValid(final CharSequence charSequence, final IpType type) { if(charSequence == null || charSequence.length() == 0){ return false; } @@ -70,7 +70,7 @@ public static boolean isValid(final CharSequence charSequence, final IpType type } } - private static boolean isIpv4(final String str){ + private static boolean isIpv4(final String str) { if(str == null){ return false; } @@ -99,7 +99,7 @@ private static boolean isIpv4(final String str){ return true; } - private static boolean IPV4_group_valid(final char[] digits, final int digitSize){ + private static boolean IPV4_group_valid(final char[] digits, final int digitSize) { switch(digitSize){ case 1: return digits[0] >= '0' && digits[0] <= '9'; @@ -122,7 +122,7 @@ private static boolean IPV4_group_valid(final char[] digits, final int digitSize } } - private static boolean isIpv6(final String str){ + private static boolean isIpv6(final String str) { if(str == null){ return false; } @@ -143,7 +143,7 @@ private static boolean isIpv6(final String str){ } } - private static boolean isIpv6(final String str, final int minGroup, final int maxGroup){ + private static boolean isIpv6(final String str, final int minGroup, final int maxGroup) { if("::".equals(str)){ return true; } @@ -179,14 +179,13 @@ private static boolean isIpv6(final String str, final int minGroup, final int ma return true; } - private static boolean IPV6_group_valid(final char[] digits, final int digitSize){ + private static boolean IPV6_group_valid(final char[] digits, final int digitSize) { if(digitSize < 1 || digitSize > 4){ return false; } for(char c : digits){ if((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')){ - continue; }else{ return false; } diff --git a/buession-core/src/main/java/com/buession/core/validator/routines/TelValidator.java b/buession-core/src/main/java/com/buession/core/validator/routines/TelValidator.java index 75aa4f856..72bafd46a 100644 --- a/buession-core/src/main/java/com/buession/core/validator/routines/TelValidator.java +++ b/buession-core/src/main/java/com/buession/core/validator/routines/TelValidator.java @@ -21,7 +21,7 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.core.validator.routines; @@ -34,19 +34,24 @@ */ public class TelValidator { - private final static String AREA_ACODE_PATTERN = "(86-?)|0)\\d{2,3}"; + private final static String AREA_CODE_REGEX = "(86-?)|0)\\d{2,3}"; - private final static String TEL_PATTERN = "[1-9]\\d{6,7}"; + private final static String TEL_REGEX = "[1-9]\\d{6,7}"; - private final static String WITH_AREA_CODE_PATTERN = - "^(((" + AREA_ACODE_PATTERN + "-?)|(((" + AREA_ACODE_PATTERN + "))|(\\((" + AREA_ACODE_PATTERN + "\\)))" + TEL_PATTERN + "$"; + private final static String WITH_AREA_CODE_REGEX = + "^(((" + AREA_CODE_REGEX + "-?)|(((" + AREA_CODE_REGEX + "))|(\\((" + AREA_CODE_REGEX + "\\)))" + + TEL_REGEX + "$"; - private final static String WITHOUT_AREA_CODE_PATTERN = "^" + TEL_PATTERN + "$"; + private final static String WITHOUT_AREA_CODE_REGEX = "^" + TEL_REGEX + "$"; - private TelValidator(){ + private final static Pattern WITH_AREA_CODE_PATTERN = Pattern.compile(WITH_AREA_CODE_REGEX); + + private final static Pattern WITHOUT_AREA_CODE_PATTERN = Pattern.compile(WITHOUT_AREA_CODE_REGEX); + + private TelValidator() { } - public static boolean isValid(final CharSequence charSequence, final AreaCodeType areaCodeType){ + public static boolean isValid(final CharSequence charSequence, final AreaCodeType areaCodeType) { if(charSequence == null || charSequence.length() < 7){ return false; } @@ -61,13 +66,13 @@ public static boolean isValid(final CharSequence charSequence, final AreaCodeTyp } } - private static boolean validHasAreaCode(final CharSequence charSequence){ - Matcher matcher = Pattern.compile(WITH_AREA_CODE_PATTERN).matcher(charSequence); + private static boolean validHasAreaCode(final CharSequence charSequence) { + Matcher matcher = WITH_AREA_CODE_PATTERN.matcher(charSequence); return matcher.matches(); } - private static boolean validNotHasAreaCode(final CharSequence charSequence){ - Matcher matcher = Pattern.compile(WITHOUT_AREA_CODE_PATTERN).matcher(charSequence); + private static boolean validNotHasAreaCode(final CharSequence charSequence) { + Matcher matcher = WITHOUT_AREA_CODE_PATTERN.matcher(charSequence); return matcher.matches(); } diff --git a/buession-core/src/test/java/com/buession/core/utils/ObjectUtilsTest.java b/buession-core/src/test/java/com/buession/core/utils/ObjectUtilsTest.java new file mode 100644 index 000000000..db8603a90 --- /dev/null +++ b/buession-core/src/test/java/com/buession/core/utils/ObjectUtilsTest.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2023 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.core.utils; + +import org.junit.Test; + +/** + * @author Yong.Teng + * @since 2.3.2 + */ +public class ObjectUtilsTest { + + @Test + public void nullTest() { + String str = null; + ObjectUtils.invokeIfAvailable(str, String::length); + } + + @Test + public void nonNullTest() { + String str = "abc"; + ObjectUtils.invokeIfAvailable(str, String::length); + } + +} diff --git a/buession-cron/pom.xml b/buession-cron/pom.xml index 4b477824e..926269469 100644 --- a/buession-cron/pom.xml +++ b/buession-cron/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.1 + 2.3.2 buession-cron http://www.buession.com/ diff --git a/buession-dao/pom.xml b/buession-dao/pom.xml index fe82a007d..1a93d528b 100644 --- a/buession-dao/pom.xml +++ b/buession-dao/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.1 + 2.3.2 buession-dao http://www.buession.com/ diff --git a/buession-dao/src/main/java/com/buession/dao/AbstractMyBatisDao.java b/buession-dao/src/main/java/com/buession/dao/AbstractMyBatisDao.java index 81eb1ef5e..62848f946 100755 --- a/buession-dao/src/main/java/com/buession/dao/AbstractMyBatisDao.java +++ b/buession-dao/src/main/java/com/buession/dao/AbstractMyBatisDao.java @@ -32,7 +32,8 @@ import java.util.List; import java.util.Map; -import com.buession.beans.BeanUtils; +import com.buession.beans.BeanConverter; +import com.buession.beans.DefaultBeanConverter; import com.buession.core.utils.FieldUtils; import com.buession.core.utils.Assert; import com.buession.core.utils.RandomUtils; @@ -139,7 +140,10 @@ public int update(E e, Map conditions) { Map eMap = (Map) e; eMap.forEach((key, value)->data.put(key.toString(), value)); }else{ - Map eData = BeanUtils.toMap(e); + BeanConverter beanConverter = new DefaultBeanConverter(); + Map eData = new HashMap<>(); + + beanConverter.convert(e, eData); data.putAll(eData); } diff --git a/buession-dao/src/main/java/com/buession/dao/Pagination.java b/buession-dao/src/main/java/com/buession/dao/Pagination.java index c06aa5a5a..bca6acebf 100644 --- a/buession-dao/src/main/java/com/buession/dao/Pagination.java +++ b/buession-dao/src/main/java/com/buession/dao/Pagination.java @@ -21,7 +21,7 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.dao; @@ -44,7 +44,7 @@ public class Pagination extends com.buession.core.Pagination { /** * Constructs with default configuration. */ - public Pagination(){ + public Pagination() { super(); } @@ -56,8 +56,9 @@ public Pagination(){ * @param pagesize * 每页大小 */ - public Pagination(int page, int pagesize){ + public Pagination(int page, int pagesize) { super(page, pagesize); + setNextPage(getPage() + 1); } /** @@ -70,8 +71,9 @@ public Pagination(int page, int pagesize){ * @param totalRecords * 总记录数 */ - public Pagination(int page, int pagesize, long totalRecords){ + public Pagination(int page, int pagesize, long totalRecords) { super(page, pagesize, totalRecords); + setNextPage(getPage() + 1); } /** @@ -79,7 +81,7 @@ public Pagination(int page, int pagesize, long totalRecords){ * * @return 查询偏移量 */ - public int getOffset(){ + public int getOffset() { if(offset == null){ if(getPage() > 1){ setOffset((getPage() - 1) * getPagesize()); @@ -97,7 +99,7 @@ public int getOffset(){ * @param offset * 查询偏移量 */ - public void setOffset(int offset){ + public void setOffset(int offset) { this.offset = Math.max(offset, 0); } diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/ClickHouseDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/ClickHouseDialect.java index 70d965f23..014192f4c 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/ClickHouseDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/ClickHouseDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/CsiiDBDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/CsiiDBDialect.java index c26c5977d..778a7b41f 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/CsiiDBDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/CsiiDBDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/CubridDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/CubridDialect.java index 3967d7fad..2c3d9dee5 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/CubridDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/CubridDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/DB2Dialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/DB2Dialect.java index 45c9f4b37..d5f557102 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/DB2Dialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/DB2Dialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder("SELECT * FROM "); sb.append("(SELECT TEMP.*, ROWNUMBER() OVER() AS ROW_ID FROM (").append(sql).append(") AS TEMP)"); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/Dialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/Dialect.java index 8cca4c8a3..c599ac83a 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/Dialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/Dialect.java @@ -60,7 +60,7 @@ default boolean supportsLimit() { * * @return 分页 SQL */ - default String buildPaginationSql(final String sql, final long offset, final long limit) { + default String buildPaginationSql(final String sql, final int offset, final int limit) { return null; } diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/DmDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/DmDialect.java index c8ecd98c8..e9e5005e8 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/DmDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/DmDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder("SELECT * FROM"); sb.append("(SELECT TEMP.*, ROWNUM ROW_ID FROM (").append(sql).append(") TEMP WHERE ROWNUM <= ").append(limit) diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/FirebirdDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/FirebirdDialect.java index b2824b31d..7a7cd912b 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/FirebirdDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/FirebirdDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" OFFSET ").append(offset).append(" ROWS FETCH NEXT ").append(limit) diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/GBase8sDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/GBase8sDialect.java index 4bcca9ac9..80f894ab0 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/GBase8sDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/GBase8sDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); int lastIndex = sql.toLowerCase().indexOf("select"); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/GBaseDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/GBaseDialect.java index 85b29912e..1d898d83f 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/GBaseDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/GBaseDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/GaussDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/GaussDialect.java index da1e5c961..2248ed4e0 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/GaussDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/GaussDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder("SELECT * FROM"); sb.append("(SELECT TEMP.*, ROWNUM ROW_ID FROM (").append(sql).append(") TEMP WHERE ROWNUM <= ").append(limit) diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/GoldiLocksDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/GoldiLocksDialect.java index 84a79220d..8192a3ab5 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/GoldiLocksDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/GoldiLocksDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/H2Dialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/H2Dialect.java index 24cb9da74..973c73291 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/H2Dialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/H2Dialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/HSQLDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/HSQLDialect.java index 4e727daed..b99dc0337 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/HSQLDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/HSQLDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/HighGoDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/HighGoDialect.java index ebea04c47..713d445f2 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/HighGoDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/HighGoDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/ImpalaDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/ImpalaDialect.java index 2fb9127a3..1a43e6ba6 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/ImpalaDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/ImpalaDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/InformixDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/InformixDialect.java index c286fbda0..56527cd90 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/InformixDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/InformixDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(); sb.append("SELECT SKIP ").append(offset).append(" FIRST ").append(limit); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/KingBaseEsDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/KingBaseEsDialect.java index 4e2431c66..96331a8f3 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/KingBaseEsDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/KingBaseEsDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/LealoneDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/LealoneDialect.java index 4db563f0a..9c8849661 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/LealoneDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/LealoneDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/MariaDBDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/MariaDBDialect.java index d0feb348a..e56fb5fc1 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/MariaDBDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/MariaDBDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/MySQLDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/MySQLDialect.java index 6b5d56dcb..9750e8793 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/MySQLDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/MySQLDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/OceanBaseDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/OceanBaseDialect.java index 347788bf7..255681257 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/OceanBaseDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/OceanBaseDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/OpenGaussDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/OpenGaussDialect.java index 88ba1ee4b..934bccf45 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/OpenGaussDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/OpenGaussDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/Oracle12cDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/Oracle12cDialect.java index 1454ed410..23d695146 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/Oracle12cDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/Oracle12cDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" OFFSET ").append(offset).append(" ROWS FETCH NEXT ").append(limit) diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/OracleDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/OracleDialect.java index ccee24a0f..28109cdb4 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/OracleDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/OracleDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(String sql, long offset, long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder("SELECT * FROM"); sb.append("(SELECT TEMP.*, ROWNUM ROW_ID FROM (").append(sql).append(") TEMP WHERE ROWNUM <= ").append(limit) diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/OscarDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/OscarDialect.java index 214d31d31..a610eb308 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/OscarDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/OscarDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/PhoenixDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/PhoenixDialect.java index c0cdf35c9..e7136bc0e 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/PhoenixDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/PhoenixDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/PostgreSQLDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/PostgreSQLDialect.java index 519296dd3..b0189c8f3 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/PostgreSQLDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/PostgreSQLDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/RedShiftDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/RedShiftDialect.java index 874a5b79b..6f227ea94 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/RedShiftDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/RedShiftDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SAPHanaDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SAPHanaDialect.java index 4c7b1ed8b..7ee70a0f4 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SAPHanaDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SAPHanaDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SQLLiteDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SQLLiteDialect.java index 3819ead32..74a07737d 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SQLLiteDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SQLLiteDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SQLServer2005Dialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SQLServer2005Dialect.java index 1905332b7..d807d4a6c 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SQLServer2005Dialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SQLServer2005Dialect.java @@ -46,7 +46,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { StringBuilder pagingBuilder = new StringBuilder(); String orderBy = getOrderByPart(sql); String distinctStr = Constants.EMPTY_STRING; diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SQLServerDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SQLServerDialect.java index 54c0f8b2a..3e092ad86 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SQLServerDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SQLServerDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" OFFSET ").append(offset).append(" ROWS FETCH NEXT ").append(limit) diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SinodbDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SinodbDialect.java index 6cdbc46b3..be1d2cc6e 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SinodbDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SinodbDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); int lastIndex = sql.toLowerCase().indexOf("select"); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SybaseDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SybaseDialect.java index 64062df9f..db5c43e9c 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SybaseDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/SybaseDialect.java @@ -48,7 +48,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { int index = findFrom(sql); if(index == -1){ diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/TDengineDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/TDengineDialect.java index 5685a0352..a4781704b 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/TDengineDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/TDengineDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/UxDBDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/UxDBDialect.java index 19d0d7065..5cbd1665a 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/UxDBDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/UxDBDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/VerticaDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/VerticaDialect.java index 4374e7dc3..020c7e29c 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/VerticaDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/VerticaDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/XCloudDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/XCloudDialect.java index 45145619f..36bad119d 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/XCloudDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/XCloudDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/XuGuDialect.java b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/XuGuDialect.java index e1bffb585..378b1c56f 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/XuGuDialect.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/dialect/XuGuDialect.java @@ -38,7 +38,7 @@ public DbType dbType() { } @Override - public String buildPaginationSql(final String sql, final long offset, final long limit) { + public String buildPaginationSql(final String sql, final int offset, final int limit) { final StringBuilder sb = new StringBuilder(sql); sb.append(" LIMIT "); diff --git a/buession-dao/src/main/java/com/buession/dao/mybatis/interceptor/PaginationInterceptor.java b/buession-dao/src/main/java/com/buession/dao/mybatis/interceptor/PaginationInterceptor.java index bf74954ef..7b3b353c3 100644 --- a/buession-dao/src/main/java/com/buession/dao/mybatis/interceptor/PaginationInterceptor.java +++ b/buession-dao/src/main/java/com/buession/dao/mybatis/interceptor/PaginationInterceptor.java @@ -24,14 +24,18 @@ */ package com.buession.dao.mybatis.interceptor; +import com.buession.core.converter.mapper.PropertyMapper; +import com.buession.core.utils.StringUtils; import com.buession.dao.mybatis.PageRowBounds; import com.buession.dao.mybatis.dialect.Dialect; +import org.apache.ibatis.BoundSqlSqlSource; import org.apache.ibatis.cache.CacheKey; import org.apache.ibatis.executor.Executor; import org.apache.ibatis.executor.statement.StatementHandler; import org.apache.ibatis.mapping.BoundSql; import org.apache.ibatis.mapping.MappedStatement; import org.apache.ibatis.mapping.SqlCommandType; +import org.apache.ibatis.mapping.SqlSource; import org.apache.ibatis.plugin.Intercepts; import org.apache.ibatis.plugin.Invocation; import org.apache.ibatis.plugin.Plugin; @@ -39,8 +43,6 @@ import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.RowBounds; -import java.sql.Connection; -import java.sql.Statement; import java.util.Properties; /** @@ -49,21 +51,14 @@ * @author Yong.Teng * @since 2.3.1 */ -@Intercepts( - { - @Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class}), - @Signature(type = StatementHandler.class, method = "query", args = {Statement.class, - ResultHandler.class}), - @Signature(type = StatementHandler.class, method = "getBoundSql", args = {}), - @Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, - RowBounds.class, ResultHandler.class}), - @Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, - RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class}) - } -) +@Intercepts({ + @Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, + RowBounds.class, ResultHandler.class}), + @Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class, + RowBounds.class, ResultHandler.class, CacheKey.class, BoundSql.class}) +}) public class PaginationInterceptor extends AbstractInterceptor { - @SuppressWarnings({"rawtypes"}) @Override public Object intercept(Invocation invocation) throws Throwable { Object target = invocation.getTarget(); @@ -75,11 +70,9 @@ public Object intercept(Invocation invocation) throws Throwable { if(statement.getSqlCommandType() == SqlCommandType.SELECT && rowBounds instanceof PageRowBounds){ final Executor executor = (Executor) target; + final Object parameter = args[1]; - Object parameter = args[1]; - ResultHandler resultHandler = (ResultHandler) args[3]; - - BoundSql boundSql = args.length == 4 ? statement.getBoundSql(parameter) : (BoundSql) args[5]; + BoundSql boundSql = args.length == 6 ? (BoundSql) args[5] : statement.getBoundSql(parameter); Dialect dialect = findDialect(executor); @@ -87,8 +80,14 @@ public Object intercept(Invocation invocation) throws Throwable { boundSql = createPaginationBoundSql(dialect, statement, boundSql, rowBounds); } - CacheKey cacheKey = executor.createCacheKey(statement, parameter, rowBounds, boundSql); - return executor.query(statement, parameter, rowBounds, resultHandler, cacheKey, boundSql); + invocation.getArgs()[0] = copyMappedStatement(statement, new BoundSqlSqlSource(boundSql)); + invocation.getArgs()[2] = RowBounds.DEFAULT; + + if(args.length == 6){ + CacheKey cacheKey = executor.createCacheKey(statement, parameter, rowBounds, boundSql); + invocation.getArgs()[4] = cacheKey; + invocation.getArgs()[5] = boundSql; + } } }else{ // StatementHandler @@ -111,6 +110,28 @@ public Object plugin(Object target) { public void setProperties(Properties properties) { } + private static MappedStatement copyMappedStatement(final MappedStatement statement, final SqlSource newSqlSource) { + final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); + final MappedStatement.Builder builder = new MappedStatement.Builder(statement.getConfiguration(), + statement.getId(), newSqlSource, statement.getSqlCommandType()); + + builder.resource(statement.getResource()).parameterMap(statement.getParameterMap()) + .resultMaps(statement.getResultMaps()).fetchSize(statement.getFetchSize()) + .timeout(statement.getTimeout()).statementType(statement.getStatementType()) + .resultSetType(statement.getResultSetType()).cache(statement.getCache()) + .flushCacheRequired(statement.isFlushCacheRequired()).useCache(statement.isUseCache()) + .resultOrdered(statement.isResultOrdered()).keyGenerator(statement.getKeyGenerator()) + .databaseId(statement.getDatabaseId()).lang(statement.getLang()).dirtySelect(statement.isDirtySelect()); + + propertyMapper.from(statement.getKeyProperties()).as((value)->StringUtils.join(value, ',')) + .to(builder::keyProperty); + propertyMapper.from(statement.getKeyColumns()).as((value)->StringUtils.join(value, ',')).to(builder::keyColumn); + propertyMapper.from(statement.getResultSets()).as((value)->StringUtils.join(value, ',')) + .to(builder::resultSets); + + return builder.build(); + } + private static BoundSql createPaginationBoundSql(final Dialect dialect, final MappedStatement statement, final BoundSql originalBoundSql, final RowBounds rowBounds) { final String sql = dialect.buildPaginationSql(originalBoundSql.getSql(), rowBounds.getOffset(), diff --git a/buession-dao/src/main/java/org/apache/ibatis/BoundSqlSqlSource.java b/buession-dao/src/main/java/org/apache/ibatis/BoundSqlSqlSource.java new file mode 100644 index 000000000..b8f33f50b --- /dev/null +++ b/buession-dao/src/main/java/org/apache/ibatis/BoundSqlSqlSource.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2023 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package org.apache.ibatis; + +import org.apache.ibatis.mapping.BoundSql; +import org.apache.ibatis.mapping.SqlSource; + +/** + * @author Yong.Teng + * @since 2.3.2 + */ +public class BoundSqlSqlSource implements SqlSource { + + BoundSql boundSql; + + public BoundSqlSqlSource(BoundSql boundSql) { + this.boundSql = boundSql; + } + + @Override + public BoundSql getBoundSql(Object parameterObject) { + return boundSql; + } + +} diff --git a/buession-geoip/pom.xml b/buession-geoip/pom.xml index db1ef5e21..967596528 100644 --- a/buession-geoip/pom.xml +++ b/buession-geoip/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.1 + 2.3.2 buession-geoip http://www.buession.com/ diff --git a/buession-geoip/src/main/java/com/buession/geoip/converter/AbstractConverter.java b/buession-geoip/src/main/java/com/buession/geoip/converter/AbstractConverter.java index 25233f81e..cb0904abf 100644 --- a/buession-geoip/src/main/java/com/buession/geoip/converter/AbstractConverter.java +++ b/buession-geoip/src/main/java/com/buession/geoip/converter/AbstractConverter.java @@ -21,7 +21,7 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2023 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.geoip.converter; @@ -48,7 +48,7 @@ public abstract class AbstractConverter implements Converter { - protected static String getName(final Map names, Locale locale){ + protected static String getName(final Map names, Locale locale) { if(Validate.isEmpty(names)){ return null; } @@ -72,14 +72,11 @@ protected static String getName(final Map names, Locale locale){ return result; } - private static String getLanguageTag(final Locale locale, final char separator){ + private static String getLanguageTag(final Locale locale, final char separator) { final String language = locale.getLanguage(); final String country = locale.getCountry(); - final StringBuilder sb = new StringBuilder(language.length() + country.length() + 1); - sb.append(language).append(separator).append(country); - - return sb.toString(); + return language + separator + country; } } diff --git a/buession-geoip/src/main/java/com/buession/geoip/spring/GeoIPResolverFactoryBean.java b/buession-geoip/src/main/java/com/buession/geoip/spring/GeoIPResolverFactoryBean.java index dd73f913b..296772000 100644 --- a/buession-geoip/src/main/java/com/buession/geoip/spring/GeoIPResolverFactoryBean.java +++ b/buession-geoip/src/main/java/com/buession/geoip/spring/GeoIPResolverFactoryBean.java @@ -46,23 +46,25 @@ public class GeoIPResolverFactoryBean extends GeoIPResolverFactory implements Fa private DatabaseResolver resolver; @Override - public DatabaseResolver getObject() throws Exception{ + public DatabaseResolver getObject() throws Exception { return resolver; } @Override - public Class getObjectType(){ + public Class getObjectType() { return DatabaseResolver.class; } @Override - public void afterPropertiesSet() throws Exception{ - resolver = isEnableCache() ? new CacheDatabaseResolver(getStream(), getAsnStream()) : new DatabaseResolver( - getStream(), getAsnStream()); + public void afterPropertiesSet() throws Exception { + if(resolver == null){ + resolver = isEnableCache() ? new CacheDatabaseResolver(getStream(), + getAsnStream()) : new DatabaseResolver(getStream(), getAsnStream()); + } } @Override - public void close() throws IOException{ + public void close() throws IOException { resolver.close(); } diff --git a/buession-git/pom.xml b/buession-git/pom.xml index 61297b7ed..1f4ac606c 100644 --- a/buession-git/pom.xml +++ b/buession-git/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.1 + 2.3.2 buession-git http://www.buession.com/ diff --git a/buession-git/src/main/java/com/buession/git/GitInfoBuilder.java b/buession-git/src/main/java/com/buession/git/GitInfoBuilder.java index ab6e8c50d..8b74e207b 100644 --- a/buession-git/src/main/java/com/buession/git/GitInfoBuilder.java +++ b/buession-git/src/main/java/com/buession/git/GitInfoBuilder.java @@ -43,19 +43,19 @@ class GitInfoBuilder { private int i = 0; - private GitInfoBuilder(final String group){ + private GitInfoBuilder(final String group) { this.group = group; } - public static GitInfoBuilder getInstance(){ + public static GitInfoBuilder getInstance() { return getInstance(null); } - public static GitInfoBuilder getInstance(final String group){ + public static GitInfoBuilder getInstance(final String group) { return new GitInfoBuilder(group); } - public GitInfoBuilder append(final String name, final String value){ + public GitInfoBuilder append(final String name, final String value) { ensure(); ensurePrefix(); @@ -72,7 +72,7 @@ public GitInfoBuilder append(final String name, final String value){ return this; } - public GitInfoBuilder append(final String name, final Integer value){ + public GitInfoBuilder append(final String name, final Integer value) { ensure(); ensurePrefix(); @@ -87,7 +87,7 @@ public GitInfoBuilder append(final String name, final Integer value){ return this; } - public GitInfoBuilder append(final String name, final Boolean value){ + public GitInfoBuilder append(final String name, final Boolean value) { ensure(); ensurePrefix(); @@ -102,7 +102,7 @@ public GitInfoBuilder append(final String name, final Boolean value){ return this; } - public GitInfoBuilder append(final String name, final Set value){ + public GitInfoBuilder append(final String name, final Set value) { if(value != null){ ensure(); ensurePrefix(); @@ -113,9 +113,7 @@ public GitInfoBuilder append(final String name, final Set value){ endDotReplaceToEqualsSign(); } - if(value == null){ - sb.append(Constants.EMPTY_STRING); - }else{ + if(value != null){ sb.append(String.join(",", value)); } } @@ -123,7 +121,7 @@ public GitInfoBuilder append(final String name, final Set value){ return this; } - public GitInfoBuilder append(final String name, final ZonedDateTime value){ + public GitInfoBuilder append(final String name, final ZonedDateTime value) { ensure(); ensurePrefix(); @@ -138,11 +136,11 @@ public GitInfoBuilder append(final String name, final ZonedDateTime value){ return this; } - public GitInfoBuilder append(final String name, final Info value){ + public GitInfoBuilder append(final String name, final Info value) { return append(name, value, false); } - public GitInfoBuilder append(final String name, final Info value, final boolean containName){ + public GitInfoBuilder append(final String name, final Info value, final boolean containName) { if(value != null){ ensure(); @@ -156,24 +154,24 @@ public GitInfoBuilder append(final String name, final Info value, final boolean return this; } - public String build(){ + public String build() { return sb.toString(); } - private void ensurePrefix(){ + private void ensurePrefix() { sb.append(PREFIX).append('.'); if(group != null){ sb.append(group).append('.'); } } - private void ensure(){ + private void ensure() { if(i++ > 0){ sb.append(System.lineSeparator()); } } - private void endDotReplaceToEqualsSign(){ + private void endDotReplaceToEqualsSign() { sb.setCharAt(sb.length() - 1, '='); } diff --git a/buession-git/src/main/java/com/buession/git/parser/AbstractGitParser.java b/buession-git/src/main/java/com/buession/git/parser/AbstractGitParser.java index d3def3f20..1955152b8 100644 --- a/buession-git/src/main/java/com/buession/git/parser/AbstractGitParser.java +++ b/buession-git/src/main/java/com/buession/git/parser/AbstractGitParser.java @@ -45,7 +45,7 @@ public abstract class AbstractGitParser implements GitParser { /** * 构造函数 */ - public AbstractGitParser(){ + public AbstractGitParser() { } @@ -55,7 +55,7 @@ public AbstractGitParser(){ * @param resource * 文件资源 */ - public AbstractGitParser(final Resource resource){ + public AbstractGitParser(final Resource resource) { Assert.isNull(resource, "Git properties resource cloud not be null."); this.resource = resource; } @@ -66,16 +66,21 @@ public AbstractGitParser(final Resource resource){ * @param path * Git 信息文件路径 */ - public AbstractGitParser(final String path){ + public AbstractGitParser(final String path) { Assert.isBlank(path, "Git properties path cloud not be empty or null."); this.resource = new ClassPathResource(path); } @Nullable @Override - public Git parse(){ - final Git git = new Git(); + public Git parse() { final Properties properties = loadData(); + + if(properties == null){ + return null; + } + + final Git git = new Git(); final GitInfoParser infoParser = new GitInfoParser(properties); git.setBranch(properties.getProperty("git.branch")); diff --git a/buession-httpclient/pom.xml b/buession-httpclient/pom.xml index 34732bd83..fa68d8a7e 100644 --- a/buession-httpclient/pom.xml +++ b/buession-httpclient/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.1 + 2.3.2 buession-httpclient http://www.buession.com/ diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/AbstractBaseHttpClient.java b/buession-httpclient/src/main/java/com/buession/httpclient/AbstractBaseHttpClient.java index d69ed1cb0..0fdf1fe38 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/AbstractBaseHttpClient.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/AbstractBaseHttpClient.java @@ -27,9 +27,7 @@ import com.buession.core.utils.Assert; import com.buession.httpclient.conn.ConnectionManager; import com.buession.httpclient.core.ProtocolVersion; -import com.buession.httpclient.exception.RequestException; -import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; @@ -87,34 +85,4 @@ protected static URI URL2URI(final URL url) throws URISyntaxException { return url.toURI(); } - protected static T execute(Execute execute) throws IOException, RequestException { - try{ - return execute.exec(); - }catch(URISyntaxException e){ - throw new IllegalArgumentException(e.getMessage(), e); - } - } - - protected static void asyncExecute(AsyncExecute execute) throws IOException, RequestException { - try{ - execute.exec(); - }catch(URISyntaxException e){ - throw new IllegalArgumentException(e.getMessage(), e); - } - } - - @FunctionalInterface - protected interface Execute { - - T exec() throws URISyntaxException, IOException, RequestException; - - } - - @FunctionalInterface - protected interface AsyncExecute { - - void exec() throws URISyntaxException, IOException, RequestException; - - } - } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/AbstractHttpAsyncClient.java b/buession-httpclient/src/main/java/com/buession/httpclient/AbstractHttpAsyncClient.java index 407a258d3..78b47c0e1 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/AbstractHttpAsyncClient.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/AbstractHttpAsyncClient.java @@ -34,6 +34,7 @@ import java.io.IOException; import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.util.List; import java.util.Map; @@ -49,7 +50,7 @@ public abstract class AbstractHttpAsyncClient extends AbstractBaseHttpClient imp /** * 构造函数 */ - public AbstractHttpAsyncClient(){ + public AbstractHttpAsyncClient() { super(); } @@ -59,2171 +60,2179 @@ public AbstractHttpAsyncClient(){ * @param connectionManager * 连接管理器 */ - public AbstractHttpAsyncClient(ConnectionManager connectionManager){ + public AbstractHttpAsyncClient(ConnectionManager connectionManager) { super(connectionManager); } @Override - public void get(URI uri, Callback callback) throws IOException, RequestException{ + public void get(URI uri, Callback callback) throws IOException, RequestException { get(uri, null, null, callback); } @Override - public void get(URL url, Callback callback) throws IOException, RequestException{ + public void get(URL url, Callback callback) throws IOException, RequestException { asyncExecute(()->get(URL2URI(url), null, null, callback)); } @Override - public void get(URI uri, Map parameters, Callback callback) throws IOException, RequestException{ + public void get(URI uri, Map parameters, Callback callback) throws IOException, RequestException { get(uri, parameters, null, callback); } @Override - public void get(URL url, Map parameters, Callback callback) throws IOException, RequestException{ + public void get(URL url, Map parameters, Callback callback) throws IOException, RequestException { asyncExecute(()->get(URL2URI(url), parameters, null, callback)); } @Override - public void get(URI uri, List