8 Replies Latest reply: Dec 6, 2012 6:44 AM by Gandhaveedi RSS

    to call stored procedure inside servlet.java class

    Gandhaveedi
      Hi,

      I am using JDEV 11GR2.

      My requirement is i need to call store procedure in my servlet java class.

      I am able to call store procedure in my backing bean class: this is done mi the following manner.

      1. created method in AppModuleImpl class and expose same method in client interface.
      2. Added method in the test.jspx page pagedef.xml and execute the same in backing bean test.java in the following manner:

      FacesContext facesContext = FacesContext.getCurrentInstance();
      Application app = facesContext.getApplication();
      ExpressionFactory elFactory = app.getExpressionFactory();
      ELContext elContext = facesContext.getELContext();
      ValueExpression valueExp =
      elFactory.createValueExpression(elContext, "#{bindings}", Object.class);
      BindingContainer binding= (BindingContainer)valueExp.getValue(elContext);
      OperationBinding operationBinding=binding.getOperationBinding("procedure_name");
      // Set the Input parameters to the operation bindings as below
      operationBinding.getParamsMap().put("OrgName", "org");
      //operationBinding.getParamsMap().put("SiteIdentifier", "M");
      // Invoke the Application module method
      operationBinding.execute();

      the above approach is working fine.

      Now my question is how can I call the method written inside AppModuleImpl, in servlet.java(Servlet will not be having any jspx page and this will be executed before the link is launched in the browser).

      please suggest me if there are any alternatives as well.

      Thanks,
      Veeresh
        • 1. Re: to call stored procedure inside servlet.java class
          Timo Hahn
          Check http://wp.me/pcBZk-bU where I outlined two solutions.

          Timo
          • 2. Re: to call stored procedure inside servlet.java class
            Alejandro Profet
            Hi Veeresh,

            I recently had to deal with a similar issue (concurrent timers), and the solution was as simple as creating an ADF filter extending from oracle.adf.share.http.ServletADFFilter.

            Something like this works fine for me:
            ADF filter class:
            public final class TimerManager
              extends ServletADFFilter
            {
              @Override
              public void init(FilterConfig filterConfig)
              {
                ApplicationModule am = Configuration.createRootApplicationModule("model.Model", "AppModuleLocal");
                ...
              }
            }
            Declared in web.xml:
            <filter>
              <display-name>timer</display-name>
              <filter-name>timer</filter-name>
              <filter-class>core.TimerManager</filter-class>
            </filter>
            AP
            • 3. Re: to call stored procedure inside servlet.java class
              Gandhaveedi
              Hi Timo, AP,

              thank you very much for your valuable response.

              I am trying to implement the same thing in my servlet class.

              I ll post my progress in the next post.

              Thanks,
              Veeresh
              • 4. Re: to call stored procedure inside servlet.java class
                Gandhaveedi
                Hi Timo,

                The approach you mentioned in the post to access AppModuleImpl method inside servlet, same things will holds good to access the view object inside servlet?

                Please suggest.

                Thanks,
                Veeresh
                • 5. Re: to call stored procedure inside servlet.java class
                  Timo Hahn
                  Yes, this works too. If you need access to the same score from a page read http://www.oracle.com/technetwork/indexes/samplecode/jdeveloper-adf-sample-522118.html

                  Timo
                  • 6. Re: to call stored procedure inside servlet.java class
                    Gandhaveedi
                    Hi Timo,

                    I followed the steps which you mentioned in the post :http://wp.me/pcBZk-bU.

                    I am getting following error while executing the application. The only change i made from your approach is instead mapping to imageServlet I mapped to QuartzServlet(I am executing Appmodule method in quartzServlet) in ADFBindings filter mappings.

                    <ADFContext> <getCurrent> Automatically initializing a DefaultContext for getCurrent.
                    Caller should ensure that a DefaultContext is proper for this use.
                    Memory leaks and/or unexpected behaviour may occur if the automatic initialization is performed improperly.
                    This message may be avoided by performing initADFContext before using getCurrent().
                    For more information please enable logging for oracle.adf.share.ADFContext at FINEST level.
                    Inside catch of Quartz servlet
                    java.lang.NullPointerException
                         at com.mmi.enc.servlet.QuartzServlet.init(QuartzServlet.java:65)
                         at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run(StubSecurityHelper.java:283)
                         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
                         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)


                    From what i understand is BindingContext is not yet initialized to access the method in servlet. Please suggest me if I missed anything in web.xml mapping

                    thanks,
                    Veeresh
                    • 7. Re: to call stored procedure inside servlet.java class
                      Timo Hahn
                      So what line of code is at the given position in your servlet?

                      Timo
                      • 8. Re: to call stored procedure inside servlet.java class
                        Gandhaveedi
                        Hi Timo,

                        thanks for your response.

                        Here is the code which throws that exception.

                        BindingContext bindingContext=null;
                        bindingContext = BindingContext.getCurrent();
                        at this line DCBindingContainer dcBindingContainer =
                        bindingContext.findBindingContainer("com_mmi_enc_ServletPageDef");

                        thanks,
                        Veeresh