You are viewing a plain text version of this content. The canonical link for it is here.
Posted to sandesha-dev@ws.apache.org by ga...@apache.org on 2007/02/01 16:44:29 UTC

svn commit: r502245 - in /webservices/sandesha/trunk/java: src/org/apache/sandesha2/msgprocessors/ src/org/apache/sandesha2/util/ src/org/apache/sandesha2/wsrm/ test/src/org/apache/sandesha2/faulttests/

Author: gatfora
Date: Thu Feb  1 07:44:28 2007
New Revision: 502245

URL: http://svn.apache.org/viewvc?view=rev&rev=502245
Log:
Add support for generating wsrm:UnknownSequence faults

Added:
    webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/faulttests/
    webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/faulttests/CreateSequenceRefusedFaultTest.java
    webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/faulttests/FaultTestUtils.java
    webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/faulttests/UnknownSequenceFaultTest.java
Modified:
    webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/AckRequestedProcessor.java
    webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/AcknowledgementProcessor.java
    webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/CloseSequenceProcessor.java
    webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/SequenceProcessor.java
    webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/TerminateSeqMsgProcessor.java
    webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/FaultManager.java
    webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SOAPFaultEnvelopeCreator.java
    webservices/sandesha/trunk/java/src/org/apache/sandesha2/wsrm/FaultCode.java

Modified: webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/AckRequestedProcessor.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/AckRequestedProcessor.java?view=diff&rev=502245&r1=502244&r2=502245
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/AckRequestedProcessor.java (original)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/AckRequestedProcessor.java Thu Feb  1 07:44:28 2007
@@ -127,7 +127,11 @@
 		}
 
 		// Check that the sequence requested exists
-		FaultManager.checkForUnknownSequence(rmMsgCtx, sequenceId, storageManager);
+		if (FaultManager.checkForUnknownSequence(rmMsgCtx, sequenceId, storageManager)) {
+			if (log.isDebugEnabled())
+				log.debug("Exit: AckRequestedProcessor::processAckRequestedHeader, Unknown sequence ");
+			return false;
+		}
 
 		// Setting the ack depending on AcksTo.
 		EndpointReference acksTo = new EndpointReference(rmdBean.getAcksToEPR());

Modified: webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/AcknowledgementProcessor.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/AcknowledgementProcessor.java?view=diff&rev=502245&r1=502244&r2=502245
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/AcknowledgementProcessor.java (original)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/AcknowledgementProcessor.java Thu Feb  1 07:44:28 2007
@@ -137,7 +137,11 @@
 		Iterator ackRangeIterator = sequenceAck.getAcknowledgementRanges().iterator();
 		Iterator nackIterator = sequenceAck.getNackList().iterator();
 
-		FaultManager.checkForUnknownSequence(rmMsgCtx, outSequenceId, storageManager);
+		if (FaultManager.checkForUnknownSequence(rmMsgCtx, outSequenceId, storageManager)) {
+			if (log.isDebugEnabled())
+				log.debug("Exit: AcknowledgementProcessor::processAckHeader, Unknown sequence ");
+			return;
+		}
 		FaultManager.checkForInvalidAcknowledgement(rmMsgCtx, storageManager);
 		
 		SenderBean input = new SenderBean();

Modified: webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/CloseSequenceProcessor.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/CloseSequenceProcessor.java?view=diff&rev=502245&r1=502244&r2=502245
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/CloseSequenceProcessor.java (original)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/CloseSequenceProcessor.java Thu Feb  1 07:44:28 2007
@@ -84,7 +84,11 @@
 			secManager.checkProofOfPossession(token, body, msgCtx);
 		}
 
-		FaultManager.checkForUnknownSequence(rmMsgCtx, sequenceId, storageManager);
+		if (FaultManager.checkForUnknownSequence(rmMsgCtx, sequenceId, storageManager)) {
+			if (log.isDebugEnabled())
+				log.debug("Exit: CloseSequenceProcessor::processInMessage, Unknown sequence " + sequenceId);
+			return false;
+		}
 		
 		rmdBean.setClosed(true);
 		storageManager.getRMDBeanMgr().update(rmdBean);

Modified: webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/SequenceProcessor.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/SequenceProcessor.java?view=diff&rev=502245&r1=502244&r2=502245
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/SequenceProcessor.java (original)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/SequenceProcessor.java Thu Feb  1 07:44:28 2007
@@ -128,16 +128,15 @@
 			throw new SandeshaException(message);
 		}
 
-		FaultManager.checkForUnknownSequence(rmMsgCtx, sequenceId, storageManager);
+		if (FaultManager.checkForUnknownSequence(rmMsgCtx, sequenceId, storageManager)) {
+			if (log.isDebugEnabled())
+				log.debug("Exit: SequenceProcessor::processReliableMessage, Unknown sequence");
+			return InvocationResponse.ABORT;
+		}
 
 		// setting mustUnderstand to false.
 		sequence.setMustUnderstand(false);
 		rmMsgCtx.addSOAPEnvelope();
-
-		if (bean == null) {
-			throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.cannotFindSequence,
-					sequenceId));
-		}
 
 		// throwing a fault if the sequence is closed.
 		FaultManager.checkForSequenceClosed(rmMsgCtx, sequenceId, bean);

Modified: webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/TerminateSeqMsgProcessor.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/TerminateSeqMsgProcessor.java?view=diff&rev=502245&r1=502244&r2=502245
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/TerminateSeqMsgProcessor.java (original)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/TerminateSeqMsgProcessor.java Thu Feb  1 07:44:28 2007
@@ -99,7 +99,11 @@
 			secManager.checkProofOfPossession(token, body, terminateSeqRMMsg.getMessageContext());
 		}
 
-		FaultManager.checkForUnknownSequence(terminateSeqRMMsg, sequenceId, storageManager);
+		if (FaultManager.checkForUnknownSequence(terminateSeqRMMsg, sequenceId, storageManager)) {
+			if (log.isDebugEnabled())
+				log.debug("Exit: TerminateSeqMsgProcessor::processInMessage, unknown sequence");
+			return false;
+		}
 
 		// add the terminate sequence response if required.
 		RMMsgContext terminateSequenceResponse = null;

Modified: 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?view=diff&rev=502245&r1=502244&r2=502245
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/FaultManager.java (original)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/FaultManager.java Thu Feb  1 07:44:28 2007
@@ -131,10 +131,10 @@
 	 * predifined limit ( genenrates a Message Number Rollover fault)
 	 * 
 	 * @param msgCtx
-	 * @return
+	 * @return true if no exception has been thrown and the sequence doesn't exist 
 	 * @throws SandeshaException
 	 */
-	public static void checkForUnknownSequence(RMMsgContext rmMessageContext, String sequenceID,
+	public static boolean checkForUnknownSequence(RMMsgContext rmMessageContext, String sequenceID,
 			StorageManager storageManager) throws AxisFault {
 		if (log.isDebugEnabled())
 			log.debug("Enter: FaultManager::checkForUnknownSequence, " + sequenceID);
@@ -176,14 +176,18 @@
 			data.setDetail(identifierElement);
 
 			data.setReason(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.noSequenceEstablished, sequenceID));
+			
+			data.setType(Sandesha2Constants.SOAPFaults.FaultType.UNKNOWN_SEQUENCE);
 
 			if (log.isDebugEnabled())
 				log.debug("Exit: FaultManager::checkForUnknownSequence, Sequence unknown");
-			getFault(rmMessageContext, data);
+			getOrSendFault(rmMessageContext, data);
+			return true;
 		}
 
 		if (log.isDebugEnabled())
 			log.debug("Exit: FaultManager::checkForUnknownSequence");
+		return false;
 	}
 
 	/**
@@ -384,6 +388,10 @@
 			referenceRMMsgContext.setProperty(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME, reason);
 			referenceRMMsgContext.setProperty(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME, detail);
 		} else if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals (SOAPNamespaceValue)) {
+			
+			referenceRMMsgContext.setProperty(SOAP11Constants.SOAP_FAULT_CODE_LOCAL_NAME, faultCode);
+			referenceRMMsgContext.setProperty(SOAP11Constants.SOAP_FAULT_DETAIL_LOCAL_NAME, detail);
+			referenceRMMsgContext.setProperty(SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME, reason);
 			// Need to send this message as the Axis Layer doesn't set the "SequenceFault" header
 			MessageContext faultMessageContext = 
 				MessageContextBuilder.createFaultMessageContext(referenceRMMsgContext.getMessageContext(), null);
@@ -397,10 +405,6 @@
 			// Send the message
 			AxisEngine engine = new AxisEngine(faultMessageContext.getConfigurationContext());
 			engine.sendFault(faultMessageContext);
-			
-			referenceRMMsgContext.setProperty(SOAP11Constants.SOAP_FAULT_CODE_LOCAL_NAME, faultCode);
-			referenceRMMsgContext.setProperty(SOAP11Constants.SOAP_FAULT_DETAIL_LOCAL_NAME, detail);
-			referenceRMMsgContext.setProperty(SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME, reason);
 			
 			return;
 		} else {

Modified: webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SOAPFaultEnvelopeCreator.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SOAPFaultEnvelopeCreator.java?view=diff&rev=502245&r1=502244&r2=502245
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SOAPFaultEnvelopeCreator.java (original)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SOAPFaultEnvelopeCreator.java Thu Feb  1 07:44:28 2007
@@ -113,7 +113,10 @@
 
 		FaultCode faultCode = new FaultCode(rmNamespaceValue);
 		faultCode.setFaultCode(faultData.getSubcode());
-		faultCode.setDetail(faultData.getDetailString());
+		if (faultData.getDetailString() != null)
+			faultCode.setDetail(faultData.getDetailString());
+		else
+			faultCode.setDetailOMElement(faultData.getDetail());
 		sequenceFault.setFaultCode(faultCode);
 		
 		sequenceFault.toOMElement(faultMessageContext.getEnvelope().getHeader());

Modified: webservices/sandesha/trunk/java/src/org/apache/sandesha2/wsrm/FaultCode.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/wsrm/FaultCode.java?view=diff&rev=502245&r1=502244&r2=502245
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/wsrm/FaultCode.java (original)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/wsrm/FaultCode.java Thu Feb  1 07:44:28 2007
@@ -40,6 +40,8 @@
 
 	private String detail;
 	
+	private OMElement detailOMElement;
+	
 	public FaultCode(String namespaceValue) throws SandeshaException {
 		if (!isNamespaceSupported(namespaceValue))
 			throw new SandeshaException (SandeshaMessageHelper.getMessage(
@@ -105,7 +107,12 @@
 		faultCodeElement.setText(faultCode);
 		sequenceFault.addChild(faultCodeElement);
 
-		detailElement.setText(detail);
+		if (detailOMElement != null)
+			detailElement.addChild(detailOMElement);
+		
+		if (detail != null)
+			detailElement.setText(detail);
+		
 		sequenceFault.addChild(detailElement);
 		
 		return sequenceFault;
@@ -126,7 +133,15 @@
   	public String getDetail() {
   		return detail;
   	}
-  	
+
+  	public OMElement getDetailOMElement() {
+    	return detailOMElement;
+    }
+
+  	public void setDetailOMElement(OMElement detailOMElement) {
+    	this.detailOMElement = detailOMElement;
+    }
+
 	public boolean isNamespaceSupported (String namespaceName) {
 		if (Sandesha2Constants.SPEC_2005_02.NS_URI.equals(namespaceName))
 			return true;

Added: webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/faulttests/CreateSequenceRefusedFaultTest.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/faulttests/CreateSequenceRefusedFaultTest.java?view=auto&rev=502245
==============================================================================
--- webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/faulttests/CreateSequenceRefusedFaultTest.java (added)
+++ webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/faulttests/CreateSequenceRefusedFaultTest.java Thu Feb  1 07:44:28 2007
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2004,2005 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.faulttests;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory;
+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.sandesha2.RMMsgContext;
+import org.apache.sandesha2.Sandesha2Constants;
+import org.apache.sandesha2.SandeshaTestCase;
+import org.apache.sandesha2.storage.beans.RMSBean;
+import org.apache.sandesha2.util.RMMsgCreator;
+import org.apache.sandesha2.util.SpecSpecificConstants;
+import org.apache.sandesha2.wsrm.AcksTo;
+import org.apache.sandesha2.wsrm.CreateSequence;
+
+
+public class CreateSequenceRefusedFaultTest extends SandeshaTestCase {
+
+	private static final String server_repoPath = "target" + File.separator
+	    + "repos" + File.separator + "server";
+
+	private static final String server_axis2_xml = "target" + File.separator
+	    + "repos" + File.separator + "server" + File.separator
+	    + "server_axis2.xml";
+	
+	private ConfigurationContext serverConfigContext;
+	
+	public CreateSequenceRefusedFaultTest() {
+		super("CreateSequenceProcessorTest");
+	}
+
+	public void setUp() throws Exception {
+		super.setUp();
+		serverConfigContext = startServer(server_repoPath, server_axis2_xml);
+	}
+
+	/**
+	 * Sends a Create Sequence message to an RM Destination that will be refused.
+	 * 
+	 * @throws Exception
+	 */
+	public void testInvalidAcksToSOAPFault() throws Exception {
+
+    // Open a connection to the endpoint
+		HttpURLConnection connection = 
+			FaultTestUtils.getHttpURLConnection("http://127.0.0.1:" + serverPort + "/axis2/services/RMSampleService",
+					"http://docs.oasis-open.org/ws-rx/wsrm/200608/CreateSequence");
+
+		OutputStream tmpOut2 = connection.getOutputStream();
+
+		byte ar[] = getMessageAsBytes();
+		
+		// Send the message to the socket.
+		tmpOut2.write(ar);
+		tmpOut2.flush();
+
+		// Get the response message from the connection
+		String message = FaultTestUtils.retrieveResponseMessage(connection);
+    
+    // Check that the fault message isn't null
+    assertNotNull(message);
+    
+    // Check that the response contains the wsrm:CreateSequenceRefused tag    
+    assertTrue(message.indexOf("wsrm:CreateSequenceRefused") > -1);
+    
+    // Disconnect at the end of the test
+    connection.disconnect();
+	}
+	
+	/**
+	 * Get a Create Sequence message as bytes
+	 * 
+	 * This generates a CreateSequenceMessage that has a "bad" AcksTo value which 
+	 * will generate a Fault from the service.
+	 * @return
+	 */
+	private byte[] getMessageAsBytes() throws Exception
+	{
+		String to = "http://127.0.0.1:" + serverPort + "/axis2/services/RMSampleService";
+
+		SOAPFactory factory = new SOAP11Factory();
+		SOAPEnvelope dummyEnvelope = factory.getDefaultEnvelope();
+		
+		// Create a "new" application message
+		MessageContext messageContext = new MessageContext();
+		messageContext.setConfigurationContext(serverConfigContext);
+		messageContext.setAxisService(serverConfigContext.getAxisConfiguration().getService("RMSampleService"));		
+		messageContext.setEnvelope(dummyEnvelope);
+		
+		RMMsgContext applicationRMMsg = new RMMsgContext(messageContext);
+		
+		// Create an RMSBean so the create sequence message can be created
+		RMSBean rmsBean = new RMSBean();
+		rmsBean.setRMVersion(Sandesha2Constants.SPEC_VERSIONS.v1_1);
+		rmsBean.setToEPR(to);
+		
+		// Setup the acksTo 
+		EndpointReference acksTo = new EndpointReference(AddressingConstants.Final.WSA_NONE_URI);
+				
+		// Create a Create Sequence message
+		// generating a new create sequeuce message.
+		RMMsgContext createSeqRMMessage = RMMsgCreator.createCreateSeqMsg(rmsBean, applicationRMMsg, acksTo);
+		messageContext = createSeqRMMessage.getMessageContext();
+		messageContext.setWSAAction(SpecSpecificConstants.getCreateSequenceAction(Sandesha2Constants.SPEC_VERSIONS.v1_1));
+
+		CreateSequence createSeqResPart = (CreateSequence) createSeqRMMessage
+		.getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ);
+
+		createSeqResPart.setAcksTo(
+				new AcksTo(new EndpointReference(AddressingConstants.Final.WSA_NONE_URI), 
+									 SpecSpecificConstants.getRMNamespaceValue(rmsBean.getRMVersion()),
+						       AddressingConstants.Final.WSA_NAMESPACE));
+		
+		// Update the SOAP Envelope of the message
+		createSeqRMMessage.addSOAPEnvelope();
+
+		SOAPEnvelope envelope = createSeqRMMessage.getMessageContext().getEnvelope();
+		
+		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+		
+		envelope.serialize(outputStream);
+		
+		return outputStream.toByteArray();
+	}
+}
+

Added: webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/faulttests/FaultTestUtils.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/faulttests/FaultTestUtils.java?view=auto&rev=502245
==============================================================================
--- webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/faulttests/FaultTestUtils.java (added)
+++ webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/faulttests/FaultTestUtils.java Thu Feb  1 07:44:28 2007
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2004,2005 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.faulttests;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+public class FaultTestUtils {
+
+	/** 
+	 * Sets up a connection to an HTTP endpoint
+	 * @return
+	 */
+	public static HttpURLConnection getHttpURLConnection(String uri, String soapAction) throws Exception {
+    // Open a connection to the endpoint
+		URL endPointURL = new URL(uri);
+		
+		HttpURLConnection connection = (HttpURLConnection) endPointURL.openConnection();
+		connection.setDoOutput(true);
+		connection.setDoInput(true);
+		connection.setRequestMethod("POST");
+		connection.addRequestProperty("SOAPAction", soapAction);
+		connection.setRequestProperty("Content-Type", "text/xml"); 
+		 
+		connection.connect();
+
+		return connection;
+	}
+	
+	/**
+	 * Reads a response from the HttpURLConnection instance
+	 * @param connection
+	 * @return
+	 * @throws IOException 
+	 */
+	public static final String retrieveResponseMessage(HttpURLConnection connection) throws IOException {
+		
+		InputStream tmpIn2 = connection.getInputStream();
+
+		// Read the sync response
+		boolean done = false;
+
+    byte[]      buffer = new byte[4096];
+    String      message = null;
+    int         saved = 0 ;
+    int         len ;
+    
+    a:
+		for (;;) {
+			if (done) {
+				break;
+			}
+
+			len = buffer.length;
+			// Used to be 1, but if we block it doesn't matter
+			// however 1 will break with some servers, including apache
+			if (len == 0) {
+				len = buffer.length;
+			}
+			if (saved + len > buffer.length) {
+				len = buffer.length - saved;
+			}
+			int len1 = 0;
+
+			while (len1 == 0) {
+				try {
+					len1 = tmpIn2.read(buffer, saved, len);
+				} catch (Exception ex) {
+					ex.printStackTrace();
+					if (done && saved == 0) {
+						break a;
+					}
+					len1 = -1;
+					break;
+				}
+			}
+			len = len1;
+
+			if (len == -1 && saved == 0) {
+				break;
+			}
+			if (len == -1) {
+				done = true;
+			}
+
+			// No matter how we may (or may not) format it, send it
+			// on unformatted - we don't want to mess with how its
+			// sent to the other side, just how its displayed
+
+			message = new String(buffer, 0, len);
+
+			System.out.println(message);
+		}
+
+    return message;
+	}
+}

Added: webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/faulttests/UnknownSequenceFaultTest.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/faulttests/UnknownSequenceFaultTest.java?view=auto&rev=502245
==============================================================================
--- webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/faulttests/UnknownSequenceFaultTest.java (added)
+++ webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/faulttests/UnknownSequenceFaultTest.java Thu Feb  1 07:44:28 2007
@@ -0,0 +1,159 @@
+/*
+ * Copyright 2004,2005 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.faulttests;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.sandesha2.RMMsgContext;
+import org.apache.sandesha2.Sandesha2Constants;
+import org.apache.sandesha2.SandeshaTestCase;
+import org.apache.sandesha2.msgreceivers.RMMessageReceiver;
+import org.apache.sandesha2.util.SandeshaUtil;
+import org.apache.sandesha2.util.SpecSpecificConstants;
+import org.apache.sandesha2.wsrm.Identifier;
+import org.apache.sandesha2.wsrm.MessageNumber;
+import org.apache.sandesha2.wsrm.Sequence;
+
+
+public class UnknownSequenceFaultTest extends SandeshaTestCase {
+
+	private static final String server_repoPath = "target" + File.separator
+	    + "repos" + File.separator + "server";
+
+	private static final String server_axis2_xml = "target" + File.separator
+	    + "repos" + File.separator + "server" + File.separator
+	    + "server_axis2.xml";
+	
+	private ConfigurationContext serverConfigContext;
+	
+	public UnknownSequenceFaultTest() {
+		super("CreateSequenceProcessorTest");
+	}
+
+	public void setUp() throws Exception {
+		super.setUp();
+		serverConfigContext = startServer(server_repoPath, server_axis2_xml);
+	}
+
+	/**
+	 * Sends a Create Sequence message to an RM Destination that will be refused.
+	 * 
+	 * @throws Exception
+	 */
+	/**
+	 * Sends an Application message to an RM Destination that will be refused and should be
+	 * rejected with an unknown sequence fault
+	 * 
+	 * @throws Exception
+	 */
+	public void testUnknownSequenceAppMsgSOAPFault() throws Exception {
+    // Open a connection to the endpoint
+		HttpURLConnection connection = 
+			FaultTestUtils.getHttpURLConnection("http://127.0.0.1:" + serverPort + "/axis2/services/RMSampleService",
+					pingAction);
+
+		OutputStream tmpOut2 = connection.getOutputStream();
+		String seqID = SandeshaUtil.getUUID();
+		byte ar[] = getAppMessageAsBytes(seqID);
+		
+		// Send the message to the socket.
+		tmpOut2.write(ar);
+		tmpOut2.flush();
+
+		// Get the response message from the connection
+		String message = FaultTestUtils.retrieveResponseMessage(connection);
+    
+    // Check that the fault message isn't null
+    assertNotNull(message);
+    
+    // Check that the response contains the wsrm:CreateSequenceRefused tag    
+    assertTrue(message.indexOf("wsrm:UnknownSequence") > -1);
+    
+    // Check that the <wsrm:Identifier>seqID</wsrm:Identifier> matches the sequence ID specified
+    String faultID = message.substring(message.indexOf("<wsrm:Identifier>") + 17, message.indexOf("</wsrm:Identifier>"));
+    assertEquals(seqID, faultID);
+    
+    // Disconnect at the end of the test
+    connection.disconnect();
+	}
+	
+	/**
+	 * Get a Create Sequence message as bytes
+	 * 
+	 * This generates an "application" message that has a "sequecnce id" that the RMD
+	 * will not recognise and should generate a fault.
+	 * 
+	 * @return
+	 */
+	private byte[] getAppMessageAsBytes(String uuid) throws Exception
+	{
+		SOAPFactory factory = new SOAP11Factory();
+		SOAPEnvelope dummyEnvelope = factory.getDefaultEnvelope();
+		
+		// Create a "new" application message
+		MessageContext messageContext = new MessageContext();
+		messageContext.setConfigurationContext(serverConfigContext);
+		messageContext.setAxisService(serverConfigContext.getAxisConfiguration().getService("RMSampleService"));		
+		messageContext.setEnvelope(dummyEnvelope);
+		
+		RMMsgContext applicationRMMsg = new RMMsgContext(messageContext);
+		
+		// Generate the Sequence field.
+		// -------------------------------
+		String rmNamespaceValue = SpecSpecificConstants.getRMNamespaceValue(Sandesha2Constants.SPEC_VERSIONS.v1_1);
+
+		Sequence sequence = new Sequence(rmNamespaceValue);
+		MessageNumber msgNumber = new MessageNumber(rmNamespaceValue);
+		msgNumber.setMessageNumber(1);
+		sequence.setMessageNumber(msgNumber);
+		Identifier id1 = new Identifier(rmNamespaceValue);
+		id1.setIndentifer(uuid);
+		sequence.setIdentifier(id1);
+		applicationRMMsg.setMessagePart(Sandesha2Constants.MessageParts.SEQUENCE, sequence);
+		applicationRMMsg.addSOAPEnvelope();
+
+		// --------------------------------------------
+		// Finished generating Sequence part
+		
+		// Create an RMSBean so the create sequence message can be created
+		messageContext.setWSAAction(pingAction);
+
+		// Set the AxisOperation to be InOut
+		AxisOperation operation = messageContext.getAxisService().getOperation(new QName("RMInOutOperation"));
+		operation.setMessageReceiver(new RMMessageReceiver());
+		messageContext.setAxisOperation(operation);
+
+		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+		
+		// Serialize the application message
+		applicationRMMsg.getMessageContext().getEnvelope().serialize(outputStream);
+		
+		return outputStream.toByteArray();
+	}
+}
+



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