englishteeth.co.uk

… the weblog of Ian “English Teeth” Robinson
  • rss
  • Home

JBoss not using the deployed Xalan jar

Ian | February 20, 2009

Something that felt like forever to track down…

A test running problem free on the test server was throwing a transformer error locally:

javax.xml.transform.TransformerException:
Had IO Exception with stylesheet file: C:\jboss-4.0.3SP1\server\default\conf\documentservice\pmi\include.xslt
at org.apache.xalan.processor.TransformerFactoryImpl.processFromNode(TransformerFactoryImpl.java:126)
...

On the surface, it looked like there was no difference in the environments; same deployed war file, same JBoss version, same Java version, same everything. Obviously something was different…

Xalan 2.7.0 was distributed in the WEB-INF/lib of the war, but stepping through the code on the failing local server, the byte code didn’t match the attached source. It wasn’t 2.7.0 being used, it was actually the 2.6.0 version shipped with JBoss (found in lib/endorsed).

It turns out that libraries in the lib/endorsed directory are considered system libraries by virtue of being loaded by the System and bootstrap class loaders and as such being used in preference to deployed war files version. (It should be noted that this is an older version of JBoss, namely 4.0.3 SP1.)

That explained why the wrong class was being picked up locally, but not why it worked in the test server environment.

The main difference was that the server was being run as a service on the test server and via a batch file locally.

Purely by chance, the endorsed.dirs parameter had been missed from the configuration of the service wrapper.

wrapper.java.additional.2=-Djava.endorsed.dirs=%JBOSS_HOME%\lib\endorsed

Striking this out of the local batch file, sanity returned once more.

rem set JBOSS_ENDORSED_DIRS=%JBOSS_HOME%\lib\endorsed

Removing Xalan and Xerces from lib\endorsed would have much the same effect and is proposed in this jira task at jboss.org

Comments
No Comments »
Categories
development
Tags
java, jboss, xalan, xerces, xslt
Comments rss Comments rss
Trackback Trackback

The DVD Library in Vista Media Center

Ian | February 12, 2009

I’m a fan of the DVD Library functionality built into Windows Media Center Edition and Vista Media Center. I prefer it over something like My Movies purely because of it’s slickness and simplicity.

Though I have no idea why the ability to enable it is not a core configuration option, the methods are well enough documented around the place.

With such simplicity however, you often run into a restriction or a niggle that in a stand alone set-top box you may well just live with. With an HTPC though, which is most definitely a labour of love, you search an probe for a way to do that particular thing you want to do.

My niggle was that I wanted files other than DVD images to be accessible via the DVD Library. This desire was further provoked by Vista listing movies I recorded from TV in the library. This was almost enough. If I could have moved these movies out of the Recorded TV area and still have access to them, but no.

I found references to other format files being made accessible to extenders from the DVD Library via play lists and virtual links. I was again spurred on.

Ultimately though I was disappointed to find that these only worked from the extender and locally the DVD Library was truely limited to DRMS or WTV files located in a watched TV folder or DVD files.

I came across a free plug-in called Video Browser, but I was sceptical. I really didn’t want to install a plug-in to solve something I felt there must be a way around in the core software.

Nevertheless, in a fit of idle curiosity I installed it and pointed it at my folder of DVD Images.

Excellent. By default I had an interface almost identical to that of the DVD Library (at least in that release), but with a richer detail screen and the promise of other file types. There were eye-candy back drops and cover art for nearly every film without me doing anything. The plug-in is really slick and integrates seamlessly.

Slowly I started moving my other movie files into the sights to the plug-in. It has a simple convention…

Create a folder for the movie and drop your file, image or whatever into it.

After a spousal consultation, I gave up on the standard DVD Library “poster” view and moved to the detail view.

I then started thinking about the series I had and moved them over. I played with the options and tried the supporting metadata tools for getting more images and information Media Scout and Salamis movie browser (which is a stripped back version of the My Movies data capture interface tuned to the plug-in).

Finally, I moved the library, movies, series and all to the Home Server, something I’d never felt ready to do with my “open issues” with the DVD Library.

I feel my quest for the solution to my original niggle may be over.
Until the next one that is…

One problem with video browser is aside effect of a very positive side of it. It is in beta and is under the seemingly constant attention of its contributing developers. Even while writing this post and update was released which significantly changed the detail screens and removed some of the big brash eye candy banner art for a more subtle presentation.

But the project from the forum the developers seem open to suggestions and besides, it is also open source. If I really want something a certain way, I just need to pull my finger out and make it so.

Comments
No Comments »
Categories
development, miscellaneous, software
Tags
movies, open source, video browser, vmc
Comments rss Comments rss
Trackback Trackback

Grails: Role based security on Jetty & JBoss

Ian | October 22, 2008

Todays challenge.. Security!

Hardly a challenge at all really, the JSecurity Plugin - Quick Start takes you through everything you need to do and there’s also a AcegiSecurity Plugin, if that’s your bag.

There you go, post done.

Well… unless you want/need to use JEE role based authentication at the application server level. That’s a little more involved.

Unfortunately, this involves a little jiggery pokery in grails itself, but this is only really to have the bundled jetty server include some security configuration. The intention here is after all, having the authentication at the application server level.

The task has been covered admirably at the coders corner in the article Setting up Grails to work with JEE role based authentication. This then goes on expand on how to expose the grails project’s web.xml, in order to configure the access.
grails install-templates
And what you need to put in src/templates/web.xml to configure the access is covered in Using Role based security, in much greater detail than I would want to duplicate here.

There really is nothing to add so far, the steps described just work.

The next step took a bit more digging and looking outside of grails oriented guides. The actual deployment environment I have to target is JBoss, but the best description of the security configuration I found was in the article JBoss Role-Based Security.

This got me 90% there. To bend it to grails, I had to add a little bit more to the jboss-web.xml file I added for deploying to JBoss:

    <context-root>/my_app</context-root>
    <security-domain>java:/jaas/my_app_policy</security-domain>

Obviously making sure the domain matched what I had put in the JBoss configuration.

I also happened to include two properties files for roles and users in src\java so they were deployed with the application and reference these in the JBoss configuration file login-config.xml:

  <application-policy name ="my_app_policy">
    <authentication>
      <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule" flag="required">
        <module-option name="usersProperties">my_app-users.properties</module-option>
        <module-option name="rolesProperties">my_app-roles.properties</module-option>
      </login-module>
    </authentication>
  </application-policy>

This has worked for me locally, but as I describe it, I feel that it is a bit odd having a dependency between the server configuration and specific files in a deployed application; even though their absence doesn’t seem to cause a problem. I think I might move those into the folder along with login-config.xml

I also believe that these could be just as easily be the default files JBoss expects by not specifying the above module-option elements.

All this done…

It didn’t work!

As soon as I tried to access a protected resource, I got a 404 error trying to locate the authentication controller actions I have in my application!

I couldn’t find a clear reference to this problem, but the following entry on the struts issues dashboard -
Action’s can’t be used for web.xml declarative security URL’s certainly describes the problem and also provided me with a fudge solution.

I edited my web.xml to point at a jsp:

    <login-config>
        <auth-method>FORM</auth-method>
        <form-login-config>
            <form-login-page>/login_redirect.jsp</form-login-page>
            <form-error-page>/login_redirect.jsp?success=false</form-error-page>
        </form-login-config>
    </login-config>

and added a login_redirect.jsp:

   <%
        if ("false".equals(request.getParameter("success"))) {
            response.sendRedirect( request.getContextPath() + "/auth/failed" );
        } else {
            response.sendRedirect( request.getContextPath() + "/auth/login" );
        }
    %>

Now it works!

Comments
No Comments »
Categories
development
Tags
grails, jaas, jboss, jetty, security
Comments rss Comments rss
Trackback Trackback

Deplyoing a Grails application to JBoss

Ian | October 17, 2008

So it seems that every month or so I am able to blow the dust off my little Groovy on Grails project and progress it a little. A little frustrating, since the elapsed time of this belies the gains in using grails.

I have a working application. It has a few rough edges, but for all intents and purposes, it’s there. I just needed to see if creating war and deploying to the target environment, JBoss.

Surely it can’t be as simple as…
C:\local\groovy\my_app> grails war

No, it isn’t… But nearly!

Deploying into JBoss, the problem I hit was down to log4j and the jar within the deployed grails application conflicting with the one in JBoss.

Obviously this has all been covered before and a few alternatives are offered on the grails faq.
Q: I’m getting errors when deploying on JBoss 4.0.x What do I do?

First off I had to scope the application classloader. To do this for a war, create a file called jboss-web.xml with content like the following:

<jboss-web>
    <class-loading java2ClassLoadingCompliance = "false">
        <loader-repository>
            my_app:loader=my_app-0.1.war
            <loader-repository-config>java2ParentDelegation=false</loader-repository-config>
        </loader-repository>
    </class-loading>
</jboss-web>

and place it in the web-app\WEB-INF folder.

This still isn’t quite enough to get it to work though, since the log4j.properties file used by JBoss still results in a conflict of interest.

Luckily enough I was able to take the preferred solution of renaming JBoss’ log4j.xml to jboss-log4j.xml and editing the jboss-service.xml file such that the ConfigurationURL of org.jboss.logging.Log4JService points to the renamed file.

Et voila!

Comments
1 Comment »
Categories
development
Tags
deploy, grails, jboss
Comments rss Comments rss
Trackback Trackback

Groovy on Grails and my “Test First” impasse

Ian | September 4, 2008

I’ve hit what would be a test first impasse (if I had tried to write my test first). So in an attempt to leave it alone, I’ll record where I got to and the resources that I think nearly got me to a solution…

I have a domain object for which I want to return a filtered set. I know that this can be done as a closure to the list method of hibernate criteria and having figured out how to mock a closure I can assert that a filter has indeed been applied.

 def criteria = Customer.createCriteria()
 items = criteria.list(params) {
   or {
     ilike ('surname', "%${params.filter}%")
     ilike ('forename', "%${params.filter}%")
     ilike ('emailAddress', "%${params.filter}%")
   }
 }
---
def customerCriteria = new MockFor(org.hibernate.Criteria)
customerCriteria.demand.list { Map params, Closure cls -> testItems }
Customer.metaClass.static.createCriteria = { org.hibernate.Criteria }

But how can I assert that the filter closure contains/does what I want?
Having mocked the closure call, I now want to define what it is supposed to do in my unit test.

I just can’t figure out how and I have started delving much deeper into how closures work than I originally wanted to. Unfortunately, I don’t seem to get any further than the MetaClass, where everything is still a little abstract. There must be some representation of the code to be run/resolved in there somewhere!?

I’ve poured over the hierarchy for package groovy.lang and pages on Closures and the ExpandoMetaClass - GroovyObject Methods.

Kick started by Fun with Groovy and the Reflection API and definitely helped by What methods does my Groovy/Grails class have? I distilled my problem to a script and proceeded to dump anything and everything I could think of or come across…

class MyClassUnderTest {

  def foo() { return "foo" }
  def bar() { return "bar" }
  def ray() { return "ray" }

  def someMethod(Closure val) {

      println("Closure:")
      println(val.dump())
      println("-----------------------------------------------------------------")
      println("My Closure: ")
      println(val.getMyClosure().dump())
      println("-----------------------------------------------------------------")
      println("Meta Class: ")
      println(val.getMyClosure().metaClass.dump())
      println("-----------------------------------------------------------------")
      println("My Meta Class: ")
      println(val.getMyClosure().metaClass.myMetaClass.dump())
      println("-----------------------------------------------------------------")
      println("My Meta Class Methods Index: ")
      println(val.getMyClosure().metaClass.myMetaClass.metaMethodIndex.table*.name.sort().unique() )
      println("-----------------------------------------------------------------")
      println(val.getMyClosure().metaClass.inheritedMetaMethods*.name.sort().unique())
      println(val.getMyClosure().metaClass.methods*.name.sort().unique())
      println("-----------------------------------------------------------------")
      println(val.getMyClosure().metaClass.theClass.dump())
      println("-----------------------------------------------------------------")
      println("Constructors:")
      val.getMyClosure().metaClass.theClass.declaredConstructors.each { println it.toGenericString() }
      println("-----------------------------------------------------------------")
      println("Methods:")
      val.getMyClosure().metaClass.theClass.declaredMethods.each { println it.toGenericString() }
      println("-----------------------------------------------------------------")

      return 'result!'
  }

}

def cut = new MyClassUnderTest()
def myClosure = {
    foo ('valueOne')
    bar ('valueTwo')
    ray ('valueThree')
    'valueFour'
}
cut.someMethod { myClosure }

I thought I might have struck lucky when came across a post by Danno Ferrin who had learned more than he wanted to know about groovy.lang.Closure. This cleared up a great deal about scope and lead me to a post by Guillaume Laforge on knowing which variables are bound or not in a Groovy script.

Unfortunately the actual contents of the closure still allude me, but I’ve got work to do and this has had far more of my time than I can justify!

Comments
No Comments »
Categories
development
Tags
grails, groovy, hibernate, mock, testing
Comments rss Comments rss
Trackback Trackback

« Previous Entries

Author

Ian Robinson is a relatively agile software engineer interested in things both sides of the object relational divide and beyond.

Categories

  • development (37)
  • miscellaneous (28)
  • music (7)
  • software (19)

What I'm Doing...

  • If I drink enough to see double will normal TV look 3D? 12 hrs ago
  • SLF - Here we go! 1 week ago
  • Quite a crowd of media outside Portsmouth's training ground and in the car park opposite this morning. 2 weeks ago
  • More updates...

Posting tweet...

Powered by Twitter Tools.

Blogroll

  • Dan North
  • Dave Astels
  • Dave Wood
  • eirikso.com
  • Matt Raible
  • Object Mentor Blog
  • The Ancient Art of Programming
  • The Wisdom of Ganesh

Tags

active-mq architecture bauhaus css db eclipse esb festivals freesat gorm grails groovy hd hibernate htpc java jboss jms junit links mce media center mini music oracle osgi patterns pirsig plugins satellite soa software spring sql struts2 testing themes tools tv vmc web wordpress xml xpath xslt
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox