Categories
Computing Java

Running the Apache James Mail Server as a Windows Service

To make the Apache James mail server into a service on your Windows machine, follow these instructions (shamelessly copied from here)

From a command prompt change directory to the bin folder located under the James installation directory. From the bin folder enter the following command

Wrapper.exe -i ..\conf\wrapper.conf

This will install the James NT service. You can then control this like another service from the Windows Services screen.

To remove the James service use this command

Wrapper.exe -r ..\conf\wrapper.conf

Share
Categories
Java SQL Server

Sending null values as parameters into a SQLServer stored procedure using JDBC

When calling a SQL Server stored procedure using JDBC’s CallableStatement object one uses its setXXX methods to set input parameters. XXX is the name of the type the input parameter is assumed to be of.
SQL Server does not support the setNull() method, throwing this exception:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC] The specified SQL type is not supported by this driver.

One way we went around this unpleasantry was to instead set the null value to be a different type, so instead of
setNull(position, variable)

There is an entry in the SQL Server JDBC newsgroup about this issue.
we create a new null String object and then call:
setString(position, nullString)

Share
Categories
Java

Servlets and submitting form using the POST method with enctype “multipart/form-data”

Uploading files from forms into a servlet appears to be a common sore in J2EE that was left to be addressed by developers. Apache has what appears to be a solid package in their org.apache.commons.fileupload package (get it here).

What is not clear (or if you merely forgot) is that when you use the form encoding (which you basically must when you are uploading a file) multipart/form-data is that the HttpServletRequest object will no longer hold the parameters from the form. You must use the a mechanism I found to be non-intuitive (if for the class names used if not anything else):

DiskFileUpload upload = new DiskFileUpload();
upload.setSizeMax(2000000); //max. file size 2M
List items = upload.parseRequest(portletRequest);
Iterator iter = items.iterator();
while (iter.hasNext()) {
// although it is named a FileItem it is actually a form input
FileItem item = (FileItem)iter.next();
// check whether it is the file being uploaded or a mere form input field
if (!item.isFormField()) {
// this is a file
String fileName = item.getName();
File location = new File(destinationDirectory + "/" + fileName);
item.write(location);
}
else
{
// this is a plain form field
String formFieldName = item.getFieldName();
String formFieldValue = item.getString();

}
}

Awkward.

Share
Share