Friday, August 29, 2014

CORS XMLHttpRequest in IE10 and newer: "access is denied" caused by Sarissa/Richfaces

If you receive the message "access is denied" when using a CORS XMLHttpRequest in IE10 and newer when using JSF/Richfaces 3.x or Sarissa alone, it is most likely that Sarissa has overridden your window.XMLHttpRequest object.

From the latest Sarissa source code:

if (Sarissa._SARISSA_IS_IE) {
    // commenting the condition out; we need to redefine XMLHttpRequest 
    // anyway as IE7 hardcodes it to MSXML3.0 causing version problems 
    // between different activex controls 

    Sarissa.originalXMLHttpRequest = window.XMLHttpRequest;

     * Emulate XMLHttpRequest
     * @constructor
    XMLHttpRequest = function() {
            _SARISSA_XMLHTTP_PROGID = Sarissa.pickRecentProgID(["Msxml2.XMLHTTP.6.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"]);
        return new ActiveXObject(_SARISSA_XMLHTTP_PROGID);

As you can see, the original method is still available as Sarissa.originalXMLHttpRequest = window.XMLHttpRequest;. I tried adding a condition to prevent Sarissa from creating its own request when an HTML5 XMLHttpRequest2 is available. Sadly, this breaks Richfaces/a4j because of some invalid property being set. I guess this can be fixed too, but I did not have time to dig further. So the easiest workarround now is to use new Sarissa.originalXMLHttpRequest() instead of new window.XMLHttpRequest() if Sarissa.originalXMLHttpRequest is defined.

A note for Richfaces 3.3.3: In my case, the newest Sarissa version was included after the one from Richfaces to fix, so I had to backup the original request manually before loading Sarissa a second time as it would have been overridden twice and the old Sarissa request would have erased the original window.XMLHttpRequest backup.

Edit (some days later): I modified Sarissa to leave IEs greater than 9 completely alone and patched the richfaces jar. The newer IEs seem to work fine with RF this way as they support the majority of APIs by their own. Feel free to comment if further information is wanted.

Monday, February 24, 2014

Capture a video from a webcam using vlc (cvlc) and dump a frame grap image periodically on a linux server

Use this if you want to capture a video from a webcam while dumping a frame grap image periodically every 300 frames. This way you can still upload a plain old webcam image to your webserver without losing the ability to capture a higher framerate video at the same time. Webcam settings are set in the v4l2-url at the beginning. I am not really sure about the mkv file name ending or if the video is already in a mkv container, but that's not the point here. Note that the image is roateted by 180 degrees in this example. This all works in a linux console without X. The parameters should be similar for other OS than Linux, though.
cvlc v4l2:///dev/video0:width=640:height=480:fps=30 --noaudio --sout '#transcode{vcodec=h264,acodec=none,vb=4096}:file{dst=output.mkv}}' --sout-transcode-vfilter="rotate{angle=180}:scene{path=scene/,prefix=out,ratio=300,replace}"

Sunday, February 16, 2014

PropertiesMapper - Java library to map java.lang.Properties to Object fields via annotations

I created a small java library called PropertiesMapper to map the values from java.util.Properties objects to abitrary java.lang.Object fields and vice versa using annotations and reflection. This is especially useful to populate your java objects with the contents of .properties files while maintaing a good code readability. For more information, see the git repository for PropertiesMapper. Code examples are available in the project's