multipart/form-data로 파일 업로드 하자.
서버
interface
@POST
@Path("/TEST02")
@Consumes("multipart/form-data")
void TEST02(MultipartBody body) throws BizException;
implement
public void TEST02(MultipartBody body) throws BizException {
File file = null;
try {
file = FileUtil.makeFile(body.getAttachment("testFile").getDataHandler().getInputStream(),
"D:/upload", body.getAttachmentObject("fileName", String.class) );
} catch (IOException e) {
e.printStackTrace();
}
}
inputStrem을 파일로 떨궈주면 땡..
클라이언트
public static void excute_post1(String url) throws ClientProtocolException, IOException {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setHeader("content", "multipart/form-data");
httppost.addHeader("Accept", "application/json; charset=UTF-8" );
FileBody filebody = new FileBody(new File("D:\\test.txt"));
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("testFile", filebody);
reqEntity.addPart("fileName", new StringBody("aaaa.txt"));
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
httppost.abort();
httpclient.getConnectionManager().shutdown();
}
'framework > apache cxf' 카테고리의 다른 글
[JAX-RS] - @Produces를 다중으로 설정 시 클라이언트 헤더 설정방법 (0) | 2011.09.27 |
---|---|
[apache cxf] - Spring에서 soap, rest, json endpoint 설정하자 (0) | 2011.01.27 |
[Apache cxf] - log4j 설정하자 (0) | 2010.06.28 |
[Apache cxf] - 톰켓에서 한글 설정하자 (0) | 2010.06.28 |
[Apache cxf] - session support (0) | 2010.06.28 |