* if problems were encountered
*/
public boolean deliver(Message message) throws CourierException, MalformedEPRException
{
if (_receiverOnly)
throw new CourierException("This is a pickUp-only Courier");
if (null == message)
return false;
// FileHandler is durable only for local filesystem (see
// checkEprParms())
FileHandler handler = (null != _localFhandler) ? _localFhandler
: FileHandlerFactory.getInstance().getFileHandler(_epr);
if (null == handler)
throw new CourierServiceBindException(
"Can't find appropriate file handler for "
+ _uri.toASCIIString());
Call call = message.getHeader().getCall();
if (null==call)
message.getHeader().setCall(call=new Call());
try
{
if (null==call.getMessageID())
call.setMessageID(new URI(UUID.randomUUID().toString()));
}
catch (URISyntaxException e)
{
throw new MalformedEPRException("Problems with message header ",e);
}
File tmpFile = null;
if (handler instanceof LocalFileHandler)
{
try
{
File dir = new File(_uri);
String name = message.getHeader().getCall().getMessageID()
.toString();
name += _inputSuffix;
tmpFile = CourierUtil.messageToLocalFile(dir, message);
handler.renameFile(tmpFile, new File(dir, name));
return true;
}
catch (final CourierException e)
{
throw new CourierTransportException(e);
}
catch (final IOException e)
{
throw new CourierMarshalUnmarshalException(e);
}
catch (final ParserConfigurationException e) // it's no longer thrown so we can ignore it!
{
throw new CourierException(e);
}
}
tmpFile = null;
try
{
Method upload = handler.getClass().getMethod("uploadFile",
new Class[]
{ File.class });
String sDir = FtpUtils.getLocalDir();
File dir = new File(sDir);
String name = message.getHeader().getCall().getMessageID().toString();
name += _inputSuffix;
tmpFile = CourierUtil.messageToLocalFile(dir, message);
File messageFile = new File(dir, name);
FileUtil.renameTo(tmpFile, messageFile);
tmpFile = messageFile;
upload.invoke(handler, new Object[]
{ messageFile });
return true;
}
catch (final IOException ex)
{
throw new CourierMarshalUnmarshalException(ex);
}
catch (final Exception e)
{
throw new CourierException(e);
}
finally
{
if ((null != tmpFile) && !tmpFile.delete() && _logger.isDebugEnabled())
{