Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Check http response of an external application from sightly code

Avatar

Community Advisor

Hi All,

I am planing to check the Http response of an external application from my sightly component.

From development perspective which one is better -

1. Make ajax call to check the application response code from sightly component itself.

                      

                                 or

2. Write a back end logic using WCMPojo with HttpURLConnection and validate the response.

                                   

                                or

3. Crate a servlet, get the response using HttpURLConnection and make a ajax call to that servlet  from sightly component.

Please suggest.

Thanks,

Debal

1 Accepted Solution

Avatar

Correct answer by
Level 2

For Point 1: You need CORS enabled for the service to be consumed if you want to make Ajax call from a sightly component.

For Point 2: If you are going to use WCMPojo, you should be taking cache and clear the responses and its tied to the component.

For Point 3: Create a common servlet to pass on the response code through HttpURL Connection to servlet response and read it through any component however you want it. Here again, you should be taking care of cache and clear the responses but the code is common and can be used in any component and externalize the URL you want to call in the servlet.

I will leave it to you on how you want to implement. I prefer option 3.

View solution in original post

4 Replies

Avatar

Level 10

For this - make your call from HTL backend - like WCMUsePojo. Follow the way we did in invoking a RESTFUL service - Creating an Adobe Experience Manager 6.3 HTL Component that displays data from a Restful Web Service

Avatar

Community Advisor

Hi Debal

     Decide on the approach keeping how you want to handle the request. If you write a server side code, the responses are going to get cached and you might have to clear it out before you pull in a new request or some how you have to disable the cache for the same.

     If you don't need to cache , may be you can figure out to use clientside (ajax call). But then may be you have to figure out how you are going to handle the response. If it is just to display on the page a simple ajax call would do.

Thanks

Veena

Avatar

Correct answer by
Level 2

For Point 1: You need CORS enabled for the service to be consumed if you want to make Ajax call from a sightly component.

For Point 2: If you are going to use WCMPojo, you should be taking cache and clear the responses and its tied to the component.

For Point 3: Create a common servlet to pass on the response code through HttpURL Connection to servlet response and read it through any component however you want it. Here again, you should be taking care of cache and clear the responses but the code is common and can be used in any component and externalize the URL you want to call in the servlet.

I will leave it to you on how you want to implement. I prefer option 3.

Avatar

Employee Advisor

Please ask your architect, if you are supposed to do a clientside integration of that piece of frontend content or if you are supposed to deliver a single HTML page, which contains all data already.

The decision to use AJAX or not is something I would never leave to any single developer. It must to decision shared with the whole team, and the consequences should be very clear to all.

Jörg