Friday, January 27, 2006

Suns J2EE JMS Example in eclipse

I'm hastily trying to learn all things java. To add to the mix, its the enterprise stuff. Before this week I'd heard of "enterprise Java," but never really understood what it meant. It appears to mean "complicated, scalable Java."

I've been looking into all aspects of it, specifically Java Messaging Service (JMS) which is a scalable messaging system between java programs.

I ran through the tutorial from Sun [http://java.sun.com/j2ee/1.4/docs/tutorial/doc/index.html] (be sure to get the tut specific to your SDK, it seems to change quite a bit), and had a bit of trouble with it, as I didn't understand the need to package the code into jars, and run it via the "appclient" batch file provided by Sun [http://java.sun.com/j2ee/1.4/docs/relnotes/cliref/hman1m/appclient.1m.html].

This sets up the environment to allow the "application client" to run under the control of the application server, and have full access to its queues etc. This is necessary because of something called Environment Naming Context (ENC) which the application needs to have access to to connect to the application server.

C:\JMS_Test\bin>appclient -client SimpleProducer.jar jms/Queue 4

Works perfectly.

With that running the next step was to get it running from within Eclipse. After many dead ends, I found someone who had had this problem before [http://forum.java.sun.com/thread.jspa?threadID=484229&tstart=90]. I mostly followed his instructions, not quite - here's what worked for me:
I set up a project in eclipse, just an ordinary project, and added a source folder to it. I then copied in the simplified code supplied by Sun. Running this leads to a series of problems. The first thing that needs set is command line arguments. Right click the project and select debug as -> debug.... - from the dialog select the arguments tab, and insert "jms/Queue 3" (without the quotes) into the top box. This specifies the command line arguments expected in the program.

This gets through the first part of the code, but then throws an NoInitialContextException Exception:
JNDI API lookup failed: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial

This is because the environment is not set up properly. That's where This article comes in - I set up the project as suggested :
1) Set the VM Arguments (in the Arguments Tab [debug as -> debug...])
-Dcom.sun.aas.installRoot="%AS_INSTALL%" -Dcom.sun.aas.imqLib="%AS_IMQ_LIB%" -Djava.security.policy="%AS_INSTALL%\lib\appclient\client.policy" -Djava.security.auth.login.config="%AS_INSTALL%\lib\appclient\appclientlogin.conf" -Djava.endorsed.dirs="%AS_INSTALL%\lib\endorsed" -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl -Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl -Djavax.xml.transform.TransformerFactory=org.apache.xalan.xsltc.trax.TransformerFactoryImpl -Dorg.xml.sax.parser=org.xml.sax.helpers.XMLReaderAdapter -Dorg.xml.sax.driver=org.apache.xerces.parsers.SAXParser
2) In the Classpath Tab, click on user entries and add the following External Jars:

From the directory C:\Sun\AppServer\libj2ee.jar
appserv-rt.jar
appserv-ext.jar
mail.jar
activation.jar
jaxrpc-impl.jar
saaj-impl.jar
jaxr-impl.jar
relaxngDatatype.jar
xsdlib.jar
install\applications\jmsra\imqjmsra.jar
appserv-cmp.jar
appserv-admin.jar
From the directory C:\Sun\AppServer\imq\lib\
fscontext.jar


Debugging this application now works. Phew.

Friday, January 13, 2006

Explorer crash when viewing thumbnail AVIs

This Google Groups article helped me fix a problem with explorer crashing when browsing folders of avi files. I reallly don't know what the problem was, but this solution worked, although it is a workaround rather than a fix.

regsvr32 /u shmedia.dll

Wednesday, January 04, 2006

ASP.Net Application Architecture

Maybe not really an "architecture" as such, perhaps more of a set of design goals, or statements. For a recent project I came up with the following:

1) Authentication is carried out in Global_AcquireRequestState. Only done once, then a session variable is set
2) All pages inherit from a BasePage class which provides:
- A "DataAccess" object through which all database activity is conducted (see later)
- A "UserSession" object which is used instead of the default "Session" (see later)
- Global catch all exception handling - for unrecoverable errors
3) All database interaction uses NHibernate
4) DataAccess is a class which collates all NHibernate functions, so the application simply calls dataAccess.GetUserList() to return a list of user objects etc...
5) UserSession is a small class which contains typesafe session variables, so rather than Session["someVar"] I can do UserSession.SomeVar - strongly typed, intellisense friendly and less error prone. I dislike HashTables keyed by text strings, I see this as a very unsafe practice.
6) No code or logic whatsoever in the aspx file - all in the code behind
7) HTTP GET on all page deliveries
- HTTP POST back form data, process it, and then Response.Redirect() to the viewing page - prevents “Warning: Page has Expired” messages
- Item Ids are passed in the URL, so bookmarking of pages is possible
8) Button clicks are all handled in event handlers
9) Consts all places in a globally accessible file, static classes used. E.g. Page names are declared in a static class called “Pages” allowing the developer to use the following syntax to redirect to a page: Response.Redirect(Pages.AccountDetails)

Any comments welcome.

Is it legal to copy DVDs and CDs to my PC?

I thought not. For a number of reasons. Firstly I thought it was illegal to copy something that is copyrighted. Then I hear I can backup for personal use. That sounds like a stretch to me too, because if you "backup"you don't typically exclusively use the "backup" - you use the source, and only resort to the backup if the primary fails.

However, I came across this today: From this google groups post I see that The Copyright, Design and Patents Act 1988 section 197 [click here] declares that a copy "for private purposes" is not an illicit recording, and thus any action under the CDPA against me for making a copy of a CD or DVD for my own private use would fail.

Turns out it's legal after all. I'll carry on as before then.