Genial Daniel!! Gracias por la contribución. --- Salut, ==================================== Ricardo Borillo Domenech http://xml-utils.com / http://twitter.com/borillo
2010/5/6 Daniel Ibáñez - ADR Infor <[email protected]>: > Hola Ricardo, > > Adjunto el código. He probado enviándo 2 pdfs de 2.5 Mb cada uno, y parece > que no ha dado ningún problema. > > Hay que tener en cuenta que en la recepción, el archivo no se recibe como > $_POST['content'], sino com $_FILES['content']. $_FILES['content'][] es un > array, para acceder al contenido del fichero usaremos > > move_uploaded_file($_FILES['content']['tmp_name'], $nomArchivoDestino ); > > file_get_contents ($_FILES['content']['tmp_name'] ); > > > Éste sería el código de la clase: > //////////////////////////////////////////////////////////////////////////// > > package es.uji.security.ui.applet.io; > > import java.io.DataOutputStream; > import java.io.File; > import java.io.IOException; > import java.io.InputStream; > import java.net.HttpURLConnection; > import java.net.URL; > import java.net.URLEncoder; > import java.util.StringTokenizer; > > import netscape.javascript.JSObject; > > import org.apache.log4j.Logger; > > import es.uji.security.ui.applet.JSCommands; > import es.uji.security.ui.applet.SignatureApplet; > import es.uji.security.util.OS; > > public class URLUploadOutputParams extends AbstractData implements > OutputParams > { > private Logger log = Logger.getLogger(URLUploadOutputParams.class); > > private static final String NEWLINE = "\r\n"; > private static final String PREFIX = "--"; > > private String[] urls = null; > private int current = 0; > private boolean signOkInvoked = false; > private int _count = 1; > private int outputcount = 0; > private int conn_timeout = 10000; > private int read_timeout = 60000; > private String postVariable = "content"; > > public URLUploadOutputParams(String[] urls) > { > this(urls, "content"); > } > > public URLUploadOutputParams(String[] urls, String postVariable) > { > log.debug("Parametro URLS: "+urls); > log.debug("Parametro postVariable: "+postVariable); > > this.urls = urls; > this.postVariable = postVariable; > } > > public void setOutputCount(int oCount) > { > this.outputcount = oCount; > } > > public void setSignData(InputStream is) throws IOException > { > String cookies = ""; > > // Try to obtain and configure Cookies > try > { > log.debug("Recover JavaScript member: document"); > JSObject document = (JSObject) > JSCommands.getWindow().getMember("document"); > > cookies = (String) document.getMember("cookie"); > log.debug("Cookies: " + cookies); > } > catch (Exception e) > { > log.debug("Cookies can not be obtained", e); > } > > String urlOk = this.urls[current]; > > if (this.urls[current].indexOf('?') > -1) > { > urlOk = this.urls[current].substring(0, > this.urls[current].indexOf('?')); > } > else > { > urlOk = this.urls[current]; > } > > log.debug("Posting data to " + urlOk + ", with post parameter > variable " + postVariable); > > URL url = new URL(urlOk); > > HttpURLConnection urlConn = (HttpURLConnection) > url.openConnection(); > > urlConn.setConnectTimeout(conn_timeout); > urlConn.setReadTimeout(read_timeout); > > urlConn.setRequestMethod("POST"); > > String Boundary = ((Math.random()*1000000000000l) + > 9000000000000l)+""; > > urlConn.setRequestProperty("Content-Type", "multipart/form-data; > boundary="+ Boundary); > //urlConn.setRequestProperty("Content-type", > "application/x-www-form-urlencoded"); > > urlConn.setRequestProperty("Connection", "Keep-Alive"); > urlConn.setRequestProperty("Cache-Control", "no-cache"); > urlConn.setRequestProperty("Cookie", ""); > > urlConn.setDoOutput(true); > urlConn.setDoInput(true); > urlConn.setAllowUserInteraction(false); > urlConn.setUseCaches(false); > urlConn.setChunkedStreamingMode(1024); > > DataOutputStream out = new > DataOutputStream(urlConn.getOutputStream()); > > String str = PREFIX + Boundary + NEWLINE + > "Content-Disposition:form-data;name=\"item\"" + NEWLINE + NEWLINE + > URLEncoder.encode("" + _count, "ISO-8859-1") + NEWLINE; > > //System.out.println(str); > out.writeBytes(str); > > StringTokenizer strTok = new > StringTokenizer(this.urls[current].substring(this.urls[current].indexOf('?') > + 1), "&"); > > while (strTok.hasMoreTokens()) > { > String strAux = strTok.nextToken(); > log.debug("PROCESANDO TOKEN: " + strAux); > > if (strAux.indexOf("=") > -1) > { > String var = strAux.substring(0, strAux.indexOf("=")); > String value = strAux.substring(strAux.indexOf("=") + 1); > log.debug("ENVIANDO EN EL POST : " + var + "=" + value); > > str = PREFIX + Boundary + NEWLINE + > "Content-Disposition:form-data;name=\"" + var + "\"" + NEWLINE + NEWLINE + > URLEncoder.encode(value, "ISO-8859-1") + NEWLINE; > //System.out.println(str); > out.writeBytes(str); > } > } > > out.flush(); > > int contadorPartes = 0; > > log.debug("ENVIANDO EL FICHERO FIRMADO "); > > String strPostFile = PREFIX + Boundary + NEWLINE + > "Content-Disposition:form-data;name=\"" + postVariable + "\";filename=\"" + > postVariable + ".pdf\"" + NEWLINE + "Content-Type: application/pdf'" + > NEWLINE + NEWLINE; > //System.out.println((strPostFile)); > out.writeBytes((strPostFile)); > out.flush(); > > byte[] buffer = new byte[1024]; > int length = 0; > > while((length = is.read(buffer)) != -1) { > out.write(buffer, 0, length); > } > > try > { > is.close(); > new File(OS.getSystemTmpDir() + "/signature.xsig").delete(); > } > catch(Exception e) > { > } > > out.writeBytes(NEWLINE + PREFIX + Boundary); > // out.writeBytes(NEWLINE + PREFIX + Boundary); > > out.flush(); > out.close(); > > if (urlConn.getResponseCode() >= 400) > { > log.error("Error en el post: " + urlConn.getResponseCode()); > > throw new IOException("Error en el post: " + > urlConn.getResponseCode()); > } > > _count++; > current++; > } > > public void setSignFormat(SignatureApplet base, byte[] signFormat) > { > } > > public void setSignFormat(byte[] signFormat) throws IOException > { > } > > public void signOk() > { > if (!signOkInvoked) > { > log.debug("Call JavaScript method: onSignOk"); > JSCommands.getWindow().call("onSignOk", new String[] { "" }); > } > } > > public void flush() > { > _count = 1; > current = 0; > } > } > > //////////////////////////////////////////////////////////////////////////// > > Un saludo, > Daniel > > > -----Mensaje original----- > De: [email protected] > [mailto:[email protected]] En nombre de Ricardo Borillo > Enviado el: jueves, 06 de mayo de 2010 9:31 > Para: Llista de correu per al CryptoApplet > Asunto: Re: [CryptoApplet] Tamaño máximo Firmado PDFs > > Hola Daniel, > > El actual UrlOuputParams simplemente envía los parámetros por POST, > pero si quieres que incorporemos el soporte para el upload del > documento que comentas, puedes crear una nueva clase con esta > funcionalidad y enviarnos el parche (quizás podría ser algo como > UrlUploadOutputParams). De esta forma lo tendrás disponible en > próximas versiones ... > > --- > Salut, > ==================================== > Ricardo Borillo Domenech > http://xml-utils.com / http://twitter.com/borillo > > > > 2010/5/4 Daniel Ibáñez - ADR Infor <[email protected]>: >> Hola, >> >> He conseguido compilar CryptoApplet, y he averiguado cual era el problema. >> >> Parece ser que en la clase uji.security.ui.applet.io.UrlOutputParams al >> definir la propiedad urlConn.setRequestProperty >> Con >> urlConn.setRequestProperty("Content-type", >> "application/x-www-form-urlencoded"); >> >> el servidor no admite el POST. En cambio, definiendolo como >> >> urlConn.setRequestProperty("Content-Type", "multipart/form-data; boundary= >> --7d021a37605f0"); >> >> lo interpreta como un envoi de formulario con >> "enctype='multimart/form-data'" y no es rechazado. >> >> Así consigo enviar al servidor el documento firmado. >> Espero que os sea de utilidad. >> >> Un saludo, >> Daniel >> >> -----Mensaje original----- >> De: [email protected] >> [mailto:[email protected]] En nombre de Ricardo Borillo >> Enviado el: lunes, 03 de mayo de 2010 19:10 >> Para: Llista de correu per al CryptoApplet >> Asunto: Re: [CryptoApplet] Tamaño máximo Firmado PDFs >> >> Hola Daniel, >> >> Si tienes un checkout en el disco, tienes que utilizar la opción de >> importar proyectos. >> Si aun no has bajado el código, tienes que hacer el checkout desde el SVN. >> >> --- >> Salut, >> ==================================== >> Ricardo Borillo Domenech >> http://xml-utils.com / http://twitter.com/borillo >> >> >> >> 2010/5/3 Daniel Ibáñez - ADR Infor <[email protected]>: >>> Hola Ricardo, >>> >>> Ya tengo configurado el Eclipse con los 2 plugins, pero no se cuál es el >>> proceso a realizar para crear el proyecto: >>> ¿"File" -> "Import" -> "Checkout Projects from SVN? >>> >>> -----Mensaje original----- >>> De: [email protected] >>> [mailto:[email protected]] En nombre de Ricardo Borillo >>> Enviado el: lunes, 03 de mayo de 2010 10:23 >>> Para: Llista de correu per al CryptoApplet >>> Asunto: Re: [CryptoApplet] Tamaño máximo Firmado PDFs >>> >>> Hola Daniel, >>> >>> Usamos Eclipse con el plugin para Subversion >>> (http://subclipse.tigris.org/download.html) y el plugin para Maven >>> (http://m2eclipse.sonatype.org/) >>> >>> --- >>> Salut, >>> ==================================== >>> Ricardo Borillo Domenech >>> http://xml-utils.com / http://twitter.com/borillo >>> >>> >>> >>> 2010/5/3 Daniel Ibáñez - ADR Infor <[email protected]>: >>>> Hola Ricardo, >>>> >>>> Estoy intentando cargar el proyecto en Eclipse, pero no tengo ni idea de >>>> cómo cargarlo y compilarlo, ¿cómo realizáis la carga desde SVN? >> ¿Utilizáis >>>> algún otro tipo de editor? >>>> >>>> Un saludo, >>>> Daniel >>>> >>>> _______________________________________________ >>>> CryptoApplet mailing list >>>> [email protected] >>>> http://llistes.uji.es/mailman/listinfo/cryptoapplet >>>> >>>> >>> _______________________________________________ >>> CryptoApplet mailing list >>> [email protected] >>> http://llistes.uji.es/mailman/listinfo/cryptoapplet >>> >>> _______________________________________________ >>> CryptoApplet mailing list >>> [email protected] >>> http://llistes.uji.es/mailman/listinfo/cryptoapplet >>> >>> >> _______________________________________________ >> CryptoApplet mailing list >> [email protected] >> http://llistes.uji.es/mailman/listinfo/cryptoapplet >> >> _______________________________________________ >> CryptoApplet mailing list >> [email protected] >> http://llistes.uji.es/mailman/listinfo/cryptoapplet >> >> > _______________________________________________ > CryptoApplet mailing list > [email protected] > http://llistes.uji.es/mailman/listinfo/cryptoapplet > > _______________________________________________ > CryptoApplet mailing list > [email protected] > http://llistes.uji.es/mailman/listinfo/cryptoapplet > > _______________________________________________ CryptoApplet mailing list [email protected] http://llistes.uji.es/mailman/listinfo/cryptoapplet
