[jboss-user] [JBossWS] - file transfer via SOAP and RPC

mendret do-not-reply at jboss.com
Wed Jan 21 10:34:35 EST 2009


hi folks,

I'm trying to write a webservice which is capable of receiving and sending files, for JBoss 5 GA.
So I'm quite new to webservices and jboss, thus I`ve got a few problems concerning this matter.

I`m quite sure that I need to use attachments to the soap message, but the question is how to do that?

I tried something using MTOM/SwaRef like it stand here:
http://jbossws.jboss.org/mediawiki/index.php/JAX-WS_User_Guide#Attachments

but the code fragments are a bit short, thus I wasn't able to see how I actually attach the files and retrieve them from the attachment

I tried the following:

Interface IFileTransfer:

  | @WebService(targetNamespace = "http://server/")
  | @SOAPBinding(style = SOAPBinding.Style.RPC, parameterStyle = SOAPBinding.ParameterStyle.BARE)
  | @BindingType(value="http://schemas.xmlsoap.org/wsdl/soap/http?mtom=true")
  | public interface IFileTransfer extends java.rmi.Remote {
  | 
  | 	@WebMethod
  | 	DocumentPayload beanAnnotation(DocumentPayload payload) ;
  | }
  | 

Implementation FileTransfer:

  | @WebService(name = "FileTransfer",
  | 			serviceName = "FileTransferService",
  | 			portName = "FileTransfer",
  | 			endpointInterface = "remote.IFileTransfer")
  | @SOAPBinding(style = SOAPBinding.Style.RPC)
  | public class FileTransfer implements IFileTransfer {
  | 
  | 	@WebMethod
  | 	public DocumentPayload beanAnnotation(DocumentPayload payload) {
  | 
  | 		System.out.println(payload.getData().getContentType());
  | 		//do something cool with the data
  | 		return payload;
  | 	}
  | }
  | 

DocumentPayload:


  | package remote;
  | 
  | import javax.activation.DataHandler;
  | import javax.xml.bind.annotation.XmlAttachmentRef;
  | import javax.xml.bind.annotation.XmlElement;
  | import javax.xml.bind.annotation.XmlRootElement;
  | 
  | @XmlRootElement
  | public class DocumentPayload
  | {
  |    private DataHandler data;
  | 
  |    public DocumentPayload()
  |    {
  |    }
  | 
  |    public DocumentPayload(DataHandler data)
  |    {
  |       this.data = data;
  |    }
  | 
  |    @XmlElement
  |    @XmlAttachmentRef
  |    public DataHandler getData()
  |    {
  |       return data;
  |    }
  | 
  |    public void setData(DataHandler data)
  |    {
  |       this.data = data;
  |    }
  | }
  | 

and on client side:

  | QName serviceName = new QName("http://server/", "FileTransferService");
  | 			Service service = Service.create(new URL("http://127.0.0.1:8080/SOAP-test?wsdl"), serviceName);
  | 			IFileTransfer port = service.getPort(IFileTransfer.class);
  | 
  | 			// enable MTOM
  | 			SOAPBinding binding = (SOAPBinding)((BindingProvider)port).getBinding();
  | 			binding.setMTOMEnabled(true);
  | 			DataHandler data = new DataHandler(new File("/opt/test.dat").toURI().toURL());
  | 			DocumentPayload dp = (DocumentPayload)port.beanAnnotation(new DocumentPayload(data));
  | 

hopefully you understand my problem and can give some good advices

mendret

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4203697#4203697

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4203697



More information about the jboss-user mailing list