Large File Downloads with JBoss Seam 2 and Servlets

23. November 2012 Keine Kommentare

Today I worked an an issue which presented users of our application a 403 error page when downloading large files which were generated on the fly. The files were delivered by a servlet and the files were directly copied to the ServletOutputStream, so the files were streamed instead of holding them in memory.

After some debugging it turned out, that the files were not streamed since the Seam Ajax4JSF Filter doesn’t allow to stream files and this resulted in OutOfMemoryExceptions. There are a few ways how to disable or extend the Ajax4JSF Filter (see this Seam Forum Thread).

Since all our download resources are mapped to servlets which resides in the “/media/*” path, it was pretty easy to just enable the Ajax4JSF Filter for all paths except the “/media/*” paths. To achieve this, just add to your components.xml:

<web:ajax4jsf-filter regex-url-pattern="^(?:[^/]|/(?!media/))*$"/>

Set Context Root for a JavaEE 6 Application with JBoss 7.1

12. Juli 2012 1 Kommentar

Per default, a Web Application which is packaged as a WAR file is mapped to “http://jbossurl:port/war_file_name” when deployed to JBoss AS 7.1. We wanted the application to be mapped to the root context instead of the file name. It turns out, that this is pretty easy to achieve:

  1. Edit standalone.xml in the JBoss configuration directory. Edit the relevant part of the file like this:
    <subsystem xmlns="urn:jboss:domain:web:1.0" default-virtual-server="default-host">
        <connector name="http" protocol="HTTP/1.1" socket-binding="http" scheme="http"/>
        <virtual-server name="default-host" enable-welcome-root="false">

    The important part is the enable-welcome-root=”false”.

  2. Create a file “jboss-web.xml” in the WEB-INF folder of your application.
  3. Add the following to the file:

    <?xml version="1.0" encoding="UTF-8"?>
    <jboss-web>
        <context-root>/</context-root>
    </jboss-web>

Now your Application will be mapped to the context-root of the Application Server and should be accessible with “http://jbossurl:port”.

Programatically Login User with Seam 2 Security Framework

20. Juni 2012 Keine Kommentare

This is a quick one:

When you want to login a user programmatically without checking if the credentials are right or the user is in the IdentityStore with Seam 2, that is pretty easy.


 
final Principal principal = new SimplePrincipal("username");
identity.acceptExternallyAuthenticatedPrincipal(principal);
identity.authenticate();



This will override the Seam 2 Security Framework authentication mechanism and a user with the given username will be logged in, even if the user is not in the IdentityStore of the Application.

I use this regularly when I have some sort of administration interface where I cannot use the default IdentityStore of the application. In this case I provide an own implementation of the required authentication mechanism and just log in the the user with the approach described above. When doing this I add a role to the logged in user (via identity.addRole("myRole")), so I can use all the Seam goodies like the Authorization Annotations (@Restrict) or checks like Identity.loggedIn.

KategorienJBoss Seam Tags: , , ,

Autostart resque for Gitlab on CentOS 6.2 with RVM installed

8. Juni 2012 Keine Kommentare

In my previous blog post I described how to install Gitlab on a CentOS 6.2 machine. The Resque demon did not start automatically, so I thought I’ll create a little startup script for the resque.sh in the /var/www/gitlabhq directory, so it would autostart. As it turned out, it was harder than expected, because I use RVM. I assume, that you use the installation script I linked in my last blog post to install gitlab, otherwise the following steps could be different for you…. Here are the necessary steps to get it working:

Mehr…

KategorienLinux Tags: ,

Installing Gitlab on CentOS 6.2

3. Juni 2012 5 Kommentare

I had a hard time installing Gitlab on a CentOS 6.2 machine and I tried several tutorials. I was lucky and I found an awesome installation script by Mattias Ohlsson which installs Ruby, Gitlab, Gitoline and Apache with the Passenger Module. On my machine I was not able to create new repositories with Gitlab.


The solution for the problem was, that the ‘git’ user had to be added to the AllowedUsers in /etc/ssh/sshd_config .

KategorienLinux Tags:

SLF4J Logger Injection with Guice

23. Mai 2012 Keine Kommentare

I experimented with Google Guice Custom Injections because I wanted to inject a Logger to my guicified application. There is a great part in the Guice documentation about Custom Logger Injection, but in my case I wanted a SLF4J Logger with Logback as implementation. The example in the Guice Wiki is with Log4j Injection.

Here is how I wanted to inject loggers:

1
2
3
4
5
6
@Log
Logger log;
 
public void doSomething{
  log.info("Logmessage");
}

Mehr…

KategorienGuice Tags: , ,

Different ways to redirect with JSF and Seam

13. Mai 2012 Keine Kommentare

This is just a quick reminder for myself how to implement programmatic redirects with JBoss Seam and JSF.

I will describe three different techniques:

  • Redirecting to a 404 Error Page from a JSF Backing Bean
  • Redirecting to an external Website
  • Redirecting to a JSF view in a Seam Application

Mehr…

Applescript for generating Random UUID

31. Oktober 2011 1 Kommentar

I wrote my first Applescript today and I thought it could be useful, so I decided to share it with you :)

This script generates a random UUID and copies it to the clipboard.

set the clipboard to (do shell script "python  -c 'import uuid; print uuid.uuid1()'")
KategorienMac OS X Tags:

Allowed Characters for Javascript Variables

20. Oktober 2011 Keine Kommentare

I am playing with the JDK Javascript API (JSR 223) and I wanted to check out the replacement of variables in a String. Then I suddenly got this error:

javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: missing ; before statement (<Unknown source>#1) in <Unknown source> at line number 1

After some reseach I found out, that my variables did contain invalid characters in my case the variable contained a -.


So the Regular Expression for valid Javascript variable names is:

[a-zA-Z_$][0-9a-zA-Z_$]*

It is also possible to use any unicode characters for variables, but of course this is not recommended.

Time consuming processes with Seam, Richfaces a4j:poll and Quartz

28. September 2011 1 Kommentar

Today I had a hard time implementing time-consuming processes with AJAX status updates. I stripped down everything to a minimal working example. The technologies used in this example are

  • Seam 2.2.2
  • Richfaces 3.3
  • Quartz 1.6

So here is what I wanted to achieve: The user of my application should click a button and in the background, a long running process should do some database stuff. Since this could take a while, I wanted to show some progress to the user. I did not want a progress bar, but I wanted to display some text to the user, depending on what the long-running tasks current status was.

I stripped it all down to an minimal example, which starts a long running process (huge for loop which generates random UUIDs) when a button is clicked and displays the current UUID to the user. With this basic example I hope you can get the ideas behind the a4j:poll component and how to do asynchronous long-running tasks with Seam. I must admit, that I was heavily(!) inspired by Andrey Chorniys blog post Show dynamic progress of time-consuming process in Seam/RichFaces where I shamelessly stole code and adapted it to my needs.

Here are the neccessary steps to get started

Mehr…