Today i am going to share for my experience how to send binary attachments to a webservice using apache axis.The following piece of code will help you to do the same.
String endpoint = "http://localhost:9000/ecm/yourwebservice.jws";
javax.activation.DataHandler dataHandler = new javax.activation.DataHandler(
new FileDataSource(
"C:\\WINDOWS\\TEMP\\user\\data\\metadata.xml"));
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
QName qnameAttachment = new QName("uploadUser", "DataHandler");
call.addParameter("source", qnameAttachment, ParameterMode.IN);
call.registerTypeMapping(dataHandler.getClass(), // Add serializer for attachment.
qnameAttachment, JAFDataHandlerSerializerFactory.class,
JAFDataHandlerDeserializerFactory.class);
call.setOperationName("uploadUser");
call.invoke(new Object[] { dataHandler});
The above code is the client.
The webservice will be something like this
public void uploadUser(DataHandler handler){
InputStream in = handler.getInputStream();
//in is the bytes send by the client to the webservice
}
Thats all how we can send attachments to webservice.
Happy Coding
Thursday, August 27, 2009
Subscribe to:
Post Comments (Atom)
1 comment:
hey ajay, nice blog for quick fundas.
Particularly i liked bcoz they are small and informative.
Post a Comment