[jboss-svn-commits] JBL Code SVN: r23429 - in labs/jbossesb/branches/JBESB_4_4_GA_CP/product: rosetta/src/org/jboss/internal/soa/esb/message/format/serialized and 10 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Oct 12 11:29:57 EDT 2008


Author: kevin.conner at jboss.com
Date: 2008-10-12 11:29:56 -0400 (Sun, 12 Oct 2008)
New Revision: 23429

Added:
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/message/ByReferenceMessage.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/message/tests/ContextUnitTest.java
Modified:
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/couriers/InVMCourier.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/ContextImpl.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/MessageImpl.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/CallImpl.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/ContextImpl.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/MessageImpl.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/XMLUtil.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/client/ServiceInvoker.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListener.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/message/Context.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/InVMListenerUnitTest.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipelineUnitTest.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/services/security/SecurityContextUnitTest.java
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/security_basic/src/org/jboss/soa/esb/samples/quickstart/securitybasic/test/SendEsbMessage.java
Log:
Add message context, handle invm by reference, move security to context: JBESB-2112

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/couriers/InVMCourier.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/couriers/InVMCourier.java	2008-10-10 15:52:16 UTC (rev 23428)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/couriers/InVMCourier.java	2008-10-12 15:29:56 UTC (rev 23429)
@@ -29,6 +29,7 @@
 import org.jboss.soa.esb.common.TransactionStrategy;
 import org.jboss.soa.esb.common.TransactionStrategyException;
 import org.jboss.soa.esb.couriers.CourierException;
+import org.jboss.soa.esb.message.ByReferenceMessage;
 import org.jboss.soa.esb.message.Message;
 
 import java.io.IOException;
@@ -160,6 +161,8 @@
                         logger.warn("Could not serialize message to pass by value.", ex);
                         return false;
                     }
+                } else if (message instanceof ByReferenceMessage){
+                    addedObject = ((ByReferenceMessage)message).reference() ;
                 } else {
                     addedObject = message;
                 }

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/ContextImpl.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/ContextImpl.java	2008-10-10 15:52:16 UTC (rev 23428)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/ContextImpl.java	2008-10-12 15:29:56 UTC (rev 23429)
@@ -1,5 +1,12 @@
 package org.jboss.internal.soa.esb.message.format.serialized;
 
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.internal.soa.esb.assertion.AssertArgument;
 import org.jboss.soa.esb.message.Context;
 
 /*
@@ -25,10 +32,89 @@
 
 public class ContextImpl implements Context, java.io.Serializable
 {
+    /**
+     * The context variables.
+     */
+    private Map<String, Serializable> context = new HashMap<String, Serializable>() ;
+    
+    /**
+     * Default constructor for the context.
+     */ 
+    public ContextImpl()
+    {
+    }
+    
+    /**
+     * Create a copy of the context.
+     * @param copy The context to copy.
+     */
+    ContextImpl(final ContextImpl copy)
+    {
+        context.putAll(copy.context) ;
+    }
+    
 	private static final long serialVersionUID = 0x0;
 	
 	public String toString ()
 	{
-		return "context: [  ]";
+		return "context: " + context ;
 	}
+	
+    /**
+     * Set the context value, replacing existing value if present.
+     * @param key The context key.
+     * @param value The context value.
+     * @return the previous value of the context or null if not set.
+     */
+    public Object setContext(final String key, final Object value)
+    {
+        AssertArgument.isNotNull(key, "key");
+        AssertArgument.isNotNull(value, "value");
+        
+        if (value instanceof Serializable)
+        {
+            return context.put(key, (Serializable)value) ;
+        }
+        else
+        {
+            throw new IllegalArgumentException("value must be serializable");
+        }
+    }
+    
+    /**
+     * Retrieves the context value.
+     * @param key The context key.
+     * @return The value or null if not present.
+     */
+    public Object getContext(final String key)
+    {
+        return context.get(key) ;
+    }
+    
+    /**
+     * Remove the context value.
+     * @param key The context key.
+     * @return The value of the context, or null if not present.
+     */
+    public Object removeContext(final String key)
+    {
+        return context.remove(key) ;
+    }
+    
+    /**
+     * Get the keys in the context.
+     * @return the context keys.
+     */
+    public Set<String> getContextKeys()
+    {
+        return Collections.unmodifiableSet(context.keySet()) ;
+    }
+    
+    /**
+     * Clear the context.
+     */
+    public void clearContext()
+    {
+        context = new HashMap<String, Serializable>() ;
+    }
 }
\ No newline at end of file

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/MessageImpl.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/MessageImpl.java	2008-10-10 15:52:16 UTC (rev 23428)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/serialized/MessageImpl.java	2008-10-12 15:29:56 UTC (rev 23429)
@@ -30,8 +30,10 @@
 import java.io.ObjectOutputStream;
 import java.net.URI;
 
+import org.jboss.soa.esb.addressing.Call;
 import org.jboss.soa.esb.message.Attachment;
 import org.jboss.soa.esb.message.Body;
+import org.jboss.soa.esb.message.ByReferenceMessage;
 import org.jboss.soa.esb.message.Context;
 import org.jboss.soa.esb.message.Fault;
 import org.jboss.soa.esb.message.Header;
@@ -61,7 +63,7 @@
  * 
  */
 
-public class MessageImpl implements Message, Externalizable
+public class MessageImpl implements ByReferenceMessage, Externalizable
 {
     private static final long serialVersionUID = 0x0;
 
@@ -75,6 +77,27 @@
 	_theProperties = new PropertiesImpl();
     }
 
+    private MessageImpl(final MessageImpl message)
+    {
+        // Header and context are not by reference.
+        _theHeader = new HeaderImpl() ;
+        final Call origCall = message._theHeader.getCall() ;
+        final Call call = new Call(origCall.getTo()) ;
+        call.setAction(origCall.getAction()) ;
+        call.setFaultTo(origCall.getFaultTo()) ;
+        call.setFrom(origCall.getFrom()) ;
+        call.setMessageID(origCall.getMessageID()) ;
+        call.setRelatesTo(origCall.getRelatesTo()) ;
+        call.setReplyTo(origCall.getReplyTo()) ;
+        _theHeader.setCall(call) ;
+        _theContext = new ContextImpl(message._theContext) ;
+        
+        _theBody = message._theBody ;
+        _theFault = message._theFault ;
+        _theAttachment = message._theAttachment ;
+        _theProperties = message._theProperties ;
+    }
+    
     /**
          * @return get the header component of the message.
          */
@@ -202,6 +225,16 @@
 	}
     }
 
+
+    /**
+     * Create the message used for pass by reference semantics.
+     * @return the referencable message.
+     */
+    public Message reference()
+    {
+        return new MessageImpl(this) ;
+    }
+
     // should be a capability on the base interface, but no changes for 4.2
         // ...
 

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/CallImpl.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/CallImpl.java	2008-10-10 15:52:16 UTC (rev 23428)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/CallImpl.java	2008-10-12 15:29:56 UTC (rev 23429)
@@ -21,7 +21,6 @@
 import org.jboss.soa.esb.addressing.EPR;
 import org.jboss.soa.esb.addressing.PortReference;
 import org.jboss.soa.esb.addressing.XMLUtil;
-import org.jboss.soa.esb.message.Context;
 /*
  * JBoss, Home of Professional Open Source
  * Copyright 2006, JBoss Inc., and others contributors as indicated 
@@ -42,7 +41,7 @@
  * (C) 2005-2006,
  */
 
-public class CallImpl extends ElementContent implements Context
+public class CallImpl extends ElementContent
 {
     /**
      * The call object associated with this type.

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/ContextImpl.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/ContextImpl.java	2008-10-10 15:52:16 UTC (rev 23428)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/ContextImpl.java	2008-10-12 15:29:56 UTC (rev 23429)
@@ -1,10 +1,22 @@
 package org.jboss.internal.soa.esb.message.format.xml;
 
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
 
+import org.jboss.internal.soa.esb.assertion.AssertArgument;
+import org.jboss.internal.soa.esb.util.Encoding;
 import org.jboss.internal.soa.esb.util.stax.ElementContent;
+import org.jboss.internal.soa.esb.util.stax.StreamHelper;
+import org.jboss.internal.soa.esb.util.stax.TextElement;
 import org.jboss.soa.esb.message.Context;
 
 /*
@@ -31,6 +43,11 @@
 public class ContextImpl extends ElementContent implements Context
 {
     /**
+     * The context variables.
+     */
+    private Map<String, SerializedValueImpl> context = new HashMap<String, SerializedValueImpl>() ;
+    
+    /**
      * Default constructor for the context.
      */ 
     public ContextImpl()
@@ -38,6 +55,15 @@
     }
     
     /**
+     * Create a copy of the context.
+     * @param copy The context to copy.
+     */
+    ContextImpl(final ContextImpl copy)
+    {
+        context.putAll(copy.context) ;
+    }
+    
+    /**
      * Construct a context from the input stream.
      * 
      * @param in The input stream.
@@ -51,17 +77,129 @@
     
     public String toString ()
     {
-        return "context: [  ]";
+        return "context: " + context ;
     }
     
     /**
+     * Set the context value, replacing existing value if present.
+     * @param key The context key.
+     * @param value The context value.
+     * @return the previous value of the context or null if not set.
+     */
+    public Object setContext(final String key, final Object value)
+    {
+        AssertArgument.isNotNull(key, "key");
+        AssertArgument.isNotNull(value, "value");
+        
+        if (value instanceof Serializable)
+        {
+            return unwrap(context.put(key, new SerializedValueImpl((Serializable)value))) ;
+        }
+        else
+        {
+            throw new IllegalArgumentException("value must be serializable");
+        }
+    }
+    
+    /**
+     * Retrieves the context value.
+     * @param key The context key.
+     * @return The value or null if not present.
+     */
+    public Object getContext(final String key)
+    {
+        return unwrap(context.get(key)) ;
+    }
+    
+    /**
+     * Remove the context value.
+     * @param key The context key.
+     * @return The value of the context, or null if not present.
+     */
+    public Object removeContext(final String key)
+    {
+        return unwrap(context.remove(key)) ;
+    }
+    
+    /**
+     * Get the keys in the context.
+     * @return the context keys.
+     */
+    public Set<String> getContextKeys()
+    {
+        return Collections.unmodifiableSet(context.keySet()) ;
+    }
+    
+    /**
+     * Clear the context.
+     */
+    public void clearContext()
+    {
+        context = new HashMap<String, SerializedValueImpl>() ;
+    }
+    
+    /**
+     * Write the child content of the element.
+     * @param out The output stream.
+     * @throws XMLStreamException For errors during output.
+     */
+    @Override
+    protected void writeChildContent(XMLStreamWriter out)
+        throws XMLStreamException
+    {
+        for (Entry<String, SerializedValueImpl> entry: context.entrySet())
+        {
+            final String origPropertyURI = StreamHelper.writeStartElement(out, XMLUtil.ESB_QNAME_CONTEXT_ENTRY) ;
+            
+            final TextElement keyElement = new TextElement(Encoding.encodeBytes(entry.getKey().getBytes())) ;
+            StreamHelper.writeElement(out, XMLUtil.ESB_QNAME_CONTEXT_ENTRY_KEY, keyElement) ;
+            
+            final String value = entry.getValue().getSerialisedForm() ;
+            final TextElement valueElement = new TextElement(value) ;
+            StreamHelper.writeElement(out, XMLUtil.ESB_QNAME_CONTEXT_ENTRY_VALUE, valueElement) ;
+            
+            StreamHelper.writeEndElement(out, XMLUtil.ESB_QNAME_CONTEXT_ENTRY.getPrefix(), origPropertyURI) ;
+        }
+    }
+
+    /**
      * Add the element.
      * @param in The current input stream.
      * @param elementName The qualified element name.
+     * @throws XMLStreamException For errors during parsing.
      */
-    protected void putElement(final XMLStreamReader in, final QName elementName)
+    @Override
+    protected void putElement(final XMLStreamReader in,
+        final QName elementName)
         throws XMLStreamException
     {
-        throw new XMLStreamException("Unexpected element name: " + elementName) ;
+        if (XMLUtil.ESB_QNAME_CONTEXT_ENTRY.equals(elementName))
+        {
+            StreamHelper.checkNextStartTag(in, XMLUtil.ESB_QNAME_CONTEXT_ENTRY_KEY) ;
+            final TextElement keyElement = new TextElement(in) ;
+            final String key = new String(Encoding.decodeToBytes(keyElement.getText())) ;
+            
+            StreamHelper.checkNextStartTag(in, XMLUtil.ESB_QNAME_CONTEXT_ENTRY_VALUE) ;
+            final TextElement valueElement = new TextElement(in) ;
+            final SerializedValueImpl value = new SerializedValueImpl(valueElement.getText()) ;
+            
+            StreamHelper.checkParentFinished(in) ;
+            
+            context.put(key, value) ;
+        }
+        else
+        {
+            throw new XMLStreamException("Unexpected element name: " + elementName) ;
+        }
     }
+    
+    /**
+     * Unwrap the serialised value.
+     * @param value The serialised value.
+     * @return The unwrapped value.
+     */
+    private Object unwrap(final SerializedValueImpl value)
+    {
+        return (value == null ? null : value.getValue()) ;
+    }
 }
\ No newline at end of file

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/MessageImpl.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/MessageImpl.java	2008-10-10 15:52:16 UTC (rev 23428)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/MessageImpl.java	2008-10-12 15:29:56 UTC (rev 23429)
@@ -31,8 +31,10 @@
 
 import org.jboss.internal.soa.esb.util.stax.ElementContent;
 import org.jboss.internal.soa.esb.util.stax.StreamHelper;
+import org.jboss.soa.esb.addressing.Call;
 import org.jboss.soa.esb.message.Attachment;
 import org.jboss.soa.esb.message.Body;
+import org.jboss.soa.esb.message.ByReferenceMessage;
 import org.jboss.soa.esb.message.Context;
 import org.jboss.soa.esb.message.Fault;
 import org.jboss.soa.esb.message.Header;
@@ -65,7 +67,7 @@
  * 
  */
 
-public class MessageImpl extends ElementContent implements Message
+public class MessageImpl extends ElementContent implements ByReferenceMessage
 {
 	public MessageImpl()
 	{
@@ -77,6 +79,26 @@
 		_theProperties = new PropertiesImpl();
 	}
 	
+	private MessageImpl(final MessageImpl message)
+	{
+		// Header and context are not by reference.
+		_theHeader = new HeaderImpl() ;
+		final Call origCall = message._theHeader.getCall() ;
+		final Call call = new Call(origCall.getTo()) ;
+		call.setAction(origCall.getAction()) ;
+		call.setFaultTo(origCall.getFaultTo()) ;
+		call.setFrom(origCall.getFrom()) ;
+		call.setMessageID(origCall.getMessageID()) ;
+		call.setRelatesTo(origCall.getRelatesTo()) ;
+		call.setReplyTo(origCall.getReplyTo()) ;
+		_theHeader.setCall(call) ;
+		_theContext = new ContextImpl(message._theContext) ;
+		
+		_theBody = message._theBody ;
+		_theFault = message._theFault ;
+		_theAttachment = message._theAttachment ;
+		_theProperties = message._theProperties ;
+	}
         /**
          * Construct a message from the input stream.
          * 
@@ -244,6 +266,15 @@
             }
         }
 
+        /**
+         * Create the message used for pass by reference semantics.
+         * @return the referencable message.
+         */
+        public Message reference()
+        {
+            return new MessageImpl(this) ;
+        }
+
 	// should be a capability on the base interface, but no changes for 4.2
 	// ...
 

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/XMLUtil.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/XMLUtil.java	2008-10-10 15:52:16 UTC (rev 23428)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/message/format/xml/XMLUtil.java	2008-10-12 15:29:56 UTC (rev 23429)
@@ -60,6 +60,30 @@
      */
     public static final QName ESB_QNAME_CONTEXT = new QName(ESB_ELEMENT_CONTEXT) ;
     /**
+     * The name of the context entry element.
+     */
+    public static final String ESB_ELEMENT_CONTEXT_ENTRY = "ContextEntry" ;
+    /**
+     * The qualified name of the context entry element.
+     */
+    public static final QName ESB_QNAME_CONTEXT_ENTRY = new QName(ESB_ELEMENT_CONTEXT_ENTRY) ;
+    /**
+     * The name of the context entry key element.
+     */
+    public static final String ESB_ELEMENT_CONTEXT_ENTRY_KEY = "ContextKey" ;
+    /**
+     * The qualified name of the context entry key element.
+     */
+    public static final QName ESB_QNAME_CONTEXT_ENTRY_KEY = new QName(ESB_ELEMENT_CONTEXT_ENTRY_KEY) ;
+    /**
+     * The name of the context entry value element.
+     */
+    public static final String ESB_ELEMENT_CONTEXT_ENTRY_VALUE = "ContextValue" ;
+    /**
+     * The qualified name of the context entry value element.
+     */
+    public static final QName ESB_QNAME_CONTEXT_ENTRY_VALUE = new QName(ESB_ELEMENT_CONTEXT_ENTRY_VALUE) ;
+    /**
      * The name of the body element.
      */
     public static final String ESB_ELEMENT_BODY = "Body" ;

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/client/ServiceInvoker.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/client/ServiceInvoker.java	2008-10-10 15:52:16 UTC (rev 23428)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/client/ServiceInvoker.java	2008-10-12 15:29:56 UTC (rev 23429)
@@ -330,7 +330,7 @@
                         try
                         {
                 			byte[] encrypted = PrivateCryptoUtil.INSTANCE.encrypt(new SecurityContext(subject));
-                    	    message.getProperties().setProperty(SecurityService.CONTEXT, encrypted);
+                    	    message.getContext().setContext(SecurityService.CONTEXT, encrypted);
                         }
                         catch (final SecurityServiceException e)
                         {
@@ -341,7 +341,7 @@
 	                replyMessage = eprInvoker.attemptDelivery(message, epr);
 	                if (replyMessage != null) {
                         // remove the security context so that it is not exposed to the action pipeline.
-                        replyMessage.getProperties().remove(SecurityService.CONTEXT);
+                        replyMessage.getContext().removeContext(SecurityService.CONTEXT);
 
                         if (Type.isFaultMessage(replyMessage)) {
                             Factory.createExceptionFromFault(replyMessage) ;

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListener.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListener.java	2008-10-10 15:52:16 UTC (rev 23428)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListener.java	2008-10-12 15:29:56 UTC (rev 23429)
@@ -527,7 +527,7 @@
                     try {
                         byte[] encrypted = PublicCryptoUtil.INSTANCE.encrypt((Serializable) authRequest);
                         if (encrypted != null) {
-                            message.getProperties().setProperty(SecurityService.AUTH_REQUEST, encrypted);
+                            message.getContext().setContext(SecurityService.AUTH_REQUEST, encrypted);
                         } else {
                             logger.warn("No public keystore has been configured which means that the authentication request cannot be encrypted. Please configure jbossesb-properties.xml with a publickey store.");
                         }

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java	2008-10-10 15:52:16 UTC (rev 23428)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java	2008-10-12 15:29:56 UTC (rev 23429)
@@ -374,7 +374,7 @@
 			try
             {
 			    // Check if a encrypted SecurityContext was passed with the Message to this service.
-                securityContext = SecurityContext.decryptContext((byte[])message.getProperties().getProperty(SecurityService.CONTEXT));
+                securityContext = SecurityContext.decryptContext((byte[])message.getContext().getContext(SecurityService.CONTEXT));
             }
 			catch (final SecurityServiceException e)
             {
@@ -423,7 +423,7 @@
     		        securityContext = new SecurityContext();
 
         			// 	get the authentication request from the message
-            		byte[] encrypted = (byte[]) message.getProperties().getProperty(SecurityService.AUTH_REQUEST);
+            		byte[] encrypted = (byte[]) message.getContext().getContext(SecurityService.AUTH_REQUEST);
             		if (encrypted == null)
             		{
             		   throw new SecurityServiceException("Missing AuthenticationRequest. Cannot be authenticated.");
@@ -461,8 +461,8 @@
 		finally
 		{
 		    // always remove the security context
-    		message.getProperties().remove(SecurityService.CONTEXT);
-    		message.getProperties().remove(SecurityService.AUTH_REQUEST);
+    		message.getContext().removeContext(SecurityService.CONTEXT);
+    		message.getContext().removeContext(SecurityService.AUTH_REQUEST);
 		}
 
 		// the work to be performed in the context of the authenticated caller

Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/message/ByReferenceMessage.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/message/ByReferenceMessage.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/message/ByReferenceMessage.java	2008-10-12 15:29:56 UTC (rev 23429)
@@ -0,0 +1,41 @@
+package org.jboss.soa.esb.message;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+
+/**
+ * This interface extends the generic Message interface to provide a mechanism
+ * whereby implementations can take control over pass by value messaging.
+ * The implementation will be provided with an opportunity to create the
+ * reference message.
+ *
+ * @author <a href='mailto:kevin.conner at jboss.com'>Kevin Conner</a>
+ */
+
+public interface ByReferenceMessage extends Message
+{
+    /**
+     * Create the message used for pass by reference semantics.
+     * @return the referencable message.
+     */
+    public Message reference() ;
+}


Property changes on: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/message/ByReferenceMessage.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/message/Context.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/message/Context.java	2008-10-10 15:52:16 UTC (rev 23428)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/message/Context.java	2008-10-12 15:29:56 UTC (rev 23429)
@@ -1,5 +1,7 @@
 package org.jboss.soa.esb.message;
 
+import java.util.Set;
+
 /*
  * JBoss, Home of Professional Open Source
  * Copyright 2006, JBoss Inc., and others contributors as indicated 
@@ -25,9 +27,42 @@
  * The context is the section of the message containing information such as session
  * management, transaction information, security data etc. Entries in the context
  * may be ordered.
+ * 
+ * This section should never be passed by reference.
  */
 
 public interface Context
 {
-	// TODO add some methods!
+    /**
+     * Set the context value, replacing existing value if present.
+     * @param key The context key.
+     * @param value The context value.
+     * @return the previous value of the context or null if not set.
+     */
+    public Object setContext(final String key, final Object value) ;
+    
+    /**
+     * Retrieves the context value.
+     * @param key The context key.
+     * @return The value or null if not present.
+     */
+    public Object getContext(final String key) ;
+    
+    /**
+     * Remove the context value.
+     * @param key The context key.
+     * @return The value of the context, or null if not present.
+     */
+    public Object removeContext(final String key) ;
+    
+    /**
+     * Get the keys in the context.
+     * @return the context keys.
+     */
+    public Set<String> getContextKeys() ;
+    
+    /**
+     * Clear the context.
+     */
+    public void clearContext() ;
 }
\ No newline at end of file

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/InVMListenerUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/InVMListenerUnitTest.java	2008-10-10 15:52:16 UTC (rev 23428)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/InVMListenerUnitTest.java	2008-10-12 15:29:56 UTC (rev 23429)
@@ -65,7 +65,7 @@
                 invoker.deliverAsync(message);
 
                 waitForMockSet(message);
-                assertTrue(message == MockAction.message);
+                assertTrue("Message equality", checkMessageEquality(message, MockAction.message));
             }
         }.setServiceConfig("in-listener-config-01.xml");
 
@@ -104,8 +104,8 @@
                 message.getBody().add("Hi there!");
                 Message response = invoker.deliverSync(message, 2000);
 
-                assertTrue(message == MockAction.message);
-                assertTrue(message == response);
+                assertTrue("Message equality", checkMessageEquality(message, MockAction.message));
+                assertTrue("Message equality", checkMessageEquality(message, response));
             }
         }.setServiceConfig("in-listener-config-01.xml");
 
@@ -229,7 +229,7 @@
                     } catch (Exception e) {
                         fail("Error delivering message: " + e.getMessage());
                     }
-                    assertTrue(message == response);
+                    assertTrue("Message equality", checkMessageEquality(message, response));
                     assertEquals("Tom Fennelly", response.getBody().get());
 
                     InVMListenerUnitTest.sleep(10);
@@ -252,14 +252,14 @@
         invoker.deliverAsync(message);
 
         waitForMockSet(message);
-        assertTrue(message == MockAction.message);
+        assertTrue("Message equality", checkMessageEquality(message, MockAction.message));
     }
 
     private void waitForMockSet(Message message) {
         long start = System.currentTimeMillis();
 
         while(System.currentTimeMillis() - start < 5000) {
-            if(message == MockAction.message) {
+            if(checkMessageEquality(message, MockAction.message)) {
                 return;
             }
             sleep(50);
@@ -273,4 +273,12 @@
             fail("Unexpected InterruptedException exception.");
         }
     }
+    
+    private static boolean checkMessageEquality(final Message expected, final Message actual) {
+        return (actual != null) && (expected.getAttachment().equals(actual.getAttachment())) &&
+            (expected.getBody().equals(actual.getBody())) &&
+            (expected.getFault().equals(actual.getFault())) &&
+            (expected.getProperties().equals(actual.getProperties())) &&
+            (expected.getType().equals(actual.getType())) ;
+    }
 }
\ No newline at end of file

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipelineUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipelineUnitTest.java	2008-10-10 15:52:16 UTC (rev 23428)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipelineUnitTest.java	2008-10-12 15:29:56 UTC (rev 23429)
@@ -465,7 +465,7 @@
 
         //  create an AuthenticationRequest which is needed to authenticate if the security
         AuthenticationRequest build = new AuthenticationRequestImpl.Builder().build();
-        message.getProperties().setProperty(SecurityService.AUTH_REQUEST, PublicCryptoUtil.INSTANCE.encrypt((Serializable) build));
+        message.getContext().setContext(SecurityService.AUTH_REQUEST, PublicCryptoUtil.INSTANCE.encrypt((Serializable) build));
 
         final boolean result = pipeline.process(message);
         assertTrue(result);
@@ -534,14 +534,14 @@
         SecurityContext securityContext = new SecurityContext(subject);
         byte[] encrypt = SecurityContext.encryptContext(securityContext);
 
-        message.getProperties().setProperty(SecurityService.CONTEXT, encrypt);
+        message.getContext().setContext(SecurityService.CONTEXT, encrypt);
 
         final boolean result = pipeline.process(message);
 
         assertTrue(result);
         assertEquals(user, MockSecuredActionProcessor.getSubject().getPrincipals().iterator().next());
 
-        assertNull(message.getProperties().getProperty(SecurityService.CONTEXT));
+        assertNull(message.getContext().getContext(SecurityService.CONTEXT));
 
         pipeline.destroy() ;
         checkOrder(MockActionInfo.getDestroyList()) ;
@@ -571,7 +571,7 @@
         SecurityContext securityContext = new SecurityContext(subject);
         byte[] encrypt = SecurityContext.encryptContext(securityContext);
 
-        message.getProperties().setProperty(SecurityService.CONTEXT, encrypt);
+        message.getContext().setContext(SecurityService.CONTEXT, encrypt);
 
         try
         {

Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/message/tests/ContextUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/message/tests/ContextUnitTest.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/message/tests/ContextUnitTest.java	2008-10-12 15:29:56 UTC (rev 23429)
@@ -0,0 +1,141 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.message.tests;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.net.URI;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.message.ByReferenceMessage;
+import org.jboss.soa.esb.message.Context;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.jboss.soa.esb.util.Util;
+
+/**
+ * Unit tests for the Context class.
+ * 
+ * @author <a href='mailto:kevin.conner at jboss.com'>Kevin Conner</a>
+ */
+
+public class ContextUnitTest extends TestCase
+{
+    public void testSerializeMessage()
+        throws Exception
+    {
+        execute(MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED)) ;
+    }
+    
+    public void testXMLMessage()
+        throws Exception
+    {
+        execute(MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML)) ;
+    }
+    
+    private void execute(final Message message)
+        throws Exception
+    {
+        assertNotNull("Created message", message) ;
+        message.getHeader().getCall().setTo(new EPR(new URI("test:to_uri"))) ;
+        
+        final Context context = message.getContext() ;
+        assertNotNull("Context", context) ;
+        
+        final Object result1 = context.setContext("foo", "bar") ;
+        assertNull("First setter result", result1) ;
+        
+        assertEquals("Getting context", "bar", context.getContext("foo")) ;
+        
+        final Set<String> keys = context.getContextKeys() ;
+        assertNotNull("Context keys", keys) ;
+        assertEquals("Context key count", 1, keys.size()) ;
+        assertTrue("Contains key", keys.contains("foo")) ;
+        
+        final Object result2 = context.setContext("foo", "bar2") ;
+        assertEquals("Second setter result", "bar", result2) ;
+        
+        assertEquals("Getting context", "bar2", context.getContext("foo")) ;
+        
+        final Set<String> keys2 = context.getContextKeys() ;
+        assertNotNull("Context keys2", keys2) ;
+        assertEquals("Context key count", 1, keys2.size()) ;
+        assertTrue("Contains key", keys2.contains("foo")) ;
+        
+        context.clearContext() ;
+        
+        final Set<String> keys3 = context.getContextKeys() ;
+        assertNotNull("Context keys3", keys3) ;
+        assertEquals("Context key count", 0, keys3.size()) ;
+        
+        try
+        {
+            context.setContext("non-serializable", new Object()) ;
+            fail("Non serializable object set on context");
+        }
+        catch (IllegalArgumentException ex) {} // expected
+        
+        context.setContext("skey", "svalue") ;
+        final Serializable serializable = Util.serialize(message) ;
+        final ByteArrayOutputStream baos = new ByteArrayOutputStream() ;
+        final ObjectOutputStream oos = new ObjectOutputStream(baos) ;
+        
+        oos.writeObject(serializable);
+        oos.close();
+        
+        final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()) ;
+        final ObjectInputStream ois = new ObjectInputStream(bais) ;
+        
+        final Serializable newSerializable = (Serializable)ois.readObject() ;
+        final Message newMessage = Util.deserialize(newSerializable) ;
+        assertEquals("Serialized context", "svalue", newMessage.getContext().getContext("skey")) ;
+        
+        assertTrue("Implements ByReferenceMessage", (message instanceof ByReferenceMessage)) ;
+        
+        final Message referencedMessage = ((ByReferenceMessage)message).reference() ;
+        assertSame("Attachment is same", message.getAttachment(), referencedMessage.getAttachment()) ;
+        assertSame("Body is same", message.getBody(), referencedMessage.getBody()) ;
+        assertSame("Fault is same", message.getFault(), referencedMessage.getFault()) ;
+        assertSame("Properties are same", message.getProperties(), referencedMessage.getProperties()) ;
+        assertSame("type is same", message.getType(), referencedMessage.getType()) ;
+        
+        assertNotSame("header is not same", message.getHeader(), referencedMessage.getHeader()) ;
+        assertNotSame("Context is not same", context, referencedMessage.getContext()) ;
+        
+        assertEquals("Header equals", message.getHeader().getCall().getTo(), referencedMessage.getHeader().getCall().getTo()) ;
+        message.getHeader().getCall().setTo(new EPR(new URI("test:to_uri2"))) ;
+        assertFalse("Header not equals", message.getHeader().getCall().getTo().equals(referencedMessage.getHeader().getCall().getTo())) ;
+        
+        assertEquals("Context equals", context.getContext("skey"), referencedMessage.getContext().getContext("skey")) ;
+        context.setContext("skey", "other value") ;
+        assertFalse("Context not equals", context.getContext("skey").equals(referencedMessage.getContext().getContext("skey"))) ;
+        assertEquals("Referenced Context unchanged", "svalue", referencedMessage.getContext().getContext("skey")) ;
+    }
+}


Property changes on: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/message/tests/ContextUnitTest.java
___________________________________________________________________
Name: svn:keywords
   + Rev Date
Name: svn:eol-style
   + native

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/services/security/SecurityContextUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/services/security/SecurityContextUnitTest.java	2008-10-10 15:52:16 UTC (rev 23428)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/services/security/SecurityContextUnitTest.java	2008-10-12 15:29:56 UTC (rev 23429)
@@ -117,7 +117,7 @@
         SecurityContext securityContext = new SecurityContext(subject);
         Message message = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
         byte[] encryptContext = SecurityContext.encryptContext(securityContext);
-        message.getProperties().setProperty(SecurityService.CONTEXT, encryptContext);
+        message.getContext().setContext(SecurityService.CONTEXT, encryptContext);
 
 
         //  serialize object
@@ -133,7 +133,7 @@
         //  assert that the content is still matches.
         assertTrue (readObject instanceof Message);
         Message deserializedMsg = (Message) readObject;
-        SecurityContext deserialized = SecurityContext.decryptContext((byte[]) deserializedMsg.getProperties().getProperty(SecurityService.CONTEXT));
+        SecurityContext deserialized = SecurityContext.decryptContext((byte[]) deserializedMsg.getContext().getContext(SecurityService.CONTEXT));
         assertEquals( user, deserialized.getSubject().getPrincipals().iterator().next() );
         //assertEquals( new String(publicCred), new String((byte[])deserialized.getPubCredentials().iterator().next()));
         assertEquals( new String(publicCred), new String((byte[])deserialized.getSubject().getPublicCredentials().iterator().next()));

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/security_basic/src/org/jboss/soa/esb/samples/quickstart/securitybasic/test/SendEsbMessage.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/security_basic/src/org/jboss/soa/esb/samples/quickstart/securitybasic/test/SendEsbMessage.java	2008-10-10 15:52:16 UTC (rev 23428)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/samples/quickstarts/security_basic/src/org/jboss/soa/esb/samples/quickstart/securitybasic/test/SendEsbMessage.java	2008-10-12 15:29:56 UTC (rev 23429)
@@ -63,7 +63,7 @@
 		AuthenticationRequest authRequest = new AuthenticationRequestImpl.Builder().username(args[3]).password(args[4].toCharArray()).build();
 		
 		// 	set the authentication request on the message
-		esbMessage.getProperties().setProperty(SecurityService.AUTH_REQUEST, PublicCryptoUtil.INSTANCE.encrypt((Serializable) authRequest));
+		esbMessage.getContext().setContext(SecurityService.AUTH_REQUEST, PublicCryptoUtil.INSTANCE.encrypt((Serializable) authRequest));
 		
         final String message = args[2];
         esbMessage.getBody().add(message);




More information about the jboss-svn-commits mailing list