Topic
  • No replies
Edward_Wang
Edward_Wang
1 Post

Pinned topic Tips on checking the references of cloud services in ICAP application code

‏2013-07-01T08:16:48Z |

ICAP provides two ways to get and check the reference of the service in your application code. They are:

1. Enable JNDI lookup

2. Use the ICAP_SERVICES system variable.

Here, I'm going to talk about the approach of using ICAP_SERVICES system variable rather than enabling JNDI lookup.  Because it is more flexible and capable than JNDI lookup.

ICAP_SERVICES is a JSON-based system variable and can be fetched by using System.getenv("ICAP_SERVICES") when the application is running. You can connect to the cloud service by yourself by using the information from the ICAP_SERVICES system variable.

I will take three ICAP projects as examples to  illustrate the usage of this system property. These ICAP projects are created based on the templates ICAP provided.

The common steps for all the three projects:

a. drag and drop the Derby service and Location service into Cloud Resource of the project from the Cloud Explore View.

Add cloud services


1. Steps for JAX-RS project:

a. Open HelloICAP.java file, comments out the String result line and add a new line

String result = "<!DOCTYPE html><meta charset=\"UTF-8\"><html><body><h1>" + System.getenv("ICAP_SERVICES") + "</h1></body></html>";

b. Save codes and run the application from project overview page

Run application

c. After  the application is running, click the Try In Browser: http://localhost:8890/JAXRS to open page.

d. The references of the two used services will show up on the page like the picture.

Reference_json

You could notice that all the service references are displayed, such as service name, credential, tags and endpoint, etc.

2. Steps for SpringMVC project

a. Open home.jsp file under WebContent folder, change the line <h1>Hello world!</h1> to <h1><% out.println(System.getenv("ICAP_SERVICES"));%></h1>

b. save and run the application from overview page as JAXRS does .

c. open from browser, you will see the same output on the page

3. Steps for Servlet project:

a. Open SampleServlet.java, replace greeting with System.getenv("ICAP_SERVICES") and save the changes

b. run this servlet from overview page and then click  to open from browser

c. the cloud service references will show up on the page.

 

After you know those references of cloud service, you could consume them in your code.

 

 

Updated on 2013-07-01T09:06:50Z at 2013-07-01T09:06:50Z by Edward_Wang