简体   繁体   English

我如何从HttpServlet执行Gravity数据推送

[英]How do i perform Gravity data push from HttpServlet

Last few days i was playing with GranideDS tutorials (using Spring server and AIR client) 最近几天,我在玩GranideDS教程(使用Spring服务器和AIR客户端)
https://github.com/graniteds-tutorials/graniteds-tutorial-data https://github.com/graniteds-tutorials/graniteds-tutorial-data

"This tutorial shows how to build a simple data application that manages a database of user accounts. All connected clients are notified and synchronized with data updates using a GraniteDS long polling channel." “本教程展示了如何构建一个简单的数据应用程序来管理用户帐户数据库。所有连接的客户端都可以通过GraniteDS长轮询通道得到通知并与数据更新同步。”

Unfortunately i cannot find any GraniteDS javascript client library or example. 不幸的是,我找不到任何GraniteDS javascript客户端库或示例。
I created an HttpServlet to manage (add Entity for example) persistense context using http (ajax) requests. 我创建了一个HttpServlet来使用http(ajax)请求来管理(例如添加Entity)持久性上下文。

my TestServlet.java 我的TestServlet.java

@WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;     

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
        AccountService srvObject = (AccountService) wac.getBean("testService");
            //testService mean spring service annotation parameter
        Account emp = new Account();
               emp.setName(request.getParameter("name"));
               emp.setEmail(request.getParameter("email"));
        srvObject.save(emp);
        response.getWriter().println("OK");
    }
}

This method adds an entity correctly but connected client's data are NOT syncronized. 此方法正确添加了一个实体,但连接的客户端数据未同步。 How can i notify all clients about new changes? 我如何通知所有客户新变化?

UPDATE: I was trying to change DataEnabled's publish to PublishMode.ON_COMMIT 更新:我试图将DataEnabled的发布更改为PublishMode.ON_COMMIT

@DataEnabled(topic="dataTopic", publish=DataEnabled.PublishMode.ON_COMMIT, useInterceptor=true)

add to application-context.xml 添加到application-context.xml

<graniteds:tide-data-publishing-advice/>

In this case both air application and servlet causing server error: 在这种情况下,空中应用程序和servlet都会导致服务器错误:

SEVERE: Could not register synchronization for ON_COMMIT publish mode, check that the Spring PlatformTransactionManager supports it and that the order of the TransactionInterceptor is lower than the order of TideDataPublishingInterceptor 严重:无法为ON_COMMIT发布模式注册同步,请检查Spring PlatformTransactionManager是否支持该同步,以及TransactionInterceptor的顺序是否低于TideDataPublishingInterceptor的顺序

And <graniteds:tide-data-publishing-advice order="-1"/> does not helps. <graniteds:tide-data-publishing-advice order="-1"/><graniteds:tide-data-publishing-advice order="-1"/>

您可以尝试使用useInterceptor = true的模式ON_SUCCESS“ useInterceptor = true”,因为这会使GraniteDS意识到您的服务,而这完全超出了它的控制范围

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM