尝试在JasperServer中上传报表单元时出现错误请求

时间:2016-06-01 11:22:02

标签: java api rest jasperserver bad-request

尝试使用Exception in thread "main" com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.BadRequestException: Bad Request at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.handling.DefaultErrorHandler.handleStatusCodeError(DefaultErrorHandler.java:111) at com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.handling.DefaultErrorHandler.handleError(DefaultErrorHandler.java:68) at com.jaspersoft.jasperserver.jaxrs.client.core.JerseyRequest.executeRequest(JerseyRequest.java:189) at com.jaspersoft.jasperserver.jaxrs.client.core.JerseyRequest.post(JerseyRequest.java:140) at com.jaspersoft.jasperserver.jaxrs.client.apiadapters.resources.SingleResourceAdapter.uploadMultipartResource(SingleResourceAdapter.java:204) at com.jaspersoft.jasperserver.jaxrs.client.apiadapters.resources.support.processor.CommonOperationProcessorImpl.create(CommonOperationProcessorImpl.java:46) at com.jaspersoft.jasperserver.jaxrs.client.apiadapters.resources.support.decorator.ReportUnitResourceOperationProcessorDecorator.createInFolder(ReportUnitResourceOperationProcessorDecorator.java:46) at com.jaspersoft.jasperserver.jaxrs.client.TestJasperDeploy.uploadingReportunit(TestJasperDeploy.java:170) 上传报告单元时,我遇到了错误的请求。

我一直在寻找JasperServer社区的解决方案,但我找不到答案。

          Properties props = new Properties() {  
             setProperty("url", "http://localhost:8080/jasperserver/");
             setProperty("contentMimeType", "JSON");
             setProperty("acceptMimeType", "JSON");
             setProperty("connectionTimeout", "");
             setProperty("readTimeout", "");
             setProperty("authenticationType", "SPRING");
             setProperty("restrictedHttpMethods", "false");
             setProperty("logHttpEntity", "true");
             setProperty("logHttp", "true");
             setProperty("handleErrors", "true");   
         }  
     };

     RestClientConfiguration configuration = RestClientConfiguration.loadConfiguration(props);
     client = new JasperserverRestClient(configuration);  
     session = client.authenticate("jasperadmin", "jasperadmin");

初始化JasperServer的代码是

//this report has no subreports
// and requires a datasource not included in this example
ClientReferenceableFile jrxml = new ClientReferenceableFile() {
     @ Override
    public String getUri() {
        //my local  jrxm report
        String fileString1 = "C:/reports/documentos/subreports/SR_D_01_nome_funcionario.jrxml";
        return fileString1;
    }
};

ClientReportUnit repunit = new ClientReportUnit();
repunit.setJrxml(jrxml);

//this is the report location on the server
repunit.setUri("/reports/documentos/subreports");
repunit.setLabel("label report unit");
repunit.setDescription("descricao report");
ClientFile clifile = new ClientFile();
clifile.setType(ClientFile.FileType.jrxml);
clifile.setUri("/reports/documentos/subreports");
ReportUnitResourceBuilder repUnut = session.resourcesService().resource(repunit).withJrxml(repunit.getUri(), clifile);
repUnut.createInFolder("/reports");

我上传报告单元的代码是:

initialCountry

1 个答案:

答案 0 :(得分:3)

在这种情况下,您没有正确使用API​​。这就是你应该拥有的:

ClientReportUnit reportUnit = new ClientReportUnit();
reportUnit.setLabel("label report unit");
reportUnit.setDescription("descricao report");

ClientFile clientFile = new ClientFile();
clientFile.setType(ClientFile.FileType.jrxml);
clientFile.setLabel("Main Report");

FileInputStream fis;
try {
    fis = new FileInputStream("/path/to/report_template.jrxml");

    ReportUnitResourceBuilder reportUnitResourceBuilder = session.resourcesService().resource(reportUnit).withJrxml(fis, clientFile);
    reportUnitResourceBuilder.createInFolder("/reports/documentos/subreports");
} catch (FileNotFoundException e) {
    // do something with the error
    throw new RuntimeException(e);
}