如何解决ErrorCode: SecondLevelDomainForbidden ErrorMessage: Please use virtual hosted style to access.

最新推荐文章于 2023-05-22 00:00:00 发布
最新推荐文章于 2023-05-22 00:00:00 发布 阅读量1.7k

报错日志:

com.baiwang.ofs.exception.OFSException: S3上传文件: ng-bop-datart/datart/download/发票录入处理状态图表仪表盘_2023-03-21_13-40-11-101_256.xlsx 失败,ErrorCode: SecondLevelDomainForbidden ErrorMessage: Please use virtual hosted style to access., RequestId: 6419433CC1D7133434172FC1
    at com.baiwang.ofs.client.AmazonS3WrapClient.doPutObject(AmazonS3WrapClient.java:53)
    at com.baiwang.ofs.client.OFSBaseClient.putObject(OFSBaseClient.java:53)
    at datart.server.service.impl.AttachmentExcelServiceImpl.uploadFile(AttachmentExcelServiceImpl.java:86)
    at datart.server.service.impl.AttachmentExcelServiceImpl.getZlFile(AttachmentExcelServiceImpl.java:121)
    at datart.server.service.impl.DownloadServiceImpl.lambda$submitZlDownloadTask$1(DownloadServiceImpl.java:218)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: com.amazonaws.services.s3.model.AmazonS3Exception: Please use virtual hosted style to access. (Service: Amazon S3; Status Code: 403; Error Code: SecondLevelDomainForbidden; Request ID: 6419433CC1D7133434172FC1), S3 Extended Request ID: oss-cn-beijing-internal.aliyuncs.com
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1588)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1258)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1030)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:742)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:716)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:699)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:667)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:649)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:513)
    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4169)
    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4116)
    at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1700)
    at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1563)
    at com.baiwang.ofs.client.AmazonS3WrapClient.doPutObject(AmazonS3WrapClient.java:50)

原配置信息:

definitions: ofsPrivateClient: clientName: ofsPrivateClient type: amazonS3 properties: endpoint: https://oss-cn-beijing-internal.aliyuncs.com bucketName: ng objectKeyPrefix: ng-bop-datart accessKeyId: 123 accessKeySecret: 123 accessUrlPattern: ${ofs.definitions.ofsPrivateClient.properties.endpoint}/${ofs.definitions.ofsPrivateClient.properties.bucketName}/${ofs.definitions.ofsPrivateClient.properties.objectKeyPrefix}/{ {objectKey}} connectionTimeout: 50000 socketTimeout: 150000 pathStyleAccessEnabled: true

解决思路:

根据具体报错日志,定位到ofs文件上传报错,使用的是amazonS3上传到oss(ali)文件服务器,"Please use virtual hosted style to access.",报错信息提示的是需要用虚拟主机方式访问,因为这是产线环境,原来测试环境使用的是minio文件服务器,所以配置的pathStyleAccessEnabled为true,指的是路径方式访问,如path style: oss-cn-shenzhen.aliyuncs.com:/mybucket/myfile,但产线阿里的oss支持的是虚拟主机方式,如virtual hosted style: mybucket.oss-cn-shenzhen.aliyuncs.com/myfile,所以直接将测试环境的配置搬到产线就是会出问题的,需要将 pathStyleAccessEnabled改为false ,验证通过。看过AmazonS3Client的源码,其实不配此参数也行的,因为默认为false。

如何解决ErrorCode: SecondLevelDomainForbidden ErrorMessage: Please use virtual hosted style to access. 看过AmazonS3Client的源码,其实不配此参数也行的,因为默认为false。pathStyleAccessEnabled改为false。 public static class AWS_ S3 Client Info private static readonly string aws Access Key = "AKIAJOXFZDXXXXX"; private static readonly string awsS... [2020-08-20 10:29:57.772] [http-nio-8888-exec-10] ERROR [JsonExceptionHandler. java :186] - Unhandl ed exception: org.springframework.web.util.Nest ed ServletException: Handler dispatch fail ed ; nest ed exception is java .lang.NoSuchMethod Error : org.ap
ImageIO.read(File file)报异常"Unsupport ed ImageType",是因为其内部读取文件的类JPEGImageReader只能读取RGB color model,而你的图片可能被ps过,colormodel是CMYK。 如果你坚持要读取CMYK图片,你需要转换图片,使用一下代码。 Buffer ed Image buffer ed I
This error message usually means that the dependency "com.github.CymChad:BaseRecyclerViewAdapterHelper:v2.9.34" could not be found in the repository where your project is looking for it. To solve this issue, you can try the following steps: 1. Make sure that you have add ed the correct repository where this dependency is locat ed in your project's build.gradle file. For example, if this dependency is host ed on JCenter, add the following line to your build.gradle file: repositories { jcenter() 2. Check if your internet connection is working properly and try syncing your project with the repositories again. 3. If the above steps do not work, try changing the version of the dependency to a more recent one or to a different one that is available in the repositories. You can search for available versions on a repository website or by using a search engine. 4. If all else fails, you can try manually downloading the dependency and adding it to your project's "libs" folder. However, this is not recommend ed as it can ca use conflicts and make your project harder to maintain.
NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError 21786