Results 1 to 3 of 3

Thread: Ensuring a system property is set

  1. #1

    Default Ensuring a system property is set

    Hi

    I have a bunch of system properties that i need to be set before I can do any JSSE stuff. I wont rely on these being set with -D options on the command line (though they may be), so my bean - in this case a connection factory - which depends on these properties has a dependency like

    Code:
      <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath&#58;jsse.properties"/>
        <property name="ignoreResourceNotFound" value="true"/>
      </bean>
    
      <bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean" depends-on="keyStoreProperty,keyStoreTypeProperty,keyStorePasswordProperty,trustStoreProperty,trustStoreTypeProperty,trustStorePasswordProperty">
    ...
    and then my definition of one of these properties is

    Code:
      <bean id="setSystemProperty" abstract="true" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetClass" value="java.lang.System"/>
        <property name="targetMethod" value="setProperty"/>
      </bean>
    
      <bean id="keyStoreProperty" parent="setSystemProperty">
        <property name="arguments">
          <list>
            <value>javax.net.ssl.keyStore</value>
            <value>$&#123;javax.net.ssl.keyStore&#125;</value>
          </list>
        </property>
      </bean>
    This works OK, because a user could invoke Java with a -Djavax.net.ssl.keyStore=whatever.jks option or put javax.net.ssl.keyStore=whatever.jks in jsse.properties (and they'd not be able to override it at the command line, which is potentially useful).

    This is all a bit long-winded - can anyone think of a more consice way to do it?

  2. #2

    Default

    Actually, my main gripe with this is that there may be times when JSSE properties may not be set (when they're not relevant).

    Is there a way to avoid the PropertyPlaceholderConfigurer complaining when the JSSE properties are not set, when I'm trying to use the same set of config for non-JSSE communictions?

    I can get around this by setting

    Code:
    javax.net.ssl.keyStore=
    javax.net.ssl.keyStoreType=
    ...
    in my jsse.properties, but I'd like it to cope if there is just no jsse.properties supplied at all.

  3. #3
    Join Date
    Oct 2004
    Location
    Herndon, VA, US
    Posts
    648

    Default

    I can think of two ways, both having to do with overriding some method from PropertiesLoaderSupport - PropertyPlaceholderConfigurer's grandparent class.

    You can subclass PropertyPlaceholderConfigurer and override loadProperties with some logic that ignore FileNotFoundException.

    You can also subclass the same class, but override setLocation and/or setLocations to preemptively check all the locations and filter out the ones that don't exist.
    --Jing Xue

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Unit testing with JOTM and JtaTransactionManager
    By lalle in forum Architecture
    Replies: 1
    Last Post: Oct 15th, 2005, 09:05 AM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. Replies: 4
    Last Post: Aug 17th, 2005, 04:42 AM
  5. Replies: 2
    Last Post: May 13th, 2005, 05:42 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
  •