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/11/03 10:44:00 UTC
svn commit: r470737 [1/2] - in /webservices/sandesha/trunk/java:
src/org/apache/sandesha2/msgprocessors/ src/org/apache/sandesha2/security/
src/org/apache/sandesha2/security/dummy/
src/org/apache/sandesha2/security/rampart/ src/org/apache/sandesha2/uti...
Author: chamikara
Date: Fri Nov 3 01:43:59 2006
New Revision: 470737
URL: http://svn.apache.org/viewvc?view=rev&rev=470737
Log:
Applied the patch from Matt for Sandesha2-38
Modified:
webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/AckRequestedProcessor.java
webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/ApplicationMsgProcessor.java
webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/CloseSequenceProcessor.java
webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/CreateSeqMsgProcessor.java
webservices/sandesha/trunk/java/src/org/apache/sandesha2/security/SecurityManager.java
webservices/sandesha/trunk/java/src/org/apache/sandesha2/security/dummy/DummySecurityManager.java
webservices/sandesha/trunk/java/src/org/apache/sandesha2/security/rampart/RampartBasedSecurityManager.java
webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/RMMsgCreator.java
webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SequenceManager.java
webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/security/UnitTestSecurityManager.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=470737&r1=470736&r2=470737
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/AckRequestedProcessor.java (original)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/AckRequestedProcessor.java Fri Nov 3 01:43:59 2006
@@ -370,6 +370,16 @@
ackRequestRMMsg.setProperty(Sandesha2Constants.MessageContextProperties.SEQUENCE_PROPERTY_KEY , sequenceKey);
ackRequestRMMsg.addSOAPEnvelope();
+
+ // Ensure the outbound message us secured using the correct token
+ String tokenData = SandeshaUtil.getSequenceProperty(internalSeqenceID,
+ Sandesha2Constants.SequenceProperties.SECURITY_TOKEN,
+ storageManager);
+ if(tokenData != null) {
+ SecurityManager secMgr = SandeshaUtil.getSecurityManager(configurationContext);
+ SecurityToken token = secMgr.recoverSecurityToken(tokenData);
+ secMgr.applySecurityToken(token, msgContext);
+ }
String key = SandeshaUtil.getUUID();
Modified: webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/ApplicationMsgProcessor.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/ApplicationMsgProcessor.java?view=diff&rev=470737&r1=470736&r2=470737
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/ApplicationMsgProcessor.java (original)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/ApplicationMsgProcessor.java Fri Nov 3 01:43:59 2006
@@ -58,7 +58,6 @@
import org.apache.sandesha2.wsrm.MessageNumber;
import org.apache.sandesha2.wsrm.Sequence;
import org.apache.sandesha2.wsrm.SequenceOffer;
-import org.apache.sandesha2.wsrm.UsesSequenceSTR;
/**
* Responsible for processing an incoming Application message.
@@ -560,13 +559,6 @@
if(token != null) {
SecurityManager secManager = SandeshaUtil.getSecurityManager(configCtx);
createSeqBean.setSecurityTokenData(secManager.getTokenRecoveryData(token));
-
- // If we are using token based security, and the 1.1 spec level, then we
- // should introduce a UsesSequenceSTR header into the message.
- if(createSequencePart.getNamespaceValue().equals(Sandesha2Constants.SPEC_2006_08.NS_URI)) {
- UsesSequenceSTR header = new UsesSequenceSTR(null, Sandesha2Constants.SPEC_2006_08.NS_URI);
- header.toSOAPEnvelope(createSeqMsg.getEnvelope());
- }
}
createSeqMgr.insert(createSeqBean);
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=470737&r1=470736&r2=470737
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/CloseSequenceProcessor.java (original)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/CloseSequenceProcessor.java Fri Nov 3 01:43:59 2006
@@ -234,6 +234,16 @@
rmMsgCtx.addSOAPEnvelope();
+ // Ensure the outbound message us secured using the correct token
+ String tokenData = SandeshaUtil.getSequenceProperty(internalSeqenceID,
+ Sandesha2Constants.SequenceProperties.SECURITY_TOKEN,
+ storageManager);
+ if(tokenData != null) {
+ SecurityManager secMgr = SandeshaUtil.getSecurityManager(configurationContext);
+ SecurityToken token = secMgr.recoverSecurityToken(tokenData);
+ secMgr.applySecurityToken(token, msgContext);
+ }
+
String key = SandeshaUtil.getUUID();
SenderBean closeBean = new SenderBean();
Modified: webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/CreateSeqMsgProcessor.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/CreateSeqMsgProcessor.java?view=diff&rev=470737&r1=470736&r2=470737
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/CreateSeqMsgProcessor.java (original)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/CreateSeqMsgProcessor.java Fri Nov 3 01:43:59 2006
@@ -91,10 +91,10 @@
// If the inbound CreateSequence includes a SecurityTokenReference then
// ask the security manager to resolve that to a token for us. We also
// check that the Create was secured using the token.
+ SecurityManager secManager = SandeshaUtil.getSecurityManager(context);
OMElement theSTR = createSeqPart.getSecurityTokenReference();
SecurityToken token = null;
if(theSTR != null) {
- SecurityManager secManager = SandeshaUtil.getSecurityManager(context);
MessageContext msgcontext = createSeqRMMsg.getMessageContext();
token = secManager.getSecurityToken(theSTR, msgcontext);
@@ -116,12 +116,9 @@
SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropertyBeanMgr();
try {
- String newSequenceId = SequenceManager.setupNewSequence(createSeqRMMsg, storageManager); // newly
- // created
- // sequnceID.
-
-
-
+ // Create the new sequence id, as well as establishing the beans that handle the
+ // sequence state.
+ String newSequenceId = SequenceManager.setupNewSequence(createSeqRMMsg, storageManager, secManager, token);
RMMsgContext createSeqResponse = RMMsgCreator.createCreateSeqResponseMsg(createSeqRMMsg, outMessage,
newSequenceId, storageManager); // converting the blank out
@@ -205,6 +202,16 @@
offeredEndpointBean.setValue(endpoint.getEPR().getAddress());
offeredEndpointBean.setSequencePropertyKey(outgoingSideSequencePropertyKey);
seqPropMgr.insert(offeredEndpointBean);
+ }
+
+ // Store the inbound token (if any) with the new sequence
+ if(token != null) {
+ String tokenData = secManager.getTokenRecoveryData(token);
+ SequencePropertyBean tokenBean = new SequencePropertyBean(
+ offeredSequenceID,
+ Sandesha2Constants.SequenceProperties.SECURITY_TOKEN,
+ tokenData);
+ seqPropMgr.insert(tokenBean);
}
} else {
// removing the accept part.
Modified: webservices/sandesha/trunk/java/src/org/apache/sandesha2/security/SecurityManager.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/security/SecurityManager.java?view=diff&rev=470737&r1=470736&r2=470737
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/security/SecurityManager.java (original)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/security/SecurityManager.java Fri Nov 3 01:43:59 2006
@@ -1,101 +1,109 @@
-/*
- * Copyright 2006 The Apache Software Foundation.
- * Copyright 2006 International Business Machines Corp.
- *
- * 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.security;
-
-import org.apache.axiom.om.OMElement;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.description.AxisModule;
-import org.apache.sandesha2.SandeshaException;
-
-/**
- * SecurityManager interface. This manages the link between the RM layer and Security,
- * so that the CreateSequence message can be secured using a SecurityTokenReference.
- * Once the sequence is secured using the STR, each inbound messgae must be checked to
- * ensure the sender has demonstrated proof-of-possession of the referenced token.
- *
- * See the WS-RM 1.0 spec for details.
- */
-public abstract class SecurityManager {
-
- public SecurityManager(ConfigurationContext context) {
-
- }
-
- /**
- * Initialize the security manager. This may perfom setup such as checking the set
- * of sequences that have been persisted over restart, and bootstrapping their
- * security state.
- */
- public abstract void initSecurity(AxisModule moduleDesc);
-
- /**
- * Get a security token to secure an outbound create sequence message. This token
- * will be the one referenced with the body of the CreateSequence. This method may
- * return null, in which case the CreateSequence message will not contain the
- * SecurityTokenReference.
- */
- public abstract SecurityToken getSecurityToken(MessageContext message)
- throws SandeshaException;
-
- /**
- * Get a security token, from a SecurityTokenReference within an inbound message.
- * This method should not return null, so if the Token cannot be found the implementation
- * should throw an exception.
- */
- public abstract SecurityToken getSecurityToken(OMElement theSTR, MessageContext message)
- throws SandeshaException;
-
- /**
- * Create a SecurityTokenReference, suitable for inclusion in the given message.
- * The imelementation may choose to insert security headers into the SOAP envelope at
- * this point, or it may choose to simple place some state into the message context
- * and defer the real work until the security handlers execute.
- */
- public abstract OMElement createSecurityTokenReference(SecurityToken token, MessageContext message)
- throws SandeshaException;
-
- /**
- * Check that the given element of the message demonstrated proof of possession of
- * the given token. This allows Sandesha to implement the checking required by the
- * RM spec. Proof is normally demonstrated by signing or encrypting the the given
- * part using the token.
- * If the elements is not secured with the given token the SecurityManager must
- * throw an exception.
- */
- public abstract void checkProofOfPossession(SecurityToken token, OMElement messagePart, MessageContext message)
- throws SandeshaException;
-
- /**
- * Write the data from this token in to a String. This is here to simplify storing
- * token data into the storage layer - rather than rely on Java serialization we
- * use this method, and the matching SecurityManager method to rebuild the token
- * object.
- */
- public abstract String getTokenRecoveryData(SecurityToken token)
- throws SandeshaException;
-
- /**
- * Reconstruct a token from a String. This method should not return null - if the
- * security manager is unable to recover the token from the correlation data then
- * it should throw an exception.
- */
- public abstract SecurityToken recoverSecurityToken(String tokenData)
- throws SandeshaException;
-
-}
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.security;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisModule;
+import org.apache.sandesha2.SandeshaException;
+
+/**
+ * SecurityManager interface. This manages the link between the RM layer and Security,
+ * so that the CreateSequence message can be secured using a SecurityTokenReference.
+ * Once the sequence is secured using the STR, each inbound messgae must be checked to
+ * ensure the sender has demonstrated proof-of-possession of the referenced token.
+ *
+ * See the WS-RM 1.0 spec for details.
+ */
+public abstract class SecurityManager {
+
+ public SecurityManager(ConfigurationContext context) {
+
+ }
+
+ /**
+ * Initialize the security manager. This may perfom setup such as checking the set
+ * of sequences that have been persisted over restart, and bootstrapping their
+ * security state.
+ */
+ public abstract void initSecurity(AxisModule moduleDesc);
+
+ /**
+ * Get a security token to secure an outbound create sequence message. This token
+ * will be the one referenced with the body of the CreateSequence. This method may
+ * return null, in which case the CreateSequence message will not contain the
+ * SecurityTokenReference.
+ */
+ public abstract SecurityToken getSecurityToken(MessageContext message)
+ throws SandeshaException;
+
+ /**
+ * Get a security token, from a SecurityTokenReference within an inbound message.
+ * This method should not return null, so if the Token cannot be found the implementation
+ * should throw an exception.
+ */
+ public abstract SecurityToken getSecurityToken(OMElement theSTR, MessageContext message)
+ throws SandeshaException;
+
+ /**
+ * Create a SecurityTokenReference, suitable for inclusion in the given message.
+ * The imelementation may choose to insert security headers into the SOAP envelope at
+ * this point, or it may choose to simple place some state into the message context
+ * and defer the real work until the security handlers execute.
+ */
+ public abstract OMElement createSecurityTokenReference(SecurityToken token, MessageContext message)
+ throws SandeshaException;
+
+ /**
+ * Check that the given element of the message demonstrated proof of possession of
+ * the given token. This allows Sandesha to implement the checking required by the
+ * RM spec. Proof is normally demonstrated by signing or encrypting the the given
+ * part using the token.
+ * If the elements is not secured with the given token the SecurityManager must
+ * throw an exception.
+ */
+ public abstract void checkProofOfPossession(SecurityToken token, OMElement messagePart, MessageContext message)
+ throws SandeshaException;
+
+ /**
+ * Write the data from this token in to a String. This is here to simplify storing
+ * token data into the storage layer - rather than rely on Java serialization we
+ * use this method, and the matching SecurityManager method to rebuild the token
+ * object.
+ */
+ public abstract String getTokenRecoveryData(SecurityToken token)
+ throws SandeshaException;
+
+ /**
+ * Reconstruct a token from a String. This method should not return null - if the
+ * security manager is unable to recover the token from the correlation data then
+ * it should throw an exception.
+ */
+ public abstract SecurityToken recoverSecurityToken(String tokenData)
+ throws SandeshaException;
+
+ /**
+ * Ensure that the given token will be associated with an outbound message.
+ * This gives the SecurityManager implementation an opportunity to decorate
+ * the message context with properties that will then be used by the security
+ * handlers.
+ */
+ public abstract void applySecurityToken(SecurityToken token, MessageContext outboundMessage)
+ throws SandeshaException;
+}
Modified: webservices/sandesha/trunk/java/src/org/apache/sandesha2/security/dummy/DummySecurityManager.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/security/dummy/DummySecurityManager.java?view=diff&rev=470737&r1=470736&r2=470737
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/security/dummy/DummySecurityManager.java (original)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/security/dummy/DummySecurityManager.java Fri Nov 3 01:43:59 2006
@@ -1,82 +1,87 @@
-/*
- * Copyright 2006 The Apache Software Foundation.
- * Copyright 2006 International Business Machines Corp.
- *
- * 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.security.dummy;
-
-import org.apache.axiom.om.OMElement;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.description.AxisModule;
-import org.apache.sandesha2.SandeshaException;
-import org.apache.sandesha2.i18n.SandeshaMessageHelper;
-import org.apache.sandesha2.security.SecurityManager;
-import org.apache.sandesha2.security.SecurityToken;
-
-/**
- * A null implementation of a security manager. This manager cannot create tokens, so the
- * messages sent using this manager will not be secured.
- */
-public class DummySecurityManager extends SecurityManager {
-
- public DummySecurityManager(ConfigurationContext context) {
- super(context);
- }
-
- public void initSecurity(AxisModule moduleDesc) {
- }
-
- public void checkProofOfPossession(SecurityToken token, OMElement messagePart, MessageContext message)
- throws SandeshaException
- {
- String msg = SandeshaMessageHelper.getMessage("secureDummyNoProof");
- throw new SandeshaException(msg);
- }
-
- public SecurityToken getSecurityToken(MessageContext message) {
- // Returning null will tell the rest of sandesha to continue without attempting to secure the sequence.
- return null;
- }
-
- public String getTokenRecoveryData(SecurityToken token)
- throws SandeshaException
- {
- String msg = SandeshaMessageHelper.getMessage("secureDummyNoToken");
- throw new SandeshaException(msg);
- }
-
- public SecurityToken recoverSecurityToken(String tokenData)
- throws SandeshaException
- {
- String msg = SandeshaMessageHelper.getMessage("secureDummyNoToken");
- throw new SandeshaException(msg);
- }
-
-
- public SecurityToken getSecurityToken(OMElement theSTR, MessageContext message)
- throws SandeshaException
- {
- String msg = SandeshaMessageHelper.getMessage("secureDummyNoSTR");
- throw new SandeshaException(msg);
- }
-
- public OMElement createSecurityTokenReference(SecurityToken token, MessageContext message) throws SandeshaException {
- String msg = SandeshaMessageHelper.getMessage("secureDummyNoSTR");
- throw new SandeshaException(msg);
- }
-
-
-}
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.security.dummy;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisModule;
+import org.apache.sandesha2.SandeshaException;
+import org.apache.sandesha2.i18n.SandeshaMessageHelper;
+import org.apache.sandesha2.security.SecurityManager;
+import org.apache.sandesha2.security.SecurityToken;
+
+/**
+ * A null implementation of a security manager. This manager cannot create tokens, so the
+ * messages sent using this manager will not be secured.
+ */
+public class DummySecurityManager extends SecurityManager {
+
+ public DummySecurityManager(ConfigurationContext context) {
+ super(context);
+ }
+
+ public void initSecurity(AxisModule moduleDesc) {
+ }
+
+ public void checkProofOfPossession(SecurityToken token, OMElement messagePart, MessageContext message)
+ throws SandeshaException
+ {
+ String msg = SandeshaMessageHelper.getMessage("secureDummyNoProof");
+ throw new SandeshaException(msg);
+ }
+
+ public SecurityToken getSecurityToken(MessageContext message) {
+ // Returning null will tell the rest of sandesha to continue without attempting to secure the sequence.
+ return null;
+ }
+
+ public String getTokenRecoveryData(SecurityToken token)
+ throws SandeshaException
+ {
+ String msg = SandeshaMessageHelper.getMessage("secureDummyNoToken");
+ throw new SandeshaException(msg);
+ }
+
+ public SecurityToken recoverSecurityToken(String tokenData)
+ throws SandeshaException
+ {
+ String msg = SandeshaMessageHelper.getMessage("secureDummyNoToken");
+ throw new SandeshaException(msg);
+ }
+
+
+ public SecurityToken getSecurityToken(OMElement theSTR, MessageContext message)
+ throws SandeshaException
+ {
+ String msg = SandeshaMessageHelper.getMessage("secureDummyNoSTR");
+ throw new SandeshaException(msg);
+ }
+
+ public OMElement createSecurityTokenReference(SecurityToken token, MessageContext message) throws SandeshaException {
+ String msg = SandeshaMessageHelper.getMessage("secureDummyNoSTR");
+ throw new SandeshaException(msg);
+ }
+
+ public void applySecurityToken(SecurityToken token, MessageContext outboundMessage) throws SandeshaException {
+ String msg = SandeshaMessageHelper.getMessage("secureDummyNoSTR");
+ throw new SandeshaException(msg);
+ }
+
+
+}
Modified: webservices/sandesha/trunk/java/src/org/apache/sandesha2/security/rampart/RampartBasedSecurityManager.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/security/rampart/RampartBasedSecurityManager.java?view=diff&rev=470737&r1=470736&r2=470737
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/security/rampart/RampartBasedSecurityManager.java (original)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/security/rampart/RampartBasedSecurityManager.java Fri Nov 3 01:43:59 2006
@@ -310,4 +310,10 @@
private OMElement convertOMElement(OMFactory fac, OMElement elem) {
return new StAXOMBuilder(fac, elem.getXMLStreamReader()).getDocumentElement();
}
+
+ public void applySecurityToken(SecurityToken token, MessageContext outboundMessage) throws SandeshaException {
+ // TODO If there are any properties that should be put onto the outbound message
+ // to ensure that the correct token is used to secure it, then they should be
+ // added now.
+ }
}
Modified: webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/RMMsgCreator.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/RMMsgCreator.java?view=diff&rev=470737&r1=470736&r2=470737
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/RMMsgCreator.java (original)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/RMMsgCreator.java Fri Nov 3 01:43:59 2006
@@ -19,21 +19,17 @@
import java.util.ArrayList;
import java.util.Iterator;
-import java.util.Map;
import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.AddressingConstants;
import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.client.Options;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.OperationContext;
import org.apache.axis2.description.AxisOperation;
-import org.apache.axis2.description.Parameter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.sandesha2.RMMsgContext;
@@ -64,6 +60,7 @@
import org.apache.sandesha2.wsrm.SequenceOffer;
import org.apache.sandesha2.wsrm.TerminateSequence;
import org.apache.sandesha2.wsrm.TerminateSequenceResponse;
+import org.apache.sandesha2.wsrm.UsesSequenceSTR;
/**
* Used to create new RM messages.
@@ -73,124 +70,8 @@
private static Log log = LogFactory.getLog(RMMsgCreator.class);
- private static void initializeCreation(MessageContext relatedMessage, MessageContext newMessage)
- throws SandeshaException {
-
- if (relatedMessage.getAxisService() != null && newMessage.getAxisService() != null
- && newMessage.getAxisService() != relatedMessage.getAxisService()) {
-
- Parameter referencePolicyParam = relatedMessage.getAxisService().getParameter(
- Sandesha2Constants.SANDESHA_PROPERTY_BEAN);
- if (referencePolicyParam != null) {
- Parameter newPolicyParam = new Parameter();
- newPolicyParam.setName(Sandesha2Constants.SANDESHA_PROPERTY_BEAN);
- newPolicyParam.setValue(newPolicyParam.getValue());
- }
- }
-
- if (relatedMessage.getAxisOperation() != null && newMessage.getAxisOperation() != null
- && newMessage.getAxisOperation() != relatedMessage.getAxisOperation()) {
-
- Parameter referencePolicyParam = relatedMessage.getAxisOperation().getParameter(
- Sandesha2Constants.SANDESHA_PROPERTY_BEAN);
- if (referencePolicyParam != null) {
- Parameter newPolicyParam = new Parameter();
- newPolicyParam.setName(Sandesha2Constants.SANDESHA_PROPERTY_BEAN);
- newPolicyParam.setValue(newPolicyParam.getValue());
- }
- }
- }
-
- private static void finalizeCreation(MessageContext relatedMessage, MessageContext newMessage)
- throws SandeshaException {
-
- newMessage.setServerSide(relatedMessage.isServerSide());
-
- // adding all parameters from old message to the new one.
- try {
- // axisOperation parameters
- AxisOperation oldAxisOperation = relatedMessage.getAxisOperation();
- if (oldAxisOperation != null) {
- ArrayList axisOpParams = oldAxisOperation.getParameters();
- if (axisOpParams != null) {
- AxisOperation newAxisOperation = newMessage.getAxisOperation();
- Iterator iter = axisOpParams.iterator();
- while (iter.hasNext()) {
- Parameter nextParam = (Parameter) iter.next();
- Parameter newParam = new Parameter();
-
- newParam.setName(nextParam.getName());
- newParam.setValue(nextParam.getValue());
-
- newAxisOperation.addParameter(newParam);
- }
- }
- }
-
- } catch (AxisFault e) {
- String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.couldNotCopyParameters, e.getLocalizedMessage());
- log.error(message, e);
- throw new SandeshaException(message, e);
- }
-
- // TODO optimize by cloning the Map rather than copying one by one.
-
- // operationContext properties
- OperationContext oldOpContext = relatedMessage.getOperationContext();
- if (oldOpContext != null) {
- Map oldOpContextProperties = oldOpContext.getProperties();
- if (oldOpContextProperties != null) {
- OperationContext newOpContext = newMessage.getOperationContext();
- Iterator keyIter = oldOpContextProperties.keySet().iterator();
- while (keyIter.hasNext()) {
- String key = (String) keyIter.next();
- newOpContext.setProperty(key, oldOpContextProperties.get(key));
- }
- }
- }
-
- // MessageContext properties
- if (relatedMessage != null && newMessage != null) {
- Map oldMsgContextProperties = relatedMessage.getProperties();
- if (oldMsgContextProperties != null) {
- Iterator keyIter = oldMsgContextProperties.keySet().iterator();
- while (keyIter.hasNext()) {
- String key = (String) keyIter.next();
- newMessage.setProperty(key, oldMsgContextProperties.get(key));
- }
- }
- }
-
- // setting an options with properties copied from the old one.
- Options relatesMessageOptions = relatedMessage.getOptions();
- if (relatesMessageOptions != null) {
- Options newMessageOptions = newMessage.getOptions();
- if (newMessageOptions == null) {
- newMessageOptions = new Options();
- newMessage.setOptions(newMessageOptions);
- }
-
- Map relatedMessageProperties = relatesMessageOptions.getProperties();
- Iterator keys = relatedMessageProperties.keySet().iterator();
- while (keys.hasNext()) {
- String key = (String) keys.next();
- newMessageOptions.setProperty(key, relatedMessageProperties.get(key));
- }
-
- Options relatedMessageParentOptions = relatesMessageOptions.getParent();
- if (relatedMessageParentOptions != null) {
- Map relatedMessageParentProperties = relatedMessageParentOptions.getProperties();
- keys = relatedMessageParentProperties.keySet().iterator();
- while (keys.hasNext()) {
- String key = (String) keys.next();
- newMessageOptions.setProperty(key, relatedMessageParentProperties.get(key));
- }
- }
- }
- }
-
/**
- * Create a new CreateSeqnence message.
+ * Create a new CreateSequence message.
*
* @param applicationRMMsg
* @param internalSequenceId
@@ -221,8 +102,6 @@
createSeqmsgContext = SandeshaUtil
.createNewRelatedMessageContext(applicationRMMsg, createSequenceOperation);
- initializeCreation(applicationMsgContext, createSeqmsgContext);
-
OperationContext createSeqOpCtx = createSeqmsgContext.getOperationContext();
String createSeqMsgId = SandeshaUtil.getUUID();
createSeqmsgContext.setMessageID(createSeqMsgId);
@@ -316,6 +195,8 @@
AcksTo acksTo = new AcksTo(acksToEPR,rmNamespaceValue,addressingNamespaceValue);
createSequencePart.setAcksTo(acksTo);
+ createSeqRMMsg.setMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ, createSequencePart);
+
// Find the token that should be used to secure this new sequence. If there is a token, then we
// save it in the properties so that the caller can store the token within the create sequence
// bean.
@@ -326,18 +207,16 @@
createSequencePart.setSecurityTokenReference(str);
createSeqRMMsg.setProperty(Sandesha2Constants.SequenceProperties.SECURITY_TOKEN, token);
- //adding the UseSequenceSTR header
- SOAPFactory createSeqFactory = (SOAPFactory) createSeqRMMsg.getSOAPEnvelope().getOMFactory();
- OMNamespace namespace = createSeqFactory.createOMNamespace(Sandesha2Constants.WSRM_COMMON.NS_PREFIX_RM, createSeqRMMsg.getRMNamespaceValue());
- createSeqFactory.createSOAPHeaderBlock(Sandesha2Constants.WSRM_COMMON.USES_SEQUENCE_STR, namespace);
- }
-
- createSeqRMMsg.setMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ, createSequencePart);
+ // If we are using token based security, and the 1.1 spec level, then we
+ // should introduce a UsesSequenceSTR header into the message.
+ if(createSequencePart.getNamespaceValue().equals(Sandesha2Constants.SPEC_2006_08.NS_URI)) {
+ UsesSequenceSTR header = new UsesSequenceSTR(null, Sandesha2Constants.SPEC_2006_08.NS_URI);
+ header.toSOAPEnvelope(createSeqmsgContext.getEnvelope());
+ }
- try {
- createSeqRMMsg.addSOAPEnvelope();
- } catch (AxisFault e1) {
- throw new SandeshaException(e1.getMessage());
+ // Ensure that the correct token will be used to secure the outbound create sequence message.
+ // We cannot use the normal helper method as we have not stored the token into the sequence bean yet.
+ secMgr.applySecurityToken(token, createSeqRMMsg.getMessageContext());
}
createSeqRMMsg.setAction(SpecSpecificConstants.getCreateSequenceAction(SandeshaUtil.getRMVersion(
@@ -345,8 +224,8 @@
createSeqRMMsg.setSOAPAction(SpecSpecificConstants.getCreateSequenceSOAPAction(SandeshaUtil.getRMVersion(
sequencePropertyKey, storageManager)));
- finalizeCreation(applicationMsgContext, createSeqmsgContext);
-
+ createSeqRMMsg.addSOAPEnvelope();
+
return createSeqRMMsg;
}
@@ -391,8 +270,6 @@
String rmNamespaceValue = SpecSpecificConstants.getRMNamespaceValue(rmVersion);
- initializeCreation(referenceMessage, terminateMessage);
-
if (!SpecSpecificConstants.isTerminateSequenceResponseRequired(rmVersion)) {
terminateMessage.setProperty(MessageContext.TRANSPORT_IN, null);
}
@@ -418,17 +295,12 @@
}
}
- SOAPEnvelope envelope = factory.getDefaultEnvelope();
- terminateRMMessage.setSOAPEnvelop(envelope);
-
TerminateSequence terminateSequencePart = new TerminateSequence(rmNamespaceValue);
Identifier identifier = new Identifier(rmNamespaceValue);
identifier.setIndentifer(sequenceId);
terminateSequencePart.setIdentifier(identifier);
terminateRMMessage.setMessagePart(Sandesha2Constants.MessageParts.TERMINATE_SEQ, terminateSequencePart);
- finalizeCreation(referenceMessage, terminateMessage);
-
terminateMessage.setProperty(MessageContext.TRANSPORT_IN, null); // no
// need
// for
@@ -440,6 +312,9 @@
// terminate
// message. If this is put, sender will look for an response.
+ // Ensure the correct token is used to secure the terminate sequence
+ secureOutboundMessage(sequencePropertyKey, terminateMessage);
+
return terminateRMMessage;
}
@@ -507,8 +382,6 @@
outMessage.setEnvelope(envelope);
- initializeCreation(createSeqMessage.getMessageContext(), outMessage);
-
RMMsgContext createSeqResponse = null;
try {
createSeqResponse = MsgInitializer.initializeMessage(outMessage);
@@ -518,9 +391,11 @@
createSeqResponse.setMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ_RESPONSE, response);
- finalizeCreation(createSeqMessage.getMessageContext(), outMessage);
-
createSeqMessage.getMessageContext().setServerSide(true);
+
+ // Ensure the correct token is used to secure the create sequence response
+ secureOutboundMessage(newSequenceID, outMessage);
+
return createSeqResponse;
}
@@ -554,13 +429,13 @@
outMessage.setSoapAction(SpecSpecificConstants.getTerminateSequenceResponseAction(SandeshaUtil.getRMVersion(
sequenceID, storageManager)));
- initializeCreation(terminateSeqRMMsg.getMessageContext(), outMessage);
-
terminateSeqResponseRMMsg.addSOAPEnvelope();
- finalizeCreation(terminateSeqRMMsg.getMessageContext(), outMessage);
-
terminateSeqResponseRMMsg.getMessageContext().setServerSide(true);
+
+ // Ensure the correct token is used to secure the terminate sequence response
+ secureOutboundMessage(sequenceID, outMessage);
+
return terminateSeqResponseRMMsg;
}
@@ -594,12 +469,12 @@
outMessage.setSoapAction(SpecSpecificConstants.getCloseSequenceResponseAction(SandeshaUtil.getRMVersion(
sequenceID, storageManager)));
- initializeCreation(closeSeqRMMsg.getMessageContext(), outMessage);
-
closeSeqResponseRMMsg.addSOAPEnvelope();
-
- finalizeCreation(closeSeqRMMsg.getMessageContext(), outMessage);
closeSeqResponseRMMsg.getMessageContext().setServerSide(true);
+
+ // Ensure the correct token is used to secure the close sequence response
+ secureOutboundMessage(sequenceID, outMessage);
+
return closeSeqResponseRMMsg;
}
@@ -669,6 +544,9 @@
//generating the SOAP envelope.
applicationMsg.addSOAPEnvelope();
+
+ // Ensure the message also contains the token that needs to be used
+ secureOutboundMessage(sequencePropertyKey, applicationMsg.getMessageContext());
}
public static RMMsgContext createMakeConnectionMessage (RMMsgContext referenceRMMessage, String makeConnectionSeqId,
@@ -710,7 +588,30 @@
//generating the SOAP Envelope.
makeConnectionRMMessageCtx.addSOAPEnvelope();
+ // TODO work out how to find the correct sequence property key to look up the token
+ // that we should include in the makeConnection (assuming we need one)
+
return makeConnectionRMMessageCtx;
+ }
+
+ private static void secureOutboundMessage(String sequenceKey, MessageContext message)
+ throws SandeshaException
+ {
+ if(log.isDebugEnabled()) log.debug("Entry: RMMsgCreator::secureOutboundMessage");
+
+ ConfigurationContext configCtx = message.getConfigurationContext();
+ StorageManager storageManager = SandeshaUtil.getSandeshaStorageManager(configCtx, configCtx.getAxisConfiguration());
+ SequencePropertyBeanMgr sequencePropMgr = storageManager.getSequencePropertyBeanMgr();
+
+ SequencePropertyBean tokenBean = sequencePropMgr.retrieve(sequenceKey, Sandesha2Constants.SequenceProperties.SECURITY_TOKEN);
+ if(tokenBean != null) {
+ if(log.isDebugEnabled()) log.debug("Securing outbound message");
+ SecurityManager secManager = SandeshaUtil.getSecurityManager(configCtx);
+ SecurityToken token = secManager.recoverSecurityToken(tokenBean.getValue());
+ secManager.applySecurityToken(token, message);
+ }
+
+ if(log.isDebugEnabled()) log.debug("Exit: RMMsgCreator::secureOutboundMessage");
}
}
Modified: webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SequenceManager.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SequenceManager.java?view=diff&rev=470737&r1=470736&r2=470737
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SequenceManager.java (original)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/SequenceManager.java Fri Nov 3 01:43:59 2006
@@ -1,565 +1,575 @@
-/*
- * Created on Sep 5, 2005
- *
- * TODO To change the template for this generated file go to
- * Window - Preferences - Java - Code Style - Code Templates
- */
-package org.apache.sandesha2.util;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Collection;
-
-import javax.xml.namespace.QName;
-
-import org.apache.axis2.AxisFault;
-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.MessageContextConstants;
-import org.apache.axis2.context.OperationContext;
-import org.apache.axis2.context.OperationContextFactory;
-import org.apache.axis2.description.TransportInDescription;
-import org.apache.axis2.engine.ListenerManager;
-import org.apache.axis2.i18n.Messages;
-import org.apache.axis2.wsdl.WSDLConstants.WSDL20_2004Constants;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.sandesha2.RMMsgContext;
-import org.apache.sandesha2.Sandesha2Constants;
-import org.apache.sandesha2.SandeshaException;
-import org.apache.sandesha2.client.SandeshaClientConstants;
-import org.apache.sandesha2.i18n.SandeshaMessageHelper;
-import org.apache.sandesha2.i18n.SandeshaMessageKeys;
-import org.apache.sandesha2.policy.SandeshaPolicyBean;
-import org.apache.sandesha2.storage.StorageManager;
-import org.apache.sandesha2.storage.beanmanagers.NextMsgBeanMgr;
-import org.apache.sandesha2.storage.beanmanagers.SequencePropertyBeanMgr;
-import org.apache.sandesha2.storage.beans.NextMsgBean;
-import org.apache.sandesha2.storage.beans.SequencePropertyBean;
-import org.apache.sandesha2.wsrm.CreateSequence;
-
-/**
- * This is used to set up a new sequence, both at the sending side and the
- * receiving side.
- */
-
-public class SequenceManager {
-
- private static Log log = LogFactory.getLog(SequenceManager.class);
-
- public static String setupNewSequence(RMMsgContext createSequenceMsg, StorageManager storageManager)
- throws AxisFault {
-
- String sequenceId = SandeshaUtil.getUUID();
-
- EndpointReference to = createSequenceMsg.getTo();
- if (to == null) {
- String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.toEPRNotValid, null);
- log.debug(message);
- throw new AxisFault(message);
- }
-
- EndpointReference replyTo = createSequenceMsg.getReplyTo();
-
- CreateSequence createSequence = (CreateSequence) createSequenceMsg
- .getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ);
- if (createSequence == null) {
- String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.createSeqEntryNotFound);
- log.debug(message);
- throw new AxisFault(message);
- }
-
- EndpointReference acksTo = createSequence.getAcksTo().getEPR();
-
- if (acksTo == null) {
- String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.noAcksToPartInCreateSequence);
- log.debug(message);
- throw new AxisFault(message);
- }
-
- ConfigurationContext configurationContext = createSequenceMsg.getMessageContext().getConfigurationContext();
-
- SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropertyBeanMgr();
-
- SequencePropertyBean receivedMsgBean = new SequencePropertyBean(sequenceId,
- Sandesha2Constants.SequenceProperties.SERVER_COMPLETED_MESSAGES, "");
-
- // setting the addressing version
- String addressingNamespaceValue = createSequenceMsg.getAddressingNamespaceValue();
- SequencePropertyBean addressingNamespaceBean = new SequencePropertyBean(sequenceId,
- Sandesha2Constants.SequenceProperties.ADDRESSING_NAMESPACE_VALUE, addressingNamespaceValue);
- seqPropMgr.insert(addressingNamespaceBean);
-
- String anonymousURI = SpecSpecificConstants.getAddressingAnonymousURI(addressingNamespaceValue);
-
- // If no replyTo value. Send responses as sync.
- SequencePropertyBean toBean = null;
- if (replyTo != null) {
- toBean = new SequencePropertyBean(sequenceId, Sandesha2Constants.SequenceProperties.TO_EPR, replyTo
- .getAddress());
- } else {
- toBean = new SequencePropertyBean(sequenceId, Sandesha2Constants.SequenceProperties.TO_EPR, anonymousURI);
- }
-
- SequencePropertyBean replyToBean = new SequencePropertyBean(sequenceId,
- Sandesha2Constants.SequenceProperties.REPLY_TO_EPR, to.getAddress());
- SequencePropertyBean acksToBean = new SequencePropertyBean(sequenceId,
- Sandesha2Constants.SequenceProperties.ACKS_TO_EPR, acksTo.getAddress());
-
- seqPropMgr.insert(receivedMsgBean);
- seqPropMgr.insert(replyToBean);
- seqPropMgr.insert(acksToBean);
-
- if (toBean != null)
- seqPropMgr.insert(toBean);
-
- NextMsgBeanMgr nextMsgMgr = storageManager.getNextMsgBeanMgr();
- nextMsgMgr.insert(new NextMsgBean(sequenceId, 1)); // 1 will be the
- // next
-
- // message to invoke. This will apply for only in-order invocations.
-
- SandeshaUtil.startSenderForTheSequence(configurationContext, sequenceId);
-
- // stting the RM SPEC version for this sequence.
- String createSequenceMsgAction = createSequenceMsg.getWSAAction();
- if (createSequenceMsgAction == null)
- throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.noWSAACtionValue));
-
- String messageRMNamespace = createSequence.getNamespaceValue();
-
- String specVersion = null;
- if (Sandesha2Constants.SPEC_2005_02.NS_URI.equals(messageRMNamespace)) {
- specVersion = Sandesha2Constants.SPEC_VERSIONS.v1_0;
- } else if (Sandesha2Constants.SPEC_2006_08.NS_URI.equals(messageRMNamespace)) {
- specVersion = Sandesha2Constants.SPEC_VERSIONS.v1_1;
- } else {
- throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.cannotDecideRMVersion));
- }
-
- SequencePropertyBean specVerionBean = new SequencePropertyBean();
- specVerionBean.setSequencePropertyKey(sequenceId);
- specVerionBean.setName(Sandesha2Constants.SequenceProperties.RM_SPEC_VERSION);
- specVerionBean.setValue(specVersion);
-
- seqPropMgr.insert(specVerionBean);
-
- // TODO get the SOAP version from the create seq message.
-
- return sequenceId;
- }
-
- public void removeSequence(String sequence) {
-
- }
-
- public static void setupNewClientSequence(MessageContext firstAplicationMsgCtx, String sequencePropertyKey,
- String specVersion, StorageManager storageManager) throws SandeshaException {
-
- ConfigurationContext configurationContext = firstAplicationMsgCtx.getConfigurationContext();
-
- SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropertyBeanMgr();
-
- // setting the addressing version
- String addressingNamespace = (String) firstAplicationMsgCtx
- .getProperty(AddressingConstants.WS_ADDRESSING_VERSION);
-
- if (addressingNamespace == null) {
- OperationContext opCtx = firstAplicationMsgCtx.getOperationContext();
- if (opCtx != null) {
- try {
- MessageContext requestMsg = opCtx.getMessageContext(OperationContextFactory.MESSAGE_LABEL_IN_VALUE);
- if (requestMsg != null)
- addressingNamespace = (String) requestMsg
- .getProperty(AddressingConstants.WS_ADDRESSING_VERSION);
- } catch (AxisFault e) {
- throw new SandeshaException(e);
- }
- }
- }
-
- if (addressingNamespace == null)
- addressingNamespace = AddressingConstants.Final.WSA_NAMESPACE; // defaults
- // to
- // Final.
- // Make
- // sure
- // this
- // is
- // synchronized
- // with
- // addressing.
-
- SequencePropertyBean addressingNamespaceBean = new SequencePropertyBean(sequencePropertyKey,
- Sandesha2Constants.SequenceProperties.ADDRESSING_NAMESPACE_VALUE, addressingNamespace);
- seqPropMgr.insert(addressingNamespaceBean);
-
-
- //setting the SOAPVersion Bean.
- String SOAPVersion = firstAplicationMsgCtx.getOptions().getSoapVersionURI();
- SequencePropertyBean SOAPVersionBean = new SequencePropertyBean (sequencePropertyKey,
- Sandesha2Constants.SequenceProperties.SOAP_VERSION, SOAPVersion);
-
- seqPropMgr.insert(SOAPVersionBean);
-
-
- String anonymousURI = SpecSpecificConstants.getAddressingAnonymousURI(addressingNamespace);
-
- EndpointReference toEPR = firstAplicationMsgCtx.getTo();
- String acksTo = (String) firstAplicationMsgCtx.getProperty(SandeshaClientConstants.AcksTo);
-
- if (toEPR == null) {
- String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.toEPRNotValid, null);
- log.debug(message);
- throw new SandeshaException(message);
- }
-
- SequencePropertyBean toBean = new SequencePropertyBean(sequencePropertyKey,
- Sandesha2Constants.SequenceProperties.TO_EPR, toEPR.getAddress());
- SequencePropertyBean replyToBean = null;
- SequencePropertyBean acksToBean = null;
-
- if (firstAplicationMsgCtx.isServerSide()) {
- // setting replyTo value, if this is the server side.
- OperationContext opContext = firstAplicationMsgCtx.getOperationContext();
- try {
- MessageContext requestMessage = opContext
- .getMessageContext(OperationContextFactory.MESSAGE_LABEL_IN_VALUE);
- if (requestMessage == null) {
- String message = SandeshaMessageHelper
- .getMessage(SandeshaMessageKeys.cannotFindReqMsgFromOpContext);
- log.error(message);
- throw new SandeshaException(message);
- }
-
- EndpointReference replyToEPR = requestMessage.getTo(); // 'replyTo'
- // of
- // the
- // response
- // msg
- // is
- // the
- // 'to'
- // value
- // of
- // the
- // req
- // msg.
- if (replyToEPR != null) {
- replyToBean = new SequencePropertyBean(sequencePropertyKey,
- Sandesha2Constants.SequenceProperties.REPLY_TO_EPR, replyToEPR.getAddress());
- acksToBean = new SequencePropertyBean(sequencePropertyKey,
- Sandesha2Constants.SequenceProperties.ACKS_TO_EPR, replyToEPR.getAddress());
- } else {
- String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.toEPRNotValid, null);
- log.error(message);
- throw new SandeshaException(message);
- }
- } catch (AxisFault e) {
- String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.cannotFindReqMsgFromOpContext);
- log.error(message);
- log.error(e.getStackTrace());
- throw new SandeshaException(message);
- }
- } else {
-
- EndpointReference replyToEPR = firstAplicationMsgCtx.getReplyTo();
- //setting replyTo and acksTo beans.
-
- if (replyToEPR!=null)
- replyToBean = new SequencePropertyBean(sequencePropertyKey,
- Sandesha2Constants.SequenceProperties.REPLY_TO_EPR, replyToEPR.getAddress());
-
- //TODO set AcksToBean.
- }
-
- // Default value for acksTo is anonymous (this happens only for the
- // client side)
- if (acksTo == null) {
- acksTo = anonymousURI;
- }
-
- acksToBean = new SequencePropertyBean(sequencePropertyKey, Sandesha2Constants.SequenceProperties.ACKS_TO_EPR,
- acksTo);
-
- // start the in listner for the client side, if acksTo is not anonymous.
- if (!firstAplicationMsgCtx.isServerSide() && !anonymousURI.equals(acksTo)) {
-
- String transportInProtocol = firstAplicationMsgCtx.getOptions().getTransportInProtocol();
- if (transportInProtocol == null) {
- throw new SandeshaException(SandeshaMessageHelper
- .getMessage(SandeshaMessageKeys.cannotStartListenerForIncommingMsgs));
- }
-
- try {
- ListenerManager listenerManager = firstAplicationMsgCtx.getConfigurationContext().getListenerManager();
- TransportInDescription transportIn = firstAplicationMsgCtx.getConfigurationContext()
- .getAxisConfiguration().getTransportIn(new QName(transportInProtocol));
- // if acksTo is not anonymous start the in-transport
- if (!listenerManager.isListenerRunning(transportIn.getName().getLocalPart())) {
- listenerManager.addListener(transportIn, false);
- }
- } catch (AxisFault e) {
- throw new SandeshaException(SandeshaMessageHelper.getMessage(
- SandeshaMessageKeys.cannotStartTransportListenerDueToError, e.toString()), e);
- }
-
- }
-
- SequencePropertyBean msgsBean = new SequencePropertyBean();
- msgsBean.setSequencePropertyKey(sequencePropertyKey);
- msgsBean.setName(Sandesha2Constants.SequenceProperties.CLIENT_COMPLETED_MESSAGES);
- msgsBean.setValue("");
-
- seqPropMgr.insert(msgsBean);
-
- seqPropMgr.insert(toBean);
- if (acksToBean != null)
- seqPropMgr.insert(acksToBean);
- if (replyToBean != null)
- seqPropMgr.insert(replyToBean);
-
- // saving transportTo value;
- String transportTo = (String) firstAplicationMsgCtx.getProperty(MessageContextConstants.TRANSPORT_URL);
- if (transportTo != null) {
- SequencePropertyBean transportToBean = new SequencePropertyBean();
- transportToBean.setSequencePropertyKey(sequencePropertyKey);
- transportToBean.setName(Sandesha2Constants.SequenceProperties.TRANSPORT_TO);
- transportToBean.setValue(transportTo);
-
- seqPropMgr.insert(transportToBean);
- }
-
- // setting the spec version for the client side.
- SequencePropertyBean specVerionBean = new SequencePropertyBean();
- specVerionBean.setSequencePropertyKey(sequencePropertyKey);
- specVerionBean.setName(Sandesha2Constants.SequenceProperties.RM_SPEC_VERSION);
- specVerionBean.setValue(specVersion);
- seqPropMgr.insert(specVerionBean);
-
- // updating the last activated time.
- updateLastActivatedTime(sequencePropertyKey, storageManager);
-
- SandeshaUtil.startSenderForTheSequence(configurationContext, sequencePropertyKey);
-
-
- updateClientSideListnerIfNeeded(firstAplicationMsgCtx, anonymousURI);
-
- }
-
- private static void updateClientSideListnerIfNeeded(MessageContext messageContext, String addressingAnonymousURI)
- throws SandeshaException {
- if (messageContext.isServerSide())
- return; // listners are updated only for the client side.
-
- String transportInProtocol = messageContext.getOptions().getTransportInProtocol();
-
- String acksTo = (String) messageContext.getProperty(SandeshaClientConstants.AcksTo);
- String mep = messageContext.getAxisOperation().getMessageExchangePattern();
-
- boolean startListnerForAsyncAcks = false;
- boolean startListnerForAsyncControlMsgs = false; // For async
- // createSerRes &
- // terminateSeq.
-
- if (acksTo != null && !addressingAnonymousURI.equals(acksTo)) {
- // starting listner for async acks.
- startListnerForAsyncAcks = true;
- }
-
- try {
- if ((startListnerForAsyncAcks || startListnerForAsyncControlMsgs) ) {
-
- if (transportInProtocol == null){
- EndpointReference toEPR = messageContext.getOptions().getTo();
- if (toEPR==null) {
- String message = SandeshaMessageHelper.getMessage(
- SandeshaMessageKeys.toEPRNotSet);
- throw new AxisFault (message);
- }
-
- try {
- URI uri = new URI (toEPR.getAddress());
- String scheme = uri.getScheme();
-
- //this is a convention is Axis2. The name of the TransportInDescription has to be the
- //scheme of a URI of that transport.
- //Here we also assume that the Incoming transport will be same as the outgoing one.
- transportInProtocol = scheme;
- } catch (URISyntaxException e) {
- throw new SandeshaException (e);
- }
-
- }
-
- //TODO following code was taken from ServiceContext.gegMyEPR method.
- // When a listner-starting method becomes available from Axis2, use that.
- ConfigurationContext configctx = messageContext.getConfigurationContext();
- ListenerManager lm = configctx.getListenerManager();
- if (!lm.isListenerRunning(transportInProtocol)) {
- TransportInDescription trsin = configctx.getAxisConfiguration().
- getTransportIn(new QName(transportInProtocol));
- if (trsin != null) {
- lm.addListener(trsin, false);
- } else {
- String message = SandeshaMessageHelper.getMessage(
- SandeshaMessageKeys.cannotFindTransportInDesc,transportInProtocol);
- throw new AxisFault(message);
- }
- }
- }
-
- } catch (AxisFault e) {
- String message = SandeshaMessageHelper.getMessage(
- SandeshaMessageKeys.cannotStartTransportListenerDueToError, e.toString());
- log.error(e.getStackTrace());
- throw new SandeshaException(message, e);
- }
-
- }
-
- /**
- * Takes the internalSeqID as the param. Not the sequenceID.
- *
- * @param internalSequenceID
- * @param configContext
- * @throws SandeshaException
- */
- public static void updateLastActivatedTime(String sequencePropertyKey, StorageManager storageManager)
- throws SandeshaException {
- // Transaction lastActivatedTransaction =
- // storageManager.getTransaction();
- SequencePropertyBeanMgr sequencePropertyBeanMgr = storageManager.getSequencePropertyBeanMgr();
-
- SequencePropertyBean lastActivatedBean = sequencePropertyBeanMgr.retrieve(sequencePropertyKey,
- Sandesha2Constants.SequenceProperties.LAST_ACTIVATED_TIME);
-
- boolean added = false;
-
- if (lastActivatedBean == null) {
- added = true;
- lastActivatedBean = new SequencePropertyBean();
- lastActivatedBean.setSequencePropertyKey(sequencePropertyKey);
- lastActivatedBean.setName(Sandesha2Constants.SequenceProperties.LAST_ACTIVATED_TIME);
- }
-
- long currentTime = System.currentTimeMillis();
- lastActivatedBean.setValue(Long.toString(currentTime));
-
- if (added)
- sequencePropertyBeanMgr.insert(lastActivatedBean);
- else
- sequencePropertyBeanMgr.update(lastActivatedBean);
-
- }
-
- public static long getLastActivatedTime(String propertyKey, StorageManager storageManager) throws SandeshaException {
-
- SequencePropertyBeanMgr seqPropBeanMgr = storageManager.getSequencePropertyBeanMgr();
-
- SequencePropertyBean lastActivatedBean = seqPropBeanMgr.retrieve(propertyKey,
- Sandesha2Constants.SequenceProperties.LAST_ACTIVATED_TIME);
-
- long lastActivatedTime = -1;
-
- if (lastActivatedBean != null) {
- lastActivatedTime = Long.parseLong(lastActivatedBean.getValue());
- }
-
- return lastActivatedTime;
- }
-
- public static boolean hasSequenceTimedOut(String propertyKey, RMMsgContext rmMsgCtx, StorageManager storageManager)
- throws SandeshaException {
-
- // operation is the lowest level, Sandesha2 could be engaged.
- SandeshaPolicyBean propertyBean = SandeshaUtil.getPropertyBean(rmMsgCtx.getMessageContext()
- .getAxisOperation());
-
- if (propertyBean.getInactivityTimeoutInterval() <= 0)
- return false;
-
- boolean sequenceTimedOut = false;
-
- long lastActivatedTime = getLastActivatedTime(propertyKey, storageManager);
- long timeNow = System.currentTimeMillis();
- if (lastActivatedTime > 0 && (lastActivatedTime + propertyBean.getInactivityTimeoutInterval() < timeNow))
- sequenceTimedOut = true;
-
- return sequenceTimedOut;
- }
-
- public static long getOutGoingSequenceAckedMessageCount(String sequencePropertyKey, StorageManager storageManager)
- throws SandeshaException {
- // / Transaction transaction = storageManager.getTransaction();
- SequencePropertyBeanMgr seqPropBeanMgr = storageManager.getSequencePropertyBeanMgr();
-
- SequencePropertyBean ackedMsgBean = seqPropBeanMgr.retrieve(sequencePropertyKey,
- Sandesha2Constants.SequenceProperties.NO_OF_OUTGOING_MSGS_ACKED);
- if (ackedMsgBean == null)
- return 0; // No acknowledgement has been received yet.
-
- long noOfMessagesAcked = Long.parseLong(ackedMsgBean.getValue());
- // / transaction.commit();
-
- return noOfMessagesAcked;
- }
-
- public static boolean isOutGoingSequenceCompleted(String internalSequenceID, StorageManager storageManager)
- throws SandeshaException {
- // / Transaction transaction = storageManager.getTransaction();
- SequencePropertyBeanMgr seqPropBeanMgr = storageManager.getSequencePropertyBeanMgr();
-
- SequencePropertyBean findSeqIDBean = new SequencePropertyBean();
- findSeqIDBean.setValue(internalSequenceID);
- findSeqIDBean.setName(Sandesha2Constants.SequenceProperties.INTERNAL_SEQUENCE_ID);
- Collection seqIDBeans = seqPropBeanMgr.find(findSeqIDBean);
-
- if (seqIDBeans.size() == 0) {
- String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.noSequenceEstablished);
- log.debug(message);
- throw new SandeshaException(message);
- }
-
- if (seqIDBeans.size() > 1) {
- String message = SandeshaMessageHelper.getMessage(
- SandeshaMessageKeys.cannotGenerateReportNonUniqueSequence, internalSequenceID);
- log.debug(message);
- throw new SandeshaException(message);
- }
-
- SequencePropertyBean seqIDBean = (SequencePropertyBean) seqIDBeans.iterator().next();
- String sequenceID = seqIDBean.getSequencePropertyKey();
-
- SequencePropertyBean terminateAddedBean = seqPropBeanMgr.retrieve(sequenceID,
- Sandesha2Constants.SequenceProperties.TERMINATE_ADDED);
- if (terminateAddedBean == null)
- return false;
-
- if ("true".equals(terminateAddedBean.getValue()))
- return true;
-
- // / transaction.commit();
- return false;
- }
-
- public static boolean isIncomingSequenceCompleted(String sequenceID, StorageManager storageManager)
- throws SandeshaException {
-
- // / Transaction transaction = storageManager.getTransaction();
- SequencePropertyBeanMgr seqPropBeanMgr = storageManager.getSequencePropertyBeanMgr();
-
- SequencePropertyBean terminateReceivedBean = seqPropBeanMgr.retrieve(sequenceID,
- Sandesha2Constants.SequenceProperties.TERMINATE_RECEIVED);
- boolean complete = false;
-
- if (terminateReceivedBean != null && "true".equals(terminateReceivedBean.getValue()))
- complete = true;
-
- // / transaction.commit();
- return complete;
- }
-
-}
+/*
+ * Created on Sep 5, 2005
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.apache.sandesha2.util;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Collection;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axis2.AxisFault;
+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.MessageContextConstants;
+import org.apache.axis2.context.OperationContext;
+import org.apache.axis2.context.OperationContextFactory;
+import org.apache.axis2.description.TransportInDescription;
+import org.apache.axis2.engine.ListenerManager;
+import org.apache.axis2.i18n.Messages;
+import org.apache.axis2.wsdl.WSDLConstants.WSDL20_2004Constants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.sandesha2.RMMsgContext;
+import org.apache.sandesha2.Sandesha2Constants;
+import org.apache.sandesha2.SandeshaException;
+import org.apache.sandesha2.client.SandeshaClientConstants;
+import org.apache.sandesha2.i18n.SandeshaMessageHelper;
+import org.apache.sandesha2.i18n.SandeshaMessageKeys;
+import org.apache.sandesha2.policy.SandeshaPolicyBean;
+import org.apache.sandesha2.security.SecurityManager;
+import org.apache.sandesha2.security.SecurityToken;
+import org.apache.sandesha2.storage.StorageManager;
+import org.apache.sandesha2.storage.beanmanagers.NextMsgBeanMgr;
+import org.apache.sandesha2.storage.beanmanagers.SequencePropertyBeanMgr;
+import org.apache.sandesha2.storage.beans.NextMsgBean;
+import org.apache.sandesha2.storage.beans.SequencePropertyBean;
+import org.apache.sandesha2.wsrm.CreateSequence;
+
+/**
+ * This is used to set up a new sequence, both at the sending side and the
+ * receiving side.
+ */
+
+public class SequenceManager {
+
+ private static Log log = LogFactory.getLog(SequenceManager.class);
+
+ public static String setupNewSequence(RMMsgContext createSequenceMsg, StorageManager storageManager, SecurityManager securityManager, SecurityToken token)
+ throws AxisFault {
+
+ String sequenceId = SandeshaUtil.getUUID();
+
+ EndpointReference to = createSequenceMsg.getTo();
+ if (to == null) {
+ String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.toEPRNotValid, null);
+ log.debug(message);
+ throw new AxisFault(message);
+ }
+
+ EndpointReference replyTo = createSequenceMsg.getReplyTo();
+
+ CreateSequence createSequence = (CreateSequence) createSequenceMsg
+ .getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ);
+ if (createSequence == null) {
+ String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.createSeqEntryNotFound);
+ log.debug(message);
+ throw new AxisFault(message);
+ }
+
+ EndpointReference acksTo = createSequence.getAcksTo().getEPR();
+
+ if (acksTo == null) {
+ String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.noAcksToPartInCreateSequence);
+ log.debug(message);
+ throw new AxisFault(message);
+ }
+
+ ConfigurationContext configurationContext = createSequenceMsg.getMessageContext().getConfigurationContext();
+
+ SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropertyBeanMgr();
+
+ SequencePropertyBean receivedMsgBean = new SequencePropertyBean(sequenceId,
+ Sandesha2Constants.SequenceProperties.SERVER_COMPLETED_MESSAGES, "");
+
+ // setting the addressing version
+ String addressingNamespaceValue = createSequenceMsg.getAddressingNamespaceValue();
+ SequencePropertyBean addressingNamespaceBean = new SequencePropertyBean(sequenceId,
+ Sandesha2Constants.SequenceProperties.ADDRESSING_NAMESPACE_VALUE, addressingNamespaceValue);
+ seqPropMgr.insert(addressingNamespaceBean);
+
+ String anonymousURI = SpecSpecificConstants.getAddressingAnonymousURI(addressingNamespaceValue);
+
+ // If no replyTo value. Send responses as sync.
+ SequencePropertyBean toBean = null;
+ if (replyTo != null) {
+ toBean = new SequencePropertyBean(sequenceId, Sandesha2Constants.SequenceProperties.TO_EPR, replyTo
+ .getAddress());
+ } else {
+ toBean = new SequencePropertyBean(sequenceId, Sandesha2Constants.SequenceProperties.TO_EPR, anonymousURI);
+ }
+
+ SequencePropertyBean replyToBean = new SequencePropertyBean(sequenceId,
+ Sandesha2Constants.SequenceProperties.REPLY_TO_EPR, to.getAddress());
+ SequencePropertyBean acksToBean = new SequencePropertyBean(sequenceId,
+ Sandesha2Constants.SequenceProperties.ACKS_TO_EPR, acksTo.getAddress());
+
+ seqPropMgr.insert(receivedMsgBean);
+ seqPropMgr.insert(replyToBean);
+ seqPropMgr.insert(acksToBean);
+
+ if (toBean != null)
+ seqPropMgr.insert(toBean);
+
+ // Store the security token alongside the sequence
+ if(token != null) {
+ String tokenData = securityManager.getTokenRecoveryData(token);
+ SequencePropertyBean tokenBean = new SequencePropertyBean(sequenceId,
+ Sandesha2Constants.SequenceProperties.SECURITY_TOKEN, tokenData);
+ seqPropMgr.insert(tokenBean);
+ }
+
+ NextMsgBeanMgr nextMsgMgr = storageManager.getNextMsgBeanMgr();
+ nextMsgMgr.insert(new NextMsgBean(sequenceId, 1)); // 1 will be the
+ // next
+
+ // message to invoke. This will apply for only in-order invocations.
+
+ SandeshaUtil.startSenderForTheSequence(configurationContext, sequenceId);
+
+ // stting the RM SPEC version for this sequence.
+ String createSequenceMsgAction = createSequenceMsg.getWSAAction();
+ if (createSequenceMsgAction == null)
+ throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.noWSAACtionValue));
+
+ String messageRMNamespace = createSequence.getNamespaceValue();
+
+ String specVersion = null;
+ if (Sandesha2Constants.SPEC_2005_02.NS_URI.equals(messageRMNamespace)) {
+ specVersion = Sandesha2Constants.SPEC_VERSIONS.v1_0;
+ } else if (Sandesha2Constants.SPEC_2006_08.NS_URI.equals(messageRMNamespace)) {
+ specVersion = Sandesha2Constants.SPEC_VERSIONS.v1_1;
+ } else {
+ throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.cannotDecideRMVersion));
+ }
+
+ SequencePropertyBean specVerionBean = new SequencePropertyBean();
+ specVerionBean.setSequencePropertyKey(sequenceId);
+ specVerionBean.setName(Sandesha2Constants.SequenceProperties.RM_SPEC_VERSION);
+ specVerionBean.setValue(specVersion);
+
+ seqPropMgr.insert(specVerionBean);
+
+ // TODO get the SOAP version from the create seq message.
+
+ return sequenceId;
+ }
+
+ public void removeSequence(String sequence) {
+
+ }
+
+ public static void setupNewClientSequence(MessageContext firstAplicationMsgCtx, String sequencePropertyKey,
+ String specVersion, StorageManager storageManager) throws SandeshaException {
+
+ ConfigurationContext configurationContext = firstAplicationMsgCtx.getConfigurationContext();
+
+ SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropertyBeanMgr();
+
+ // setting the addressing version
+ String addressingNamespace = (String) firstAplicationMsgCtx
+ .getProperty(AddressingConstants.WS_ADDRESSING_VERSION);
+
+ if (addressingNamespace == null) {
+ OperationContext opCtx = firstAplicationMsgCtx.getOperationContext();
+ if (opCtx != null) {
+ try {
+ MessageContext requestMsg = opCtx.getMessageContext(OperationContextFactory.MESSAGE_LABEL_IN_VALUE);
+ if (requestMsg != null)
+ addressingNamespace = (String) requestMsg
+ .getProperty(AddressingConstants.WS_ADDRESSING_VERSION);
+ } catch (AxisFault e) {
+ throw new SandeshaException(e);
+ }
+ }
+ }
+
+ if (addressingNamespace == null)
+ addressingNamespace = AddressingConstants.Final.WSA_NAMESPACE; // defaults
+ // to
+ // Final.
+ // Make
+ // sure
+ // this
+ // is
+ // synchronized
+ // with
+ // addressing.
+
+ SequencePropertyBean addressingNamespaceBean = new SequencePropertyBean(sequencePropertyKey,
+ Sandesha2Constants.SequenceProperties.ADDRESSING_NAMESPACE_VALUE, addressingNamespace);
+ seqPropMgr.insert(addressingNamespaceBean);
+
+
+ //setting the SOAPVersion Bean.
+ String SOAPVersion = firstAplicationMsgCtx.getOptions().getSoapVersionURI();
+ SequencePropertyBean SOAPVersionBean = new SequencePropertyBean (sequencePropertyKey,
+ Sandesha2Constants.SequenceProperties.SOAP_VERSION, SOAPVersion);
+
+ seqPropMgr.insert(SOAPVersionBean);
+
+
+ String anonymousURI = SpecSpecificConstants.getAddressingAnonymousURI(addressingNamespace);
+
+ EndpointReference toEPR = firstAplicationMsgCtx.getTo();
+ String acksTo = (String) firstAplicationMsgCtx.getProperty(SandeshaClientConstants.AcksTo);
+
+ if (toEPR == null) {
+ String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.toEPRNotValid, null);
+ log.debug(message);
+ throw new SandeshaException(message);
+ }
+
+ SequencePropertyBean toBean = new SequencePropertyBean(sequencePropertyKey,
+ Sandesha2Constants.SequenceProperties.TO_EPR, toEPR.getAddress());
+ SequencePropertyBean replyToBean = null;
+ SequencePropertyBean acksToBean = null;
+
+ if (firstAplicationMsgCtx.isServerSide()) {
+ // setting replyTo value, if this is the server side.
+ OperationContext opContext = firstAplicationMsgCtx.getOperationContext();
+ try {
+ MessageContext requestMessage = opContext
+ .getMessageContext(OperationContextFactory.MESSAGE_LABEL_IN_VALUE);
+ if (requestMessage == null) {
+ String message = SandeshaMessageHelper
+ .getMessage(SandeshaMessageKeys.cannotFindReqMsgFromOpContext);
+ log.error(message);
+ throw new SandeshaException(message);
+ }
+
+ EndpointReference replyToEPR = requestMessage.getTo(); // 'replyTo'
+ // of
+ // the
+ // response
+ // msg
+ // is
+ // the
+ // 'to'
+ // value
+ // of
+ // the
+ // req
+ // msg.
+ if (replyToEPR != null) {
+ replyToBean = new SequencePropertyBean(sequencePropertyKey,
+ Sandesha2Constants.SequenceProperties.REPLY_TO_EPR, replyToEPR.getAddress());
+ acksToBean = new SequencePropertyBean(sequencePropertyKey,
+ Sandesha2Constants.SequenceProperties.ACKS_TO_EPR, replyToEPR.getAddress());
+ } else {
+ String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.toEPRNotValid, null);
+ log.error(message);
+ throw new SandeshaException(message);
+ }
+ } catch (AxisFault e) {
+ String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.cannotFindReqMsgFromOpContext);
+ log.error(message);
+ log.error(e.getStackTrace());
+ throw new SandeshaException(message);
+ }
+ } else {
+
+ EndpointReference replyToEPR = firstAplicationMsgCtx.getReplyTo();
+ //setting replyTo and acksTo beans.
+
+ if (replyToEPR!=null)
+ replyToBean = new SequencePropertyBean(sequencePropertyKey,
+ Sandesha2Constants.SequenceProperties.REPLY_TO_EPR, replyToEPR.getAddress());
+
+ //TODO set AcksToBean.
+ }
+
+ // Default value for acksTo is anonymous (this happens only for the
+ // client side)
+ if (acksTo == null) {
+ acksTo = anonymousURI;
+ }
+
+ acksToBean = new SequencePropertyBean(sequencePropertyKey, Sandesha2Constants.SequenceProperties.ACKS_TO_EPR,
+ acksTo);
+
+ // start the in listner for the client side, if acksTo is not anonymous.
+ if (!firstAplicationMsgCtx.isServerSide() && !anonymousURI.equals(acksTo)) {
+
+ String transportInProtocol = firstAplicationMsgCtx.getOptions().getTransportInProtocol();
+ if (transportInProtocol == null) {
+ throw new SandeshaException(SandeshaMessageHelper
+ .getMessage(SandeshaMessageKeys.cannotStartListenerForIncommingMsgs));
+ }
+
+ try {
+ ListenerManager listenerManager = firstAplicationMsgCtx.getConfigurationContext().getListenerManager();
+ TransportInDescription transportIn = firstAplicationMsgCtx.getConfigurationContext()
+ .getAxisConfiguration().getTransportIn(new QName(transportInProtocol));
+ // if acksTo is not anonymous start the in-transport
+ if (!listenerManager.isListenerRunning(transportIn.getName().getLocalPart())) {
+ listenerManager.addListener(transportIn, false);
+ }
+ } catch (AxisFault e) {
+ throw new SandeshaException(SandeshaMessageHelper.getMessage(
+ SandeshaMessageKeys.cannotStartTransportListenerDueToError, e.toString()), e);
+ }
+
+ }
+
+ SequencePropertyBean msgsBean = new SequencePropertyBean();
+ msgsBean.setSequencePropertyKey(sequencePropertyKey);
+ msgsBean.setName(Sandesha2Constants.SequenceProperties.CLIENT_COMPLETED_MESSAGES);
+ msgsBean.setValue("");
+
+ seqPropMgr.insert(msgsBean);
+
+ seqPropMgr.insert(toBean);
+ if (acksToBean != null)
+ seqPropMgr.insert(acksToBean);
+ if (replyToBean != null)
+ seqPropMgr.insert(replyToBean);
+
+ // saving transportTo value;
+ String transportTo = (String) firstAplicationMsgCtx.getProperty(MessageContextConstants.TRANSPORT_URL);
+ if (transportTo != null) {
+ SequencePropertyBean transportToBean = new SequencePropertyBean();
+ transportToBean.setSequencePropertyKey(sequencePropertyKey);
+ transportToBean.setName(Sandesha2Constants.SequenceProperties.TRANSPORT_TO);
+ transportToBean.setValue(transportTo);
+
+ seqPropMgr.insert(transportToBean);
+ }
+
+ // setting the spec version for the client side.
+ SequencePropertyBean specVerionBean = new SequencePropertyBean();
+ specVerionBean.setSequencePropertyKey(sequencePropertyKey);
+ specVerionBean.setName(Sandesha2Constants.SequenceProperties.RM_SPEC_VERSION);
+ specVerionBean.setValue(specVersion);
+ seqPropMgr.insert(specVerionBean);
+
+ // updating the last activated time.
+ updateLastActivatedTime(sequencePropertyKey, storageManager);
+
+ SandeshaUtil.startSenderForTheSequence(configurationContext, sequencePropertyKey);
+
+
+ updateClientSideListnerIfNeeded(firstAplicationMsgCtx, anonymousURI);
+
+ }
+
+ private static void updateClientSideListnerIfNeeded(MessageContext messageContext, String addressingAnonymousURI)
+ throws SandeshaException {
+ if (messageContext.isServerSide())
+ return; // listners are updated only for the client side.
+
+ String transportInProtocol = messageContext.getOptions().getTransportInProtocol();
+
+ String acksTo = (String) messageContext.getProperty(SandeshaClientConstants.AcksTo);
+ String mep = messageContext.getAxisOperation().getMessageExchangePattern();
+
+ boolean startListnerForAsyncAcks = false;
+ boolean startListnerForAsyncControlMsgs = false; // For async
+ // createSerRes &
+ // terminateSeq.
+
+ if (acksTo != null && !addressingAnonymousURI.equals(acksTo)) {
+ // starting listner for async acks.
+ startListnerForAsyncAcks = true;
+ }
+
+ try {
+ if ((startListnerForAsyncAcks || startListnerForAsyncControlMsgs) ) {
+
+ if (transportInProtocol == null){
+ EndpointReference toEPR = messageContext.getOptions().getTo();
+ if (toEPR==null) {
+ String message = SandeshaMessageHelper.getMessage(
+ SandeshaMessageKeys.toEPRNotSet);
+ throw new AxisFault (message);
+ }
+
+ try {
+ URI uri = new URI (toEPR.getAddress());
+ String scheme = uri.getScheme();
+
+ //this is a convention is Axis2. The name of the TransportInDescription has to be the
+ //scheme of a URI of that transport.
+ //Here we also assume that the Incoming transport will be same as the outgoing one.
+ transportInProtocol = scheme;
+ } catch (URISyntaxException e) {
+ throw new SandeshaException (e);
+ }
+
+ }
+
+ //TODO following code was taken from ServiceContext.gegMyEPR method.
+ // When a listner-starting method becomes available from Axis2, use that.
+ ConfigurationContext configctx = messageContext.getConfigurationContext();
+ ListenerManager lm = configctx.getListenerManager();
+ if (!lm.isListenerRunning(transportInProtocol)) {
+ TransportInDescription trsin = configctx.getAxisConfiguration().
+ getTransportIn(new QName(transportInProtocol));
+ if (trsin != null) {
+ lm.addListener(trsin, false);
+ } else {
+ String message = SandeshaMessageHelper.getMessage(
+ SandeshaMessageKeys.cannotFindTransportInDesc,transportInProtocol);
+ throw new AxisFault(message);
+ }
+ }
+ }
+
+ } catch (AxisFault e) {
+ String message = SandeshaMessageHelper.getMessage(
+ SandeshaMessageKeys.cannotStartTransportListenerDueToError, e.toString());
+ log.error(e.getStackTrace());
+ throw new SandeshaException(message, e);
+ }
+
+ }
+
+ /**
+ * Takes the internalSeqID as the param. Not the sequenceID.
+ *
+ * @param internalSequenceID
+ * @param configContext
+ * @throws SandeshaException
+ */
+ public static void updateLastActivatedTime(String sequencePropertyKey, StorageManager storageManager)
+ throws SandeshaException {
+ // Transaction lastActivatedTransaction =
+ // storageManager.getTransaction();
+ SequencePropertyBeanMgr sequencePropertyBeanMgr = storageManager.getSequencePropertyBeanMgr();
+
+ SequencePropertyBean lastActivatedBean = sequencePropertyBeanMgr.retrieve(sequencePropertyKey,
+ Sandesha2Constants.SequenceProperties.LAST_ACTIVATED_TIME);
+
+ boolean added = false;
+
+ if (lastActivatedBean == null) {
+ added = true;
+ lastActivatedBean = new SequencePropertyBean();
+ lastActivatedBean.setSequencePropertyKey(sequencePropertyKey);
+ lastActivatedBean.setName(Sandesha2Constants.SequenceProperties.LAST_ACTIVATED_TIME);
+ }
+
+ long currentTime = System.currentTimeMillis();
+ lastActivatedBean.setValue(Long.toString(currentTime));
+
+ if (added)
+ sequencePropertyBeanMgr.insert(lastActivatedBean);
+ else
+ sequencePropertyBeanMgr.update(lastActivatedBean);
+
+ }
+
+ public static long getLastActivatedTime(String propertyKey, StorageManager storageManager) throws SandeshaException {
+
+ SequencePropertyBeanMgr seqPropBeanMgr = storageManager.getSequencePropertyBeanMgr();
+
+ SequencePropertyBean lastActivatedBean = seqPropBeanMgr.retrieve(propertyKey,
+ Sandesha2Constants.SequenceProperties.LAST_ACTIVATED_TIME);
+
+ long lastActivatedTime = -1;
+
+ if (lastActivatedBean != null) {
+ lastActivatedTime = Long.parseLong(lastActivatedBean.getValue());
+ }
+
+ return lastActivatedTime;
+ }
+
+ public static boolean hasSequenceTimedOut(String propertyKey, RMMsgContext rmMsgCtx, StorageManager storageManager)
+ throws SandeshaException {
+
+ // operation is the lowest level, Sandesha2 could be engaged.
+ SandeshaPolicyBean propertyBean = SandeshaUtil.getPropertyBean(rmMsgCtx.getMessageContext()
+ .getAxisOperation());
+
+ if (propertyBean.getInactivityTimeoutInterval() <= 0)
+ return false;
+
+ boolean sequenceTimedOut = false;
+
+ long lastActivatedTime = getLastActivatedTime(propertyKey, storageManager);
+ long timeNow = System.currentTimeMillis();
+ if (lastActivatedTime > 0 && (lastActivatedTime + propertyBean.getInactivityTimeoutInterval() < timeNow))
+ sequenceTimedOut = true;
+
+ return sequenceTimedOut;
+ }
+
+ public static long getOutGoingSequenceAckedMessageCount(String sequencePropertyKey, StorageManager storageManager)
+ throws SandeshaException {
+ // / Transaction transaction = storageManager.getTransaction();
+ SequencePropertyBeanMgr seqPropBeanMgr = storageManager.getSequencePropertyBeanMgr();
+
+ SequencePropertyBean ackedMsgBean = seqPropBeanMgr.retrieve(sequencePropertyKey,
+ Sandesha2Constants.SequenceProperties.NO_OF_OUTGOING_MSGS_ACKED);
+ if (ackedMsgBean == null)
+ return 0; // No acknowledgement has been received yet.
+
+ long noOfMessagesAcked = Long.parseLong(ackedMsgBean.getValue());
+ // / transaction.commit();
+
+ return noOfMessagesAcked;
+ }
+
+ public static boolean isOutGoingSequenceCompleted(String internalSequenceID, StorageManager storageManager)
+ throws SandeshaException {
+ // / Transaction transaction = storageManager.getTransaction();
+ SequencePropertyBeanMgr seqPropBeanMgr = storageManager.getSequencePropertyBeanMgr();
+
+ SequencePropertyBean findSeqIDBean = new SequencePropertyBean();
+ findSeqIDBean.setValue(internalSequenceID);
+ findSeqIDBean.setName(Sandesha2Constants.SequenceProperties.INTERNAL_SEQUENCE_ID);
+ Collection seqIDBeans = seqPropBeanMgr.find(findSeqIDBean);
+
+ if (seqIDBeans.size() == 0) {
+ String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.noSequenceEstablished);
+ log.debug(message);
+ throw new SandeshaException(message);
+ }
+
+ if (seqIDBeans.size() > 1) {
+ String message = SandeshaMessageHelper.getMessage(
+ SandeshaMessageKeys.cannotGenerateReportNonUniqueSequence, internalSequenceID);
+ log.debug(message);
+ throw new SandeshaException(message);
+ }
+
+ SequencePropertyBean seqIDBean = (SequencePropertyBean) seqIDBeans.iterator().next();
+ String sequenceID = seqIDBean.getSequencePropertyKey();
+
+ SequencePropertyBean terminateAddedBean = seqPropBeanMgr.retrieve(sequenceID,
+ Sandesha2Constants.SequenceProperties.TERMINATE_ADDED);
+ if (terminateAddedBean == null)
+ return false;
+
+ if ("true".equals(terminateAddedBean.getValue()))
+ return true;
+
+ // / transaction.commit();
+ return false;
+ }
+
+ public static boolean isIncomingSequenceCompleted(String sequenceID, StorageManager storageManager)
+ throws SandeshaException {
+
+ // / Transaction transaction = storageManager.getTransaction();
+ SequencePropertyBeanMgr seqPropBeanMgr = storageManager.getSequencePropertyBeanMgr();
+
+ SequencePropertyBean terminateReceivedBean = seqPropBeanMgr.retrieve(sequenceID,
+ Sandesha2Constants.SequenceProperties.TERMINATE_RECEIVED);
+ boolean complete = false;
+
+ if (terminateReceivedBean != null && "true".equals(terminateReceivedBean.getValue()))
+ complete = true;
+
+ // / transaction.commit();
+ return complete;
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: sandesha-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: sandesha-dev-help@ws.apache.org