JasperServer REST客户端路径如何?

编程入门 行业动态 更新时间:2024-10-07 09:25:16
本文介绍了JasperServer REST客户端路径如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在努力使用jasperserver进行客户端休息服务以生成报告。我正在使用以下代码来实现:

I'm working to make client rest service with jasperserver to generate reports. I'm using the following code to make that:

我在设置服务器URL和报告路径方面遇到问题,用于服务器URL我放了 http:// localhost:8081 / jasperserver / ,如下图所示,我把报告路径 rest / report / mytest / my_report 但是我发现404未找到错误

I have problem in setting server url and report path, for server url I put localhost:8081/jasperserver/ and as shown in next image I put report path rest/report/mytest/my_report but I get 404 not found error in line

File remoteFile = resource.get(File.class);

那么我怎样才能从jasperserver获得正确的报告路径?

So how can I get the proper report path from jasperserver?

public class App2 { private final static String serverUrl = "localhost:8081 /jasperserver/"; private final static String serverUser = "jasperadmin"; private final static String serverPassword = "jasperadmin"; public static void main(String arg[]) throws Exception { Report reporte = new Report(); reporte.setFormat("pdf"); reporte.setOutputFolder("/home/ali/images"); ClientConfig clientConfig; Map<String, String> resourceCache=new HashMap<String, String>(); clientConfig = new DefaultApacheHttpClientConfig(); clientConfig.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true); clientConfig.getProperties().put(ApacheHttpClientConfig.PROPERTY_HANDLE_COOKIES, true); ApacheHttpClient client = ApacheHttpClient.create(clientConfig); client.addFilter(new HTTPBasicAuthFilter(serverUser, serverPassword)); String describeResourcePath = "/rest/resource" + "/mytest/my_report/"; String generateReportPath = "/rest/report" + "/mytest/my_report/" + "?RUN_OUTPUT_FORMAT=" + reporte.getFormat(); WebResource resource = null; String resourceResponse = null; if (resourceCache.containsKey(describeResourcePath)) { resourceResponse = resourceCache.get(describeResourcePath); } else { resource = client.resource(serverUrl); resource.accept(MediaType.APPLICATION_XML); resourceResponse = resource.path(describeResourcePath).get(String.class); resourceCache.put(describeResourcePath, resourceResponse); } Document resourceXML = parseResource(resourceResponse); resourceXML = addParametersToResource(resourceXML, reporte); resource = client.resource(serverUrl + generateReportPath); resource.accept(MediaType.TEXT_XML); System.out.println(resource); String reportResponse = resource.put(String.class, serializetoXML(resourceXML)); String urlReport = parseReport(reportResponse); resource = client.resource(urlReport); System.out.println(resource); File destFile = null; try { File remoteFile = resource.get(File.class); File parentDir = new File(reporte.getOutputFolder()); destFile = File.createTempFile("report_", "." + getExtension(reporte.getFormat()), parentDir); FileUtils.copyFile(remoteFile, destFile); } catch (IOException e) { throw e; } } /** * * @return * @throws DocumentException */ private static Document parseResource(String resourceAsText) throws Exception { // LOGGER.debug("parseResource:\n" + resourceAsText); Document document; try { document = DocumentHelper.parseText(resourceAsText); } catch (DocumentException e) { throw e; } return document; } /** * */ private static String parseReport(String reportResponse) throws Exception { String urlReport = null; try { Document document = DocumentHelper.parseText(reportResponse); Node node = document.selectSingleNode("/report/uuid"); String uuid = node.getText(); node = document.selectSingleNode("/report/totalPages"); Integer totalPages = Integer.parseInt(node.getText()); if (totalPages == 0) { throw new Exception("Error generando reporte"); } urlReport = serverUrl + "/report/" + uuid + "?file=report"; } catch (DocumentException e) { throw e; } return urlReport; } /** * * @param resource * @param reporte * @return */ private static Document addParametersToResource(Document resource, Report reporte) { // LOGGER.debug("addParametersToResource"); Element root = resource.getRootElement(); Map<String, String> params = reporte.getParams(); for (Map.Entry<String, String> entry : params.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (key != null && value != null) { root.addElement("parameter").addAttribute("name", key).addText(value); } } // LOGGER.debug("resource:" + resource.asXML()); return resource; } /** * * @param aEncodingScheme * @throws IOException * @throws Exception */ private static String serializetoXML(Document resource) throws Exception { OutputFormat outformat = OutputFormat.createCompactFormat(); ByteArrayOutputStream out = new ByteArrayOutputStream(); outformat.setEncoding("ISO-8859-1"); try { XMLWriter writer = new XMLWriter(out, outformat); writer.write(resource); writer.flush(); } catch (IOException e) { throw e; } return out.toString(); } /** * * @param format * @return */ private static String getExtension(String format) { String ext = null; if (format.equals(Report.FORMAT_PDF)) { ext = "pdf"; } else if (format.equals(Report.FORMAT_EXCEL)) { ext = "xls"; } return ext; } }

推荐答案

我修好了,我需要更改路径

I have fixed it,I need to change path

urlReport = serverUrl + "/report/" + uuid + "?file=report";

urlReport = serverUrl + "/rest/report/" + uuid + "?file=report";

parseReport方法中的

in parseReport method

private static String parseReport(String reportResponse) throws Exception { String urlReport = null; try { Document document = DocumentHelper.parseText(reportResponse); Node node = document.selectSingleNode("/report/uuid"); String uuid = node.getText(); node = document.selectSingleNode("/report/totalPages"); Integer totalPages = Integer.parseInt(node.getText()); if (totalPages == 0) { throw new Exception("Error generando reporte"); } urlReport = serverUrl + "/report/" + uuid + "?file=report"; } catch (DocumentException e) { throw e; } return urlReport;

}

更多推荐

JasperServer REST客户端路径如何?

本文发布于:2023-11-13 02:46:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583213.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   客户端   JasperServer   REST

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!