Announcement Announcement Module
Collapse
No announcement yet.
InputStream proporties Injection Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • InputStream proporties Injection

    Hello

    For few days I'm straggling with some problem.
    My applicationsContext config file looks like that:

    <bean id="ksInputStream" class="java.io.FileInputStream">
    <constructor-arg type="java.lang.String" value="/tmp/out.jks"></constructor-arg>
    </bean>

    <bean id="keyStoreProvider" class="java.security.KeyStore" factory-method="getInstance">
    <constructor-arg type="java.lang.String" value="jks"></constructor-arg>
    </bean>


    <bean id="certVerificator" class="pki.certificate.CertVerificatorImpl" destroy-method="save" init-method="setUp">
    <property name="ksIs">
    <ref bean="ksInputStream"/>
    </property>
    <property name="keyStore">
    <ref bean="keyStoreProvider"/>
    </property>
    <property name="ksOs">
    <ref bean="ksOutputStream"/>
    </property>
    </bean>


    So as You can see I'm injecting FileInputStream as property on certVerificator bean, here you have setter:

    public void setKsIs(InputStream ksIs) throws IOException
    {
    this.ksIs = ksIs;
    }


    Everything works fine with one little problem(main method):

    AbstractApplicationContext ac = new ClassPathXmlApplicationContext("cfg/testApplicationContext.xml");
    CertVerificatorImpl cv = (CertVerificatorImpl)ac.getBean("certVerificator") ;

    cv.preValidateCertFile("org.cert", RandomStringUtils.randomAlphanumeric(4) );
    cv.preValidateCertFile("second.pem", RandomStringUtils.randomAlphanumeric(4) );
    ac.close();

    I'm validate certificate and storing them to KeyStore and this id fine, but when I'm trying to load stored before certs ( from FileInputStream on /tmp/out.jks ) file is EOFExeption.

    When I was debugging application I observed that when application context is loaded out.jks is cleaned!! What is going on?

  • #2
    Not quite sure I understand what you mean here.

    Originally posted by karibe View Post
    When I was debugging application I observed that when application context is loaded out.jks is cleaned!! What is going on?

    Comment


    • #3
      OK, I'll try to explain.

      CertVerificator bean have to verify X509Cert and store it to output file.

      After all properties set I'm calling setUp init method where key store file is loaded
      this.getKeyStore().load( this.getKsInputStream, "pass".toCharArray() ) and then cv.preValidateCertFile("org.cert", RandomStringUtils.randomAlphanumeric(4) ); is called. Ater all certs files are validated destroy method is called where KeyStore is stored. this.getKeyStore().store( this.getKsOutputStream, "pass".toCharArray() ). In eclipse depug mode when I'm observing output key store file everything is OK, after destroy method is called all needed data is putted to file. As I said on next time bean initialization InputStream from key store file is loaded but in this moment file is empty, and this is very strange because after destroy method key store file was filled with proper certs entries. I observed that if this lines are executed:

      AbstractApplicationContext ac = new ClassPathXmlApplicationContext("cfg/testApplicationContext.xml");
      CertVerificatorImpl cv = (CertVerificatorImpl)ac.getBean("certVerificator") ;

      file is cleaned in some "magical" way:-)

      Comment

      Working...
      X