1 2 Previous Next 20 Replies Latest reply: Jan 18, 2013 3:27 AM by Kayaman RSS

    How to invoke a method ?

    689442
      Why method EditOrder in service cannot be invoked? I get error message: java.lang.reflect.InvocationTargetException: null
      public class WebServiceSecurity{
           
           private WebServiceSecurityService webServiceSecurityService;
           
           public WebServiceSecurity(){}
      
           private String EditOrder(String userName, Integer type, Integer startNo, Integer endNo){
                
                return webServiceSecurityService.EditOrder(userName, type, startNo, endNo);
           }
      
      ........................
      }
      
      
      public class WebServiceSecurityService {
           private WebServiceSecurityDao webServiceSecurityDao;
           public WebServiceSecurityService(){}
           
           public String EditOrder(String userName, Integer type, Integer startNo, Integer endNo){
      ..................
      }
      This is part of applicationContext.xml
           <bean id="webServiceSecurityBean" class="com.ws.WebServiceSecurity" >
           </bean>
           
           <bean id="webServiceSecurityDao" class="com.dao.WebServiceSecurityDao" >
           </bean>
           <bean id="webServiceSecurityService" class="com.service.WebServiceSecurityService">
                <property name="webServiceSecurityDao" ref="webServiceSecurityDao">
                </property>
           </bean>
        • 1. Re: How to invoke a method ?
          EJP
          Why method EditOrder in service cannot be invoked? I get error message: java.lang.reflect.InvocationTargetException: null
          Because you never initialize this:
               private WebServiceSecurityService webServiceSecurityService;
          • 2. Re: How to invoke a method ?
            689442
            I change it to public. But I still get the same error.
            • 3. Re: How to invoke a method ?
              Kayaman
              YE wrote:
              I change it to public. But I still get the same error.
              Nobody said anything about changing it to public. It's still null. It's uninitialized.

              You need to either initialize it yourself, or have it be automatically initialized with an annotation of some sort.
              • 4. Re: How to invoke a method ?
                689442
                How to initialize it with an annotation of some sort?
                • 5. Re: How to invoke a method ?
                  Kayaman
                  Eh, I don't know why spring isn't injecting the bean properly.
                  It's always hard to help you ADF people. You're in a world of your own.
                  • 6. Re: How to invoke a method ?
                    689442
                    What do you mean ADF people?
                    • 7. Re: How to invoke a method ?
                      EJP
                      Eh, I don't know why spring isn't injecting the bean properly.
                      I'm not aware that Spring has been told to do so.
                      • 8. Re: How to invoke a method ?
                        689442
                        I use injection. Is it a problem?
                        public class WebServiceSecurity{
                             
                             @Autowired
                             public WebServiceSecurityService webServiceSecurityService;
                             
                        ..............................................
                        
                             public  String ComService(String paramString) throws Exception{
                                  
                                  Object returnValue = null;
                                  String functionName="";
                        
                                  ArrayList<Object []>s = parseXml2(paramString);
                                  functionName = s.get(0)[0].toString();
                                  
                                  Class<?>[] mapValue = WStype.map.get(functionName);
                        
                                  Class cl=Class.forName("com.ws.WebServiceSecurity");
                        
                                  Method m=cl.getDeclaredMethod(functionName, mapValue);
                                  m.setAccessible(true);
                                  
                                  Object[] newobject=getObject(s.get(1), mapValue);
                                  
                                  m.invoke(cl.newInstance(), newobject);
                        
                                  return functionName;
                                  
                             }
                        • 9. Re: How to invoke a method ?
                          r035198x
                          Are you trying to call web services using reflection?
                          What are you trying to accomplish here? Some of those classes interfaces act as proxies and should only be invoked by the published interfaces for the proxy behavior to kick in.
                          • 10. Re: How to invoke a method ?
                            689442
                            No, I am not trying to invoke web services by reflection.
                            Reflection is used to invoked a method in the server level.
                            Client side send message including method name to wsdl . I just want to use reflection to find the method and run this method.
                            @Component
                            @WebService(name="webServiceSecurity",serviceName="webServiceSrcSecurity",targetNamespace="http://com.ws")
                            @SOAPBinding(style = SOAPBinding.Style.DOCUMENT,
                                      use=SOAPBinding.Use.LITERAL,
                                      parameterStyle=SOAPBinding.ParameterStyle.WRAPPED
                            )
                            public class WebServiceSecurity{
                            • 11. Re: How to invoke a method ?
                              r035198x
                              YE wrote:
                              No, I am not trying to invoke web services by reflection.
                              Great.

                              Why not add logging and printout the full stacktrace to know exactly which line is throwing the exception. At this stage we don't know if the problem is with the injection or elsewhere. Logging/checking the trace will narrow the problem down.
                              • 12. Re: How to invoke a method ?
                                689442
                                I chang the code about reflection in WebServiceSecurity Class like follows:
                                Class cl=Class.forName("com.dao.WebServiceSecurityDao");
                                I want it can invoke the method based on the name in WebServiceSecurityDao.
                                public class WebServiceSecurityDao extends HibernateDaoSupport{
                                
                                     public WebServiceSecurityDao(){}
                                     
                                     private String EditOrder(Integer type, Integer startNo, Integer endNo){
                                          
                                          try {
                                
                                               Session session = this.getSession();   //Error from here
                                               
                                               Criteria criteria = session.createCriteria(OrderUser.class);
                                Then, I get error as follow:
                                The session is null. How to load a session?

                                Thanks
                                -------------
                                java.lang.NullPointerException
                                     at org.springframework.orm.hibernate3.support.HibernateDaoSupport.getSession(HibernateDaoSupport.java:142)
                                     at com.dao.WebServiceSecurityDao.EditOrder(WebServiceSecurityDao.java:31)
                                     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                                     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                                • 13. Re: How to invoke a method ?
                                  r035198x
                                  1.) you should probably be posting in a Spring forum
                                  2.) You probably haven't setup the SessionFactory through a HibernateTemplate.
                                  3.) Much better is not to use HibernateDaoSupport at all. You don't need to tie yourself up with those Spring classes since Hibernate 3.0.1 :http://stackoverflow.com/questions/5104765/hibernatedaosupport-is-not-recommended-why
                                  • 14. Re: How to invoke a method ?
                                    gimbal2
                                    "The session is null. How to load a session?"

                                    Excellent question! To answer by reading the very rich and complete Spring manual, or one of the many books available on the framework.
                                    1 2 Previous Next