RE: I want to upload a file to the server from a java client but receive a (415) error code

2010-11-25 Thread Thierry Boileau
Hello,

I send you a sample jee project that works for me. It uses the core module and 
servlet extension of Restlet 2.0.3. I hope this helps.

Here is the server code:
@Post
public FileRepresentation receive(Representation file) throws Exception {
  File fichier = new File(d:\\test.txt);
  file.write(new FileOutputStream(fichier));
  return new FileRepresentation(fichier, file.getMediaType());
}

Best regards,
Thierry Boileau

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2685605


RE: I want to upload a file to the server from a java client but receive a (415) error code

2010-11-22 Thread ShiYu Gao
Hello,

I have use the Representation as the argument. But the program is always 
running in the client side, it never stop.

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2684323


RE: I want to upload a file to the server from a java client but receive a (415) error code

2010-11-22 Thread ShiYu Gao
Hello,

I change some code in the server side and debugged it.

code:
/***

 public FileRepresentation receive(Representation  file){   

 try {



InputStream is = file.getStream();
FileOutputStream fo = new FileOutputStream(new 
  File(/usr/temp/file2.txt));

byte[] b = new byte[1024];
while(is.read(b)=0){
fo.write(b);
 b = new byte[1024];
 fo.flush();
}

is.close();
fo.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
 }

**/

it paused at the is.read(b)=0 place.

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2684328


RE: I want to upload a file to the server from a java client but receive a (415) error code

2010-11-17 Thread Thierry Boileau
Hello,

in your case, you don't need to use a FileRepresentation on server side.
You can just replace the type of the parameter:
@Post
public FileRepresentation receive(Representation file){
[...]
}

Having said that, you still have access to the Representation#disposition 
attribute on server side.

Best regards,
Thierry Boileau

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2682443