【发布时间】:2013-06-15 12:33:01
【问题描述】:
当对我的服务器调用 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)。我做错了什么?
【问题讨论】:
标签: java android xml rest restlet