[JBossWS] - file transfer via SOAP and RPC
by mendret
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
17 years, 3 months
[EJB 3.0] - Re: Migrating EJB3 Code from 4.2 to 5.0 and encountering [J
by jriley
I actually found the problem. It was caused by my ejb-jar.xml entries
My entries were something like this:
<?xml version="1.0" encoding="UTF-8"?>
| <ejb-jar version="3.0">
| <enterprise-beans>
| <session>
| <ejb-name>PropertyService</ejb-name>
| <remote>com.emageon.properties.service.PropertyService</remote>
| <ejb-class>
| com.emageon.properties.service.ejb.PropertyServiceBean
| </ejb-class>
| <session-type>Stateless</session-type>
| <transaction-type>Container</transaction-type>
| </session>
| </enterprise-beans>
| </ejb-jar>
The tags need to be changed to <business-remote>. Here is the corrected content.
<?xml version="1.0" encoding="UTF-8"?>
| <ejb-jar version="3.0">
|
| <enterprise-beans>
| <session>
| <ejb-name>PropertyService</ejb-name>
| <business-remote>com.emageon.properties.service.PropertyService</business-remote>
| <ejb-class>
| com.emageon.properties.service.ejb.PropertyServiceBean
| </ejb-class>
| <session-type>Stateless</session-type>
| <transaction-type>Container</transaction-type>
| </session>
| </enterprise-beans>
| </ejb-jar>
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4203691#4203691
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4203691
17 years, 3 months