You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by ph...@fr.netgrs.com on 2005/12/02 15:44:55 UTC

Downloading file attachments from an axis webservice

Hello,
I've been using axis for a while, but until now I only used to pass simple
types like Strings... Now I want to use Attachments. 
My goal is to have the server piloting an application that produces a file,
then send this file through SOAP to my client app. The file can be huge
(several GB of data).
The examples in the axis/samples directory look quite complex to me. I've
also seen some examples on how to upload file attachments to the server, but
never on how to download them...
 
Could someone provide me a sample code for server and client classes that
would allow me to do this easily ?
 
I would like, if possible, to use stubs generated by WSDL2Java on the client
side...
 
For now, I have a server code that looks like this :
 
import java.rmi.Remote;
import java.rmi.RemoteException;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.xml.soap.AttachmentPart;
import javax.xml.soap.SOAPMessage;
 
import org.apache.axis.MessageContext;
 
public class myService implements Serializable, Remote {
    public void getResultsFile() {
          MessageContext msgCntxt = MessageContext.getCurrentContext();
          SOAPMessage msg = msgCntxt.getMessage();
 
          DataHandler dataHander = new DataHandler(new
FileDataSource("c:\\Temp\\seqs.gb"));
          AttachmentPart attachment = msg.createAttachmentPart(dataHander);
          attachment.setContentId("attached_processed_file");
      msg.addAttachmentPart(attachment);
     }
}
 
The problem is that I don't know how to transmit the files to the client...
I can't figure out what kind of return my method should have instead of
"void" in order to process that information on the client side...
 
 
Thanks in advance for your help.
 
Best regards,
 
Philippe
 

Philippe SOARES 
E-mail : philippe.soares@fr.netgrs.com 
Institut de Recherches Servier (IdRS) 
125 Chemin de Ronde 
78290 CROISSY SUR SEINE - FRANCE 
Tél. : +33 (0) 1 55 72 25 31 
Fax : +33 (0) 1 55 72 20 81

 

Re: Downloading file attachments from an axis webservice

Posted by Tom Ziemer <t....@dkfz-heidelberg.de>.
Hi Philippe,

I am using Axis 1.3 (cvs). There are some issues with large attachments, 
but they should be fixed in the current 1.3 release, or as far as I 
know, by using Commons.HttpSender.
If you are using axis2, I'd suggest you take a look at MTOM 
(http://ws.apache.org/axis2/mtom-guide.html)

this is how I do it - works fine for me:
(NOTE: the wsdl will NOT reflect that attachments are being transmitted.)

/***************************
* server - some service:
***************************/
...
// do something meaningful, that produces data
...
// add the output file as attachment
Message response = context.getResponseMessage(); 
response.getAttachmentsImpl().setSendType(Attachments.SEND_TYPE_DIME);
DataHandler dh = new DataHandler(new FileDataSource(file));
AttachmentPart part = new AttachmentPart(dh);
response.addAttachmentPart(part);
// server - finished

/***************************
* client
****************************
...
// constructor
...
this.YOUR_SERVICE_HERE_Stub = (GENERATED_STUB_SoapBindingStub) new 
YOUR_SERVICE_ServiceLocator().getYOUR_SERVICE();
// call web service
MessageContext context = 
this.YOUR_SERVICE_HERE_Stub._getCall().getMessageContext();
DataHandler dh = this.extractAttachment(context);
dh.writeTo(os);

Hope that helps,
Tom

philippe.soares@fr.netgrs.com wrote:
> Hello,
> I've been using axis for a while, but until now I only used to pass 
> simple types like Strings... Now I want to use Attachments.
> My goal is to have the server piloting an application that produces a 
> file, then send this file through SOAP to my client app. The file can be 
> huge (several GB of data).
> The examples in the axis/samples directory look quite complex to me. 
> I've also seen some examples on how to upload file attachments to the 
> server, but never on how to download them...
>  
> Could someone provide me a sample code for server and client classes 
> that would allow me to do this easily ?
>  
> I would like, if possible, to use stubs generated by WSDL2Java on the 
> client side...
>  
> For now, I have a server code that looks like this :
>  
> import java.rmi.Remote;
> import java.rmi.RemoteException;
> import javax.activation.DataHandler;
> import javax.activation.FileDataSource;
> import javax.xml.soap.AttachmentPart;
> import javax.xml.soap.SOAPMessage;
>  
> import org.apache.axis.MessageContext;
>  
> public class myService implements Serializable, Remote {
>     public void getResultsFile() {
>           MessageContext msgCntxt = MessageContext.getCurrentContext();
>           SOAPMessage msg = msgCntxt.getMessage();
>  
>           DataHandler dataHander = new DataHandler(new 
> FileDataSource("c:\\Temp\\seqs.gb"));
>           AttachmentPart attachment = msg.createAttachmentPart(dataHander);
>           attachment.setContentId("attached_processed_file");
>       msg.addAttachmentPart(attachment);
>      }
> }
>  
> The problem is that I don't know how to transmit the files to the 
> client... I can't figure out what kind of return my method should have 
> instead of "void" in order to process that information on the client side...
>  
>  
> Thanks in advance for your help.
>  
> Best regards,
>  
> Philippe
>  
> 
> Philippe SOARES
> E-mail :_ philippe.soares@fr.netgrs.com_
> Institut de Recherches Servier (IdRS)
> 125 Chemin de Ronde
> 78290 CROISSY SUR SEINE - FRANCE
> Tél. : +33 (0) 1 55 72 25 31
> Fax : +33 (0) 1 55 72 20 81
> 
>