Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: Injecting the return value of a method into a bean

  1. #1
    Join Date
    Mar 2006
    Posts
    7

    Default Injecting the return value of a method into a bean

    Greetings

    I'm new to spring. Im amazed at how easy Spring makes everything. Now to the question. I need to be able to dynamically set the value of wsdlDocumentUrl. I wanted to create a bean that constructs the url and inject it into my TRMSReadinessService bean. Is that possible? The bean would have a getWsdlDocumentUrl method that would return the URL to the web service.

    So can you inject the return value from a bean?

    Thanks in advance
    Derrick

    The following is the bean that I want to inject into.
    PHP Code:

        
    <bean id="TRMSReadinessService" class="RASWEB.webservice.TRMS.src.TRMSPortProxyFactoryBean">
            <
    property name="serviceFactoryClass">
                <
    value>org.apache.axis.client.ServiceFactory</value>
            </
    property>
            <
    property name="wsdlDocumentUrl">
                <
    value>http://localhost:7001/SwnnWebServices/V1_0/Services/TEST.jws?WSDL</value>
            
    </property>
            
            <
    property name="namespaceUri"
                <
    value>http://www.openuri.org/</value>
            
    </property>
            
            <
    property name="serviceName">
                <
    value>TEST</value>
            </
    property>
            <
    property name="portName">
                <
    value>TESTSoap</value>
            </
    property>
            <
    property name="portInterface">
                <
    value>RASWEB.webservice.TRMS.axis.TESTSoap</value>
            </
    property>
            
            <
    property name="serviceInterface">
                <
    value>RASWEB.webservice.TRMS.src.TestService</value>
            </
    property>
        </
    bean

  2. #2
    Join Date
    Dec 2005
    Posts
    269

    Default

    threre are 4 ways (roughly):
    1. you can use PropertyPlaceholderConfigurer and store your URL in an external .properties file (not exactly what you need, but very simple )
    2. Use MethodInvokingFactoryBean
    3. Use your url-generating class as a factory and call it's factory method: static or instance's.
    4. Implement the FactoryBean interface for the url-generating class, though you'll introduce the dependency on Spring.

  3. #3
    Join Date
    Mar 2006
    Posts
    7

    Default

    Thank Injecteer

    I'm going to try your option 2

    Derrick

  4. #4
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    Quote Originally Posted by derrickfn
    I need to be able to dynamically set the value of wsdlDocumentUrl.
    Can you clarify "dynamic". Do you mean it can change at run time (e.g. specific to each logged on user)?

    Quote Originally Posted by derrickfn
    I wanted to create a bean that constructs the url and inject it into my TRMSReadinessService bean. Is that possible? The bean would have a getWsdlDocumentUrl method that would return the URL to the web service.
    Injecteers already answered this, very nicely as well One thing I would add is I am not sure whether Spring can convert from Strings to URLs. You might need to write your own propertyEditor (if you are using the propertyPlaceHolder suggestion). Checkout http://springframework.org/docs/refe...-customeditors (3.14)

    Quote Originally Posted by derrickfn
    So can you inject the return value from a bean?
    A resounding yes; you most certainly can

  5. #5
    Join Date
    Dec 2005
    Posts
    269

    Default

    Quote Originally Posted by yatesco
    One thing I would add is I am not sure whether Spring can convert from Strings to URLs.
    why not?

    the only issue, that can appear here is, that the default URLEditor might be servlet-context-related, so you'll have to expliciltly register org.springframework.beans.propertyeditors.URLEdito r in your context.

  6. #6
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    Quote Originally Posted by Injecteer
    why not?
    I was wondering whether Spring already had a registered URLPropertyEditor....
    Quote Originally Posted by Injecteer
    the only issue, that can appear here is, that the default URLEditor might be servlet-context-related, so you'll have to expliciltly register org.springframework.beans.propertyeditors.URLEdito r in your context.
    .....which you thenanswered

  7. #7
    Join Date
    Mar 2006
    Posts
    7

    Default

    Sorry for the long delay,

    I was trying to get the rest of the application working.

    Injectors suggest #2 worked without any problems. MY method returned a String with the Url. This application is part of a government delivery. The application will be delivered before I know what the actual end point is. Due to the delivery/installation requirements, I can not make any changes to the application contained in the war files. However, I can make changes to items stored in a database.

    Thanks for all of the suggestions
    Derrick

  8. #8

    Default

    I also have a similar requirement. I want to set wsdl url and web service end point at the run time.

    I am a newbie and not really familiar with MethodInvokingFactoryBean. Can you please paste an example on how this could be done.

    Thanks.


    Quote Originally Posted by derrickfn
    Sorry for the long delay,

    I was trying to get the rest of the application working.

    Injectors suggest #2 worked without any problems. MY method returned a String with the Url. This application is part of a government delivery. The application will be delivered before I know what the actual end point is. Due to the delivery/installation requirements, I can not make any changes to the application contained in the war files. However, I can make changes to items stored in a database.

    Thanks for all of the suggestions
    Derrick

  9. #9
    Join Date
    Jun 2005
    Posts
    4,231

    Default

    There is an example of usage of MethodInvolingFactoryBean in the API docs. See also PropertyPathFactoryBean - might also suit your needs.

  10. #10
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    Quote Originally Posted by parmod
    I am a newbie and not really familiar with MethodInvokingFactoryBean. Can you please paste an example on how this could be done.
    An example of the usage of MethodInvokingFactoryBean can be found in the API documentation of that class.

    Regards,
    Andreas

Posting Permissions

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