简体   繁体   English

浏览器和Java组件之间的通信

[英]Communication between browser and java component

I am currently working on a point of sale application. 我目前正在研究销售点应用程序。 we have a existing system based on java which uses javapos to integrate with the devices (such as receipt printer, cash drawer , MSR etc). 我们有一个基于java的现有系统,该系统使用javapos与设备集成(例如收据打印机,现金抽屉,MSR等)。 now we are trying to port the java based thick client to service enable , so it is set to become a web app backed by html5 and spring webservice 现在,我们正在尝试将基于Java的胖客户端移植到service enable,因此它将设置为由html5和spring webservice支持的Web应用程序

my problem is to integrate the devices to the web ie browser so that the cashier can access the point of sale application from the browser . 我的问题是将设备集成到网络(即浏览器)中,以便收银员可以从浏览器访问销售点应用程序。

how do i integrate the devices to the web app now. 我现在如何将设备集成到Web应用程序。 one option i have is deploying a java component in the register and make it communicate it to browser via websocket. 我有一个选择是在寄存器中部署一个Java组件,并使其通过websocket与浏览器通信。

browser<-> websocket <-> java device component in local system 浏览器<-> websocket <->本地系统中的Java设备组件

Is there any better way to do this? 有什么更好的方法吗? i need the technology which enable me to do the same. 我需要使我能够做到的技术。

i have considered the applet as well but the problem is the local java component is kinda huge and it will have different device drivers for each system. 我也考虑过该applet,但是问题是本地Java组件相当庞大,并且每个系统都有不同的设备驱动程序。

JavaFX offers a pretty decent web browser component, that allows easy communication between the Javascript code that runs in the page and the Java code outside. JavaFX提供了一个相当不错的Web浏览器组件,该组件使页面中运行的Javascript代码与外部的Java代码之间的通信变得容易。 You could port your application so that: 您可以移植您的应用程序,以便:

  1. It uses JavaFX, openning a window with just a browser component and pointing it to your web application 它使用JavaFX,仅使用浏览器组件打开一个窗口并将其指向您的Web应用程序
  2. Implement the web app as normal - it will display in the browser component 正常实施网络应用-它将显示在浏览器组件中
  3. Move the device-specific Java code in the JavaFX app, expose its methods to the browser; 在JavaFX应用程序中移动设备特定的Java代码,将其方法公开给浏览器; now the Javascript code will call Java and (hopefully) you will be able to reuse most of your existing code, excluding UI code of course 现在Javascript代码将调用Java,(希望)您将能够重用大多数现有代码,当然不包括UI代码

A "Hybrid" JavaFX/HTML application example is iBreed (it is a framework that you can use actually). iBreed是“混合” JavaFX / HTML应用程序示例(它是您可以实际使用的框架)。

I think you can make it work, but you will need one more piece of software. 我认为您可以使其正常运行,但是您将需要另外一个软件。

  1. Webserver (hosting the HTML-files and API) 网络服务器(托管HTML文件和API)
  2. Client PC (runnning the HTML-frontend in a browser) woth conected devices 客户端PC(在浏览器中运行HTML前端)都连接了设备
  3. new service running on the client PC, with a Web-API for the connected devices 在客户端PC上运行的服务,带有用于连接设备的Web-API

I think, this is exactly the same approach as you mentioned with websockets. 我认为,这与您在websockets中提到的方法完全相同。 (Ony for older browser). (仅适用于较旧的浏览器)。

Take a look at atmosphere. 看一下气氛。 This may help you to get the websocket stuff done: https://github.com/Atmosphere/atmosphere 这可以帮助您完成websocket的工作: https : //github.com/Atmosphere/atmosphere

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

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