users@glassfish.java.net

File Write on Server Problem in Web Service

From: <glassfish_at_javadesktop.org>
Date: Mon, 07 Jan 2008 09:22:44 PST

I have write a Web Service deployed in Glassfish, in the operation there is a logic like this. It seems work fine, and the result is good too. Unfortunately, the File is created and the keeps in blank. How can that happened? It is wrong to write to a file on server by WS?

Operation:

        public int WriteToServer (String str){
                File f = new File("TWriteToFile.log");
                try {
                        OutputStreamWriter os = new OutputStreamWriter(new FileOutputStream(f));
                        os.write(str);
                        return str.length();
                } catch (FileNotFoundException e) {
                        
                        return -1;
                } catch (IOException e) {
                        return -1;
                }
                
                
        }

Message:
- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://file" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <soapenv:Body>
- <q0:WriteToServer>
  <q0:str>ttt</q0:str>
  </q0:WriteToServer>
  </soapenv:Body>
  </soapenv:Envelope>

- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
- <soapenv:Body>
- <WriteToServerResponse xmlns:ns="http://file">
  <ns:return>3</ns:return>
  </WriteToServerResponse>
  </soapenv:Body>
  </soapenv:Envelope>
[Message sent by forum member 'lorna_hu' (lorna_hu)]

http://forums.java.net/jive/thread.jspa?messageID=252535