Using java to access bluemix object storage v2

Preview:

Citation preview

© 2014 IBM Corporation

Using Java to access Object Storage v2 in Bluemix

Joseph Chang

Senior IT Specialist

IBM Cloud Group

Document number

© 2014 IBM Corporation

https://github.com/whitfiea/bluemix-objectstorage-v2

2

The sample code in this slide is from the following url.

© 2014 IBM Corporation

Take me to BluemixClick Here

If you need the guidance and sample code of using Java to access object storage v2 in bluemix, go ahead.

© 2014 IBM Corporation4

https://ibm.biz/BdEzTZ

Read/Write files with OpenStack Dashboard

You can use openstack dashboard to read/write

container/folder/file in object storage v2.

© 2014 IBM Corporation5

Click Here.

© 2014 IBM Corporation6

Click Here.

© 2014 IBM Corporation7

Fill in user name and password.

Then click sign in.

© 2014 IBM Corporation8

Click Object Store ->

Container

© 2014 IBM Corporation

Now you see the containers, folders, files.

9

You can create folder/ upload files with this dashboard

© 2014 IBM Corporation

Now let’s create object storage service from catalog.

10

Your service created.

© 2014 IBM Corporation

Click the service, you can see the number of containers and objects.

11

© 2014 IBM Corporation

Click Show Credentials.

12

Take note for all of these information. We will use these

info in our Java code.

© 2014 IBM Corporation

Now let’s look at the Java code. You can view it from JazzHub.

https://hub.jazz.net/code/edit/edit.html#/code/file/joseph-OrionContent/joseph%2520%257C%2520jx-object-storage2/

13

© 2014 IBM Corporation

Or you can take a copy to local.

14

git clone https://hub.jazz.net/git/joseph/jx-object-storage2/

© 2014 IBM Corporation

Use Eclipse to import the sample code

15

© 2014 IBM Corporation

Libraries required by this sample

16

© 2014 IBM Corporation

Sample 1 : Java Application in Local

17

© 2014 IBM Corporation

Classes required by this sample

18

© 2014 IBM Corporation

You can get the information from object storage service credential.Refer to p.12.

19

© 2014 IBM Corporation

Connect to Object Storage with SwiftApi

20

© 2014 IBM Corporation

Java main program

21

© 2014 IBM Corporation

Using ContainerApi and ObjectApi

22

© 2014 IBM Corporation

Using ContainerApi and ObjectApi

23

© 2014 IBM Corporation

Let’s run it

24

© 2014 IBM Corporation

View the log in eclipse console

25

© 2014 IBM Corporation

Sample 2 : Java Servlet in Bluemix Liberty

26

© 2014 IBM Corporation

Prepare the manifest file

27

Replace the host name,

object storage service name

with yours.

© 2014 IBM Corporation

View the Servlet souce

28

The servlet which running in Bluemix liberty

with automatically take the environment

variables.

© 2014 IBM Corporation

Deploy it with cf push

29

© 2014 IBM Corporation

The application is running

30

© 2014 IBM Corporation

View the result in Browser

31

© 2014 IBM Corporation

Thank you

32

Take me to BluemixClick Here