[
http://issues.apache.org/jira/browse/AXIS-2181?page=comments#action_12330683 ]
Clemente Simonetti commented on AXIS-2181:
------------------------------------------
Jan,
if I close the inputstream on the server side the download fail, here is the
full code:
>>>SERVER
private final String REPOSITORY = "C:\repository";
public void download(java.lang.String fileName) throws java.rmi.RemoteException
{
File downloadFile = new File(REPOSITORY+fileName);
if (!downloadFile.isFile())
throw new AxisFault("The file "+fileName+" not is in repository.");
MessageContext msgContext = MessageContext.getCurrentContext();
Message respMsg = msgContext.getResponseMessage();
respMsg.getAttachmentsImpl().setSendType(Attachments.SEND_TYPE_DIME);
MyFileDataSource fds = new MyFileDataSource(downloadFile);
DataHandler dhSource = new DataHandler(fds);
System.out.println("The file attached with the response is:
"+dhSource.getName());
AttachmentPart replyPart = new AttachmentPart(dhSource);
replyPart.setContentId(fileName);
respMsg.addAttachmentPart(replyPart);
try {
fds.getInputStream().close();
} catch (IOException e) {
throw new RemoteException(e.getMessage(), e);
}
}
>>>CLIENT
public static void download(String endpoint, String repositoryFile, File
destinationDir)
throws ServiceException, MalformedURLException,
RemoteException
{
if (repositoryFile == null)
throw new AxisFault("The name of file to download is NULL.");
Service service = new Service();
Call call = (Call) service.createCall();
call = (Call) service.createCall();
call.setOperationName(new QName(endpoint, "download"));
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
//Turn DIME on
call.setProperty(Call.ATTACHMENT_ENCAPSULATION_FORMAT,
Call.ATTACHMENT_ENCAPSULATION_FORMAT_DIME);
call.invoke( new Object[]{ repositoryFile } );
Message respMsg = call.getResponseMessage();
Attachments messageAttachments = respMsg.getAttachmentsImpl();
if (null == messageAttachments) {
throw new AxisFault("No support for attachments.");
}
if (messageAttachments.getAttachmentCount() == 0)
throw new AxisFault("No file received with response");
AttachmentPart p = (AttachmentPart)
messageAttachments.getAttachmentByReference(repositoryFile);
// move the attached file to the destination directory
try {
DataHandler dh = p.getDataHandler();
File attachedFile = new File(dh.getName());
File localFile = new File(destinationDir,
repositoryFile);
dh.getDataSource().getInputStream().close();
if (localFile.exists())
if (!localFile.delete())
throw new AxisFault("Local file already
opened, cannot delete.");
if (!attachedFile.renameTo(localFile))
throw new AxisFault("Cannot move file to the
destination directory.");
} catch (Exception e) {
throw new RemoteException(e.getMessage(), e);
}
}
Clemente.
> After sending an Attachments the local File can not removed from the
> filesystem ==> cause File is locked by axis?
> -----------------------------------------------------------------------------------------------------------------
>
> Key: AXIS-2181
> URL: http://issues.apache.org/jira/browse/AXIS-2181
> Project: Apache Axis
> Type: Bug
> Components: Basic Architecture
> Versions: 1.2
> Environment: Client: Windows 2000, PIII 800 MHz, 512 MB RAM.
> Server Windows 2003 Server, 512 MB.
> Reporter: Ferruh Zamangoer
> Priority: Critical
>
> Hi,
> we are using AXIS WS to send some MP3 files to an server where we register
> these files. The problem which occurred in our scenario is that after we have
> send the file we want to delete the local file on the filesystem. But we
> can?t delete the file because anything references or blocks the file. We have
> localized that the problem occurs in the part after the webservice call. When
> we uncomment the the part of the call the removing works. For sending our
> file as attachment we use the following code lines.
> boolean status = ws.registerContent("trebun",
> "password", ci); //call service
> System.out.println("status: " + status);
> File file = new
> File("MP3/RENCBER_DEWRANO_10_ELE__WWW.MP3"); //delete file
> boolean deleteState = file.delete(); ==> error occurs
> here?
> We cause for the error could be that a Stream are opened and not closed.
> FileDataSource fds = new FileDataSource(new File(filename));
> DataHandler contentHandler =
> new DataHandler(fds
> );
> The scenario can reproduced easily.
> 1. send and file to a server with attachment
> 2. After the Call of the webserice try to remove the local file without to
> shutdown your app.
> We are using on the client side the following Java Version:
> java version "1.4.2_05"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-b04)
> Java HotSpot(TM) Client VM (build 1.4.2_05-b04, mixed mode)
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira