Update of /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/senders
In directory sc8-pr-cvs1:/tmp/cvs-serv10766/src/java/org/neuclear/senders
Modified Files:
Sender.java SmtpSender.java
Added Files:
NeuSender.java UnsupportedEndpointException.java
Log Message:
Added SignedMessage contract for signing simple textual contracts.
Added NeuSender, updated SmtpSender and Sender to take plain email addresses (without the mailto:)
Added AbstractObjectCreationTest to make it quicker to write unit tests to verify
NamedObjectBuilder/SignedNamedObject Pairs.
Sample application has been expanded with a basic email application.
Updated docs for sample web app.
Added missing LGPL LICENSE.txt files to signer and sample app
--- NEW FILE: NeuSender.java ---
package org.neuclear.senders;
import org.neuclear.id.SignedNamedObject;
import org.neuclear.id.NSTools;
import org.neuclear.id.Identity;
import org.neuclear.id.resolver.NSResolver;
import org.neuclear.commons.NeuClearException;
import org.neuclear.xml.XMLException;
/**
* Created by IntelliJ IDEA.
* User: pelleb
* Date: Dec 16, 2003
* Time: 8:42:56 AM
* To change this template use Options | File Templates.
*/
public class NeuSender extends Sender{
public SignedNamedObject send(String endpoint, SignedNamedObject obj) throws NeuClearException, XMLException, UnsupportedEndpointException {
if (NSTools.isValidName(endpoint)){
Identity id=NSResolver.resolveIdentity(endpoint);
return id.receive(obj);
}
throw new UnsupportedEndpointException(this,endpoint);
}
}
--- NEW FILE: UnsupportedEndpointException.java ---
package org.neuclear.senders;
import org.neuclear.commons.NeuClearException;
/**
* Created by IntelliJ IDEA.
* User: pelleb
* Date: Dec 16, 2003
* Time: 8:45:31 AM
* To change this template use Options | File Templates.
*/
public class UnsupportedEndpointException extends NeuClearException {
public UnsupportedEndpointException(Sender sender,String endpoint) {
super("endpoint: "+endpoint+" not supported by: "+sender.getClass().getName());
this.endpoint=endpoint;
this.sender=sender;
}
public String getEndpoint() {
return endpoint;
}
public Sender getSender() {
return sender;
}
private final String endpoint;
private final Sender sender;
}
Index: Sender.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/senders/Sender.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** Sender.java 10 Dec 2003 23:58:52 -0000 1.13
--- Sender.java 16 Dec 2003 15:05:00 -0000 1.14
***************
*** 8,11 ****
--- 8,20 ----
* $Id$
* $Log$
+ * Revision 1.14 2003/12/16 15:05:00 pelle
+ * Added SignedMessage contract for signing simple textual contracts.
+ * Added NeuSender, updated SmtpSender and Sender to take plain email addresses (without the mailto:)
+ * Added AbstractObjectCreationTest to make it quicker to write unit tests to verify
+ * NamedObjectBuilder/SignedNamedObject Pairs.
+ * Sample application has been expanded with a basic email application.
+ * Updated docs for sample web app.
+ * Added missing LGPL LICENSE.txt files to signer and sample app
+ *
* Revision 1.13 2003/12/10 23:58:52 pelle
* Did some cleaning up in the builders
***************
*** 83,93 ****
public abstract class Sender {
! public abstract SignedNamedObject send(String endpoint, SignedNamedObject obj) throws NeuClearException, XMLException;
public static SignedNamedObject quickSend(final String endpoint, final SignedNamedObject obj) throws NeuClearException {
! final int protloc = endpoint.indexOf(":");
! if (protloc < 0)
! throw new NeuClearException(endpoint + "Is not in URL format");
! final String protocol = endpoint.substring(0, protloc);
final Sender sender = getSender(protocol);
if (sender == null)
--- 92,99 ----
public abstract class Sender {
! public abstract SignedNamedObject send(String endpoint, SignedNamedObject obj) throws NeuClearException, XMLException, UnsupportedEndpointException;
public static SignedNamedObject quickSend(final String endpoint, final SignedNamedObject obj) throws NeuClearException {
! final String protocol = getProtocol(endpoint);
final Sender sender = getSender(protocol);
if (sender == null)
***************
*** 100,103 ****
--- 106,119 ----
}
+ private static String getProtocol(final String endpoint) throws NeuClearException {
+ final int protloc = endpoint.indexOf(":");
+ final int atloc = endpoint.indexOf("@");
+ if (protloc < 0&&atloc<0)
+ throw new NeuClearException(endpoint + "Is not in URL format");
+ if (protloc>=0)
+ return endpoint.substring(0, protloc);
+ return "mailto";
+ }
+
public static Sender getSender(final String protocol) {
if (SENDERS == null) {
***************
*** 106,109 ****
--- 122,126 ----
SENDERS.put("http", new SoapSender());
SENDERS.put("mailto", new SmtpSender());
+ SENDERS.put("neu", new NeuSender());
}
Index: SmtpSender.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/senders/SmtpSender.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** SmtpSender.java 10 Dec 2003 23:58:52 -0000 1.15
--- SmtpSender.java 16 Dec 2003 15:05:00 -0000 1.16
***************
*** 8,11 ****
--- 8,20 ----
* $Id$
* $Log$
+ * Revision 1.16 2003/12/16 15:05:00 pelle
+ * Added SignedMessage contract for signing simple textual contracts.
+ * Added NeuSender, updated SmtpSender and Sender to take plain email addresses (without the mailto:)
+ * Added AbstractObjectCreationTest to make it quicker to write unit tests to verify
+ * NamedObjectBuilder/SignedNamedObject Pairs.
+ * Sample application has been expanded with a basic email application.
+ * Updated docs for sample web app.
+ * Added missing LGPL LICENSE.txt files to signer and sample app
+ *
* Revision 1.15 2003/12/10 23:58:52 pelle
* Did some cleaning up in the builders
***************
*** 115,118 ****
--- 124,128 ----
import org.neuclear.commons.Utility;
import org.neuclear.id.SignedNamedObject;
+ import org.neuclear.id.Identity;
import javax.mail.*;
***************
*** 123,129 ****
import java.util.Date;
import java.util.Properties;
public final class SmtpSender extends Sender {
! public final SignedNamedObject send(String endpoint, final SignedNamedObject obj) throws NeuClearException {
final Properties props = System.getProperties();
if (endpoint.startsWith("mailto:"))
--- 133,141 ----
import java.util.Date;
import java.util.Properties;
+ import java.util.regex.Pattern;
+ import java.util.regex.Matcher;
public final class SmtpSender extends Sender {
! public final SignedNamedObject send(String endpoint, final SignedNamedObject obj) throws NeuClearException,UnsupportedEndpointException {
final Properties props = System.getProperties();
if (endpoint.startsWith("mailto:"))
***************
*** 139,143 ****
// -- Set the FROM and TO fields --
! msg.setFrom(new InternetAddress("pe...@ne..."));// TODO Remove this hardcoded email
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(endpoint, false));
--- 151,155 ----
// -- Set the FROM and TO fields --
! msg.setFrom(new InternetAddress(getSender(obj)));// TODO Remove this hardcoded email
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(endpoint, false));
***************
*** 173,175 ****
--- 185,197 ----
return null;// We never receive a response
}
+
+ private String getSender(final SignedNamedObject obj) {
+ Identity senderid=obj.getSignatory();
+ final Matcher matcher = SENDER.matcher(senderid.getReceiver());
+ if (matcher.matches())
+ return matcher.group(2) ;
+ return "du...@ne...";
+ }
+ private static final Pattern SENDER = Pattern.compile("^(mailto:)([\\w-.]+\\@[\\w-.]+)");
+
}
|