Hello,
I've built a very simple class file that pushed an e-mail out to a desired recepient.
Here is the class file:
package myBeans.src;
import java.beans.*;
import java.io.Serializable;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public class mailBean extends Object implements Serializable {
public static final String PROP_SAMPLE_PROPERTY = "sampleProperty";
private String sampleProperty;
private PropertyChangeSupport propertySupport;
private String host;
private String to;
private String from;
private String subject;
private String message;
private Properties props;
private Session session;
private MimeMessage mimeMess;
public mailBean() {
propertySupport = new PropertyChangeSupport(this);
//Get system properties
props = System.getProperties();
//Get session
session = Session.getDefaultInstance(props, null);
}
public String getMessageHost() {
return host;
}
public String getMessageTo() {
return to;
}
public String getMessageFrom() {
return from;
}
public String getMessageMessage() {
return message;
}
public String getMessageSubject() {
return subject;
}
public String getSampleProperty() {
return sampleProperty;
}
public void setMessageHost(String h) {
this.host = h;
props.put("mail.smtp.host", h);
// Define message
mimeMess = new MimeMessage(session);
}
public void setMessageTo(String t) {
this.to = t;
try {
mimeMess.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
} catch (AddressException e) {
System.err.println();
} catch (MessagingException e) {
System.err.println();
}
}
public void setMessageFrom(String f) {
this.from = f;
try {
mimeMess.setFrom(new InternetAddress(from));
} catch (AddressException e) {
System.err.println();
} catch (MessagingException e) {
System.err.println();
}
}
public void setMessageMessage(String m) {
this.message = m;
try{
mimeMess.setContent(message, "text/html");
//mimeMess.setText(message);
} catch (MessagingException e) {
System.err.println();
}
}
public void setMessageSubject(String s) {
subject = s;
try {
mimeMess.setSubject(subject);
} catch (MessagingException e) {
System.err.println();
}
}
public void sendMessage() {
try {
Transport.send(mimeMess);
} catch (MessagingException e) {
System.err.println();
}
}
public void setSampleProperty(String value) {
String oldValue = sampleProperty;
sampleProperty = value;
propertySupport.firePropertyChange(PROP_SAMPLE_PROPERTY, oldValue, sampleProperty);
}
public void addPropertyChangeListener(PropertyChangeListener listener) {
propertySupport.addPropertyChangeListener(listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
propertySupport.removePropertyChangeListener(listener);
}
public static void main(String args[]) {
mailBean mb = new mailBean();
mb.setMessageHost("<smtp server>");
mb.setMessageFrom("<from e-mail address>");
mb.setMessageTo("<to e-mail address>");
mb.setMessageSubject("A message test.");
mb.setMessageMessage("<H1>Test Message</H1> This is a test message.");
mb.sendMessage();
System.out.println("Message sent...");
}
}
I comment out the "main" method, before placing it in my WEB-INF/Classes directory. Now, after compiling this file, I'm able to run it in DOS and receive the test e-mail created in the main method.
However, once I comment out the main method and simply "instantiate" the bean from my JSP, I get that security error in the subject line.
The only thing I do is instantiate it. Here's the JSP file:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<jsp:useBean id="mailBean" class="myBeans.src.mailBean" scope="page" >
</jsp:useBean>
<html>
<head><title>JSP Page</title></head>
<body>
<h1>Contact Page</h1>
</body>
</html>
I verified that the properties on my class file is read/write within the myBeans/src directory under WEB-INF/classes
What can be causing this error? Did I forget something in my class file?
Discussions
EJB programming & troubleshooting: java.security.AccessControlException: access denied (java.util.P
-
java.security.AccessControlException: access denied (java.util.P (2 messages)
- Posted by: Ricardo Rodriguez
- Posted on: June 17 2004 14:04 EDT
Threaded Messages (2)
- java.security.AccessControlException: access denied (java.util.P by Ricardo Rodriguez on June 21 2004 14:33 EDT
- java.security.AccessControlException: access denied (java.util.P by Ricardo Rodriguez on June 26 2004 12:16 EDT
-
java.security.AccessControlException: access denied (java.util.P[ Go to top ]
- Posted by: Ricardo Rodriguez
- Posted on: June 21 2004 14:33 EDT
- in response to Ricardo Rodriguez
Anyone out there that might know about this "java.security.AccessControlException: access denied (java.util.PropertyPermission * read,write)" error? -
java.security.AccessControlException: access denied (java.util.P[ Go to top ]
- Posted by: Ricardo Rodriguez
- Posted on: June 26 2004 12:16 EDT
- in response to Ricardo Rodriguez
FYI to anyone out there who may be experiencing this on a server that they are not "hosting/managin" themselves, I discovered that my Web hosting company only supports Servlets and JSP.
Given this, I took out references to "PropertyChangeSupport" and "java.beans.*", and my code (servlet) worked, no longer giving me that security error.