Results 1 to 9 of 9

Thread: Invoke a method that passes two null arguments?

  1. #1
    Join Date
    Aug 2004
    Posts
    7

    Default Invoke a method that passes two null arguments?

    Hi,
    I am trying to refactor some code, so that I can inject an object from a 3rd party class into my constructor. Usually, to get an object instance of this 3rd party class, I would invoke the following code

    ServiceEncryptor encryptor = com.third.party.ServiceEncryptorFactory.getInstanc e().getServiceEncryptor(null, null);

    How do I invoke a method that passes two null arguments to get an instance of my object? Currently, we use Spring v1.0.2.

    Thanks in advance.

    -Ed.

  2. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    You can use a MethodInvokingFactoryBean, but I'm not sure if 1.0.2 allows the calling of static method and the passing of arguments (1.1.1 does).

    Passing null arguments is always possible using the <nulll/> tag in your bean definition. Calling a static method can be done using the MethodInvokingFactoryBean's staticMethod property. Have a look at the JavaDocs from the MethodInvokingFactoryBean (http://www.springframework.org/docs/...ctoryBean.html). In your case, you'll have to use two of those
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  3. #3
    Join Date
    Aug 2004
    Posts
    7

    Default

    Thanks.

    Is this the correct declaration for passing two null arguments?

    <bean id="encryptionServiceFactory" class="org.springframework.beans.factory.config.Me thodInvokingFactoryBean">
    <property name="targetClass">
    <value>com.third.party.ServiceEncryptorFactory</value>
    </property>
    <property name="targetMethod">
    <value>getInstance</value>
    </property>
    </bean>

    <bean id="encryptionService" class="org.springframework.beans.factory.config.Me thodInvokingFactoryBean">
    <property name="targetObject">
    <ref local='encryptionServiceFactory'/>
    </property>
    <property name="targetMethod">
    <value>getServiceEncryptor</value>
    </property>
    <property name="arguments">
    <list>
    <value><null/></value>
    <value><null/></value>
    </list>
    </property>
    </bean>

  4. #4
    Join Date
    Aug 2004
    Location
    Toulouse, France
    Posts
    148

    Default

    Your configuration looks ok to "emulate" your initial need.
    Is it working like this or do you get troubles ?

    Olivier

  5. #5
    Join Date
    Aug 2004
    Posts
    7

    Default

    I'm getting exception messages upon startup. Here is the exception that I am seeing. My guess is that I am not declaring the null values correctly in the method invocation of getServiceEncryptor(null,null)



    [04.11.08 08:10:15:851 EST] 6b70b6fd SystemOut U 08:10:15 ERROR [P=362421:O=0:CT] (ContextLoader.java:108) ( ) Context initialization failed
    org.springframework.beans.factory.BeanDefinitionSt oreException: Line 24 in XML document from resource [/WEB-INF/conf/dev/env-specific-beans.xml] of ServletContext is invalid; nested exception is org.xml.sax.SAXParseException: The content of element type "value" must match "(#PCDATA)".
    org.xml.sax.SAXParseException: The content of element type "value" must match "(#PCDATA)".
    at org.apache.xerces.framework.XMLParser.parse(XMLPar ser.java:1033)
    at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(D ocumentBuilderImpl.java:172)
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBu ilder.java:138)
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:126)
    at org.springframework.context.support.AbstractXmlApp licationContext.loadBeanDefinitions(AbstractXmlApp licationContext.java:125)
    at org.springframework.context.support.AbstractXmlApp licationContext.refreshBeanFactory(AbstractXmlAppl icationContext.java:65)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:226)
    at org.springframework.web.context.support.XmlWebAppl icationContext.refresh(XmlWebApplicationContext.ja va:131)
    at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:156)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:97)
    at org.springframework.web.context.ContextLoaderServl et.init(ContextLoaderServlet.java:80)
    at javax.servlet.GenericServlet.init(GenericServlet.j ava:258)
    at com.ibm.servlet.engine.webapp.StrictServletInstanc e.doInit(ServletManager.java:802)
    at com.ibm.servlet.engine.webapp.StrictLifecycleServl et._init(StrictLifecycleServlet.java:137)
    at com.ibm.servlet.engine.webapp.PreInitializedServle tState.init(StrictLifecycleServlet.java:243)
    at com.ibm.servlet.engine.webapp.StrictLifecycleServl et.init(StrictLifecycleServlet.java:103)
    at com.ibm.servlet.engine.webapp.ServletInstance.init (ServletManager.java:388)
    at javax.servlet.GenericServlet.init(GenericServlet.j ava:258)
    at com.ibm.servlet.engine.webapp.ServletManager.addSe rvlet(ServletManager.java:84)
    at com.ibm.servlet.engine.webapp.WebAppServletManager .loadServlet(WebAppServletManager.java:226)
    at com.ibm.servlet.engine.webapp.WebAppServletManager .loadAutoLoadServlets(WebAppServletManager.java:35 7)
    at com.ibm.servlet.engine.webapp.WebApp.loadServletMa nager(WebApp.java:1001)
    at com.ibm.servlet.engine.webapp.WebApp.init(WebApp.j ava:133)
    at com.ibm.servlet.engine.srt.WebGroup.loadWebApp(Web Group.java:234)
    at com.ibm.servlet.engine.srt.WebGroup.init(WebGroup. java:139)
    at com.ibm.servlet.engine.ServletEngine.addWebApplica tion(ServletEngine.java:633)
    at com.ibm.ws.runtime.WebContainer.install(WebContain er.java:36)
    at com.ibm.ws.runtime.Server.startModule(Server.java: 615)
    at com.ibm.ws.runtime.StandardServer.initializeModule s(StandardServer.java:333)
    at com.ibm.ws.runtime.StandardServer.initializeRuntim e0(StandardServer.java:349)
    at com.ibm.ws.runtime.Server.initializeRuntime(Server .java:882)
    at com.ibm.ws.runtime.StandardServer.main(StandardSer ver.java:519)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.ibm.ws.bootstrap.WSLauncher.main(WSLauncher.ja va:158)

  6. #6
    Join Date
    Aug 2004
    Location
    Toulouse, France
    Posts
    148

    Default

    right, it is not <list> <value> <null /> etc.. but directly <list> <null /> <null /> </list>.
    Can you check this ?

    Olivier

  7. #7
    Join Date
    Aug 2004
    Posts
    7

    Default

    Thanks for the suggestion. So, I've changed the declaration to be

    <property name="arguments">
    <list>
    <null/>
    <null/>
    </list>
    </property>

    and upon system startup, I get this exception.


    [04.11.08 09:24:06:417 EST] 6b70bfa5 SystemOut U 09:24:06 ERROR [P=792636:O=0:CT] (ContextLoader.java:108) ( ) Context initialization failed
    org.springframework.beans.factory.BeanDefinitionSt oreException: Line 46 in XML document from resource [/WEB-INF/conf/dev/env-specific-beans.xml] of ServletContext is invalid; nested exception is org.xml.sax.SAXParseException: The content of element type "property" must match "(description?,(bean|ref|idref|list|set|map|props| value|null))".
    org.xml.sax.SAXParseException: The content of element type "property" must match "(description?,(bean|ref|idref|list|set|map|props| value|null))".
    at org.apache.xerces.framework.XMLParser.parse(XMLPar ser.java:1033)
    at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(D ocumentBuilderImpl.java:172)
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBu ilder.java:138)
    at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:126)
    at org.springframework.context.support.AbstractXmlApp licationContext.loadBeanDefinitions(AbstractXmlApp licationContext.java:125)
    at org.springframework.context.support.AbstractXmlApp licationContext.refreshBeanFactory(AbstractXmlAppl icationContext.java:65)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:226)
    at org.springframework.web.context.support.XmlWebAppl icationContext.refresh(XmlWebApplicationContext.ja va:131)
    at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:156)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:97)
    at org.springframework.web.context.ContextLoaderServl et.init(ContextLoaderServlet.java:80)
    at javax.servlet.GenericServlet.init(GenericServlet.j ava:258)
    at com.ibm.servlet.engine.webapp.StrictServletInstanc e.doInit(ServletManager.java:802)
    at com.ibm.servlet.engine.webapp.StrictLifecycleServl et._init(StrictLifecycleServlet.java:137)
    at com.ibm.servlet.engine.webapp.PreInitializedServle tState.init(StrictLifecycleServlet.java:243)
    at com.ibm.servlet.engine.webapp.StrictLifecycleServl et.init(StrictLifecycleServlet.java:103)
    at com.ibm.servlet.engine.webapp.ServletInstance.init (ServletManager.java:388)
    at javax.servlet.GenericServlet.init(GenericServlet.j ava:258)
    at com.ibm.servlet.engine.webapp.ServletManager.addSe rvlet(ServletManager.java:84)
    at com.ibm.servlet.engine.webapp.WebAppServletManager .loadServlet(WebAppServletManager.java:226)
    at com.ibm.servlet.engine.webapp.WebAppServletManager .loadAutoLoadServlets(WebAppServletManager.java:35 7)
    at com.ibm.servlet.engine.webapp.WebApp.loadServletMa nager(WebApp.java:1001)
    at com.ibm.servlet.engine.webapp.WebApp.init(WebApp.j ava:133)
    at com.ibm.servlet.engine.srt.WebGroup.loadWebApp(Web Group.java:234)
    at com.ibm.servlet.engine.srt.WebGroup.init(WebGroup. java:139)
    at com.ibm.servlet.engine.ServletEngine.addWebApplica tion(ServletEngine.java:633)
    at com.ibm.ws.runtime.WebContainer.install(WebContain er.java:36)
    at com.ibm.ws.runtime.Server.startModule(Server.java: 615)
    at com.ibm.ws.runtime.StandardServer.initializeModule s(StandardServer.java:333)
    at com.ibm.ws.runtime.StandardServer.initializeRuntim e0(StandardServer.java:349)
    at com.ibm.ws.runtime.Server.initializeRuntime(Server .java:882)
    at com.ibm.ws.runtime.StandardServer.main(StandardSer ver.java:519)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.ibm.ws.bootstrap.WSLauncher.main(WSLauncher.ja va:158)

  8. #8
    Join Date
    Aug 2004
    Location
    Toulouse, France
    Posts
    148

    Default

    The new piece of code shouldn't trigger the SAX exception that xerces now returns. The faulty line is number 46 while we were at line 24 before. Could you check that it is not another property which is problematic now ?

    Olivier

  9. #9
    Join Date
    Aug 2004
    Posts
    7

    Default

    Thank you for pointing that out. You are correct. There was a mis declaration at line 46, which I was able to fix. It looks like the system is initializing correctly. I'll do some more testing. Thanks very much for the advice.

    -Ed.

Similar Threads

  1. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  2. Replies: 4
    Last Post: Sep 27th, 2005, 11:31 PM
  3. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  4. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM
  5. Strange Data Access Error
    By webifyit in forum Data
    Replies: 2
    Last Post: Dec 28th, 2004, 11:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •