@MultipartForm を使用して byte[] および InputStream オブジェクトの送信をテストしようとしましたが、両方のタイプで null オブジェクトを取得しました。RestEasy 2.3.5.Final を使用しています
public class DocumentForm {
private byte[] bytes;
private InputStream stream;
public byte[] getBytes() {
return bytes;
}
@FormParam("bytes")
@PartType(MediaType.APPLICATION_OCTET_STREAM)
public void setBytes(byte[] bytes) {
this.bytes = bytes;
}
public InputStream getStream() {
return stream;
}
@FormParam("stream")
@PartType(MediaType.APPLICATION_OCTET_STREAM)
public void setStream(InputStream stream) {
this.stream = stream;
}
}
public interface DocumentService {
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response store(@MultipartForm DocumentForm documentForm);
}
@Path("/document")
public class DocumentServiceEndpoint implements DocumentService {
public Response store(DocumentForm documentForm) {
System.out.println(documentForm.getBytes());
System.out.println(documentForm.getStream());
return Response.status(200).entity("OK").build();
}
}
public class DocumentServiceTest {
public static void main(String[] args) {
DocumentForm documentForm = new DocumentForm();
byte[] data = "TEST".getBytes();
documentForm.setBytes(data);
documentForm.setStream(new ByteArrayInputStream(data));
DocumentService documentService = ProxyFactory.create(DocumentService.class, "http://localhost:8080/document-rs/document");
documentService.store(documentForm);
}
}
クライアント側にログインすると、次のようになります。
DEBUG BasicClientConnectionManager - Get connection for route {}->http://localhost:8080
DEBUG DefaultClientConnectionOperator - Connecting to localhost:8080
DEBUG RequestAddCookies - CookieSpec selected: best-match
DEBUG RequestAuthCache - Auth cache not set in the context
DEBUG RequestTargetAuthentication - Target auth state: UNCHALLENGED
DEBUG RequestProxyAuthentication - Proxy auth state: UNCHALLENGED
DEBUG DefaultHttpClient - Attempt 1 to execute request
DEBUG DefaultClientConnection - Sending request: POST /document-rs/document HTTP/1.1
DEBUG wire - >> "POST /document-rs/document HTTP/1.1[\r][\n]"
DEBUG wire - >> "Accept-Encoding: gzip, deflate[\r][\n]"
DEBUG wire - >> "Content-Type: multipart/form-data; boundary=37e8b375-affb-47ec-94b0-f69f0eff1d36[\r][\n]"
DEBUG wire - >> "Content-Length: 40[\r][\n]"
DEBUG wire - >> "Host: localhost:8080[\r][\n]"
DEBUG wire - >> "Connection: Keep-Alive[\r][\n]"
DEBUG wire - >> "User-Agent: Apache-HttpClient/4.2.3 (java 1.5)[\r][\n]"
DEBUG wire - >> "[\r][\n]"
DEBUG headers - >> POST /document-rs/document HTTP/1.1
DEBUG headers - >> Accept-Encoding: gzip, deflate
DEBUG headers - >> Content-Type: multipart/form-data; boundary=37e8b375-affb-47ec-94b0-f69f0eff1d36
DEBUG headers - >> Content-Length: 40
DEBUG headers - >> Host: localhost:8080
DEBUG headers - >> Connection: Keep-Alive
DEBUG headers - >> User-Agent: Apache-HttpClient/4.2.3 (java 1.5)
DEBUG wire - >> "--37e8b375-affb-47ec-94b0-f69f0eff1d36--"
DEBUG wire - << "HTTP/1.1 200 OK[\r][\n]"
DEBUG wire - << "Server: Apache-Coyote/1.1[\r][\n]"
DEBUG wire - << "X-Powered-By: Servlet 2.5; JBoss-5.0/JBossWeb-2.1[\r][\n]"
DEBUG wire - << "Content-Type: */*[\r][\n]"
DEBUG wire - << "Content-Length: 2[\r][\n]"
DEBUG wire - << "Date: Wed, 24 Apr 2013 16:32:40 GMT[\r][\n]"
DEBUG wire - << "[\r][\n]"
DEBUG DefaultClientConnection - Receiving response: HTTP/1.1 200 OK
DEBUG headers - << HTTP/1.1 200 OK
DEBUG headers - << Server: Apache-Coyote/1.1
DEBUG headers - << X-Powered-By: Servlet 2.5; JBoss-5.0/JBossWeb-2.1
DEBUG headers - << Content-Type: */*
DEBUG headers - << Content-Length: 2
DEBUG headers - << Date: Wed, 24 Apr 2013 16:32:40 GMT
DEBUG DefaultHttpClient - Connection can be kept alive indefinitely
そしてサーバー側では:
13:32:40,380 INFO [STDOUT] null
13:32:40,381 INFO [STDOUT] null