mirror of
https://github.com/dromara/tianai-captcha.git
synced 2026-05-07 06:04:34 +08:00
U 修复 ClassPathResourceProvider 读到资源为空的情况处理
This commit is contained in:
@@ -104,7 +104,7 @@
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
<goal>jar-no-fork</goal>6
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
|
||||
+6
-1
@@ -70,7 +70,12 @@ public class DefaultSliderCaptchaResourceManager implements SliderCaptchaResourc
|
||||
public InputStream getResourceInputStream(Resource resource) {
|
||||
for (ResourceProvider resourceProvider : resourceProviderList) {
|
||||
if (resourceProvider.supported(resource.getType())) {
|
||||
return resourceProvider.getResourceInputStream(resource);
|
||||
InputStream resourceInputStream = resourceProvider.getResourceInputStream(resource);
|
||||
if (resourceInputStream == null) {
|
||||
throw new IllegalArgumentException("滑块验证码 ResourceProvider 读到的图片资源为空,providerName=["
|
||||
+ resourceProvider.getName() + "], resource=[" + resource + "]");
|
||||
}
|
||||
return resourceInputStream;
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("没有找到Resource [" + resource.getType() + "]对应的资源提供者");
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package cloud.tianai.captcha.template.slider.provider;
|
||||
|
||||
import cloud.tianai.captcha.template.slider.Resource;
|
||||
import cloud.tianai.captcha.template.slider.ResourceProvider;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @Author: 天爱有情
|
||||
* @date 2021/12/16 16:52
|
||||
* @Description 抽象的ResourceProvider
|
||||
*/
|
||||
public abstract class AbstractResourceProvider implements ResourceProvider{
|
||||
@Override
|
||||
public InputStream getResourceInputStream(Resource data) {
|
||||
InputStream resourceInputStream = doGetResourceInputStream(data);
|
||||
if (resourceInputStream == null) {
|
||||
throw new IllegalArgumentException("滑块验证码无法读到指定的资源[" + getName() + "]" + data);
|
||||
}
|
||||
return resourceInputStream;
|
||||
}
|
||||
|
||||
public abstract InputStream doGetResourceInputStream(Resource data);
|
||||
}
|
||||
+2
-3
@@ -1,7 +1,6 @@
|
||||
package cloud.tianai.captcha.template.slider.provider;
|
||||
|
||||
import cloud.tianai.captcha.template.slider.Resource;
|
||||
import cloud.tianai.captcha.template.slider.ResourceProvider;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
@@ -10,12 +9,12 @@ import java.io.InputStream;
|
||||
* @date 2021/8/7 16:07
|
||||
* @Description classPath
|
||||
*/
|
||||
public class ClassPathResourceProvider implements ResourceProvider {
|
||||
public class ClassPathResourceProvider extends AbstractResourceProvider {
|
||||
|
||||
public static final String NAME = "classpath";
|
||||
|
||||
@Override
|
||||
public InputStream getResourceInputStream(Resource data) {
|
||||
public InputStream doGetResourceInputStream(Resource data) {
|
||||
return getClassLoader().getResourceAsStream(data.getData());
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -12,13 +12,13 @@ import java.net.URL;
|
||||
* @date 2021/8/7 16:05
|
||||
* @Description url
|
||||
*/
|
||||
public class URLResourceProvider implements ResourceProvider {
|
||||
public class URLResourceProvider implements AbstractResourceProvider {
|
||||
|
||||
public static final String NAME = "URL";
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public InputStream getResourceInputStream(Resource data) {
|
||||
public InputStream doGetResourceInputStream(Resource data) {
|
||||
URL url = new URL(data.getData());
|
||||
return url.openStream();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user