Multipart request is garbled in case of binary file (excel)

Hi,
I am having problem in uploading file in our portal application.
Setup:
We have a 10g portal server (10.1.0.4). Authentication is done using coreid.
We have a http apache server hosted on a different machine with webgate plugin protecting all the request. Coreid is hosted on a different machine. So we have three machines, one for http server, one for portal server and one for coreid. The request is SSL request.
When I submit a multipart request, I am not able to upload the file. When I printed the whole request in a file, I could see header of file item (which contains filename, content type etc.) is getting stripped off. Not only this, any html element above "file" element in the form is also stripped off. This happens only in case of binary file. Uploading text files works fine.
Above case is when I submit the request to http apache server.
Now if I submit the multipart request directly to portal server, file upload works fine, both for text and binary (excel).
What is different in these two cases:
In case of first case request is going thru http server and webgate. SSL is configured in http server, so request is SSL request.
In second case, submitting directly to portal server, the request is not over SSL.
Please help me solving this problem.
Help is greatly appreciated.
Regards,
Rana Biswas

Would like to add another thing, the problem is not limited to portal application. I created two simple jsps one form and another to receive the multipart request and deployed it in a separate application, which is NOT a portal application.
Same problem is there.
Regards,
Rana Biswas

Similar Messages

  • Multipart/form-data using HTTPService, sending a binary file and some text in the same request.

    Hi There,
             I am new to FLEX and also new to writing a client for a web service.
    My question is more about flex (Flash builder 4.5) APIs, what APIs to use.
    I want to access a web service, that's published here.
    https://build.phonegap.com/docs/write_api
    here is the description of webservice
    ===========
    1) I have to do a post on POST https://build.phonegap.com/api/v1/apps
    2) content type has to be "multipart/form-data"
    3) JSON bodies of requests are expected to have the name 'data'
      data will be someting like this
    'data={"title":"API V1 App","package":"com.alunny.apiv1","version":"0.1.0","create_method":"file"}'
    4) include a zip file in the multipart body of your post, with the parameter name 'file'.
    ===========
    I want to make a 'multipart/form-data' Post and send
    one string and one zip file.
    My first question to self was If i send both string + binary data in the body ...
    how will server understand where string end and where zip file starts?
    Then read on W3.org( http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2 )
    How is text + binary data can be sent through "multipart/form-data" post requst.
    there has to be some boundries.
    After this I read and example in flex and  tried following it.
    http://codeio.wordpress.com/2010/04/03/5-minutes-on-adobe-flex-mimic-file-upload-for-in-me mory-contents/
    but it doesn't seems to be working for me.
                        public function createNewApp(cb:Function , appFile : File):void
                                  var service:HTTPService = new HTTPService();
                                  service.url = ROOT+"apps";
                                  service.showBusyCursor = true;
                                  service.addEventListener(ResultEvent.RESULT, function(e:ResultEvent):void {
                                            //translate JSON
                                            trace(e.result);
                                            var result:String = e.result.toString();
                                            var data:Object = JSON.parse(result);
                                            cb(data.link);
                                  service.addEventListener(FaultEvent.FAULT, defaultFaultHandler); //todo : allow user to add his own as well
                                  authAndUploadNewApp(service,appFile);
                        private function authAndUploadNewApp(service:HTTPService,appFile : File):void {
                                  var encoder:Base64Encoder = new Base64Encoder();
                                  encoder.encode(username + ":"+password);
                                  service.headers = {Accept:"application/json", Authorization:"Basic " + encoder.toString()};
                                  service.method ="POST";
                                  var boundary:String = UIDUtil.createUID();
                                  service.contentType = "multipart/form-data; boundary=—————————" + boundary;
                                  var stream:FileStream = new FileStream();
                                  stream.open(appFile, FileMode.READ);
                                  var binaryData:ByteArray = new ByteArray();
                                  var fileData : String = new String();
                                  stream.readBytes(binaryData);
                                  stream.close();
                                  fileData = binaryData.readUTFBytes(binaryData.bytesAvailable); // I think this is where I have problem.... how do
                           //how do i converrt this bytearray/stream of data to string and send it in my post request's body - i guess if this step work rest should work..  
                                  var params: String = new String();
                                  var content:String = "—————————" + boundary + "nr";
                                  content += 'Content-Disposition: form-data; name="data";' + '{"title":"ELS test app 2","package":"com.elsapp.captivate","version":"12.3.09","create_method":"file"}' + "nr";
                                  content += "—————————" + boundary + "nr";
                                  content += 'Content-Disposition: form-data; name="file";' + fileData  + "nr";
                                  content += "—————————–" + boundary + "–nr";
                                  service.request = content;
                                  service.send();

    In the past I have used URLVariables with URLRequest and URLLoader to achieve this kind of requirement.
    Check out http://livedocs.adobe.com/flex/3/html/help.html?content=17_Networking_and_communications_3 .html which should be useful. My preference has always been to use this style instead of HTTPService objects, giving you a little more control which is what you need here.
    Let me know if you need any more assistance.

  • Multipart request and modern browsers

    Hi!
    I want to write own parser of multipart http request for my http service. I have tried to find not-outdated (as, say, RFCs are) information about the ways modern browsers form the request with all their (browsers's) bugs (IE, am sure, has plenty of them as always), but have not found any information (the information which I have found is scattered and far from to be complete).
    Can anybody point me appropriate resources to dig in?

    ChrisBoy wrote:
    Hi Anli,
    Can you tell us a little more about what you're trying to achieve and why the servlet framework is not appropriate?
    If you are using Java to field HTTP requests, then you will most likely be using servlets, either explicitly (i.e. writing your own servlet) or implicitly (for example through JSP).
    Chris.Chris,
    As I have mentioned, I do use servlets (during many years). OTOH, it doesn't mean the servlet framework is the only universal way to provide http service at all use cases (say, I need more flexible dispatching rather web.xml offers, or don't want to deploy all servlet framework related jars chain, or want to have fine tuning of resources consumption, and such...). The own http service works fine, but now I'm interested in adding multipart request parsing. So, the question isn't "what is my motivation" or "how to write code", but rather "where to find the information about" :-)

  • Uploading a file without using multipart request

    I want to upload a xml file from my java application(standalone, no webserver involved) ... please suggest. I am able to do it through servlet multipart request but don't want to continue with that just to bypass the browser interaction the client have to perform to choose the said file.
    thanks

    Upload to what? You need something running on the machine where the file is to be uploaded to. If it's not a web server, then you'll have to run something else. Once you decide what that is going to be, then you will have to change your program to send the XML file to that server.

  • Mixed/multipart Request with a image file and a amr audio file

    Hi people
    I am struggling with multipart/mixed request as i am new to java and http. I basically have to write a java code to send a request with two attachments, an audio amr file and a image file of a proprietry format. following is my code
    public static void GetVideo()
         HttpURLConnection httpConnection = null;
    InputStream bis = null;
         InputStream bis1 = null;
    OutputStream bos = null;
         File audioFile = new File("voicejunk.amr");     
         File avatarFile = new File("out.frf");
         System.out.println("Entered Get Video");
         String Boundary = new String("asdfgh");
    try
    URL url = new URL("http://10.4.21.51:5006/");
    httpConnection = (HttpURLConnection) url.openConnection();
         httpConnection.setRequestProperty("Cache-control", "no-cache");
    httpConnection.setRequestProperty("Pragma", "no-cache");
    httpConnection.setRequestProperty("Content-Type", "multipart/mixed;boundary= \"asdfgh\"");
         httpConnection.setRequestProperty("video-type", "3GPP");
         httpConnection.setRequestProperty("video-encoder", "H.263");
    httpConnection.setRequestProperty("audio-encoder", "AMR-NB");
         httpConnection.setRequestProperty("video-size", "QCIF");
         httpConnection.setRequestProperty("video-fps", "10.0");
         httpConnection.setRequestProperty("video-anti-aliasing","yes");      
         httpConnection.setRequestProperty("Content-Length", Long.toString(audioFile.length()+avatarFile.length()+(3*Boundary.length())));     
         //byte[] bytes = createMessage();
         //httpConnection.setRequestProperty("Content-Length", String.valueOf(bytes.length));     
    //System.out.println("Size of: "+bytes.length);     
         httpConnection.setRequestProperty("Expect", "100-continue");          
         httpConnection.setRequestProperty("Connection", "Keep-Alive");
         //String AvatarType = new String("FRF");     
    httpConnection.setRequestMethod("POST");
         httpConnection.setDoOutput(true);     
         bos = new BufferedOutputStream(httpConnection.getOutputStream());
         bos.write(Boundary.getBytes());
         Session session = Session.getDefaultInstance(new Properties());          
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         Message msg = new MimeMessage(session);
    MimeBodyPart mbp1 = new MimeBodyPart();
    FileDataSource filedatasource1 = new FileDataSource("seestorme.frf");
    DataHandler dh1 = new DataHandler(filedatasource1);
    mbp1.setDataHandler(dh1);
    mbp1.setHeader("Content-Type", "x-seestorm-avatar/frf");
         MimeMultipart mmp = new MimeMultipart();
    mmp.addBodyPart(mbp1);
    msg.setContent(mmp);
    msg.writeTo(baos);
         bos.write(baos.toByteArray());     
    bos.write(Boundary.getBytes());
         ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
         Message msg2 = new MimeMessage(session);     
         MimeBodyPart mbp2 = new MimeBodyPart();
    FileDataSource filedatasource2 = new FileDataSource("voice.amr");
    DataHandler dh2 = new DataHandler(filedatasource2);
    mbp2.setDataHandler(dh2);
    mbp2.setHeader("Content-Type", "audio/amr-nb");
         MimeMultipart mmp2 = new MimeMultipart();
    mmp2.addBodyPart(mbp2);
         msg2.setContent(mmp2);
    msg2.writeTo(baos2);
         bos.write(baos2.toByteArray());     
    bos.write(Boundary.getBytes());          
    //httpConnection.getOutputStream().write(bytes);
         //httpConnection.getOutputStream().flush();
         System.out.println("Request made");
    int result = httpConnection.getResponseCode();
         String Msg1 = new String(httpConnection.getHeaderField(0));
         String Msg2 = new String(httpConnection.getHeaderField(1));
         String Msg3 = new String(httpConnection.getHeaderField(2));
         String Msg4 = new String(httpConnection.getHeaderField(3));     
         String Msg5 = new String(httpConnection.getHeaderField(4));
         System.out.println(Msg1+" " + Msg2+" " + Msg3+" " + Msg4+" " + Msg5+" ");
    if (HttpURLConnection.HTTP_OK == result) {
              System.out.println("Received HTTP result = " + result);
    saveResponseData2(httpConnection.getInputStream(),"SeeStorm.frf");
    } else {
    System.out.println("Received HTTP result = " + result);
         catch (MessagingException me) {
    me.printStackTrace();
    catch (MalformedURLException mue) {
    mue.printStackTrace();
    } catch (ConnectException ce) {
    ce.printStackTrace();
    } catch (IOException ioe) {
         ioe.printStackTrace();
    } finally {
    if (null != bis) {
    try {
    bis.close();
    } catch (IOException ioe) {
    ioe.printStackTrace();
    if (null != httpConnection) {
    httpConnection.disconnect();
    i frankly have no idea how to create a multipart mixed request with boundaries. I get a bad http request error with the above code. Can please someone help me.
    Thanks
    Adil Saleem

    Your WriteImage servlet needs to read the image file in from wherever it is (hard drive, database, whatever), then write it back out to the browser. To do that, first use the HTTPServletResponse object to send the appropriate headers, then call the getOutputStream() method to get an output stream to write the data to. This data will be sent to the browser which, if you've set the headers correctly, will display it as an image.
    It's been a long time since I did this (we abandoned storing images in databases quite a long time ago), so I can't be more specific than that, but hopefully that'll be enough to get you going. If you run into any problems, reply and I'll see if I can help further.

  • Issue in downloading Binary File on Safari 5 (MAC OS)

    Hi,
    We are working on an application, which download binary file when clicks the button, when i am using Safari 6 the below code snippet download file successfully.
    Image:
    Safari 6: on clicking Export file downloaded:
    code:
    String userAgent = request.getHeader("user-agent");
                if (userAgent.toLowerCase().indexOf("mac") >= 0) {
                    response.setContentType("application/octet-stream");
                } else {
                    response.setContentType(TEXT_CSV);
                // These Lines were added to make it work on the secure https
                // connection
                response.setHeader("Pragma", "public");
                response.setHeader("Cache-Control", "max-age=0");
                response.setHeader("Content-Disposition", "filename=contacts.csv");
    but when we use safari 5 on MAC its not downloading the file, it simply display the content on browser it self
    Image:
    and file is not downloaded in this case, can some one tell what should be the contentType(""); should be set to download the file in Safari 5, so that the file can be downloaded in case of Safari 5.
    Thanks in advance:)

    You can set content type to:
    response.setContentType("application/vnd.ms-excel");
    file will download on safari 6

  • Problem when streaming out a binary file

    Hi,
    I am trying to stream out a binary file to an output stream (not a file, but a socket). My file is a gzip file, and I was initially simply trying to open the
    file, read it to a a byte array, and writing it out to my output stream. However, I got corrupted data at my other end and it took me quite a bit of
    debugging hours to find out why.
    I tried writing to a file the same information I was writing to my output stream but, although my file was correct, my output stream still contained
    corrupted data.
    I think I have finally narrowed down my problem to the fact that when I try to write a 0x00 value to my output stream, everything gets ignored from this
    point until I write a 0x0a byte to my output stream. Obviously this produces corrupted data, since I need all the bytes of my binary file.
    If somebody can direct me as to how to write a 0x00 value to a socket output stream, I would really appreciate your input.
    This is a sample of my code (Right now I am writing byte by byte: not very efficient, but was the only way I found where I was getting a problem):
    // out is of type OutputStream
    if (Zipped){
         // In this case we just have to stream the file out
    File myFile = new File(fileName);
         FileInputStream inputFile = new FileInputStream(myFile);
         FileOutputStream fos = new FileOutputStream(new File("/tmp/zip.gz")); //zip.gz results in a good (not corrupted) file.
         ByteArrayOutputStream out1 = new ByteArrayOutputStream(1024);
         int bytes = (int)myFile.length();
         byte[] buffer = new byte[bytes];
         bytes = inputFile.read(buffer);
         while (bytes != -1) {
              out1.write(buffer,0,bytes);
              bytes = inputFile.read(buffer);
         inputFile.close();
         try {
              int count=0;
              bytes=out1.size();
              while (count<bytes){
                   fos.write(buffer,count,1);
    out.write(buffer,count,1); // when buffer[count] == 0x00, everything after it gets ignored until a 0x0a byte is written.
                   count++;
         } catch (IOException ioe) {
              SysLog.event("IOEXCEPTION: "+ioe);
         } catch (Exception e) {
              SysLog.event("EXCEPTION: "+e);
         fos.flush();
         fos.close();
         out.flush();
    out.close();
         return;
    }

    Actually, I had thought about that and for some time I tried getting rid of some of the header information in the gzipped file, and then I stopped doing that when I realized that part of the gzipped file is a CRC value which I believe is computed taking into account both the data of the file and the header information. If this is the case, then getting rid of part of the header would produce a corrupted file ... but then, I might be wrong in this issue.
    Anyway, to make my application more clear, what I am doing is writing the code for a cgi command which is suppossed to access information from a database, create an xml file, gzip it, and then send it to the client who requested the information.
    Therefore, what I am sending is an xml file (Content-Type: text/xml) in compressed format (Content-Encoding: gzip). Note that if I don't gzip the file and then send it uncompressed to the client, I have no problems. However, for me it is very important to gzip it because the size of the file can get very large and that would just take bandwidth unnecessarily.
    On the other hand, if I try to gunzip the file locally, I have no problem either (the file is not corrupt at the server's end). Therefore, my problem is when I stream it out.
    Any further help would be really appreciated!

  • Binary file with File adapter

    Hi gurus,
    I am getting binary file as base64binary (not a text/xml file) in a request XML tag. I need to write this file to a file directory with the file adapter after retrieving it from the request message by a message/java mapping and use another field in XML as the file name.
    I followed the blog `how to send binary data through PI` but in that case, the request message is also the same. Mine requires a mapping to be executed and in this case I cannot use dummy names for message types/interfaces as Enterprise Repository development is required.
    How can I achieve this?
    Thanks
    Gokhan

    Just solved the problem actually
    As I was trying to write a binary file directly with the receiver file adapter, I wasn't sure how to define a data type / message type for it. I developed a java mapping that decodes the base64 to binary data and writes it to the output stream, and used a dummy message type / data type for the service interface as the target in Operation Mapping
    And it worked!
    Regards,
    Gökhan

  • Read a binary file written by a C program

    Hi,
    I have a binary file that is written by a C program. The C program fills the values into a structure and then writes to the binary file. I posted a message earlier requesting for help in reading this data and got the help. I am able to read the various fields.
    The question is in the link below.( Just in case of reference)
    http://forum.java.sun.com/thread.jsp?forum=31&thread=509414
    My question is the structure totally has 32456 bytes. It is kind of very difficult to get the values that I require as it is scattered. Moreover, the structure is nested. Based on a count in the first structre I have to loop that many times the second structre and retrive a particular value each time.
    For example : I have this
    typedef struct {
    int a;
    char b[10];
    int c;
    } one;
    typedef struct {
    long d;
    char e[9];
    char f[8];
    }two;
    typedef struct {
    one first;
    two second[10];
    }main;
    So, here first i will have to get the int c from struct one and based on that value i will have to loop the struct two. The maximum value can be 10 which is given in struct main.
    So, if i use DataInputStream, ByteBuffer and get the values based on buffer.getInt(), etc the process is very tedious and i tend to make error in counting the bytes to get the values as such. Moreover as I have said, the byte array is very large.
    Is there any other simple way to do this. I dont need to write to the file. I will just need to read from the file based on the C header. Do, I need to use JNI for this, in that case any pointers would be very much useful as I am very far from those topics.
    Thanks,
    Sreeni.

    So, what is the possible solution for this. I am badly
    needing this to complete my project.
    The solution has been provided to you. The only alternative would be to read the file using JNI and populate and create Java objects using the native interface. This would most likely be more difficult than just doing it using byte counting.
    I'm certain that a creating person could create a bunch of method calls that could encapsulate each structure used here. Doing this byte by byte is really a trivial exercise - you could have it finished and working in less than an hour if you put your mind to it.
    - K

  • Urgent - pls help - Problem while inserting binary file into Oracle DB

    Hi,
    I am trying to insert binary files into a Blob column in a Oracle 10G table.
    The binary files would be uploaded by the web users and hence come as multipart request. I use apache commons upload streaming API to handle it. Finally i am getting a input stream of the uploaded file.
    The JDBC code is
    PreparedStatement ps=conn.prepareStatement("insert into bincontent_table values(?)");
    ps.setBinaryStream(1,inStream,length);
    My problem starts when i try to find the length of the stream. available() method of inputstream does not return the full length of the stream. so i put a loop to read thru the stream and find the length as shown below
    int length=0;
    while((v=inStream.read())!=-1)
    length++;
    Now, though i got the length, my stream pointer has reached the end and i cant reset it(it throws an error if i try).
    So i copied the stream content to a byte array and created an ByteArrayInputStream like this.
    tempByteArray=new byte[length];
    stream.read(tempByteArray,0,length);
    ByteArrayInputStream bais=new ByteArrayInputStream(tempByteArray);
    Now if i pass this bytearray input stream instead of the normal input stream to the prepared statement's setBinaryStream() method it throws an error as
    "ORA-01460: unimplemented or unreasonable conversion requested".
    Now how to solve this?
    My doubts are ,
    1) preparedStatement.setBinaryStream(int parameterIndex, InputStream x, int length) expects an inputstream and its length. if i have the stream how to find its length with out reading the stream?
    2) Also as the length parameter is a integer, what if i have a large binary file whose length runs more than the capacity of integer
    3) Alternatively there is a setBlob(int i, Blob x) in prepared statement. But how to instantiate a Blob object and set it here
    4) Is there any better way to do this.
    Thanks in advance

    "ORA-01460: unimplemented or unreasonable conversion
    requested".When the setBinaryStream method is used, the driver may have to do extra work to determine whether the parameter data should be sent to the server as a LONGVARBINARY or a BLOB (reference: javadoc)
    1) preparedStatement.setBinaryStream(int parameterIndex,
    InputStream x, int length) expects an inputstream and its length. if i
    have the stream how to find its length with out reading the stream?no. stream may have no specified length. i think you have wrong understanding about stream.
    2) Also as the length parameter is a integer, what if i have a large
    binary file whose length runs more than the capacity of integer
    3) Alternatively there is a setBlob(int i, Blob x) in prepared statement.
    But how to instantiate a Blob object and set it here
    4) Is there any better way to do this.use ps.setBlob(1, instream) instead

  • Uploading Binary File

    Hi,
    I have all the server side stuff working and it receives ordinary file uploads from a form just fine.
    However, I now need to use a Java Applet instead of this HTML form and it all goes just fine except the binary file that appears on the server is missing it's 2K header.
    This is a very serious problem for me, as I have got to complete this ASAP.
    I have been trying to make this work now for 3 days and I cannot find a solution anywhere on the Internet.
    any thoughts?
    cheers
    Bruce

    My code currently is as follows, sorry all the indenting seems to have vanished after pasting the code in:-
    import com.ms.security.*;
    import java.lang.*;
    import java.net.*;
    import java.io.*;
    import java.util.*;
    import java.applet.*;
    public class urlFetch extends Applet {
    public void UploadFile(String serverURL,
    String serverFilePath,
    String clientFilePath,
    String filename,
    // Form values
    String func,
    String objType,
    String objAction,
    String parentId,
    String CTT_ID,
    String nextURL,
    String comment,
    String InheritRequired,
    String CREATE_Required,
    String CREATE_Edited,
    String CREATE_CacheID,
    String CREATE_CatNames,
    String name) {
    try {
              System.out.println("***Get Permission");
              PolicyEngine.assertPermission(PermissionID.FILEIO);
              System.out.println("***Create URL : " + serverURL);
              URL url = new URL(serverURL);
              System.out.println("***Create Connection");
              URLConnection conn = url.openConnection();
              String str = "";
              System.out.println("***Create data");
              str += "--" + BOUNDARY + NEWLINE;
              // Add all the values of the form data fields.
              str += _formData("func",            func);
              str += _formData("objType",         objType);
              str += _formData("objAction",       objAction);
              str += _formData("parentId",        parentId);
              str += formData("CTTID", CTT_ID);
              str += _formData("nextURL", nextURL);
              str += _formData("comment", comment);
              str += _formData("InheritRequired", InheritRequired);
              str += _formData("CREATE_Required", CREATE_Required);
              str += _formData("CREATE_Edited", CREATE_Edited);
              str += _formData("CREATE_CacheID", CREATE_CacheID);
              str += _formData("CREATE_CatNames", CREATE_CatNames);
              str += _formData("name", name);
              byte[] formData = str.getBytes();
              str = "";
    // add the file
              str += "Content-disposition: form-data; name=\"versionFile\"; filename=\"" + filename + "\"";
              str += "Content-type: application/msword" + NEWLINE;
              str += "Content-Transfer-Encoding: binary" + NEWLINE;
              byte[] fileHeader = str.getBytes();
              byte[] fileContents = _readFile(clientFilePath);
              str = "";
              str += NEWLINE; //This is the file content
              str += "--" + BOUNDARY + "--" + NEWLINE;
              byte[] fileFooter = str.getBytes();
              System.out.println("***Setup Request***");
              conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
              int lengthOfData = formData.length + fileHeader.length + fileContents.length + fileFooter.length;
              System.out.println("***Data Length : " + lengthOfData);
              System.out.println("***File Length : " + fileContents.length);
              conn.setRequestProperty("Content-Length", String.valueOf(lengthOfData) );
              conn.setDoOutput(true);
              conn.setUseCaches(false);
              System.out.println("***Get Output Stream");
              DataOutputStream os = new DataOutputStream(conn.getOutputStream());
              System.out.println("***Connect");
              conn.connect();
              System.out.println("***Send data");
              os.write( formData, 0, formData.length );
              os.write( fileHeader, 0, fileHeader.length );
              os.write( fileContents, 0, fileContents.length );
              os.write( fileFooter, 0, fileFooter.length );
              System.out.println("***Flush");
              os.flush();
              System.out.println("***Close");
              os.close();
    catch ( Exception e ) {
    System.out.println("***** Exception: " + e.toString());
    * Split a String on delimiters to return an array of the delimited Strings.
    * @param s The String to split up
    * @param d The delimiter on which to split s
    * @return Array of delimited Strings from s.
    private String[] _split(String s, String d) {
    StringTokenizer st = new StringTokenizer(s,d);
    String[] parts = new String[st.countTokens()];
    int i = 0; // Loop counter
    while (st.hasMoreTokens())
    parts[i++] = st.nextToken();
    return parts;
    * Create a String which is the HTTP representation of the field name/value pair
    * @param fieldName The HTML field name
    * @param fieldVal The (String) field value
    * @return A String to be used in the HTTP sent to the server.
    private String _formData(String fieldName, String fieldVal) {
    // return fieldName + " = " + fieldVal + NEWLINE;
    return "Content-Disposition: form-data; name=\"" + fieldName + "\"" + NEWLINE + NEWLINE
    + fieldVal + NEWLINE
    + "--" + BOUNDARY + NEWLINE;
    * Read the contents of filePath as a String and return.
    * @param filePath The full path to the file to be read
    * @return A string containing the contents of the file
    private byte[] _readFile(String filePath) {
         byte[] bytes;
         try {
              File fileIn = new File(filePath);
              FileInputStream fis = new FileInputStream(fileIn);
              bytes = new byte[ (int)fileIn.length() ];
              fis.read(bytes);
    /* my old one
              FileReader fr = new FileReader(filePath);
              int charsRead = 0;
              //my new bits
              File fileIn = new File(filePath);
              FileInputStream fis = new FileInputStream(fileIn);
              int size = ((int) fileIn.length());
              bytes = new byte[size];
              byte[] aByte = new byte[1];
              int n = 0;
              for (int i = 0; size > i; i++ ) {
                   charsRead = fis.read(aByte);
                   bytes[n] = aByte[0];
         ++n;
    /*          mick's original ***
              StringBuffer sBuffer = new StringBuffer();
              while (charsRead != -1) {
              charsRead = fr.read(BUFFER, 0, BUFFER_LEN);
              if( charsRead != -1 ) {
                   sBuffer.append(BUFFER, 0, charsRead);
    catch ( Exception e ) {
              bytes = new byte[1];
    System.out.println("***** Exception xxx: " + e.toString());
    // return sBuffer.toString();
         return bytes;
    * Private statics
    private static final String BOUNDARY = "BbC04y";
    private static final int BUFFER_LEN = 4096;
    private static byte[] BUFFER = new byte[BUFFER_LEN];
    private static final String NEWLINE     = "\r\n";

  • Binary file transfert over socket : data corupted !

    Hi everyone,
    I am trying to transfert binary files over Socket (java.net) and I get corrupted data... I know the data I write in the Socket is ok and I wonder why I don't get it right at the end.
    Does anyone know about it ?

    Ok i have re-written it without the Packet class and it know works...
    I give my code in case someone would be interested.
    ENCODER :
    public class Encoder {
         // the file to send
         private File file;
          * Constructor of the Encoder class
          * @param path the path to the file to send
         public Encoder(String path){
              this.file = new File(path);
              this.encodeFile();
          * This method contains the connection an file tranfert code
         private void encodeFile(){
              try {
                   // opening file reading stream
                   FileInputStream fis = new FileInputStream(this.file);
                   // connection...
                   Socket sock = new Socket("127.0.0.1", 5698);
                   // opening an output stream
                   BufferedOutputStream bos = new BufferedOutputStream(sock.getOutputStream(), 1024);
                   // start time
                   long start = System.currentTimeMillis();
                   // setting up the buffer
                   byte[] buffer = new byte[1024];
                   /* ---- File Transfert Loop ---- */
                   // reading for the first time
                   int read = fis.read(buffer);
                   while (read > 0){
                        bos.write(buffer);
                        bos.flush();
                        read = fis.read(buffer);
                   /* ----End Of File Transfert ---- */
                   // end time
                   long end = System.currentTimeMillis();
                   // closing streams and connection
                   fis.close();
                   bos.close();
                   sock.close();
                   // display file transfert duration
                   System.out.println("Completed in :" + (end - start) + " ms !");
              } catch (IOException e) {
                   e.printStackTrace();
    DECODER :
    public class Decoder {
         private File destFile;
         public Decoder(String path){
              try {
                   // setting up destination file
                   this.destFile = new File(path);
                   // setting up file writting stream
                   FileOutputStream fos = new FileOutputStream(this.destFile);
                   // setting up connection server
                   ServerSocket serv = new ServerSocket(5698);
                   // accepting client connection request
                   Socket sock = serv.accept();
                   // setting up reading stream for the connection
                   BufferedInputStream bis = new BufferedInputStream(sock.getInputStream());
                   // setting up byte buffer
                   byte[] buffer = new byte[1024];
                   // first reading
                   int read = bis.read(buffer);
                   while (read != -1){
                        // writting buffer content into file
                        for (int i=0; i < read; i++){
                             fos.write(buffer);
                        // reading next bytes
                        read = bis.read(buffer);
                   //closing streams
                   fos.close();
                   bis.close();
              } catch (IOException e) {
                   e.printStackTrace();

  • Siebel 8.0.0.12 Fix Pack; Unable to get the seed from binary file.

    Hello Folks,
    Can anyone throw some light into what action is required on my scenario.
    I have applied Fix Pack Siebel 8.0.0.12 on top of 8.0.0.11 SBA. After it is appled, I am facing a documented issue within the Release Notes for the 8.0.0.12 Fix Pack
    The issue is "UNABLE TO LAUNCH URL AFTER APPLYING SIEBEL 8.0.0.12". I tried the steps given with the MR document, however, I am still having this issue.
    I am also not sure what is expected at the step of; Run the following command: seedgeneratorutil myseed.dat abcdef .
    It's asking me for a value to enter for seed at command prompt. "Enter the seed":
    what I should give here. As an assumption values,I gave SADMIN and tried to launch but still shows up the same error
    Please Assit
    Steps Details from Release Notes:
    UNABLE TO LAUNCH URL AFTER APPLYING SIEBEL 8.0.0.12
    Component: Server Infrastructure
    Subcomponent: SWSE
    Product Version: Siebel 8.0.0.12
    Base Bug ID: 11938270
    **Users are unable to launch the URL after applying the Siebel 8.0.0.12 Fix Pack.
    **Use the following workaround to address this issue:
    Navigate to the eappweb/bin directory from the command line on the SWSE installation.
    Run the following command:
    seedgeneratorutil myseed.dat abcdef
    NOTE: In the example, myseed.dat is a filename. You can give any file name you wish.
    The myseed.dat file is generated in the eappweb/bin directory.
    Edit eapps.cfg to include the following parameters under the SWE section:
    seedfile = < complete path for myseed.dat >
    Bounce the web server.
    (For Linux only) Copy libmod_swe.so from the eappweb/bin folder to the web/ohs/modules folder
    Thanks
    Kumar

    Wilson,
    Thanks for your reply.I have repeated the steps and regenerated the error messages.
    Browser
    Message:
    An error occurred while trying to process your request. This error indicates a problem with the configuration of this server and should be reported to the webmaster (along with any errors listed below). We apologize for the inconvenience
    Initialization error:
    Unable to get the seed from binary file.
    Log
    2021 2011-09-20 23:23:01 0000-00-00 00:00:00 +0530 00000000 001 003f 0001 09 ss110920_7068 7068 7852 E:\sba80\SWEApp\log\ss110920_7068.log 8.0.0.12 [20444] ENU
    ProcessPluginState     ProcessPluginStateError     1     000000024e781b9c:0     2011-09-20 23:23:01     7852: [SWSE] Unable to get the seed from binary file.
    Eapps.cfg
    [swe]
    Language = enu
    Log = errors
    LogDirectory = $(SWSERoot)\log
    ClientRootDir = $(SWSERoot)
    SessionMonitor = False
    AllowStats = true
    LogSegmentSize = 0
    LogMaxSegments = 0
    DisableNagle = False
    seedfile = E:\sba80\SWEApp\BIN\80012seed.dat
    Thanks
    Kumar

  • Bug in LV8 : 'Save for previous version' and 'Write to Binary File' VI

    Hello
    I am using LabVIEW 8's revamped 'Write to Binary File' VI with a 'TRUE' boolean constant wired to the optional 'prepend array or string size?' to write non-trivial structures to a binary file. I then read the file with the 'Read from Binary File' VI and everything is fine. I don't wire anything to the 'file (use dialog)' input (don't know if this can help).
    However, after saving my VI for LabVIEW 7.1, I cannot read the binary files created with the LV7 version of the VI anymore. After examining the LV7 converted version of the VI, there is a 'FALSE' boolean constant that is wired to the equivalent of the 'prepend array or string size' input, which breaks the binary format that is expected.
    The attached files are LV8 and 'saved for LV7' versions of a dummy VI that writes an array of 5 integers into a binary file. To test the bug, start LV8, open the LV8 version, run it and create a 'test-lv8.bin' file, then open the LV7 version, run it and create a 'test-lv7.bin' file. Check the content of the two files : the size of the array is indeed missing from the 'test-lv7.bin' file, which can be assimilated as a bug in my opinion.
    I think I found another one too : if in LV8 I wire the 'cancelled' boolean output of the 'Open/Create/Replace file' to the selector of a case structure, the 'converted to LV7' version VI will have an error, saying the Case Structure selector is not wired.
    Could someone please confirm these are indeed bugs ?
    Thanks in advance and have a nice day.
    Eric Batut
    Attachments:
    Test Binary File v7-v8 LV7.vi ‏15 KB
    Test Binary File v7-v8 LV8.vi ‏7 KB

    I'm using LV8.6 and need to read a .bin file created in MATLAB. This file obviously does not contain the 4 byte header that LabVIEW prepends .bin files with. So when I use Read from Binary File, I get no data (I'm trying to read an array of doubles). I've tried making my .bin file both in native and big-endian format and changing the representation (double, int64, float64) but none of this works. I noted that if I create the same array in a .bin file in LabVIEW and wire a FALSE to the "prepend array or string size?", my VI for reading .bin files can't read this file either.
    Any work-arounds here?
    (I'll try attaching my write & read VI's)
    Attachments:
    ReadWriteBinFile.zip ‏19 KB

  • Firefox crashed when I try to download a binary file

    In this instance it is IE8 which I am trying to download (for business purposes I need Activex controls). When I currently open IE it runs as a process rather than an application. I have tried to download IE8 and google's Chrome but Firefox crashes as soon as I try to save the Binary files.

    Sorry you are having problems. Can you give an example preferably of some small publicly available file and the site you are trying to download it from ?
    As a simple example of a download (ok it is a .png image file not not a .exe file) but can you try to download a copy of your avtar/icon, as used on these forums. In Windows one method is that you right click & should get an option save. <br/> Mine alongside uses the link
    * https://support.mozilla.com/media/uploads/avatars/avatar-257447.png
    Are you able to download such an image, then see it in your download manager, and find it on your computer.
    Once you have got Firefox to save your binary file you can use it. In the case of the .exe file you are trying to download that should be usable as intended with your Windows Operating System, the avatar also should be easily opened and viewed.
    P.S.
    You could try installing the add-on https://addons.mozilla.org/en-US/firefox/addon/opendownload-10902/ if you wished to adapt Firefox to run .exe files instead of just save them.

Maybe you are looking for

  • Auto-save in Logic 8

    Hey Guys I've been trying to find an option for auto-save in Logic (and to set how often it does this)... but I can't find anything... Does it just do auto-save in the background? Or is there no auto-save feature? It's easy to forget to keep saving i

  • Locked out of my ipad help

    locked out of my ipad please help

  • How do I move a movie off my iPod touch?

    I need help on how to move a movie off my iPod and onto my iTunes account.  I have the new iTunes where there is no left side bar, and I don't know how to use it.  My computer (Dell) runs iTunes extremely slow as well.  Currently the movie i want to

  • Keeps asking for password at step 8

    Hi, I just bought a Linksys WRT54G wireless router and am having some trouble getting it setup. I have gone through the setup disc until step 8 where  it just keeps asking me for a password.  I have tried using the default password, but it still just

  • Freeing up my hard drive on a MacBook

    How do I move my entire library to an external hard drive, keeping all the adjustments, so that I can access them easily and safely whilst freeing up space on my MacBook