0

我正在尝试编写一个 POST 测试,我必须将 XML 文件发送到服务器(使用 PLAY!框架)。但是,我必须做错事。运行时的结果是控制器中没有“数据”。

这是我的代码:路线:

POST    /server/?                               Server.index(format:'xml')

控制器:

   public static void index(Upload data) {
        if (data != null){
                DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                DocumentBuilder builder = dbf.newDocumentBuilder();

                Document xmlDoc = builder.parse(data.asStream());
         }
       etc..
   }

测试:

    File f = new File("request.xml");
    TransformerFactory tFactory =
            TransformerFactory.newInstance();
    Transformer transformer = tFactory.newTransformer();

    DOMSource source = new DOMSource(doc);
    StreamResult result = new StreamResult(f);
    transformer.transform(source, result);

    Map<String,String> map = new HashMap<String,String>();
    //map.put("data", xmlString);

    Map<String,File> files = new HashMap<String,File>();

    files.put("request.xml", f);
    Http.Response response = POST("/server/", map, files);
    assertIsOk(response);

    f.delete();

    StringReader reader = new StringReader(response.out.toString());
    InputSource inputSource = new InputSource( reader );
    Document xmlDoc = builder.parse( inputSource );
    reader.close();
4

0 回答 0