[Openstack] Developing with Scala/Java on OpenStack Swift

Luis Gervaso luis at woorea.es
Thu Jan 3 06:00:40 UTC 2013


Hi Gui!

I just upgraded the code to work properly with latest Jersey release

Below the swift example code (just tested and working with HPCloud)

Hope it helps you :)

private static final File TEST_FILE = new File("pom.xml");

 private static final String KEYSTONE_AUTH_URL = "
https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0";

 private static final String KEYSTONE_USERNAME = "";

 private static final String KEYSTONE_PASSWORD = "";


 /**

 * @param args

 */

public static void main(String[] args) throws Exception {

 KeystoneClient keystone = new KeystoneClient(KEYSTONE_AUTH_URL);

 //access with unscoped token

 Access access = keystone.execute(Authenticate.withPasswordCredentials(
KEYSTONE_USERNAME, KEYSTONE_PASSWORD));

  //use the token in the following requests

 keystone.setToken(access.getToken().getId());

  Tenants tenants = keystone.execute(new ListTenants());

  //try to exchange token using the first tenant

 if(tenants.getList().size() > 0) {

   access =
keystone.execute(Authenticate.withToken(access.getToken().getId()).withTenantId(tenants.getList().get(0).getId()));

   SwiftClient swiftClient =
newSwiftClient(KeystoneUtils.findEndpointURL(access.getServiceCatalog(),
"object-store", null, "public"), access.getToken().getId());

   //swiftClient.execute(new DeleteContainer("navidad2"));

   swiftClient.execute(new CreateContainer("navidad2"));

   System.out.println(swiftClient.execute(new ListContainers()));

   ObjectForUpload upload = new ObjectForUpload();

 upload.setContainer("navidad2");

 upload.setName("example2");

 upload.setInputStream(new FileInputStream(TEST_FILE));

 swiftClient.execute(new UploadObject(upload));

   System.out.println(swiftClient.execute(new ListObjects("navidad2",
new HashMap<String,
String>() {{

  put("path", "");

 }})).get(0).getContentType());

   }


 }

On Wed, Jan 2, 2013 at 8:01 PM, Gui Maluf <guimalufb at gmail.com> wrote:

> Hey guys,
> I'm trying to extend a software project<https://github.com/VirtualCloudDrive/CloudDrive>to talk with Swift.
>
> This project was developed on Scala, and my issue is: how should I access
> Swift resource? Should I use openstack-java-sdk<https://github.com/woorea/openstack-java-sdk/>,
> jclouds <http://www.jclouds.org/documentation/quickstart/openstack/> or
> develop my own library to access the REST API?
> I've tried to use openstack-java-sdk but I wasn't able to import the
> libraries exposed at examples.
>
> I'm really confuse about that and I'll appreciate any help, hint, advice!
>
> Thanks in advance.!
>
> --
> *guilherme* \n
> \t *maluf*
>
> _______________________________________________
> Mailing list: https://launchpad.net/~openstack
> Post to     : openstack at lists.launchpad.net
> Unsubscribe : https://launchpad.net/~openstack
> More help   : https://help.launchpad.net/ListHelp
>
>


-- 
-------------------------------------------
Luis Alberto Gervaso Martin
Woorea Solutions, S.L
CEO & CTO
mobile: (+34) 627983344
luis@ <luis.gervaso at gmail.com>woorea.es
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack/attachments/20130103/b87b6629/attachment.html>


More information about the Openstack mailing list