서버 측 cxf 구성을 확인하는 방법은 다음과 같습니다.
@POST
@Path("/upload")
@Produces(MediaType.TEXT_XML)
public String upload(
@Multipart(value = "File", type = MediaType.APPLICATION_OCTET_STREAM) final InputStream fileStream,
@Multipart(value = "DATA1", type = MediaType.TEXT_PLAIN) final String fileNumber,
@Multipart(value = "DATA2", type = MediaType.TEXT_PLAIN) final String outputType) {
BufferedImage image;
try {
image = ImageIO.read(fileStream);
LOG.info("Received Image with dimensions {}x{} ", image.getWidth(), image.getHeight());
} catch (IOException e) {
LOG.error(e.getMessage(), e);
}
LOG.info("Received Multipart data1 {} ", fileNumber);
LOG.info("Received Multipart data2 {} ", outputType);
return "Recieved all data";
}
테스트 된 클라이언트 파일
public static void main(String[] args) throws IOException {
WebClient client = WebClient.create("http://localhost:8080/services/kp/upload");
ClientConfiguration config = WebClient.getConfig(client);
config.getInInterceptors().add(new LoggingInInterceptor());
config.getOutInterceptors().add(new LoggingOutInterceptor());
client.type("multipart/form-data");
InputStream is = FileUtils.openInputStream(new File("vCenter_del.jpg"));
List<Attachment> attachments = new ArrayList<>();
ContentDisposition cd = new ContentDisposition("attachment;filename=image.jpg");
Attachment att = new Attachment("File", is, cd);
Attachment pageNumber = new Attachment("DATA1", MediaType.TEXT_PLAIN, "1");
Attachment OutputType = new Attachment("DATA2", MediaType.TEXT_PLAIN, "2");
attachments.add(att);
attachments.add(pageNumber);
attachments.add(OutputType);
MultipartBody body = new MultipartBody(attachments);
Response res = client.post(body);
String data = res.readEntity(String.class);
System.out.println(data);
}
참고 : 컨텐츠 ID에 일치하지 않는 경우 짧은에서 해당 파일, 데이터 1 또는 콘텐츠 형식은 서버 모두에서 데이터를받을하지 않을 수 있습니다 경우 당신은 400과 415와 같은 적절한 오류를 얻을 것이다.