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

kautuk_sahni
Community Manager
Community Manager
August 30, 2016

Hi, Can you please check if OSGI bundle is in active state? 

~kautuk

Kautuk Sahni
August 30, 2016

Hi Kautuk,

Yes the bundle is in active states, even it is working when we are keeping the same code in render component that uses the template. it is not working when keeping it in new component and dropping the component on same template.

Thanks

~S

smacdonald2008
August 30, 2016

In the new component, are you calling the back end the same way? It does not make sense that it works when called from a page component but not from a separate component.

August 30, 2016

Yes Scott, we are calling exactly same way. it is very strange. when calling from separate component then only getting below attached error. You can see the attached screen shot.

 GET http://localhost:4502/content/aemexample/en/restservicecomponent/_jcr_content.query.json 400 (Bad Request)  granite.js:229

Thanks

~S

smacdonald2008
August 30, 2016

I am away at Evolve AEM conference, back in Office on Fri. We can setup a connect session. We can solve this during a connect session. I want to see your code, etc. 

August 30, 2016

please find the below url ,this link may help to you  

Consuming GET and POST request rest webservices in cq5:

http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manager.topic.html/forum__7h9p-hi_all_httpww.html

August 30, 2016

Yes sure Scott. we can connect on Friday. It would be great help to us.

Here is the error trace: as well.

Invalid recursion selector value 'query'

Cannot serve request to /content/aemexample/en/testt/_jcr_content.query.json in org.apache.sling.servlets.get.DefaultGetServlet

Request Progress:

0 TIMER_START{Request Processing} 0 COMMENT timer_end format is {<elapsed msec>,<timer name>} <optional message> 0 LOG Method=GET, PathInfo=/content/irlsoft/en/testt/_jcr_content.query.json 0 TIMER_START{ResourceResolution} 1 TIMER_END{1,ResourceResolution} URI=/content/irlsoft/en/testt/_jcr_content.query.json resolves to Resource=JcrNodeResource, type=irlsoft/components/structure/page, superType=null, path=/content/irlsoft/en/testt/jcr:content 1 LOG Resource Path Info: SlingRequestPathInfo: path='/content/irlsoft/en/testt/jcr:content', selectorString='query', extension='json', suffix='null' 1 TIMER_START{ServletResolution} 1 TIMER_START{resolveServlet(/content/irlsoft/en/testt/jcr:content)} 1 TIMER_END{0,resolveServlet(/content/irlsoft/en/testt/jcr:content)} Using servlet org.apache.sling.servlets.get.DefaultGetServlet 1 TIMER_END{0,ServletResolution} URI=/content/irlsoft/en/testt/_jcr_content.query.json handled by Servlet=org.apache.sling.servlets.get.DefaultGetServlet 1 LOG Applying Requestfilters 1 LOG Calling filter: com.adobe.granite.resourceresolverhelper.impl.ResourceResolverHelperImpl 1 LOG Calling filter: org.apache.sling.bgservlets.impl.BackgroundServletStarterFilter 1 LOG Calling filter: com.adobe.granite.rest.impl.servlet.ApiResourceFilter 1 LOG Calling filter: org.apache.sling.i18n.impl.I18NFilter 1 LOG Calling filter: com.adobe.granite.httpcache.impl.InnerCacheFilter 1 LOG Calling filter: org.apache.sling.rewriter.impl.RewriterFilter 1 LOG Calling filter: com.adobe.cq.mcm.campaign.servlets.CampaignCopyTracker 1 LOG Calling filter: com.day.cq.wcm.core.impl.WCMRequestFilter 1 LOG Calling filter: com.adobe.cq.history.impl.HistoryRequestFilter 1 LOG Calling filter: com.adobe.granite.optout.impl.OptOutFilter 1 LOG Calling filter: com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet 1 LOG Calling filter: com.adobe.cq.social.commons.cors.CORSAuthenticationFilter 1 LOG Calling filter: com.day.cq.analytics.provisioning.impl.UserAuthenticationRequestFilter 1 LOG Calling filter: org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter 1 LOG Calling filter: com.adobe.aem.irlsoft.core.filters.LoggingFilter 1 LOG Calling filter: com.day.cq.wcm.mobile.core.impl.redirect.RedirectFilter 1 LOG RedirectFilter did not redirect (not redirecting in author mode) 1 LOG Calling filter: com.day.cq.wcm.core.impl.warp.TimeWarpFilter 1 LOG Calling filter: com.day.cq.wcm.core.impl.AuthoringUIModeServiceImpl 1 LOG Calling filter: org.apache.sling.security.impl.ContentDispositionFilter 1 LOG Calling filter: com.adobe.granite.csrf.impl.CSRFFilter 1 LOG Calling filter: com.adobe.granite.requests.logging.impl.RequestLoggerImpl 1 LOG Calling filter: com.day.cq.dam.core.impl.servlet.ActivityRecordHandler 1 LOG Calling filter: com.day.cq.dam.core.impl.assetlinkshare.AdhocAssetShareAuthHandler 1 LOG Calling filter: com.adobe.cq.social.ugcbase.security.impl.SaferSlingPostServlet 1 LOG Applying Componentfilters 1 LOG Calling filter: com.day.cq.wcm.core.impl.WCMComponentFilter 1 LOG Calling filter: com.day.cq.wcm.core.impl.WCMDebugFilter 1 LOG Calling filter: com.day.cq.personalization.impl.TargetComponentFilter 1 TIMER_START{org.apache.sling.servlets.get.DefaultGetServlet#0} 1 LOG Using org.apache.sling.servlets.get.impl.helpers.JsonRendererServlet to render for extension=json 1 LOG Applying Error filters 1 LOG Calling filter: org.apache.sling.i18n.impl.I18NFilter 1 LOG Calling filter: org.apache.sling.rewriter.impl.RewriterFilter 1 TIMER_START{handleError:status=400} 2 TIMER_END{1,handleError:status=400} Using handler /libs/sling/servlet/errorhandler/default.jsp 5 LOG Found processor for post processing ProcessorConfiguration: {contentTypes=[text/html], order=-1, active=true, valid=true, processErrorResponse=true, pipeline=(generator=Config(type=htmlparser, config={}), transformers=(Config(type=linkchecker, config={}), Config(type=mobile, config=JcrPropertyMap [node=Node[NodeDelegate{tree=/libs/cq/config/rewriter/default/transformer-mobile: { jcr:primaryType = nt:unstructured, component-optional = true}}], values={jcr:primaryType=nt:unstructured, component-optional=true}]), Config(type=mobiledebug, config=JcrPropertyMap [node=Node[NodeDelegate{tree=/libs/cq/config/rewriter/default/transformer-mobiledebug: { jcr:primaryType = nt:unstructured, component-optional = true}}], values={jcr:primaryType=nt:unstructured, component-optional=true}]), Config(type=contentsync, config=JcrPropertyMap [node=Node[NodeDelegate{tree=/libs/cq/config/rewriter/default/transformer-contentsync: { jcr:primaryType = nt:unstructured, component-optional = true}}], values={jcr:primaryType=nt:unstructured, component-optional=true}]), serializer=Config(type=htmlwriter, config={}))} 6 TIMER_END{6,Request Processing} Dumping SlingRequestProgressTracker Entries

ApacheSling/2.4 (jetty/9.2.14.v20151106, Java HotSpot(TM) Client VM 1.7.0_80, Windows 7 6.1 x8
kautuk_sahni
Community Manager
Community Manager
August 31, 2016

Hi 

I just tested the article on AEM 6.2..

Please have a look at this video.

Link:- https://kautuksahni.tinytake.com/sf/OTQzNDM2XzM5Njc1NTE

I would request you to please try this package on fresh instance.

Thanks and Regards

Kautuk Sahni

Kautuk Sahni
kautuk_sahni
Community Manager
Community Manager
August 31, 2016

smacdonald2008 wrote...

I am away at Evolve AEM conference, back in Office on Fri. We can setup a connect session. We can solve this during a connect session. I want to see your code, etc. 

 

We need to add following line in our Ajex call at /apps/restservice/components/page/templateRest/templateRest.jsp

//

$.ajax(url, {

        crossDomain: true,
           dataType: 'text',

 

Now it is is working fine.

~kautuk

Kautuk Sahni
August 31, 2016

Hi Kautuk,

Thanks for troubleshooting but I just tried this also but it is not working.

It is working when we are using the same code base in to template renders component's directly.

 Case 1: Working -- when keeping the code in template renders component
 Case 2: Not working-- when keeping the code in to separate standalone component and dropping the component in different template page
Please have look at this video (I have captured both working and non-working cases) :

LINK:https://sameryadav.tinytake.com/sf/OTQ1NTEzXzM5NzI1NjQ

Thanks

Samer