Hello. I've created a web service with Axis2 to download a file
from server to client. When I execute the client, the server initiates the
download but it never stop. Can anyone help me?
Here is the server code :
public OMElement getFile () {
OMElement resultado = null;
try {
File file = new File ("D:\\temp\\prueba.zip");
OMFactory fac = OMAbstractFactory.getOMFactory();
resultado = fac.createOMElement("downloadFile", null);
FileDataSource fileDataSource = new FileDataSource (file);
DataHandler dataHandler = new DataHandler(fileDataSource);
OMText textData = fac.createOMText(dataHandler, true);
textData.setOptimize(true);
textData.setBinary(true);
resultado.addChild(textData);
}
}
catch (Throwable excepcion) {}
return resultado;
}
Here is the client code :
…
RPCServiceClient servicioCliente = new RPCServiceClient();
Options options = servicioCliente.getOptions();
EndpointReference targetEPR = new EndpointReference("
http://localhost:8080/axis2/services/MyService");
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
options.setTimeOutInMilliSeconds(300000);
options.setProperty(Constants.Configuration.ENABLE_MTOM,
Constants.VALUE_TRUE);
options.setProperty(Constants.Configuration.CACHE_ATTACHMENTS,
Constants.VALUE_TRUE);
options.setProperty(Constants.Configuration.ATTACHMENT_TEMP_DIR,"c:\\temp");
options.setProperty(Constants.Configuration.FILE_SIZE_THRESHOLD, "4000");
servicioCliente.setOptions(options);
OMElement respuesta = null;
File file = null;
try {
QName opMyOperation =
new QName ("http://distribucion.servicios.ietm.doc.indra.es/xsd","getFile");
Object[] argumentos = new Object[] { };
Class[] returnTypes = new Class[] {OMElement.class};
Object[] response = servicioCliente.invokeBlocking
(opMyOperation,argumentos,returnTypes);
respuesta = (OMElement) response[0];
if (respuesta != null) {
file = File.createTempFile(identificador,null,new File ("d:\\temp"));
file.deleteOnExit();
FileOutputStream fos = new FileOutputStream (file);
BufferedOutputStream bos = new BufferedOutputStream (fos);
OMText data = (OMText) respuesta.getFirstElement().getFirstOMChild();
DataHandler dataHandler = (DataHandler) data.getDataHandler();
dataHandler.writeTo(bos);
bos.flush();
bos.close();
}
…
--
Manuel Salvago García