Jump to content
We've recently updated our Privacy Statement, available here ×

dlcathukorala

Members
  • Posts

    7
  • Joined

  • Last visited

 Content Type 

Profiles

Forum

Events

Featured Visualizations

Knowledge Base

Documentation (PDF Downloads)

Blog

Documentation (Test Area)

Documentation

Dr. Jaspersoft Webinar Series

Downloads

Posts posted by dlcathukorala

  1. Hi,

    I want to get report output as pdf using the REST API. I have written some code to get it using Spring RestTemplate class. But Im getting an error in invoking the service.

    Here is the code that i have written

    public ResponseEntity runReport(HttpServletRequest request , String reportUri , String parameters , String outFormat) throws IOException{

     
       String serverIp = (String) request.getSession().getAttribute("serverIp");
       String company = (String) request.getSession().getAttribute("company");
       HttpHeaders headers = (HttpHeaders) request.getSession().getAttribute("headers");
     
       headers.setContentType(MediaType.parseMediaType("application/pdf"));
       String filename = "BSJA6.pdf";
       headers.setContentDispositionFormData(filename, filename);
       headers.setCacheControl("no-cache");
       HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);
     
       final String uri = "{serverIp}/jasperserver-pro/rest_v2/reports/{reportUri}.{outFormat}?{parameters}";
     
       Map<String, Object> params = new HashMap<String, Object>();
       params.put("serverIp", serverIp);
       params.put("reportUri", reportUri);
       params.put("outFormat", outFormat);
       params.put("parameters", parameters);
     
       RestTemplate restTemplate = new RestTemplate();
     
       ResponseEntity<ResponseEntity> response = restTemplate.exchange(uri, HttpMethod.GET, entity, ResponseEntity.class , params);
     
       return response;  
    }

    but I'm getting the following error.

    WARN  [org.springframework.web.client.RestTemplate] (http-localhost/127.0.0.1:8080-1) GET request for "http://lolcdc1ms:8080/jasperserver-pro/rest_v2/reports/reports/BSJA6.pdf?p_prod%3D%26P_COMP_NAME%3D%26p_branch%3D%26p_date2%3D%26p_date%3D2016-07-19%26P_SCM%3Ddasd%26p_user%3D%26p_rpt_path%3D" resulted in 400 (Bad Request); invoking error handler
    ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/jasper-restclient].[jasper-restclient]] (http-localhost/127.0.0.1:8080-1) JBWEB000236: Servlet.service() for servlet jasper-restclient threw exception: org.springframework.web.client.HttpClientErrorException: 400 Bad Request
    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:76) [spring-web-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:486) [spring-web-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:443) [spring-web-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:409) [spring-web-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:384) [spring-web-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at com.loits.jasper.rest.repo.ModuleDaoImpl.runReport(ModuleDaoImpl.java:334) [classes:]
    at com.loits.jasper.rest.mvc.ModuleController.runReport(ModuleController.java:103) [classes:]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_17]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_17]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_17]
    at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_17]
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213) [spring-web-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126) [spring-web-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final-redhat-1.jar:1.0.2.Final-redhat-1]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at com.loits.jasper.rest.mvc.SessionFilter.doFilter(SessionFilter.java:46) [classes:]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
    at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) [jboss-as-web-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:920) [jbossweb-7.2.2.Final-redhat-1.jar:7.2.2.Final-redhat-1]
    at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_17]
     
    any idea regarding this ?
  2. Hi,

    I have created a bean data source to connect to my database. My objective of creating this datasource is to switch datasource as per a parameter given. But when I run reports using the bean data source, it does not release the connection back into the pool. My connection pool size is 20, so when I run the 21st report, server hangs printing the following message on the JConsole

    Name: pool-7-thread-9
    State: WAITING on org.apache.commons.pool.impl.GenericObjectPool@1f8ed84
    Total blocked: 0  Total waited: 4
     
    Stack trace: 
    java.lang.Object.wait(Native Method)
    java.lang.Object.wait(Object.java:485)
    org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:748)
    org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:95)
    com.loits.jasper.ds.SwitchDS.setReportParameterValues(SwitchDS.java:75)
    com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl.fillReport(EngineServiceImpl.java:1725)
    com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl$ReportFill.runWithDataSource(EngineServiceImpl.java:1086)
    com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl$ReportFill.runReport(EngineServiceImpl.java:1015)
    com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl$ReportRunnable.run(EngineServiceImpl.java:908)
    java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    java.lang.Thread.run(Unknown Source)
     
    Here what I have done in my bean 
    package com.loits.jasper.ds;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;import java.sql.SQLException;import net.sf.jasperreports.engine.JRParameter;import org.springframework.security.context.SecurityContextHolder;import com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.ReportDataSource;import com.jaspersoft.jasperserver.api.metadata.jasperreports.service.ReportDataSourceService;import com.jaspersoft.jasperserver.api.metadata.user.domain.Role;import com.jaspersoft.jasperserver.api.metadata.user.domain.client.ProfileAttributeImpl;import com.jaspersoft.jasperserver.api.metadata.user.domain.impl.client.MetadataUserDetails;import com.jaspersoft.jasperserver.api.common.domain.ExecutionContext;import com.jaspersoft.jasperserver.api.common.service.BeanForInterfaceImplementationFactory;import com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.JdbcDataSourceService;import com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.JdbcReportDataSourceServiceFactory;import com.jaspersoft.jasperserver.war.common.JasperServerUtil;import com.jaspersoft.jasperserver.api.metadata.common.service.RepositoryService;public class SwitchDS implements ReportDataSourceService {private JdbcDataSourceService connection; private RepositoryService repositoryService; private BeanForInterfaceImplementationFactory dataSourceServiceFactory;// private DataSourceServiceFactory dataSourceServiceFactory;public SwitchDS(RepositoryService repositoryService,   BeanForInterfaceImplementationFactory dsServiceFactory) {      super();      this.repositoryService = repositoryService;      this.dataSourceServiceFactory = dsServiceFactory;    System.out.println("repositoryService " + repositoryService);  System.out.println("dataSourceServiceFactory "    + dataSourceServiceFactory); }@SuppressWarnings({ "unchecked", "rawtypes" }) public void setReportParameterValues(Map parametersValue) {  String ds_name = (String) parametersValue.get("P_SCM");    String ds_uri = "";      if(ds_name.equalsIgnoreCase("D_001_S")){       ds_uri = "/datasources/lolc_fusion";    }    else if(ds_name.equalsIgnoreCase("D_005_S")){       ds_uri = "/datasources/lofc_fusion";    }    else if(ds_name.equalsIgnoreCase("D_009_S")){       ds_uri = "/datasources/lomc_fusion";       }    else if(ds_name.equalsIgnoreCase("D_010_S")){       ds_uri = "/datasources/clc_fusion";    }    else if(ds_name.equalsIgnoreCase("D_025_S")){       ds_uri = "/datasources/lofac_fusion";    }   if(connection == null){       connection = getRepositoryDatasource(ds_uri);    }  try {       parametersValue.put(JRParameter.REPORT_CONNECTION, connection     .getDataSource().getConnection());    } catch (SQLException e) {       e.printStackTrace();    }}public JdbcDataSourceService getRepositoryDatasource(String repositoryURI) {  try {       ExecutionContext context = JasperServerUtil.getExecutionContext();       ReportDataSource datasource = (ReportDataSource) repositoryService.getResource(context, repositoryURI);    System.out.println("datasource " + datasource.getName());       System.out.println("datasource class " + datasource.getClass());   JdbcReportDataSourceServiceFactory factory = (JdbcReportDataSourceServiceFactory) dataSourceServiceFactory.getBean(datasource.getClass());      JdbcDataSourceService DSservice = (JdbcDataSourceService) factory     .createService(datasource);    return DSservice;     }     catch (Exception ex) {       System.out.println(ex);   return null;     } }@Override public void closeConnection() {      if (connection != null) {           connection.closeConnection();           System.out.println("Connection closed .. ");     } }public static void main(String[] args) {}}[/code]
     
  3. Hi,

    I use Jaspersoft 5.6.1 Community Edition for reporting on jboss eap 6 . I recently encountered a problem that my report server hangs when running many reports at a time. Server shows me as Loading but it never get finished. I have to manually restart the server and continue.. It seems there is a problem with the database connection pool which it does not get released after invoking a report. 

    Here are my connection pool configuration

    In jasperserver.warWEB-INFapplicationContext.xml

     

    <bean id="dataSourceObjectPoolFactory" class="org.apache.commons.pool.impl.GenericObjectPoolFactory">  <constructor-arg type="org.apache.commons.pool.PoolableObjectFactory">    <null/>  </constructor-arg>  <constructor-arg type="int" value="20" /></bean>[/code]

    In jasperserver.warMETA-INFcontext.xml

    <Resource name="jdbc/jasperserver"          auth="Container"          type="javax.sql.DataSource"          maxActive="100" maxIdle="30" maxWait="10000"          username="root"          password="root"          driverClassName="org.mariadb.jdbc.Driver"          accessToUnderlyingConnectionAllowed="true"          testOnBorrow="true"          url="jdbc:mysql://127.0.0.1:3306/jasperserver"          factory="${tomcatBasicDatasourceFactory}" />[/code]

    and also I noticed that my jvm heap usage goes to 100 % when the report server hangs. Is there any solution regarding this?

×
×
  • Create New...