Skip to main content

how to send attachments with jax-ws?

1 reply [Last post]
erkap
Offline
Joined: 2006-03-09

I want to send a soap request with attachments in my client app.

This is how I tried to send the attachments (can be images, sound..).

File[] files
...
SendMessageService sendMessageService = new SendMessageService();
SendMessage sendMessage = endMessageService.getSendMessage();

setEndpoint(sendMessage);

SecurityManager.setStubSecurity((BindingProvider)sendMessage);

DataSource dataSource = new FileDataSource(files[i]);
DataHandler dataHandler = new DataHandler(dataSource);

Map messageContext = ((BindingProvider)sendMessage).getRequestContext();

messageContext.put(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS, dataHandler);

But when I try to send a get
javax.xml.ws.WebServiceException: java.lang.RuntimeException: javax.xml.soap.SOAPException: java.lang.ClassCastException: javax.activation.DataHandler

So my question is how I in a simple way is going to attach my File[] to my SOAP message with JAX-WS?

I know that with Apache's Axis there is a method called org.apache.axis.client.Stub.addAttachment(Object arg0) and I'm porting the application from Axis to JAX-WS...

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ramapulavarthi
Offline
Joined: 2004-06-01

The Type of OUTBOUND_MESSAGE_ATTACHMENTS is java.util.Map

You are trying to put DataHandler directly in this property.
Trying creating a Map of attachments as listed above and set it on the property