geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ivan <xhh...@gmail.com>
Subject Re: svn commit: r1083678 - in /geronimo/server/trunk/plugins/javamail: geronimo-mail/ geronimo-mail/src/main/java/org/apache/geronimo/resource/mail/ geronimo-mail/src/test/java/org/apache/geronimo/resource/mail/ javamail/src/main/plan/
Date Mon, 21 Mar 2011 08:58:11 GMT
I think that "ger" name space should not be hardcoded there. It should be
got from the value of the jndiName.

2011/3/21 <violalu@apache.org>

> Author: violalu
> Date: Mon Mar 21 05:45:34 2011
> New Revision: 1083678
>
> URL: http://svn.apache.org/viewvc?rev=1083678&view=rev
> Log:
> GERONIMO-5862 bound ger:MailSession jndi to ger namespace.
>
> Modified:
>    geronimo/server/trunk/plugins/javamail/geronimo-mail/pom.xml
>
>  geronimo/server/trunk/plugins/javamail/geronimo-mail/src/main/java/org/apache/geronimo/resource/mail/MailGBean.java
>
>  geronimo/server/trunk/plugins/javamail/geronimo-mail/src/test/java/org/apache/geronimo/resource/mail/MailGBeanTest.java
>    geronimo/server/trunk/plugins/javamail/javamail/src/main/plan/plan.xml
>
> Modified: geronimo/server/trunk/plugins/javamail/geronimo-mail/pom.xml
> URL:
> http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/javamail/geronimo-mail/pom.xml?rev=1083678&r1=1083677&r2=1083678&view=diff
>
> ==============================================================================
> --- geronimo/server/trunk/plugins/javamail/geronimo-mail/pom.xml (original)
> +++ geronimo/server/trunk/plugins/javamail/geronimo-mail/pom.xml Mon Mar 21
> 05:45:34 2011
> @@ -63,6 +63,14 @@
>             <groupId>org.apache.geronimo.specs</groupId>
>             <artifactId>geronimo-activation_1.1_spec</artifactId>
>         </dependency>
> +
> +         <dependency>
> +            <groupId>org.apache.geronimo.framework</groupId>
> +            <artifactId>geronimo-kernel</artifactId>
> +            <version>${project.version}</version>
> +            <classifier>tests</classifier>
> +            <scope>test</scope>
> +        </dependency>
>     </dependencies>
>
>  </project>
>
> Modified:
> geronimo/server/trunk/plugins/javamail/geronimo-mail/src/main/java/org/apache/geronimo/resource/mail/MailGBean.java
> URL:
> http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/javamail/geronimo-mail/src/main/java/org/apache/geronimo/resource/mail/MailGBean.java?rev=1083678&r1=1083677&r2=1083678&view=diff
>
> ==============================================================================
> ---
> geronimo/server/trunk/plugins/javamail/geronimo-mail/src/main/java/org/apache/geronimo/resource/mail/MailGBean.java
> (original)
> +++
> geronimo/server/trunk/plugins/javamail/geronimo-mail/src/main/java/org/apache/geronimo/resource/mail/MailGBean.java
> Mon Mar 21 05:45:34 2011
> @@ -39,6 +39,11 @@ import org.apache.geronimo.management.Ja
>  import org.apache.geronimo.naming.ResourceSource;
>  import org.slf4j.Logger;
>  import org.slf4j.LoggerFactory;
> +import org.osgi.framework.BundleContext;
> +import org.osgi.framework.Filter;
> +import org.osgi.framework.ServiceReference;
> +
> +import javax.naming.spi.ObjectFactory;
>
>
>  /**
> @@ -72,6 +77,7 @@ public class MailGBean implements GBeanL
>     private String user;
>     private Boolean debug;
>     private String jndiName;
> +    private BundleContext bundleContext;
>
>
>     /**
> @@ -101,7 +107,8 @@ public class MailGBean implements GBeanL
>                      @ParamAttribute(name="host") String host,
>                      @ParamAttribute(name="user") String user,
>                      @ParamAttribute(name="debug") Boolean debug,
> -                     @ParamAttribute(name="jndiName") String jndiName) {
> +                     @ParamAttribute(name="jndiName") String jndiName,
> +                     @ParamSpecial(type =
> SpecialAttributeType.bundleContext) BundleContext bundleContext){
>         this.objectName = objectName;
>         this.protocols = protocols;
>         setUseDefault(useDefault);
> @@ -113,6 +120,7 @@ public class MailGBean implements GBeanL
>         setUser(user);
>         setDebug(debug);
>         setJndiName(jndiName);
> +        this.bundleContext = bundleContext;
>     }
>
>     /**
> @@ -374,21 +382,15 @@ public class MailGBean implements GBeanL
>         if (jndiName != null && jndiName.length() > 0) {
>             // first get the resource incase there are exceptions
>             Object value = $getResource();
> -
> -            // get the initial context
> -            Context context = new InitialContext();
> -            Name parsedName = context.getNameParser("").parse(jndiName);
> -
> -            // create intermediate contexts
> -            for (int i = 1; i < parsedName.size(); i++) {
> -                Name contextName = parsedName.getPrefix(i);
> -                if (!bindingExists(context, contextName)) {
> -                    context.createSubcontext(contextName);
> -                }
> -            }
> -
> -            // bind
> -            context.bind(jndiName, value);
> +
> +            //Get ger service, and bind ger:MailSession to context
> +            ServiceReference[] sr =
> bundleContext.getServiceReferences(ObjectFactory.class.getName(),
> "(osgi.jndi.url.scheme=ger)");
> +            if (sr != null){
> +             ObjectFactory objectFactory =  (ObjectFactory)
> bundleContext.getService(sr[0]);
> +             Context context =
> (Context)objectFactory.getObjectInstance(null, null, null, null);
> +             context.bind(jndiName, value);
> +            }
> +
>             log.info("JavaMail session bound to " + jndiName);
>         }
>     }
> @@ -407,10 +409,15 @@ public class MailGBean implements GBeanL
>         String jndiName = getJndiName();
>         if (jndiName != null && jndiName.length() > 0) {
>             try {
> -                Context context = new InitialContext();
> -                context.unbind(jndiName);
> +               //Get ger service, and bind ger:MailSession to context
> +                ServiceReference[] sr =
> bundleContext.getServiceReferences(ObjectFactory.class.getName(),
> "(osgi.jndi.url.scheme=ger)");
> +                if (sr != null){
> +                 ObjectFactory objectFactory =  (ObjectFactory)
> bundleContext.getService(sr[0]);
> +                 Context context =
> (Context)objectFactory.getObjectInstance(null, null, null, null);
> +                 context.unbind(jndiName);
> +                }
>                 log.info("JavaMail session unbound from " + jndiName);
> -            } catch (NamingException e) {
> +            } catch (Exception e) {
>                 // we tried... this is a common error which occurs during
> shutdown due to ordering
>             }
>         }
> @@ -443,4 +450,12 @@ public class MailGBean implements GBeanL
>         return false;
>     }
>
> +       public void setBundleContext(BundleContext bundleContext) {
> +               this.bundleContext = bundleContext;
> +       }
> +
> +       public BundleContext getBundleContext() {
> +               return bundleContext;
> +       }
> +
>  }
>
> Modified:
> geronimo/server/trunk/plugins/javamail/geronimo-mail/src/test/java/org/apache/geronimo/resource/mail/MailGBeanTest.java
> URL:
> http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/javamail/geronimo-mail/src/test/java/org/apache/geronimo/resource/mail/MailGBeanTest.java?rev=1083678&r1=1083677&r2=1083678&view=diff
>
> ==============================================================================
> ---
> geronimo/server/trunk/plugins/javamail/geronimo-mail/src/test/java/org/apache/geronimo/resource/mail/MailGBeanTest.java
> (original)
> +++
> geronimo/server/trunk/plugins/javamail/geronimo-mail/src/test/java/org/apache/geronimo/resource/mail/MailGBeanTest.java
> Mon Mar 21 05:45:34 2011
> @@ -25,6 +25,9 @@ import javax.mail.Transport;
>
>  import junit.framework.TestCase;
>
> +import org.osgi.framework.BundleContext;
> +import org.apache.geronimo.kernel.osgi.MockBundleContext;
> +
>
>  /**
>  * @version $Rev$ $Date$
> @@ -37,7 +40,8 @@ public class MailGBeanTest extends TestC
>         properties.put("mail.store.protocol", "testStore");
>         properties.put("mail.transport.protocol", "testTransport");
>
> -        MailGBean mail = new MailGBean("test:name=mail", null,
> Boolean.TRUE, properties, null, null, null, null, null, null, null);
> +        BundleContext bundleContext = new
> MockBundleContext(getClass().getClassLoader(), "", null, null);
> +        MailGBean mail = new MailGBean("test:name=mail", null,
> Boolean.TRUE, properties, null, null, null, null, null, null, null,
> bundleContext);
>         mail.doStart();
>         Object proxy = mail.$getResource();
>
> @@ -59,7 +63,8 @@ public class MailGBeanTest extends TestC
>         properties.put("mail.store.protocol", "POOKIE");
>         properties.put("mail.transport.protocol", "BEAR");
>
> -        MailGBean mail = new MailGBean("test:name=mail", null,
> Boolean.TRUE, properties, null, "test", "test", null, null, null, null);
> +        BundleContext bundleContext = new
> MockBundleContext(getClass().getClassLoader(), "", null, null);
> +        MailGBean mail = new MailGBean("test:name=mail", null,
> Boolean.TRUE, properties, null, "test", "test", null, null, null, null,
> bundleContext);
>         mail.doStart();
>         Object proxy = mail.$getResource();
>
> @@ -91,7 +96,8 @@ public class MailGBeanTest extends TestC
>         SMTPTransportGBean protocol = new
> SMTPTransportGBean("test:name=smtp", null, null, null, null, null, null,
> null, null, null, null, null, null, null, null, null, null, null, null,
> null, null, null, null, null, null, null);
>         protocol.doStart();
>
> -        MailGBean mail = new MailGBean("test:name=mail",
> Collections.<ProtocolGBean>singleton(protocol), Boolean.TRUE, properties,
> null, "test", "test", null, null, null, null);
> +        BundleContext bundleContext = new
> MockBundleContext(getClass().getClassLoader(), "", null, null);
> +        MailGBean mail = new MailGBean("test:name=mail",
> Collections.<ProtocolGBean>singleton(protocol), Boolean.TRUE, properties,
> null, "test", "test", null, null, null, null, bundleContext);
>         mail.doStart();
>         Object proxy = mail.$getResource();
>
> @@ -120,7 +126,8 @@ public class MailGBeanTest extends TestC
>         POP3StoreGBean protocol = new POP3StoreGBean("test:name=pop3",
> null, null, null, null, null, null, null, null, null, null, null, null,
> null, null);
>         protocol.doStart();
>
> -        MailGBean mail = new MailGBean("test:name=mail",
> Collections.<ProtocolGBean>singleton(protocol), Boolean.TRUE, properties,
> null, "test", "test", null, null, null, null);
> +        BundleContext bundleContext = new
> MockBundleContext(getClass().getClassLoader(), "", null, null);
> +        MailGBean mail = new MailGBean("test:name=mail",
> Collections.<ProtocolGBean>singleton(protocol), Boolean.TRUE, properties,
> null, "test", "test", null, null, null, null, bundleContext);
>         mail.doStart();
>         Object proxy = mail.$getResource();
>
> @@ -146,7 +153,8 @@ public class MailGBeanTest extends TestC
>         IMAPStoreGBean protocol = new IMAPStoreGBean("test:name=imap",
> null, null, null, null, null, null, null, null, null, null, null, null,
> null, null, null, null, null, null, null, null, null, null, null, null,
> null);
>         protocol.doStart();
>
> -        MailGBean mail = new MailGBean("test:name=mail",
> Collections.<ProtocolGBean>singleton(protocol), Boolean.TRUE, properties,
> null, "test", "test", null, null, null, null);
> +        BundleContext bundleContext = new
> MockBundleContext(getClass().getClassLoader(), "", null, null);
> +        MailGBean mail = new MailGBean("test:name=mail",
> Collections.<ProtocolGBean>singleton(protocol), Boolean.TRUE, properties,
> null, "test", "test", null, null, null, null, bundleContext);
>         mail.doStart();
>         Object proxy = mail.$getResource();
>
>
> Modified:
> geronimo/server/trunk/plugins/javamail/javamail/src/main/plan/plan.xml
> URL:
> http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/javamail/javamail/src/main/plan/plan.xml?rev=1083678&r1=1083677&r2=1083678&view=diff
>
> ==============================================================================
> --- geronimo/server/trunk/plugins/javamail/javamail/src/main/plan/plan.xml
> (original)
> +++ geronimo/server/trunk/plugins/javamail/javamail/src/main/plan/plan.xml
> Mon Mar 21 05:45:34 2011
> @@ -23,7 +23,7 @@
>     <gbean name="mail/MailSession"
> class="org.apache.geronimo.resource.mail.MailGBean">
>         <attribute name="transportProtocol">smtp</attribute>
>       <!--TODO osgi:jndi -->
> -        <!--<attribute name="jndiName">ger:MailSession</attribute>-->
> +       <attribute name="jndiName">ger:MailSession</attribute>
>         <reference name="Protocols"/>
>     </gbean>
>
>
>
>


-- 
Ivan

Mime
View raw message