Announcement Announcement Module
Collapse
No announcement yet.
WebApp on Maven/Tomcat - JNDI configuration? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • WebApp on Maven/Tomcat - JNDI configuration?

    Sorry if it's not right forum to ask question like this.
    Hello there.
    Since monday I'm trying to build small sample web app where I could download prepared report in pentaho designer. Main problem is that I can't read datasource using jndi.

    1. I have created report with Pentaho Designer, I've defined connection using jndi, and everything works fine, Report is generated correctly. Jndi name I've used - jndiTestName.

    2. My web app is based on Spring Framework. I'm also using Maven and Tomcat.
    That's how directories in project look like:
    +Web Pages
    _+META-INF
    __-context.htm
    _+WEB-INF
    __-applicationContext.xml
    __-binder-servlet.xml
    __-web.xml

    3. I've configured JNDI, but it's highly possible that I've made it wrong:
    context.xml contains
    Code:
        <Resource name="jndiTestName"
    Code:
              auth="Container"
              type="javax.sql.DataSource"
              driverClassName="org.postgresql.Driver"
              url="jdbc:postgresql://localhost:5432/binder2"
              username="xyz"
              password="zyx"
              removeAbandoned="true"
              removeAbandonedTimeout="90"
              logAbandoned="true"
              maxActive="20"
              maxIdle="10"
              maxWait="-1"/>


    applicationContext.xml contains
    Code:
        <bean id="jndiTestName" class="org.springframework.jndi.JndiObjectFactoryBean">
    Code:
            <property name="jndiName" value="java:comp/env/jndiTestName"/>
            <property name="lookupOnStartup" value="true"/>
            <property name="proxyInterface" value="javax.sql.DataSource"/>
        </bean>


    web.xml contains
    Code:
        <resource-ref>
    Code:
            <description>jndiTestName</description>
            <res-ref-name>jndiTestName</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
        </resource-ref>


    4. My java class ReportTest:
    Code:
    package com.mycompany.pentahotest;
    Code:
    import java.io.File;
    import java.io.IOException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import javax.servlet.http.HttpServletResponse;
    import org.pentaho.reporting.engine.classic.core.ClassicEngineBoot;
    import org.pentaho.reporting.engine.classic.core.MasterReport;
    import org.pentaho.reporting.engine.classic.core.ReportProcessingException;
    import org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.PdfReportUtil;
    import org.pentaho.reporting.libraries.resourceloader.Resource;
    import org.pentaho.reporting.libraries.resourceloader.ResourceException;
    import org.pentaho.reporting.libraries.resourceloader.ResourceManager;
    import org.springframework.beans.propertyeditors.CustomDateEditor;
    import org.springframework.beans.propertyeditors.StringTrimmerEditor;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.WebDataBinder;
    import org.springframework.web.bind.annotation.InitBinder;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    
    
    @Controller
    public class ReportTest {
    
    
        @InitBinder
    
    
        public void initBinder(WebDataBinder binder) {
            binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            df.setLenient(false);
            binder.registerCustomEditor(Date.class, new CustomDateEditor(df, true));
        }
    
    
        @RequestMapping(value = "pentaho.htm", method = RequestMethod.GET)
        public void testRun(HttpServletResponse response) throws Exception {
    
    
            ClassicEngineBoot.getInstance().start();
    
    
            ResourceManager manager = new ResourceManager();
            manager.registerDefaults();
            String reportPath = "D:\\testRaport.prpt";
    
    
            try {
                Resource res = manager.createDirectly(new File(reportPath).toURI().toURL(), MasterReport.class);
                MasterReport report = (MasterReport) res.getResource();
                PdfReportUtil.createPDF(report, response.getOutputStream());
            } catch (ResourceException e) {
                System.out.println(e.getMessage());
            } catch (IOException e) {
                System.out.println(e.getMessage());
            } catch (ReportProcessingException e) {
                System.out.println(e.getMessage());
            }
        }
    }


    Project is build without any errors. But when I "call" pentaho.htm:
    #/ org.pentaho.reporting.engine.classic.core.modules. misc.datafactory.sql.JndiConnectionProvider.getCon nection Failed to access the JDNI-System
    javax.naming.NameNotFoundException: Name [jndiTestName] is not bound in this Context. Unable to find [jndiTestName].

    I can't find solution for this. Report must have jndi name visible. I know that error is or in jndi configuration, or that there is no initialization and binding between report and jndi name.

    Please, can some one give me a tip how to solve this problem.
    Thanks.
Working...
X