SOAPUI - REST请求multipart / mixed - 如何添加附件

时间:2013-02-07 19:28:44

标签: soapui multipart mixed

我正在尝试测试RESTful服务,该服务配置为使用soapui工具使用multipart / mixed。

@POST
@Path("requestXmlAndAttachment")
@Consumes({ "multipart/mixed" })
@Produces({ MediaType.APPLICATION_XML })
public ResponseTO processRequestXmlAndAttachment(final       com.sun.jersey.multipart.MultiPart     multiPartRequest) {
 // application logic

}

在SOAPUI中,我设置了REST资源并添加了2个参数,第一个文件指向请求xml,第二个文件包含数据(我从下拉列表选择了PLAIN样式)。

File1       file:request.xml
File2       file:datafile.xls

在SOAPUI请求编辑器窗口中,我选择了multipart / mixed for media type。当我向服务器提交请求时,我没有看到文件附加到请求。以下是可在服务器日志中查看的内容:

Feb 7, 2013 1:36:58 PM com.sun.jersey.api.container.filter.LoggingFilter filter
INFO: 56 * Server in-bound request
56> POST http://localhost:7001/myservice/requestXmlAndAttachment
56 > Accept-Encoding: gzip,deflate
56 > Content-Type: multipart/mixed
56 > Content-Length: 0
56 > Host: localhost:7001
56 > Connection: Keep-Alive
56 > User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
56 >

正如您所看到的,Content-Length为0 我已经能够从java junit程序测试这个服务。这是该计划的一部分:

BodyPart bp1 = new BodyPart();
bp1.setEntity(requestXMLString);
bp1.setMediaType(MediaType.APPLICATION_XML_TYPE);

BodyPart bp2 = new BodyPart();
bp2.setContentDisposition(ContentDisposition.type("file").fileName("datafaile.xls").build  ());
bp2.setEntity(binaryData1);
bp2.setMediaType(MediaType.APPLICATION_OCTET_STREAM_TYPE);


MultiPart multiPart = new MultiPart().bodyPart(bp1).bodyPart(bp2);

ClientConfig cc = new DefaultClientConfig();
cc.getClasses().add(MultiPartWriter.class);
Client client = Client.create(cc);
WebResource webResource = client.resource ("http://localhost:7001/myservice/requestXmlAndAttachment");
ClientResponse response = webResource.type(new MediaType("multipart", "mixed")).post(ClientResponse.class, multiPart);

我还尝试在SOAP UI请求编辑器框中将媒体类型更改为multipart / formdata(仅用于实验),然后我可以看到Content-Length = 30654,我看到在服务器日志中读取的文件内容。

我还尝试在请求中添加http标头(MIME-Version等),但它没有任何区别。

虽然我可以在没有SOAPUI的情况下进行单元测试,但我更倾向于让这个测试与SOAPUI一起使用,因为我已经在soapui中设置了一堆其他测试设置,在同一服务中执行不同的方法。

是否有使用SOAP UI测试multipart /与附件混合?
提前感谢您的回顾。

0 个答案:

没有答案
相关问题