You are viewing a plain text version of this content. The canonical link for it is here.
Posted to sandesha-dev@ws.apache.org by ch...@apache.org on 2006/06/15 07:51:24 UTC

svn commit: r414476 [9/15] - in /webservices/sandesha/trunk: ./ c/ config/ interop/ java/ java/config/ java/interop/ java/interop/conf/ java/interop/src/ java/interop/src/org/ java/interop/src/org/apache/ java/interop/src/org/apache/sandesha2/ java/int...

Added: webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/RMMsgCreator.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/RMMsgCreator.java?rev=414476&view=auto
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/RMMsgCreator.java (added)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/RMMsgCreator.java Wed Jun 14 22:51:15 2006
@@ -0,0 +1,721 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ *  
+ */
+
+package org.apache.sandesha2.util;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.OperationContext;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisOperationFactory;
+import org.apache.axis2.description.Parameter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.sandesha2.RMMsgContext;
+import org.apache.sandesha2.Sandesha2Constants;
+import org.apache.sandesha2.SandeshaException;
+import org.apache.sandesha2.client.SandeshaClientConstants;
+import org.apache.sandesha2.storage.StorageManager;
+import org.apache.sandesha2.storage.beanmanagers.SequencePropertyBeanMgr;
+import org.apache.sandesha2.storage.beans.SequencePropertyBean;
+import org.apache.sandesha2.wsrm.Accept;
+import org.apache.sandesha2.wsrm.AckFinal;
+import org.apache.sandesha2.wsrm.AcknowledgementRange;
+import org.apache.sandesha2.wsrm.AcksTo;
+import org.apache.sandesha2.wsrm.Address;
+import org.apache.sandesha2.wsrm.CloseSequence;
+import org.apache.sandesha2.wsrm.CloseSequenceResponse;
+import org.apache.sandesha2.wsrm.CreateSequence;
+import org.apache.sandesha2.wsrm.CreateSequenceResponse;
+import org.apache.sandesha2.wsrm.IOMRMElement;
+import org.apache.sandesha2.wsrm.Identifier;
+import org.apache.sandesha2.wsrm.SequenceAcknowledgement;
+import org.apache.sandesha2.wsrm.SequenceOffer;
+import org.apache.sandesha2.wsrm.TerminateSequence;
+import org.apache.sandesha2.wsrm.TerminateSequenceResponse;
+
+/**
+ * Used to create new RM messages.
+ * 
+ * @author Chamikara Jayalath <ch...@gmail.com>
+ */
+
+public class RMMsgCreator {
+
+	private static Log log = LogFactory.getLog(RMMsgCreator.class);
+
+	private static void initializeCreation(MessageContext relatedMessage,
+			MessageContext newMessage) throws SandeshaException {
+		
+		if (relatedMessage.getAxisService()!=null &&  newMessage.getAxisService()!=null && 
+				newMessage.getAxisService()!=relatedMessage.getAxisService()) {
+			
+			Parameter referencePolicyParam = relatedMessage.getAxisService().getParameter(Sandesha2Constants.SANDESHA_PROPERTY_BEAN);
+			if (referencePolicyParam!=null) {
+				Parameter newPolicyParam = new Parameter ();
+				newPolicyParam.setName(Sandesha2Constants.SANDESHA_PROPERTY_BEAN);
+				newPolicyParam.setValue(newPolicyParam.getValue());
+			}
+		}
+		
+		if (relatedMessage.getAxisOperation()!=null &&  newMessage.getAxisOperation()!=null && 
+				newMessage.getAxisOperation()!=relatedMessage.getAxisOperation()) {
+			
+			Parameter referencePolicyParam = relatedMessage.getAxisOperation().getParameter(Sandesha2Constants.SANDESHA_PROPERTY_BEAN);
+			if (referencePolicyParam!=null) {
+				Parameter newPolicyParam = new Parameter ();
+				newPolicyParam.setName(Sandesha2Constants.SANDESHA_PROPERTY_BEAN);
+				newPolicyParam.setValue(newPolicyParam.getValue());
+			}
+		}
+	}
+
+	private static void finalizeCreation(MessageContext relatedMessage,
+			MessageContext newMessage) throws SandeshaException {
+
+		newMessage.setServerSide(relatedMessage.isServerSide());
+
+		// adding all parameters from old message to the new one.
+		try {
+			// axisOperation parameters
+			AxisOperation oldAxisOperation = relatedMessage.getAxisOperation();
+			if (oldAxisOperation != null) {
+				ArrayList axisOpParams = oldAxisOperation.getParameters();
+				if (axisOpParams != null) {
+					AxisOperation newAxisOperation = newMessage
+							.getAxisOperation();
+					Iterator iter = axisOpParams.iterator();
+					while (iter.hasNext()) {
+						Parameter nextParam = (Parameter) iter.next();
+						Parameter newParam = new Parameter();
+
+						newParam.setName(nextParam.getName());
+						newParam.setValue(nextParam.getValue());
+
+						newAxisOperation.addParameter(newParam);
+					}
+				}
+			}
+
+		} catch (AxisFault e) {
+			log.error("Could not copy parameters when creating the new RM Message");
+			throw new SandeshaException(e.getMessage());
+		}		
+		
+		// TODO optimize by cloning the Map rather than copying one by one.
+
+		// operationContext properties
+		OperationContext oldOpContext = relatedMessage.getOperationContext();
+		if (oldOpContext != null) {
+			Map oldOpContextProperties = oldOpContext.getProperties();
+			if (oldOpContextProperties != null) {
+				OperationContext newOpContext = newMessage
+						.getOperationContext();
+				Iterator keyIter = oldOpContextProperties.keySet().iterator();
+				while (keyIter.hasNext()) {
+					String key = (String) keyIter.next();
+					newOpContext.setProperty(key, oldOpContextProperties
+							.get(key));
+				}
+			}
+		}
+
+		// MessageContext properties
+		if (relatedMessage != null && newMessage != null) {
+			Map oldMsgContextProperties = relatedMessage.getProperties();
+			if (oldMsgContextProperties != null) {
+				Iterator keyIter = oldMsgContextProperties.keySet().iterator();
+				while (keyIter.hasNext()) {
+					String key = (String) keyIter.next();
+					newMessage.setProperty(key, oldMsgContextProperties
+							.get(key));
+				}
+			}
+		}
+		
+		// setting an options with properties copied from the old one.
+		Options relatesMessageOptions = relatedMessage.getOptions();
+		if (relatesMessageOptions != null) {
+			Options newMessageOptions = newMessage.getOptions();
+			if (newMessageOptions == null) {
+				newMessageOptions = new Options();
+				newMessage.setOptions(newMessageOptions);
+			}
+			
+
+			Map relatedMessageProperties = relatesMessageOptions
+					.getProperties();
+			Iterator keys = relatedMessageProperties.keySet().iterator();
+			while (keys.hasNext()) {
+				String key = (String) keys.next();
+				newMessageOptions.setProperty(key, relatedMessageProperties
+						.get(key));
+			}
+
+			Options relatedMessageParentOptions = relatesMessageOptions
+					.getParent();
+			if (relatedMessageParentOptions != null) {
+				Map relatedMessageParentProperties = relatedMessageParentOptions.getProperties();
+				keys = relatedMessageParentProperties.keySet().iterator();
+				while (keys.hasNext()) {
+					String key = (String) keys.next();
+					newMessageOptions.setProperty(key,
+							relatedMessageParentProperties.get(key));
+				}
+			}
+		}
+	}
+
+	/**
+	 * Create a new CreateSeqnence message.
+	 * 
+	 * @param applicationRMMsg
+	 * @param internalSequenceId
+	 * @param acksTo
+	 * @return
+	 * @throws SandeshaException
+	 */
+	public static RMMsgContext createCreateSeqMsg(
+			RMMsgContext applicationRMMsg, String internalSequenceId,
+			String acksTo,StorageManager storageManager) throws SandeshaException {
+
+		MessageContext applicationMsgContext = applicationRMMsg
+				.getMessageContext();
+		if (applicationMsgContext == null)
+			throw new SandeshaException("Application message is null");
+		ConfigurationContext context = applicationMsgContext
+				.getConfigurationContext();
+		if (context == null)
+			throw new SandeshaException("Configuration Context is null");
+
+		SOAPFactory factory = SOAPAbstractFactory.getSOAPFactory(SandeshaUtil
+				.getSOAPVersion(applicationMsgContext.getEnvelope()));
+
+		SequencePropertyBeanMgr seqPropMgr = storageManager
+				.getSequencePropretyBeanMgr();
+		MessageContext createSeqmsgContext;
+		try {
+			// creating by copying common contents. (this will not set contexts
+			// except for configCtx).
+			AxisOperation createSequenceOperation = AxisOperationFactory
+					.getAxisOperation(AxisOperation.MEP_CONSTANT_OUT_IN);
+
+			createSeqmsgContext = SandeshaUtil.createNewRelatedMessageContext(
+					applicationRMMsg, createSequenceOperation);
+
+			initializeCreation(applicationMsgContext, createSeqmsgContext);
+
+			OperationContext createSeqOpCtx = createSeqmsgContext
+					.getOperationContext();
+			String createSeqMsgId = SandeshaUtil.getUUID();
+			createSeqmsgContext.setMessageID(createSeqMsgId);
+			context.registerOperationContext(createSeqMsgId, createSeqOpCtx);
+
+		} catch (AxisFault e) {
+			throw new SandeshaException(e.getMessage());
+		}
+
+		AxisOperation appMsgOperationDesc = applicationMsgContext
+				.getAxisOperation();
+
+		AxisOperation createSeqOperation = createSeqmsgContext
+				.getAxisOperation();
+		
+		createSeqOperation.setName(new QName("CreateSequenceOperation"));
+		if (appMsgOperationDesc != null) {
+			createSeqOperation.setPhasesOutFlow(appMsgOperationDesc
+					.getPhasesOutFlow());
+			createSeqOperation.setPhasesOutFaultFlow(appMsgOperationDesc
+					.getPhasesOutFaultFlow());
+			createSeqOperation.setPhasesInFaultFlow(appMsgOperationDesc
+					.getPhasesInFaultFlow());
+			createSeqOperation.setRemainingPhasesInFlow(appMsgOperationDesc
+					.getRemainingPhasesInFlow());
+		}
+
+		createSeqmsgContext.setAxisOperation(createSeqOperation);
+
+		createSeqmsgContext.setTo(applicationRMMsg.getTo());
+		createSeqmsgContext.setReplyTo(applicationRMMsg.getReplyTo());
+
+		RMMsgContext createSeqRMMsg = new RMMsgContext(createSeqmsgContext);
+
+		String rmVersion = SandeshaUtil.getRMVersion(internalSequenceId,storageManager);
+		if (rmVersion==null)
+			throw new SandeshaException ("Cant find the rmVersion of the given message");
+		
+		String rmNamespaceValue = SpecSpecificConstants.getRMNamespaceValue(rmVersion);
+		
+		String addressingNamespaceValue = SandeshaUtil.getSequenceProperty(internalSequenceId,Sandesha2Constants.SequenceProperties.ADDRESSING_NAMESPACE_VALUE,storageManager);
+		
+		CreateSequence createSequencePart = new CreateSequence(factory,rmNamespaceValue,addressingNamespaceValue);
+
+		// Adding sequence offer - if present
+		OperationContext operationcontext = applicationMsgContext
+				.getOperationContext();
+		if (operationcontext != null) {
+			String offeredSequence = (String) applicationMsgContext
+					.getProperty(SandeshaClientConstants.OFFERED_SEQUENCE_ID);
+			if (offeredSequence != null && !"".equals(offeredSequence)) {
+				SequenceOffer offerPart = new SequenceOffer(factory,rmNamespaceValue);
+				Identifier identifier = new Identifier(factory,rmNamespaceValue);
+				identifier.setIndentifer(offeredSequence);
+				offerPart.setIdentifier(identifier);
+				createSequencePart.setSequenceOffer(offerPart);
+			}
+		}
+
+		SequencePropertyBean replyToBean = seqPropMgr.retrieve(
+				internalSequenceId,
+				Sandesha2Constants.SequenceProperties.REPLY_TO_EPR);
+		SequencePropertyBean toBean = seqPropMgr.retrieve(internalSequenceId,
+				Sandesha2Constants.SequenceProperties.TO_EPR);
+
+		if (toBean == null || toBean.getValue() == null)
+			throw new SandeshaException("To EPR is not set.");
+
+		EndpointReference toEPR = new EndpointReference(toBean.getValue());
+		EndpointReference replyToEPR = null;
+		EndpointReference acksToEPR = null;
+
+		String anonymousURI = SpecSpecificConstants.getAddressingAnonymousURI(addressingNamespaceValue);
+		
+		if (acksTo == null || "".equals(acksTo))
+			acksTo = anonymousURI;
+
+		acksToEPR = new EndpointReference(acksTo);
+
+		if (replyToBean != null && replyToBean.getValue() != null)
+			replyToEPR = new EndpointReference(replyToBean.getValue());
+
+		if(createSeqRMMsg.getTo()==null)
+			createSeqRMMsg.setTo(toEPR);
+
+		// ReplyTo will be set only if not null.
+		if (replyToEPR != null)
+			createSeqRMMsg.setReplyTo(replyToEPR);
+
+		createSequencePart.setAcksTo(new AcksTo(
+				new Address(acksToEPR, factory, addressingNamespaceValue), factory,rmNamespaceValue,addressingNamespaceValue));
+
+		createSeqRMMsg.setMessagePart(
+				Sandesha2Constants.MessageParts.CREATE_SEQ, createSequencePart);
+
+		try {
+			createSeqRMMsg.addSOAPEnvelope();
+		} catch (AxisFault e1) {
+			throw new SandeshaException(e1.getMessage());
+		}
+		
+
+		createSeqRMMsg.setAction(SpecSpecificConstants.getCreateSequenceAction(SandeshaUtil.getRMVersion(internalSequenceId,storageManager)));
+		createSeqRMMsg.setSOAPAction(SpecSpecificConstants.getCreateSequenceSOAPAction(SandeshaUtil.getRMVersion(internalSequenceId,storageManager)));
+
+		finalizeCreation(applicationMsgContext, createSeqmsgContext);
+		
+		return createSeqRMMsg;
+	}
+
+	/**
+	 * Creates a new TerminateSequence message.
+	 * 
+	 * @param referenceRMMessage
+	 * @param sequenceId
+	 * @return
+	 * @throws SandeshaException
+	 */
+	public static RMMsgContext createTerminateSequenceMessage(
+			RMMsgContext referenceRMMessage, String sequenceId, String internalSequenceID,StorageManager storageManager)
+			throws SandeshaException {
+		MessageContext referenceMessage = referenceRMMessage
+				.getMessageContext();
+		if (referenceMessage == null)
+			throw new SandeshaException("MessageContext is null");
+
+		AxisOperation terminateOperation = null;
+
+		try {
+			terminateOperation = AxisOperationFactory
+					.getAxisOperation(AxisOperationFactory.MEP_CONSTANT_OUT_ONLY);
+		} catch (AxisFault e1) {
+			throw new SandeshaException(e1.getMessage());
+		}
+
+		if (terminateOperation == null)
+			throw new SandeshaException("Terminate Operation was null");
+
+		ConfigurationContext configCtx = referenceMessage
+		.getConfigurationContext();
+		if (configCtx == null)
+			throw new SandeshaException("Configuration Context is null");
+
+		MessageContext terminateMessage = SandeshaUtil
+				.createNewRelatedMessageContext(referenceRMMessage,
+						terminateOperation);
+
+		OperationContext operationContext = terminateMessage.getOperationContext();
+		configCtx.registerOperationContext(terminateMessage.getMessageID(), operationContext);   //to receive terminate sequence response messages correctly.
+		
+		AxisOperation teferenceMsgOperation = referenceMessage.getAxisOperation();
+		AxisOperation terminateMsgOperation = terminateMessage.getAxisOperation();
+		if (teferenceMsgOperation != null) {
+			terminateMsgOperation.setPhasesOutFlow(teferenceMsgOperation
+					.getPhasesOutFlow());
+			terminateMsgOperation.setPhasesOutFaultFlow(teferenceMsgOperation
+					.getPhasesOutFaultFlow());
+			terminateMsgOperation.setPhasesInFaultFlow(teferenceMsgOperation
+					.getPhasesInFaultFlow());
+			terminateMsgOperation.setRemainingPhasesInFlow(teferenceMsgOperation
+					.getRemainingPhasesInFlow());
+		}
+		
+		String rmVersion = SandeshaUtil.getRMVersion(internalSequenceID,storageManager);
+		if (rmVersion==null)
+			throw new SandeshaException ("Cant find the rmVersion of the given message");
+		
+		String rmNamespaceValue = SpecSpecificConstants.getRMNamespaceValue(rmVersion);
+		
+		initializeCreation(referenceMessage, terminateMessage);
+
+		if (!SpecSpecificConstants.isTerminateSequenceResponseRequired(rmVersion)) {
+			terminateMessage.setProperty(MessageContext.TRANSPORT_IN,null);
+		}
+		
+		RMMsgContext terminateRMMessage = MsgInitializer
+				.initializeMessage(terminateMessage);
+
+		if (terminateMessage == null)
+			throw new SandeshaException("MessageContext is null");
+
+		// setUpMessage(referenceMessage, terminateMessage);
+		
+		SOAPFactory factory = SOAPAbstractFactory.getSOAPFactory(SandeshaUtil
+				.getSOAPVersion(referenceMessage.getEnvelope()));
+
+		terminateMessage.setMessageID(SandeshaUtil.getUUID());
+
+		AxisOperation referenceMsgOperation = referenceMessage
+				.getAxisOperation();
+		if (referenceMsgOperation != null) {
+			ArrayList outPhases = referenceMsgOperation.getPhasesOutFlow();
+			if (outPhases != null) {
+				terminateOperation.setPhasesOutFlow(outPhases);
+				terminateOperation.setPhasesOutFaultFlow(outPhases);
+			}
+		}
+		
+		SOAPEnvelope envelope = factory.getDefaultEnvelope();
+		terminateRMMessage.setSOAPEnvelop(envelope);
+		
+		TerminateSequence terminateSequencePart = new TerminateSequence(factory,rmNamespaceValue);
+		Identifier identifier = new Identifier(factory,rmNamespaceValue);
+		identifier.setIndentifer(sequenceId);
+		terminateSequencePart.setIdentifier(identifier);
+		terminateRMMessage.setMessagePart(
+				Sandesha2Constants.MessageParts.TERMINATE_SEQ,
+				terminateSequencePart);
+
+		finalizeCreation(referenceMessage, terminateMessage);
+		
+		terminateMessage.setProperty(MessageContext.TRANSPORT_IN,null);   //no need for an incoming transport for an terminate
+																		  //message. If this is put, sender will look for an response.
+		
+		return terminateRMMessage;
+	}
+
+	/**
+	 * Create a new CreateSequenceResponse message.
+	 * 
+	 * @param createSeqMessage
+	 * @param outMessage
+	 * @param newSequenceID
+	 * @return
+	 * @throws AxisFault
+	 */
+	public static RMMsgContext createCreateSeqResponseMsg(
+			RMMsgContext createSeqMessage, MessageContext outMessage,
+			String newSequenceID,StorageManager storageManager) throws AxisFault {
+
+		SOAPFactory factory = SOAPAbstractFactory.getSOAPFactory(SandeshaUtil
+				.getSOAPVersion(createSeqMessage.getSOAPEnvelope()));
+
+		ConfigurationContext configurationContext = createSeqMessage.getMessageContext().getConfigurationContext();
+		
+		IOMRMElement messagePart = createSeqMessage
+				.getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ);
+		CreateSequence cs = (CreateSequence) messagePart;
+
+		String rmVersion = SandeshaUtil.getRMVersion(newSequenceID,storageManager);
+		if (rmVersion==null)
+			throw new SandeshaException ("Cant find the rmVersion of the given message");
+		
+		String rmNamespaceValue = SpecSpecificConstants.getRMNamespaceValue(rmVersion);		
+		String addressingNamespaceValue = SandeshaUtil.getSequenceProperty(newSequenceID,Sandesha2Constants.SequenceProperties.ADDRESSING_NAMESPACE_VALUE,storageManager);
+		
+		CreateSequenceResponse response = new CreateSequenceResponse(factory,rmNamespaceValue,addressingNamespaceValue);
+
+		Identifier identifier = new Identifier(factory,rmNamespaceValue);
+		identifier.setIndentifer(newSequenceID);
+
+		response.setIdentifier(identifier);
+
+		SequenceOffer offer = cs.getSequenceOffer();
+		if (offer != null) {
+			String outSequenceId = offer.getIdentifer().getIdentifier();
+
+			if (outSequenceId != null && !"".equals(outSequenceId)) {
+
+				Accept accept = new Accept(factory,rmNamespaceValue,addressingNamespaceValue);
+				EndpointReference acksToEPR = createSeqMessage.getTo();
+				AcksTo acksTo = new AcksTo(factory,rmNamespaceValue,addressingNamespaceValue);
+				Address address = new Address(factory,addressingNamespaceValue);
+				address.setEpr(acksToEPR);
+				acksTo.setAddress(address);
+				accept.setAcksTo(acksTo);
+				response.setAccept(accept);
+			}
+
+		}
+
+		SOAPEnvelope envelope = factory.getDefaultEnvelope();
+		response.toOMElement(envelope.getBody());
+		outMessage.setWSAAction(SpecSpecificConstants.getCreateSequenceResponseAction(SandeshaUtil.getRMVersion(newSequenceID,storageManager)));
+		outMessage.setSoapAction(SpecSpecificConstants.getCreateSequenceResponseSOAPAction(SandeshaUtil.getRMVersion(newSequenceID,storageManager)));
+		outMessage.setProperty(AddressingConstants.WS_ADDRESSING_VERSION,addressingNamespaceValue);
+		
+		String newMessageId = SandeshaUtil.getUUID();
+		outMessage.setMessageID(newMessageId);
+
+		outMessage.setEnvelope(envelope);
+
+		initializeCreation(createSeqMessage.getMessageContext(), outMessage);
+
+		RMMsgContext createSeqResponse = null;
+		try {
+			createSeqResponse = MsgInitializer.initializeMessage(outMessage);
+		} catch (SandeshaException ex) {
+			throw new AxisFault("Cant initialize the message",ex);
+		}
+		
+		createSeqResponse.setMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ_RESPONSE,response);
+
+		finalizeCreation(createSeqMessage.getMessageContext(), outMessage);
+
+		createSeqMessage.getMessageContext().setServerSide(true);
+		return createSeqResponse;
+	}
+	
+	
+	public static RMMsgContext createTerminateSeqResponseMsg (RMMsgContext terminateSeqRMMsg, MessageContext outMessage,StorageManager storageManager) throws SandeshaException {
+		
+		RMMsgContext terminateSeqResponseRMMsg = new RMMsgContext (outMessage);
+		ConfigurationContext configurationContext = terminateSeqRMMsg.getMessageContext().getConfigurationContext();
+		
+		SOAPFactory factory = SOAPAbstractFactory.getSOAPFactory(SandeshaUtil
+				.getSOAPVersion(terminateSeqRMMsg.getSOAPEnvelope()));
+		
+		TerminateSequence terminateSequence = (TerminateSequence) terminateSeqRMMsg.getMessagePart(Sandesha2Constants.MessageParts.TERMINATE_SEQ);
+		String sequenceID = terminateSequence.getIdentifier().getIdentifier();
+		
+		String namespace = terminateSeqRMMsg.getRMNamespaceValue();
+		terminateSeqResponseRMMsg.setRMNamespaceValue(namespace);
+		
+		TerminateSequenceResponse terminateSequenceResponse = new TerminateSequenceResponse (factory,namespace);
+		Identifier identifier = new Identifier (factory,namespace);
+		identifier.setIndentifer(sequenceID);
+		terminateSequenceResponse.setIdentifier(identifier);
+		
+		SOAPEnvelope envelope = factory.getDefaultEnvelope();
+		terminateSeqResponseRMMsg.setSOAPEnvelop(envelope);
+		terminateSeqResponseRMMsg.setMessagePart(Sandesha2Constants.MessageParts.TERMINATE_SEQ_RESPONSE,terminateSequenceResponse);
+		
+		outMessage.setWSAAction(SpecSpecificConstants.getTerminateSequenceResponseAction(SandeshaUtil.getRMVersion(sequenceID,storageManager)));
+		outMessage.setSoapAction(SpecSpecificConstants.getTerminateSequenceResponseAction(SandeshaUtil.getRMVersion(sequenceID,storageManager)));
+
+		initializeCreation(terminateSeqRMMsg.getMessageContext(),outMessage);
+		
+		terminateSeqResponseRMMsg.addSOAPEnvelope();
+		
+		
+		finalizeCreation(terminateSeqRMMsg.getMessageContext(), outMessage);
+		
+		terminateSeqResponseRMMsg.getMessageContext().setServerSide(true);
+		return terminateSeqResponseRMMsg;
+	}
+	
+	
+	public static RMMsgContext createCloseSeqResponseMsg (RMMsgContext closeSeqRMMsg, MessageContext outMessage,StorageManager storageManager) throws SandeshaException {
+		
+		RMMsgContext closeSeqResponseRMMsg = new RMMsgContext (outMessage);
+		ConfigurationContext configurationContext = closeSeqRMMsg.getMessageContext().getConfigurationContext();
+		
+		SOAPFactory factory = SOAPAbstractFactory.getSOAPFactory(SandeshaUtil
+				.getSOAPVersion(closeSeqRMMsg.getSOAPEnvelope()));
+		
+		CloseSequence closeSequence = (CloseSequence) closeSeqRMMsg.getMessagePart(Sandesha2Constants.MessageParts.CLOSE_SEQUENCE);
+		String sequenceID = closeSequence.getIdentifier().getIdentifier();
+		
+		String namespace = closeSeqRMMsg.getRMNamespaceValue();
+		closeSeqResponseRMMsg.setRMNamespaceValue(namespace);
+		
+		CloseSequenceResponse closeSequenceResponse = new CloseSequenceResponse (factory,namespace);
+		Identifier identifier = new Identifier (factory,namespace);
+		identifier.setIndentifer(sequenceID);
+		closeSequenceResponse.setIdentifier(identifier);
+		
+		SOAPEnvelope envelope = factory.getDefaultEnvelope();
+		closeSeqResponseRMMsg.setSOAPEnvelop(envelope);
+		closeSeqResponseRMMsg.setMessagePart(Sandesha2Constants.MessageParts.CLOSE_SEQUENCE_RESPONSE,closeSequenceResponse);
+		
+		outMessage.setWSAAction(SpecSpecificConstants.getCloseSequenceResponseAction(SandeshaUtil.getRMVersion(sequenceID,storageManager)));
+		outMessage.setSoapAction(SpecSpecificConstants.getCloseSequenceResponseAction(SandeshaUtil.getRMVersion(sequenceID,storageManager)));
+
+		initializeCreation(closeSeqRMMsg.getMessageContext(),outMessage);
+		
+		closeSeqResponseRMMsg.addSOAPEnvelope();
+		
+		
+		finalizeCreation(closeSeqRMMsg.getMessageContext(), outMessage);
+		closeSeqResponseRMMsg.getMessageContext().setServerSide(true);
+		return closeSeqResponseRMMsg;
+	}
+	
+
+	/**
+	 * Adds an ack message to the given application message.
+	 * 
+	 * @param applicationMsg
+	 * @param sequenceId
+	 * @throws SandeshaException
+	 */
+	public static void addAckMessage(RMMsgContext applicationMsg,
+			String sequenceId,StorageManager storageManager) throws SandeshaException {
+
+		SOAPFactory factory = SOAPAbstractFactory.getSOAPFactory(SandeshaUtil
+				.getSOAPVersion(applicationMsg.getSOAPEnvelope()));
+
+		SOAPEnvelope envelope = applicationMsg.getSOAPEnvelope();
+		if (envelope == null) {
+			SOAPEnvelope newEnvelope = factory.getDefaultEnvelope();
+			applicationMsg.setSOAPEnvelop(newEnvelope);
+		}
+		envelope = applicationMsg.getSOAPEnvelope();
+		
+		ConfigurationContext ctx = applicationMsg.getMessageContext()
+		.getConfigurationContext();
+		
+		String rmVersion = SandeshaUtil.getRMVersion(sequenceId,storageManager);
+		if (rmVersion==null)
+			throw new SandeshaException ("Cant find the rmVersion of the given message");
+		
+		String rmNamespaceValue = SpecSpecificConstants.getRMNamespaceValue(rmVersion);
+		
+		SequenceAcknowledgement sequenceAck = new SequenceAcknowledgement(
+				factory,rmNamespaceValue);
+		Identifier id = new Identifier(factory,rmNamespaceValue);
+		id.setIndentifer(sequenceId);
+		sequenceAck.setIdentifier(id);
+
+		SequencePropertyBeanMgr seqPropMgr = storageManager
+				.getSequencePropretyBeanMgr();
+
+		SequencePropertyBean seqBean = seqPropMgr.retrieve(sequenceId,
+				Sandesha2Constants.SequenceProperties.SERVER_COMPLETED_MESSAGES);
+		String msgNoList = (String) seqBean.getValue();
+
+		ArrayList ackRangeArrayList = SandeshaUtil.getAckRangeArrayList(
+				msgNoList, factory,rmNamespaceValue);
+		Iterator iterator = ackRangeArrayList.iterator();
+		while (iterator.hasNext()) {
+			AcknowledgementRange ackRange = (AcknowledgementRange) iterator
+					.next();
+			sequenceAck.addAcknowledgementRanges(ackRange);
+		}
+		
+		
+		SequencePropertyBean sequenceClosedBean = seqPropMgr.retrieve(sequenceId,Sandesha2Constants.SequenceProperties.SEQUENCE_CLOSED );
+		
+		if (sequenceClosedBean!=null && Sandesha2Constants.VALUE_TRUE.equals(sequenceClosedBean.getValue())) {
+			//sequence is closed. so add the 'Final' part.
+			if (SpecSpecificConstants.isAckFinalAllowed(rmVersion)) {
+				AckFinal ackFinal = new AckFinal (factory,rmNamespaceValue);
+				sequenceAck.setAckFinal(ackFinal);
+			}
+		}
+
+		applicationMsg.setMessagePart(Sandesha2Constants.MessageParts.SEQ_ACKNOWLEDGEMENT,sequenceAck);
+		
+		sequenceAck.toOMElement(envelope.getHeader());
+		applicationMsg
+				.setAction(SpecSpecificConstants.getSequenceAcknowledgementAction(SandeshaUtil.getRMVersion(sequenceId,storageManager)));
+		applicationMsg
+				.setSOAPAction(SpecSpecificConstants.getSequenceAcknowledgementSOAPAction(SandeshaUtil.getRMVersion(sequenceId,storageManager)));
+		applicationMsg.setMessageId(SandeshaUtil.getUUID());
+	}
+
+	/**
+	 * Create a new Acknowledgement message.
+	 * 
+	 * @param applicationRMMsgCtx
+	 * @return
+	 * @throws SandeshaException
+	 */
+	public static RMMsgContext createAckMessage(RMMsgContext relatedRMMessage, String sequenceID, String rmNamespaceValue,StorageManager storageManager)
+			throws SandeshaException {
+		
+		try {
+			MessageContext applicationMsgCtx = relatedRMMessage
+					.getMessageContext();
+
+			AxisOperation ackOperation = AxisOperationFactory
+					.getAxisOperation(AxisOperationFactory.MEP_CONSTANT_OUT_ONLY);
+			
+			MessageContext ackMsgCtx = SandeshaUtil
+					.createNewRelatedMessageContext(relatedRMMessage,
+							ackOperation);
+			
+			RMMsgContext ackRMMsgCtx = MsgInitializer
+					.initializeMessage(ackMsgCtx);
+
+			initializeCreation(applicationMsgCtx, ackMsgCtx);
+
+			addAckMessage(ackRMMsgCtx, sequenceID,storageManager);
+
+			ackMsgCtx.setProperty(MessageContext.TRANSPORT_IN,null);
+			
+			finalizeCreation(applicationMsgCtx, ackMsgCtx);
+
+			ackRMMsgCtx.getMessageContext().setServerSide(true);
+			return ackRMMsgCtx;
+		} catch (AxisFault e) {
+			throw new SandeshaException(e.getMessage());
+		}
+	}
+
+}
\ No newline at end of file

Added: webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SOAPAbstractFactory.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SOAPAbstractFactory.java?rev=414476&view=auto
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SOAPAbstractFactory.java (added)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SOAPAbstractFactory.java Wed Jun 14 22:51:15 2006
@@ -0,0 +1,38 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.sandesha2.util;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.sandesha2.Sandesha2Constants;
+
+/**
+ * @author Chamikara Jayalath <ch...@gmail.com>
+ */
+
+public class SOAPAbstractFactory {
+
+	public static SOAPFactory getSOAPFactory(int SOAPVersion) {
+
+		if (SOAPVersion == Sandesha2Constants.SOAPVersion.v1_1)
+			return OMAbstractFactory.getSOAP11Factory();
+		else
+			return OMAbstractFactory.getSOAP12Factory();
+
+	}
+}
\ No newline at end of file

Added: webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SOAPFaultEnvelopeCreator.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SOAPFaultEnvelopeCreator.java?rev=414476&view=auto
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SOAPFaultEnvelopeCreator.java (added)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SOAPFaultEnvelopeCreator.java Wed Jun 14 22:51:15 2006
@@ -0,0 +1,221 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.sandesha2.util;
+
+import org.apache.axiom.om.OMConstants;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.SOAPFault;
+import org.apache.axiom.soap.SOAPFaultCode;
+import org.apache.axiom.soap.SOAPFaultDetail;
+import org.apache.axiom.soap.SOAPFaultReason;
+import org.apache.axiom.soap.SOAPFaultSubCode;
+import org.apache.axiom.soap.SOAPFaultText;
+import org.apache.axiom.soap.SOAPFaultValue;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.context.MessageContext;
+import org.apache.sandesha2.FaultData;
+import org.apache.sandesha2.Sandesha2Constants;
+import org.apache.sandesha2.SandeshaException;
+import org.apache.sandesha2.wsrm.FaultCode;
+import org.apache.sandesha2.wsrm.SequenceFault;
+
+/**
+ * Used to create an SOAP Envelope for a RM Related Fault.
+ * Support both SOAP 1.1 and SOAP 1.2 encoding.
+ * 
+ * @author Sanka Samaranayaka <ss...@gmail.com>
+ * @author Chamikara Jayalath <ch...@gmail.com>
+ */
+
+public class SOAPFaultEnvelopeCreator {
+
+	/**
+	 * Adding the SOAP Fault Envelope. 
+	 * 
+	 * @param faultMsgContext
+	 * @param SOAPVersion
+	 * @param faultData
+	 * @throws SandeshaException
+	 */
+	public static void addSOAPFaultEnvelope(MessageContext faultMsgContext,
+			int SOAPVersion, FaultData faultData, String rmNamespaceValue) throws SandeshaException {
+
+		SOAPFactory factory = SOAPAbstractFactory.getSOAPFactory(SOAPVersion);
+		SOAPEnvelope env = factory.getDefaultFaultEnvelope();
+
+		try {
+			faultMsgContext.setEnvelope(env);
+		} catch (AxisFault e) {
+			throw new SandeshaException(e.getMessage());
+		}
+
+		if (SOAPVersion == Sandesha2Constants.SOAPVersion.v1_1)
+			doSOAP11Encoding(faultMsgContext, faultData, rmNamespaceValue);
+		else
+			doSOAP12Encoding(faultMsgContext, faultData, rmNamespaceValue);
+
+	}
+
+	/**
+	 * To find out weather this is a sequence fault. These faults are handeled differently 
+	 * accodting to the RM spec.
+	 * 
+	 * @param faultData
+	 * @return
+	 */
+	private static boolean isSequenceFault(FaultData faultData) {
+
+		boolean sequenceFault = false;
+
+		int faultType = faultData.getType();
+
+		if (faultType <= 0)
+			return false;
+
+		if (faultType == Sandesha2Constants.SOAPFaults.FaultType.CREATE_SEQUENCE_REFUSED)
+			sequenceFault = true;
+
+		if (faultType == Sandesha2Constants.SOAPFaults.FaultType.UNKNOWN_SEQUENCE)
+			sequenceFault = true;
+
+		return sequenceFault;
+
+	}
+
+	/**
+	 * Adding the SequenceFault header. Only for Sequence faults.
+	 * 
+	 * @param faultMessageContext
+	 * @param faultData
+	 * @param factory
+	 */
+	private static void addSequenceFaultHeader(
+			MessageContext faultMessageContext, FaultData faultData,
+			SOAPFactory factory, String rmNamespaceValue) throws SandeshaException {
+
+		SequenceFault sequenceFault = new SequenceFault(factory, rmNamespaceValue);
+
+		FaultCode faultCode = new FaultCode(factory, rmNamespaceValue);
+		faultCode.setFaultCode(faultData.getSubcode());
+		sequenceFault.setFaultCode(faultCode);
+	}
+
+	/**
+	 * Building the envelope with SOAP 1.1
+	 * 
+	 * @param faultMsgContext
+	 * @param data
+	 * @throws SandeshaException
+	 */
+	private static void doSOAP11Encoding(MessageContext faultMsgContext,
+			FaultData data, String rmNamespaceValue) throws SandeshaException {
+
+		SOAPEnvelope faultMsgEnvelope = faultMsgContext.getEnvelope();
+		if (faultMsgEnvelope == null)
+			throw new SandeshaException("SOAP Envelope is null");
+
+		SOAPFactory factory = SOAPAbstractFactory.getSOAPFactory(SandeshaUtil
+				.getSOAPVersion(faultMsgEnvelope));
+
+		SOAPFault fault = faultMsgEnvelope.getBody().getFault();
+		SOAPFaultCode faultCode = fault.getCode();
+
+		if (isSequenceFault(data)) {
+			faultCode.setText(data.getCode());
+		} else {
+			faultCode.setText(data.getSubcode());
+		}
+
+		SOAPFaultReason faultReason = fault.getReason();
+
+		OMNamespace namespace = factory.createOMNamespace(
+				OMConstants.XMLNS_URI, OMConstants.XMLNS_PREFIX);
+		faultReason.getSOAPFaultText("en").addAttribute("lang", "en", namespace);
+
+		faultReason.setText(data.getReason());
+		faultCode.getValue().setText(data.getSubcode());
+		SOAPFaultText faultText = faultReason.getSOAPFaultText("en");
+		if (faultText==null)
+			faultText = factory.createSOAPFaultText();
+		
+		faultText.setText(data.getReason());
+
+		//SequenceFault header is added only for SOAP 1.1
+		if (isSequenceFault(data))
+			addSequenceFaultHeader(faultMsgContext, data, factory, rmNamespaceValue);
+
+	}
+
+	
+	/**
+	 * Building the envelope with SOAP 1.2
+	 * 
+	 * @param faultMsgContext
+	 * @param data
+	 * @throws SandeshaException
+	 */
+	private static void doSOAP12Encoding(MessageContext faultMsgContext,
+			FaultData data, String rmNamespaceValue) throws SandeshaException {
+
+		SOAPEnvelope faultEnvelope = faultMsgContext.getEnvelope();
+		if (faultEnvelope == null)
+			throw new SandeshaException("SOAP Envelope is null");
+
+		SOAPFactory factory = SOAPAbstractFactory.getSOAPFactory(SandeshaUtil
+				.getSOAPVersion(faultEnvelope));
+
+		SOAPFault fault = faultEnvelope.getBody().getFault();
+		if (fault == null)
+			throw new SandeshaException("Fault part is null");
+
+		SOAPFaultCode faultCode = fault.getCode();
+		SOAPFaultValue codeValue = faultCode.getValue();
+		codeValue.setText(data.getCode());
+
+		SOAPFaultSubCode faultSubCode = factory
+				.createSOAPFaultSubCode(faultCode);
+		SOAPFaultValue subCodeValue = factory
+				.createSOAPFaultValue(faultSubCode);
+		subCodeValue.setText(data.getSubcode());
+
+		SOAPFaultReason faultReason = fault.getReason();
+		SOAPFaultText faultText = faultReason.getSOAPFaultText("en");
+		
+		if (faultText==null) {
+			faultText = factory.createSOAPFaultText();
+		}
+		
+		if (data!=null && data.getReason()!=null)
+			faultText.setText(data.getReason());
+
+		SOAPFaultDetail faultDetail = fault.getDetail();
+
+		OMElement detailElement = data.getDetail();
+
+		if (detailElement != null)
+			faultDetail.addChild(detailElement);
+
+		
+		faultMsgContext.setWSAAction(AddressingConstants.Final.WSA_FAULT_ACTION);
+	}
+
+}
\ No newline at end of file

Added: webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SandeshaPropertyBean.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SandeshaPropertyBean.java?rev=414476&view=auto
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SandeshaPropertyBean.java (added)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SandeshaPropertyBean.java Wed Jun 14 22:51:15 2006
@@ -0,0 +1,155 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.sandesha2.util;
+
+import java.util.ArrayList;
+
+import org.apache.sandesha2.policy.RMPolicyBean;
+
+/**
+ * Used to hold peoperties loaded from sandesha2.properties file or Sandesha2Constants.
+ * 
+ * @author Chamikara Jayalath <ch...@gmail.com>
+ */
+
+public class SandeshaPropertyBean {
+
+	RMPolicyBean policyBean = new RMPolicyBean ();
+//	String storageManagerClass = null;
+	boolean inOrder = true;
+	ArrayList msgTypesToDrop = null;
+	private String inMemoryStorageManagerClass = null;
+	private String permanentStorageManagerClass = null;
+	
+    public long getInactiveTimeoutInterval() {
+        return policyBean.getInactiveTimeoutInterval();
+    }
+    
+    public long getAcknowledgementInaterval() {
+        return policyBean.getAcknowledgementInaterval();
+    }
+    
+    public long getRetransmissionInterval() {
+        return policyBean.getRetransmissionInterval();
+    }
+    
+    public boolean isExponentialBackoff() {
+        return policyBean.isExponentialBackoff();
+    }
+    
+    public void setExponentialBackoff(boolean exponentialBackoff) {
+        policyBean.setExponentialBackoff(exponentialBackoff);    
+    }
+    
+    public void setRetransmissionInterval(long retransmissionInterval) {
+        policyBean.setRetransmissionInterval(retransmissionInterval);
+    }
+    
+    public void setInactiveTimeoutInterval(long value, String measure) {
+    	long timeOut = -1;
+    	
+        if (measure==null) {
+        	policyBean.setInactiveTimeoutInterval(timeOut);
+        	return;
+        } else if ("seconds".equals(measure)){
+        	timeOut = value*1000;
+        } else if ("minutes".equals(measure)){
+        	timeOut = value*60*1000;
+        } else if ("hours".equals(measure)){
+        	timeOut = value*60*60*1000;
+        } else if ("days".equals(measure)){
+        	timeOut = value*24*60*60*1000;
+        }
+        
+        policyBean.setInactiveTimeoutInterval(timeOut);
+        
+    }
+    
+    public void setInactiveTimeoutInterval(long inactivityTimeoutInterval) {
+    	policyBean.setInactiveTimeoutInterval(inactivityTimeoutInterval);
+    }
+    
+    public void setAcknowledgementInterval(long acknowledgementInterval) {
+        policyBean.setAcknowledgementInterval(acknowledgementInterval);
+    }
+	
+//	public String getStorageManagerClass() {
+//		return storageManagerClass;
+//	}
+//	
+//	public void setStorageManagerClass(String storageManagerClass) {
+//		this.storageManagerClass = storageManagerClass;
+//	}
+	
+	public String getInMemoryStorageManagerClass() {
+		return inMemoryStorageManagerClass;
+	}
+	
+	public void setInMemoryStorageManagerClass(String inMemoryStorageManagerClass) {
+		this.inMemoryStorageManagerClass = inMemoryStorageManagerClass;
+	}
+	
+	public String getPermanentStorageManagerClass() {
+		return permanentStorageManagerClass;
+	}
+	
+	public void setPermanentStorageManagerClass(String permanentStorageManagerClass) {
+		this.permanentStorageManagerClass = permanentStorageManagerClass;
+	}
+	
+	public RMPolicyBean getPolicyBean () {
+		return policyBean;
+	}
+	
+	
+	public boolean isInOrder() {
+		return inOrder;
+	}
+	
+	public void setInOrder(boolean inOrder) {
+		this.inOrder = inOrder;
+	}
+
+	public ArrayList getMsgTypesToDrop() {
+		return msgTypesToDrop;
+	}
+
+	public void setMsgTypesToDrop(ArrayList msgTypesToDrop) {
+		this.msgTypesToDrop = msgTypesToDrop;
+	}
+	
+	public void addMsgTypeToDrop (Integer typeNo) {
+		
+		if (typeNo!=null) {
+			if (msgTypesToDrop==null) 
+				msgTypesToDrop = new ArrayList ();
+			
+			msgTypesToDrop.add(typeNo);
+		}
+	}
+	
+	public int getMaximumRetransmissionCount() {
+		return policyBean.getMaximumRetransmissionCount();
+	}
+
+	public void setMaximumRetransmissionCount(int maximumRetransmissionCount) {
+		policyBean.setMaximumRetransmissionCount(maximumRetransmissionCount);
+	}
+	
+	
+}

Added: webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SandeshaUtil.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SandeshaUtil.java?rev=414476&view=auto
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SandeshaUtil.java (added)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SandeshaUtil.java Wed Jun 14 22:51:15 2006
@@ -0,0 +1,897 @@
+/*
+ * Copyright  1999-2004 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.sandesha2.util;
+
+import java.io.OutputStream;
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.StringTokenizer;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.SOAPHeader;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.MessageContextConstants;
+import org.apache.axis2.context.OperationContext;
+import org.apache.axis2.context.OperationContextFactory;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.context.ServiceGroupContext;
+import org.apache.axis2.description.AxisDescription;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.AxisServiceGroup;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.engine.Handler;
+import org.apache.axis2.util.UUIDGenerator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.sandesha2.RMMsgContext;
+import org.apache.sandesha2.Sandesha2Constants;
+import org.apache.sandesha2.SandeshaException;
+import org.apache.sandesha2.storage.StorageManager;
+import org.apache.sandesha2.storage.beanmanagers.SequencePropertyBeanMgr;
+import org.apache.sandesha2.storage.beans.SequencePropertyBean;
+import org.apache.sandesha2.workers.InOrderInvoker;
+import org.apache.sandesha2.workers.Sender;
+import org.apache.sandesha2.wsrm.AckRequested;
+import org.apache.sandesha2.wsrm.AcknowledgementRange;
+import org.apache.sandesha2.wsrm.CloseSequence;
+import org.apache.sandesha2.wsrm.CloseSequenceResponse;
+import org.apache.sandesha2.wsrm.Sequence;
+import org.apache.sandesha2.wsrm.SequenceAcknowledgement;
+
+/**
+ * Contains utility methods that are used in many plases of Sandesha2.
+ * 
+ * @author Chamikara Jayalath <ch...@gmail.com>
+ */
+
+public class SandeshaUtil {
+
+	// private static Hashtable storedMsgContexts = new Hashtable();
+
+	private static Log log = LogFactory.getLog(SandeshaUtil.class);
+
+	/**
+	 * Create a new UUID.
+	 * 
+	 * @return
+	 */
+	public static String getUUID() {
+		// String uuid = "uuid:" + UUIDGenerator.getUUID();
+		String uuid = UUIDGenerator.getUUID();
+
+		return uuid;
+	}
+
+	/**
+	 * Used to convert a message number list (a comma seperated list of message
+	 * numbers) into a set of AcknowledgementRanges. This breaks the list, sort
+	 * the items and group them to create the AcknowledgementRange objects.
+	 * 
+	 * @param msgNoStr
+	 * @param factory
+	 * @return
+	 * @throws SandeshaException
+	 */
+	public static ArrayList getAckRangeArrayList(String msgNoStr, SOAPFactory factory, String rmNamespaceValue)
+			throws SandeshaException {
+
+		ArrayList ackRanges = new ArrayList();
+
+		StringTokenizer tokenizer = new StringTokenizer(msgNoStr, ",");
+		ArrayList sortedMsgNoArrayList = getSortedMsgNoArrayList(tokenizer);
+
+		Iterator iterator = sortedMsgNoArrayList.iterator();
+		long lower = 0;
+		long upper = 0;
+		boolean completed = true;
+
+		while (iterator.hasNext()) {
+			Long tempLng = (Long) iterator.next();
+			long temp = tempLng.longValue();
+			if (lower == 0) {
+				lower = temp;
+				upper = temp;
+				completed = false;
+			} else if (temp == (upper + 1)) {
+				upper = temp;
+				completed = false;
+			} else {
+				// add ackRange (lower,upper)
+				AcknowledgementRange ackRange = new AcknowledgementRange(factory, rmNamespaceValue);
+				ackRange.setLowerValue(lower);
+				ackRange.setUpperValue(upper);
+				ackRanges.add(ackRange);
+
+				lower = temp;
+				upper = temp;
+				completed = false;
+			}
+		}
+
+		if (!completed) {
+			AcknowledgementRange ackRange = new AcknowledgementRange(factory, rmNamespaceValue);
+			ackRange.setLowerValue(lower);
+			ackRange.setUpperValue(upper);
+			ackRanges.add(ackRange);
+			completed = true;
+		}
+
+		return ackRanges;
+	}
+
+	private static ArrayList getSortedMsgNoArrayList(StringTokenizer tokenizer) throws SandeshaException {
+		ArrayList msgNubers = new ArrayList();
+
+		while (tokenizer.hasMoreElements()) {
+			String temp = tokenizer.nextToken();
+
+			try {
+				long msgNo = Long.parseLong(temp);
+				msgNubers.add(new Long(msgNo));
+			} catch (Exception ex) {
+				String message = "Invalid msg number list";
+				log.debug(message);
+				throw new SandeshaException(message);
+			}
+		}
+
+		ArrayList sortedMsgNumberList = sort(msgNubers);
+		return sortedMsgNumberList;
+	}
+
+	public static ArrayList sort(ArrayList list) {
+
+		ArrayList sortedList = new ArrayList();
+
+		long max = 0;
+		Iterator it1 = list.iterator();
+		while (it1.hasNext()) {
+			Long tempLng = (Long) it1.next();
+			long temp = tempLng.longValue();
+			if (temp > max)
+				max = temp;
+		}
+
+		int item = 0;
+		for (long i = 1; i <= max; i++) {
+			Long temp = new Long(i);
+			if (list.contains(temp)) {
+				sortedList.add(item, temp);
+				item++;
+			}
+		}
+
+		return sortedList;
+	}
+
+	public static void startSenderForTheSequence(ConfigurationContext context, String sequenceID) {
+		
+		Sender sender = (Sender) context.getProperty(Sandesha2Constants.SENDER);
+		
+		if (sender!=null)
+			sender.runSenderForTheSequence(context, sequenceID);
+		else {
+			sender = new Sender ();
+			context.setProperty(Sandesha2Constants.SENDER,sender);
+			sender.runSenderForTheSequence(context, sequenceID);
+		}
+	}
+
+	private static void stopSenderForTheSequence(String sequenceID, ConfigurationContext context) {
+		Sender sender = (Sender) context.getProperty(Sandesha2Constants.SENDER);
+		
+		if (sender!=null) {
+			sender.stopSenderForTheSequence(sequenceID);
+		}
+	}
+	
+	public static void stopSender(ConfigurationContext context) {
+		Sender sender = (Sender) context.getProperty(Sandesha2Constants.SENDER);
+		
+		if (sender!=null) {
+			sender.stopSending ();
+		}
+	}
+
+	public static void startInvokerForTheSequence(ConfigurationContext context, String sequenceID) {
+		
+		InOrderInvoker invoker = (InOrderInvoker) context.getProperty(Sandesha2Constants.INVOKER);
+		if (invoker!=null)
+			invoker.runInvokerForTheSequence(context,sequenceID);
+		else {
+			invoker = new InOrderInvoker ();
+			context.setProperty(Sandesha2Constants.INVOKER,invoker);
+			invoker.runInvokerForTheSequence(context,sequenceID);
+		}
+	}
+
+	private static void stopInvokerForTheSequence(String sequenceID, ConfigurationContext context) {
+		InOrderInvoker invoker = (InOrderInvoker) context.getProperty(Sandesha2Constants.INVOKER);
+		if (invoker!=null)
+			invoker.stopInvokerForTheSequence(sequenceID);
+	}
+	
+	public static void stopInvoker(ConfigurationContext context) {
+		InOrderInvoker invoker = (InOrderInvoker) context.getProperty(Sandesha2Constants.INVOKER);
+		if (invoker!=null)
+			invoker.stopInvoking();
+	}
+
+	public static String getMessageTypeString(int messageType) {
+		switch (messageType) {
+		case Sandesha2Constants.MessageTypes.CREATE_SEQ:
+			return "CreateSequence";
+		case Sandesha2Constants.MessageTypes.CREATE_SEQ_RESPONSE:
+			return "CreateSequenceResponse";
+		case Sandesha2Constants.MessageTypes.ACK:
+			return "Acknowledgement";
+		case Sandesha2Constants.MessageTypes.APPLICATION:
+			return "Application";
+		case Sandesha2Constants.MessageTypes.TERMINATE_SEQ:
+			return "TerminateSequence";
+		case Sandesha2Constants.MessageTypes.ACK_REQUEST:
+			return "AckRequest";
+		case Sandesha2Constants.MessageTypes.CLOSE_SEQUENCE:
+			return "CloseSequence";
+		case Sandesha2Constants.MessageTypes.CLOSE_SEQUENCE_RESPONSE:
+			return "CloseSequenceResponse";
+		case Sandesha2Constants.MessageTypes.TERMINATE_SEQ_RESPONSE:
+			return "TerminateSequenceResponse";
+		case Sandesha2Constants.MessageTypes.UNKNOWN:
+			return "Unknown";
+		default:
+			return "Error";
+		}
+	}
+
+	public static boolean isGloballyProcessableMessageType(int type) {
+		if (type == Sandesha2Constants.MessageTypes.ACK || type == Sandesha2Constants.MessageTypes.TERMINATE_SEQ) {
+			return true;
+		}
+
+		return false;
+	}
+
+	public static boolean isDuplicateDropRequiredMsgType(int rmMessageType) {
+		if (rmMessageType == Sandesha2Constants.MessageTypes.APPLICATION)
+			return true;
+
+		if (rmMessageType == Sandesha2Constants.MessageTypes.CREATE_SEQ_RESPONSE)
+			return true;
+
+		return false;
+	}
+
+	public static ArrayList getSplittedMsgNoArraylist(String str) {
+
+		StringTokenizer tokenizer = new StringTokenizer(str, ",");
+
+		ArrayList results = new ArrayList();
+
+		while (tokenizer.hasMoreTokens()) {
+			results.add(tokenizer.nextToken());
+		}
+
+		return results;
+	}
+
+	public static String getServerSideIncomingSeqIdFromInternalSeqId(String internalSequenceId)
+			throws SandeshaException {
+
+		String startStr = Sandesha2Constants.INTERNAL_SEQUENCE_PREFIX + ":";
+		if (!internalSequenceId.startsWith(startStr)) {
+			throw new SandeshaException("Invalid internal sequence ID");
+		}
+
+		String incomingSequenceId = internalSequenceId.substring(startStr.length());
+		return incomingSequenceId;
+	}
+
+	/**
+	 * Used to obtain the storage Manager Implementation.
+	 * 
+	 * @param context
+	 * @return
+	 * @throws SandeshaException
+	 */
+	public static StorageManager getSandeshaStorageManager(ConfigurationContext context,AxisDescription description) throws SandeshaException {
+
+		Parameter parameter = description.getParameter(Sandesha2Constants.STORAGE_MANAGER_PARAMETER);
+		if (parameter==null) {
+			parameter = new Parameter (Sandesha2Constants.STORAGE_MANAGER_PARAMETER,Sandesha2Constants.DEFAULT_STORAGE_MANAGER);
+		}
+		
+		String value = (String) parameter.getValue();
+		
+		if (Sandesha2Constants.INMEMORY_STORAGE_MANAGER.equals(value))
+			return getInMemoryStorageManager(context);
+		else if (Sandesha2Constants.PERMANENT_STORAGE_MANAGER.equals(value))
+			return getPermanentStorageManager(context);
+		else
+			throw new SandeshaException ("Unknown StorageManager type. Please check your parameter value.");
+	}
+	
+	public static StorageManager getInMemoryStorageManager(ConfigurationContext context) throws SandeshaException {
+
+		StorageManager inMemoryStorageManager = (StorageManager) context.getProperty(Sandesha2Constants.INMEMORY_STORAGE_MANAGER);
+		if (inMemoryStorageManager != null)
+			return inMemoryStorageManager;
+
+		//Currently module policies (default) are used to find the storage manager. These cant be overriden
+		//TODO change this so that different services can hv different storage managers.
+		String storageManagerClassStr = getDefaultPropertyBean(context.getAxisConfiguration()).getInMemoryStorageManagerClass();
+		inMemoryStorageManager = getStorageManagerInstance(storageManagerClassStr,context);
+		context.setProperty(Sandesha2Constants.INMEMORY_STORAGE_MANAGER,inMemoryStorageManager);
+		
+		return inMemoryStorageManager;
+	}
+	
+	public static StorageManager getPermanentStorageManager(ConfigurationContext context) throws SandeshaException {
+
+		StorageManager permanentStorageManager = (StorageManager) context.getProperty(Sandesha2Constants.PERMANENT_STORAGE_MANAGER);
+		if (permanentStorageManager != null)
+			return permanentStorageManager;
+
+		//Currently module policies (default) are used to find the storage manager. These cant be overriden
+		//TODO change this so that different services can hv different storage managers.
+		String storageManagerClassStr = getDefaultPropertyBean(context.getAxisConfiguration()).getPermanentStorageManagerClass ();
+		permanentStorageManager = getStorageManagerInstance(storageManagerClassStr,context);
+		context.setProperty(Sandesha2Constants.PERMANENT_STORAGE_MANAGER,permanentStorageManager);
+		
+		return permanentStorageManager;
+	}
+	
+	private static StorageManager getStorageManagerInstance (String className,ConfigurationContext context) throws SandeshaException {
+		
+		StorageManager storageManager = null;
+		try {
+		    ClassLoader classLoader = (ClassLoader)	context.getProperty(Sandesha2Constants.MODULE_CLASS_LOADER);
+
+		    if (classLoader==null)
+		    	throw new SandeshaException ("Module class loader not found");
+		    
+		    Class c = classLoader.loadClass(className);
+			Class configContextClass = context.getClass();
+			
+			Constructor constructor = c.getConstructor(new Class[] { configContextClass });
+			Object obj = constructor.newInstance(new Object[] {context});
+
+			if (obj == null || !(obj instanceof StorageManager))
+				throw new SandeshaException("StorageManager must implement org.apache.sandesha2.storage.StorageManager");
+
+			StorageManager mgr = (StorageManager) obj;
+			storageManager = mgr;
+			return storageManager;
+			
+		} catch (Exception e) {
+			String message = "Cannot load the given storage manager";
+			log.error(message);
+			throw new SandeshaException(message,e);
+		}
+	}
+
+	public static int getSOAPVersion(SOAPEnvelope envelope) throws SandeshaException {
+		String namespaceName = envelope.getNamespace().getName();
+		if (namespaceName.equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI))
+			return Sandesha2Constants.SOAPVersion.v1_1;
+		else if (namespaceName.equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI))
+			return Sandesha2Constants.SOAPVersion.v1_2;
+		else
+			throw new SandeshaException("Unknown SOAP version");
+	}
+
+	public static boolean isRMGlobalMessage(MessageContext msgCtx) {
+		boolean rmGlobalMsg = false;
+
+		String action = msgCtx.getWSAAction();
+		SOAPEnvelope env = msgCtx.getEnvelope();
+		SOAPHeader header = null;
+		if (env != null)
+			header = env.getHeader();
+		else {
+			log.error("SOAP envelope is null");
+			return false;
+		}
+
+		// TODO make this spec indipendent
+
+		OMElement sequenceElem = null;
+		if (header != null)
+			sequenceElem = header.getFirstChildWithName(new QName(Sandesha2Constants.SPEC_2005_02.NS_URI,
+					Sandesha2Constants.WSRM_COMMON.SEQUENCE));
+
+		if (sequenceElem == null)
+			sequenceElem = header.getFirstChildWithName(new QName(Sandesha2Constants.SPEC_2005_10.NS_URI,
+					Sandesha2Constants.WSRM_COMMON.SEQUENCE));
+
+		if (sequenceElem != null)
+			rmGlobalMsg = true;
+
+		if (Sandesha2Constants.SPEC_2005_02.Actions.ACTION_SEQUENCE_ACKNOWLEDGEMENT.equals(action))
+			rmGlobalMsg = true;
+
+		if (Sandesha2Constants.SPEC_2005_02.Actions.ACTION_CREATE_SEQUENCE_RESPONSE.equals(action))
+			rmGlobalMsg = true;
+
+		if (Sandesha2Constants.SPEC_2005_02.Actions.ACTION_TERMINATE_SEQUENCE.equals(action))
+			rmGlobalMsg = true;
+
+		if (Sandesha2Constants.SPEC_2005_10.Actions.ACTION_SEQUENCE_ACKNOWLEDGEMENT.equals(action))
+			rmGlobalMsg = true;
+
+		if (Sandesha2Constants.SPEC_2005_10.Actions.ACTION_TERMINATE_SEQUENCE.equals(action))
+			rmGlobalMsg = true;
+
+		if (Sandesha2Constants.SPEC_2005_10.Actions.ACTION_CREATE_SEQUENCE_RESPONSE.equals(action))
+			rmGlobalMsg = true;
+
+		return rmGlobalMsg;
+	}
+
+	// RM will retry sending the message even if a fault arrive for following message types.
+	public static boolean isRetriableOnFaults(MessageContext msgCtx) {
+		boolean rmGlobalMsg = false;
+
+		String action = msgCtx.getWSAAction();
+
+
+		if (Sandesha2Constants.SPEC_2005_02.Actions.ACTION_CREATE_SEQUENCE.equals(action))
+			rmGlobalMsg = true;
+
+		if (Sandesha2Constants.SPEC_2005_10.Actions.ACTION_CREATE_SEQUENCE.equals(action))
+			rmGlobalMsg = true;
+
+		return rmGlobalMsg;
+	}
+	
+	public static MessageContext createNewRelatedMessageContext(RMMsgContext referenceRMMessage, AxisOperation operation)
+			throws SandeshaException {
+		try {
+			MessageContext referenceMessage = referenceRMMessage.getMessageContext();
+			ConfigurationContext configContext = referenceMessage.getConfigurationContext();
+			AxisConfiguration axisConfiguration = configContext.getAxisConfiguration();
+
+			MessageContext newMessageContext = new MessageContext();
+			newMessageContext.setConfigurationContext(configContext);
+
+//			Options referenceMsgOptions = referenceMessage.getOptions();
+//			Options newOptions = null;
+//			if (referenceMsgOptions!=null)
+//				newOptions = new Options (referenceMsgOptions);
+//			else
+			
+			Options newOptions = new Options ();
+			
+			newMessageContext.setOptions(newOptions);
+			
+			if (referenceMessage.getAxisServiceGroup() != null) {
+				newMessageContext.setAxisServiceGroup(referenceMessage.getAxisServiceGroup());
+				
+				if (referenceMessage.getServiceGroupContext()!=null) {
+					newMessageContext.setServiceGroupContext(referenceMessage.getServiceGroupContext());
+					newMessageContext.setServiceGroupContextId(referenceMessage.getServiceGroupContextId());
+				} else {
+					ServiceGroupContext serviceGroupContext = new ServiceGroupContext (
+							configContext,referenceMessage.getAxisServiceGroup());
+					newMessageContext.setServiceGroupContext(serviceGroupContext);
+				}
+			} else {
+				AxisServiceGroup axisServiceGroup = new AxisServiceGroup(axisConfiguration);
+				ServiceGroupContext serviceGroupContext = new ServiceGroupContext(configContext, axisServiceGroup);
+
+				newMessageContext.setAxisServiceGroup(axisServiceGroup);
+				newMessageContext.setServiceGroupContext(serviceGroupContext);
+			}
+
+			if (referenceMessage.getAxisService() != null) {
+				newMessageContext.setAxisService(referenceMessage.getAxisService());
+				
+				if (referenceMessage.getServiceContext()!=null) {
+					newMessageContext.setServiceContext(referenceMessage.getServiceContext());
+					newMessageContext.setServiceContextID(referenceMessage.getServiceContextID());
+				} else {
+					ServiceContext serviceContext = new ServiceContext (referenceMessage.getAxisService(),newMessageContext.getServiceGroupContext());
+					newMessageContext.setServiceContext(serviceContext);
+				}
+			} else {
+				AxisService axisService = new AxisService("AnonymousRMService"); 
+				
+				AxisServiceGroup serviceGroup = newMessageContext.getAxisServiceGroup();
+				axisService.setParent(serviceGroup);
+				serviceGroup.addChild(axisService);
+				
+				ServiceContext serviceContext = new ServiceContext(axisService, newMessageContext.getServiceGroupContext());
+
+				newMessageContext.setAxisService(axisService);
+				newMessageContext.setServiceContext(serviceContext);
+			}
+
+			newMessageContext.setAxisOperation(operation);
+
+			// setting parent child relationships
+			AxisService service = newMessageContext.getAxisService();
+
+			if (service != null && operation != null) {
+				service.addChild(operation);
+				operation.setParent(service);
+			}
+			
+
+			OperationContext operationContext = new OperationContext(operation);
+			newMessageContext.setOperationContext(operationContext);
+			operationContext.addMessageContext(newMessageContext);
+
+			// adding a blank envelope
+			SOAPFactory factory = SOAPAbstractFactory.getSOAPFactory(SandeshaUtil.getSOAPVersion(referenceMessage
+					.getEnvelope()));
+			newMessageContext.setEnvelope(factory.getDefaultEnvelope());
+
+			newMessageContext.setTransportIn(referenceMessage.getTransportIn());
+			newMessageContext.setTransportOut(referenceMessage.getTransportOut());
+
+			copyNecessaryPropertiesFromRelatedContext(referenceMessage, newMessageContext);
+
+			// copying transport info.
+			newMessageContext.setProperty(MessageContext.TRANSPORT_OUT, referenceMessage
+					.getProperty(MessageContext.TRANSPORT_OUT));
+
+			newMessageContext.setProperty(Constants.OUT_TRANSPORT_INFO, referenceMessage
+					.getProperty(Constants.OUT_TRANSPORT_INFO));
+			newMessageContext.setProperty(MessageContext.TRANSPORT_HEADERS, referenceMessage
+					.getProperty(MessageContext.TRANSPORT_HEADERS));
+			newMessageContext.setProperty(MessageContext.TRANSPORT_IN, referenceMessage
+					.getProperty(MessageContext.TRANSPORT_IN));
+			newMessageContext.setProperty(MessageContext.TRANSPORT_OUT, referenceMessage
+					.getProperty(MessageContext.TRANSPORT_OUT));
+			newMessageContext.setExecutionChain(referenceMessage.getExecutionChain());
+
+			return newMessageContext;
+
+		} catch (AxisFault e) {
+			log.debug(e.getMessage());
+			throw new SandeshaException(e.getMessage());
+		}
+
+	}
+	
+
+	
+	public static SandeshaPropertyBean getDefaultPropertyBean (AxisConfiguration axisConfiguration) throws SandeshaException {
+		Parameter parameter = axisConfiguration.getParameter(Sandesha2Constants.SANDESHA_PROPERTY_BEAN);
+		if (parameter==null)
+			throw new SandeshaException ("Default Sandesha Property Bean is not available");
+		
+		SandeshaPropertyBean sandeshaPropertyBean = (SandeshaPropertyBean) parameter.getValue();
+		return sandeshaPropertyBean;
+	}
+
+	private static void copyNecessaryPropertiesFromRelatedContext(MessageContext fromMessage, MessageContext toMessage) throws SandeshaException {
+		toMessage.setProperty(MessageContextConstants.TRANSPORT_URL, fromMessage
+				.getProperty(MessageContextConstants.TRANSPORT_URL));
+		
+		String addressingVersion = (String) fromMessage.getProperty(AddressingConstants.WS_ADDRESSING_VERSION);
+		if (addressingVersion==null) {
+			OperationContext opCtx = fromMessage.getOperationContext();
+			if (opCtx!=null) {
+				try {
+					MessageContext requestMsg = opCtx.getMessageContext(OperationContextFactory.MESSAGE_LABEL_IN_VALUE);
+					if (requestMsg!=null)
+						addressingVersion = (String) requestMsg.getProperty(AddressingConstants.WS_ADDRESSING_VERSION);
+				} catch (AxisFault e) {
+					throw new SandeshaException (e);
+				}
+			}
+		}
+		
+		toMessage.setProperty(AddressingConstants.WS_ADDRESSING_VERSION,addressingVersion);
+	}
+
+	//TODO change this method.
+	public static ArrayList getArrayListFromString(String str) throws SandeshaException {
+
+		if (str == null || "".equals(str))
+			return new ArrayList();
+
+		if (str.length() < 2) {
+			String message = "Invalid String array : " + str;
+			log.debug(message);
+			throw new SandeshaException(message);
+		}
+
+		int length = str.length();
+
+		if (str.charAt(0) != '[' || str.charAt(length - 1) != ']') {
+			String message = "Invalid String array" + str;
+			log.debug(message);
+			throw new SandeshaException(message);
+		}
+
+		ArrayList retArr = new ArrayList();
+
+		String subStr = str.substring(1, length - 1);
+
+		String[] parts = subStr.split(",");
+
+		for (int i = 0; i < parts.length; i++) {
+			if (!"".equals(parts[i]))
+				retArr.add(parts[i].trim());
+		}
+
+		return retArr;
+	}
+
+	public static ArrayList getArrayListFromMsgsString(String str) throws SandeshaException {
+
+		if (str == null || "".equals(str))
+			return new ArrayList();
+
+		ArrayList retArr = new ArrayList();
+
+		StringTokenizer tokenizer = new StringTokenizer(str, ",");
+
+		while (tokenizer.hasMoreElements()) {
+			String nextToken = tokenizer.nextToken();
+			if (nextToken != null && !"".equals(nextToken)) {
+				Long lng = new Long(nextToken);
+				retArr.add(lng);
+			}
+		}
+
+		return retArr;
+	}
+
+	public static String getInternalSequenceID(String to, String sequenceKey) {
+		if (to == null && sequenceKey == null)
+			return null;
+		else if (to == null)
+			return sequenceKey;
+		else if (sequenceKey == null)
+			return to;
+		else
+			return Sandesha2Constants.INTERNAL_SEQUENCE_PREFIX + ":" + to + ":" + sequenceKey;
+	}
+
+	public static String getOutgoingSideInternalSequenceID(String sequenceID) {
+		return Sandesha2Constants.INTERNAL_SEQUENCE_PREFIX + ":" + sequenceID;
+	}
+
+	public static String getSequenceIDFromInternalSequenceID(String internalSequenceID,
+			StorageManager storageManager) throws SandeshaException {
+
+		SequencePropertyBeanMgr sequencePropertyBeanMgr = storageManager.getSequencePropretyBeanMgr();
+
+		SequencePropertyBean outSequenceBean = sequencePropertyBeanMgr.retrieve(internalSequenceID,
+				Sandesha2Constants.SequenceProperties.OUT_SEQUENCE_ID);
+
+		String sequeunceID = null;
+		if (outSequenceBean != null)
+			sequeunceID = outSequenceBean.getValue();
+
+		return sequeunceID;
+	}
+
+	public static QName getQNameFromString(String qnameStr) throws SandeshaException {
+		String[] parts = qnameStr.split(Sandesha2Constants.QNAME_SEPERATOR);
+		if (!(parts.length == 3))
+			throw new SandeshaException("Invalid QName String");
+
+		if (parts[0].equals(Sandesha2Constants.VALUE_NONE))
+			parts[0] = null;
+
+		if (parts[1].equals(Sandesha2Constants.VALUE_NONE))
+			parts[1] = null;
+
+		if (parts[2].equals(Sandesha2Constants.VALUE_NONE))
+			parts[2] = null;
+
+		if (parts[0].equals(Sandesha2Constants.VALUE_EMPTY))
+			parts[0] = "";
+
+		if (parts[1].equals(Sandesha2Constants.VALUE_EMPTY))
+			parts[1] = "";
+
+		if (parts[2].equals(Sandesha2Constants.VALUE_EMPTY))
+			parts[2] = "";
+
+		String namespace = parts[0];
+		String localPart = parts[1];
+		String prefix = parts[2];
+
+		QName name = new QName(namespace, localPart, prefix);
+		return name;
+	}
+
+	public static String getStringFromQName(QName name) {
+		String localPart = name.getLocalPart();
+		String namespace = name.getNamespaceURI();
+		String prefix = name.getPrefix();
+
+		if (localPart == null)
+			localPart = Sandesha2Constants.VALUE_NONE;
+
+		if (namespace == null)
+			namespace = Sandesha2Constants.VALUE_NONE;
+
+		if (prefix == null)
+			prefix = Sandesha2Constants.VALUE_NONE;
+
+		if ("".equals(localPart))
+			localPart = Sandesha2Constants.VALUE_EMPTY;
+
+		if ("".equals(namespace))
+			namespace = Sandesha2Constants.VALUE_EMPTY;
+
+		if ("".equals(prefix))
+			prefix = Sandesha2Constants.VALUE_EMPTY;
+
+		String QNameStr = namespace + Sandesha2Constants.QNAME_SEPERATOR + localPart
+				+ Sandesha2Constants.QNAME_SEPERATOR + prefix;
+
+		return QNameStr;
+	}
+
+	public static String getExecutionChainString(ArrayList executionChain) {
+		Iterator iter = executionChain.iterator();
+
+		String executionChainStr = "";
+		while (iter.hasNext()) {
+			Handler handler = (Handler) iter.next();
+			QName name = handler.getName();
+			String handlerStr = SandeshaUtil.getStringFromQName(name);
+			executionChainStr = executionChainStr + Sandesha2Constants.EXECUTIN_CHAIN_SEPERATOR + handlerStr;
+		}
+
+		return executionChainStr;
+	}
+
+	// TODO complete below.
+	public static ArrayList getExecutionChainFromString(String executionChainStr, ConfigurationContext configContext)
+			throws SandeshaException {
+		String[] QNameStrs = executionChainStr.split(Sandesha2Constants.EXECUTIN_CHAIN_SEPERATOR);
+
+		AxisConfiguration axisConfiguration = configContext.getAxisConfiguration();
+
+		int length = QNameStrs.length;
+		for (int i = 0; i < length; i++) {
+			String QNameStr = QNameStrs[i];
+			QName name = getQNameFromString(QNameStr);
+			// axisConfiguration.get
+
+		}
+
+		return null; // not complete yet.
+	}
+
+	public static void printSOAPEnvelope(SOAPEnvelope envelope, OutputStream out) throws SandeshaException {
+		try {
+			XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(out);
+			System.out.println("\n");
+			envelope.serialize(writer);
+		} catch (XMLStreamException e) {
+			throw new SandeshaException(e.getMessage());
+		} catch (FactoryConfigurationError e) {
+			throw new SandeshaException(e.getMessage());
+		}
+	}
+
+	/**
+	 * 
+	 * @param propertyKey
+	 *            for the client side - internalSequenceID, for the server side -
+	 *            sequenceID
+	 * @param configurationContext
+	 * @return
+	 * @throws SandeshaException
+	 */
+	public static String getRMVersion(String propertyKey, StorageManager storageManager)
+			throws SandeshaException {
+
+		SequencePropertyBeanMgr sequencePropertyBeanMgr = storageManager.getSequencePropretyBeanMgr();
+		SequencePropertyBean specVersionBean = sequencePropertyBeanMgr.retrieve(propertyKey,
+				Sandesha2Constants.SequenceProperties.RM_SPEC_VERSION);
+
+		if (specVersionBean == null)
+			return null;
+
+		return specVersionBean.getValue();
+	}
+
+	public static String getSequenceProperty(String id, String name, StorageManager storageManager)
+			throws SandeshaException {
+		SequencePropertyBeanMgr sequencePropertyBeanMgr = storageManager.getSequencePropretyBeanMgr();
+
+		SequencePropertyBean sequencePropertyBean = sequencePropertyBeanMgr.retrieve(id, name);
+		if (sequencePropertyBean == null)
+			return null;
+		else
+			return sequencePropertyBean.getValue();
+	}
+
+	public static boolean isAllMsgsAckedUpto(long highestInMsgNo, String internalSequenceID,
+			StorageManager storageManager) throws SandeshaException {
+
+		String clientCompletedMessages = getSequenceProperty(internalSequenceID,
+				Sandesha2Constants.SequenceProperties.CLIENT_COMPLETED_MESSAGES, storageManager);
+		ArrayList ackedMsgsList = getArrayListFromString(clientCompletedMessages);
+
+		long smallestMsgNo = 1;
+		for (long tempMsgNo = smallestMsgNo; tempMsgNo <= highestInMsgNo; tempMsgNo++) {
+			if (!ackedMsgsList.contains(new Long(tempMsgNo).toString()))
+				return false;
+		}
+
+		return true; // all message upto the highest have been acked.
+	}
+	
+	public static SandeshaPropertyBean getPropertyBean (AxisDescription axisDescription) throws SandeshaException {
+		Parameter parameter = axisDescription.getParameter(Sandesha2Constants.SANDESHA_PROPERTY_BEAN);
+		if (parameter==null)
+			throw new SandeshaException ("Property bean is not set. Cant find Sandesha2 configuration data");
+		
+		SandeshaPropertyBean propertyBean = (SandeshaPropertyBean) parameter.getValue();
+		return propertyBean;
+	}
+
+	public static String getSequenceIDFromRMMessage(RMMsgContext rmMessageContext) {
+		int messageType = rmMessageContext.getMessageType();
+
+		String sequenceID = null;
+		if (messageType == Sandesha2Constants.MessageTypes.APPLICATION) {
+			Sequence sequence = (Sequence) rmMessageContext.getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
+			sequenceID = sequence.getIdentifier().getIdentifier();
+		} else if (messageType == Sandesha2Constants.MessageTypes.ACK) {
+			SequenceAcknowledgement sequenceAcknowledgement = (SequenceAcknowledgement) rmMessageContext
+					.getMessagePart(Sandesha2Constants.MessageParts.SEQ_ACKNOWLEDGEMENT);
+			sequenceID = sequenceAcknowledgement.getIdentifier().getIdentifier();
+		} else if (messageType == Sandesha2Constants.MessageTypes.ACK_REQUEST) {
+			AckRequested ackRequested = (AckRequested) rmMessageContext
+					.getMessagePart(Sandesha2Constants.MessageParts.ACK_REQUEST);
+			sequenceID = ackRequested.getIdentifier().getIdentifier();
+		} else if (messageType == Sandesha2Constants.MessageTypes.CLOSE_SEQUENCE) {
+			CloseSequence closeSequence = (CloseSequence) rmMessageContext
+					.getMessagePart(Sandesha2Constants.MessageParts.CLOSE_SEQUENCE);
+			sequenceID = closeSequence.getIdentifier().getIdentifier();
+		} else if (messageType == Sandesha2Constants.MessageTypes.CLOSE_SEQUENCE_RESPONSE) {
+			CloseSequenceResponse closeSequenceResponse = (CloseSequenceResponse) rmMessageContext
+					.getMessagePart(Sandesha2Constants.MessageParts.CLOSE_SEQUENCE_RESPONSE);
+			sequenceID = closeSequenceResponse.getIdentifier().getIdentifier();
+		}
+
+		// TODO complete for other message types
+
+		return sequenceID;
+	}
+
+}
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: sandesha-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: sandesha-dev-help@ws.apache.org