In this scenario. I have a web application, that runs in the browser, and now I want to access the scanner of the local desktop.
As far as i can see, the only option is installing some type of local agent in each computer, through java or an agent app (.exe).
Example: scanner.js
My question is just about the logic, not code.
Ok, I have a website. Now how the website can connect and communicate with the agent? How can i define the communication port?
What is the concept design of this type of process between an agent that have access to hardware and the local browser?
Ok, I have a website. Now how the website can connect and communicate
with the agent? How can i define the communication port?
In common, agents provide Rest or SOAP API, and website script send JSON/XML requests. But don't foget about security and authentication.
List of lib and frameworks:
Rest
framework,
SOAP,
WebServers,
Security and
Authentication
One of the options is indeed a local agent that runs on the PC of the user. That local agent could be a web server with a port open to connect to from browser. Calls to the service should be protected so that others can't abuse the service. The communication could take place via websockets.
Resources that might be interesting to check are:
Tutorial CORS
NanoHTTPd
Related
I have separate application for client side which is in ReactJs and NodeJS (Express server) and Web Services in Java application running in tomcat.
My query is which is better approach in terms of making web service call.
One is making direct web service call from ReactJS and get the data.
Other one is calling web service in Express server. Request from client browser will go to Express and Express will make all web services call.
I know one issue in making direct call to web service will be cross domain policy which can be handle by setting configuration in Java server.
Apart from it what should be better approach.
From my experience it ended up better using direct calls from UI application and avoiding intermediate server.
Reason for doing this directly is that our servers ended up with a lot of restrictions based on IP addresses, and all requests have been coming from intermediate server (nodeJS server), so DDOS protection of end server had to have some exceptions (our node server which could be on ACS with dynamic IP addresses so it might be hard to manage).
Also If you want to pass and track end users IP addresses, you need to manage headers on Node server (to be sure you are passing it as it was in original request).
It is way simpler to manage this kind of situation if calls are comming from React app and simply set up CORS on java server.
Also its way easier to debug it on UI app directly, so you will be watching response logs on one place only. Other way around you could end up debugging your node server and UI app.
Hope this helps a bit.
Best way IMO is to create a router in Node js specifically for all your Java webservices and act as a proxy.
Suppose if your url pattern is like http://domain/java-ws/api then all these requests will be routed to your Java service.
If you have an Apache server directing requests to your node JS then configure url pattern proxy using proxy module.
Browsers are blocking CORS requests for a reason. You may get away by setting things on your server.
I'm thinking about what might be the best solution to create a standalone client-server application in java with these features:
Server: it must provide APIs (probably rest?)
Client: javafx webview with angularjs to make requests to webserver.
Loader; it starts the server and the client;
The user can then manage the application directly from the webview or from the browser (to the server port)
This would also be able to create in the future a "cloud" version of the application, the client instead to query the localhost will perform to a remote server.
A solution of this type is correct?
What might be useful tools for its realization and how could it be structured?
I would like in particular a solution which does not require the use of a large Java Application Server, but something more simple that it can be included as a library.
I thought same architecture which you think because it's easy. localhost binding, angularjs, bootstrap in java Webview. one of solutions is Spring MVC Rest API with embedded tomcat. it may be not lightweight.
I have a JavaScript embedded in a website, running in a normal browser, and I have a Java Application running on the same machine. I am looking for a way have both communicate with each other.
I assume that creating files in the local file system from inside JavaScript running in a browser is out of question.
The only way I came up with would be to use a server that both programs can send messages to, and from which they poll for new messages.
Is there any other other way to accomplish this?
A couple of ways I saw in practice:
You Java Application may listen to some local port which your JS will access for instance via XHR. You'll need to mind cross-site scripting (your JS may need to be loaded from that local URL), but this is doable. The easiest would probably be to run an embedded HTTP server.
Your Java Application may be registered as a protocoll handler in the OS. Then JS would open links registered with the application thus sending data to it.
As #PavelHoral is pointing out, CORS is a way to workaround same-origin policy.
JavaScript inside a browser can only make AJAX requests or communicate with browser plugins if they provide some additional JS interface.
Local HTTP connection
One option is to listen for HTTP connections in your Java application (does not have to be servlet).
You will need to handle CORS correctly.
Central server
Other option is to have a central server to which both your JS and Java code will connect.
Java applet
Another option is to have Java applet. When running in privileged mode you can do pretty much anything (maybe you can convert your Java application to Java applet).
You will need to handle applet security here (e.g. signing applet with trusted certificate).
Please refer to this question for direct sockets communications from within javascript. You'll need a HTML5 browser, and likely this won't "just" work or necessarily be a good idea if you want to publish this on the WWW.
How to Use Sockets in JavaScript\HTML?
I am learning to program Java. My objective is to create client server application based on Java and MySQL.
That would have following.
Server Application where all admin controls would be available to configure.
server application will be the only to have access rights to MySQL.
Server will have all functions and objects that clients will require and call and get that functionality. (Reason for that is "I don't want to share MySQL credentials to client apps or rather i don't want MySQL credentials to be transmitted on the network to clients"). As it would increase maintenance tough and it could be a security loop hole.
An analogy of functionality could be: client calls to server telling to add an Order such addOrder(order_id, payment,..,...,..) and so on.
What are the method in practice for such kind of application these days? A example code/or material to get in right direction would suffice
These days the universal way to expose a service remotely is via a web service. This solution was preferred by the industry over time due to its simplicity and ease of integration to the point that binary based protocols like CORBA are now seldom used.
Take the example of Android applications, they are native application mostly using REST web services.
A REST web service can be easilly integrated in the same way with a desktop application, a mobile application or a web application, even if the clients are written in different native platforms and languages.
As sample code, have a look at tutorials on the Spring stack. For the server see this tutorial for building an hello word REST web service. For the client, consider the REST template.
For security, see this Spring security hello world example. Using the Spring stack in Java will likelly give you the largest number of tutorials and online support.
This sounds like a good place to use RMI, which Java has built in support for. RMI will allow your client to call server-side methods on a local object that corresponds to the server, where all messages/commands get transparently sent to the actual server, where you have your DB access stuff and logic.
My project is an Android application that communicates with a server. The server is written in Java, deployed in Tomcat, and running on a Windows Server host.
I need to provide authentication against Windows domain accounts. Basically I need to ask the user of the app to type in their username and password; send this data to the Tomcat server; and have the server authenticate it.
I'm having trouble finding a straight answer as to how to do this. Since my app is not a web site, I don't have the option to do browser redirects or anything like that, and obviously the Android device on which the app runs is not a Windows machine and will most likely not even be on the local network.
I don't really need to execute anything as the Windows user, I just need to know that they are who they say they are. Hopefully there is a simple way to do this?
Thanks.
Assuming you want to use Java EE container-based form authentication, on the server you'll have to:
secure your web application
configure Tomcat to use Windows authentication
On the client, you can:
POST application/x-www-form-urlencoded login data with the special keys in the web form (j_password, etc.)
retain the session cookies in the response for subsequent interactions with the server
I haven't tested the specifics with these exact technologies but approach is sound.