hi,
i have a webservice developed which save a file on a server. A client send a file using DataHandler. So the in the exchange from java to wsdl Datahandler is replaced by byte Array. The web method is like following:
@WebMethod
public String StoreFileService(DataHandler dh, String fileName){
try {
System.out.println(">>>> StoreFileService storing File to /home/younes/StoredFile/" + fileName);
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("/home/younes/StoredFile/"+ fileName));
BufferedInputStream in = new BufferedInputStream(dh.getInputStream());
byte [] buffer = new byte[256];
while (true){
int bytesRead = in.read(buffer);
if (bytesRead == -1)
break;
out.write(buffer, 0, bytesRead);
}
in.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
return ("File process succesfully " + fileName + " "+ new Da
die WSDL is like so:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
man see that DataHandler is replaces by "xsd:base64Binary" in the wsdl. I have created the web service stub using wsimport.
On the client side the webmethod StoreFileService(DataHandler dh, String fileName) support not DataHandler. As a parameted will be byte[] expected. So i habe used byte[] on client side
the client is like so:
package client;
import gen.clientgen.StoreFile;
import gen.clientgen.StoreFileService;
import java.io.ByteArrayOutputStream;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
public class StoreFileClient {
/**
* @param args
*/
static StoreFileService service = new StoreFileService();
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
StoreFileClient client = new StoreFileClient();
client.doTest(args);
} catch (Exception e) {
e.printStackTrace();
}
}
private void doTest(String[] args) {
try {
System.out.println(" Retrieving port from the service " + service);
StoreFile port = service.getStoreFilePort();
System.out.println(" Invoking StoreFileService Operation");
String file = "D:/soabpelopenesb.pdf";
DataHandler dh = new DataHandler(new FileDataSource(file));
//convert DataHandler to byte []
ByteArrayOutputStream buffOS = new ByteArrayOutputStream();
dh.writeTo(buffOS);
byte[] buff = buffOS.toByteArray();
//invoke service
String resp = port.storeFileService(buff, "soabpelopenesb.pdf");
System.out.println("Response from the server: " + resp);
} catch (Exception e) {
e.printStackTrace();
}
}
}
i have deployed the webservice under JBoss-5.0.1 AS and i have tried to call it. An Error was occured on the server side like the following:
javax.xml.ws.soap.SOAPFaultException: com.sun.xml.bind.v2.util.DataSourceSource cannot be cast to javax.activation.DataHandler
at com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:188)
at com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:108)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:119)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:89)
at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:118)
at $Proxy22.storeFileService(Unknown Source)
at client.StoreFileClient.doTest(StoreFileClient.java:57)
at client.StoreFileClient.main(StoreFileClient.java:25)
can someone help me.
thanks in advance
youens