Biz新建的模块中,获取oss配置域名及空间名

Blade 未结 1 1640
yangqi
yangqi 剑童 2020-02-28 12:50

一、该问题的重现步骤是什么?

1. Biz中新建了一个模块,通过maven依赖了本地的blade-resource.jar包。

2. 在controller中注入OssBuilder,通过getOss获取oss对象。

3.如果从来没有上传过文件,则通过getOss方法获取的oss对象为空;如果上传过一个文件后,即可通过OssBuilder中的getOss方法获取Oss对象。


二、你期待的结果是什么?实际看到的又是什么?

        因为担心将来更改对象存储的服务地址,所以打算在数据中保存文件路径,使用相对路径,获取文件时,通过读取oss配置的地址,来返回全路径。

        目前直接引入resourde模块jar包,注入OssBuilder,通过getOss方法来获取oss对象,从而获取oss配置的服务地址及空间名。但是在获取oss对象过程中发现,如果从来没有通过resource服务上传过文件,则通过getOss方法获取的oss对象为空;如果上传过一个文件后,即可通过OssBuilder中的getOss方法获取Oss对象,不知什么原因。

        另外想问下有什么更好的办法,获取oss配置的url及空间名?


三、你正在使用的是什么产品,什么版本?在什么操作系统上?

bladex-2.3.1 on windows server 2016


四、请提供详细的错误堆栈信息,这很重要。

org.springframework.jdbc.UncategorizedSQLException:
### Error querying database.  Cause: java.sql.SQLException: sql injection violation, part alway true condition not allow : SELECT id, category, endpoint, access_key, secret_key, bucket_name, app_id, region, remark, tenant_id, create_user, create_dept, create_time, update_user, update_time, status, is_deleted FROM blade_oss WHERE is_deleted = 0 AND (status = ? AND tenant_id = ?) AND '1' = '1'
### The error may exist in org/springblade/resource/mapper/OssMapper.java (best guess)
### The error may involve org.springblade.resource.mapper.OssMapper.selectOne
### The error occurred while executing a query
### SQL: SELECT id, category, endpoint, access_key, secret_key, bucket_name, app_id, region, remark, tenant_id, create_user, create_dept, create_time, update_user, update_time, status, is_deleted FROM blade_oss WHERE is_deleted = 0 AND (status = ? AND tenant_id = ?) AND '1' = '1'
### Cause: java.sql.SQLException: sql injection violation, part alway true condition not allow : SELECT id, category, endpoint, access_key, secret_key, bucket_name, app_id, region, remark, tenant_id, create_user, create_dept, create_time, update_user, update_time, status, is_deleted FROM blade_oss WHERE is_deleted = 0 AND (status = ? AND tenant_id = ?) AND '1' = '1'
; uncategorized SQLException; SQL state [null]; error code [0]; sql injection violation, part alway true condition not allow : SELECT id, category, endpoint, access_key, secret_key, bucket_name, app_id, region, remark, tenant_id, create_user, create_dept, create_time, update_user, update_time, status, is_deleted FROM blade_oss WHERE is_deleted = 0 AND (status = ? AND tenant_id = ?) AND '1' = '1'; nested exception is java.sql.SQLException: sql injection violation, part alway true condition not allow : SELECT id, category, endpoint, access_key, secret_key, bucket_name, app_id, region, remark, tenant_id, create_user, create_dept, create_time, update_user, update_time, status, is_deleted FROM blade_oss WHERE is_deleted = 0 AND (status = ? AND tenant_id = ?) AND '1' = '1'
 at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:89)
 at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
 at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
 at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:88)
 at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440)
 at com.sun.proxy.$Proxy164.selectOne(Unknown Source)
 at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:159)
 at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:108)
 at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:96)
 at com.sun.proxy.$Proxy165.selectOne(Unknown Source)
 at org.springblade.resource.builder.OssBuilder.lambda$getOss$0(OssBuilder.java:111)
 at org.springblade.core.cache.utils.CacheUtil.get(CacheUtil.java:110)
 at org.springblade.resource.builder.OssBuilder.getOss(OssBuilder.java:110)
 at org.hg.news.wrapper.NewsWrapper.updateNews(NewsWrapper.java:76)
 at org.hg.news.wrapper.NewsWrapper.entityVO(NewsWrapper.java:71)
 at org.hg.news.wrapper.NewsWrapper.entityVO(NewsWrapper.java:38)
 at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
 at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
 at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
 at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
 at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
 at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
 at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
 at org.springblade.core.mp.support.BaseEntityWrapper.listVO(BaseEntityWrapper.java:45)
 at org.springblade.core.mp.support.BaseEntityWrapper.pageVO(BaseEntityWrapper.java:54)
 at org.hg.news.controller.NewsController.list(NewsController.java:88)
 at org.hg.news.controller.NewsController$$FastClassBySpringCGLIB$$4fd5fe6b.invoke()
 at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
 at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:750)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
 at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:88)
 at org.springblade.core.log.aspect.RequestLogAspect.aroundApi(RequestLogAspect.java:110)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644)
 at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633)
 at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
 at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
 at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689)
 at org.hg.news.controller.NewsController$$EnhancerBySpringCGLIB$$8e35a575.list()
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
 at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
 at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:893)
 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:798)
 at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
 at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
 at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
 at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:645)
 at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:750)
 at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
 at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
 at com.github.xiaoymin.knife4j.spring.filter.ProductionSecurityFilter.doFilter(ProductionSecurityFilter.java:53)
 at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
 at com.github.xiaoymin.knife4j.spring.filter.SecurityBasicAuthFilter.doFilter(SecurityBasicAuthFilter.java:90)
 at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
 at org.springblade.core.tool.support.xss.XssFilter.doFilter(XssFilter.java:49)
 at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
 at org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:88)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
 at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
 at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
 at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
 at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
 at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
 at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:94)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
 at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
 at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:114)
 at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:104)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
 at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
 at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
 at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
 at com.alibaba.csp.sentinel.adapter.servlet.CommonFilter.doFilter(CommonFilter.java:110)
 at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
 at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
 at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
 at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
 at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
 at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
 at io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68)
 at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132)
 at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
 at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
 at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
 at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
 at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
 at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
 at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
 at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
 at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
 at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:269)
 at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:78)
 at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:133)
 at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:130)
 at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
 at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
 at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:249)
 at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:78)
 at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:99)
 at io.undertow.server.Connectors.executeRootHandler(Connectors.java:376)
 at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
 at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLException: sql injection violation, part alway true condition not allow : SELECT id, category, endpoint, access_key, secret_key, bucket_name, app_id, region, remark, tenant_id, create_user, create_dept, create_time, update_user, update_time, status, is_deleted FROM blade_oss WHERE is_deleted = 0 AND (status = ? AND tenant_id = ?) AND '1' = '1'
 at com.alibaba.druid.wall.WallFilter.checkInternal(WallFilter.java:808)
 at com.alibaba.druid.wall.WallFilter.connection_prepareStatement(WallFilter.java:259)
 at com.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:568)
 at com.alibaba.druid.filter.FilterAdapter.connection_prepareStatement(FilterAdapter.java:930)
 at com.alibaba.druid.filter.FilterEventAdapter.connection_prepareStatement(FilterEventAdapter.java:122)
 at com.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:568)
 at com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl.prepareStatement(ConnectionProxyImpl.java:341)
 at com.alibaba.druid.pool.DruidPooledConnection.prepareStatement(DruidPooledConnection.java:350)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at org.apache.ibatis.logging.jdbc.ConnectionLogger.invoke(ConnectionLogger.java:55)
 at com.sun.proxy.$Proxy233.prepareStatement(Unknown Source)
 at org.apache.ibatis.executor.statement.PreparedStatementHandler.instantiateStatement(PreparedStatementHandler.java:86)
 at org.apache.ibatis.executor.statement.BaseStatementHandler.prepare(BaseStatementHandler.java:88)
 at org.apache.ibatis.executor.statement.RoutingStatementHandler.prepare(RoutingStatementHandler.java:59)
 at sun.reflect.GeneratedMethodAccessor156.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49)
 at com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor.intercept(PaginationInterceptor.java:205)
 at org.springblade.core.mp.plugins.BladePaginationInterceptor.intercept(BladePaginationInterceptor.java:49)
 at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)
 at com.sun.proxy.$Proxy232.prepare(Unknown Source)
 at sun.reflect.GeneratedMethodAccessor156.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63)
 at com.sun.proxy.$Proxy232.prepare(Unknown Source)
 at com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor.prepareStatement(MybatisSimpleExecutor.java:92)
 at com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor.doQuery(MybatisSimpleExecutor.java:66)
 at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)
 at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
 at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:136)
 at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)
 at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
 at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:76)
 at sun.reflect.GeneratedMethodAccessor175.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426)
 ... 124 more


五、若有更多详细信息,请在下面提供。

1582865400(1).png


1条回答
  • resource是独立的一个服务,不要依赖他

    你在后台新增了配置后,前端直接调用resource开放的接口上传就行了。

    否则每个服务都要引入很多oss的包,会显得非常冗余

    具体可以看手册

    image.png

    作者追问:2020-02-28 16:24

    如果我想在Biz后端服务中,获取到对象存储的服务地址及空间名称,怎么获取呢?

    0 讨论(1)
提交回复