Author: mckierna
Date: Thu Jul 10 08:56:49 2008
New Revision: 675621
URL: http://svn.apache.org/viewvc?rev=675621&view=rev
Log:
Do not ack if no msgs sent and some serialization tests
Added:
webservices/sandesha/trunk/java/modules/tests/src/test/java/org/apache/sandesha2/MessageContextSerializationTest.java
webservices/sandesha/trunk/java/modules/tests/test-resources/MessageContext.dat
(with props)
webservices/sandesha/trunk/java/modules/tests/test-resources/RMDBean.dat
(with props)
webservices/sandesha/trunk/java/modules/tests/test-resources/RMSBean.dat
(with props)
Modified:
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/msgprocessors/ApplicationMsgProcessor.java
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/RMMsgCreator.java
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/RangeString.java
Modified:
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/msgprocessors/ApplicationMsgProcessor.java
URL:
http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/msgprocessors/ApplicationMsgProcessor.java?rev=675621&r1=675620&r2=675621&view=diff
==============================================================================
---
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/msgprocessors/ApplicationMsgProcessor.java
(original)
+++
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/msgprocessors/ApplicationMsgProcessor.java
Thu Jul 10 08:56:49 2008
@@ -30,6 +30,7 @@
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.OperationContext;
import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.Parameter;
import org.apache.axis2.wsdl.WSDLConstants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -90,6 +91,9 @@
}
private String getSequenceID(RMMsgContext rmMsgCtx, boolean serverSide,
boolean forceNewSequence)throws SandeshaException{
+ if (log.isDebugEnabled())
+ log.debug("Enter:
ApplicationMsgProcessor::getSequenceID " + rmMsgCtx + ", " + serverSide + ", "
+ forceNewSequence);
+
MessageContext msgContext = rmMsgCtx.getMessageContext();
ConfigurationContext configContext =
msgContext.getConfigurationContext();
@@ -114,8 +118,18 @@
String to = toEPR.getAddress();
String sequenceKey = null;
if(forceNewSequence){
- sequenceKey = SandeshaUtil.getUUID();
-
msgContext.setProperty(SandeshaClientConstants.SEQUENCE_KEY, sequenceKey);
+ //try to set a new sequence key
+ try{
+ sequenceKey = SandeshaUtil.getUUID();
+
msgContext.setProperty(SandeshaClientConstants.SEQUENCE_KEY, sequenceKey);
+
configContext.getAxisConfiguration().addParameter(new
Parameter(SandeshaClientConstants.SEQUENCE_KEY, sequenceKey));
+ }
+ catch(AxisFault e){
+ if (log.isDebugEnabled())
+ log.debug("Enter:
ApplicationMsgProcessor::getSequenceID " + e);
+ throw new SandeshaException(e);
+ }
+
}
else{
sequenceKey = (String)
msgContext.getProperty(SandeshaClientConstants.SEQUENCE_KEY);
@@ -126,6 +140,8 @@
internalSequenceId =
SandeshaUtil.getInternalSequenceID(to, sequenceKey);
}
+ if (log.isDebugEnabled())
+ log.debug("Exit: ApplicationMsgProcessor::getSequenceID
" + internalSequenceId);
return internalSequenceId;
}
@@ -221,7 +237,11 @@
if(rmsBean.isSequenceClosedClient() ||
rmsBean.isTerminateAdded() || rmsBean.isTimedOut()){
if(SandeshaUtil.isAutoStartNewSequence(msgContext)){
internalSequenceId =
getSequenceID(rmMsgCtx, serverSide, true); //require a new sequence
+ if (log.isDebugEnabled())
+
log.debug("ApplicationMsgProcessor: auto start new sequence " +
internalSequenceId + " :: " + rmsBean);
+ //set this new internal sequence ID on
the msg
rmMsgCtx.setProperty(Sandesha2Constants.MessageContextProperties.INTERNAL_SEQUENCE_ID,internalSequenceId);
+ rmsBean = null;
}
else if(rmsBean.isSequenceClosedClient()){
throw new
SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.cannotSendMsgAsSequenceClosed,
internalSequenceId));
Modified:
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/RMMsgCreator.java
URL:
http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/RMMsgCreator.java?rev=675621&r1=675620&r2=675621&view=diff
==============================================================================
---
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/RMMsgCreator.java
(original)
+++
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/RMMsgCreator.java
Thu Jul 10 08:56:49 2008
@@ -486,50 +486,56 @@
String rmVersion = rmdBean.getRMVersion();
String rmNamespaceValue =
SpecSpecificConstants.getRMNamespaceValue(rmVersion);
-
- SequenceAcknowledgement sequenceAck = new
SequenceAcknowledgement(rmNamespaceValue);
- Identifier id = new Identifier(rmNamespaceValue);
- id.setIndentifer(sequenceId);
- sequenceAck.setIdentifier(id);
-
ArrayList ackRangeArrayList =
SandeshaUtil.getAckRangeArrayList(rmdBean.getServerCompletedMessages(),
rmNamespaceValue);
- sequenceAck.setAckRanges(ackRangeArrayList);
-
- if (rmdBean.isClosed()) {
- // sequence is closed. so add the 'Final' part.
- if (SpecSpecificConstants.isAckFinalAllowed(rmVersion))
{
- sequenceAck.setAckFinal(true);
+ if(ackRangeArrayList!=null && ackRangeArrayList.size()!=0){
+ if(LoggingControl.isAnyTracingEnabled() &&
log.isDebugEnabled())
+ log.debug("RMMsgCreator::addAckMessage : there
are messages to ack " + ackRangeArrayList);
+ //there are actually messages to ack
+ SequenceAcknowledgement sequenceAck = new
SequenceAcknowledgement(rmNamespaceValue);
+ Identifier id = new Identifier(rmNamespaceValue);
+ id.setIndentifer(sequenceId);
+ sequenceAck.setIdentifier(id);
+
+ sequenceAck.setAckRanges(ackRangeArrayList);
+
+ if (rmdBean.isClosed()) {
+ // sequence is closed. so add the 'Final' part.
+ if(LoggingControl.isAnyTracingEnabled() &&
log.isDebugEnabled())
+ log.debug("RMMsgCreator::addAckMessage
: sequence closed");
+ if
(SpecSpecificConstants.isAckFinalAllowed(rmVersion)) {
+ sequenceAck.setAckFinal(true);
+ }
}
- }
- applicationMsg.addSequenceAcknowledgement(sequenceAck);
+ applicationMsg.addSequenceAcknowledgement(sequenceAck);
- if (applicationMsg.getWSAAction()==null) {
-
applicationMsg.setAction(SpecSpecificConstants.getSequenceAcknowledgementAction(rmVersion));
-
applicationMsg.setSOAPAction(SpecSpecificConstants.getSequenceAcknowledgementSOAPAction(rmVersion));
- }
- if(applicationMsg.getMessageId() == null) {
- applicationMsg.setMessageId(SandeshaUtil.getUUID());
- }
-
- if(addToEnvelope){
- // Write the ack into the soap envelope
- try {
- applicationMsg.addSOAPEnvelope();
- } catch(AxisFault e) {
- if(LoggingControl.isAnyTracingEnabled() &&
log.isDebugEnabled()) log.debug("Caught AxisFault", e);
- throw new SandeshaException(e.getMessage(), e);
+ if (applicationMsg.getWSAAction()==null) {
+
applicationMsg.setAction(SpecSpecificConstants.getSequenceAcknowledgementAction(rmVersion));
+
applicationMsg.setSOAPAction(SpecSpecificConstants.getSequenceAcknowledgementSOAPAction(rmVersion));
+ }
+ if(applicationMsg.getMessageId() == null) {
+
applicationMsg.setMessageId(SandeshaUtil.getUUID());
}
- }else{
- // Should use a constant in the final fix.
- applicationMsg.setProperty(ACK_TO_BE_WRITTEN,
Boolean.TRUE);
+
+ if(addToEnvelope){
+ // Write the ack into the soap envelope
+ try {
+ applicationMsg.addSOAPEnvelope();
+ } catch(AxisFault e) {
+ if(LoggingControl.isAnyTracingEnabled()
&& log.isDebugEnabled()) log.debug("Caught AxisFault", e);
+ throw new
SandeshaException(e.getMessage(), e);
+ }
+ }else{
+ // Should use a constant in the final fix.
+ applicationMsg.setProperty(ACK_TO_BE_WRITTEN,
Boolean.TRUE);
+ }
+
+ // Ensure the message also contains the token that
needs to be used
+ secureOutboundMessage(rmdBean,
applicationMsg.getMessageContext());
}
- // Ensure the message also contains the token that needs to be
used
- secureOutboundMessage(rmdBean,
applicationMsg.getMessageContext());
-
if(LoggingControl.isAnyTracingEnabled() &&
log.isDebugEnabled())
- log.debug("Exit: RMMsgCreator::addAckMessage");
+ log.debug("Exit: RMMsgCreator::addAckMessage " +
applicationMsg);
}
Modified:
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/RangeString.java
URL:
http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/RangeString.java?rev=675621&r1=675620&r2=675621&view=diff
==============================================================================
---
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/RangeString.java
(original)
+++
webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/RangeString.java
Thu Jul 10 08:56:49 2008
@@ -365,6 +365,27 @@
}
+ public boolean equals(Object o){
+ //this method is called by unit tests. It is not generally
called in common paths.
+ if(o==null){
+ return false;
+ }
+ else if(o == this){
+ return true; //we know we must be the same since we are
the exact same object
+ }
+ else{
+ if(!o.getClass().equals(this.getClass())){
+ //we are two different classes so we interpret
that as not equivalent
+ return false;
+ }
+ else{
+ //these are two seperate range strings - if
there string form is the same then
+ //they are equivalent
+ return o.toString().equals(this.toString());
+ }
+ }
+ }
+
}
Added:
webservices/sandesha/trunk/java/modules/tests/src/test/java/org/apache/sandesha2/MessageContextSerializationTest.java
URL:
http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/src/test/java/org/apache/sandesha2/MessageContextSerializationTest.java?rev=675621&view=auto
==============================================================================
---
webservices/sandesha/trunk/java/modules/tests/src/test/java/org/apache/sandesha2/MessageContextSerializationTest.java
(added)
+++
webservices/sandesha/trunk/java/modules/tests/src/test/java/org/apache/sandesha2/MessageContextSerializationTest.java
Thu Jul 10 08:56:49 2008
@@ -0,0 +1,220 @@
+/*
+ * 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;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisOperationFactory;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.sandesha2.storage.beans.RMDBean;
+import org.apache.sandesha2.storage.beans.RMSBean;
+import org.apache.sandesha2.util.RMMsgCreator;
+import org.apache.sandesha2.util.RangeString;
+
+/**
+ * This class tests the Axis2 Message Context Serialization code.
+ * Since sandesha can, in certain modes, serializae message contexts, it is
+ * important that changes to message context serialization does not break
anything.
+ *
+ * These tests use some pre-produced binary data ".dat" resource files.
+ * These files contain the binary data for certain sandesha data structures.
+ * This test ensures that sandesha is still capable of deserializing
previously
+ * serialized sandesha data.
+ *
+ */
+public class MessageContextSerializationTest extends SandeshaTestCase{
+
+ private static final String rmsDatFileName = "RMSBean.dat";
+ private static final String rmdDatFileName = "RMDBean.dat";
+ private static final String msgCtxDatFileName = "MessageContext.dat";
+
+ private static RMSBean expectedRMSBean;
+ private static RMDBean expectedRMDBean;
+ private static MessageContext expectedMessageContext;
+
+ private static EndpointReference epr = new EndpointReference("someEPR");
+
+
+
+ public MessageContextSerializationTest(String s)throws Exception
+ {
+ super(s);
+ }
+
+ public void testMain()throws Exception{
+
+ //ensure we can deserialize the rms bean
+ {
+ FileInputStream fis = new FileInputStream(resourceDir +
File.separator + rmsDatFileName);
+ ObjectInputStream rmsBeanData = new
ObjectInputStream(fis);
+ RMSBean bean = (RMSBean)rmsBeanData.readObject();
+ assertTrue(bean.match(expectedRMSBean));
+ }
+
+ //ensure we can deserialize the rmd bean
+ {
+ FileInputStream fis = new FileInputStream(resourceDir +
File.separator + rmdDatFileName);
+ ObjectInputStream rmdBeanData = new
ObjectInputStream(fis);
+ RMDBean bean = (RMDBean)rmdBeanData.readObject();
+ assertTrue(bean.match(expectedRMDBean));
+ }
+
+ //ensure we can deserialize the msg ctx
+ {
+ FileInputStream fis = new FileInputStream(resourceDir +
File.separator + msgCtxDatFileName);
+ ObjectInputStream msgCtxData = new
ObjectInputStream(fis);
+ MessageContext msg =
(MessageContext)msgCtxData.readObject();
+ //TODO any extra properties set earlier should be read
and verified here
+ }
+ }
+
+ public void setUp()throws Exception
+ {
+ //setup the RMSBean
+ expectedRMSBean = new RMSBean();
+ expectedRMSBean.setAnonymousUUID("someAnonymousUUID");
+ expectedRMSBean.setAvoidAutoTermination(true);
+ expectedRMSBean.setClientCompletedMessages(new RangeString());
+ expectedRMSBean.setClosed(true);
+ expectedRMSBean.setCreateSeqMsgID("someCSeqMsgId");
+ expectedRMSBean.setCreateSequenceMsgStoreKey("someMsgStoreKey");
+ expectedRMSBean.setExpectedReplies(1);
+ expectedRMSBean.setHighestOutMessageNumber(1);
+ expectedRMSBean.setHighestOutRelatesTo("someRelatesTo");
+ expectedRMSBean.setInternalSequenceID("someInternalSequenceID");
+ expectedRMSBean.setLastActivatedTime(1);
+ expectedRMSBean.setLastOutMessage(1);
+ expectedRMSBean.setLastSendError(new Exception());
+ expectedRMSBean.setLastSendErrorTimestamp(1);
+ expectedRMSBean.setNextMessageNumber(1);
+ expectedRMSBean.setOfferedEndPoint("someEndPoint");
+ expectedRMSBean.setOfferedSequence("offeredSequence");
+ expectedRMSBean.setPollingMode(true);
+
expectedRMSBean.setReferenceMessageStoreKey("someRefMsgStoreKey");
+
expectedRMSBean.setRMVersion(Sandesha2Constants.SPEC_VERSIONS.v1_1);
+ expectedRMSBean.setSecurityTokenData("someSecurityToken");
+ expectedRMSBean.setSequenceClosedClient(true);
+ expectedRMSBean.setSequenceID("someSequenceID");
+ expectedRMSBean.setServiceName("someService");
+ expectedRMSBean.setSoapVersion(1);
+ expectedRMSBean.setTerminateAdded(true);
+ expectedRMSBean.setTerminationPauserForCS(true);
+ expectedRMSBean.setTimedOut(true);
+ expectedRMSBean.setTransaction(null);
+ expectedRMSBean.setTransportTo("transportTo");
+ expectedRMSBean.setToEndpointReference(epr);
+ expectedRMSBean.setReplyToEndpointReference(epr);
+ expectedRMSBean.setAcksToEndpointReference(epr);
+
+ //setup the RMDBean
+ expectedRMDBean = new RMDBean();
+ expectedRMDBean.setClosed(true);
+ expectedRMDBean.setHighestInMessageId("someMsgId");
+ expectedRMDBean.setLastActivatedTime(1);
+ expectedRMDBean.setNextMsgNoToProcess(1);
+ expectedRMDBean.setOutboundInternalSequence("someSequenceID");
+ expectedRMDBean.setOutOfOrderRanges(new RangeString());
+ expectedRMDBean.setPollingMode(true);
+ expectedRMDBean.setReferenceMessageKey("someRefMsgStoreKey");
+ expectedRMDBean.setRMVersion("someVersion");
+ expectedRMDBean.setSecurityTokenData("someTokenData");
+ expectedRMDBean.setSequenceID("someSequenceID");
+ expectedRMDBean.setServerCompletedMessages(new RangeString());
+ expectedRMDBean.setServiceName("someService");
+ expectedRMDBean.setTerminated(true);
+ expectedRMDBean.setToEndpointReference(epr);
+ expectedRMDBean.setReplyToEndpointReference(epr);
+ expectedRMDBean.setAcksToEndpointReference(epr);
+
+ //setup a typical message context - for this we will also need
a config context
+ String repoPath = "target" + File.separator + "repos" +
File.separator + "client";
+ String axis2_xml = "target" + File.separator + "repos" +
File.separator + "client" + File.separator + "client_axis2.xml";
+
+ ConfigurationContext configContext =
ConfigurationContextFactory.createConfigurationContextFromFileSystem(repoPath,axis2_xml);
+ expectedMessageContext = configContext.createMessageContext();
+ //TODO this could be improved by adding some RM sequence headers
+ }
+
+ /**
+ * If called, this method produces/updates the set of .dat files in the
resources directory
+ * Since the data set is complete, this method should not be called
(and the data set should
+ * not be changed) unless it is due to a considered requirement.
+ */
+ private void produceDataSet()throws IOException{
+
+ String resourceDir = new
File("test-resources").getAbsolutePath();
+
+ //write the RMSBean
+ {
+ FileOutputStream fos = new FileOutputStream(resourceDir
+ File.separator + rmsDatFileName);
+ ObjectOutputStream rmsBeanData = new
ObjectOutputStream(fos);
+ rmsBeanData.writeObject(expectedRMSBean);
+ rmsBeanData.flush();
+ fos.flush();
+ rmsBeanData.close();
+ fos.close();
+ }
+
+
+ //write the RMDBean
+ {
+ FileOutputStream fos = new FileOutputStream(resourceDir
+ File.separator + rmdDatFileName);
+ ObjectOutputStream rmdBeanData = new
ObjectOutputStream(fos);
+ rmdBeanData.writeObject(expectedRMDBean);
+ rmdBeanData.flush();
+ fos.flush();
+ rmdBeanData.close();
+ fos.close();
+ }
+
+ //write the msg ctx
+ {
+ FileOutputStream fos = new FileOutputStream(resourceDir
+ File.separator + msgCtxDatFileName);
+ ObjectOutputStream msgCtxData = new
ObjectOutputStream(fos);
+ msgCtxData.writeObject(expectedMessageContext);
+ msgCtxData.flush();
+ fos.flush();
+ msgCtxData.close();
+ fos.close();
+ }
+ }
+
+
+ /**
+ * This main method, when run, will setup the .dat files that this test
expects.
+ * These files should be checked into SVN when generated/modified
+ */
+// public static void main(String[] args)throws Exception{
+// MessageContextSerializationTest test = new
MessageContextSerializationTest("");
+// test.setUp();
+// test.produceDataSet();
+// }
+
+}
Added:
webservices/sandesha/trunk/java/modules/tests/test-resources/MessageContext.dat
URL:
http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/test-resources/MessageContext.dat?rev=675621&view=auto
==============================================================================
Binary file - no diff available.
Propchange:
webservices/sandesha/trunk/java/modules/tests/test-resources/MessageContext.dat
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: webservices/sandesha/trunk/java/modules/tests/test-resources/RMDBean.dat
URL:
http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/test-resources/RMDBean.dat?rev=675621&view=auto
==============================================================================
Binary file - no diff available.
Propchange:
webservices/sandesha/trunk/java/modules/tests/test-resources/RMDBean.dat
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: webservices/sandesha/trunk/java/modules/tests/test-resources/RMSBean.dat
URL:
http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/tests/test-resources/RMSBean.dat?rev=675621&view=auto
==============================================================================
Binary file - no diff available.
Propchange:
webservices/sandesha/trunk/java/modules/tests/test-resources/RMSBean.dat
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]