Problem on configuring Java Mail Session

View: New views
20 Messages — Rating Filter:   Alert me  
< Prev | 1 - 2 | Next >

Problem on configuring Java Mail Session

by glassfish-2 :: Rate this Message:

| View Threaded | Show Only this Message

Dear All,

I was trying to configure a Java mail session on Glassfish V2 using the admin console, everything looks fine. But when I tried to deploy my app I got the following exceptions. I am using Spring 2.5 to instantiate the mail session, it works on other environment e.g. websphere and weblogic etc. but it encountered type mismatch on glassfish. I have read some articles suggesting to use MailConfiguration instead of MailSession in application, but that should be just a workaround. How can I solve this in a more appropriate way? What are matching editor or conversion strategy meant for?

 nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mailSender' defined in ServletContext resource [/WEB-INF/agd-service.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [com.sun.enterprise.deployment.MailConfiguration] to required type [javax.mail.Session] for property 'session'; nested exception is java.lang.IllegalArgumentException: No matching editors or conversion strategy found
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mailSender' defined in ServletContext resource [/WEB-INF/agd-service.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [com.sun.enterprise.deployment.MailConfiguration] to required type [javax.mail.Session] for property 'session'; nested exception is java.lang.IllegalArgumentException: No matching editors or conversion strategy found
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessException details (1) are:
PropertyAccessException 1:
org.springframework.beans.TypeMismatchException: Failed to convert property value of type [com.sun.enterprise.deployment.MailConfiguration] to required type [javax.mail.Session] for property 'session'; nested exception is java.lang.IllegalArgumentException: No matching editors or conversion strategy found
Caused by: java.lang.IllegalArgumentException: No matching editors or conversion strategy found
 at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:212)
 at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:127)
 at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:774)
 at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:607)
 at org.springframework.beans.AbstractPropertyAccessor.setPropertyValue(AbstractPropertyAccessor.java:49)
 at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:74)
 at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:57)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:965)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:740)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:417)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:140)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:248)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:128)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:950)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:740)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:417)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:140)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:248)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:128)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:950)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:740)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:417)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBeanDefinition(BeanDefinitionValueResolver.java:200)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:111)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:950)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:740)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:417)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:140)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:248)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:128)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:950)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:740)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:417)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBeanDefinition(BeanDefinitionValueResolver.java:200)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:111)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:950)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:740)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:417)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:140)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:248)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:128)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:950)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:740)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:417)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBeanDefinition(BeanDefinitionValueResolver.java:200)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:111)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:950)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:740)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:417)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:140)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:248)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:128)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:950)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:740)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:417)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBeanDefinition(BeanDefinitionValueResolver.java:200)
 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:111)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:950)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:740)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:417)
 at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:140)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:270)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:346)
 at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:156)
 at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
 at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
 at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4523)
 at org.apache.catalina.core.StandardContext.start(StandardContext.java:5184)
 at com.sun.enterprise.web.WebModule.start(WebModule.java:326)
 at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:973)
 at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:957)
 at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:688)
 at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1584)
 at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1222)
 at com.sun.enterprise.server.WebModuleDeployEventListener.moduleDeployed(WebModuleDeployEventListener.java:182)
 at com.sun.enterprise.server.WebModuleDeployEventListener.moduleDeployed(WebModuleDeployEventListener.java:278)
 at com.sun.enterprise.admin.event.AdminEventMulticaster.invokeModuleDeployEventListener(AdminEventMulticaster.java:974)
 at com.sun.enterprise.admin.event.AdminEventMulticaster.handleModuleDeployEvent(AdminEventMulticaster.java:961)
 at com.sun.enterprise.admin.event.AdminEventMulticaster.processEvent(AdminEventMulticaster.java:464)
 at com.sun.enterprise.admin.event.AdminEventMulticaster.multicastEvent(AdminEventMulticaster.java:176)
 at com.sun.enterprise.admin.server.core.DeploymentNotificationHelper.multicastEvent(DeploymentNotificationHelper.java:308)
 at com.sun.enterprise.deployment.phasing.DeploymentServiceUtils.multicastEvent(DeploymentServiceUtils.java:226)
 at com.sun.enterprise.deployment.phasing.ServerDeploymentTarget.sendStartEvent(ServerDeploymentTarget.java:298)
 at com.sun.enterprise.deployment.phasing.ApplicationStartPhase.runPhase(ApplicationStartPhase.java:132)
 at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:108)
 at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:919)
 at com.sun.enterprise.deployment.phasing.PEDeploymentService.start(PEDeploymentService.java:591)
 at com.sun.enterprise.deployment.phasing.PEDeploymentService.start(PEDeploymentService.java:635)
 at com.sun.enterprise.admin.mbeans.ApplicationsConfigMBean.start(ApplicationsConfigMBean.java:744)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at com.sun.enterprise.admin.MBeanHelper.invokeOperationInBean(MBeanHelper.java:375)
 at com.sun.enterprise.admin.MBeanHelper.invokeOperationInBean(MBeanHelper.java:358)
 at com.sun.enterprise.admin.config.BaseConfigMBean.invoke(BaseConfigMBean.java:464)
 at com.sun.jmx.mbeanserver.DynamicMetaDataImpl.invoke(DynamicMetaDataImpl.java:213)
 at com.sun.jmx.mbeanserver.MetaDataImpl.invoke(MetaDataImpl.java:220)
 at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:815)
 at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:784)
 at sun.reflect.GeneratedMethodAccessor14.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at com.sun.enterprise.admin.util.proxy.ProxyClass.invoke(ProxyClass.java:90)
 at $Proxy1.invoke(Unknown Source)
 at com.sun.enterprise.admin.server.core.jmx.SunoneInterceptor.invoke(SunoneInterceptor.java:304)
 at com.sun.enterprise.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:174)
 at com.sun.enterprise.deployment.client.DeploymentClientUtils.startApplication(DeploymentClientUtils.java:145)
 at com.sun.enterprise.deployment.client.DeployAction.run(DeployAction.java:537)
 at java.lang.Thread.run(Thread.java:595)
[Message sent by forum member 'dabaner' (dabaner)]

http://forums.java.net/jive/thread.jspa?messageID=263152

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Problem on configuring Java Mail Session

by glassfish-2 :: Rate this Message:

| View Threaded | Show Only this Message

The Java Mail session created on Glassfish works well if it is injected as @Resource (name="mail/myMail"), but it fails on direct using JNDI as following,
...
InitialContext ctx = new InitialContext();
Session session = (Session)ctx.lookup("mail/myMail");
...
the exceptioin is exactly the same as the spring case. MailConfiguration can not be cast to MailSession etc. Can someone give some lights on this?
[Message sent by forum member 'dabaner' (dabaner)]

http://forums.java.net/jive/thread.jspa?messageID=263316

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Problem on configuring Java Mail Session

by Sanjeeb Sahoo :: Rate this Message:

| View Threaded | Show Only this Message

If @Resource (name="mail/myMail")  was successfully injected, then you
should look up the resource in "java:comp/env" namespace as shown below:

new InitialContext().lookup("java:comp/env/mail/myMail");


Thanks,
Sahoo
glassfish@... wrote:

> The Java Mail session created on Glassfish works well if it is injected as @Resource (name="mail/myMail"), but it fails on direct using JNDI as following,
> ...
> InitialContext ctx = new InitialContext();
> Session session = (Session)ctx.lookup("mail/myMail");
> ...
> the exceptioin is exactly the same as the spring case. MailConfiguration can not be cast to MailSession etc. Can someone give some lights on this?
> [Message sent by forum member 'dabaner' (dabaner)]
>
> http://forums.java.net/jive/thread.jspa?messageID=263316
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>  

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Problem on configuring Java Mail Session

by glassfish-2 :: Rate this Message:

| View Threaded | Show Only this Message

Thanks for you reply.
Using "java:comp/env" as prefix didn't work, the application would encounter name not found exception. Actually using lookup("mail/MyMail") had found the resource but it failed to instantiate the Session object due to something else e.g. ClassCasting exception as the resource was recognized as mail configuration etc.
I am assuming in the scenario of dependency injection Glassfish might have done something internally convert the "MailConfiguration" to mail Session, but more likely in the JNDI scenario the convertion Glassfish has left the conversion to application developer! I don't think this is desirable for both Glassfish and application developer, please correct me if I have missed something.
Please note that, I have also tried using following code, it didn't work either,

@Resource (name="mail/MyMail")
public class MyMailerBean {
   @Resource SessionContext ctx;
    public void sendMail(){
        javax.mail.Session session = (javax.mail.Session)ctx.lookup("mail/MyMail");
......
[Message sent by forum member 'dabaner' (dabaner)]

http://forums.java.net/jive/thread.jspa?messageID=263770

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Problem on configuring Java Mail Session

by Sanjeeb Sahoo :: Rate this Message:

| View Threaded | Show Only this Message

Of course, you would NameNotFoundException if you just tried to look up
the resource without the injection code. Read chapter 5 of the Java
Platform Spec, where it is clearly described how you should be looking
up a resource and java:comp/env works.

Thanks,
Sahoo

glassfish@... wrote:

> Thanks for you reply.
> Using "java:comp/env" as prefix didn't work, the application would encounter name not found exception. Actually using lookup("mail/MyMail") had found the resource but it failed to instantiate the Session object due to something else e.g. ClassCasting exception as the resource was recognized as mail configuration etc.
> I am assuming in the scenario of dependency injection Glassfish might have done something internally convert the "MailConfiguration" to mail Session, but more likely in the JNDI scenario the convertion Glassfish has left the conversion to application developer! I don't think this is desirable for both Glassfish and application developer, please correct me if I have missed something.
> Please note that, I have also tried using following code, it didn't work either,
>
> @Resource (name="mail/MyMail")
> public class MyMailerBean {
>    @Resource SessionContext ctx;
>     public void sendMail(){
>         javax.mail.Session session = (javax.mail.Session)ctx.lookup("mail/MyMail");
> ......
> [Message sent by forum member 'dabaner' (dabaner)]
>
> http://forums.java.net/jive/thread.jspa?messageID=263770
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>  

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Problem on configuring Java Mail Session

by glassfish-2 :: Rate this Message:

| View Threaded | Show Only this Message

*** It is a bug. ***

Sun inconsistently returns Session when you're inside their Glassfish EE container, and a MailConfiguration if you're inside a non-compliant portion of their Glassfish EE container or a 3rd party container.  Here's a work around:
       
            // Outside the EJB container, MailSession lookups return a MailConfiguration rather
            // than a mail Session like one would expect.
           
            context = new InitialContext();
            Object object = context.lookup("mail/MyMailSession");
            Session session = null;
           
            if (object instanceof MailConfiguration)
            {
            MailConfiguration configuration = (MailConfiguration) object;
            session = Session.getInstance(configuration.getMailProperties());
            }
            else if (object instanceof Session)
            {
            session = (Session) object;
            }

            //  Compose the e-mail message.
           
            Message message = new MimeMessage(session);
[Message sent by forum member 'frenchdrip' (frenchdrip)]

http://forums.java.net/jive/thread.jspa?messageID=263855

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Problem on configuring Java Mail Session

by glassfish-2 :: Rate this Message:

| View Threaded | Show Only this Message

Hi Sahoo,
Below post from 'Frenchdrip' pointed out what my doubt was. Actually I tried followig different ways,
1. directly using resource injection on setter or instance variable
2. inject resource on class level and lookup it from sessionContext
3. inject resource on class level and lookup it from JNDI initial context.

Only 1 gets mailSession object. Both 2 and 3 return mail configuration which requires casting to session. I had never experienced such as well known 'NameNotFoundException' so I don't believe that's a JNDI problem.

Thanks,
Ken
[Message sent by forum member 'dabaner' (dabaner)]

http://forums.java.net/jive/thread.jspa?messageID=264257

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Problem on configuring Java Mail Session

by Sanjeeb Sahoo :: Rate this Message:

| View Threaded | Show Only this Message

Give me sometime, I shall get back to you after writing a sample to test
it myself.

Thanks,
Sahoo

glassfish@... wrote:

> Hi Sahoo,
> Below post from 'Frenchdrip' pointed out what my doubt was. Actually I tried followig different ways,
> 1. directly using resource injection on setter or instance variable
> 2. inject resource on class level and lookup it from sessionContext
> 3. inject resource on class level and lookup it from JNDI initial context.
>
> Only 1 gets mailSession object. Both 2 and 3 return mail configuration which requires casting to session. I had never experienced such as well known 'NameNotFoundException' so I don't believe that's a JNDI problem.
>
> Thanks,
> Ken
> [Message sent by forum member 'dabaner' (dabaner)]
>
> http://forums.java.net/jive/thread.jspa?messageID=264257
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>  

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Problem on configuring Java Mail Session

by Sanjeeb Sahoo :: Rate this Message:

| View Threaded | Show Only this Message

The correct way to look up resource in Java EE is to use the local name
(a.k.a. logical name) of the resource rather than the actual JNDI name
of the resource. You can run the following sample and see the difference:

@Stateless()
@WebService()
public class VisitorRegistrationService {

    // The actual JNDI name is mail/FossDemoMailSession
   // where as the local name is mail/MailSession.
    @Resource(name="mail/MailSession",
mappedName="mail/FossDemoMailSession")
    Session mailSession; // inject a Mail Session
    /**
     * Web service operation
     */
    @WebMethod
    public int registerVisitor(
            String name,
            String email) {
        try {
        InitialContext ctx = new InitialContext();
        Object a = ctx.lookup("mail/FossDemoMailSession");
        Object b = ctx.lookup("java:comp/env/mail/MailSession");
        System.out.println(a);
        System.out.println(b);
        } catch(Exception e) {
        e.printStackTrace();
        }
        return 0;
  }
}

Looking up the resource using the actual JNDI name
(mail/FossDemoMailSession) returns
com.sun.enterprise.deployment.MailConfiguration@49d560 object, where as
if you use java:comp/env/mail/MailSession, it returns
javax.mail.Session@157bbd4.

To try out yourself, just compile, jar and deploy. Create a MailSession
using admin gui and give it a name mail/FossDemoMailSession. You can
test the program by using the web service test client that is available
in the admin gui.

Thanks,
Sahoo

glassfish@... wrote:

> Hi Sahoo,
> Below post from 'Frenchdrip' pointed out what my doubt was. Actually I tried followig different ways,
> 1. directly using resource injection on setter or instance variable
> 2. inject resource on class level and lookup it from sessionContext
> 3. inject resource on class level and lookup it from JNDI initial context.
>
> Only 1 gets mailSession object. Both 2 and 3 return mail configuration which requires casting to session. I had never experienced such as well known 'NameNotFoundException' so I don't believe that's a JNDI problem.
>
> Thanks,
> Ken
> [Message sent by forum member 'dabaner' (dabaner)]
>
> http://forums.java.net/jive/thread.jspa?messageID=264257
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>  

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Problem on configuring Java Mail Session

by glassfish-2 :: Rate this Message:

| View Threaded | Show Only this Message

You sample code works because the @Resource(name="mail/MailSession", mappedName="...") has been injected to the Session object, as such it is "recognized" as MailSession in this context...

Could you please try to move @Resource(name="mail/MailSession", mappedName=...) up to the class level, and then look it inside the class,
e.g.
@Resource(name="mail/MailSession", mappedName="FossDemoMailSession")
@Stateless

public class VisitorRegistrationService{
....
 void someMethod{
    InitialContext ctx = new InitialContext();
    Object a = ctx.lookup("mail/FossDemoMailSession");
    Object b = ctx.lookup("java:comp/env/mail/MailSession");
...
You will get that ClassCastException!

Please note that, I changed the SessionEJB from WebService, because I was experiencing problem when I annotated @Resource on the class level, the MailSession could not be injected even it is legal according to the EJB 3 Spec...
[Message sent by forum member 'dabaner' (dabaner)]

http://forums.java.net/jive/thread.jspa?messageID=264975

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Problem on configuring Java Mail Session

by Sanjeeb Sahoo :: Rate this Message:

| View Threaded | Show Only this Message

While using @Resource at the class level, use "type" field of @Resource
to indicate the type of the resource. The javadoc of @Resource says the
following:

    /**
     * The Java type of the resource.  For field annotations,
     * the default is the type of the field.  For method annotations,
     * the default is the type of the JavaBeans property.
     * For class annotations, there is no default and this must be
     * specified.
     */
    Class type() default java.lang.Object.class;

So, you should do something like this:

@Resource(name="mail/MailSession3", type=Session.class,
mappedName="mail/FossDemoMailSession")

Without the type attribute, @Resource is ignored. If you run verifier
against such an app, it will report a nice error.

Thanks,
Sahoo

glassfish@... wrote:

> You sample code works because the @Resource(name="mail/MailSession", mappedName="...") has been injected to the Session object, as such it is "recognized" as MailSession in this context...
>
> Could you please try to move @Resource(name="mail/MailSession", mappedName=...) up to the class level, and then look it inside the class,
> e.g.
> @Resource(name="mail/MailSession", mappedName="FossDemoMailSession")
> @Stateless
>
> public class VisitorRegistrationService{
> ....
>  void someMethod{
>     InitialContext ctx = new InitialContext();
>     Object a = ctx.lookup("mail/FossDemoMailSession");
>     Object b = ctx.lookup("java:comp/env/mail/MailSession");
> ...
> You will get that ClassCastException!
>
> Please note that, I changed the SessionEJB from WebService, because I was experiencing problem when I annotated @Resource on the class level, the MailSession could not be injected even it is legal according to the EJB 3 Spec...
> [Message sent by forum member 'dabaner' (dabaner)]
>
> http://forums.java.net/jive/thread.jspa?messageID=264975
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>  

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Problem on configuring Java Mail Session

by glassfish-2 :: Rate this Message:

| View Threaded | Show Only this Message

Hi Sahoo,

Thanks for that. The @Resource at class level works either.

Can I ask you a further question on this, that is how to work it out using deployment descriptor instead? Below are ejb-jar.xml and sun-ejb-jar.xml I am using, when I added them into your example and commented out the @Resource annotation, I got both a and b are MailConfiguration, not the desired MailSession.
Can you please have a look and let me know if I did something wrong?
ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>

<ejb-jar xmlns = "http://java.sun.com/xml/ns/javaee"
         version = "3.0"
         xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
    <enterprise-beans>
        <session>
            <ejb-name>VisitorRegistrationService</ejb-name>
            <ejb-class>ejb.VisitorRegistrationService</ejb-class>
            <resource-env-ref>
                <resource-env-ref-name>mail/MailSession</resource-env-ref-name>
                <resource-env-ref-type>javax.mail.Session</resource-env-ref-type>
               
            </resource-env-ref>
        </session>
    </enterprise-beans>
</ejb-jar>

sun-ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 EJB 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-0.dtd">
<sun-ejb-jar>
  <enterprise-beans>
      <ejb>
          <ejb-name>VisitorRegistrationService</ejb-name>
          <jndi-name>VisitorRegistrationService</jndi-name>
          <resource-env-ref>
              <resource-env-ref-name>mail/MailSession</resource-env-ref-name>
              <jndi-name>mail/FossDemoMailSession</jndi-name>
          </resource-env-ref>
      </ejb>
  </enterprise-beans>
</sun-ejb-jar>


Thanks
Ken
[Message sent by forum member 'dabaner' (dabaner)]

http://forums.java.net/jive/thread.jspa?messageID=265260

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Problem on configuring Java Mail Session

by Sanjeeb Sahoo :: Rate this Message:

| View Threaded | Show Only this Message

Use resource-ref instead of resource-env-ref. Following is an example of
what you need to inject a mail.Session into your EJB without using
annotation.

<resource-ref>
    <res-ref-name>mail/MailSession</res-ref-name>
    <res-type>javax.mail.Session</res-type>
    <mapped-name>mail/FossDemoMailSession</mapped-name>
    <injection-target>
       
<injection-target-class>ejb.VisitorRegistrationService</injection-target-class>
       <injection-target-name>mailSession</injection-target-name>
    </injection-target>
</resource-ref>

It uses mappedName entry, so no need for using sun-ejb-jar.xml for
mapping the local name to global JNDI name.

There is a trick that you can use in future to find out the exact DD
required for such cases:
1. deploy the original sample which uses annotations.
2. Open to
$GF_HOME/domains/domain1/generated/xml/j2ee-module/<ejb-jar-name>/META-INF/ejb-jar.xml.
You can now see the equivalent ejb-jar.xml that GlassFish has generated
from your annotations in source code. Copy and paste relevant sections
into your ejb-jar.xml.

Thanks,
Sahoo

glassfish@... wrote:

> Hi Sahoo,
>
> Thanks for that. The @Resource at class level works either.
>
> Can I ask you a further question on this, that is how to work it out using deployment descriptor instead? Below are ejb-jar.xml and sun-ejb-jar.xml I am using, when I added them into your example and commented out the @Resource annotation, I got both a and b are MailConfiguration, not the desired MailSession.
> Can you please have a look and let me know if I did something wrong?
> ejb-jar.xml
> <?xml version="1.0" encoding="UTF-8"?>
>
> <ejb-jar xmlns = "http://java.sun.com/xml/ns/javaee"
>          version = "3.0"
>          xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
>          xsi:schemaLocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
>     <enterprise-beans>
>         <session>
>             <ejb-name>VisitorRegistrationService</ejb-name>
>             <ejb-class>ejb.VisitorRegistrationService</ejb-class>
>             <resource-env-ref>
>                 <resource-env-ref-name>mail/MailSession</resource-env-ref-name>
>                 <resource-env-ref-type>javax.mail.Session</resource-env-ref-type>
>                
>             </resource-env-ref>
>         </session>
>     </enterprise-beans>
> </ejb-jar>
>
> sun-ejb-jar.xml
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 EJB 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-0.dtd">
> <sun-ejb-jar>
>   <enterprise-beans>
>       <ejb>
>           <ejb-name>VisitorRegistrationService</ejb-name>
>           <jndi-name>VisitorRegistrationService</jndi-name>
>           <resource-env-ref>
>               <resource-env-ref-name>mail/MailSession</resource-env-ref-name>
>               <jndi-name>mail/FossDemoMailSession</jndi-name>
>           </resource-env-ref>
>       </ejb>
>   </enterprise-beans>
> </sun-ejb-jar>
>
>
> Thanks
> Ken
> [Message sent by forum member 'dabaner' (dabaner)]
>
> http://forums.java.net/jive/thread.jspa?messageID=265260
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>  

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Problem on configuring Java Mail Session

by glassfish-2 :: Rate this Message:

| View Threaded | Show Only this Message

Thanks a lot, Sahoo!
[Message sent by forum member 'dabaner' (dabaner)]

http://forums.java.net/jive/thread.jspa?messageID=265265

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Problem on configuring Java Mail Session

by glassfish-2 :: Rate this Message:

| View Threaded | Show Only this Message

Can you please file an issue on Glassfish V2 to get this issue fixed in the next update for Glassfish?
[Message sent by forum member 'uppalapati' (uppalapati)]

http://forums.java.net/jive/thread.jspa?messageID=275023

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Problem on configuring Java Mail Session

by glassfish-2 :: Rate this Message:

| View Threaded | Show Only this Message

No need.  This is a known problem, issue #4500 ( https://glassfish.dev.java.net/issues/show_bug.cgi?id=4500 )

Note that while the behavior is undesirable (and I consider it a bug), it is not a spec violation.

Feel free to add your name(s) to the CC field of the above issue if you wish to track it's progress.
[Message sent by forum member 'peterwx' (peterwx)]

http://forums.java.net/jive/thread.jspa?messageID=275029

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Problem on configuring Java Mail Session

by glassfish-2 :: Rate this Message:

| View Threaded | Show Only this Message

Hi All,

Trying to configure JavaMail in Glassfish V3 TP2, but according to few Sun email threads, i.e. http://markmail.org/message/dk7ty24u3aob3lqe, asadmin create-javamail-resource command was removed, and javamail resource menu entry was removed from admin GUI.  Another email indicated there is no backend support for these commands yet.  Has Glassfish V3 TP2 kept its JavaMail feature?  If so, how could admin user configure it?

Any helps highly appreciated.

Robert
[Message sent by forum member 'ryen' (ryen)]

http://forums.java.net/jive/thread.jspa?messageID=296723

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Problem on configuring Java Mail Session

by glassfish-2 :: Rate this Message:

| View Threaded | Show Only this Message

GlassFish V3 (TP2 or the upcoming Prelude release) do not support mail resources yet.  

The mail api is included, but you'll have to create and manage the sessions yourself if you want to use such code with V3 right now.
[Message sent by forum member 'peterwx' (peterwx)]

http://forums.java.net/jive/thread.jspa?messageID=296730

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Problem on configuring Java Mail Session

by glassfish-2 :: Rate this Message:

| View Threaded | Show Only this Message

Could you provide me a sample, or point me to the resources where I could find one?  

I'm currently deploying Liferay 5.1 to Glassfish v3 tp2.  Has anyone implement similar JavaMail session management code in Websynergy?  

Thank you for your help!
[Message sent by forum member 'ryen' (ryen)]

http://forums.java.net/jive/thread.jspa?messageID=296736

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Problem on configuring Java Mail Session

by glassfish-2 :: Rate this Message:

| View Threaded | Show Only this Message

Could you provide me a sample, or point me to the resources where I could find one?

I'm currently deploying Liferay 5.1 to Glassfish v3 tp2. Has anyone implement similar JavaMail session management code in Websynergy?

Thank you for your help!
[Message sent by forum member 'ryen' (ryen)]

http://forums.java.net/jive/thread.jspa?messageID=296739

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...

< Prev | 1 - 2 | Next >