« September 2002 | Main | November 2002 »
JMock does actually look quite similar to what I've done, but it is focussed more on the normal use of Mockobjects - ie. checking they were called with the expected values. I'm not really doing Mocks at this point - its more like convincing an application that its running inside a real servlet container. Which means that I have to be able to understand that when I get a call like request.getHeader("user-agent"), I need to return "Fakezilla", but when I get request.getHeader("if-modified-since"), I have to return a valid date string, or null. I'm not trying to assert how the mocks are called, just fake up a convincing looking environment. What I've ended up with is essentially a form of dynamic dispatch, as each mock has a collection of MethodReceivers in a Map keyed by method name, and each MethodReceiver has a Map of MethodReturn objects, keyed by an ArrayList of the arguments. Its then a case of calling getReturnValue on the MethodReturn object (confused yet?). I can therefore return different responses based on the actual values (not just type) of the arguments. I can also simply make the Mock return a hard-coded response directly where I can get away with it (methods with no arguments for example). There's some syntactic ugliness in the setup code due to Java's lack of enclosures - the closest approximation I've found is to implement an interface 'in-place' with an anonymous block. The alternative is hundreds of really tiny and very similar looking concrete classes. The whole thing isn't exactly generic or lightweight, as you have to know quite a lot about what your application is going to need in the way of parameters, and which methods its going to call on the request/response objects, but it has been quite illuminating finding out just how the application in question interacts with its environment. And its nice to work on something a little off the wall every now and then :)JMock is your friend...
[Joe's Jelly]
Untangling the Gordian Knot. Currently working on a project to untangle a hairball project. Its quite tempting to cut the Gordian Knot, but we... [development]Interfaces are my friend in this situation. I have found it really useful to extract a single method on the bloated object I'm trying to break up into an interface, and substituting a reference to the interface in the calling code wherever possible, repeating for each method, initially by defining one interface per method, and occasionally consolidating the interfaces where I find that several of them are passed around together. It does mean that for really blob-like objects, at about the halfway stage I find myself with humourous constructors like:-
MyThing thing = new MyThing(this, this, this, this, this);Where 'this' is some bloated object that now implements 5 distinct interfaces, and the target class has been refactored to work through the interfaces. Its so obviously wrong that sheer embarrassment forces you to keep refactoring until its all clean. Writing tests gets really easy too. Its easy to make the TestCase implement an interface and pass itself to the object under test (self-shunt pattern) when the interface only declares one method!
Another useful AOP article here.
Jumping back on the aspects bandwagon (trying to explain something often helps me to understand it):
Indirection, aka abstraction: You call a method on an interface, and the recipient is determined at runtime, and may be at the end of several 'middlemen' who simply pass the message along. What AOP does for you is allow you to dynamically compose a whole method call chain using reusable interceptors. So calling setFoo() on something that appears to be a simple bean can actually take a quick detour to your validation interceptor to check the syntax, then visit the persistence interceptor, telling it that the field is dirty, before returning. This is nothing that can't already be done without AOP, but AOP (ie. interceptors & extensions) appears to be much more flexible and reusable. Being able to define your interceptor stack in a descriptor or programmatically means you can substantially alter the behaviour of bits of your application while its running, and the calling code still sees a simple 'setFoo' bean like interface. And the possibilities for code reuse look huge.
Of course, I could be entirely wrong - I'm still trying to wrap my brain around the concept.
/** * @webwork.action * name="myCoolAction" * input="myInput.jsp" * success="myCoolActionSuccess.jsp" /*Write a simple jsp called myInput.jsp with an input form along the lines of:-
FORM METHOD="POST" ACTION="myCoolAction.action"Write a quick success.jsp page with a 'well done' or similar message. Get XDoclet 1.2 beta. Stick the jars in Ant's classpath. Add a target that look like this:-
<target name="xdoclet" depends="init"
<taskdef
name="webdoclet"
classname="xdoclet.modules.web.WebDocletTask"
classpathref="class.path"
/>
<webdoclet
destdir="${build}/src"
mergedir="parent-fake-to-debug"
excludedtags="@version,@author,@todo"
addedtags="@xdoclet-generated at ${TODAY}, XDoclet,@version ${version}"
verbose="false"
>
<fileset dir="${src.java}">
<include name="**/*Servlet.java"/>
<include name="**/*Filter.java"/>
<include name="**/*Tag.java"/>
<include name="**/*Action.java"/>
</fileset>
<webWorkConfigProperties destDir="${webinf.classes}"/>
</webdoclet>
</target>
Include the target into your default build, just before the compilation step.
Run ANT. Wait for resin to reload your webapp.
Open /yourWebapp/myInput.jsp. Submit it. See the success.jsp page. Modify your Action class's execute() method to actually do something, like check for the right name/value pairs. Make it return Action.INPUT to go round again, Action.SUCCESS to succeed and go to success.jsp, Action.ERROR to report an error etc.
Repeat.
More details when I have time.
it's actually really simple.Doh! No I didn't know about Joseph's tutorial, I must have skimmed over the post where you mentioned it. That would have made life much easier :) I find this kind of blow-by-blow guide to be an excellent 'kickstart' when using a new tool or framework. It helps me get my mind around the paradigm of the tool being used. I wish every new technology had one of these. For anyone else like me who missed Mike's link, the guide can be found here:- http://enigmastation.com/~joeo/webwork.htmlWeb-the_simplest_thing_that_can_possibly-Work. I get WebWork. Finally. For some reason I've had a mental block on it up until now. Every time I sat down to explore it something came up, or I got bored. Finally cracked it this afternoon. Turns it I was expecting something complex, and it's actually really simple. This appeared to cause me as much (or more) mental discontinuity as when I'm expecting something to be trivial, and it turns out to be much more complex. WW really is very simple, but it lacks an 'idiots guide' which would have been very helpful to me. I'll see if I can retrace my steps and post my experiences up sometime. [Pushing the envelope]
Great! A WW idiots guide would be fantastic. Did you read Joseph Ottinger's tutorial? Maybe that would be a good starting point to collaborate on?
[rebelutionary]
Conditional Get Update. Various news aggregators are leaping on the conditional get bandwagon. (108 Words) [The Fishbowl]Its somewhat ironic that all this effort is suddenly being devoted to make aggregators only perform full GETs when they are needed, when as anyone who's ever developed a public facing stateful web-app knows, its usually a knock-down drag-out fight to prevent misconfigured proxy servers from caching all your pages (and cookies, some of them) for all eternity and breaking your app in a variety of interesting and humorous ways.
OSAF Post Feedbacks.I do pay for software. I would pay for more software, if there was quality software out there worth paying for. I think I've said it before, but free / open-source software entering a market won't ipso-facto kill commercial software, but it certainly will raise the quality bar. If the only means for a commercial product to survive in a marketplace is to monopolise it, then it probably doesn't deserve to survive. I bought The Bat, not because there are no free (or indeed pre-installed) email clients, but because it was sufficiently better to warrant its price. If a product takes a team of 50 a year to develop and costs tens of thousands per cpu, should it really have anything to fear from a competing OSS alternative developed in a few months by 3 or 4 people who've never met working in their evenings and weekends? And if it does, does that say anything about its true 'value'?I disagree that there is no sense of value for software in this country. I do agree that I seem to be buying less software than before, but I ask what factors might have caused this change? Microsoft contributed, but there are other factors involved.
[Don Park's Blog]
Delegating SAX Parser HandlerI discovered Digester a few weeks ago and have found it very useful. Couple it with BeanUtils and you've got a great way of automagically populating your beans from an XML config. I have a Configuration object that contains a Map of the 'digested' name-value pairs and uses BeanUtils.copyProperties to set the fields on any Object it gets passed. All I have to do is obey the javabean naming conventions and it just works. For an additional check you could include the bean classname in the XML and have the Configuration object complain if it was passed an object of the wrong type.Delegating SAX Parser Handler.
At work I'm working on refactoring / redesigning something that started as a cool idea. Basically, you register sub handlers to a root handler with the path you're interested in getting messages for (like "/document/header/title" would get you the events for the document title).[Jason Carreira]It does sound quite similar to digester which allows you to register interest in SAX events using abolute paths, relative paths, wildcards and so forth and apply Rules when the SAX events fire. Plus there's default rules for all kinds of things like creating beans, setting bean properties, invoking methods. There's a default object stack so its very handy for parsing XML config files and turning them into your domain objects.
Competition in open source can be healthy, though I do prefer reuse when it makes sense since it promotes a bigger user community which often results in better software. So I'd recommend evaluating digester first to see if the effort of starting your own project and supporting it is worth the effort.
[James Strachan's Radio Weblog]
In the script group, the Perl subjects may be more capable than the others, because the Perl language appears more than others to attract especially capable people. [Lutz Prechelt, An Empirical Comparison of C, C++, Java, Perl, Python, Rexx, and Tcl]Ready flamethrowers... Fire! Could this perhaps be that it takes a better than average developer to wield Perl in anger without hurting themselves or others? I have something of a love-hate relationship with Perl. Its power and flexibility is undeniable, its syntax questionable. I have this nagging fear that the more I learn, the greater its seductive attraction will become, simply because it allows you to get away with almost anything. That's it. I'm not posting anymore on this (although I reserve the right to change my mind). There are more important things in life than 'my language is better than yours' catfights. Put your energy into writing code instead.
Another leaves radio land. It's looks as if more people are leaving Radio behind. The Desktop Fishbowl has left its old Radio shanty to... [<big>kev's</big> catalogue of this and that.]I'm not sure what the incentive is (even though I'm now feeling it myself) to leave Radio. Maybe its developer masochism, that 'not invented here' feeling that because I didn't write it / its not in my pet language, it must be bad for me. Maybe we feel vaguely guilty about using a 'consumer' product. We're geeks, we're supposed to use two or three arcane command line utilities and a dodgy perl script to achieve the same thing as a normal person using a pointy-clicky GUI app. Or something. Maybe once the blogging addiction bites then you start wanting to add your own features, which is far easier to do when you have the source in front of you, in a programming language you're comfortable with.
I thought the whole point of XML was that it allowed machine-parseable data to remain human readable. Don't tell me they could have achieved that goal without all the angular decoration? Could they? That would be like a technically superior video format being beaten by a lesser one that was just better marketed. Oh wait, that happened...NBML - Not Bunk Markup Language (Okay the name might change.)
How long have we been staring at screens full of XML and not complaining? Have a look at a typical chunk of XML - it's all noise.
[Joe's Jelly]
Wikify.... I like wiki. But... its too hard. I want to be able to wikify my entire website, so that if... [development]I believe that snipsnap attempts to meld blogging with wiki. Might be worth a look.
Deriving backtracking monad transformers. [Lambda the Ultimate]Am I alone in thinking 'Huh?'
Party like it's 1993. -Russ [Russell Beattie Notebook]1993 was also when I first heard the word 'Linux', which, because we were British, was pronounced 'Line-ux'. One of my Uni acquaintances showed it to me. "Look, free Unix on a pc". "That won't go anywhere", I thought... This rates alongside my other great predictions such as, 'Netscape are having an IPO, should I invest? Naa, they probably won't be worth much'. And Yahoo, and Redhat... I console myself that I was a poor student and didn't have much to invest at the time anyway. Wouldn't have had enough money to get rich, just enough to have had one whale of a time at Uni.
I couldn't unplug.... But I'm going to be brief tonight. It's 11:19 p.m. I want to be off the computer by 11:30 (maybe 11:45's more realistic).Russ, if you're reading this and its NOT just after you got up on thursday morning, switch off. Now. :)-Russ [Russell Beattie Notebook]
Next Generation Email Clients. Wow, you want a lot. :-)"A reasonable man adapts himself to the world around him. An unreasonable man expects the world to adapt to him. Therefore, all progress is made by unreasonable men." - George Bernard Shaw. Of course, he was a lot more eloquent than me. I just look pointedly at the title of my blog :)
Yeah, I'll probably end up doing something like that. Although I can never do things the easy way, so what I might well end up doing is running my own local IMAP server...First of all you should probably be using IMAP in the short term as it will provide a much better means for accessing email in a centralized location. The downside is that IMAP tends to require a good connection speed because the messages stay on the server and are downloaded on demand, as opposed to the POP strategy which downloads all messages in your INBOX and lets you organize and store them locally.
The most powerful windows email client I've ever used is The Bat!. Also used by Ron Jeffries I believe.As for a cross platform GUI client which actually works well, I have yet to find one which satisfies me. On W2K I use Outlook, and while it is adaquate there are a number of things which really piss me off. Sometimes Outlook just sits there for 10 or 20 minutes "checking for messages". Then there is the virus issue. On OS X I use the included Mail application which works pretty darn well. In the worse case scenerio I resort to Pine on Linux (if I can only get in via SSH).
I wasn't really suggesting a replacement for established servers, but something more along the lines of a web service. As connectivity increases and more people have permanent connections, it's not unforseeable that your own static IP is as common as having a phone number. If you believe the IPv6 hype, even your fridge will have a net presence in the not-too-far future. Anyway, if you have your own server on the net, you have more options with regard to applications. Image the scenario: your powerful home server is collecting and indexing your email, news feeds, etc. according to the criteria you have defined. You have your lightweight wireless device / laptop with you, and can simply hook up to your central system and be presented with a condensed and sorted view of all the stuff it has for you. Read some emails, send some replies, organise your calendar, all centrally stored and managed from your personal server. Your personal server could equally well be a hosted service, much like many bloggers already have.On my side I think I have abandoned the desktop client in favor of a web client. There are just too many issues with synchronization accross clients which are too difficult to overcome. The existing protocols (IMAP and POP) do not really work well when you get into the level of tens of thousands of messages in hundreds of folders. You will essentially need to have a custom server and protocol which deals with these issues so that synchronization is not completely up to the client. Unfortunately this will be a painful if not impossible uphill battle due to the fact that people have their email servers in place and would be very relucatant to replace it with your server.
All good stuff. Especially the JIRA bit :)Here are my ideas for a web-based email/information manager:
[All Things Java]
- It will not emulate a typical client-side application. No folder trees. No drag and drop. My idea is a single "INBOX" which is an aggregation of your different message sources such as email, RSS, newsgroups, etc.
- It will link together email/contact management/history/tasks/issues etc. in a fashion which makes it easy to view the lifetime of a particular discussion as well as the results of a discussion.
- It will provide multi-user functionality so that a group of users could share some messages which are related to the group but not others which are related to the individual only.
- It will work with POP and IMAP servers.
- It will track EVERYTHING which comes in and goes out.
- It will link with JIRA! :-)
What were you doing in 1993? [Russell Beattie Notebook]Hmm. Finished my A-levels, turned 18, bought my first car, started my degree in Chemical Engineering. Discovered the internet. Drunk (and drank) a lot. I just realised I can still remember the first ftp site I ever accessed. wuarchive.wustl.edu.
C# is similar enough to Java that it isn't hard to pick up for java developers who haven't rejected it merely on the basis of its heritage. As companies (like Joe's clients) start to demand .net stuff, developers coming in to .net who are used to the availability of OSS tools for java will probably start to produce equivalents for the .net world. Although what Microsoft were thinking with their first workspaces license escapes me. Unless they offer a compelling technical reason not to use sourceforge I think they may struggle. The community will decide, and it doesn't really matter whether the tools are hosted on sourceforge, apache, or gotdotnet workspaces.Interesting. I think MS has its work cut out for itself to build a large open source community anywhere near the sizes of Linux, GNU or Jakarta. Especially if its under a dodgy MS licence. All I've seen so far have been C# ports of existing Java open source projects (like NAnt, NUnit etc). Is there really much of a C# open source community out there?[James Strachan's Radio Weblog]
As someone who's turned most of their development attention to .NET (splitter), I'm feeling kind of isolated. OSS is totally alien to the existing MS community and the Java community view .NET as the plague. An umbrella is badly needed for the .NET OSS community.
How long until we see dotnet.apache.org? :)
[Joe's Jelly]
Late night ramblings.... Back to blogging... ahhhh.Nice to have you back, Russ. On Weblogic: Whoa, you've only got 4 gig of disk and a gig of RAM, are you sure she can take it captain? On JohnCompanies: I received the following at 10 pm PST on a friday night, after signing up at 1pm. Impressed.I sorta mentioned my new server setup in passing before, but I'm using OrionServer again and I love it. I was thinking about slapping a hacked copy of Weblogic on the server so I can work and play in the same environment, but Orion is just so nice I decided to play nice.
-Russ [Russell Beattie Notebook]
Hi, We have a really nice welcome message that we send out to new customers for our FreeBSD product, but I haven't finished writing the welcome message for our linux customers - I assume you'd rather not wait for that and just get an informal welcome. ...[account stuff skipped]... P.P.S. We are having a scheduled maintenance tomorrow (saturday) night for about 20 minutes ... this is rare and it is just a coincidence that it is happening the day after you sign up.A hosting firm that actually keeps their customers informed? Remarkable. Finally:
...we are very happy to have you as a customer...I think I'm going to be very happy being one.