在互联网上搜索嵌入式Java AWS S3模拟的良好解决方案后,似乎S3Ninja和S3Proxy似乎是最受欢迎的解决方案。
然而,似乎没有一种简单的方法可以通过编程方式解决这些问题。在放弃使用S3Ninja之后,我尝试使用S3Proxy,但它并没有完全正常工作。
Maven依赖
<dependency>
<groupId>org.gaul</groupId>
<artifactId>s3proxy</artifactId>
<version>${s3proxy.version}</version>
<scope>test</scope>
</dependency>
代码
String endpoint = "http://127.0.0.1:8085";
URI uri = URI.create(endpoint);
Properties properties = new Properties();
properties.setProperty("s3proxy.authorization", "none");
properties.setProperty("s3proxy.endpoint", endpoint);
properties.setProperty("jclouds.provider", "filesystem");
properties.setProperty("jclouds.filesystem.basedir", "/tmp/s3proxy");
ContextBuilder builder = ContextBuilder
.newBuilder("filesystem")
.credentials("x", "x")
.modules(ImmutableList.<Module>of(new SLF4JLoggingModule()))
.overrides(properties);
BlobStoreContext context = builder.build(BlobStoreContext.class);
BlobStore blobStore = context.getBlobStore();
S3Proxy s3Proxy = S3Proxy.builder().awsAuthentication("x", "x").endpoint(uri).keyStore("", "").blobStore(blobStore).build();
s3Proxy.start();
BasicAWSCredentials awsCredentials = new BasicAWSCredentials("x", "x");
AmazonS3Client client = new AmazonS3Client(awsCredentials, new ClientConfiguration());
client.setEndpoint(endpoint);
// Should Throw AWS Client Exception as Bucket / Key does not exist!
GetObjectRequest objectRequest = new GetObjectRequest("bucket", "key");
S3Object object = client.getObject(objectRequest);
s3Proxy.stop();
异常
java.lang.NoSuchMethodError: com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.<init>(Lcom/google/gson/internal/ConstructorConstructor;Lcom/google/gson/FieldNamingStrategy;Lcom/google/gson/internal/Excluder;)V
at org.jclouds.json.internal.DeserializationConstructorAndReflectiveTypeAdapterFactory.<init>(DeserializationConstructorAndReflectiveTypeAdapterFactory.java:116)
at org.jclouds.json.config.GsonModule.provideGson(GsonModule.java:129)
...
at org.jclouds.providers.config.BindProviderMetadataContextAndCredentials.backend(BindProviderMetadataContextAndCredentials.java:84)
...
at org.jclouds.ContextBuilder.build(ContextBuilder.java:581)
真的很感激任何帮助。我确信这是与AWS S3交互的许多Java集成测试的一个重要要求。
答案 0 :(得分:1)
只是为了评论原因是因为您的项目使用了冲突版本的gson。 S3Proxy的dep需要gson 2.5。
答案 1 :(得分:0)
也许你给 Simple feature collection with 4552 features and 2 fields (with 112 geometries empty)
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -71.43177 ymin: 41.77241 xmax: -71.36969 ymax: 41.82055
Geodetic CRS: NAD83
# A tibble: 4,552 x 3
geometry race population
<MULTIPOLYGON [°]> <chr> <int>
1 (((-71.3975 41.80041, -71.39571 41.80164, -71.39563 41.80158, -71.39547 41.80169, -7... hisp 0
2 (((-71.3975 41.80041, -71.39571 41.80164, -71.39563 41.80158, -71.39547 41.80169, -7... white 0
3 (((-71.3975 41.80041, -71.39571 41.80164, -71.39563 41.80158, -71.39547 41.80169, -7... black 0
4 (((-71.3975 41.80041, -71.39571 41.80164, -71.39563 41.80158, -71.39547 41.80169, -7... aian 0
5 (((-71.3975 41.80041, -71.39571 41.80164, -71.39563 41.80158, -71.39547 41.80169, -7... asian 0
6 (((-71.3975 41.80041, -71.39571 41.80164, -71.39563 41.80158, -71.39547 41.80169, -7... nhpi 0
7 (((-71.3975 41.80041, -71.39571 41.80164, -71.39563 41.80158, -71.39547 41.80169, -7... other 0
8 (((-71.3975 41.80041, -71.39571 41.80164, -71.39563 41.80158, -71.39547 41.80169, -7... two 0
9 (((-71.39929 41.79935, -71.39922 41.79938, -71.39915 41.79941, -71.39895 41.79949, -... hisp 0
10 (((-71.39929 41.79935, -71.39922 41.79938, -71.39915 41.79941, -71.39895 41.79949, -... white 0
# … with 4,542 more rows
一个机会。
看看我的github reference。
核心基于 ladon-S3-server
,并且只有很少的 servlet
。