32
© 2014 IBM Corporation Using Java to access Object Storage v2 in Bluemix Joseph Chang Senior IT Specialist IBM Cloud Group Document number

Using java to access bluemix object storage v2

Embed Size (px)

Citation preview

Page 1: Using java to access bluemix object storage v2

© 2014 IBM Corporation

Using Java to access Object Storage v2 in Bluemix

Joseph Chang

Senior IT Specialist

IBM Cloud Group

Document number

Page 2: Using java to access bluemix object storage v2

© 2014 IBM Corporation

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

2

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

Page 3: Using java to access bluemix object storage v2

© 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.

Page 4: Using java to access bluemix object storage v2

© 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.

Page 5: Using java to access bluemix object storage v2

© 2014 IBM Corporation5

Click Here.

Page 6: Using java to access bluemix object storage v2

© 2014 IBM Corporation6

Click Here.

Page 7: Using java to access bluemix object storage v2

© 2014 IBM Corporation7

Fill in user name and password.

Then click sign in.

Page 8: Using java to access bluemix object storage v2

© 2014 IBM Corporation8

Click Object Store ->

Container

Page 9: Using java to access bluemix object storage v2

© 2014 IBM Corporation

Now you see the containers, folders, files.

9

You can create folder/ upload files with this dashboard

Page 10: Using java to access bluemix object storage v2

© 2014 IBM Corporation

Now let’s create object storage service from catalog.

10

Your service created.

Page 11: Using java to access bluemix object storage v2

© 2014 IBM Corporation

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

11

Page 12: Using java to access bluemix object storage v2

© 2014 IBM Corporation

Click Show Credentials.

12

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

info in our Java code.

Page 13: Using java to access bluemix object storage v2

© 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

Page 14: Using java to access bluemix object storage v2

© 2014 IBM Corporation

Or you can take a copy to local.

14

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

Page 15: Using java to access bluemix object storage v2

© 2014 IBM Corporation

Use Eclipse to import the sample code

15

Page 16: Using java to access bluemix object storage v2

© 2014 IBM Corporation

Libraries required by this sample

16

Page 17: Using java to access bluemix object storage v2

© 2014 IBM Corporation

Sample 1 : Java Application in Local

17

Page 18: Using java to access bluemix object storage v2

© 2014 IBM Corporation

Classes required by this sample

18

Page 19: Using java to access bluemix object storage v2

© 2014 IBM Corporation

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

19

Page 20: Using java to access bluemix object storage v2

© 2014 IBM Corporation

Connect to Object Storage with SwiftApi

20

Page 21: Using java to access bluemix object storage v2

© 2014 IBM Corporation

Java main program

21

Page 22: Using java to access bluemix object storage v2

© 2014 IBM Corporation

Using ContainerApi and ObjectApi

22

Page 23: Using java to access bluemix object storage v2

© 2014 IBM Corporation

Using ContainerApi and ObjectApi

23

Page 24: Using java to access bluemix object storage v2

© 2014 IBM Corporation

Let’s run it

24

Page 25: Using java to access bluemix object storage v2

© 2014 IBM Corporation

View the log in eclipse console

25

Page 26: Using java to access bluemix object storage v2

© 2014 IBM Corporation

Sample 2 : Java Servlet in Bluemix Liberty

26

Page 27: Using java to access bluemix object storage v2

© 2014 IBM Corporation

Prepare the manifest file

27

Replace the host name,

object storage service name

with yours.

Page 28: Using java to access bluemix object storage v2

© 2014 IBM Corporation

View the Servlet souce

28

The servlet which running in Bluemix liberty

with automatically take the environment

variables.

Page 29: Using java to access bluemix object storage v2

© 2014 IBM Corporation

Deploy it with cf push

29

Page 30: Using java to access bluemix object storage v2

© 2014 IBM Corporation

The application is running

30

Page 31: Using java to access bluemix object storage v2

© 2014 IBM Corporation

View the result in Browser

31

Page 32: Using java to access bluemix object storage v2

© 2014 IBM Corporation

Thank you

32

Take me to BluemixClick Here