This week's book giveaway is in the Python forum.
We're giving away four copies of High Performance Python for Data Analytics and have Tiago Rodrigues Antao on-line!
See this thread for details.
Win a copy of High Performance Python for Data Analytics this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

can't using J2EE java mail?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,

Here is a problem that I have with my the usage of Java Mail Session
that i set up in weblogic. I use weblogic 8.1

When I do the JNDI lookup to the mail session (set up in the weblogic
admin interface), it looks that the lookup itself is ok but when i do
the casting, it doesn't work. Have a look at my code and the trace
produced :

writed an external client,follow:
<myCode>
Properties h = new Properties();


h.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory
");
h.put(Context.PROVIDER_URL,"t3://localhost:7001"); // provider url is
right
h.put(Context.SECURITY_PRINCIPAL,"weblogic");
h.put(Context.SECURITY_CREDENTIALS,"password");
Context namingContext = new InitialContext(h);
Session mailSession = (Session) namingContext.lookup("jndi/mail");
</myCode>


<trace>
javax.naming.ConfigurationException. Root exception is
java.rmi.MarshalExceptio
n: error marshalling return; nested exception is:
java.io.NotSerializableException: javax.mail.Session
java.io.NotSerializableException: javax.mail.Session
<<no stack trace available>>
</trace>


I can understand the exception as javax.mail.Session doesn't implement
serializble. But How do I have to do to make it work, then? Because what
I do is just how it's explained in the weblogic doc. Is there a mistake
in the do? Do I have to cast to somethig else?


Any help would be very appraciated.


Thanks.
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I took a quick look at the bea documentation and found these instructions, Using JavaMail with WebLogic Server Applications.

It has instructions to "send a message with JavaMail from within a WebLogic Server module", but you mention you're writing an external client. Did the instructions you found describe use by an external client?

You can use JavaMail without using the session configured in the weblogic console, you just need the API and to configure a session.
 
yun liu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I writed a java application that useing weblogic mail session outside weblogic ,show full codes,
<mycode>
import ........;
public class WebligicMail {
private Session mailSession;
public static void main(String[] args) {
WebligicMail weblogicMail = new WebligicMail();
try {
weblogicMail.init();
} catch (NamingException e) {
e.printStackTrace();
return;
}
try {
weblogicMail.sendMail("dliu@cn.test","test test");
} catch (MessagingException e) {
e.printStackTrace();
}
}
private void init() throws NamingException {
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL,"t3://localhost:7001"); // provider url is right
h.put(Context.SECURITY_PRINCIPAL,"weblogic");
h.put(Context.SECURITY_CREDENTIALS,"password");
Context namingContext = new InitialContext(h);
Session mailSession = (Session) namingContext.lookup("jndi/mail");
}

public void sendMail(String mailTo, String context) throws MessagingException {
Message msg = new MimeMessage(mailSession);
msg.setFrom();
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(
mailTo, false));
msg.setSubject("test weblogic mail");
msg.setSentDate(new Date());
// Content is stored in a MIME multi-part
// message// with one body partMimeBodyPart
MimeBodyPart mbp = new MimeBodyPart();
mbp.setText(context);
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp);
msg.setContent(mp);
Transport.send(msg);
}
}
</mycode>
<errors>
javax.naming.ConfigurationException. Root exception is java.rmi.MarshalException: error marshalling return; nested exception is:
java.io.NotSerializableException: javax.mail.Session
at weblogic.rjvm.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:108)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:284)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:244)
at weblogic.jndi.internal.ServerNamingNode_WLStub.lookup(Unknown Source)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:337)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:332)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at com.dsii.mail.weblogic.WebligicMail.init(WebligicMail.java:60)
at com.dsii.mail.weblogic.WebligicMail.main(WebligicMail.java:36)
Caused by: java.io.NotSerializableException: javax.mail.Session
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
at weblogic.common.internal.ChunkedObjectOutputStream.writeObject(ChunkedObjectOutputStream.java:106)
at weblogic.rjvm.MsgAbbrevOutputStream.writeObject(MsgAbbrevOutputStream.java:93)
at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:407)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:108)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:356)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:353)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:123)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:351)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:178)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:151)
</errors>

what's wrong?
thanks!
 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where in the documentation did you see that you can use that outside of weblogic?

Why don't you try configuring your own session?
 
yun liu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am only want to knowed ,why isn't running outside of weblogic?
javax.mail.Session isn't Serializable that is real reason?
or other reasons?

thanks very much!
 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your error message says the JavaMail Session isn't serializable and as you indicated it isn't. I only see the weblogic documentation discussing use of their convenience mail session within weblogic server or on server-side. So it sounds like what you are trying to do isn't supported.

But it is only a few lines of code to get your own session. Unless I am missing some important feature of the mail's session that weblogic is handling, I don't see how this is a big deal.

// set some properties like those you set in the console:
Properties props = new Properties();
props.put("mail.smtp.host", host);
props.put("mail.debug", "true");

// Get a session
Session session = Session.getInstance(props);
 
yun liu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see, thanks very much!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic