I have a DXA 2.0 webapp with Web 8.5 working without issues. I am trying to build a REST API in DXA to spit out JSON content of a DCP. I'm able to use the Broker API (ComponentPresentationFactory
) to get the content without issues. I'm having issues when I use DXA API to get the DCPs. So in the AdminController
, I have two GET requests created. One returns the index page model without any errors.
@GetMapping(value = "/getpagemodel")
public @ResponseBody PageModel getPageModel() throws Exception {
PageModel pageModel = contentProvider.getPageModel("index", webRequestContext.getLocalization());
return pageModel;
}
It's when I try and get an entity model, I'm seeing errors. It's able make a GET request to "http://localhost:8998/EntityModel/tcm/19/999-815", but fails when the mvc data is created. I don't see MvcData
object in the JSON of the GET request. There is a NullPointerException
in createMvcData
.
@GetMapping(value = "/getentitymodel")
public @ResponseBody EntityModel getEntityModel() throws Exception {
// 999 is component item id and 815 is the component template item id
EntityModel entityModel = contentProvider.getEntityModel("999-815", webRequestContext.getLocalization());
return entityModel;
}
Logs when I try and get the entity model:
3:12:33.637 [http-nio-8080-exec-7] DEBUG o.s.web.client.RestTemplate - Created GET request for "http://localhost:8998/EntityModel/tcm/19/999-815" 23:12:33.637 [http-nio-8080-exec-7] DEBUG o.s.web.client.RestTemplate - Setting request Accept header to [application/json, application/*+json] 23:12:33.812 [http-nio-8080-exec-7] DEBUG o.s.web.client.RestTemplate - GET request for "http://localhost:8998/EntityModel/tcm/19/999-815" resulted in 200 (null) 23:12:33.827 [http-nio-8080-exec-7] DEBUG o.s.web.client.RestTemplate - Reading [class com.sdl.dxa.api.datamodel.model.EntityModelData] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@116eb89] 23:12:33.827 [http-nio-8080-exec-7] DEBUG o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - Resolving exception from handler [public java.lang.String com.sdl.dxa.controller.AdminController.getEntityModel() throws java.lang.Exception]: java.lang.NullPointerException 23:12:33.827 [http-nio-8080-exec-7] DEBUG o.s.w.s.m.a.ResponseStatusExceptionResolver - Resolving exception from handler [public java.lang.String com.sdl.dxa.controller.AdminController.getEntityModel() throws java.lang.Exception]: java.lang.NullPointerException 23:12:33.843 [http-nio-8080-exec-7] DEBUG o.s.w.s.m.s.DefaultHandlerExceptionResolver - Resolving exception from handler [public java.lang.String com.sdl.dxa.controller.AdminController.getEntityModel() throws java.lang.Exception]: java.lang.NullPointerException 23:12:33.859 [http-nio-8080-exec-7] DEBUG o.s.web.servlet.DispatcherServlet - Could not complete request java.lang.NullPointerException: null at com.sdl.dxa.tridion.mapping.impl.DefaultModelBuilder.createMvcData(DefaultModelBuilder.java:141) at com.sdl.dxa.tridion.mapping.impl.DefaultModelBuilder.buildEntityModel(DefaultModelBuilder.java:109) at com.sdl.dxa.tridion.mapping.impl.ModelBuilderPipelineImpl.createEntityModel(ModelBuilderPipelineImpl.java:86) at
The output of the entity model request is below. The MvcData
object isn't present so I guess when DXA tries to create the mvc data, a null pointer exception is thrown.
The output of the page model request is below.
So my question is:
- How can I use
ContentProvider
to get the content of a DCP without registering a view model?