Added: webservices/site/trunk/targets/sandesha/sandesha2/xref/org/apache/sandesha2/storage/persistent/package-summary.html URL: http://svn.apache.org/viewcvs/webservices/site/trunk/targets/sandesha/sandesha2/xref/org/apache/sandesha2/storage/persistent/package-summary.html?rev=349924&view=auto ============================================================================== --- webservices/site/trunk/targets/sandesha/sandesha2/xref/org/apache/sandesha2/storage/persistent/package-summary.html (added) +++ webservices/site/trunk/targets/sandesha/sandesha2/xref/org/apache/sandesha2/storage/persistent/package-summary.html Wed Nov 30 03:11:01 2005 @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + Apache Sandesha2 0.9 Reference Package + + + + + + + + +
+ +
+
+ +
+ + + + + +

Package org.apache.sandesha2.storage.persistent

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Class Summary
+ PersistentCreateSeqBeanMgr +
+ PersistentInvokerBeanMgr +
+ PersistentNextMsgBeanMgr +
+ PersistentSenderBeanMgr +
+ PersistentSequencePropertyBeanMgr +
+ PersistentStorageManager +
+ TransactionImpl +
+ + + + + +
+ +
+
+ +
+ + + + + + +
+ + Copyright © 2005 Apache Web Services. All Rights Reserved. + + + Added: webservices/site/trunk/targets/sandesha/sandesha2/xref/org/apache/sandesha2/util/FaultManager.html URL: http://svn.apache.org/viewcvs/webservices/site/trunk/targets/sandesha/sandesha2/xref/org/apache/sandesha2/util/FaultManager.html?rev=349924&view=auto ============================================================================== --- webservices/site/trunk/targets/sandesha/sandesha2/xref/org/apache/sandesha2/util/FaultManager.html (added) +++ webservices/site/trunk/targets/sandesha/sandesha2/xref/org/apache/sandesha2/util/FaultManager.html Wed Nov 30 03:11:01 2005 @@ -0,0 +1,474 @@ + + + +FaultManager xref + + + +
View Javadoc
+
+1   /*
+2    * Copyright  1999-2004 The Apache Software Foundation.
+3    *
+4    *  Licensed under the Apache License, Version 2.0 (the "License");
+5    *  you may not use this file except in compliance with the License.
+6    *  You may obtain a copy of the License at
+7    *
+8    *      http://www.apache.org/licenses/LICENSE-2.0
+9    *
+10   *  Unless required by applicable law or agreed to in writing, software
+11   *  distributed under the License is distributed on an "AS IS" BASIS,
+12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+13   *  See the License for the specific language governing permissions and
+14   *  limitations under the License.
+15   *
+16   */
+17  
+18  package org.apache.sandesha2.util;
+19  
+20  import java.util.Collection;
+21  import java.util.Iterator;
+22  import java.util.List;
+23  import javax.xml.namespace.QName;
+24  import org.apache.axis2.AxisFault;
+25  import org.apache.axis2.addressing.EndpointReference;
+26  import org.apache.axis2.context.ConfigurationContext;
+27  import org.apache.axis2.context.MessageContext;
+28  import org.apache.axis2.context.OperationContext;
+29  import org.apache.axis2.description.AxisOperation;
+30  import org.apache.axis2.description.AxisOperationFactory;
+31  import org.apache.axis2.om.OMElement;
+32  import org.apache.axis2.soap.SOAP11Constants;
+33  import org.apache.axis2.soap.SOAP12Constants;
+34  import org.apache.axis2.soap.SOAPEnvelope;
+35  import org.apache.axis2.soap.SOAPFactory;
+36  import org.apache.axis2.soap.SOAPHeader;
+37  import org.apache.axis2.util.Utils;
+38  import org.apache.sandesha2.Sandesha2Constants;
+39  import org.apache.sandesha2.FaultData;
+40  import org.apache.sandesha2.RMMsgContext;
+41  import org.apache.sandesha2.SOAPFaultEnvelopeCreator;
+42  import org.apache.sandesha2.SandeshaException;
+43  import org.apache.sandesha2.storage.StorageManager;
+44  import org.apache.sandesha2.storage.beanmanagers.NextMsgBeanMgr;
+45  import org.apache.sandesha2.storage.beanmanagers.SequencePropertyBeanMgr;
+46  import org.apache.sandesha2.storage.beans.NextMsgBean;
+47  import org.apache.sandesha2.storage.beans.SequencePropertyBean;
+48  import org.apache.sandesha2.wsrm.AcknowledgementRange;
+49  import org.apache.sandesha2.wsrm.CreateSequence;
+50  import org.apache.sandesha2.wsrm.Identifier;
+51  import org.apache.sandesha2.wsrm.Sequence;
+52  import org.apache.sandesha2.wsrm.SequenceAcknowledgement;
+53  import org.apache.sandesha2.wsrm.SequenceOffer;
+54  import org.apache.sandesha2.wsrm.TerminateSequence;
+55  
+56  /***
+57   * Has logic to check for possible RM related faults and create it.
+58   * 
+59   * @author Chamikara Jayalath <chamikaramj@gmail.com>
+60   * @author Sanka Samaranayaka <ssanka@gmail.com>
+61   */
+62  
+63  public class FaultManager {
+64  
+65  	public FaultManager() {
+66  	}
+67  
+68  	public RMMsgContext checkForPossibleFaults(MessageContext msgCtx)
+69  			throws SandeshaException {
+70  
+71  		//Cannot initialize message before checking for MsgNoRoleover - since
+72  		// initialization will give an exception
+73  		//for rolled over messages.
+74  
+75  		SOAPEnvelope envelope = msgCtx.getEnvelope();
+76  		if (envelope == null)
+77  			throw new SandeshaException("SOAP Envelope is null");
+78  
+79  		RMMsgContext faultMessageContext = null;
+80  
+81  		SOAPHeader header = envelope.getHeader();
+82  		if (header != null) {
+83  			OMElement sequenceHeaderBlock = header
+84  					.getFirstChildWithName(new QName(Sandesha2Constants.WSRM.NS_URI_RM,
+85  							Sandesha2Constants.WSRM.SEQUENCE));
+86  			if (sequenceHeaderBlock != null) {
+87  				faultMessageContext = checkForMessageNumberRoleover(msgCtx);
+88  				if (faultMessageContext != null)
+89  					return faultMessageContext;
+90  			}
+91  		}
+92  
+93  		RMMsgContext rmMsgCtx = MsgInitializer.initializeMessage(msgCtx);
+94  		int msgType = rmMsgCtx.getMessageType();
+95  
+96  		if (msgType == Sandesha2Constants.MessageTypes.APPLICATION
+97  				|| msgType == Sandesha2Constants.MessageTypes.TERMINATE_SEQ) {
+98  			faultMessageContext = checkForUnknownSequence(msgCtx);
+99  			if (faultMessageContext != null)
+100 				return faultMessageContext;
+101 
+102 		}
+103 
+104 		if (msgType == Sandesha2Constants.MessageTypes.CREATE_SEQ) {
+105 			faultMessageContext = checkForCreateSequenceRefused(msgCtx);
+106 			if (faultMessageContext != null)
+107 				return faultMessageContext;
+108 		}
+109 
+110 		if (msgType == Sandesha2Constants.MessageTypes.ACK) {
+111 			faultMessageContext = checkForInvalidAcknowledgement(msgCtx);
+112 			if (faultMessageContext != null)
+113 				return faultMessageContext;
+114 		}
+115 
+116 		if (msgType == Sandesha2Constants.MessageTypes.APPLICATION) {
+117 			faultMessageContext = checkForLastMsgNumberExceeded(msgCtx);
+118 			if (faultMessageContext != null)
+119 				return faultMessageContext;
+120 		}
+121 
+122 		return faultMessageContext;
+123 
+124 	}
+125 
+126 	/***
+127 	 * Check weather the CreateSequence should be refused and generate the fault if it should.
+128 	 * 
+129 	 * @param messageContext
+130 	 * @return
+131 	 * @throws SandeshaException
+132 	 */
+133 	private RMMsgContext checkForCreateSequenceRefused(
+134 			MessageContext messageContext) throws SandeshaException {
+135 
+136 		RMMsgContext rmMsgCtx = MsgInitializer
+137 				.initializeMessage(messageContext);
+138 
+139 		CreateSequence createSequence = (CreateSequence) rmMsgCtx
+140 				.getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ);
+141 		if (createSequence == null)
+142 			throw new SandeshaException(
+143 					"CreateSequence message does not have a CreateSequence part");
+144 
+145 		ConfigurationContext context = messageContext.getSystemContext();
+146 		StorageManager storageManager = (StorageManager) SandeshaUtil
+147 				.getSandeshaStorageManager(context);
+148 		if (storageManager == null)
+149 			throw new SandeshaException("Storage Manager is null");
+150 
+151 		boolean refuseSequence = false;
+152 		String reason = "";
+153 
+154 		SequenceOffer offer = createSequence.getSequenceOffer();
+155 		if (offer != null) {
+156 			String offeredSequenceId = offer.getIdentifer().getIdentifier();
+157 			if (offeredSequenceId == null || "".equals(offeredSequenceId)) {
+158 				refuseSequence = true;
+159 				reason = "Offered sequenceId is invalid";
+160 			} else {
+161 				NextMsgBeanMgr nextMsgBeanMgr = storageManager
+162 						.getNextMsgBeanMgr();
+163 				Collection collection = nextMsgBeanMgr.retrieveAll();
+164 				Iterator it = collection.iterator();
+165 				while (it.hasNext()) {
+166 
+167 					//checking weather a incoming sequence with the given id
+168 					// exists.
+169 					NextMsgBean nextMsgBean = (NextMsgBean) it.next();
+170 					String sequenceId = nextMsgBean.getSequenceId();
+171 					if (sequenceId.equals(offeredSequenceId)) {
+172 						refuseSequence = true;
+173 						reason = "A sequence with offered sequenceId, already axists";
+174 					}
+175 
+176 					//checking weather an outgoing sequence with the given id
+177 					// exists.
+178 					SequencePropertyBeanMgr sequencePropertyBeanMgr = storageManager
+179 							.getSequencePropretyBeanMgr();
+180 					SequencePropertyBean sequencePropertyBean = sequencePropertyBeanMgr
+181 							.retrieve(
+182 									sequenceId,
+183 									Sandesha2Constants.SequenceProperties.OUT_SEQUENCE_ID);
+184 					if (sequencePropertyBean != null) {
+185 						String outSequenceId = (String) sequencePropertyBean
+186 								.getValue();
+187 						if (outSequenceId != null
+188 								&& outSequenceId.equals(offeredSequenceId)) {
+189 							refuseSequence = true;
+190 							reason = "A sequence with offered sequenceId, already axists";
+191 						}
+192 
+193 					}
+194 				}
+195 			}
+196 		}
+197 
+198 		//TODO - if (securityTokenReference is present RefuseCreateSequence)
+199 
+200 		if (refuseSequence) {
+201 
+202 			FaultData data = new FaultData();
+203 			data
+204 					.setType(Sandesha2Constants.SOAPFaults.FaultType.CREATE_SEQUENCE_REFUSED);
+205 
+206 			int SOAPVersion = SandeshaUtil.getSOAPVersion(rmMsgCtx
+207 					.getSOAPEnvelope());
+208 			if (SOAPVersion == Sandesha2Constants.SOAPVersion.v1_1)
+209 				data.setCode(SOAP11Constants.FAULT_CODE_SENDER);
+210 			else
+211 				data.setCode(SOAP12Constants.FAULT_CODE_SENDER);
+212 
+213 			data
+214 					.setSubcode(Sandesha2Constants.SOAPFaults.Subcodes.CREATE_SEQUENCE_REFUSED);
+215 			data.setReason(reason);
+216 			return getFault(rmMsgCtx, data);
+217 		}
+218 
+219 		return null;
+220 
+221 	}
+222 
+223 	/***
+224 	 * Check weather the LastMessage number has been exceeded and generate the fault if it is.
+225 	 * 
+226 	 * @param msgCtx
+227 	 * @return
+228 	 */
+229 	private RMMsgContext checkForLastMsgNumberExceeded(MessageContext msgCtx) {
+230 		return null;
+231 	}
+232 
+233 	private RMMsgContext checkForMessageNumberRoleover(
+234 			MessageContext messageContext) {
+235 		return null;
+236 	}
+237 
+238 	/***
+239 	 * Check whether a Sequence message (a) belongs to a unknown sequence
+240 	 * (generates an UnknownSequence fault) (b) message number exceeds a
+241 	 * predifined limit ( genenrates a Message Number Rollover fault)
+242 	 * 
+243 	 * @param msgCtx
+244 	 * @return @throws
+245 	 *         SandeshaException
+246 	 */
+247 	public RMMsgContext checkForUnknownSequence(MessageContext messageContext)
+248 			throws SandeshaException {
+249 
+250 		RMMsgContext rmMsgCtx = MsgInitializer
+251 				.initializeMessage(messageContext);
+252 		String sequenceId = null;
+253 
+254 		if (rmMsgCtx.getMessageType() == Sandesha2Constants.MessageTypes.APPLICATION) {
+255 			Sequence sequence = (Sequence) rmMsgCtx
+256 					.getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE);
+257 			if (sequence == null)
+258 				throw new SandeshaException(
+259 						"Sequence part not found in the application message");
+260 
+261 			sequenceId = sequence.getIdentifier().getIdentifier();
+262 
+263 		} else if (rmMsgCtx.getMessageType() == Sandesha2Constants.MessageTypes.ACK) {
+264 			SequenceAcknowledgement sequenceAcknowledgement = (SequenceAcknowledgement) rmMsgCtx
+265 					.getMessagePart(Sandesha2Constants.MessageParts.SEQ_ACKNOWLEDGEMENT);
+266 			sequenceId = sequenceAcknowledgement.getIdentifier()
+267 					.getIdentifier();
+268 		} else if (rmMsgCtx.getMessageType() == Sandesha2Constants.MessageTypes.TERMINATE_SEQ) {
+269 			TerminateSequence terminateSequence = (TerminateSequence) rmMsgCtx
+270 					.getMessagePart(Sandesha2Constants.MessageParts.TERMINATE_SEQ);
+271 			sequenceId = terminateSequence.getIdentifier().getIdentifier();
+272 		} else {
+273 			//sequenceId not found.
+274 			return null;
+275 		}
+276 
+277 		StorageManager storageManager = SandeshaUtil
+278 				.getSandeshaStorageManager(messageContext.getSystemContext());
+279 
+280 		NextMsgBeanMgr mgr = storageManager.getNextMsgBeanMgr();
+281 		SOAPEnvelope envelope = messageContext.getEnvelope();
+282 
+283 		Collection coll = mgr.retrieveAll();
+284 		Iterator it = coll.iterator();
+285 
+286 		boolean validSequence = false;
+287 
+288 		while (it.hasNext()) {
+289 			NextMsgBean nextMsgBean = (NextMsgBean) it.next();
+290 			String tempId = nextMsgBean.getSequenceId();
+291 			if (tempId.equals(sequenceId)) {
+292 				validSequence = true;
+293 				break;
+294 			}
+295 		}
+296 
+297 		if (!validSequence) {
+298 			//Return an UnknownSequence error
+299 			int SOAPVersion = SandeshaUtil.getSOAPVersion(envelope);
+300 
+301 			FaultData data = new FaultData();
+302 			if (SOAPVersion == Sandesha2Constants.SOAPVersion.v1_1)
+303 				data.setCode(SOAP11Constants.FAULT_CODE_SENDER);
+304 			else
+305 				data.setCode(SOAP12Constants.FAULT_CODE_SENDER);
+306 
+307 			data.setSubcode(Sandesha2Constants.SOAPFaults.Subcodes.UNKNOWN_SEQUENCE);
+308 
+309 			SOAPFactory factory = SOAPAbstractFactory
+310 					.getSOAPFactory(SOAPVersion);
+311 			Identifier identifier = new Identifier(factory);
+312 			identifier.setIndentifer(sequenceId);
+313 			OMElement identifierOMElem = identifier.getOMElement();
+314 			data.setDetail(identifierOMElem);
+315 			data
+316 					.setReason("The value of wsrm:Identifier is not a known Sequence identifier");
+317 
+318 			return getFault(rmMsgCtx, data);
+319 
+320 		}
+321 
+322 		return null;
+323 	}
+324 
+325 	/***
+326 	 * Check weather the Acknowledgement is invalid and generate a fault if it is.
+327 	 * 
+328 	 * @param msgCtx
+329 	 * @return @throws
+330 	 *         SandeshaException
+331 	 */
+332 	public RMMsgContext checkForInvalidAcknowledgement(MessageContext msgCtx)
+333 			throws SandeshaException {
+334 
+335 		//check lower<=upper
+336 		//TODO acked for not-send message
+337 		RMMsgContext rmMsgContext = new RMMsgContext();
+338 		if (rmMsgContext.getMessageType() != Sandesha2Constants.MessageTypes.ACK)
+339 			return null;
+340 
+341 		SequenceAcknowledgement sequenceAcknowledgement = (SequenceAcknowledgement) rmMsgContext
+342 				.getMessagePart(Sandesha2Constants.MessageParts.SEQ_ACKNOWLEDGEMENT);
+343 		List sequenceAckList = sequenceAcknowledgement
+344 				.getAcknowledgementRanges();
+345 		Iterator it = sequenceAckList.iterator();
+346 
+347 		while (it.hasNext()) {
+348 			AcknowledgementRange acknowledgementRange = (AcknowledgementRange) it
+349 					.next();
+350 			long upper = acknowledgementRange.getUpperValue();
+351 			long lower = acknowledgementRange.getLowerValue();
+352 
+353 			if (lower > upper) {
+354 				//Invalid ack
+355 				FaultData data = new FaultData();
+356 				int SOAPVersion = SandeshaUtil.getSOAPVersion(msgCtx
+357 						.getEnvelope());
+358 				if (SOAPVersion == Sandesha2Constants.SOAPVersion.v1_1)
+359 					data.setCode(SOAP11Constants.FAULT_CODE_SENDER);
+360 				else
+361 					data.setCode(SOAP12Constants.FAULT_CODE_SENDER);
+362 
+363 				data.setSubcode(Sandesha2Constants.SOAPFaults.Subcodes.INVALID_ACKNOWLEDGEMENT);
+364 				data.setSubcode("The SequenceAcknowledgement is invalid. Lower value is larger than upper value");
+365 				data.setDetail(sequenceAcknowledgement.getOMElement());
+366 
+367 				return getFault(rmMsgContext, data);
+368 			}
+369 		}
+370 
+371 		return null;
+372 	}
+373 
+374 
+375 	/***
+376 	 * Returns a RMMessageContext for the fault message. Data for generating the fault is given in the data parameter.
+377 	 * 
+378 	 * @param referenceRMMsgContext
+379 	 * @param data
+380 	 * @return
+381 	 * @throws SandeshaException
+382 	 */
+383 	public RMMsgContext getFault(RMMsgContext referenceRMMsgContext,
+384 			FaultData data) throws SandeshaException {
+385 
+386 		try {
+387 
+388 			MessageContext referenceMessage = referenceRMMsgContext
+389 					.getMessageContext();
+390 			MessageContext faultMsgContext = Utils
+391 					.createOutMessageContext(referenceMessage);
+392 
+393 			StorageManager storageManager = SandeshaUtil
+394 					.getSandeshaStorageManager(referenceMessage
+395 							.getSystemContext());
+396 
+397 			//setting contexts.
+398 			faultMsgContext.setAxisServiceGroup(referenceMessage
+399 					.getAxisServiceGroup());
+400 			faultMsgContext.setAxisService(referenceMessage.getAxisService());
+401 			faultMsgContext.setAxisServiceGroup(referenceMessage
+402 					.getAxisServiceGroup());
+403 			faultMsgContext.setServiceGroupContext(referenceMessage
+404 					.getServiceGroupContext());
+405 			faultMsgContext.setServiceGroupContextId(referenceMessage
+406 					.getServiceGroupContextId());
+407 			faultMsgContext.setServiceContext(referenceMessage
+408 					.getServiceContext());
+409 			faultMsgContext.setServiceContextID(referenceMessage
+410 					.getServiceContextID());
+411 
+412 			AxisOperation operation = AxisOperationFactory
+413 					.getAxisOperation(AxisOperationFactory.MEP_CONSTANT_OUT_ONLY);
+414 
+415 			OperationContext operationContext = new OperationContext(operation);
+416 
+417 			faultMsgContext.setAxisOperation(operation);
+418 			faultMsgContext.setOperationContext(operationContext);
+419 
+420 			String acksToStr = null;
+421 			if (referenceRMMsgContext.getMessageType() == Sandesha2Constants.MessageTypes.CREATE_SEQ) {
+422 				CreateSequence createSequence = (CreateSequence) referenceRMMsgContext
+423 						.getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ);
+424 				acksToStr = createSequence.getAcksTo().getAddress().getEpr()
+425 						.getAddress();
+426 			} else {
+427 				SequencePropertyBeanMgr seqPropMgr = storageManager
+428 						.getSequencePropretyBeanMgr();
+429 				String sequenceId = data.getSequenceId();
+430 				SequencePropertyBean acksToBean = seqPropMgr.retrieve(
+431 						sequenceId, Sandesha2Constants.SequenceProperties.ACKS_TO_EPR);
+432 				if (acksToBean != null) {
+433 					EndpointReference epr = (EndpointReference) acksToBean
+434 							.getValue();
+435 					if (epr != null)
+436 						acksToStr = epr.getAddress();
+437 				}
+438 			}
+439 
+440 			if (acksToStr != null
+441 					&& !acksToStr.equals(Sandesha2Constants.WSA.NS_URI_ANONYMOUS)) {
+442 				faultMsgContext.setTo(new EndpointReference(acksToStr));
+443 			}
+444 
+445 			int SOAPVersion = SandeshaUtil.getSOAPVersion(referenceMessage
+446 					.getEnvelope());
+447 
+448 			SOAPFaultEnvelopeCreator.addSOAPFaultEnvelope(faultMsgContext,
+449 					SOAPVersion, data);
+450 
+451 			RMMsgContext faultRMMsgCtx = MsgInitializer
+452 					.initializeMessage(faultMsgContext);
+453 
+454 			return faultRMMsgCtx;
+455 
+456 		} catch (AxisFault e) {
+457 			throw new SandeshaException(e.getMessage());
+458 		}
+459 
+460 	}
+461 }
+
+
+ + Added: webservices/site/trunk/targets/sandesha/sandesha2/xref/org/apache/sandesha2/util/MessageRetransmissionAdjuster.html URL: http://svn.apache.org/viewcvs/webservices/site/trunk/targets/sandesha/sandesha2/xref/org/apache/sandesha2/util/MessageRetransmissionAdjuster.html?rev=349924&view=auto ============================================================================== --- webservices/site/trunk/targets/sandesha/sandesha2/xref/org/apache/sandesha2/util/MessageRetransmissionAdjuster.html (added) +++ webservices/site/trunk/targets/sandesha/sandesha2/xref/org/apache/sandesha2/util/MessageRetransmissionAdjuster.html Wed Nov 30 03:11:01 2005 @@ -0,0 +1,117 @@ + + + +MessageRetransmissionAdjuster xref + + + +
View Javadoc
+
+1   /*
+2    * Copyright  1999-2004 The Apache Software Foundation.
+3    *
+4    *  Licensed under the Apache License, Version 2.0 (the "License");
+5    *  you may not use this file except in compliance with the License.
+6    *  You may obtain a copy of the License at
+7    *
+8    *      http://www.apache.org/licenses/LICENSE-2.0
+9    *
+10   *  Unless required by applicable law or agreed to in writing, software
+11   *  distributed under the License is distributed on an "AS IS" BASIS,
+12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+13   *  See the License for the specific language governing permissions and
+14   *  limitations under the License.
+15   *
+16   */
+17  
+18  package org.apache.sandesha2.util;
+19  
+20  import org.apache.axis2.context.MessageContext;
+21  import org.apache.sandesha2.Sandesha2Constants;
+22  import org.apache.sandesha2.policy.RMPolicyBean;
+23  import org.apache.sandesha2.storage.beans.SenderBean;
+24  
+25  /***
+26   * This is used to adjust retransmission infoamation after each time the message is sent.
+27   * 
+28   * @author Chamikara Jayalath <chamikaramj@gmail.com>
+29   */
+30  
+31  public class MessageRetransmissionAdjuster {
+32  
+33  	public SenderBean adjustRetransmittion(
+34  			SenderBean retransmitterBean) {
+35  		String storedKey = (String) retransmitterBean.getKey();
+36  
+37  		if (storedKey == null)
+38  			return retransmitterBean;
+39  
+40  		MessageContext messageContext = SandeshaUtil
+41  				.getStoredMessageContext(storedKey);
+42  
+43  		if (messageContext.getSystemContext() == null)
+44  			return retransmitterBean;
+45  
+46  		RMPolicyBean policyBean = (RMPolicyBean) messageContext
+47  				.getProperty(Sandesha2Constants.WSP.RM_POLICY_BEAN);
+48  		if (policyBean == null) {
+49  			//loading default policies.
+50  			policyBean = PropertyManager.getInstance().getRMPolicyBean();
+51  		}
+52  
+53  		retransmitterBean.setSentCount(retransmitterBean.getSentCount() + 1);
+54  		adjustNextRetransmissionTime(retransmitterBean, policyBean);
+55  
+56  		if (retransmitterBean.getSentCount() >= Sandesha2Constants.MAXIMUM_RETRANSMISSION_ATTEMPTS)
+57  			stopRetransmission(retransmitterBean);
+58  
+59  		return retransmitterBean;
+60  	}
+61  
+62  	/***
+63  	 * This sets the next time the message has to be retransmitted. This uses the base retransmission interval
+64  	 * and exponentialBackoff properties to calculate the correct time.
+65  	 * 
+66  	 * @param retransmitterBean
+67  	 * @param policyBean
+68  	 * @return
+69  	 */
+70  	private SenderBean adjustNextRetransmissionTime(
+71  			SenderBean retransmitterBean, RMPolicyBean policyBean) {
+72  
+73  		long lastSentTime = retransmitterBean.getTimeToSend();
+74  
+75  		int count = retransmitterBean.getSentCount();
+76  
+77  		long baseInterval = policyBean.getRetransmissionInterval();
+78  
+79  		long newInterval = baseInterval;
+80  		if (policyBean.isExponentialBackoff()) {
+81  			newInterval = generateNextExponentialBackedoffDifference(count,
+82  					baseInterval);
+83  		}
+84  
+85  		retransmitterBean.setTimeToSend(lastSentTime + newInterval);
+86  
+87  		return retransmitterBean;
+88  	}
+89  
+90  	private void stopRetransmission(SenderBean bean) {
+91  		bean.setReSend(false);
+92  	}
+93  
+94  	private long generateNextExponentialBackedoffDifference(int count,
+95  			long initialInterval) {
+96  		long interval = initialInterval;
+97  		for (int i = 1; i < count; i++) {
+98  			interval = interval * 2;
+99  		}
+100 
+101 		return interval;
+102 	}
+103 
+104 }
+
+
+ + Added: webservices/site/trunk/targets/sandesha/sandesha2/xref/org/apache/sandesha2/util/MsgInitializer.html URL: http://svn.apache.org/viewcvs/webservices/site/trunk/targets/sandesha/sandesha2/xref/org/apache/sandesha2/util/MsgInitializer.html?rev=349924&view=auto ============================================================================== --- webservices/site/trunk/targets/sandesha/sandesha2/xref/org/apache/sandesha2/util/MsgInitializer.html (added) +++ webservices/site/trunk/targets/sandesha/sandesha2/xref/org/apache/sandesha2/util/MsgInitializer.html Wed Nov 30 03:11:01 2005 @@ -0,0 +1,125 @@ + + + +MsgInitializer xref + + + +
View Javadoc
+
+1   /*
+2    * Copyright 1999-2004 The Apache Software Foundation.
+3    * 
+4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+5    * use this file except in compliance with the License. You may obtain a copy of
+6    * the License at
+7    * 
+8    * http://www.apache.org/licenses/LICENSE-2.0
+9    * 
+10   * Unless required by applicable law or agreed to in writing, software
+11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+13   * License for the specific language governing permissions and limitations under
+14   * the License.
+15   *  
+16   */
+17  
+18  package org.apache.sandesha2.util;
+19  
+20  import org.apache.axis2.context.MessageContext;
+21  import org.apache.sandesha2.Sandesha2Constants;
+22  import org.apache.sandesha2.RMMsgContext;
+23  import org.apache.sandesha2.SandeshaException;
+24  import org.apache.sandesha2.wsrm.RMElements;
+25  
+26  /***
+27   * This class is used to create an RMMessageContext out of an MessageContext.
+28   * 
+29   * @author Chamikara Jayalath <chamikaramj@gmail.com>
+30   */
+31  
+32  public class MsgInitializer {
+33  
+34  	public static RMMsgContext initializeMessage(MessageContext ctx)
+35  			throws SandeshaException {
+36  		RMMsgContext rmMsgCtx = new RMMsgContext(ctx);
+37  		populateRMMsgContext(ctx, rmMsgCtx);
+38  		validateMessage(rmMsgCtx);
+39  		return rmMsgCtx;
+40  	}
+41  
+42  	/***
+43  	 * Adds the message parts the the RMMessageContext.
+44  	 * 
+45  	 * @param msgCtx
+46  	 * @param rmMsgContext
+47  	 */
+48  	private static void populateRMMsgContext(MessageContext msgCtx,
+49  			RMMsgContext rmMsgContext) {
+50  
+51  		RMElements elements = new RMElements();
+52  		elements.fromSOAPEnvelope(msgCtx.getEnvelope());
+53  
+54  		if (elements.getCreateSequence() != null)
+55  			rmMsgContext.setMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ,
+56  					elements.getCreateSequence());
+57  
+58  		if (elements.getCreateSequenceResponse() != null)
+59  			rmMsgContext.setMessagePart(
+60  					Sandesha2Constants.MessageParts.CREATE_SEQ_RESPONSE, elements
+61  							.getCreateSequenceResponse());
+62  
+63  		if (elements.getSequence() != null)
+64  			rmMsgContext.setMessagePart(Sandesha2Constants.MessageParts.SEQUENCE,
+65  					elements.getSequence());
+66  
+67  		if (elements.getSequenceAcknowledgement() != null)
+68  			rmMsgContext.setMessagePart(
+69  					Sandesha2Constants.MessageParts.SEQ_ACKNOWLEDGEMENT, elements
+70  							.getSequenceAcknowledgement());
+71  
+72  		if (elements.getTerminateSequence() != null)
+73  			rmMsgContext.setMessagePart(Sandesha2Constants.MessageParts.TERMINATE_SEQ,
+74  					elements.getTerminateSequence());
+75  
+76  		if (elements.getAckRequested() != null)
+77  			rmMsgContext.setMessagePart(Sandesha2Constants.MessageParts.ACK_REQUEST,
+78  					elements.getAckRequested());
+79  
+80  	}
+81  
+82  	/***
+83  	 * This is used to validate the message.
+84  	 * Also set an Message type. Possible types are given in the Sandesha2Constants.MessageTypes interface.
+85  	 * 
+86  	 * @param rmMsgCtx
+87  	 * @return
+88  	 * @throws SandeshaException
+89  	 */
+90  	private static boolean validateMessage(RMMsgContext rmMsgCtx)
+91  			throws SandeshaException {
+92  
+93  		//Setting message type.
+94  		if (rmMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ) != null)
+95  			rmMsgCtx.setMessageType(Sandesha2Constants.MessageTypes.CREATE_SEQ);
+96  		else if (rmMsgCtx
+97  				.getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ_RESPONSE) != null)
+98  			rmMsgCtx.setMessageType(Sandesha2Constants.MessageTypes.CREATE_SEQ_RESPONSE);
+99  		else if (rmMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.TERMINATE_SEQ) != null)
+100 			rmMsgCtx.setMessageType(Sandesha2Constants.MessageTypes.TERMINATE_SEQ);
+101 		else if (rmMsgCtx.getMessagePart(Sandesha2Constants.MessageParts.SEQUENCE) != null)
+102 			rmMsgCtx.setMessageType(Sandesha2Constants.MessageTypes.APPLICATION);
+103 		else if (rmMsgCtx
+104 				.getMessagePart(Sandesha2Constants.MessageParts.SEQ_ACKNOWLEDGEMENT) != null)
+105 			rmMsgCtx.setMessageType(Sandesha2Constants.MessageTypes.ACK);
+106 		else
+107 			rmMsgCtx.setMessageType(Sandesha2Constants.MessageTypes.UNKNOWN);
+108 
+109 		return true;
+110 	}
+111 
+112 }
+
+
+ + Added: webservices/site/trunk/targets/sandesha/sandesha2/xref/org/apache/sandesha2/util/MsgValidator.html URL: http://svn.apache.org/viewcvs/webservices/site/trunk/targets/sandesha/sandesha2/xref/org/apache/sandesha2/util/MsgValidator.html?rev=349924&view=auto ============================================================================== --- webservices/site/trunk/targets/sandesha/sandesha2/xref/org/apache/sandesha2/util/MsgValidator.html (added) +++ webservices/site/trunk/targets/sandesha/sandesha2/xref/org/apache/sandesha2/util/MsgValidator.html Wed Nov 30 03:11:01 2005 @@ -0,0 +1,48 @@ + + + +MsgValidator xref + + + +
View Javadoc
+
+1   /*
+2    * Copyright  1999-2004 The Apache Software Foundation.
+3    *
+4    *  Licensed under the Apache License, Version 2.0 (the "License");
+5    *  you may not use this file except in compliance with the License.
+6    *  You may obtain a copy of the License at
+7    *
+8    *      http://www.apache.org/licenses/LICENSE-2.0
+9    *
+10   *  Unless required by applicable law or agreed to in writing, software
+11   *  distributed under the License is distributed on an "AS IS" BASIS,
+12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+13   *  See the License for the specific language governing permissions and
+14   *  limitations under the License.
+15   *
+16   */
+17  
+18  package org.apache.sandesha2.util;
+19  
+20  import org.apache.axis2.AxisFault;
+21  import org.apache.sandesha2.RMMsgContext;
+22  
+23  /***
+24   * @author Chamikara Jayalath <chamikaramj@gmail.com>
+25   */
+26  
+27  //TODO remove this class.
+28  public class MsgValidator {
+29  
+30  	private static void validateMessage(RMMsgContext rmMsgCtx) throws AxisFault {
+31  
+32  		//no need of this method any more.
+33  		//Validation is done in the message initialized
+34  	}
+35  }
+
+
+ +