event java google app engine - java

I just started using google app engine to develop a web application and I'm a little lost on how to deal with events sent from buttons properly.
For some reason, when I try to use a JButton on my application I get this error.
"javax.swing.JButton is not supported by Google App Engine's Java runtime environment"
the only way I managed to get an on_click event so far was to use an html button and use a "post" or "get" requests.
So, is their a tutorial somewhere to help me understand better how to use buttons and other components in my application?

I think you have a deep misunderstanding of what Google AppEngine does. You deploy your code to AppEngine, and it runs on Google's servers. It generally interacts with users in the form of HTTP requests. A user enters a URL, and the Java code might send back some HTML and javascript.
A JButton is a Java Swing component, which is used when developing Java software to run on an end user's machine. Your AppEngine app is not going to run on an end user's machine. You are seeing that error message, because GAE has a whitelist of allowed classes from the JRE.
https://developers.google.com/appengine/docs/java/jrewhitelist
It's possible you may be thinking of Google Web Toolkit(GWT). GWT allows you to write the client/server of a web application in Java, and then cross-compile the client into javascript. This is separate from AppEngine. Although you can develop a GWT application, and deploy it on AppEngine.

Related

How to create a desktop app for the existing web application?

Well, I've tried to do some researches before creating a question but only a little has been found.
Basically, I have got a Spring-based web application. Apparently, you can navigate through web application using HTTP requests and URLs. If you want to edit a user you do a GET request /users/edit/{id} and a new page appears. Then you make some changes to the user and do a POST request /users/edit/{id} and let's say the main page appears.
So, now I need to create a desktop application which can do the same things.
Do I need to rewrite the whole app to port it on the desktop? Is it possible somehow to do sort of HTTP requests from the desktop app to the server, then get a response and process it? Or perhaps there is a proper way to do it?
I feel like it's a big topic but I only need you to point me in the right direction as I'm lacking experience in creating both desktop and web applications together (I'd say, I have never ported app from web to desktop and vice verse).
Earlier I created a few apps using JavaFX and I want to use it again as my GUI platform for the desktop app.
You can go for a solution like, Electron.
It's a framework for creating native applications with web technologies like JavaScript, HTML, and CSS. It uses Chromium and Node.js. You can develop your desktop GUI applications using front and back end components originally developed for your web application.
I'm just pointing you a way. You can look in to this solution and it's also open-source.
If you were about to develop the frontend from scratch I'd recommend you to use something like Ionic Framework where in the latest beta 4 allows you to write once run everywhere (web, PWA, desktop with Electron, and build native build for iOS and Android).
Basically Ionic is an Angular 7 library/superset that allows you to create mobile apps based on a webview. This webview can be embedded and run on any device in a native way.
Even though the same codebase can be run on multiple devices you can customise the look and feel on each platform and access through Cordova, Electron or Capacitor the native device capabilities and hardware.
If you don't want to rewrite the web client, you can use any desktop framework with the preferred language you want. Any modern language/framework will allow you to make HTTP requests against your backend and get the data through your API.
Honestly, nowadays I'd day that JavaFX is not the best option out there and I'd recommend you to go through the web-based approach.
Good luck!

What is the alternatives for Java Applet to launch client programs using Chrome browsers?

I am working in a web application using ASP.net and C#.
My target is to check on a desktop application on the client machine .. If it was exist then I should launch it. Else if it wasn't exist, we should download, install and then launch it.
I could develop this module using Java Applet but unfortunately, Google decided to disable NPAPI in September 2015, So the applet will not working on Chrome.
My question is about the Applet alternatives to help me implementing the above scenario ?
The only (semi) viable option as far as I can see, is to offer the Chrome user a link to a JNLP file for a desktop application. Then when/if the JWS desktop application starts, have it report back to the server 'loaded OK' and then 'target app. installed/not installed'.
On your server, have a time out for waiting on the client to report back. If it passes that time, presume the client machine does not support Java at all and the user is checking some web service to try and figure out what app. opens a JNLP!
After searching about the most suitable way to achieve my goal, I think using custom protocols will be a nice solution to access my client applications from the web page.
This solution is used by many companies such as Microsoft (using mailto: to open Outlook application) and Apple (using itms: to open iTunes application).
The following link is a very good link which talk about a custom protocols:
https://support.shotgunsoftware.com/entries/86754-How-to-launch-external-applications-using-custom-protocols-rock-instead-of-http-
Once Google Chrome was the first to announce that they won’t be supporting NPAPI anymore, they were also the first to provide a new architecture in order to rewrite your code to work on their browser. You can take a look on Native Messaging, which “can exchange messages with native applications using an API that is similar to the other message passing APIs”. The problem is that this approach only works on Chrome, is not something that you can adapt to other browsers.
A more useful approach is FireBreath, a browser plugin in a post NPAPI world. Check the words below from one buddy of the project:
“FireBreath 2 will allow you to write a plugin that works in NPAPI, ActiveX, or through Native Messaging; it’s getting close to ready to go into beta. It doesn’t have any kind of real drawing support, but would work for what you describe. The install process is a bit of a pain, but it works. The FireWyrm protocol that the native messaging component uses could be used with any connection that allows passing text data; it should be possible to make it work with js-ctypes on firefox or plausibly WEB-RTC or even CORS AJAX in some way. For now the only thing we needed to solve was Chrome, but we did it in a way that should be pretty portable to other technologies.”

Transitioning from Java to Google App Engine

I am writing a Java program for my workplace, to help catalog pricing with several parameters involved. The current program implements JComboBox, along with other Container objects.
I have realized that our workstation will not run a Java program through Windows due to protective limitations, so I am hoping to transition to Google App Engine, since we can load websites much more freely.
The problem I have run into is that JComboBox doesn't run through Google App Engine. In fact, none of the Containers I was using will work in Google App Engine. The tutorials on Google Developers haven't provided the information I need.
Where can I find information on what objects I can use in Google App Engine to simulate a GUI with pop-up menus and buttons?
(I am using the Google Plugin for Eclipse.)
Maybe this link will help you, it lists all compatible frameworks: http://code.google.com/p/googleappengine/wiki/WillItPlayInJava
For a higly responsive GUI, I suggest you take a look at the GWT: http://www.gwtproject.org/examples.html
In a nutshell: GWT allows you to write web applications with Java. Some/all of the Java is converted into JavaScript for better usability.
If you want to use Google App Engine (GAE) you can either use GWT for a standard GUI or a Java Webframework like Vaadin or JSF.

How do I connect my Desktop Java Application to an Existing GAE Datastore?

Currently I have a very basic desktop Java application in Eclipse that is meant to add entities to an existing project's datastore on Google App Engine. I have it all setup right now but since I am new to working with Google App Engine, I have no clue on how to get the application to send the Entities into the datastore of my existing project.
I tried looking this up online but most of what I found was for making java web apps. My goal is to have the application running as its own application, not through a browser.
So, what do I have to do to make the application connect to my GAE datastore? Is there some code I need to type, or perhaps some xml file I need to have within the project? I am just using the Java Eclipse plugin for Google App Engine.
Thanks for the help!
Based on the language of your question, I think you really need a big-picture sort of answer, rather than any specific code. Therefore:
You have a desktop application. This runs on some desktop computer.
You have a Google App Engine application with its data store. This runs in Google's data centers.
These are not the same computer. Therefore, they must communicate over the network in some fashion — that is the missing piece you're looking for.
Since GAE is designed around doing web applications, I recommend you think of this as a “web service” situation — that is, your desktop application makes HTTP requests to your GAE application. (The situation is simplified over the general case because you are writing both the client and the server.)
I recommend you read about designing simple web services and do whatever seems to fit your application.
One important warning: Unless your GAE application only ever has one user, you must not simply write a bridge that gives access to the data store over HTTP, because then anyone can make arbitrary changes to other people's data. As it is said for multiplayer game design: don't trust the client — that is, only accept network requests that make sense according to the rules of your application, and do not expect the client to enforce those rules. This is because anyone can make requests to your GAE application using something other than your desktop application, so you must assume you could receive arbitrary requests. This is the fundamental nature of the Internet.
For example, in the simple case of a multi-user application whose users do not interact with each other using the application, this means that every request that, say, updates a record, should only update a record which belongs to the logged-in user, not one of any other user.
For anyone that gets this problem in the future, I got an answer to it. I just tried experimenting around with the project settings and found it. So as it turns out, after you have installed the GAE Eclipse Plugin, you can just right click your project folder in the Package Explorer, go the Google sub menu, then click on App Engine Settings... .
From there, you need to check the Use Google App Engine checkbox, then in the deployment section, just fill in your project's Application ID. Your project's application ID can be found under the Application Settings tab of your project's online Google app engine dashboard. It is listed there as your Application Identifier.
Turns out that for me, I will need to find a different solution as you cannot integrate GAE with a desktop application that uses the Java Swing library. Bummer :/

How to play a sound in a JSF web app?

Is it possible to play a sound (.wav or .mp3) in a client's browser using a JSF web app?
I have tried using javax.sound.sampled.SourceDataLine and it worked on Windows, but when I deploy the .war on a Linux host I get this exception:
"javax.sound.sampled.LineUnavailableException: Audio Device Unavailable"
Java code executes on the server to generate web pages that are displayed in the client's browser. If you have JSF web app code using the javax.sound.sampled.SourceDataLine class, the sound will play on the server (if this is even possible...), not in the client's browser.
To play a sound at the client, you'll either have to reference an audio file in the web page as Pascal Thivent has posted, or you'll have to play the sound through a Flash/Silverlight/Java Applet plugin referenced in the page.
Is it possible to play a sound (.wav or .mp3) in a client's browser using a JSF web app?
I should have mentioned that, but this has nothing to do with JSF or any other server-side technology. If you want to play a sound on the client-side, generate the appropriate client-side code, i.e. HTML here.
HTML 5 has an <audio> tag but, until it gets mainstream, see Playing Sounds on a Web Site and How To Play Sound (which does a good job at summarizing the solutions) to learn more on the <embed> tag and the <object> tag.
I have tried using javax.sound.sampled.SourceDataLine and it worked on Windows, but when I deploy the .war on a Linux host I get this exception: "javax.sound.sampled.LineUnavailableException: Audio Device Unavailable"
This exception literally means that the machine where the code runs doesn't have an audio device. I can imagine that it is very reasonable that webservers doesn't have any audio device, this namely doesn't make any sense.
As others have pointed out, you need to play sound at the client machine. You can find here a lot of background information and examples.
Not via JSF but you can use primefaces for an app like that http://www.primefaces.org/showcase/ui/media.jsf

Categories

Resources