You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fx-dev@ws.apache.org by ch...@apache.org on 2006/06/15 07:51:24 UTC
svn commit: r414476 [8/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/AcknowledgementManager.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/AcknowledgementManager.java?rev=414476&view=auto
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/AcknowledgementManager.java (added)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/AcknowledgementManager.java Wed Jun 14 22:51:15 2006
@@ -0,0 +1,390 @@
+/*
+ * 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.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.addressing.EndpointReference;
+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.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.SenderBeanMgr;
+import org.apache.sandesha2.storage.beanmanagers.SequencePropertyBeanMgr;
+import org.apache.sandesha2.storage.beans.SenderBean;
+import org.apache.sandesha2.storage.beans.SequencePropertyBean;
+import org.apache.sandesha2.transport.Sandesha2TransportOutDesc;
+import org.apache.sandesha2.wsrm.AcknowledgementRange;
+import org.apache.sandesha2.wsrm.SequenceAcknowledgement;
+
+/**
+ * Contains logic for managing acknowledgements.
+ *
+ * @author Chamikara Jayalath <ch...@gmail.com>
+ */
+
+public class AcknowledgementManager {
+
+ private static Log log = LogFactory.getLog(AcknowledgementManager.class);
+
+ /**
+ * Piggybacks any available acks of the same sequence to the given
+ * application message.
+ *
+ * @param applicationRMMsgContext
+ * @throws SandeshaException
+ */
+ public static void piggybackAcksIfPresent(
+ RMMsgContext rmMessageContext,StorageManager storageManager) throws SandeshaException {
+
+ ConfigurationContext configurationContext = rmMessageContext.getConfigurationContext();
+
+ SenderBeanMgr retransmitterBeanMgr = storageManager.getRetransmitterBeanMgr();
+ SequencePropertyBeanMgr sequencePropertyBeanMgr = storageManager.getSequencePropretyBeanMgr();
+
+ SenderBean findBean = new SenderBean();
+
+ String sequnceID = SandeshaUtil.getSequenceIDFromRMMessage (rmMessageContext);
+
+ findBean.setMessageType(Sandesha2Constants.MessageTypes.ACK);
+ findBean.setSend(true);
+ findBean.setReSend(false);
+
+ String carrietTo = rmMessageContext.getTo().getAddress();
+
+ Collection collection = retransmitterBeanMgr.find(findBean);
+
+ Iterator it = collection.iterator();
+
+
+ piggybackLoop:
+ while (it.hasNext()) {
+ SenderBean ackBean = (SenderBean) it.next();
+
+ long timeNow = System.currentTimeMillis();
+ if (ackBean.getTimeToSend() > timeNow) {
+// //Piggybacking will happen only if the end of ack interval (timeToSend) is not reached.
+
+ boolean disablePiggybacking = false;
+ if (disablePiggybacking)
+ continue piggybackLoop;
+
+ MessageContext ackMsgContext = storageManager
+ .retrieveMessageContext(ackBean.getMessageContextRefKey(),configurationContext);
+
+ //wsa:To has to match for piggybacking.
+ String to = ackMsgContext.getTo().getAddress();
+ if (!carrietTo.equals(to)) {
+ continue piggybackLoop;
+ }
+
+// String ackSequenceID = ackBean.getSequenceID();
+
+// //sequenceID has to match for piggybacking
+// if (!ackSequenceID.equals(sequnceID)) {
+// continue piggybackLoop;
+// }
+
+ //deleting the ack entry.
+ retransmitterBeanMgr.delete(ackBean.getMessageID());
+
+ //Adding the ack to the application message
+ RMMsgContext ackRMMsgContext = MsgInitializer.initializeMessage(ackMsgContext);
+ if (ackRMMsgContext.getMessageType() != Sandesha2Constants.MessageTypes.ACK) {
+ String message = "Invalid ack message entry";
+ log.debug(message);
+ throw new SandeshaException(message);
+ }
+
+ SequenceAcknowledgement sequenceAcknowledgement = (SequenceAcknowledgement) ackRMMsgContext
+ .getMessagePart(Sandesha2Constants.MessageParts.SEQ_ACKNOWLEDGEMENT);
+ rmMessageContext.setMessagePart(
+ Sandesha2Constants.MessageParts.SEQ_ACKNOWLEDGEMENT,
+ sequenceAcknowledgement);
+
+ rmMessageContext.addSOAPEnvelope();
+ break piggybackLoop;
+ }
+ }
+ }
+
+ /**this is used to get the acked messages of a sequence. If this is an outgoing message the sequenceIdentifier should
+ * be the internal sequenceID.
+ *
+ * @param sequenceIdentifier
+ * @param outGoingMessage
+ * @return
+ */
+ public static ArrayList getClientCompletedMessagesList (String sequenceID,SequencePropertyBeanMgr seqPropMgr) throws SandeshaException {
+
+ //first trying to get it from the internal sequence id.
+ SequencePropertyBean internalSequenceBean = seqPropMgr.retrieve(sequenceID,Sandesha2Constants.SequenceProperties.INTERNAL_SEQUENCE_ID);
+ String internalSequenceID = null;
+ if (internalSequenceBean!=null)
+ internalSequenceID = internalSequenceBean.getValue();
+
+ SequencePropertyBean completedMessagesBean = null;
+ if (internalSequenceID!=null)
+ completedMessagesBean = seqPropMgr.retrieve(internalSequenceID,Sandesha2Constants.SequenceProperties.CLIENT_COMPLETED_MESSAGES);
+
+ if (completedMessagesBean==null)
+ completedMessagesBean = seqPropMgr.retrieve(sequenceID,Sandesha2Constants.SequenceProperties.CLIENT_COMPLETED_MESSAGES);
+
+ ArrayList completedMsgList = null;
+ if (completedMessagesBean!=null) {
+ completedMsgList = SandeshaUtil.getArrayListFromString(completedMessagesBean.getValue());
+ } else {
+ String message = "Completed messages bean is null, for the sequence " + sequenceID;
+ throw new SandeshaException (message);
+ }
+
+ return completedMsgList;
+ }
+
+ public static ArrayList getServerCompletedMessagesList (String sequenceID,SequencePropertyBeanMgr seqPropMgr) throws SandeshaException {
+
+ SequencePropertyBean completedMessagesBean = null;
+
+ completedMessagesBean = seqPropMgr.retrieve(sequenceID,Sandesha2Constants.SequenceProperties.SERVER_COMPLETED_MESSAGES);
+
+ ArrayList completedMsgList = null;
+ if (completedMessagesBean!=null) {
+ completedMsgList = SandeshaUtil.getArrayListFromMsgsString (completedMessagesBean.getValue());
+ } else {
+ String message = "Completed messages bean is null, for the sequence " + sequenceID;
+ throw new SandeshaException (message);
+ }
+
+ return completedMsgList;
+ }
+
+ public static RMMsgContext generateAckMessage (RMMsgContext referenceRMMessage, String sequenceID, StorageManager storageManager)throws SandeshaException {
+
+ MessageContext referenceMsg = referenceRMMessage.getMessageContext();
+
+ ConfigurationContext configurationContext = referenceRMMessage.getMessageContext().getConfigurationContext();
+ SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropretyBeanMgr();
+
+ //Setting the ack depending on AcksTo.
+ SequencePropertyBean acksToBean = seqPropMgr.retrieve(sequenceID,
+ Sandesha2Constants.SequenceProperties.ACKS_TO_EPR);
+
+ EndpointReference acksTo = new EndpointReference(acksToBean.getValue());
+ String acksToStr = acksTo.getAddress();
+
+ if (acksToStr == null)
+ throw new SandeshaException(
+ "acksToStr Seqeunce property is not set correctly");
+
+ AxisOperation ackOperation = null;
+
+ try {
+ ackOperation = AxisOperationFactory.getOperationDescription(AxisOperationFactory.MEP_URI_IN_ONLY);
+ } catch (AxisFault e) {
+ throw new SandeshaException("Could not create the Operation");
+ }
+
+ AxisOperation rmMsgOperation = referenceRMMessage.getMessageContext()
+ .getAxisOperation();
+ if (rmMsgOperation != null) {
+ ArrayList outFlow = rmMsgOperation.getPhasesOutFlow();
+ if (outFlow != null) {
+ ackOperation.setPhasesOutFlow(outFlow);
+ ackOperation.setPhasesOutFaultFlow(outFlow);
+ }
+ }
+
+ MessageContext ackMsgCtx = SandeshaUtil.createNewRelatedMessageContext(
+ referenceRMMessage, ackOperation);
+ ackMsgCtx.setProperty(AddressingConstants.WS_ADDRESSING_VERSION,
+ referenceMsg.getProperty(AddressingConstants.WS_ADDRESSING_VERSION)); //TODO do this in the RMMsgCreator
+
+
+ ackMsgCtx.setProperty(Sandesha2Constants.APPLICATION_PROCESSING_DONE,"true");
+
+ RMMsgContext ackRMMsgCtx = MsgInitializer.initializeMessage(ackMsgCtx);
+ ackRMMsgCtx.setRMNamespaceValue(referenceRMMessage.getRMNamespaceValue());
+
+ ackMsgCtx.setMessageID(SandeshaUtil.getUUID());
+
+ SOAPFactory factory = SOAPAbstractFactory.getSOAPFactory(SandeshaUtil
+ .getSOAPVersion(referenceMsg.getEnvelope()));
+
+ //Setting new envelope
+ SOAPEnvelope envelope = factory.getDefaultEnvelope();
+ try {
+ ackMsgCtx.setEnvelope(envelope);
+ } catch (AxisFault e3) {
+ throw new SandeshaException(e3.getMessage());
+ }
+
+ ackMsgCtx.setTo(acksTo);
+
+ //adding the SequenceAcknowledgement part.
+ RMMsgCreator.addAckMessage(ackRMMsgCtx, sequenceID,storageManager);
+
+ ackMsgCtx.setProperty(MessageContext.TRANSPORT_IN,null);
+
+ String addressingNamespaceURI = SandeshaUtil.getSequenceProperty(sequenceID,Sandesha2Constants.SequenceProperties.ADDRESSING_NAMESPACE_VALUE,storageManager);
+ String anonymousURI = SpecSpecificConstants.getAddressingAnonymousURI(addressingNamespaceURI);
+
+ ackMsgCtx.setProperty(AddressingConstants.WS_ADDRESSING_VERSION,addressingNamespaceURI);
+
+ if (anonymousURI.equals(acksTo.getAddress())) {
+
+// AxisEngine engine = new AxisEngine(ackRMMsgCtx.getMessageContext()
+// .getConfigurationContext());
+
+ //setting CONTEXT_WRITTEN since acksto is anonymous
+ if (referenceRMMessage.getMessageContext().getOperationContext() == null) {
+ //operation context will be null when doing in a GLOBAL
+ // handler.
+ try {
+ AxisOperation op = AxisOperationFactory
+ .getAxisOperation(AxisOperationFactory.MEP_CONSTANT_IN_OUT);
+ OperationContext opCtx = new OperationContext(op);
+ referenceRMMessage.getMessageContext().setAxisOperation(op);
+ referenceRMMessage.getMessageContext().setOperationContext(opCtx);
+ } catch (AxisFault e2) {
+ throw new SandeshaException(e2.getMessage());
+ }
+ }
+
+ referenceRMMessage.getMessageContext().getOperationContext().setProperty(
+ org.apache.axis2.Constants.RESPONSE_WRITTEN,
+ Constants.VALUE_TRUE);
+
+ referenceRMMessage.getMessageContext().setProperty(
+ Sandesha2Constants.ACK_WRITTEN, "true");
+
+ ackRMMsgCtx.getMessageContext().setServerSide(true);
+ return ackRMMsgCtx;
+
+ } else {
+
+/// Transaction asyncAckTransaction = storageManager.getTransaction();
+
+ SenderBeanMgr retransmitterBeanMgr = storageManager
+ .getRetransmitterBeanMgr();
+
+ String key = SandeshaUtil.getUUID();
+
+ SenderBean ackBean = new SenderBean();
+ ackBean.setMessageContextRefKey(key);
+ ackBean.setMessageID(ackMsgCtx.getMessageID());
+ ackBean.setReSend(false);
+ ackBean.setSequenceID(sequenceID);
+
+ //this will be set to true in the sender.
+ ackBean.setSend(true);
+
+ ackMsgCtx.setProperty(Sandesha2Constants.QUALIFIED_FOR_SENDING,
+ Sandesha2Constants.VALUE_FALSE);
+
+ ackBean.setMessageType(Sandesha2Constants.MessageTypes.ACK);
+ long ackInterval = SandeshaUtil.getPropertyBean(referenceMsg.getAxisOperation()).getAcknowledgementInaterval();
+
+ //Ack will be sent as stand alone, only after the retransmitter
+ // interval.
+ long timeToSend = System.currentTimeMillis() + ackInterval;
+
+ //removing old acks.
+ SenderBean findBean = new SenderBean();
+ findBean.setMessageType(Sandesha2Constants.MessageTypes.ACK);
+
+ //this will be set to true in the sandesha2TransportSender.
+ findBean.setSend(true);
+ findBean.setReSend(false);
+ Collection coll = retransmitterBeanMgr.find(findBean);
+ Iterator it = coll.iterator();
+
+ if (it.hasNext()) {
+ SenderBean oldAckBean = (SenderBean) it.next();
+ timeToSend = oldAckBean.getTimeToSend(); //If there is an old ack. This ack will be sent in the old timeToSend.
+
+ //removing the retransmitted entry for the oldAck
+ retransmitterBeanMgr.delete(oldAckBean.getMessageID());
+
+ //removing the message store entry for the old ack
+ storageManager.removeMessageContext(oldAckBean.getMessageContextRefKey());
+ }
+
+ ackBean.setTimeToSend(timeToSend);
+ storageManager.storeMessageContext(key,ackMsgCtx);
+
+ //inserting the new ack.
+ retransmitterBeanMgr.insert(ackBean);
+/// asyncAckTransaction.commit();
+
+ //passing the message through sandesha2sender
+ ackMsgCtx.setProperty(Sandesha2Constants.ORIGINAL_TRANSPORT_OUT_DESC,ackMsgCtx.getTransportOut());
+ ackMsgCtx.setProperty(Sandesha2Constants.SET_SEND_TO_TRUE,Sandesha2Constants.VALUE_TRUE);
+ ackMsgCtx.setProperty(Sandesha2Constants.MESSAGE_STORE_KEY,key);
+ ackMsgCtx.setTransportOut(new Sandesha2TransportOutDesc ());
+ RMMsgContext ackRMMessageCtx = MsgInitializer.initializeMessage(ackMsgCtx);
+
+ SandeshaUtil.startSenderForTheSequence(configurationContext,sequenceID);
+ referenceMsg.pause();
+ return ackRMMessageCtx;
+ }
+ }
+
+ public static boolean verifySequenceCompletion(Iterator ackRangesIterator,
+ long lastMessageNo) {
+ HashMap startMap = new HashMap();
+
+ while (ackRangesIterator.hasNext()) {
+ AcknowledgementRange temp = (AcknowledgementRange) ackRangesIterator
+ .next();
+ startMap.put(new Long(temp.getLowerValue()), temp);
+ }
+
+ long start = 1;
+ boolean loop = true;
+ while (loop) {
+ AcknowledgementRange temp = (AcknowledgementRange) startMap
+ .get(new Long(start));
+ if (temp == null) {
+ loop = false;
+ continue;
+ }
+
+ if (temp.getUpperValue() >= lastMessageNo)
+ return true;
+
+ start = temp.getUpperValue() + 1;
+ }
+
+ return false;
+ }
+}
\ No newline at end of file
Added: webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/FaultManager.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/FaultManager.java?rev=414476&view=auto
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/FaultManager.java (added)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/FaultManager.java Wed Jun 14 22:51:15 2006
@@ -0,0 +1,490 @@
+/*
+ * 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.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+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.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.OperationContext;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.context.ServiceGroupContext;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisOperationFactory;
+import org.apache.axis2.util.Utils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.sandesha2.FaultData;
+import org.apache.sandesha2.RMMsgContext;
+import org.apache.sandesha2.Sandesha2Constants;
+import org.apache.sandesha2.SandeshaException;
+import org.apache.sandesha2.msgprocessors.AcknowledgementProcessor;
+import org.apache.sandesha2.storage.StorageManager;
+import org.apache.sandesha2.storage.beanmanagers.CreateSeqBeanMgr;
+import org.apache.sandesha2.storage.beanmanagers.NextMsgBeanMgr;
+import org.apache.sandesha2.storage.beanmanagers.SequencePropertyBeanMgr;
+import org.apache.sandesha2.storage.beans.CreateSeqBean;
+import org.apache.sandesha2.storage.beans.NextMsgBean;
+import org.apache.sandesha2.storage.beans.SequencePropertyBean;
+import org.apache.sandesha2.wsrm.AcknowledgementRange;
+import org.apache.sandesha2.wsrm.CreateSequence;
+import org.apache.sandesha2.wsrm.Sequence;
+import org.apache.sandesha2.wsrm.SequenceAcknowledgement;
+
+/**
+ * Has logic to check for possible RM related faults and create it.
+ *
+ * @author Chamikara Jayalath <ch...@gmail.com>
+ * @author Sanka Samaranayaka <ss...@gmail.com>
+ */
+
+public class FaultManager {
+
+ private static final Log log = LogFactory.getLog(FaultManager.class);
+
+ public FaultManager() {
+ }
+
+ /**
+ * Check weather the CreateSequence should be refused and generate the fault if it should.
+ *
+ * @param messageContext
+ * @return
+ * @throws SandeshaException
+ */
+ public RMMsgContext checkForCreateSequenceRefused(
+ MessageContext createSequenceMessage, StorageManager storageManager) throws SandeshaException {
+
+ if (log.isDebugEnabled())
+ log.debug("Enter: FaultManager::checkForCreateSequenceRefused");
+
+ RMMsgContext createSequenceRMMsg = MsgInitializer
+ .initializeMessage(createSequenceMessage);
+
+ CreateSequence createSequence = (CreateSequence) createSequenceRMMsg
+ .getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ);
+ if (createSequence == null)
+ throw new SandeshaException(
+ "Passed message does not have a CreateSequence part");
+
+ ConfigurationContext context = createSequenceMessage.getConfigurationContext();
+ if (storageManager == null)
+ throw new SandeshaException("Storage Manager is null");
+
+ boolean refuseSequence = false;
+ String reason = "";
+
+ if (refuseSequence) {
+ FaultData data = new FaultData();
+ data.setType(Sandesha2Constants.SOAPFaults.FaultType.CREATE_SEQUENCE_REFUSED);
+ int SOAPVersion = SandeshaUtil.getSOAPVersion(createSequenceRMMsg.getSOAPEnvelope());
+ if (SOAPVersion == Sandesha2Constants.SOAPVersion.v1_1)
+ data.setCode(SOAP11Constants.FAULT_CODE_SENDER);
+ else
+ data.setCode(SOAP12Constants.FAULT_CODE_SENDER);
+
+ data.setSubcode(Sandesha2Constants.SOAPFaults.Subcodes.CREATE_SEQUENCE_REFUSED);
+ data.setReason(reason);
+ if (log.isDebugEnabled())
+ log.debug("Exit: FaultManager::checkForCreateSequenceRefused, refused sequence");
+ return getFault(createSequenceRMMsg, data,createSequenceRMMsg.getAddressingNamespaceValue(),storageManager);
+ }
+
+ if (log.isDebugEnabled())
+ log.debug("Exit: FaultManager::checkForCreateSequenceRefused");
+ return null;
+
+ }
+
+ /**
+ * Check weather the LastMessage number has been exceeded and generate the fault if it is.
+ *
+ * @param msgCtx
+ * @return
+ */
+ public RMMsgContext checkForLastMsgNumberExceeded(RMMsgContext applicationRMMessage, StorageManager storageManager) throws SandeshaException {
+ if (log.isDebugEnabled())
+ log.debug("Enter: FaultManager::checkForLastMsgNumberExceeded");
+ Sequence sequence = (Sequence) applicationRMMessage.getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
+ long messageNumber = sequence.getMessageNumber().getMessageNumber();
+ String sequenceID = sequence.getIdentifier().getIdentifier();
+
+ ConfigurationContext configCtx = applicationRMMessage.getMessageContext().getConfigurationContext();
+ SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropretyBeanMgr();
+
+ boolean lastMessageNumberExceeded = false;
+ String reason = null;
+ SequencePropertyBean lastMessageBean = seqPropMgr.retrieve(sequenceID,Sandesha2Constants.SequenceProperties.LAST_OUT_MESSAGE_NO);
+ if (lastMessageBean!=null) {
+ long lastMessageNo = Long.parseLong(lastMessageBean.getValue());
+ if (messageNumber>lastMessageNo) {
+ lastMessageNumberExceeded = true;
+ reason = "The message number of the message '" + messageNumber + "' exceeded the last message number '" + lastMessageNo + "'"+
+ "which was mentioned as last message in a previosly received application message";
+ }
+ }
+
+ if (lastMessageNumberExceeded) {
+ FaultData faultData = new FaultData ();
+ faultData.setType(Sandesha2Constants.SOAPFaults.FaultType.LAST_MESSAGE_NO_EXCEEDED);
+ int SOAPVersion = SandeshaUtil.getSOAPVersion(applicationRMMessage.getSOAPEnvelope());
+ if (SOAPVersion == Sandesha2Constants.SOAPVersion.v1_1)
+ faultData.setCode(SOAP11Constants.FAULT_CODE_SENDER);
+ else
+ faultData.setCode(SOAP12Constants.FAULT_CODE_SENDER);
+
+ faultData.setSubcode(Sandesha2Constants.SOAPFaults.Subcodes.LAST_MESSAGE_NO_EXCEEDED);
+ faultData.setReason(reason);
+ if (log.isDebugEnabled())
+ log.debug("Exit: FaultManager::checkForLastMsgNumberExceeded, lastMessageNumberExceeded");
+ return getFault(applicationRMMessage, faultData, applicationRMMessage.getAddressingNamespaceValue(),storageManager);
+ }
+
+ if (log.isDebugEnabled())
+ log.debug("Exit: FaultManager::checkForLastMsgNumberExceeded");
+ return null;
+ }
+
+ public RMMsgContext checkForMessageNumberRoleover(
+ MessageContext messageContext) {
+ return null;
+ }
+
+ /**
+ * Check whether a Sequence message (a) belongs to a unknown sequence
+ * (generates an UnknownSequence fault) (b) message number exceeds a
+ * predifined limit ( genenrates a Message Number Rollover fault)
+ *
+ * @param msgCtx
+ * @return @throws
+ * SandeshaException
+ */
+ public RMMsgContext checkForUnknownSequence(RMMsgContext rmMessageContext, String sequenceID, StorageManager storageManager)
+ throws SandeshaException {
+ if (log.isDebugEnabled())
+ log.debug("Enter: FaultManager::checkForUnknownSequence, " + sequenceID);
+
+ MessageContext messageContext = rmMessageContext.getMessageContext();
+ ConfigurationContext configCtx = messageContext.getConfigurationContext();
+
+ CreateSeqBeanMgr createSeqMgr = storageManager.getCreateSeqBeanMgr();
+ int type = rmMessageContext.getMessageType();
+
+ boolean validSequence = true;
+ String reason = null;
+
+ if (type==Sandesha2Constants.MessageTypes.ACK ||
+ type==Sandesha2Constants.MessageTypes.CREATE_SEQ_RESPONSE ||
+ type==Sandesha2Constants.MessageTypes.TERMINATE_SEQ_RESPONSE ||
+ type==Sandesha2Constants.MessageTypes.CLOSE_SEQUENCE_RESPONSE) {
+
+ CreateSeqBean createSeqFindBean = new CreateSeqBean ();
+ createSeqFindBean.setSequenceID(sequenceID);
+
+ Collection coll = createSeqMgr.find(createSeqFindBean);
+ if (coll.size()==0) {
+ validSequence = false;
+ }
+
+ } else {
+ NextMsgBeanMgr mgr = storageManager.getNextMsgBeanMgr();
+ SOAPEnvelope envelope = messageContext.getEnvelope();
+
+ Collection coll = mgr.retrieveAll();
+ Iterator it = coll.iterator();
+
+ boolean contains = false;
+ while (it.hasNext()) {
+ NextMsgBean nextMsgBean = (NextMsgBean) it.next();
+ String tempId = nextMsgBean.getSequenceID();
+ if (tempId.equals(sequenceID)) {
+ contains = true;
+ break;
+ }
+ }
+
+ if (contains)
+ validSequence = true;
+ }
+
+ String rmNamespaceValue = rmMessageContext.getRMNamespaceValue();
+
+ if (!validSequence) {
+
+ if (log.isDebugEnabled())
+ log.debug("Sequence not valid " + sequenceID);
+
+ //Return an UnknownSequence error
+ int SOAPVersion = SandeshaUtil.getSOAPVersion(messageContext.getEnvelope());
+
+ FaultData data = new FaultData();
+ if (SOAPVersion == Sandesha2Constants.SOAPVersion.v1_1)
+ data.setCode(SOAP11Constants.FAULT_CODE_SENDER);
+ else
+ data.setCode(SOAP12Constants.FAULT_CODE_SENDER);
+
+ data.setSubcode(Sandesha2Constants.SOAPFaults.Subcodes.UNKNOWN_SEQUENCE);
+
+ SOAPFactory factory = SOAPAbstractFactory.getSOAPFactory(SOAPVersion);
+// Identifier identifier = new Identifier(factory,rmNamespaceValue);
+// identifier.setIndentifer(sequenceID);
+// OMElement identifierOMElem = identifier.getOMElement();
+
+ OMElement identifierElement = factory.createOMElement(Sandesha2Constants.WSRM_COMMON.IDENTIFIER,rmNamespaceValue, Sandesha2Constants.WSRM_COMMON.NS_PREFIX_RM);
+ data.setDetail(identifierElement);
+
+ data.setReason("A sequence with the given sequenceID has NOT been established");
+
+ if (log.isDebugEnabled())
+ log.debug("Exit: FaultManager::checkForUnknownSequence");
+
+ return getFault(rmMessageContext, data,rmMessageContext.getAddressingNamespaceValue(),storageManager);
+ }
+
+ if (log.isDebugEnabled())
+ log.debug("Exit: FaultManager::checkForUnknownSequence");
+ return null;
+ }
+
+ /**
+ * Check weather the Acknowledgement is invalid and generate a fault if it is.
+ *
+ * @param msgCtx
+ * @return @throws
+ * SandeshaException
+ */
+ public RMMsgContext checkForInvalidAcknowledgement(RMMsgContext ackRMMessageContext,StorageManager storageManager)
+ throws SandeshaException {
+ if (log.isDebugEnabled())
+ log.debug("Enter: FaultManager::checkForInvalidAcknowledgement");
+
+ //check lower<=upper
+ //TODO acked for not-send message
+
+ MessageContext ackMessageContext = ackRMMessageContext.getMessageContext();
+ if (ackRMMessageContext.getMessageType() != Sandesha2Constants.MessageTypes.ACK) {
+ if (log.isDebugEnabled())
+ log.debug("Exit: FaultManager::checkForInvalidAcknowledgement, MessageType not an ACK");
+ return null;
+ }
+
+ boolean invalidAck = false;
+ String reason = null;
+ SequenceAcknowledgement sequenceAcknowledgement = (SequenceAcknowledgement) ackRMMessageContext
+ .getMessagePart(Sandesha2Constants.MessageParts.SEQ_ACKNOWLEDGEMENT);
+ List sequenceAckList = sequenceAcknowledgement
+ .getAcknowledgementRanges();
+ Iterator it = sequenceAckList.iterator();
+
+ while (it.hasNext()) {
+ AcknowledgementRange acknowledgementRange = (AcknowledgementRange) it
+ .next();
+ long upper = acknowledgementRange.getUpperValue();
+ long lower = acknowledgementRange.getLowerValue();
+
+ if (lower > upper) {
+ invalidAck = true;
+ reason = "The SequenceAcknowledgement is invalid. Lower value is larger than upper value";
+
+ }
+ }
+
+ if (invalidAck) {
+ FaultData data = new FaultData();
+ int SOAPVersion = SandeshaUtil.getSOAPVersion(ackMessageContext.getEnvelope());
+ if (SOAPVersion == Sandesha2Constants.SOAPVersion.v1_1)
+ data.setCode(SOAP11Constants.FAULT_CODE_SENDER);
+ else
+ data.setCode(SOAP12Constants.FAULT_CODE_SENDER);
+
+ data.setSubcode(Sandesha2Constants.SOAPFaults.Subcodes.INVALID_ACKNOWLEDGEMENT);
+ data.setReason(reason);
+
+ SOAPFactory factory = SOAPAbstractFactory.getSOAPFactory(SOAPVersion);
+ OMElement dummyElement = factory.createOMElement("dummyElem",null);
+ sequenceAcknowledgement.toOMElement(dummyElement);
+
+ OMElement sequenceAckElement = dummyElement.getFirstChildWithName(
+ new QName (Sandesha2Constants.WSRM_COMMON.SEQUENCE_ACK));
+ data.setDetail(sequenceAckElement);
+
+ if (log.isDebugEnabled())
+ log.debug("Exit: FaultManager::checkForInvalidAcknowledgement, invalid ACK");
+ return getFault(ackRMMessageContext, data,ackRMMessageContext.getAddressingNamespaceValue(),storageManager);
+ }
+
+ if (log.isDebugEnabled())
+ log.debug("Exit: FaultManager::checkForInvalidAcknowledgement");
+ return null;
+ }
+
+ public RMMsgContext checkForSequenceClosed ( RMMsgContext referenceRMMessage, String sequenceID, StorageManager storageManager) throws SandeshaException {
+ if (log.isDebugEnabled())
+ log.debug("Enter: FaultManager::checkForSequenceClosed, " + sequenceID);
+
+ MessageContext referenceMessage = referenceRMMessage.getMessageContext();
+ ConfigurationContext configCtx = referenceMessage.getConfigurationContext();
+
+ SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropretyBeanMgr();
+
+ boolean sequenceClosed = false;
+ String reason = null;
+ SequencePropertyBean sequenceClosedBean = seqPropMgr.retrieve(sequenceID,Sandesha2Constants.SequenceProperties.SEQUENCE_CLOSED);
+ if (sequenceClosedBean!=null && Sandesha2Constants.VALUE_TRUE.equals(sequenceClosedBean.getValue())) {
+ sequenceClosed = true;
+ reason = "The sequence with the id " + sequenceID + " was closed previously. Cannot accept this message";
+ }
+
+ if (sequenceClosed) {
+ FaultData data = new FaultData();
+ int SOAPVersion = SandeshaUtil.getSOAPVersion(referenceMessage.getEnvelope());
+ if (SOAPVersion == Sandesha2Constants.SOAPVersion.v1_1)
+ data.setCode(SOAP11Constants.FAULT_CODE_SENDER);
+ else
+ data.setCode(SOAP12Constants.FAULT_CODE_SENDER);
+
+ data.setSubcode(Sandesha2Constants.SOAPFaults.Subcodes.SEQUENCE_CLOSED);
+ data.setReason(reason);
+
+ if (log.isDebugEnabled())
+ log.debug("Exit: FaultManager::checkForSequenceClosed, sequence closed");
+ return getFault(referenceRMMessage, data, referenceRMMessage.getAddressingNamespaceValue(),storageManager);
+ }
+
+ if (log.isDebugEnabled())
+ log.debug("Exit: FaultManager::checkForSequenceClosed");
+ return null;
+
+ }
+
+ /**
+ * Returns a RMMessageContext for the fault message. Data for generating the fault is given in the data parameter.
+ *
+ * @param referenceRMMsgContext
+ * @param data
+ * @return
+ * @throws SandeshaException
+ */
+ public RMMsgContext getFault(RMMsgContext referenceRMMsgContext,
+ FaultData data, String addressingNamespaceURI,StorageManager storageManager) throws SandeshaException {
+ if (log.isDebugEnabled())
+ log.debug("Enter: FaultManager::getFault");
+
+ try {
+ MessageContext referenceMessage = referenceRMMsgContext.getMessageContext();
+ ConfigurationContext configCtx = referenceRMMsgContext.getConfigurationContext();
+
+ //This is to hack to remove NPE. TODO remove this.
+ if (referenceMessage.getServiceGroupContext()==null) {
+ ServiceGroupContext serviceGroupContext = new ServiceGroupContext (referenceMessage.getConfigurationContext(),referenceMessage.getAxisServiceGroup());
+ referenceMessage.setServiceGroupContext(serviceGroupContext);
+ }
+ if (referenceMessage.getServiceContext()==null) {
+ ServiceContext serviceContext = new ServiceContext (
+ referenceMessage.getAxisService(),
+ referenceMessage.getServiceGroupContext());
+ referenceMessage.setServiceContext(serviceContext);
+ }
+
+ //end hack
+
+
+ MessageContext faultMsgContext = Utils
+ .createOutMessageContext(referenceMessage);
+
+ //setting contexts.
+ faultMsgContext.setAxisServiceGroup(referenceMessage
+ .getAxisServiceGroup());
+ faultMsgContext.setAxisService(referenceMessage.getAxisService());
+ faultMsgContext.setAxisServiceGroup(referenceMessage
+ .getAxisServiceGroup());
+ faultMsgContext.setServiceGroupContext(referenceMessage
+ .getServiceGroupContext());
+ faultMsgContext.setServiceGroupContextId(referenceMessage
+ .getServiceGroupContextId());
+ faultMsgContext.setServiceContext(referenceMessage
+ .getServiceContext());
+ faultMsgContext.setServiceContextID(referenceMessage
+ .getServiceContextID());
+
+ AxisOperation operation = AxisOperationFactory
+ .getAxisOperation(AxisOperationFactory.MEP_CONSTANT_OUT_ONLY);
+
+ OperationContext operationContext = new OperationContext(operation);
+
+ faultMsgContext.setAxisOperation(operation);
+ faultMsgContext.setOperationContext(operationContext);
+
+ String acksToStr = null;
+ if (referenceRMMsgContext.getMessageType() == Sandesha2Constants.MessageTypes.CREATE_SEQ) {
+ CreateSequence createSequence = (CreateSequence) referenceRMMsgContext
+ .getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ);
+ acksToStr = createSequence.getAcksTo().getAddress().getEpr()
+ .getAddress();
+ } else {
+ SequencePropertyBeanMgr seqPropMgr = storageManager
+ .getSequencePropretyBeanMgr();
+
+ //TODO get the acksTo value using the property key.
+
+ String sequenceId = data.getSequenceId();
+ SequencePropertyBean acksToBean = seqPropMgr.retrieve(
+ sequenceId, Sandesha2Constants.SequenceProperties.ACKS_TO_EPR);
+ if (acksToBean != null) {
+ EndpointReference epr = new EndpointReference (acksToBean
+ .getValue());
+ if (epr != null)
+ acksToStr = epr.getAddress();
+ }
+ }
+
+ String anonymousURI = SpecSpecificConstants.getAddressingAnonymousURI(addressingNamespaceURI);
+
+ if (acksToStr != null
+ && !acksToStr.equals(anonymousURI)) {
+ faultMsgContext.setTo(new EndpointReference(acksToStr));
+ }
+
+ int SOAPVersion = SandeshaUtil.getSOAPVersion(referenceMessage.getEnvelope());
+ SOAPFaultEnvelopeCreator.addSOAPFaultEnvelope(faultMsgContext,SOAPVersion, data,referenceRMMsgContext.getRMNamespaceValue());
+
+ RMMsgContext faultRMMsgCtx = MsgInitializer.initializeMessage(faultMsgContext);
+
+ if (log.isDebugEnabled())
+ log.debug("Exit: FaultManager::getFault");
+ return faultRMMsgCtx;
+
+ } catch (AxisFault e) {
+ throw new SandeshaException(e.getMessage());
+ }
+ }
+
+
+
+}
Added: webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/MessageRetransmissionAdjuster.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/MessageRetransmissionAdjuster.java?rev=414476&view=auto
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/MessageRetransmissionAdjuster.java (added)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/MessageRetransmissionAdjuster.java Wed Jun 14 22:51:15 2006
@@ -0,0 +1,146 @@
+/*
+ * 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.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+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.SandeshaClient;
+import org.apache.sandesha2.client.SandeshaClientConstants;
+import org.apache.sandesha2.client.SandeshaListener;
+import org.apache.sandesha2.client.SequenceReport;
+import org.apache.sandesha2.storage.StorageManager;
+import org.apache.sandesha2.storage.beans.SenderBean;
+
+/**
+ * This is used to adjust retransmission infoamation after each time the message is sent.
+ *
+ * @author Chamikara Jayalath <ch...@gmail.com>
+ */
+
+public class MessageRetransmissionAdjuster {
+
+ private static final Log log = LogFactory.getLog(MessageRetransmissionAdjuster.class);
+
+ public boolean adjustRetransmittion(
+ SenderBean retransmitterBean,ConfigurationContext configContext,StorageManager storageManager) throws SandeshaException {
+
+ String storedKey = (String) retransmitterBean.getMessageContextRefKey();
+
+ if (storedKey == null)
+ throw new SandeshaException ("Stored Key not present in the retransmittable message");
+
+ MessageContext messageContext = storageManager.retrieveMessageContext(storedKey,configContext);
+ RMMsgContext rmMsgCtx = MsgInitializer.initializeMessage(messageContext);
+
+ String internalSequenceID = retransmitterBean.getInternalSequenceID();
+ String sequenceID = retransmitterBean.getSequenceID();
+
+ //operation is the lowest level Sandesha2 could be attached.
+ SandeshaPropertyBean propertyBean = SandeshaUtil.getPropertyBean(messageContext.getAxisOperation());
+
+ retransmitterBean.setSentCount(retransmitterBean.getSentCount() + 1);
+ adjustNextRetransmissionTime(retransmitterBean, propertyBean);
+
+ int maxRetransmissionAttempts = propertyBean.getMaximumRetransmissionCount();
+
+ boolean timeOutSequence = false;
+ if (maxRetransmissionAttempts>=0 && retransmitterBean.getSentCount() > maxRetransmissionAttempts)
+ timeOutSequence = true;
+
+ boolean sequenceTimedOut = SequenceManager.hasSequenceTimedOut(internalSequenceID, rmMsgCtx,storageManager);
+ if (sequenceTimedOut)
+ timeOutSequence = true;
+
+ boolean continueSending = true;
+ if (timeOutSequence) {
+ stopRetransmission(retransmitterBean);
+
+ //Only messages of outgoing sequences get retransmitted. So named following method according to that.
+ finalizeTimedOutSequence (internalSequenceID,sequenceID, messageContext,storageManager);
+ continueSending = false;
+ }
+
+ return continueSending;
+ }
+
+ /**
+ * This sets the next time the message has to be retransmitted. This uses the base retransmission interval
+ * and exponentialBackoff properties to calculate the correct time.
+ *
+ * @param retransmitterBean
+ * @param policyBean
+ * @return
+ */
+ private SenderBean adjustNextRetransmissionTime(
+ SenderBean retransmitterBean, SandeshaPropertyBean propertyBean) {
+
+// long lastSentTime = retransmitterBean.getTimeToSend();
+
+ int count = retransmitterBean.getSentCount();
+
+ long baseInterval = propertyBean.getRetransmissionInterval();
+
+ long newInterval = baseInterval;
+ if (propertyBean.isExponentialBackoff()) {
+ newInterval = generateNextExponentialBackedoffDifference(count,
+ baseInterval);
+ }
+
+ long newTimeToSend = 0;
+
+ long timeNow = System.currentTimeMillis();
+ newTimeToSend = timeNow + newInterval;
+
+ retransmitterBean.setTimeToSend(newTimeToSend);
+
+ return retransmitterBean;
+ }
+
+ private void stopRetransmission(SenderBean bean) {
+ bean.setSend(false);
+ }
+
+ private long generateNextExponentialBackedoffDifference(int count,
+ long initialInterval) {
+ long interval = initialInterval;
+ for (int i = 1; i < count; i++) {
+ interval = interval * 2;
+ }
+
+ return interval;
+ }
+
+ private void finalizeTimedOutSequence (String internalSequenceID, String sequenceID ,MessageContext messageContext,StorageManager storageManager) throws SandeshaException {
+ ConfigurationContext configurationContext = messageContext.getConfigurationContext();
+
+ configurationContext.setProperty(Sandesha2Constants.WITHIN_TRANSACTION,messageContext.getProperty(Sandesha2Constants.WITHIN_TRANSACTION));
+ SequenceReport report = SandeshaClient.getOutgoingSequenceReport(internalSequenceID ,configurationContext);
+ TerminateManager.timeOutSendingSideSequence(configurationContext,internalSequenceID, false,storageManager);
+
+ SandeshaListener listener = (SandeshaListener) messageContext.getProperty(SandeshaClientConstants.SANDESHA_LISTENER);
+ if (listener!=null) {
+ listener.onTimeOut(report);
+ }
+ }
+
+}
\ No newline at end of file
Added: webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/MsgInitializer.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/MsgInitializer.java?rev=414476&view=auto
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/MsgInitializer.java (added)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/MsgInitializer.java Wed Jun 14 22:51:15 2006
@@ -0,0 +1,239 @@
+/*
+ * 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.axis2.addressing.AddressingConstants;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.engine.AxisConfiguration;
+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.wsrm.AckRequested;
+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.RMElements;
+import org.apache.sandesha2.wsrm.Sequence;
+import org.apache.sandesha2.wsrm.SequenceAcknowledgement;
+import org.apache.sandesha2.wsrm.TerminateSequence;
+import org.apache.sandesha2.wsrm.TerminateSequenceResponse;
+
+/**
+ * This class is used to create an RMMessageContext out of an MessageContext.
+ *
+ * @author Chamikara Jayalath <ch...@gmail.com>
+ */
+
+public class MsgInitializer {
+
+ /**
+ * Called to create a rmMessageContext out of an message context. Finds out things like rm version and message type
+ * as well.
+ *
+ * @param ctx
+ * @param assumedRMNamespace
+ * this is used for validation (to find out weather the rmNamespace of the current message
+ * is equal to the regietered rmNamespace of the sequence).
+ * If null validation will not happen.
+ *
+ * @return
+ * @throws SandeshaException
+ */
+ public static RMMsgContext initializeMessage(MessageContext ctx)
+ throws SandeshaException {
+ RMMsgContext rmMsgCtx = new RMMsgContext(ctx);
+
+ populateRMMsgContext(ctx, rmMsgCtx);
+ validateMessage(rmMsgCtx);
+ return rmMsgCtx;
+ }
+
+ /**
+ * Adds the message parts the the RMMessageContext.
+ *
+ * @param msgCtx
+ * @param rmMsgContext
+ */
+ private static void populateRMMsgContext(MessageContext msgCtx,
+ RMMsgContext rmMsgContext) throws SandeshaException {
+
+ //if client side and the addressing version is not set. assuming the default addressing version
+ String addressingNamespace = (String) msgCtx.getProperty(AddressingConstants.WS_ADDRESSING_VERSION);
+ if (addressingNamespace==null && !msgCtx.isServerSide())
+ addressingNamespace = AddressingConstants.Final.WSA_NAMESPACE;
+
+ RMElements elements = new RMElements(addressingNamespace);
+ elements.fromSOAPEnvelope(msgCtx.getEnvelope(), msgCtx.getWSAAction());
+
+ String rmNamespace = null;
+
+ if (elements.getCreateSequence() != null) {
+ rmMsgContext.setMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ,
+ elements.getCreateSequence());
+ rmNamespace = elements.getCreateSequence().getNamespaceValue();
+ }
+
+ if (elements.getCreateSequenceResponse() != null) {
+ rmMsgContext.setMessagePart(
+ Sandesha2Constants.MessageParts.CREATE_SEQ_RESPONSE, elements
+ .getCreateSequenceResponse());
+ rmNamespace = elements.getCreateSequenceResponse().getNamespaceValue();
+ }
+
+ if (elements.getSequence() != null) {
+ rmMsgContext.setMessagePart(Sandesha2Constants.MessageParts.SEQUENCE,
+ elements.getSequence());
+ rmNamespace = elements.getSequence().getNamespaceValue();
+ }
+
+ if (elements.getSequenceAcknowledgement() != null) {
+ rmMsgContext.setMessagePart(
+ Sandesha2Constants.MessageParts.SEQ_ACKNOWLEDGEMENT, elements
+ .getSequenceAcknowledgement());
+ rmNamespace = elements.getSequenceAcknowledgement().getNamespaceValue();
+ }
+
+ if (elements.getTerminateSequence() != null) {
+ rmMsgContext.setMessagePart(Sandesha2Constants.MessageParts.TERMINATE_SEQ,
+ elements.getTerminateSequence());
+ rmNamespace = elements.getTerminateSequence().getNamespaceValue();
+ }
+
+ if (elements.getTerminateSequenceResponse() != null) {
+ rmMsgContext.setMessagePart(Sandesha2Constants.MessageParts.TERMINATE_SEQ_RESPONSE,
+ elements.getTerminateSequenceResponse());
+ rmNamespace = elements.getTerminateSequenceResponse().getNamespaceValue();
+ }
+
+ if (elements.getAckRequested() != null) {
+ rmMsgContext.setMessagePart(Sandesha2Constants.MessageParts.ACK_REQUEST,
+ elements.getAckRequested());
+ rmNamespace = elements.getAckRequested().getNamespaceValue();
+ }
+
+ if (elements.getCloseSequence() != null) {
+ rmMsgContext.setMessagePart(Sandesha2Constants.MessageParts.CLOSE_SEQUENCE,
+ elements.getCloseSequence());
+ rmNamespace = elements.getCloseSequence().getNamespaceValue();
+ }
+
+ if (elements.getCloseSequenceResponse() != null) {
+ rmMsgContext.setMessagePart(Sandesha2Constants.MessageParts.CLOSE_SEQUENCE_RESPONSE,
+ elements.getCloseSequenceResponse());
+ rmNamespace = elements.getCloseSequenceResponse().getNamespaceValue();
+ }
+
+ rmMsgContext.setRMNamespaceValue(rmNamespace);
+
+ String addressingNamespaceValue = elements.getAddressingNamespaceValue();
+ if (addressingNamespaceValue!=null)
+ rmMsgContext.setAddressingNamespaceValue(addressingNamespaceValue);
+ }
+
+ /**
+ * This is used to validate the message.
+ * Also set an Message type. Possible types are given in the Sandesha2Constants.MessageTypes interface.
+ *
+ * @param rmMsgCtx
+ * @return
+ * @throws SandeshaException
+ */
+ private static boolean validateMessage(RMMsgContext rmMsgCtx)
+ throws SandeshaException {
+
+ ConfigurationContext configContext = rmMsgCtx.getMessageContext().getConfigurationContext();
+ AxisConfiguration axisConfiguration = configContext.getAxisConfiguration();
+ StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configContext,axisConfiguration);
+ SequencePropertyBeanMgr sequencePropertyBeanMgr = storageManager.getSequencePropretyBeanMgr();
+
+ String sequenceID = null;
+
+ CreateSequence createSequence = (CreateSequence) rmMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ);
+ CreateSequenceResponse createSequenceResponse = (CreateSequenceResponse) rmMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ_RESPONSE);
+ TerminateSequence terminateSequence = (TerminateSequence) rmMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.TERMINATE_SEQ);
+ TerminateSequenceResponse terminateSequenceResponse = (TerminateSequenceResponse) rmMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.TERMINATE_SEQ_RESPONSE);
+ SequenceAcknowledgement sequenceAcknowledgement = (SequenceAcknowledgement) rmMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.SEQ_ACKNOWLEDGEMENT);
+ Sequence sequence = (Sequence) rmMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
+ AckRequested ackRequest = (AckRequested) rmMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.ACK_REQUEST);
+ CloseSequence closeSequence = (CloseSequence) rmMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.CLOSE_SEQUENCE);
+ CloseSequenceResponse closeSequenceResponse = (CloseSequenceResponse) rmMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.CLOSE_SEQUENCE_RESPONSE);
+
+ //Setting message type.
+ if (createSequence != null) {
+ rmMsgCtx.setMessageType(Sandesha2Constants.MessageTypes.CREATE_SEQ);
+ }else if (createSequenceResponse != null) {
+ rmMsgCtx.setMessageType(Sandesha2Constants.MessageTypes.CREATE_SEQ_RESPONSE);
+ sequenceID = createSequenceResponse.getIdentifier().getIdentifier();
+ }else if (terminateSequence != null) {
+ rmMsgCtx.setMessageType(Sandesha2Constants.MessageTypes.TERMINATE_SEQ);
+ sequenceID = terminateSequence.getIdentifier().getIdentifier();
+ }else if (terminateSequenceResponse != null) {
+ rmMsgCtx.setMessageType(Sandesha2Constants.MessageTypes.TERMINATE_SEQ_RESPONSE);
+ sequenceID = terminateSequenceResponse.getIdentifier().getIdentifier();
+ }else if (rmMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE) != null) {
+ rmMsgCtx.setMessageType(Sandesha2Constants.MessageTypes.APPLICATION);
+ sequenceID = sequence.getIdentifier().getIdentifier();
+ } else if (sequenceAcknowledgement != null) {
+ rmMsgCtx.setMessageType(Sandesha2Constants.MessageTypes.ACK);
+ sequenceID = sequenceAcknowledgement.getIdentifier().getIdentifier();
+ } else if (ackRequest != null) {
+ rmMsgCtx.setMessageType(Sandesha2Constants.MessageTypes.ACK_REQUEST);
+ sequenceID = ackRequest.getIdentifier().getIdentifier();
+ } else if (closeSequence != null) {
+ rmMsgCtx.setMessageType(Sandesha2Constants.MessageTypes.CLOSE_SEQUENCE);
+ sequenceID = closeSequence.getIdentifier().getIdentifier();
+ } else if (closeSequenceResponse != null) {
+ rmMsgCtx.setMessageType(Sandesha2Constants.MessageTypes.CLOSE_SEQUENCE_RESPONSE);
+ sequenceID = closeSequenceResponse.getIdentifier().getIdentifier();
+ } else
+ rmMsgCtx.setMessageType(Sandesha2Constants.MessageTypes.UNKNOWN);
+
+ String propertyKey = null;
+ if (rmMsgCtx.getMessageContext().getFLOW()==MessageContext.IN_FLOW) {
+ propertyKey = sequenceID;
+ } else {
+ SequencePropertyBean internalSequenceIDBean = sequencePropertyBeanMgr.retrieve(sequenceID,Sandesha2Constants.SequenceProperties.INTERNAL_SEQUENCE_ID);
+ if (internalSequenceIDBean!=null) {
+ propertyKey = internalSequenceIDBean.getValue();
+ }
+ }
+
+ String rmNamespace = rmMsgCtx.getRMNamespaceValue();
+ if (sequenceID!=null) {
+ String specVersion = SandeshaUtil.getRMVersion(propertyKey,storageManager);
+
+ String sequenceRMNamespace = null;
+ if (specVersion!=null)
+ sequenceRMNamespace = SpecSpecificConstants.getRMNamespaceValue(specVersion);
+ if (sequenceRMNamespace!=null && rmNamespace!=null) {
+ if (!sequenceRMNamespace.equals(rmNamespace)) {
+ throw new SandeshaException ("Given message has rmNamespace value, which is different from the " +
+ "reqistered namespace for the sequence");
+ }
+ }
+ }
+
+ return true;
+ }
+
+}
\ No newline at end of file
Added: webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/PropertyManager.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/PropertyManager.java?rev=414476&view=auto
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/PropertyManager.java (added)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/PropertyManager.java Wed Jun 14 22:51:15 2006
@@ -0,0 +1,503 @@
+/*
+ * 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.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Properties;
+
+import org.apache.axis2.description.AxisDescription;
+import org.apache.axis2.description.AxisModule;
+import org.apache.axis2.description.Parameter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.sandesha2.Sandesha2Constants;
+import org.apache.sandesha2.SandeshaException;
+import org.apache.sandesha2.policy.PolicyEngineData;
+import org.apache.sandesha2.policy.RMPolicyProcessor;
+import org.apache.sandesha2.policy.RMProcessorContext;
+import org.apache.ws.policy.Policy;
+
+/**
+ * Loads properties from sandesha2.properties file (from Sandesha2Constants if
+ * this is not available).
+ *
+ * @author Chamikara Jayalath <ch...@gmail.com>
+ */
+
+public class PropertyManager {
+
+ private static final Log log = LogFactory.getLog(PropertyManager.class);
+
+ public static SandeshaPropertyBean loadPropertiesFromDefaultValues() throws SandeshaException{
+ SandeshaPropertyBean propertyBean = new SandeshaPropertyBean ();
+ propertyBean.setAcknowledgementInterval(Sandesha2Constants.Properties.DefaultValues.AcknowledgementInterval);
+ propertyBean.setExponentialBackoff(Sandesha2Constants.Properties.DefaultValues.ExponentialBackoff);
+ propertyBean.setInactiveTimeoutInterval(
+ Sandesha2Constants.Properties.DefaultValues.InactivityTimeout,
+ Sandesha2Constants.Properties.DefaultValues.InactivityTimeoutMeasure);
+
+ propertyBean.setInOrder(Sandesha2Constants.Properties.DefaultValues.InvokeInOrder);
+ propertyBean.setMsgTypesToDrop(null);
+ propertyBean.setRetransmissionInterval(Sandesha2Constants.Properties.DefaultValues.RetransmissionInterval);
+// propertyBean.setStorageManagerClass(Sandesha2Constants.Properties.DefaultValues.StorageManager);
+ propertyBean.setInMemoryStorageManagerClass(Sandesha2Constants.Properties.DefaultValues.InMemoryStorageManager);
+ propertyBean.setPermanentStorageManagerClass(Sandesha2Constants.Properties.DefaultValues.PermanentStorageManager);
+ propertyBean.setMaximumRetransmissionCount(Sandesha2Constants.Properties.DefaultValues.MaximumRetransmissionCount);
+
+ String msgTypesToDrop = Sandesha2Constants.Properties.DefaultValues.MessageTypesToDrop;
+ loadMessageTypesToDrop(msgTypesToDrop,propertyBean);
+
+ return propertyBean;
+ }
+
+ public static SandeshaPropertyBean loadPropertiesFromPropertyFile(InputStream in) throws SandeshaException{
+ SandeshaPropertyBean propertyBean = new SandeshaPropertyBean ();
+ try {
+ if (in == null)
+ in = Thread.currentThread().getContextClassLoader()
+ .getResourceAsStream(Sandesha2Constants.PROPERTY_FILE);
+
+ Properties properties = new Properties();
+ if (in != null) {
+ properties.load(in);
+ }
+
+ String expoBackoffStr = properties
+ .getProperty(Sandesha2Constants.Properties.ExponentialBackoff);
+ loadExponentialBackoff(expoBackoffStr,propertyBean);
+
+ String retransmissionIntStr = properties
+ .getProperty(Sandesha2Constants.Properties.RetransmissionInterval);
+ loadRetransmissionInterval(retransmissionIntStr,propertyBean);
+
+ String acknowledgementIntStr = properties
+ .getProperty(Sandesha2Constants.Properties.AcknowledgementInterval);
+ loadAcknowledgementInterval(acknowledgementIntStr,propertyBean);
+
+ String inactivityTimeoutStr = properties
+ .getProperty(Sandesha2Constants.Properties.InactivityTimeout);
+ String inactivityTimeoutMeasure = properties
+ .getProperty(Sandesha2Constants.Properties.InactivityTimeoutMeasure);
+ loadInactivityTimeout(inactivityTimeoutStr,
+ inactivityTimeoutMeasure,propertyBean);
+
+// String storageMgrClassStr = properties
+// .getProperty(Sandesha2Constants.Properties.StorageManager);
+// loadStoragemanagerClass(storageMgrClassStr,propertyBean);
+
+ String inMemoryStorageMgrClassStr = properties
+ .getProperty(Sandesha2Constants.Properties.InMemoryStorageManager);
+ loadInMemoryStoragemanagerClass(inMemoryStorageMgrClassStr,propertyBean);
+
+ String permanentStorageMgrClassStr = properties
+ .getProperty(Sandesha2Constants.Properties.PermanentStorageManager);
+ loadPermanentStoragemanagerClass(permanentStorageMgrClassStr,propertyBean);
+
+ String inOrderInvocation = properties
+ .getProperty(Sandesha2Constants.Properties.InOrderInvocation);
+ loadInOrderInvocation(inOrderInvocation,propertyBean);
+
+ String messageTypesToDrop = properties
+ .getProperty(Sandesha2Constants.Properties.MessageTypesToDrop);
+ loadMessageTypesToDrop(messageTypesToDrop,propertyBean);
+
+ } catch (IOException e) {
+ throw new SandeshaException (e);
+ }
+
+ return propertyBean;
+ }
+
+ public static SandeshaPropertyBean loadPropertiesFromModuleDesc (AxisModule desc) throws SandeshaException{
+ SandeshaPropertyBean propertyBean = new SandeshaPropertyBean ();
+
+ Parameter expoBackoffParam = desc.getParameter (Sandesha2Constants.Properties.ExponentialBackoff);
+ String expoBackoffStr = (String) expoBackoffParam.getValue();
+ loadExponentialBackoff(expoBackoffStr,propertyBean);
+
+ Parameter retransmissionIntParam = desc.getParameter (Sandesha2Constants.Properties.RetransmissionInterval);
+ String retransmissionIntStr = (String) retransmissionIntParam.getValue();
+ loadRetransmissionInterval(retransmissionIntStr,propertyBean);
+
+ Parameter acknowledgementIntParam = desc.getParameter(Sandesha2Constants.Properties.AcknowledgementInterval);
+ String acknowledgementIntStr = (String) acknowledgementIntParam.getValue();
+ loadAcknowledgementInterval(acknowledgementIntStr,propertyBean);
+
+ Parameter inactivityTimeoutParam = desc.getParameter(Sandesha2Constants.Properties.InactivityTimeout);
+ String inactivityTimeoutStr = (String) inactivityTimeoutParam.getValue();
+ Parameter inactivityTimeoutMeasureParam = desc.getParameter(Sandesha2Constants.Properties.InactivityTimeoutMeasure);
+ String inactivityTimeoutMeasure = (String) inactivityTimeoutMeasureParam.getValue();
+ loadInactivityTimeout(inactivityTimeoutStr,inactivityTimeoutMeasure,propertyBean);
+
+// Parameter storageMgrClassParam = desc.getParameter(Sandesha2Constants.Properties.StorageManager);
+// String storageMgrClassStr = (String) storageMgrClassParam.getValue();
+// loadStoragemanagerClass(storageMgrClassStr,propertyBean);
+
+ Parameter inMemoryStorageMgrClassParam = desc.getParameter(Sandesha2Constants.Properties.InMemoryStorageManager);
+ String inMemoryStorageMgrClassStr = (String) inMemoryStorageMgrClassParam.getValue();
+ loadInMemoryStoragemanagerClass(inMemoryStorageMgrClassStr,propertyBean);
+
+ Parameter permanentStorageMgrClassParam = desc.getParameter(Sandesha2Constants.Properties.PermanentStorageManager);
+ String permanentStorageMgrClassStr = (String) permanentStorageMgrClassParam.getValue();
+ loadPermanentStoragemanagerClass(permanentStorageMgrClassStr,propertyBean);
+
+ Parameter inOrderInvocationParam = desc.getParameter(Sandesha2Constants.Properties.InOrderInvocation);
+ String inOrderInvocation = (String) inOrderInvocationParam.getValue();
+ loadInOrderInvocation (inOrderInvocation,propertyBean);
+
+ Parameter messageTypesToDropParam = desc.getParameter(Sandesha2Constants.Properties.MessageTypesToDrop);
+ String messageTypesToDrop = (String) messageTypesToDropParam.getValue();
+ loadMessageTypesToDrop (messageTypesToDrop,propertyBean);
+
+ return propertyBean;
+ }
+
+ public static SandeshaPropertyBean loadPropertiesFromModuleDescPolicy(AxisModule desc, SandeshaPropertyBean parentPropertyBean) throws SandeshaException {
+ SandeshaPropertyBean propertyBean = new SandeshaPropertyBean ();
+
+ Policy policy = desc.getPolicyInclude().getEffectivePolicy();
+
+ if (policy == null) {
+ return null; //no pilicy is available in the module description
+ }
+
+ RMPolicyProcessor processor = new RMPolicyProcessor();
+
+ try {
+ processor.setup();
+ } catch (NoSuchMethodException e) {
+ throw new SandeshaException(e);
+ }
+
+ processor.processPolicy(policy);
+
+ RMProcessorContext ctx = processor.getContext();
+ PolicyEngineData data = ctx.readCurrentPolicyEngineData();
+
+
+ if (data.isAcknowledgementIntervalSet())
+ propertyBean.setAcknowledgementInterval(data.getAcknowledgementInterval());
+ else
+ propertyBean.setAcknowledgementInterval(parentPropertyBean.getAcknowledgementInaterval());
+
+ if (data.isExponentialBackoffSet())
+ propertyBean.setExponentialBackoff(data.isExponentialBackoff());
+ else
+ propertyBean.setExponentialBackoff(parentPropertyBean.isExponentialBackoff());
+
+ //Inactivity timeout given in the policy will affect only if it gives both the measure and the value.
+ //Otherwise value will be taken from the parent.
+ if (data.isInactivityTimeoutSet() && data.isInactivityTimeoutMeassureSet() )
+ propertyBean.setInactiveTimeoutInterval(data.getInactivityTimeout(),data.getInactivityTimeoutMeassure());
+ else
+ propertyBean.setInactiveTimeoutInterval(parentPropertyBean.getInactiveTimeoutInterval());
+
+ if (data.isInvokeInOrderSet())
+ propertyBean.setInOrder(data.isInvokeInOrder());
+ else
+ propertyBean.setInOrder(parentPropertyBean.isInOrder());
+
+ if (data.isMaximumRetransmissionCountSet())
+ propertyBean.setMaximumRetransmissionCount(data.getMaximumRetransmissionCount());
+ else
+ propertyBean.setMaximumRetransmissionCount(parentPropertyBean.getMaximumRetransmissionCount());
+
+ if (data.isRetransmissionIntervalSet())
+ propertyBean.setRetransmissionInterval(data.getRetransmissionInterval());
+ else
+ propertyBean.setRetransmissionInterval(parentPropertyBean.getRetransmissionInterval());
+
+// if (data.isStorageManagerSet())
+// propertyBean.setStorageManagerClass(data.getStorageManager());
+// else
+// propertyBean.setStorageManagerClass(data.getStorageManager());
+
+ if (data.isInMemoryStorageManagerSet())
+ propertyBean.setInMemoryStorageManagerClass(data.getInMemoryStorageManager());
+ else
+ propertyBean.setInMemoryStorageManagerClass(data.getInMemoryStorageManager());
+
+// if (data.isStorageManagerSet())
+// propertyBean.setStorageManagerClass(data.getStorageManager());
+// else
+// propertyBean.setStorageManagerClass(data.getStorageManager());
+
+ if (data.isInMemoryStorageManagerSet())
+ propertyBean.setInMemoryStorageManagerClass(data.getInMemoryStorageManager());
+ else
+ propertyBean.setInMemoryStorageManagerClass(data.getInMemoryStorageManager());
+
+ if (data.isPermanentStorageManagerSet())
+ propertyBean.setPermanentStorageManagerClass(data.getPermanentStorageManager());
+ else
+ propertyBean.setPermanentStorageManagerClass(data.getPermanentStorageManager());
+
+ if (data.isMessageTypesToDropSet())
+ loadMessageTypesToDrop(data.getMessageTypesToDrop(),propertyBean);
+ else
+ propertyBean.setMsgTypesToDrop(parentPropertyBean.getMsgTypesToDrop());
+
+ return propertyBean;
+ }
+
+ public static SandeshaPropertyBean loadPropertiesFromAxisDescription(AxisDescription desc, SandeshaPropertyBean parentPropertyBean)
+ throws SandeshaException {
+ SandeshaPropertyBean propertyBean = new SandeshaPropertyBean ();
+ Policy policy = desc.getPolicyInclude().getEffectivePolicy();
+
+ if (policy == null) {
+ return null; //no policy is available in this axis description
+ }
+
+ RMPolicyProcessor processor = new RMPolicyProcessor();
+
+ try {
+ processor.setup();
+ } catch (NoSuchMethodException e) {
+ throw new SandeshaException(e.getMessage());
+ }
+
+ processor.processPolicy(policy);
+
+ RMProcessorContext ctx = processor.getContext();
+ PolicyEngineData data = ctx.readCurrentPolicyEngineData();
+
+ if (data.isAcknowledgementIntervalSet())
+ propertyBean.setAcknowledgementInterval(data.getAcknowledgementInterval());
+ else
+ propertyBean.setAcknowledgementInterval(parentPropertyBean.getAcknowledgementInaterval());
+
+ if (data.isExponentialBackoffSet())
+ propertyBean.setExponentialBackoff(data.isExponentialBackoff());
+ else
+ propertyBean.setExponentialBackoff(parentPropertyBean.isExponentialBackoff());
+
+ //Inactivity timeout given in the policy will affect only if it gives both the measure and the value.
+ //Otherwise value will be taken from the parent.
+ if (data.isInactivityTimeoutSet() && data.isInactivityTimeoutMeassureSet() )
+ propertyBean.setInactiveTimeoutInterval(data.getInactivityTimeout(),data.getInactivityTimeoutMeassure());
+ else
+ propertyBean.setInactiveTimeoutInterval(parentPropertyBean.getInactiveTimeoutInterval());
+
+ if (data.isInvokeInOrderSet())
+ propertyBean.setInOrder(data.isInvokeInOrder());
+ else
+ propertyBean.setInOrder(parentPropertyBean.isInOrder());
+
+ if (data.isMaximumRetransmissionCountSet())
+ propertyBean.setMaximumRetransmissionCount(data.getMaximumRetransmissionCount());
+ else
+ propertyBean.setMaximumRetransmissionCount(parentPropertyBean.getMaximumRetransmissionCount());
+
+ if (data.isRetransmissionIntervalSet())
+ propertyBean.setRetransmissionInterval(data.getRetransmissionInterval());
+ else
+ propertyBean.setRetransmissionInterval(parentPropertyBean.getRetransmissionInterval());
+
+// if (data.isStorageManagerSet())
+// propertyBean.setStorageManagerClass(data.getStorageManager());
+// else
+// propertyBean.setStorageManagerClass(data.getStorageManager());
+
+ if (data.isInMemoryStorageManagerSet())
+ propertyBean.setInMemoryStorageManagerClass(data.getInMemoryStorageManager());
+ else
+ propertyBean.setInMemoryStorageManagerClass(data.getInMemoryStorageManager());
+
+ if (data.isPermanentStorageManagerSet())
+ propertyBean.setPermanentStorageManagerClass(data.getPermanentStorageManager());
+ else
+ propertyBean.setPermanentStorageManagerClass(data.getPermanentStorageManager());
+
+ if (data.isMessageTypesToDropSet())
+ loadMessageTypesToDrop(data.getMessageTypesToDrop(),propertyBean);
+ else
+ propertyBean.setMsgTypesToDrop(parentPropertyBean.getMsgTypesToDrop());
+
+ return propertyBean;
+ }
+
+ public static void reloadFromPropertyFile(InputStream stream) throws SandeshaException {
+ loadPropertiesFromPropertyFile(stream);
+ }
+
+ /**
+ * Loads wsp:exponentianbackoff.
+ *
+ * @param properties
+ */
+ private static void loadExponentialBackoff(String expoBackoffStr, SandeshaPropertyBean propertyBean) throws SandeshaException {
+
+ if (expoBackoffStr != null) {
+ expoBackoffStr = expoBackoffStr.trim();
+ if (expoBackoffStr.equals("true")) {
+ propertyBean.setExponentialBackoff(true);
+ } else if (expoBackoffStr.equals("false")) {
+ propertyBean.setExponentialBackoff(false);
+ }
+ }
+ }
+
+ /**
+ * Loads wsp:retransmissionInterval.
+ *
+ * @param properties
+ */
+ private static void loadRetransmissionInterval(String retransmissionIntStr, SandeshaPropertyBean propertyBean) throws SandeshaException {
+
+ if (retransmissionIntStr != null) {
+ try {
+ retransmissionIntStr = retransmissionIntStr.trim();
+ int retransmissionInterval = Integer
+ .parseInt(retransmissionIntStr);
+ if (retransmissionInterval > 0) {
+ propertyBean.setRetransmissionInterval(retransmissionInterval);
+ }
+ } catch (NumberFormatException e) {
+ String message = "Cannot derive the Acknowledgement Interval from the passed string";
+ throw new SandeshaException (message,e);
+ }
+ }
+ }
+
+ /**
+ * Loads wsp:acknowldgementInterval.
+ *
+ * @param properties
+ */
+ private static void loadAcknowledgementInterval(String acknowledgementIntStr, SandeshaPropertyBean propertyBean) throws SandeshaException {
+
+ if (acknowledgementIntStr != null) {
+ try {
+ acknowledgementIntStr = acknowledgementIntStr.trim();
+ int acknowledgementInt = Integer
+ .parseInt(acknowledgementIntStr);
+ if (acknowledgementInt > 0) {
+ propertyBean.setAcknowledgementInterval(acknowledgementInt);
+ }
+ } catch (NumberFormatException e) {
+ String message = "Cannot derive the Acknowledgement Interval from the passed string";
+ throw new SandeshaException(message,e);
+ }
+ }
+ }
+
+ /**
+ * Loads wsp:inactivityInterval.
+ *
+ * @param properties
+ */
+ private static void loadInactivityTimeout(String inactivityTimeoutStr,
+ String inactivityTimeoutMeasure, SandeshaPropertyBean propertyBean) throws SandeshaException {
+
+ if (inactivityTimeoutStr != null && inactivityTimeoutMeasure != null) {
+ try {
+ inactivityTimeoutStr = inactivityTimeoutStr.trim();
+ inactivityTimeoutMeasure = inactivityTimeoutMeasure.trim();
+
+ int inactivityTimeoutVal = Integer
+ .parseInt(inactivityTimeoutStr);
+ if (inactivityTimeoutVal > 0) {
+ propertyBean.setInactiveTimeoutInterval(
+ inactivityTimeoutVal, inactivityTimeoutMeasure);
+ }
+ } catch (NumberFormatException e) {
+ String message = "Cannot derive the Inactivity Timeout from the passed string";
+ throw new SandeshaException(message,e);
+ }
+ }
+ }
+
+// /**
+// * Loads the StorageManager class name.
+// *
+// * @param properties
+// */
+// private static void loadStoragemanagerClass(String storageMgrClassStr, SandeshaPropertyBean propertyBean) throws SandeshaException {
+// if (storageMgrClassStr != null) {
+// storageMgrClassStr = storageMgrClassStr.trim();
+// propertyBean.setStorageManagerClass(storageMgrClassStr);
+// }
+// }
+
+ /**
+ * Loads the InMemoryStorageManager class name.
+ *
+ * @param properties
+ */
+ private static void loadInMemoryStoragemanagerClass(String inMemoryStorageMgrClassStr, SandeshaPropertyBean propertyBean) throws SandeshaException {
+ if (inMemoryStorageMgrClassStr != null) {
+ inMemoryStorageMgrClassStr = inMemoryStorageMgrClassStr.trim();
+ propertyBean.setInMemoryStorageManagerClass(inMemoryStorageMgrClassStr);
+ }
+ }
+
+ /**
+ * Loads the PermanentStorageManager class name.
+ *
+ * @param properties
+ */
+ private static void loadPermanentStoragemanagerClass(String permanentStorageMgrClassStr, SandeshaPropertyBean propertyBean) throws SandeshaException {
+ if (permanentStorageMgrClassStr != null) {
+ permanentStorageMgrClassStr = permanentStorageMgrClassStr.trim();
+ propertyBean.setPermanentStorageManagerClass(permanentStorageMgrClassStr);
+ }
+ }
+
+ private static void loadInOrderInvocation(String inOrderInvocation, SandeshaPropertyBean propertyBean) throws SandeshaException {
+
+ if (inOrderInvocation != null) {
+ inOrderInvocation = inOrderInvocation.trim();
+ if (inOrderInvocation.equalsIgnoreCase("true")) {
+ propertyBean.setInOrder(true);
+ } else if (inOrderInvocation.equalsIgnoreCase("false")) {
+ propertyBean.setInOrder(false);
+ }
+ }
+ }
+
+ private static void loadMessageTypesToDrop(String messageTypesToDrop, SandeshaPropertyBean propertyBean) throws SandeshaException {
+
+ try {
+ if (messageTypesToDrop != null
+ && !Sandesha2Constants.VALUE_NONE
+ .equals(messageTypesToDrop)) {
+ messageTypesToDrop = messageTypesToDrop.trim();
+ messageTypesToDrop = "[" + messageTypesToDrop + "]";
+ ArrayList messageTypesLst = SandeshaUtil
+ .getArrayListFromString(messageTypesToDrop);
+
+ Iterator itr = messageTypesLst.iterator();
+ while (itr.hasNext()) {
+ String typeStr = (String) itr.next();
+ Integer typeNo = new Integer(typeStr);
+ propertyBean.addMsgTypeToDrop(typeNo);
+ }
+ }
+ } catch (NumberFormatException e) {
+ String message = "Property '"
+ + Sandesha2Constants.Properties.MessageTypesToDrop
+ + "' contains an invalid value.";
+ throw new SandeshaException (message,e);
+ }
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: sandesha-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: sandesha-dev-help@ws.apache.org