0

我只需要和想法来解决这种情况:我们制作了一个 Swing 应用程序来通过串行端口捕获数据,此捕获会触发一些警报(在 JPane 中呈现),同时此信息存储在数据库中以提供一些统计信息(使用 JFreechart 和 JasperReports)。现在,我们想在 Web 基础界面中呈现相同的信息,并且我们正在考虑使用 JSF + Primefaces over Apache Tomcat 7 应用程序。

统计数据不是问题,我们关心的是如何通知 Web 应用程序在串行端口中触发了一个事件,以显示与 Swing 应用程序进行的捕获在客户端浏览器中显示相同的警报?。最终用户想要保持两种格式:本地视图 (Swing) 和用于管理目的的 Web 视图。

我们的建议是正确的吗(Swing -> JSF + Primefaces)?还有其他选择吗?

提前感谢您的任何想法

4

1 回答 1

0

我找到了解决问题的方法。我把找到的解决方案留在这里,首先: 1. 为了测试我使用 Glassfish 3.1.2.2 而不是 Tomcat 7、Netbeans 7.3 和 PrimeFaces 3.5 的解决方案 2. 我根据本教程制作了一个示例应用程序。3.我实现了PrimeFaces演示页面的PimePush Counter示例。4.我做了一个Swing应用,用一个按钮来模拟串口捕获的动作,这个应用使用ws在web应用中推送内容。5. GF 已启用 Comet 和 Web 套接字支持。

但是有一个问题,每次我重新启动 Glassfish 时,都必须取消部署应用程序并再次重新部署,以便 Web 服务可用。为什么会这样?,我错过了什么?

这里的代码:

ws 类:

@WebService(serviceName = "BotonService")
@Stateless
public class BotonService {

    private boolean push = false;

    @EJB
    private ServiceShare servicio;

    /**
     * This is a sample web service operation
     */
    @WebMethod(operationName = "hello")
    public String hello(@WebParam(name = "name") String txt) {
        return "Hello " + txt + " !";
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "setPush")
    public void setPush(@WebParam(name = "push") boolean push) {
        this.push = push;
        servicio.setPush(push);
        servicio.firePush();
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "getPush")
    public Boolean getPush() {
        return this.push;
    }  
}

这里是 ManagedBean 类:

@Stateless
@ManagedBean(name = "globalCounter")
@ApplicationScoped
public class GlobalCounterBean implements Serializable {

    private int count;
    private String CHANNEL = "/counter";

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public synchronized void increment() {
        count++;
        PushContext pushContext = PushContextFactory.getDefault().getPushContext();
        pushContext.push(CHANNEL, String.valueOf(count));
    }
}

这里是一个用于将 WS 与 Managedbean 通信的 EJB:

@Stateless
public class ServiceShare {

    @EJB
    private GlobalCounterBean counter;

    private boolean push = false;

    public boolean getPush() {
        return push;
    }

    public void setPush(boolean push){
        this.push = push;
    }

    public void firePush(){
        if(this.push){
            counter.increment();
        }
    }
 }

JSF 页面与 PrimeFaces 演示中的页面完全相同。

每次我在我制作的 swing 应用程序中按下按钮时,计数器都会在每台连接的机器上更新,这就是最终应用程序的想法。但是,为什么我必须重新部署 Web 应用程序才能让 Swing 应用程序中的 ws-client 找到它?为了避免这种行为,我在 GF 服务器中是否缺少任何配置?

于 2013-05-20T01:58:58.797 回答