Applet Integration/Screenshot add ons

Hi,

I’ve made some progress with Applet Integration but I’m not quite there yet. Dmitry was kind enough to send me an application/applet demo as a maven project, and I was able with his help to get it working under Eclipse. Also, I can substitute my applet for his demo applet and have it work inside his application.

What I still can’t do is build the screenshot add-on. When I try, the application runs, and when I press the “Take a screenshot button”, java starts up, I am asked for permission to run the applet, the java console starts up, etc. But the applet doesn’t work – if I drag and then release the mouse, the image does not appear in the application’s image window. The java console does not report any errors. This is on OS X Lion with Safari and Firefox.

This matters, because I think what I need to do is more like screenshot than Dmitry’s application/applet. He runs his applet from a subclass of AppletIntegration, whereas screenshot uses a subclass of Upload. I think I need to do the latter, because what I am trying to do is use the applet to record a sound clip on the client, and then upload this to my server. Upload provides facilities for file upload, whereas AppletIntegration does not (as far as I know).

The screenshot applet has a doPostToServer() method. I assume that this ties in somehow to the Upload.Receiver and Upload.FinishedListener interfaces that are implemented in Screenshot.java, presumably through server side components for Upload in Vaadin’s basic widgetset. Is that correct?

Would it be possible to release screenshot in a form that can be more easily rebuilt? Any advice on getting it working? Is it possible to upload a file to an AppletIntegration subclass, rather than to an Upload subclass?

Thanks very much,

Matthew Fleming

Upload provides facilities for file upload, whereas AppletIntegration does not (as far as I know).

You’re right. AppletIntegration offers simple String/double/int communication mechanism, but streaming data is made using the multipart request like in Upload.

Yes, under the hood the server-side Screenshot extends Upload and implements the receiver.

Well I haven’t found a nice way. And still I don’t think that helps you with your own applet anyway.

This “complicated build problem” is mostly about the signing. Someone has to sign the packages to be able to run an applet that accesses local computer. Another thing here is the fact that if you extend the AbstractVaadinApplet you need the appletintegration jar file in compilation classpath as well as available online for the browser.

Based on my own tests lately, I’d guess that this might have something to do with your Vaadin version. What version are you using? Also I noticed a timing issue in the screenshot that it won’t always work on first load and page reload is needed.

Also put the application in debug mode (use parameter ?debug in your url) and check what is the output in the Java console. Also use the most verbose logging to see network requests.

This should be possible, but you would have to implement the Upload functionality yourself. Based on what I saw in the Upload class I didn’t want to try :wink:

I have included the appletIntegration.jar in the compilation classpath. As for signing, mostly I’ve been just using the screenshot.jar obtained by unpacking screenshot-0-1.8.2.jar. jarsigner -verify shows that this is (self-) signed, though the signature has expired. I also tried rebuilding a screenshot.jar myself and then self-signing it, with the same result.

6.6.4

The ?debug thing was really helpful. I didn’t realize this affects the output to the java console. With that, it appears that there is some sort of timing issue, as you suggest. Initially it shows the applet loads but does not respond to mouse drags. However, if I refresh the browser and then try to drag, I get this:


debug: true
debug: appletId=v-appletPID6
debug: paintableId=PID6
debug: applicationURL=http://localhost:8080/screenshot/
debug: sessionCookie=JSESSIONID=B9D80FE2DF5D71B52E5FBB12D5544F0E
debug: actionUrl=http://localhost:8080/screenshot/
debug: Poller thread started.
debug: Screenshot applet loaded
debug: Poller thread stopped.
debug: true
debug: appletId=v-appletPID12
debug: paintableId=PID12
debug: applicationURL=http://localhost:8080/screenshot/
debug: sessionCookie=JSESSIONID=B9D80FE2DF5D71B52E5FBB12D5544F0E
debug: actionUrl=http://localhost:8080/screenshot/
debug: Poller thread started.
debug: Screenshot applet loaded
debug: Received JavaScript command 'screenshot'
debug: Taking screenshot...
debug: Exception java.security.AccessControlException: access denied (java.awt.AWTPermission createRobot)
java.security.AccessControlException: access denied (java.awt.AWTPermission createRobot)
	at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
	at java.security.AccessController.checkPermission(AccessController.java:546)
	at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
	at java.awt.Robot.checkRobotAllowed(Robot.java:129)
	at java.awt.Robot.init(Robot.java:115)
	at java.awt.Robot.<init>(Robot.java:77)
	at org.vaadin.screenshot.applet.ScreenshotApplet.doTakeScreenshot(ScreenshotApplet.java:103)
	at org.vaadin.screenshot.applet.ScreenshotApplet.doExecute(ScreenshotApplet.java:417)
	at org.vaadin.applet.AbstractVaadinApplet$JsPollerThread.run(AbstractVaadinApplet.java:339)

I must confess I have absolutely no idea what this means. I believe I was able to run screenshot on my computer in the past from your demo site (http://sami.virtuallypreinstalled.com/screenshot), although that site is apparently not online on the moment.

One more question, please. My applet has its own UI, consisting of Swing controls which are layer out in its init() method. If I load it with Dmitry’s test application, which uses a subclass of AppletIntegration, the UI appears as it should. However, when I’ve tried to load the applet with a subclass of Upload, the java console shows that the applet loaded without problems (no errors reported with ?debug), but the UI never appears. Does the layout of UI components have to be handled differently for AppletIntegration and Upload subclasses? The screenshot example didn’t really answer this question, because it doesn’t have a UI to speak of.

Thank you very, very much for your help.

Matthew Fleming

debug: Exception java.security.AccessControlException: access denied (java.awt.AWTPermission createRobot)
java.security.AccessControlException: access denied (java.awt.AWTPermission createRobot)

This still suggests a problem signing the applet. I included the build file I used to build the screenshot apple project in the svn: http://dev.vaadin.com/svn/contrib/Screenshot/sample-build.xml

I think you mean your server-side class is subclass of Upload - not the actual applet? (Applet class should extend the java.applet.Applet)
Cannot say for sure what is the problem, but I suggest to take a good look at the paintContent method in the
Screenshot.java
. It is where the data is pushed to the client-side (to the browser that is)

Upload is a server-side class that you you can extend to implement the server-side part of your widget. More typical option is to extend the AppletIntegration class. This is one of the places where multiple inheritance would be nice…

I also thought it should be a problem with signing the applet. But I am loading the applet (I think) from screenshot.jar extracted from screenshot-0-1.8.2.jar. This screenshot.jar was signed (by you). However, when Eclipse is loading the applet maybe it is getting it from somewhere else … I’ll investigate. Thank you for the svn. I’ll have a look at that too.

Yes, the server-side class is a subclass of Upload. It is analogous to your Screenshot class. The Applet is actually a subclass of AbstractVaadinApplet, which I believe is a subclass of java.applet.Applet.

My understanding is that the server-side class has a paintContent method, which in turn calls the paint method in the applet. This is how the server/client applet integration works; paintContent tells the applet to draw stuff with paint. The question is whether there is any other way for the applet to present anything. My applet was actually developed in NetBeans, so it has an auto-generated initComponents method that lays out its UI components. I call initComponents from init. This works as expected when the applet is managed with a server-side AppletIntegration subclass, but not when it is managed with a server-side Upload subclass. With the latter, the applet’s UI never appears. The Screenshot example doesn’t really answer the question, because it doesn’t have a fixed UI (with Swing controls) like my applet, so I can’t use it as a model.

No kidding!

Sami,

It turns out that the problem was that only the jar containing my applet was signed, but all the jars in the widgetset public directory have to be. Many thanks to Dmitry for pointing this out.

Now, my build of screenshot runs and I can select part of the screen by dragging with the mouse. Also, it appears that the applet’s doPostToServer() method works, because I get this in the java console:


debug: Screenshot applet loaded
debug: Received JavaScript command 'screenshot'
debug: Taking screenshot...
debug: Screenshot 1 (1920x1080)
debug: Screenshot 1 cropped to (194x87)
debug: Post to server: http://localhost:8080/screenshot/
debug: Cookie: JSESSIONID=CA1E0EC22D3A7FA499C7569BA3C14C41
debug: Posted screenshot 1 status=200
debug: Call JavaScript 'vaadin.forceSync()'
debug: JavaScript result: null

But the captured image never replaces the no_image.gif placeholder, and I have determined that Screenshot’s ScreenshotReceiver.receiveUpload() and UploadReadyListener.uploadFinished() methods never run.

I am able now to get my own applet to run inside a server-side component derived from Upload, as well as one derived from AbstractVaadinApplet. The problem was apparently also just an unsigned 3rd party jar. But my applet will also need to send a file, so I need to understand why Upload’s file transfer functionality is not working with the applets. My Vaadin app uses a vanilla Upload elsewhere, so the problem just seems to be between the derived Upload functionality and the applet’s doPostToServer. Any assistance getting this to work would be greatly appreciated.

Matthew Fleming

Hello, Sami. May I ask you?

So can I get String from my applet without “upload” class?