Question:

XPM session preview causes error on DD4T Java 2

Henry: 5 days ago

I'm implementing DD4T Java version2, and trying to use experience manager, Tridion 2013 SP1. But when using session preview, following error occurs.

org.dd4t.core.exceptions.ItemNotFoundException: Unable to find page by url 
'/dd4tj2_cn/en/products-personal/index_e79d3951-0e67-491f-89d3-7584aa333306.html' and publication '64'.
    org.dd4t.providers.impl.BrokerPageProvider.getPageMetaByURL(BrokerPageProvider.java:150)
    org.dd4t.providers.impl.BrokerPageProvider.getPageContentByURL(BrokerPageProvider.java:97)
    org.dd4t.core.factories.impl.PageFactoryImpl.findPageByUrl(PageFactoryImpl.java:136)
    org.dd4t.springmvc.controller.DynamicPageController.handleRequestInternal(DynamicPageController.java:157)
    org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
    org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    com.tridion.preview.web.AbstractContentFilter.doFilter(AbstractContentFilter.java:77)
    com.tridion.preview.web.PageContentFilter.doFilter(PageContentFilter.java:9)
    com.tridion.ambientdata.web.AmbientDataServletFilter.doFilter(AmbientDataServletFilter.java:302)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.dd4t.servlet.filters.ImageFilter.doFilter(ImageFilter.java:217)

It seems that DD4T looks for a page that session preview will create, and there is not such a page in Broker DB. Why DD4T behaves this way? How can I make session preview work?

Regards,

Answer:
Harper: 5 days ago

This is how XPM works in a non-dd4t environment; it tries to push a file with random filename in the weboot and uses a filter to redirect the user there.

In a dd4t situation, you simply don't use the servlet filter prescribed by XPM. Instead, in your front controller, you check the taf:session:preview:preview_session token in the ambient data store; if that's present then your current request is a preview request. In such a case, you have to make sure that your page lookup is served straight from the Broker and you have to bypass dd4t cache. You can do this in multiple ways depending on the dd4t version you have - either by using a NoCacheAgent in dd4t-1 in a seprate "preview page factory", or by using the preview-aware factory in dd4t-2.