Hola, estoy creando una aplicacion para enviar y recibir ficheros PDF desde un webService, pero la verdad es que estoy un poco perdido y no se porque tengo los problemas que me está dando.
Este es el codigo que tengo en android:
Código:
String fichero=org.apache.commons.io.FileUtils.readFileToString(file);
new SubirFichero().execute(fichero, file.getName()).get();
private class SubirFichero extends AsyncTask<String, Void, String> {
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
}
@Override
protected String doInBackground(String... params) {
try {
MarshalBase64 b = new MarshalBase64();
byte[] fichero = params[0].getBytes();
request = new SoapObject(NAMESPACE, Constantes.METHOD_NAME_SUBIR_FICHERO);
request.addProperty("arg0", gson.toJson(cliente.getCliente()));
request.addProperty("arg1", fichero);
request.addProperty("arg2", params[1]);
SoapSerializationEnvelope sobre = new SoapSerializationEnvelope(SoapEnvelope.VER12);
sobre.setOutputSoapObject(request);
b.register(sobre);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(Constantes.SOAP_ACTION_SUBIR_FICHERO, sobre);
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (XmlPullParserException e) {
e.printStackTrace();
return null;
}
return "";
}
}
si lo hago asi se envia (por lo menos no da fallo), pero cuando el servidor tiene que crear un archivo con esos datos no lo hace bien y no se porque
Este es el codigo del servidor:
Código:
@WebMethod(operationName = "subirFichero", action = "urn:SubirFichero")
public void subirFichero(@WebParam(name = "arg0") String clienteCIF, @WebParam(name = "arg1") byte[] buf, @WebParam(name = "arg2") String nombreFichero){
Gson gson = new Gson();
Cliente registroNuevo = gson.fromJson(clienteCIF, Cliente.class);
Adjunto adjunto=new Adjunto();
AdjuntoPK adjuntoPK=new AdjuntoPK();
adjuntoPK.setCIFCliente(registroNuevo.getCif());
adjuntoPK.setNombreFichero(nombreFichero);
try {
adjuntoPK.setFichero(new SerialBlob(buf));
FileUtils.write(new File("E:/"+nombreFichero),new String(buf));
} catch (SerialException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
adjunto.setId(adjuntoPK);
em.getTransaction().begin();
em.persist(adjunto);
em.getTransaction().commit();
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
Alguien me puede ayudar? Que alternativas puedo tener para seleccionar un fichero en la aplicacion de android, enviarlo al servidor y almacenarlo en la BBDD, y mas tarde recuperar ese fichero y abrirlo en la aplicacion.
Gracias