DebugDiag 1.1 install fails with error 2755

May 23rd, 2008

The Debug Diagnotistics Toolkit for IIS is (apparently and hopefully) a very useful tool. I installed it this morning, but not before it failed a couple of times with error 2755.

After a quick and fruitless search on Google, I shifted the install MSI from the network location it was on to a local drive. From there the install was faultless.

Hopefully this will help someone else with a similar issue.

Reinstalling MySQL

August 15th, 2007

I recently set up MySQL and made the mistake of forgetting/misplacing the root password. No harm done, I thought, since I caught it early. I’ll just reinstall. Except, after the installation was removed it seemed to remember the password when I reinstalled. After a quick look on the net, I found that you need to (on Windows):

  • uninstall via Add/Remove (done this)
  • delete the install directory (done this too)
  • remove the my.ini file from C:\WINDOWS (or WINNT, whatever your Windows install directory is called). I hadn’t done this.

The post on Expert’s Exchange - a site I dislike, but useful in this instance.

Hibernate Annotations behaving badly

September 11th, 2006

The following exception cost me some time Saturday and I’m not quite sure why it now works - which makes me nervous.

org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'entity-mappings'.

I had this error returned by both Hibernate Tools and my webapp running in Tomcat, so I wrote a tiny class to configure Hibernate so I could debug it. Lo and behold: no problem. This is not good: the same configuration files in a different environment succeeded: why?

Eclipse container: Server VM with +XXParallelGC (JDK 1.5.07)
Eclipse runner: Client VM (JDK 1.5.07)
Tomcat: JRE VM (JRE 1.5.07)

I changed Tomcat to run using the JDK server VM and now it works. I don’t know why this would make a difference, and I’m not convinced that it is the answer.

The configuration still doesn’t work in Hibernate Tools though, and I’m not sure what to change to make it work. Mind you HibTools (while it’s nice) tends to chew all available resources then die (maybe there’s an upgrade available?).

Update Updated terminology to “Hibernate Tools”. Versions in use: Eclipse 3.2, Hib Core 3.2.0b6a, Hibernate 3.2CR2, Hibernate Annotations 3.2.0CR1 (as recommended by Hibernate Annotations page). JIRA issue created.

Mixing Lucene and Databases

September 6th, 2006

Using full text search together with structured information

I’m writing an application at the moment that needs to allow searching across a whole lot of text, basically structured out into text. It would seem that a full text index would be a good approach - I can allow unstructured queries that would return results that are good enough for the majority of possible queries that users will perform.

There seem to be two options for providing full text search, with strengths and weaknesses of their own: either integrate a library (like Lucene) or use full-text features of an RDBMS (like SQL Server or MySQL).

If your information is vertical (e.g. a set of documents and each document’s metadata) then Lucene would work very well. If this is in the context of a larger, interrelated data set, then Lucene would seem to be less suited.

What happens if you have a table of album details and you want to restrict the results of the search to items that you’ve bought? You can filter the results, but the more albums you’ve bought (in this example) the less efficient the filtering process becomes.

You could build further fields into the search index that hold sets of related IDs, but this is difficult to maintain and is likely to bloat the index considerably. Alternatively, the query results could be translated into a set of IDs that would serve as input to further querying.

In essence, this is what SQL server does: an out-of-process indexer whose results are integrated in the query plan and serve to filter the results of a query. I assume that MySQL (and others) work in a similar manner, regardless of whether the indexer is in or out of the RDMS process.

So for this task, it seems that the RDBMS is the way to go. There is always a cost, however. In this case I think the primary costs are database portability and increased load on the RDBMS server. There is also some convenience lost: the database results are result sets, not summaries of matching text, so this would have to be written.

So in short, it seems that if you have a reasonably vertical dataset then a library like Lucene is a worthwhile option. Information with more complex relations is better suited to a solution based on the full-text capabilities of an RDBMS.

If there are other factors or capabilities that make the above nonsense, I’d love to hear it.

Authenticated Web Services in .NET

August 31st, 2006

Sometimes I get the feeling that I’m doing something a little too out there. This usually occurs when something that I thought would be simple and widely implemented … isn’t. This was my thinking as I dived into the world of authenticated .NET web services.

My use case is simply to invoke a web service with user-provided credentials. If the credentials fail, prompt the user again, displaying the reason they could not be logged in.

The first part is straightforward. Just set the Credentials property on the SoapHttpClientProtocol instance and you’re away.

However if you want to present the user with a login dialog when credentials are required (pull, not push), it is definitely not straightforward. I was expecting something like Java’s authentication callback but I couldn’t find anything remotely like it. There may be other ways, but the way I did it was to:

  1. Create a class that implements IAuthenticationModule and decorates another instance.
  2. Add an event to the class (I called it AuthenticationRequired and make it fire from the Authenticate method before you delegate to the wrapped instance. The event you create needs to take custom arguments so the event handlers can modify and return the authentication details.
  3. Use the System.Net.AuthenicationManager.RegisteredModules enumeration to find the module registered for the authentication type you’re using (e.g. Basic, Digest), wrap it with an instance of your event driven class, and replace it using the Register method.
  4. Register an event handler with your wrapped instance. The event handler can display a dialog, and update or replace the ICredentials instance you passed in the AuthenticationRequestEventArgs.
    Caution! Remember that Windows forms is not thread safe: if you do need to do some GUI work, make sure you use the Invoke and InvokeRequired methods on Form to avoid synchronization issues.
  5. Make sure your SoapHttpProtocolClient instance has the UseDefaultCredentials set to true, otherwise the AuthenticationModules won’t be called. PreAuthenticate should be true as well to save a request if you know that authentication will be required.

That’s it … well, almost. This will allow you to ask for Credentials once per call. If the user enters invalid credentials, the request will fail. Not optimal. To make .NET ask you again, you have to repeat the request.

You can either do that each time you make a request, or you can create a method that takes a delegate as a parameter and does the repetition … or you could use a dynamic proxy. For me, laziness appeals, so I used Castle’s dynamic proxy implementation. This might be the subject of another post though …

Like a bad penny

August 30th, 2006

Nick Lothian has shifted/diverged to another blog: WWWScope, kicking things off with a look at the AOL search data. His analysis is generally spot on, so I’m looking forward to him becoming a little more prolific (?) in the coming months. Subscribed.

XPath: not(=) <> !=

April 19th, 2006

I’ve been doing some XPath in the last couple of days (with Jaxen) and it’s a powerful tool for extracting information from XHTML. On the down side, the code you end up writing is vulnerable to slight variations in the source documents. This aside, I fell into a couple of traps that wasted my time; I hope someone benefits from my mistakes.

One thing that got me is that x != 'y' is not equivalent to not(x = 'y'). I pored over my XPath statement wondering why I wasn’t getting any results when I remembered that XPath operates on sets, not on individual elements - a realisation that made me feel somewhat foolish. x != 'y' means “there exists at least one node in x that does not equal 'y'” whereas not(x = 'y') means “there are no nodes in x that exactly equal 'y'“. A subtle distinction, and enough to give you wildly different results. This is relevant to XSLT XPath too.

For example:

If you were to use the expression ‘./td[child::text() != 'Author']‘ would select both td nodes. However, ‘./td[not(child::text() = 'Author')]‘ would select only the second td. This is because there is a text node containing whitespace immediately prior to the div element (this is dependent on your parser settings - whitespace may not be preserved).

The other thing that came as something of a surprise was when I used an expression to operate on a sub-tree of my document. The sub-tree is still a part of the overall document, so the expressions used need to be based from the current node (”.“) not from the root.

I don’t claim that any of this is rocket science, but hopefully someone finds it useful.

apache2, tomcat and mod_proxy

April 10th, 2006

Making Tomcat work with a web server is a lot easier than it used to be, but that isn’t saying a whole lot. There are quite a number of questions about this on the web, so hopefully my experience will be helpful to someone.

I needed to link Apache 2 to Tomcat 5.5 on a Debian box. There are two general methods used for this: mod_jk or mod_proxy. There are variations, but these are the usual suspects. Also in general, mod_jk is considered the faster option (though as a third alternative a standalone Tomcat instance will do the job quite well - if you don’t require anything but Java).

I tried to use JK by downloading and compiling it, however apxs2 isn’t installed and apt-get refused to install apache2-threaded-dev (apparently a broken package as some dependencies were out of whack). So mod_proxy was it.

I found these instructions (kindly translated by Babelfish), which gave me the general idea, and later the Tomcat docs themselves brought forth the Proxy HOW-TO, which is a useful, step-by-step guide.

Based on the steps in the above guides, I used the following configuration:

  • mod_proxy configured for reverse proxying:
        # reverse proxy
        ProxyRequests Off
    
        # allow proxying of all requests;
        # don't turn ProxyRequests On with this configuration!
        <Proxy *>
          Order deny,allow
          Allow from all
        </Proxy>
  • Rewrite rules in VirtualHost definition:
        #tomcat rewrite/proxy directives
        <IfModule mod_rewrite.c>
            RewriteEngine On
            RewriteLog "/var/log/apache2/rewrite.log"
            RewriteLogLevel 1
            RewriteRule ^/url-path/(.*) http://localhost:8081/context-path/$1 [P]
        </IfModule>

    Note url-path is the path that will be redirected, context-path is the Tomcat context, and 8081 is assumed to be the port your proxied Tomcat HTTP connector is listening on.

    Note also that the rewrite rule is such that a request for http://meh.com/foo would fail, but http://meh.com/foo/ would succeed. There is probably a way around this, using a slightly different regex, but I haven’t taken the time.

    The Tomcat docs detail different directives; I’ve seen fragments on the web saying that these don’t rewrite headers properly, but I’ve yet to work out the details of this.

  • In Tomcat’s server.xml, the connector includes the proxy attributes:

After reloading Apache and restarting Tomcat it all appears to work. I would like to work out how to get mod_jk working at some point though - and perhaps (if I have a weekend to spare) getting the latest Apache to work with its newer connector modules. Enabling SSL is another job that will happen somewhere along the line too.

An interesting side-note to this connection method is the possible impact on caching, as Nick found out. I don’t think this will affect me much at this point, but it’s worthwhile keeping it in mind.

Cache politics

February 19th, 2006

I’ve used a lot of open source products, followed the mailing lists of a few, and contributed to a couple. So I’m no expert. But I’ve heard of JBoss’s anonymous plugs, seen a couple of flame wars and caught wind of the various ways that humanities foibles make their way into the OSS space.

So it shouldn’t come as a surprise to see it take place; but I was.

In the last couple of months, I put a bit of time into a couple of bug fixes in EHCache, so I’ve been monitoring the forums. To my surprise, Aaron Smuts, a committer for JCS posted across the EHCache forums - answers which consisted simply of “JCS is better”, “Do this in JCS like x”, “JCS doesn’t have this bug”.

Not all his actions were quite so petty though - he posted a link to his performance comparisons in its own thread on the forum. Empirical tests are useful, and can lead to healthy discussion. So why bother splattering petty grafitti across forums where people are after useful answers?

I’m hoping he persists with his constructive comparisons and drops the schoolyard pettiness. It doesn’t help anybody.

Spring madness

February 2nd, 2006

“A little Madness in the Spring Is wholesome even for the King” Emily Dickinson (1830 - 1886) (via quotationspage).

Bob Lee (a.k.a. crazybob) just lit off at one of the Java proleteriat’s holy cows: Spring.

“no offense to Rod et al … [but] I haven’t been able to get my head around your framework.”

His complaints?

  • Most of its proponents don’t know enough about it to justify its use
  • Spring isn’t required for dependency injection - it’s just one implementation
  • It isn’t lightweight or simple - and it only seems that way when compared to J2EE
  • Why XML? (And particularly a dialect that looks suspiciously like Java)
  • Loss of type safety
  • API dependency
  • Too much inheritance
  • Not enough generics
  • No scoping

The post seems to limp a bit towards its conclusion, due perhaps to its length, and instead of discussing alternatives he calls for pragmatism:

“… simply adopting dependency injection design patterns gets you 90% of the way”, and “Be skeptical, critical.”

All in all, his criticism is well put, and some of it justified - Ted Neward certainly thought so, as did Hani Suleiman, who weighed in early on the (long and interesting) comment trail.

I used Spring (I admit it) at my former employer and some of the issues mentioned resonate with me. A lot of libraries are required, and mixing and matching jar dependencies for the 5 or 6 open source components in your enterprise application is no fun at all. Do I use commons collections 2 or 3? Can I just put the latest build of commons logging in there to get rid of the classloader bug? Maybe, who knows? You just have to suck it and see, then pick up the pieces later.Update: Wrong, see below.

As for XML configuration, well that soon gets long and frightening. Sure, you can break it up (sort of) but it is still a pain to create and maintain - particularly as there’s no decent editor (correct me if I’m wrong). Eclipse will tell me if the class I reference doesn’t exist in a Java file, but no such joy in the Spring XML. You have to (again) suck it and see. Update: Wrong again, see below.

Dynamic languages and comprehensive test suites may be the ant’s pants, but sometimes I just want a compiler error. Now. Not some obscure error in 5 … or 15 minutes once my test run has completed.

On the positive side, I liked that I didn’t have to roll my own. I liked the way it worked with Hibernate. I liked the way I could change its behaviour by writing a configuring class. I liked the way I could extend it to other areas of our application. Yes, I could have written it, but sometimes there are deadlines, and there’s only so much framework fun you can fit in.

So crazybob, criticism is healthy, and pragmatism is an underrated virtue but … what’s your alternative? I’d like to see a follow-up post that expands further on what you see as a better solution - how, for example, do you use the dependency injection pattern in applications you write? Would you expand more on your generics idea? What are the best-practices you think we would be best to practise?

Update: a very well-written comment by Keith Donald responds to this point by pointing out both that very few dependencies are required and that there is a good editor (Eclipse and IDEA). Thus I got those points badly wrong, and on points that could have all-too-easily been checked. An important lesson - thanks Keith.