Thoughts Electrique

Posts Tagged ‘Java’

Adding custom system properties to Gradles jettyRun

Saturday, July 16th, 2011

I recently had to specify some custom JVM parameters (like -Dmyapp.home=/home/foo) to Gradles jettyRun task. Thanks to Gradles task API this is easily accomplished. So if anyone is looking for a solution:

jettyRun.doFirst {
System.setProperty(“my.system.property”,”value”)
}

Thats it! I am really liking Gradle so far. I may finally step away from Ant.

Setting up XWiki in Tomcat and MySQL

Thursday, September 10th, 2009

I recently set up a new XWiki 2.0 instance (with MySQL) for documentation purposes. Although some of the steps are already described in the XWiki manual I’ll document it here mainly because I keep forgetting things. Also step-by-step tutorials come in handy when you’re in a hurry.

(more…)

Some pointers from the JBoss World 2009

Monday, September 7th, 2009

Last Week I attended the JBoss World in Chicago and I had a good time. My favorite Session was Large Clusters in JBoss presented by Bela Ban. It was a very hands-on explanation of the new mod_cluster and presented nicely some of the problems with clustered environments (such as binary incompatible rolling updates, management of configuration files, discovery, etc.) and how to work with them (I always like sessions which keep it down a bit and don’t promote the technology as the next holy grail). I also enjoyed Putting Java to REST by Bill Burke which gave a good introduction to RESTeasy. The library (including the JAX-RS standard) looks very straightforward and easy to comprehend (This is always something which I didn’t like about all the SOA stacks). I must say that I’m a bit skeptical about the announced REST-star initiative. I think it may be a little early to start a standardization effort which will certainly make the technology seem more complex.

(more…)

JSP to download OpenCms resources as a ZIP

Thursday, June 25th, 2009

What often bugged me is that I can upload a set of files into OpenCms as a ZIP file but can not download a tree of files as such (without the use of the database export feature). I had hacked together this little JSP some time ago. It allows you to dynamically download a set of OpenCms resources as a ZIP file.

The JSP has no interface since I mainly use it for development. Simply create a JSP somewhere in the OpenCms VFS and then open the file via the browser. E.g.:

“http://workplace.com/system/createzip?source=/system/modules/foo&filename=foo-module.zip

The source parameter specifies which directory to zip up and the filename parameter which filename to use for the generated file. You can only zip up resources with a total size of 10 megabytes. This is mainly to prevent OutOfMemory errors to happen. You can easily increase the size by altering the variable maxSourceSize to any value you need.

If you find any bugs or want to give feedback simply leave a comment or send me an email.

(more…)

OpenCms and Google App Engine

Wednesday, June 24th, 2009

Especially with the new JPA driver for OpenCms by Georgi Naplatanov the question of running OpenCms on Google App Engine came up quite often at the OpenCms Days 2009. I had the same Idea when I first heard of the Java support for App Engine and did some quick research on how to do this. The research showed that running OpenCms on Google App Engine would require a huge rewrite of some OpenCms core functionalities.

(more…)

Restrict visibility of OpenCms templates to certain folders

Wednesday, June 3rd, 2009

Since I’m currently working on an OpenCms mutli site solution I was looking for a possibility to restrict the available templates of a site. I know this can be done via permissions but the manual implementation of this is rather painful. I’m currently in the process of extending the OpenCms security manager to take care of this but while doing this I found an (to me) unknown feature.

By usage of the property folders.available (you might have to define it first) on a template you can specify a list of comma seperated folders in which the template is available (in the dropdown).

Unfortunately this property works only on file level and can not be inherited via the folder hierarchy. Also it does not provide a secure solution since the template can always be set via the advanced property dialog.

But you never know when a feature could come in handy.

Use the power of JSP tag files in OpenCms

Friday, December 12th, 2008

Since version 7 OpenCms is a Servlet 2.4 and JSP 2.0 conforming application. In addition to the improved expression language (EL) JSP 2.0 also brings in the possibility of developing custom tags(actions) using JSP rather than writing Java code. This allows for some pretty neat things and enables you to go one step further towards cleaner view code. I’ve used this in one of my last projects extensively to refactor common code like pagers and link generation. For example:

<cms:include file="/system/modules/com.example.ocms.commons/elements/pager">
  <cms:param name="currentPage">
    <c:out value="${model.currentPage}"/>
  </cms:param>
  <cms:param name="pageCount">
    <c:out value="${model.pageCount}"/>
  </cms:param>
</cms:include>

Became:

<wt:pager model="${model}"/>

Not does it only look cleaner and is much more focused, it also decouples your view more from the underlying CMS solution. Of course you could also develop a custom tag library using Java (which I have done a few times) but using a JSP the advantage that code can be changed on the fly and even from a web designer. You can always refactor your JSP taglib into a Java one if you need to do it. There are some limitations of JSP tag files (like you can’t use scriptlets in the body) but they are easy to get around.

But as always: This is no silver bullet. There are problems with tag files which may not be obvious at the first glance.

(more…)

Display RSS Feeds in JSPs with RSS4JSP

Thursday, December 11th, 2008

I recently discovered the freshly released RSS4JSP tag library. Its a wrapper around the mature and widely used Rome RSS library which was developed by Sun and then open sourced. The library allows you to simply display (news) feeds inside your JSP pages.

While it’s certainly a young project, I found it very useful and easy to use. I gave it a try to create the Latest blog posts box on my, OpenCms based, homepage. The box was created during 5 minutes which I think is impressive (given that you have to type the HTML too).

Unfortunately the project does not allow the syndication of multiple feeds into one feed (This is a nice feature of Rome which I used in a recent project) but maybe it will be added in the future (or I will add it myself).

Check it out at sourceforge or visit the authors blog.

Enterprise grade software is an euphemism

Thursday, December 4th, 2008

I recently had to restart a Java webapplication because somehow the JDBC connection to the database server was hanging completely. This reminded me of a sentence a friend of mine told me during the OpenCms Days 2008.

“Enterprise software just means that it’s targeted at customers who can afford the guy who restarts the application server every few hours.”

I had to laugh because while the quote is clearly cynical it has a true core. Especially if you compare languages like Java and PHP it’s true that PHP doesn’t have these kind problems. This is mostly because of the throw-away-the-state nature of PHP. After every served request PHP forgets what it’s done before and has to completely rebuild the working environment at the next request. Java in contrast is able to remember things between requests. Which makes it more powerful but also harder to maintain (more state, more problems). I’m really not sure if I’m buying into this enterprise-thing anymore. Especially if you need scalability you definitely want to keep application state at a minimum and without state you don’t really need those big interconnected clusters of application servers any more.

Here is a nice talk about scalability and serious (speak enterprise) languages I found recently. It’s from Cal Henderson a software development guy at Flickr. It’s really worth watching. Even if you’re not into Python and Django.

(Watch it at: http://www.youtube.com/watch?v=i6Fr65PFqfk&feature=PlayList&p=D415FAF806EC47A1&index=10)