Hi,
This is the code i used to successfully create containers and objects on
TryStack.
I want to try the temporaryURLs feature against the already created object.
I am quite new to Java :)
Thanks.
private SwiftApi swiftApi;
public static void main(String[] args) throws IOException {
JCloudsSwift jcloudsSwift = new JCloudsSwift();
try {
jcloudsSwift.createContainer();
jcloudsSwift.uploadObjectFromString();
jcloudsSwift.listContainers();
jcloudsSwift.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
jcloudsSwift.close();
}
}
public JCloudsSwift() {
Iterable<Module> modules = ImmutableSet.<Module>of(
new SLF4JLoggingModule());
String provider = "openstack-swift";
String identity = "facebook123:facebook123";
String credential = "somethinglike2345";
swiftApi = ContextBuilder.newBuilder(provider)
.endpoint("http://x86.trystack.org:5000/v2.0/")
.credentials(identity, credential)
.modules(modules)
.buildApi(SwiftApi.class);
}
private void createContainer() {
System.out.println("Create Container");
ContainerApi containerApi =
swiftApi.getContainerApiForRegion("RegionOne");
CreateContainerOptions options = CreateContainerOptions.Builder
.metadata(ImmutableMap.of(
"key1", "value1",
"key2", "value2"));
containerApi.create(CONTAINER_NAME);
System.out.println(" " + CONTAINER_NAME);
}
private void uploadObjectFromString() {
System.out.println("Upload Object From String");
ObjectApi objectApi =
swiftApi.getObjectApiForRegionAndContainer("RegionOne", CONTAINER_NAME);
Payload payload = newByteSourcePayload(wrap("Hello Z Xz xZ xX
ZXWorld".getBytes()));
objectApi.put(OBJECT_NAME, payload,
PutOptions.Builder.metadata(ImmutableMap.of("key1", "value1")));
System.out.println(" " + OBJECT_NAME);
}
private void listContainers() {
System.out.println("List Containers");
ContainerApi containerApi =
swiftApi.getContainerApiForRegion("RegionOne");
Set<Container> containers = containerApi.list().toSet();
for (Container container : containers) {
System.out.println(" " + container);
}
}
public void close() throws IOException {
Closeables.close(swiftApi, true);
}
}
Regards,
Ken
On Mon, Sep 29, 2014 at 5:57 PM, Jeremy Daggett <
[email protected]> wrote:
> Hi Ken,
>
> Would you be able to share some code [1] with us to further assist you?
> Thx!
>
> /jd
>
> [1] http://jclouds.apache.org/reference/report-a-bug/#code
>
> From: Kenny Aondona <[email protected]>
> Reply-To: "[email protected]" <[email protected]>
> Date: Saturday, September 27, 2014 at 3:48 PM
> To: "[email protected]" <[email protected]>
> Subject: Temporary URLs in TryStack
>
> Hi,
>
> How can I implement tempURL in Trystack. I am testing my code before a
> full implementation of openstack.
> Thanks.
>
> Ken.
>