我有一个返回PDF文档的Restlet Web服务,客户端需要接收此文档并显示它。
服务器端代码:
orderNumber = f.getFirstValue(PARAM_ORDER_NUMBER);
orderType = f.getFirstValue(PARAM_ORDER_TYPE).toUpperCase();
String fileName = OrderDM.getPDF(orderNumber, orderType);
pdfRep = new FileRepresentation(new File(fileName), MediaType.APPLICATION_PDF, 0);
return pdfRep;
客户端:
ClientResource client = getClientResource(PRINTER_FRIENDLY_DOCUMENT_RESOURCE);
Reference reference = client.getReference();
reference.addQueryParameter(PARAM_ORDER_TYPE, orderType);
reference.addQueryParameter(PARAM_ORDER_NUMBER, orderNumber);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
client.get().write(outputStream);
byte[] fileContent = outputStream.toByteArray();
这是否有效,这是最好的方法。