Bad Request Error when invoking third party Restful web services via .json | Community
Skip to main content
August 30, 2016
Solved

Bad Request Error when invoking third party Restful web services via .json

  • August 30, 2016
  • 14 replies
  • 11605 views

Hi 

We are trying to call the third party REST service in AEM 6.1 and following the example as per below URL.

https://helpx.adobe.com/experience-manager/using/restful-services.html

This example is working when we are creating the template and render the component that uses template. But when we are trying to create the separate component and using that component in some other template the it is not working and throwing the error like "Unable to retrieve data Bad request 400 (Bad Request)" (see the attached screenshot). Any idea what we are missing? or it will work only in case of render component that uses the template only not with separate component?

Thanks

~S

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by smacdonald2008

Here is the best way to interact with a 3rd party Restful service in AEM - use HTL -- https://helpx.adobe.com/experience-manager/using/restful_htl.html

14 replies

August 31, 2016

To reproduce it, you can follow the below steps (don't import the package as is on the helpx site):

1: Create one new separate component

2: Just copy the same code in to created component and also the query.json.jsp and clientlibs as well

3: Create one new page use any template and drop this new component from sidekick on the page.

4. Now, click on "Get Distance" button , you will see the error in to browser console as well

Thanks

~S

aem_dev1
August 31, 2016

    Invalid recursion selector value 'query' is valid as per sling implementation. Check following for more details. http://svn.apache.org/repos/asf/sling/tags/org.apache.sling.servlets.get-2.1.4/src/main/java/org/apache/sling/servlets/get/impl/helpers/JsonRendererServlet.java

 

For custom selectors there are two approaches.

1. create a folder called query and move json.jsp into that folder. When url accessed as query.json, invalid recursion error will be thrown. To solve the issue try query.json.html

2. I prefer to go with 2nd option.

create Page.json.jsp at /apps/foundation/components/primary/cq/Page and add "<%@include file="proxy.jsp"%>". Copy proxy.jsp from /libs/foundation/components/primary/cq/Page to current folder. In proxy.jsp , implement the support for custom selector

smacdonald2008
September 2, 2016

If you are interested in building this into an AEM component - then build a HTL (used to be Sightly) component. The Java part of the component will have a method that invokes the Restful service.

i am thinking your issue is related to calling the code via AJAX in another component. We will release this article soon that will not throw this exception when used in a HTL component. 

smacdonald2008
smacdonald2008Accepted solution
September 6, 2016

Here is the best way to interact with a 3rd party Restful service in AEM - use HTL -- https://helpx.adobe.com/experience-manager/using/restful_htl.html