当对我的服务器调用 get 请求时,我试图发送一个 XML 文件作为响应。
@Get
public Representation getRootDeviceXML() throws IOException {
File xmlFile = new File("rootdevices.xml");
if (!xmlFile.exists())
throw new ResourceException(Status.SERVER_ERROR_INTERNAL);
SaxRepresentation result;
try {
InputStream inputStream = new FileInputStream(xmlFile);
InputSource inputSource = new InputSource(new InputStreamReader(
inputStream));
result = new SaxRepresentation(MediaType.TEXT_XML, inputSource);
} catch (IOException e) {
throw new IOException(e.toString());
}
Writer writer = new OutputStreamWriter(System.out);
result.write(writer);
return result;
}
但实际上没有任何内容显示为客户端的响应(不是 404,标头正确发送为 Content-Type:text/xml; charset=UTF-8)。我究竟做错了什么?