mirror of https://github.com/apache/jclouds.git
Issue 18: implemented GetBucket options
git-svn-id: http://jclouds.googlecode.com/svn/trunk@482 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
aeba634379
commit
373f643ce8
|
@ -42,8 +42,8 @@ import com.google.common.collect.Multimap;
|
|||
*/
|
||||
public class HttpRequest {
|
||||
|
||||
String method;
|
||||
String uri;
|
||||
private final String method;
|
||||
private final String uri;
|
||||
Multimap<String, String> headers = HashMultimap.create();
|
||||
Object content;
|
||||
String contentType;
|
||||
|
@ -75,18 +75,10 @@ public class HttpRequest {
|
|||
return method;
|
||||
}
|
||||
|
||||
public void setMethod(String method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public String getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public void setUri(String uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public Multimap<String, String> getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2009 Adrian Cole <adrian@jclouds.org>
|
||||
|
||||
====================================================================
|
||||
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.
|
||||
====================================================================
|
||||
|
||||
-->
|
||||
<metadata xsi:schemaLocation="http://maven.apache.org/METADATA/1.0.0 http://maven.apache.org/xsd/metadata-1.0.0.xsd" xmlns="http://maven.apache.org/METADATA/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<groupId>org.jclouds</groupId>
|
||||
|
|
|
@ -1,4 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2009 Adrian Cole <adrian@jclouds.org>
|
||||
|
||||
====================================================================
|
||||
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.
|
||||
====================================================================
|
||||
|
||||
-->
|
||||
<metadata xsi:schemaLocation="http://maven.apache.org/METADATA/1.0.0 http://maven.apache.org/xsd/metadata-1.0.0.xsd" xmlns="http://maven.apache.org/METADATA/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<groupId>org.jclouds</groupId>
|
||||
|
|
|
@ -1,4 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2009 Adrian Cole <adrian@jclouds.org>
|
||||
|
||||
====================================================================
|
||||
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.
|
||||
====================================================================
|
||||
|
||||
-->
|
||||
<metadata xsi:schemaLocation="http://maven.apache.org/METADATA/1.0.0 http://maven.apache.org/xsd/metadata-1.0.0.xsd" xmlns="http://maven.apache.org/METADATA/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<groupId>org.jclouds</groupId>
|
||||
|
|
|
@ -1,4 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2009 Adrian Cole <adrian@jclouds.org>
|
||||
|
||||
====================================================================
|
||||
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.
|
||||
====================================================================
|
||||
|
||||
-->
|
||||
<metadata xsi:schemaLocation="http://maven.apache.org/METADATA/1.0.0 http://maven.apache.org/xsd/metadata-1.0.0.xsd" xmlns="http://maven.apache.org/METADATA/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<groupId>org.jclouds</groupId>
|
||||
|
|
|
@ -1,4 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2009 Adrian Cole <adrian@jclouds.org>
|
||||
|
||||
====================================================================
|
||||
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.
|
||||
====================================================================
|
||||
|
||||
-->
|
||||
<metadata xsi:schemaLocation="http://maven.apache.org/METADATA/1.0.0 http://maven.apache.org/xsd/metadata-1.0.0.xsd" xmlns="http://maven.apache.org/METADATA/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<groupId>org.jclouds</groupId>
|
||||
|
|
|
@ -1,4 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2009 Adrian Cole <adrian@jclouds.org>
|
||||
|
||||
====================================================================
|
||||
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.
|
||||
====================================================================
|
||||
|
||||
-->
|
||||
<metadata xsi:schemaLocation="http://maven.apache.org/METADATA/1.0.0 http://maven.apache.org/xsd/metadata-1.0.0.xsd" xmlns="http://maven.apache.org/METADATA/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<groupId>org.jclouds</groupId>
|
||||
|
|
|
@ -1,4 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2009 Adrian Cole <adrian@jclouds.org>
|
||||
|
||||
====================================================================
|
||||
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.
|
||||
====================================================================
|
||||
|
||||
-->
|
||||
<metadata xsi:schemaLocation="http://maven.apache.org/METADATA/1.0.0 http://maven.apache.org/xsd/metadata-1.0.0.xsd" xmlns="http://maven.apache.org/METADATA/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<groupId>org.jclouds</groupId>
|
||||
|
|
|
@ -1,4 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2009 Adrian Cole <adrian@jclouds.org>
|
||||
|
||||
====================================================================
|
||||
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.
|
||||
====================================================================
|
||||
|
||||
-->
|
||||
<metadata xsi:schemaLocation="http://maven.apache.org/METADATA/1.0.0 http://maven.apache.org/xsd/metadata-1.0.0.xsd" xmlns="http://maven.apache.org/METADATA/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<groupId>org.jclouds</groupId>
|
||||
|
|
|
@ -1,4 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2009 Adrian Cole <adrian@jclouds.org>
|
||||
|
||||
====================================================================
|
||||
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.
|
||||
====================================================================
|
||||
|
||||
-->
|
||||
<metadata xsi:schemaLocation="http://maven.apache.org/METADATA/1.0.0 http://maven.apache.org/xsd/metadata-1.0.0.xsd" xmlns="http://maven.apache.org/METADATA/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<groupId>org.jclouds</groupId>
|
||||
|
|
|
@ -1,4 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2009 Adrian Cole <adrian@jclouds.org>
|
||||
|
||||
====================================================================
|
||||
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.
|
||||
====================================================================
|
||||
|
||||
-->
|
||||
<metadata xsi:schemaLocation="http://maven.apache.org/METADATA/1.0.0 http://maven.apache.org/xsd/metadata-1.0.0.xsd" xmlns="http://maven.apache.org/METADATA/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<groupId>org.jclouds</groupId>
|
||||
|
|
|
@ -1,4 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2009 Adrian Cole <adrian@jclouds.org>
|
||||
|
||||
====================================================================
|
||||
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.
|
||||
====================================================================
|
||||
|
||||
-->
|
||||
<metadata xsi:schemaLocation="http://maven.apache.org/METADATA/1.0.0 http://maven.apache.org/xsd/metadata-1.0.0.xsd" xmlns="http://maven.apache.org/METADATA/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<groupId>org.jclouds</groupId>
|
||||
|
|
|
@ -1,4 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2009 Adrian Cole <adrian@jclouds.org>
|
||||
|
||||
====================================================================
|
||||
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.
|
||||
====================================================================
|
||||
|
||||
-->
|
||||
<metadata xsi:schemaLocation="http://maven.apache.org/METADATA/1.0.0 http://maven.apache.org/xsd/metadata-1.0.0.xsd" xmlns="http://maven.apache.org/METADATA/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<groupId>org.jclouds</groupId>
|
||||
|
|
|
@ -26,6 +26,7 @@ package org.jclouds.aws.s3;
|
|||
import java.util.List;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.jclouds.aws.s3.commands.options.GetBucketOptions;
|
||||
import org.jclouds.aws.s3.commands.options.PutBucketOptions;
|
||||
import org.jclouds.aws.s3.domain.S3Bucket;
|
||||
import org.jclouds.aws.s3.domain.S3Object;
|
||||
|
@ -132,5 +133,7 @@ public interface S3Connection {
|
|||
*/
|
||||
Future<S3Bucket> getBucket(String name);
|
||||
|
||||
Future<S3Bucket> getBucket(String name, GetBucketOptions options);
|
||||
|
||||
Future<List<S3Bucket.MetaData>> getMetaDataOfOwnedBuckets();
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
*/
|
||||
package org.jclouds.aws.s3.commands;
|
||||
|
||||
import org.jclouds.aws.s3.commands.options.GetBucketOptions;
|
||||
import org.jclouds.aws.s3.domain.S3Bucket;
|
||||
import org.jclouds.aws.s3.xml.ListBucketHandler;
|
||||
import org.jclouds.http.commands.callables.xml.ParseSax;
|
||||
|
@ -36,9 +37,18 @@ public class GetBucket extends S3FutureCommand<S3Bucket> {
|
|||
|
||||
@Inject
|
||||
public GetBucket(@Named("jclouds.http.address") String amazonHost,
|
||||
ParseSax<S3Bucket> callable, @Assisted String bucket) {
|
||||
super("GET", "/", callable, amazonHost, bucket);
|
||||
ListBucketHandler handler = (ListBucketHandler) callable.getHandler();
|
||||
ParseSax<S3Bucket> bucketParser, @Assisted String bucket) {
|
||||
this(amazonHost, bucketParser, bucket, new GetBucketOptions());
|
||||
}
|
||||
|
||||
@Inject
|
||||
public GetBucket(@Named("jclouds.http.address") String amazonHost,
|
||||
ParseSax<S3Bucket> bucketParser, @Assisted String bucket,
|
||||
@Assisted GetBucketOptions options) {
|
||||
super("GET", "/" + options.toQueryString(), bucketParser, amazonHost,
|
||||
bucket);
|
||||
ListBucketHandler handler = (ListBucketHandler) bucketParser
|
||||
.getHandler();
|
||||
handler.setBucketName(bucket);
|
||||
}
|
||||
}
|
|
@ -23,6 +23,7 @@
|
|||
*/
|
||||
package org.jclouds.aws.s3.commands;
|
||||
|
||||
import org.jclouds.aws.s3.commands.options.GetBucketOptions;
|
||||
import org.jclouds.aws.s3.commands.options.PutBucketOptions;
|
||||
import org.jclouds.aws.s3.domain.S3Object;
|
||||
import org.jclouds.aws.s3.xml.S3ParserFactory;
|
||||
|
@ -144,7 +145,12 @@ public class S3CommandFactory {
|
|||
return new GetBucket(amazonHost,
|
||||
parserFactory.createListBucketParser(), bucket);
|
||||
}
|
||||
|
||||
|
||||
public GetBucket createGetBucket(String bucket, GetBucketOptions options) {
|
||||
return new GetBucket(amazonHost,
|
||||
parserFactory.createListBucketParser(), bucket, options);
|
||||
}
|
||||
|
||||
public CopyObject createCopyObject(String sourceBucket,
|
||||
String sourceObject, String destinationBucket,
|
||||
String destinationObject) {
|
||||
|
@ -153,4 +159,6 @@ public class S3CommandFactory {
|
|||
destinationBucket, destinationObject);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -26,6 +26,8 @@ package org.jclouds.aws.s3.commands.options;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
@ -72,16 +74,21 @@ public class GetBucketOptions {
|
|||
builder.append("&");
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
String returnVal = builder.toString();
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limits the response to keys which begin with the indicated prefix. You
|
||||
* can use prefixes to separate a bucket into different sets of keys in a
|
||||
* way similar to how a file system uses folders.
|
||||
*
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public GetBucketOptions prefix(String prefix) {
|
||||
options.put("prefix", checkNotNull(prefix, "prefix"));
|
||||
public GetBucketOptions prefix(String prefix)
|
||||
throws UnsupportedEncodingException {
|
||||
options.put("prefix", URLEncoder.encode(checkNotNull(prefix, "prefix"),
|
||||
"UTF-8"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -97,9 +104,13 @@ public class GetBucketOptions {
|
|||
* include keys that occur lexicographically after marker. This is
|
||||
* convenient for pagination: To get the next page of results use the last
|
||||
* key of the current page as the marker.
|
||||
*
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public GetBucketOptions marker(String marker) {
|
||||
options.put("marker", checkNotNull(marker, "marker"));
|
||||
public GetBucketOptions marker(String marker)
|
||||
throws UnsupportedEncodingException {
|
||||
options.put("marker", URLEncoder.encode(checkNotNull(marker, "marker"),
|
||||
"UTF-8"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -132,9 +143,13 @@ public class GetBucketOptions {
|
|||
* occurrence of the delimiter to be rolled up into a single result element
|
||||
* in the CommonPrefixes collection. These rolled-up keys are not returned
|
||||
* elsewhere in the response.
|
||||
*
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public GetBucketOptions delimiter(String delimiter) {
|
||||
options.put("delimiter", checkNotNull(delimiter, "delimiter"));
|
||||
public GetBucketOptions delimiter(String delimiter)
|
||||
throws UnsupportedEncodingException {
|
||||
options.put("delimiter", URLEncoder.encode(checkNotNull(delimiter,
|
||||
"delimiter"), "UTF-8"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -148,17 +163,21 @@ public class GetBucketOptions {
|
|||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @throws UnsupportedEncodingException
|
||||
* @see GetBucketOptions#prefix
|
||||
*/
|
||||
public static GetBucketOptions prefix(String prefix) {
|
||||
public static GetBucketOptions prefix(String prefix)
|
||||
throws UnsupportedEncodingException {
|
||||
GetBucketOptions options = new GetBucketOptions();
|
||||
return options.prefix(prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws UnsupportedEncodingException
|
||||
* @see GetBucketOptions#marker
|
||||
*/
|
||||
public static GetBucketOptions marker(String marker) {
|
||||
public static GetBucketOptions marker(String marker)
|
||||
throws UnsupportedEncodingException {
|
||||
GetBucketOptions options = new GetBucketOptions();
|
||||
return options.marker(marker);
|
||||
}
|
||||
|
@ -172,9 +191,11 @@ public class GetBucketOptions {
|
|||
}
|
||||
|
||||
/**
|
||||
* @throws UnsupportedEncodingException
|
||||
* @see GetBucketOptions#delimiter
|
||||
*/
|
||||
public static GetBucketOptions delimiter(String delimiter) {
|
||||
public static GetBucketOptions delimiter(String delimiter)
|
||||
throws UnsupportedEncodingException {
|
||||
GetBucketOptions options = new GetBucketOptions();
|
||||
return options.delimiter(delimiter);
|
||||
}
|
||||
|
|
|
@ -32,161 +32,225 @@ import java.util.Set;
|
|||
/**
|
||||
* A container that provides namespace, access control and aggregation of
|
||||
* {@link S3Object}s
|
||||
*
|
||||
*
|
||||
* @author Adrian Cole
|
||||
* @see http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html
|
||||
*/
|
||||
public class S3Bucket {
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("S3Bucket");
|
||||
sb.append("{metaData=").append(metaData);
|
||||
sb.append(", isComplete=").append(isComplete);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("S3Bucket");
|
||||
sb.append("{metaData=").append(metaData);
|
||||
sb.append(", isComplete=").append(isComplete);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof S3Bucket)) return false;
|
||||
if (this == o)
|
||||
return true;
|
||||
if (!(o instanceof S3Bucket))
|
||||
return false;
|
||||
|
||||
S3Bucket s3Bucket = (S3Bucket) o;
|
||||
S3Bucket s3Bucket = (S3Bucket) o;
|
||||
|
||||
if (isComplete != s3Bucket.isComplete) return false;
|
||||
if (!metaData.equals(s3Bucket.metaData)) return false;
|
||||
if (objects != null ? !objects.equals(s3Bucket.objects) : s3Bucket.objects != null) return false;
|
||||
if (isComplete != s3Bucket.isComplete)
|
||||
return false;
|
||||
if (!metaData.equals(s3Bucket.metaData))
|
||||
return false;
|
||||
if (objects != null ? !objects.equals(s3Bucket.objects)
|
||||
: s3Bucket.objects != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = objects != null ? objects.hashCode() : 0;
|
||||
result = 31 * result + metaData.hashCode();
|
||||
result = 31 * result + (isComplete ? 1 : 0);
|
||||
return result;
|
||||
int result = objects != null ? objects.hashCode() : 0;
|
||||
result = 31 * result + metaData.hashCode();
|
||||
result = 31 * result + (isComplete ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static class MetaData {
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("MetaData");
|
||||
sb.append("{name='").append(name).append('\'');
|
||||
sb.append(", creationDate=").append(creationDate);
|
||||
sb.append(", canonicalUser=").append(canonicalUser);
|
||||
sb.append(", locationConstraint=").append(locationConstraint);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("MetaData");
|
||||
sb.append("{name='").append(name).append('\'');
|
||||
sb.append(", creationDate=").append(creationDate);
|
||||
sb.append(", canonicalUser=").append(canonicalUser);
|
||||
sb.append(", locationConstraint=").append(locationConstraint);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof MetaData)) return false;
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (!(o instanceof MetaData))
|
||||
return false;
|
||||
|
||||
MetaData metaData = (MetaData) o;
|
||||
MetaData metaData = (MetaData) o;
|
||||
|
||||
if (canonicalUser != null ? !canonicalUser.equals(metaData.canonicalUser) : metaData.canonicalUser != null)
|
||||
return false;
|
||||
if (creationDate != null ? !creationDate.equals(metaData.creationDate) : metaData.creationDate != null)
|
||||
return false;
|
||||
if (locationConstraint != metaData.locationConstraint) return false;
|
||||
if (!name.equals(metaData.name)) return false;
|
||||
if (canonicalUser != null ? !canonicalUser
|
||||
.equals(metaData.canonicalUser)
|
||||
: metaData.canonicalUser != null)
|
||||
return false;
|
||||
if (creationDate != null ? !creationDate
|
||||
.equals(metaData.creationDate)
|
||||
: metaData.creationDate != null)
|
||||
return false;
|
||||
if (locationConstraint != metaData.locationConstraint)
|
||||
return false;
|
||||
if (!name.equals(metaData.name))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = name.hashCode();
|
||||
result = 31 * result + (creationDate != null ? creationDate.hashCode() : 0);
|
||||
result = 31 * result + (canonicalUser != null ? canonicalUser.hashCode() : 0);
|
||||
result = 31 * result + (locationConstraint != null ? locationConstraint.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = name.hashCode();
|
||||
result = 31 * result
|
||||
+ (creationDate != null ? creationDate.hashCode() : 0);
|
||||
result = 31 * result
|
||||
+ (canonicalUser != null ? canonicalUser.hashCode() : 0);
|
||||
result = 31
|
||||
* result
|
||||
+ (locationConstraint != null ? locationConstraint
|
||||
.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static enum LocationConstraint {
|
||||
EU
|
||||
}
|
||||
public static enum LocationConstraint {
|
||||
EU
|
||||
}
|
||||
|
||||
private final String name;
|
||||
private DateTime creationDate;
|
||||
private S3Owner canonicalUser;
|
||||
private LocationConstraint locationConstraint;
|
||||
private final String name;
|
||||
private DateTime creationDate;
|
||||
private S3Owner canonicalUser;
|
||||
private LocationConstraint locationConstraint;
|
||||
|
||||
public MetaData(String name) {
|
||||
this.name = checkNotNull(name, "name").toLowerCase();
|
||||
}
|
||||
public MetaData(String name) {
|
||||
this.name = checkNotNull(name, "name").toLowerCase();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public DateTime getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
public DateTime getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
public void setCreationDate(DateTime creationDate) {
|
||||
this.creationDate = creationDate;
|
||||
}
|
||||
public void setCreationDate(DateTime creationDate) {
|
||||
this.creationDate = creationDate;
|
||||
}
|
||||
|
||||
public S3Owner getCanonicalUser() {
|
||||
return canonicalUser;
|
||||
}
|
||||
public S3Owner getCanonicalUser() {
|
||||
return canonicalUser;
|
||||
}
|
||||
|
||||
public void setCanonicalUser(S3Owner canonicalUser) {
|
||||
this.canonicalUser = canonicalUser;
|
||||
}
|
||||
public void setCanonicalUser(S3Owner canonicalUser) {
|
||||
this.canonicalUser = canonicalUser;
|
||||
}
|
||||
|
||||
public LocationConstraint getLocationConstraint() {
|
||||
return locationConstraint;
|
||||
}
|
||||
public LocationConstraint getLocationConstraint() {
|
||||
return locationConstraint;
|
||||
}
|
||||
|
||||
public void setLocationConstraint(LocationConstraint locationConstraint) {
|
||||
this.locationConstraint = locationConstraint;
|
||||
}
|
||||
public void setLocationConstraint(LocationConstraint locationConstraint) {
|
||||
this.locationConstraint = locationConstraint;
|
||||
}
|
||||
}
|
||||
|
||||
public static final S3Bucket NOT_FOUND = new S3Bucket("NOT_FOUND");
|
||||
|
||||
private Set<S3Object.MetaData> objects = new HashSet<S3Object.MetaData>();
|
||||
private Set<String> commonPrefixes = new HashSet<String>();
|
||||
private String prefix;
|
||||
private String marker;
|
||||
private String delimiter;
|
||||
private long maxKeys;
|
||||
private final MetaData metaData;
|
||||
|
||||
private boolean isComplete;
|
||||
|
||||
public S3Bucket(String name) {
|
||||
this.metaData = new MetaData(name);
|
||||
this.metaData = new MetaData(name);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.metaData.getName();
|
||||
return this.metaData.getName();
|
||||
}
|
||||
|
||||
public S3Bucket(MetaData metaData) {
|
||||
this.metaData = checkNotNull(metaData, "metaData");
|
||||
this.metaData = checkNotNull(metaData, "metaData");
|
||||
}
|
||||
|
||||
public Set<S3Object.MetaData> getContents() {
|
||||
return objects;
|
||||
return objects;
|
||||
}
|
||||
|
||||
public void setContents(Set<S3Object.MetaData> objects) {
|
||||
this.objects = objects;
|
||||
this.objects = objects;
|
||||
}
|
||||
|
||||
public boolean isComplete() {
|
||||
return isComplete;
|
||||
return isComplete;
|
||||
}
|
||||
|
||||
public void setComplete(boolean complete) {
|
||||
isComplete = complete;
|
||||
isComplete = complete;
|
||||
}
|
||||
|
||||
public MetaData getMetaData() {
|
||||
return metaData;
|
||||
return metaData;
|
||||
}
|
||||
|
||||
public void setCommonPrefixes(Set<String> commonPrefixes) {
|
||||
this.commonPrefixes = commonPrefixes;
|
||||
}
|
||||
|
||||
public Set<String> getCommonPrefixes() {
|
||||
return commonPrefixes;
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public void setMaxKeys(long maxKeys) {
|
||||
this.maxKeys = maxKeys;
|
||||
}
|
||||
|
||||
public long getMaxKeys() {
|
||||
return maxKeys;
|
||||
}
|
||||
|
||||
public void setMarker(String marker) {
|
||||
this.marker = marker;
|
||||
}
|
||||
|
||||
public String getMarker() {
|
||||
return marker;
|
||||
}
|
||||
|
||||
public void setDelimiter(String delimiter) {
|
||||
this.delimiter = delimiter;
|
||||
}
|
||||
|
||||
public String getDelimiter() {
|
||||
return delimiter;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,163 +23,184 @@
|
|||
*/
|
||||
package org.jclouds.aws.s3.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.*;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* // TODO: Adrian: Document this!
|
||||
*
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class S3Object {
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("S3Object");
|
||||
sb.append("{metaData=").append(metaData);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("S3Object");
|
||||
sb.append("{metaData=").append(metaData);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static final S3Object NOT_FOUND = new S3Object(MetaData.NOT_FOUND);
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof S3Object)) return false;
|
||||
if (this == o)
|
||||
return true;
|
||||
if (!(o instanceof S3Object))
|
||||
return false;
|
||||
|
||||
S3Object s3Object = (S3Object) o;
|
||||
S3Object s3Object = (S3Object) o;
|
||||
|
||||
if (data != null ? !data.equals(s3Object.data) : s3Object.data != null) return false;
|
||||
if (!metaData.equals(s3Object.metaData)) return false;
|
||||
if (data != null ? !data.equals(s3Object.data) : s3Object.data != null)
|
||||
return false;
|
||||
if (!metaData.equals(s3Object.metaData))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = data != null ? data.hashCode() : 0;
|
||||
result = 31 * result + metaData.hashCode();
|
||||
return result;
|
||||
int result = data != null ? data.hashCode() : 0;
|
||||
result = 31 * result + metaData.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static class MetaData {
|
||||
public static final MetaData NOT_FOUND = new MetaData("NOT_FOUND");
|
||||
public static final String UNKNOWN_MIME_TYPE = "application/x-unknown-mime-type";
|
||||
public static final MetaData NOT_FOUND = new MetaData("NOT_FOUND");
|
||||
public static final String UNKNOWN_MIME_TYPE = "application/x-unknown-mime-type";
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("MetaData");
|
||||
sb.append("{key='").append(key).append('\'');
|
||||
sb.append(", lastModified=").append(lastModified);
|
||||
sb.append(", md5=").append(getMd5() == null ? "null" : Arrays.asList(getMd5()).toString());
|
||||
sb.append(", size=").append(size);
|
||||
sb.append(", owner=").append(owner);
|
||||
sb.append(", contentType='").append(contentType).append('\'');
|
||||
sb.append(", storageClass='").append(storageClass).append('\'');
|
||||
sb.append(", server='").append(server).append('\'');
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("MetaData");
|
||||
sb.append("{key='").append(key).append('\'');
|
||||
sb.append(", lastModified=").append(lastModified);
|
||||
sb.append(", md5=").append(
|
||||
getMd5() == null ? "null" : Arrays.asList(getMd5())
|
||||
.toString());
|
||||
sb.append(", size=").append(size);
|
||||
sb.append(", owner=").append(owner);
|
||||
sb.append(", contentType='").append(contentType).append('\'');
|
||||
sb.append(", storageClass='").append(storageClass).append('\'');
|
||||
sb.append(", server='").append(server).append('\'');
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private final String key;
|
||||
private DateTime lastModified;
|
||||
private byte[] md5;
|
||||
private final String key;
|
||||
private DateTime lastModified;
|
||||
private byte[] md5;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof MetaData)) return false;
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (!(o instanceof MetaData))
|
||||
return false;
|
||||
|
||||
MetaData metaData = (MetaData) o;
|
||||
MetaData metaData = (MetaData) o;
|
||||
|
||||
if (size != metaData.size) return false;
|
||||
if (contentType != null ? !contentType.equals(metaData.contentType) : metaData.contentType != null)
|
||||
return false;
|
||||
if (!key.equals(metaData.key)) return false;
|
||||
if (lastModified != null ? !lastModified.equals(metaData.lastModified) : metaData.lastModified != null)
|
||||
return false;
|
||||
if (!Arrays.equals(getMd5(), metaData.getMd5())) return false;
|
||||
if (owner != null ? !owner.equals(metaData.owner) : metaData.owner != null) return false;
|
||||
if (size != metaData.size)
|
||||
return false;
|
||||
if (contentType != null ? !contentType.equals(metaData.contentType)
|
||||
: metaData.contentType != null)
|
||||
return false;
|
||||
if (!key.equals(metaData.key))
|
||||
return false;
|
||||
if (lastModified != null ? !lastModified
|
||||
.equals(metaData.lastModified)
|
||||
: metaData.lastModified != null)
|
||||
return false;
|
||||
if (!Arrays.equals(getMd5(), metaData.getMd5()))
|
||||
return false;
|
||||
if (owner != null ? !owner.equals(metaData.owner)
|
||||
: metaData.owner != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = key.hashCode();
|
||||
result = 31 * result + (lastModified != null ? lastModified.hashCode() : 0);
|
||||
result = 31 * result + (getMd5() != null ? Arrays.hashCode(getMd5()) : 0);
|
||||
result = 31 * result + (int) (size ^ (size >>> 32));
|
||||
result = 31 * result + (owner != null ? owner.hashCode() : 0);
|
||||
result = 31 * result + (contentType != null ? contentType.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = key.hashCode();
|
||||
result = 31 * result
|
||||
+ (lastModified != null ? lastModified.hashCode() : 0);
|
||||
result = 31 * result
|
||||
+ (getMd5() != null ? Arrays.hashCode(getMd5()) : 0);
|
||||
result = 31 * result + (int) (size ^ (size >>> 32));
|
||||
result = 31 * result + (owner != null ? owner.hashCode() : 0);
|
||||
result = 31 * result
|
||||
+ (contentType != null ? contentType.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
private long size = -1;
|
||||
private S3Owner owner;
|
||||
private String contentType = UNKNOWN_MIME_TYPE;
|
||||
private String storageClass = "STANDARD";
|
||||
private String server;
|
||||
private long size = -1;
|
||||
private S3Owner owner;
|
||||
private String contentType = UNKNOWN_MIME_TYPE;
|
||||
private String storageClass = "STANDARD";
|
||||
private String server;
|
||||
|
||||
public MetaData(String key) {
|
||||
this.key = checkNotNull(key, "key");
|
||||
}
|
||||
public MetaData(String key) {
|
||||
checkNotNull(key, "key");
|
||||
checkArgument(!key.startsWith("/"), "keys cannot start with /");
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public DateTime getLastModified() {
|
||||
return lastModified;
|
||||
}
|
||||
public DateTime getLastModified() {
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
public void setLastModified(DateTime lastModified) {
|
||||
this.lastModified = lastModified;
|
||||
}
|
||||
public void setLastModified(DateTime lastModified) {
|
||||
this.lastModified = lastModified;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(long size) {
|
||||
this.size = size;
|
||||
}
|
||||
public void setSize(long size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public S3Owner getOwner() {
|
||||
return owner;
|
||||
}
|
||||
public S3Owner getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public void setOwner(S3Owner owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
public void setOwner(S3Owner owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public String getStorageClass() {
|
||||
return storageClass;
|
||||
}
|
||||
public String getStorageClass() {
|
||||
return storageClass;
|
||||
}
|
||||
|
||||
public void setStorageClass(String storageClass) {
|
||||
this.storageClass = storageClass;
|
||||
}
|
||||
public void setStorageClass(String storageClass) {
|
||||
this.storageClass = storageClass;
|
||||
}
|
||||
|
||||
public String getServer() {
|
||||
return server;
|
||||
}
|
||||
public String getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
public void setServer(String server) {
|
||||
this.server = server;
|
||||
}
|
||||
public void setServer(String server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public void setMd5(byte[] md5) {
|
||||
this.md5 = md5;
|
||||
|
@ -194,36 +215,41 @@ public class S3Object {
|
|||
private MetaData metaData;
|
||||
|
||||
public S3Object(String key) {
|
||||
this(new MetaData(key));
|
||||
this(new MetaData(key));
|
||||
}
|
||||
|
||||
public S3Object(MetaData metaData) {
|
||||
this.metaData = metaData;
|
||||
this.metaData = metaData;
|
||||
}
|
||||
|
||||
public S3Object(MetaData metaData, Object data) {
|
||||
this(metaData);
|
||||
this.data = data;
|
||||
this(metaData);
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public S3Object(String key, Object data) {
|
||||
this(key);
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return metaData.getKey();
|
||||
return metaData.getKey();
|
||||
}
|
||||
|
||||
public void setData(Object data) {
|
||||
this.data = data;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public Object getData() {
|
||||
return data;
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setMetaData(MetaData metaData) {
|
||||
this.metaData = metaData;
|
||||
this.metaData = metaData;
|
||||
}
|
||||
|
||||
public MetaData getMetaData() {
|
||||
return metaData;
|
||||
return metaData;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.jclouds.aws.s3.commands.HeadMetaData;
|
|||
import org.jclouds.aws.s3.commands.PutBucket;
|
||||
import org.jclouds.aws.s3.commands.PutObject;
|
||||
import org.jclouds.aws.s3.commands.S3CommandFactory;
|
||||
import org.jclouds.aws.s3.commands.options.GetBucketOptions;
|
||||
import org.jclouds.aws.s3.commands.options.PutBucketOptions;
|
||||
import org.jclouds.aws.s3.domain.S3Bucket;
|
||||
import org.jclouds.aws.s3.domain.S3Object;
|
||||
|
@ -183,6 +184,17 @@ public class LiveS3Connection implements S3Connection {
|
|||
return getBucket;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see GetBucket
|
||||
*/
|
||||
public Future<S3Bucket> getBucket(String s3Bucket, GetBucketOptions options) {
|
||||
GetBucket getBucket = factory.createGetBucket(s3Bucket, options);
|
||||
client.submit(getBucket);
|
||||
return getBucket;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
|
@ -57,11 +57,13 @@ public class ListBucketHandler extends ParseSax.HandlerWithResult<S3Bucket> {
|
|||
private StringBuilder currentText = new StringBuilder();
|
||||
@Inject
|
||||
private DateService dateParser;
|
||||
private boolean inCommonPrefixes;
|
||||
|
||||
@Override
|
||||
public void startDocument() throws SAXException {
|
||||
checkNotNull(s3Bucket, "s3Bucket");
|
||||
s3Bucket.getContents().clear();
|
||||
s3Bucket.getCommonPrefixes().clear();
|
||||
super.startDocument();
|
||||
}
|
||||
|
||||
|
@ -70,6 +72,8 @@ public class ListBucketHandler extends ParseSax.HandlerWithResult<S3Bucket> {
|
|||
if (qName.equals("Contents")) {
|
||||
} else if (qName.equals("Owner")) {
|
||||
currentOwner = new S3Owner();
|
||||
} else if (qName.equals("CommonPrefixes")) {
|
||||
inCommonPrefixes = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,12 +102,20 @@ public class ListBucketHandler extends ParseSax.HandlerWithResult<S3Bucket> {
|
|||
} else if (qName.equals("Contents")) {
|
||||
s3Bucket.getContents().add(currentObjectMetaData);
|
||||
} else if (qName.equals("Name")) {// bucket stuff last, as least likely
|
||||
// } else if (qName.equals("Prefix")) {
|
||||
// // no-op
|
||||
// } else if (qName.equals("Marker")) {
|
||||
// // no-op
|
||||
// } else if (qName.equals("MaxKeys")) {
|
||||
// // no-op
|
||||
} else if (qName.equals("Prefix")) {
|
||||
String prefix = currentText.toString().trim();
|
||||
if (inCommonPrefixes)
|
||||
s3Bucket.getCommonPrefixes().add(prefix);
|
||||
else
|
||||
s3Bucket.setPrefix(prefix);
|
||||
} else if (qName.equals("Delimiter")) {
|
||||
if (!currentText.toString().equals(""))
|
||||
s3Bucket.setDelimiter(currentText.toString().trim());
|
||||
} else if (qName.equals("Marker")) {
|
||||
if (!currentText.toString().equals(""))
|
||||
s3Bucket.setMarker(currentText.toString());
|
||||
} else if (qName.equals("MaxKeys")) {
|
||||
s3Bucket.setMaxKeys(Long.parseLong(currentText.toString()));
|
||||
} else if (qName.equals("IsTruncated")) {
|
||||
boolean isTruncated = Boolean.parseBoolean(currentText.toString());
|
||||
s3Bucket.setComplete(!isTruncated);
|
||||
|
|
|
@ -29,10 +29,15 @@ import static org.testng.Assert.assertNotNull;
|
|||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import static org.jclouds.aws.s3.commands.options.GetBucketOptions.Builder.*;
|
||||
import org.jclouds.aws.s3.domain.S3Bucket;
|
||||
import org.jclouds.aws.s3.domain.S3Object;
|
||||
import org.testng.annotations.DataProvider;
|
||||
|
@ -75,25 +80,25 @@ public class AmazonS3Test extends S3IntegrationTest {
|
|||
@Test(dataProvider = "putTests")
|
||||
void testPutObject(String key, String type, Object content,
|
||||
Object realObject) throws Exception {
|
||||
String s3Bucket = bucketPrefix + "filetestsforadrian";
|
||||
client.createBucketIfNotExists(s3Bucket).get(10, TimeUnit.SECONDS);
|
||||
context.createS3ObjectMap(s3Bucket).clear();
|
||||
assertEquals(client.getBucket(s3Bucket).get(10, TimeUnit.SECONDS)
|
||||
String bucketName = bucketPrefix + "filetestsforadrian";
|
||||
client.createBucketIfNotExists(bucketName).get(10, TimeUnit.SECONDS);
|
||||
context.createS3ObjectMap(bucketName).clear();
|
||||
assertEquals(client.getBucket(bucketName).get(10, TimeUnit.SECONDS)
|
||||
.getContents().size(), 0);
|
||||
S3Object object = new S3Object(key);
|
||||
object.getMetaData().setContentType(type);
|
||||
object.setData(content);
|
||||
assertNotNull(client.addObject(s3Bucket, object).get(10,
|
||||
assertNotNull(client.addObject(bucketName, object).get(10,
|
||||
TimeUnit.SECONDS));
|
||||
object = client.getObject(s3Bucket, object.getKey()).get(10,
|
||||
object = client.getObject(bucketName, object.getKey()).get(10,
|
||||
TimeUnit.SECONDS);
|
||||
returnedString = S3Utils.getContentAsStringAndClose(object);
|
||||
assertEquals(returnedString, realObject);
|
||||
assertEquals(client.getBucket(s3Bucket).get(10, TimeUnit.SECONDS)
|
||||
assertEquals(client.getBucket(bucketName).get(10, TimeUnit.SECONDS)
|
||||
.getContents().size(), 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test()
|
||||
void testCopyObject() throws Exception {
|
||||
String realObject = IOUtils.toString(new FileInputStream("pom.xml"));
|
||||
|
||||
|
@ -136,40 +141,111 @@ public class AmazonS3Test extends S3IntegrationTest {
|
|||
}
|
||||
|
||||
S3Object.MetaData headObject() throws Exception {
|
||||
String s3Bucket = bucketPrefix + "adrianjbosstest";
|
||||
return client.getObjectMetaData(s3Bucket, "3366").get(10,
|
||||
String bucketName = bucketPrefix + "adrianjbosstest";
|
||||
return client.getObjectMetaData(bucketName, "3366").get(10,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Test
|
||||
void bucketExists() throws Exception {
|
||||
String s3Bucket = bucketPrefix + "needstoexist";
|
||||
assert !client.bucketExists(s3Bucket).get(10, TimeUnit.SECONDS);
|
||||
assert client.createBucketIfNotExists(s3Bucket).get(10,
|
||||
@Test()
|
||||
void testGetBucketDelimiter() throws InterruptedException,
|
||||
ExecutionException, TimeoutException, UnsupportedEncodingException {
|
||||
String bucketName = bucketPrefix + "delimiter";
|
||||
assert client.createBucketIfNotExists(bucketName).get(10,
|
||||
TimeUnit.SECONDS);
|
||||
assert client.bucketExists(s3Bucket).get(10, TimeUnit.SECONDS);
|
||||
String prefix = "apps";
|
||||
addTenObjectsUnderPrefix(bucketName, prefix);
|
||||
add15UnderRoot(bucketName);
|
||||
S3Bucket bucket = client.getBucket(bucketName, delimiter("/")).get(10,
|
||||
TimeUnit.SECONDS);
|
||||
assertEquals(bucket.getDelimiter(), "/");
|
||||
assertEquals(bucket.getContents().size(), 15);
|
||||
assertEquals(bucket.getCommonPrefixes().size(), 1);
|
||||
}
|
||||
|
||||
private void addAlphabetUnderRoot(String bucketName)
|
||||
throws InterruptedException, ExecutionException, TimeoutException {
|
||||
for (char letter = 'a'; letter <= 'z'; letter++) {
|
||||
client.addObject(bucketName,
|
||||
new S3Object(letter + "", letter + "content")).get(10,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetBucketMarker() throws InterruptedException, ExecutionException,
|
||||
TimeoutException, UnsupportedEncodingException {
|
||||
String bucketName = bucketPrefix + "marker";
|
||||
assert client.createBucketIfNotExists(bucketName).get(10,
|
||||
TimeUnit.SECONDS);
|
||||
addAlphabetUnderRoot(bucketName);
|
||||
S3Bucket bucket = client.getBucket(bucketName, marker("y")).get(10,
|
||||
TimeUnit.SECONDS);
|
||||
assertEquals(bucket.getMarker(), "y");
|
||||
assertEquals(bucket.getContents().size(), 1);
|
||||
}
|
||||
|
||||
@Test()
|
||||
void testGetBucketPrefix() throws InterruptedException, ExecutionException,
|
||||
TimeoutException, UnsupportedEncodingException {
|
||||
String bucketName = bucketPrefix + "prefix";
|
||||
assert client.createBucketIfNotExists(bucketName).get(10,
|
||||
TimeUnit.SECONDS);
|
||||
String prefix = "apps";
|
||||
addTenObjectsUnderPrefix(bucketName, prefix);
|
||||
add15UnderRoot(bucketName);
|
||||
|
||||
S3Bucket bucket = client.getBucket(bucketName, prefix("apps/")).get(10,
|
||||
TimeUnit.SECONDS);
|
||||
assertEquals(bucket.getContents().size(), 10);
|
||||
assertEquals(bucket.getPrefix(), "apps/");
|
||||
|
||||
}
|
||||
|
||||
private void add15UnderRoot(String bucketName) throws InterruptedException,
|
||||
ExecutionException, TimeoutException {
|
||||
for (int i = 0; i < 15; i++)
|
||||
client.addObject(bucketName, new S3Object(i + "", i + "content"))
|
||||
.get(10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
private void addTenObjectsUnderPrefix(String bucketName, String prefix)
|
||||
throws InterruptedException, ExecutionException, TimeoutException {
|
||||
for (int i = 0; i < 10; i++)
|
||||
client.addObject(bucketName,
|
||||
new S3Object(prefix + "/" + i, i + "content")).get(10,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Test()
|
||||
void bucketExists() throws Exception {
|
||||
String bucketName = bucketPrefix + "needstoexist";
|
||||
assert !client.bucketExists(bucketName).get(10, TimeUnit.SECONDS);
|
||||
assert client.createBucketIfNotExists(bucketName).get(10,
|
||||
TimeUnit.SECONDS);
|
||||
assert client.bucketExists(bucketName).get(10, TimeUnit.SECONDS);
|
||||
|
||||
}
|
||||
|
||||
Boolean deleteBucket() throws Exception {
|
||||
String s3Bucket = bucketPrefix + "adrianjbosstest";
|
||||
return client.deleteBucketIfEmpty(s3Bucket).get(10, TimeUnit.SECONDS);
|
||||
String bucketName = bucketPrefix + "adrianjbosstest";
|
||||
return client.deleteBucketIfEmpty(bucketName).get(10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
Boolean deleteObject() throws Exception {
|
||||
String s3Bucket = bucketPrefix + "adrianjbosstest";
|
||||
return client.deleteObject(s3Bucket, "3366").get(10, TimeUnit.SECONDS);
|
||||
String bucketName = bucketPrefix + "adrianjbosstest";
|
||||
return client.deleteObject(bucketName, "3366")
|
||||
.get(10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
Boolean createBucketIfNotExists() throws Exception {
|
||||
String s3Bucket = bucketPrefix + "adrianjbosstest";
|
||||
return client.createBucketIfNotExists(s3Bucket).get(10,
|
||||
String bucketName = bucketPrefix + "adrianjbosstest";
|
||||
return client.createBucketIfNotExists(bucketName).get(10,
|
||||
TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
S3Bucket getBucket() throws Exception {
|
||||
String s3Bucket = bucketPrefix + "adrianjbosstest";
|
||||
return client.getBucket(s3Bucket).get(10, TimeUnit.SECONDS);
|
||||
String bucketName = bucketPrefix + "adrianjbosstest";
|
||||
return client.getBucket(bucketName).get(10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
}
|
|
@ -34,6 +34,7 @@ import java.util.concurrent.Future;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.jclouds.aws.s3.commands.options.GetBucketOptions;
|
||||
import org.jclouds.aws.s3.commands.options.PutBucketOptions;
|
||||
import org.jclouds.aws.s3.domain.S3Bucket;
|
||||
import org.jclouds.aws.s3.domain.S3Object;
|
||||
|
@ -218,4 +219,8 @@ public class StubS3Connection implements S3Connection {
|
|||
throw new UnsupportedOperationException("todo");
|
||||
}
|
||||
|
||||
public Future<S3Bucket> getBucket(String name, GetBucketOptions options) {
|
||||
throw new UnsupportedOperationException("todo");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ public class S3ParserTest extends PerformanceTest {
|
|||
Injector injector = null;
|
||||
|
||||
public static final String listAllMyBucketsResultOn200 = "<ListAllMyBucketsResult xmlns=\"http://s3.amazonaws.com/doc/callables/\"><Owner ><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID></Owner><Buckets><Bucket><Name>adrianjbosstest</Name><CreationDate>2009-03-12T02:00:07.000Z</CreationDate></Bucket><Bucket><Name>adrianjbosstest2</Name><CreationDate>2009-03-12T02:00:09.000Z</CreationDate></Bucket></Buckets></ListAllMyBucketsResult>";
|
||||
|
||||
|
||||
S3ParserFactory parserFactory = null;
|
||||
|
||||
@BeforeMethod
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* 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
|
||||
* specifSourceic language governing permissions and limitations
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
*/
|
||||
package org.jclouds.aws.s3.commands.options;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.aws.s3.commands.options.GetBucketOptions.Builder.delimiter;
|
||||
import static org.jclouds.aws.s3.commands.options.GetBucketOptions.Builder.marker;
|
||||
import static org.jclouds.aws.s3.commands.options.GetBucketOptions.Builder.maxKeys;
|
||||
|
@ -30,6 +31,8 @@ import static org.jclouds.aws.s3.commands.options.GetBucketOptions.Builder.prefi
|
|||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNull;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
|
@ -40,7 +43,7 @@ import org.testng.annotations.Test;
|
|||
public class GetBucketOptionsTest {
|
||||
|
||||
@Test
|
||||
public void testPrefix() {
|
||||
public void testPrefix() throws UnsupportedEncodingException {
|
||||
GetBucketOptions options = new GetBucketOptions();
|
||||
options.prefix("test");
|
||||
assertEquals(options.getPrefix(), "test");
|
||||
|
@ -53,21 +56,46 @@ public class GetBucketOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testOneOptionQueryString() {
|
||||
public void testOneOptionQueryString() throws UnsupportedEncodingException {
|
||||
GetBucketOptions options = new GetBucketOptions();
|
||||
options.prefix("test");
|
||||
assertEquals(options.toQueryString(), "?prefix=test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTwoOptionQueryString() {
|
||||
public void testTwoOptionQueryString() throws UnsupportedEncodingException {
|
||||
GetBucketOptions options = new GetBucketOptions();
|
||||
options.prefix("test").maxKeys(1);
|
||||
try {
|
||||
assertEquals(options.toQueryString(), "?prefix=test&max-keys=1");
|
||||
} catch (AssertionError e) {
|
||||
assertEquals(options.toQueryString(), "?max-keys=1&prefix=test");
|
||||
String query = options.toQueryString();
|
||||
checkQuery(query);
|
||||
checkQuery(checkNotNull(query));
|
||||
|
||||
}
|
||||
|
||||
private void checkQuery(String query) {
|
||||
try {
|
||||
assertEquals(query, "?prefix=test&max-keys=1");
|
||||
} catch (AssertionError e) {
|
||||
assertEquals(query, "?max-keys=1&prefix=test");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrefixAndDelimiterUrlEncodingQueryString()
|
||||
throws UnsupportedEncodingException {
|
||||
GetBucketOptions options = new GetBucketOptions();
|
||||
options.prefix("/test").delimiter("/");
|
||||
String query = options.toQueryString();
|
||||
checkEncodedQuery(query);
|
||||
checkEncodedQuery(checkNotNull(query));
|
||||
|
||||
}
|
||||
|
||||
private void checkEncodedQuery(String query) {
|
||||
try {
|
||||
assertEquals(query, "?prefix=%2Ftest&delimiter=%2F");
|
||||
} catch (AssertionError e) {
|
||||
assertEquals(query, "?delimiter=%2F&prefix=%2Ftest");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,18 +106,18 @@ public class GetBucketOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testPrefixStatic() {
|
||||
public void testPrefixStatic() throws UnsupportedEncodingException {
|
||||
GetBucketOptions options = prefix("test");
|
||||
assertEquals(options.getPrefix(), "test");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void testPrefixNPE() {
|
||||
public void testPrefixNPE() throws UnsupportedEncodingException {
|
||||
prefix(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarker() {
|
||||
public void testMarker() throws UnsupportedEncodingException {
|
||||
GetBucketOptions options = new GetBucketOptions();
|
||||
options.marker("test");
|
||||
assertEquals(options.getMarker(), "test");
|
||||
|
@ -102,13 +130,13 @@ public class GetBucketOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testMarkerStatic() {
|
||||
public void testMarkerStatic() throws UnsupportedEncodingException {
|
||||
GetBucketOptions options = marker("test");
|
||||
assertEquals(options.getMarker(), "test");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void testMarkerNPE() {
|
||||
public void testMarkerNPE() throws UnsupportedEncodingException {
|
||||
marker(null);
|
||||
}
|
||||
|
||||
|
@ -137,7 +165,7 @@ public class GetBucketOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDelimiter() {
|
||||
public void testDelimiter() throws UnsupportedEncodingException {
|
||||
GetBucketOptions options = new GetBucketOptions();
|
||||
options.delimiter("test");
|
||||
assertEquals(options.getDelimiter(), "test");
|
||||
|
@ -150,13 +178,13 @@ public class GetBucketOptionsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testDelimiterStatic() {
|
||||
public void testDelimiterStatic() throws UnsupportedEncodingException {
|
||||
GetBucketOptions options = delimiter("test");
|
||||
assertEquals(options.getDelimiter(), "test");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = NullPointerException.class)
|
||||
public void testDelimiterNPE() {
|
||||
public void testDelimiterNPE() throws UnsupportedEncodingException {
|
||||
delimiter(null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Adrian Cole <adrian@jclouds.org>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.aws.s3.xml;
|
||||
|
||||
import org.jclouds.aws.s3.xml.config.S3ParserModule;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
public class BaseHandlerTest {
|
||||
|
||||
protected S3ParserFactory parserFactory = null;
|
||||
private Injector injector;
|
||||
|
||||
public BaseHandlerTest() {
|
||||
super();
|
||||
}
|
||||
|
||||
@BeforeMethod
|
||||
protected void setUpInjector() {
|
||||
injector = Guice.createInjector(new S3ParserModule());
|
||||
parserFactory = injector.getInstance(S3ParserFactory.class);
|
||||
assert parserFactory != null;
|
||||
}
|
||||
|
||||
@AfterMethod
|
||||
protected void tearDownInjector() {
|
||||
parserFactory = null;
|
||||
injector = null;
|
||||
}
|
||||
|
||||
}
|
|
@ -27,34 +27,13 @@ import static org.testng.Assert.*;
|
|||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.jclouds.aws.s3.domain.S3Error;
|
||||
import org.jclouds.aws.s3.xml.config.S3ParserModule;
|
||||
import org.jclouds.http.HttpException;
|
||||
import org.jclouds.http.commands.callables.xml.ParseSax;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
@Test
|
||||
public class ErrorHandlerTest {
|
||||
private S3ParserFactory parserFactory = null;
|
||||
private Injector injector;
|
||||
|
||||
@BeforeMethod
|
||||
protected void setUpInjector() {
|
||||
injector = Guice.createInjector(new S3ParserModule());
|
||||
parserFactory = injector.getInstance(S3ParserFactory.class);
|
||||
assert parserFactory != null;
|
||||
}
|
||||
|
||||
@AfterMethod
|
||||
protected void tearDownInjector() {
|
||||
parserFactory = null;
|
||||
injector = null;
|
||||
}
|
||||
|
||||
public class ErrorHandlerTest extends BaseHandlerTest {
|
||||
public static final String errorFromAmazonIfYouDontRemoveTransferEncodingHeader = "<Error><Code>NotImplemented</Code><Message>A header you provided implies functionality that is not implemented</Message><Header>Transfer-Encoding</Header><RequestId>7C59925D75D15561</RequestId><HostId>fbskVU51OZJg2yZS/wNIxoE2PmCf0ZqFd0iH6Vrzw0uKG3KmokswBytL/Bfp/GWb</HostId></Error>";
|
||||
|
||||
@Test
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Adrian Cole <adrian@jclouds.org>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.aws.s3.xml;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.jclouds.aws.s3.domain.S3Bucket;
|
||||
import org.jclouds.http.HttpException;
|
||||
import org.jclouds.http.commands.callables.xml.ParseSax;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test
|
||||
public class ListBucketHandlerTest extends BaseHandlerTest {
|
||||
public static final String listBucketWithPrefixAppsSlash = "<ListBucketResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><Name>adriancole.org.jclouds.aws.s3.amazons3testdelimiter</Name><Prefix>apps/</Prefix><Marker></Marker><MaxKeys>1000</MaxKeys><IsTruncated>false</IsTruncated><Contents><Key>apps/0</Key><LastModified>2009-05-07T18:27:08.000Z</LastModified><ETag>"c82e6a0025c31c5de5947fda62ac51ab"</ETag><Size>8</Size><Owner><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID><DisplayName>ferncam</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>apps/1</Key><LastModified>2009-05-07T18:27:09.000Z</LastModified><ETag>"944fab2c5a9a6bacf07db5e688310d7a"</ETag><Size>8</Size><Owner><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID><DisplayName>ferncam</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>apps/2</Key><LastModified>2009-05-07T18:27:09.000Z</LastModified><ETag>"a227b8888045c8fd159fb495214000f0"</ETag><Size>8</Size><Owner><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID><DisplayName>ferncam</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>apps/3</Key><LastModified>2009-05-07T18:27:09.000Z</LastModified><ETag>"c9caa76c3dec53e2a192608ce73eef03"</ETag><Size>8</Size><Owner><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID><DisplayName>ferncam</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>apps/4</Key><LastModified>2009-05-07T18:27:09.000Z</LastModified><ETag>"1ce5d0dcc6154a647ea90c7bdf82a224"</ETag><Size>8</Size><Owner><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID><DisplayName>ferncam</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>apps/5</Key><LastModified>2009-05-07T18:27:09.000Z</LastModified><ETag>"79433524d87462ee05708a8ef894ed55"</ETag><Size>8</Size><Owner><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID><DisplayName>ferncam</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>apps/6</Key><LastModified>2009-05-07T18:27:10.000Z</LastModified><ETag>"dd00a060b28ddca8bc5a21a49e306f67"</ETag><Size>8</Size><Owner><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID><DisplayName>ferncam</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>apps/7</Key><LastModified>2009-05-07T18:27:10.000Z</LastModified><ETag>"8cd06eca6e819a927b07a285d750b100"</ETag><Size>8</Size><Owner><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID><DisplayName>ferncam</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>apps/8</Key><LastModified>2009-05-07T18:27:10.000Z</LastModified><ETag>"174495094d0633b92cbe46603eee6bad"</ETag><Size>8</Size><Owner><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID><DisplayName>ferncam</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><Key>apps/9</Key><LastModified>2009-05-07T18:27:10.000Z</LastModified><ETag>"cd8a19b26fea8a827276df0ad11c580d"</ETag><Size>8</Size><Owner><ID>e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0</ID><DisplayName>ferncam</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents></ListBucketResult>";
|
||||
public static final String listBucketWithSlashDelimiterAndCommonPrefixApps = "<ListBucketResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"> <Delimiter>/</Delimiter> <CommonPrefixes><Prefix>apps/</Prefix></CommonPrefixes></ListBucketResult>";
|
||||
ParseSax<S3Bucket> parser;
|
||||
|
||||
@BeforeMethod
|
||||
void setUpParser() {
|
||||
parser = parserFactory.createListBucketParser();
|
||||
((ListBucketHandler) parser.getHandler()).setBucketName("test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListMyBucketsWithDelimiterSlashAndCommonPrefixesAppsSlash()
|
||||
throws HttpException {
|
||||
|
||||
S3Bucket bucket = parser.parse(IOUtils
|
||||
.toInputStream(listBucketWithSlashDelimiterAndCommonPrefixApps));
|
||||
assertEquals(bucket.getCommonPrefixes().iterator().next(), "apps/");
|
||||
assertEquals(bucket.getDelimiter(), "/");
|
||||
assert bucket.getMarker() == null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListMyBucketsWithPrefixAppsSlash() throws HttpException {
|
||||
|
||||
S3Bucket bucket = parser.parse(IOUtils
|
||||
.toInputStream(listBucketWithPrefixAppsSlash));
|
||||
assertEquals(bucket.getPrefix(), "apps/");
|
||||
assertEquals(bucket.getMaxKeys(), 1000);
|
||||
assert bucket.getMarker() == null;
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue