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 ch...@apache.org on 2007/04/23 11:55:16 UTC
svn commit: r531400 [8/18] - in /webservices/sandesha/trunk/java/modules:
client/ core/ core/src/ core/src/main/ core/src/main/java/
core/src/main/java/org/ core/src/main/java/org/apache/
core/src/main/java/org/apache/sandesha2/ core/src/main/java/org/...
Added: webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/PropertyManager.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/PropertyManager.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/PropertyManager.java (added)
+++ webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/PropertyManager.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,510 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.sandesha2.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.axis2.description.AxisDescription;
+import org.apache.axis2.description.AxisModule;
+import org.apache.axis2.description.Parameter;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.Policy;
+import org.apache.sandesha2.Sandesha2Constants;
+import org.apache.sandesha2.SandeshaException;
+import org.apache.sandesha2.i18n.SandeshaMessageHelper;
+import org.apache.sandesha2.i18n.SandeshaMessageKeys;
+import org.apache.sandesha2.policy.SandeshaPolicyBean;
+
+/**
+ * Loads properties from sandesha2.properties file (from Sandesha2Constants if
+ * this is not available).
+ */
+
+public class PropertyManager {
+
+ public static SandeshaPolicyBean loadPropertiesFromDefaultValues() throws SandeshaException {
+ SandeshaPolicyBean propertyBean = new SandeshaPolicyBean();
+ propertyBean.setAcknowledgementInterval(Sandesha2Constants.Properties.DefaultValues.AcknowledgementInterval);
+ propertyBean.setExponentialBackoff(Sandesha2Constants.Properties.DefaultValues.ExponentialBackoff);
+ propertyBean.setInactiveTimeoutInterval(Sandesha2Constants.Properties.DefaultValues.InactivityTimeout,
+ Sandesha2Constants.Properties.DefaultValues.InactivityTimeoutMeasure);
+
+ propertyBean.setSequenceRemovalTimeoutInterval(Sandesha2Constants.Properties.DefaultValues.sequenceRemovalTimeout,
+ Sandesha2Constants.Properties.DefaultValues.sequenceRemovalTimeoutMeasure);
+
+ propertyBean.setInOrder(Sandesha2Constants.Properties.DefaultValues.InvokeInOrder);
+ propertyBean.setMsgTypesToDrop(null);
+ propertyBean.setRetransmissionInterval(Sandesha2Constants.Properties.DefaultValues.RetransmissionInterval);
+ // propertyBean.setStorageManagerClass(Sandesha2Constants.Properties.DefaultValues.StorageManager);
+ propertyBean.setInMemoryStorageManagerClass(Sandesha2Constants.Properties.DefaultValues.InMemoryStorageManager);
+ propertyBean
+ .setPermanentStorageManagerClass(Sandesha2Constants.Properties.DefaultValues.PermanentStorageManager);
+ propertyBean
+ .setMaximumRetransmissionCount(Sandesha2Constants.Properties.DefaultValues.MaximumRetransmissionCount);
+
+ String msgTypesToDrop = Sandesha2Constants.Properties.DefaultValues.MessageTypesToDrop;
+ loadMessageTypesToDrop(msgTypesToDrop, propertyBean);
+
+ propertyBean.setSecurityManagerClass(Sandesha2Constants.Properties.DefaultValues.SecurityManager);
+
+ propertyBean.setEnableMakeConnection(Sandesha2Constants.Properties.DefaultValues.EnableMakeConnection);
+ propertyBean.setEnableRMAnonURI(Sandesha2Constants.Properties.DefaultValues.EnableRMAnonURI);
+ propertyBean.setUseMessageSerialization(Sandesha2Constants.Properties.DefaultValues.UseMessageSerialization);
+ propertyBean.setEnforceRM(Sandesha2Constants.Properties.DefaultValues.enforceRM);
+
+ return propertyBean;
+ }
+
+ public static SandeshaPolicyBean loadPropertiesFromPropertyFile(InputStream in) throws SandeshaException {
+ SandeshaPolicyBean propertyBean = new SandeshaPolicyBean();
+ try {
+ if (in == null)
+ in = Thread.currentThread().getContextClassLoader().getResourceAsStream(
+ Sandesha2Constants.PROPERTY_FILE);
+
+ Properties properties = new Properties();
+ if (in != null) {
+ properties.load(in);
+ }
+
+ String expoBackoffStr = properties.getProperty(Sandesha2Constants.Properties.ExponentialBackoff);
+ loadExponentialBackoff(expoBackoffStr, propertyBean);
+
+ String retransmissionIntStr = properties.getProperty(Sandesha2Constants.Properties.RetransmissionInterval);
+ loadRetransmissionInterval(retransmissionIntStr, propertyBean);
+
+ String acknowledgementIntStr = properties
+ .getProperty(Sandesha2Constants.Properties.AcknowledgementInterval);
+ loadAcknowledgementInterval(acknowledgementIntStr, propertyBean);
+
+ String inactivityTimeoutStr = properties.getProperty(Sandesha2Constants.Properties.InactivityTimeout);
+ String inactivityTimeoutMeasure = properties
+ .getProperty(Sandesha2Constants.Properties.InactivityTimeoutMeasure);
+ loadInactivityTimeout(inactivityTimeoutStr, inactivityTimeoutMeasure, propertyBean);
+
+ String sequenceRemovalTimeoutStr = properties.getProperty(Sandesha2Constants.Properties.SequenceRemovalTimeout);
+ String sequenceRemovalTimeoutMeasure = properties
+ .getProperty(Sandesha2Constants.Properties.SequenceRemovalTimeoutMeasure);
+ loadSequenceRemovalTimeout(sequenceRemovalTimeoutStr, sequenceRemovalTimeoutMeasure, propertyBean);
+
+ // String storageMgrClassStr = properties
+ // .getProperty(Sandesha2Constants.Properties.StorageManager);
+ // loadStoragemanagerClass(storageMgrClassStr,propertyBean);
+
+ String inMemoryStorageMgrClassStr = properties
+ .getProperty(Sandesha2Constants.Properties.InMemoryStorageManager);
+ loadInMemoryStoragemanagerClass(inMemoryStorageMgrClassStr, propertyBean);
+
+ String permanentStorageMgrClassStr = properties
+ .getProperty(Sandesha2Constants.Properties.PermanentStorageManager);
+ loadPermanentStoragemanagerClass(permanentStorageMgrClassStr, propertyBean);
+
+ String inOrderInvocation = properties.getProperty(Sandesha2Constants.Properties.InOrderInvocation);
+ loadInOrderInvocation(inOrderInvocation, propertyBean);
+
+ String enableMakeConnection = properties.getProperty(Sandesha2Constants.Properties.EnableMakeConnection);
+ loadEnableMakeConnection(enableMakeConnection, propertyBean);
+
+ String useSerlialization = properties.getProperty(Sandesha2Constants.Properties.UseMessageSerialization);
+ loadUseSerialization(useSerlialization, propertyBean);
+
+ String messageTypesToDrop = properties.getProperty(Sandesha2Constants.Properties.MessageTypesToDrop);
+ loadMessageTypesToDrop(messageTypesToDrop, propertyBean);
+
+ String securityManagerClassStr = properties
+ .getProperty(Sandesha2Constants.Properties.SecurityManager);
+ loadSecurityManagerClass(securityManagerClassStr,propertyBean);
+ } catch (IOException e) {
+ throw new SandeshaException(e);
+ }
+
+ return propertyBean;
+ }
+
+ public static SandeshaPolicyBean loadPropertiesFromModuleDesc(AxisModule desc) throws SandeshaException {
+ SandeshaPolicyBean propertyBean = new SandeshaPolicyBean();
+
+ Parameter expoBackoffParam = desc.getParameter(Sandesha2Constants.Properties.ExponentialBackoff);
+ String expoBackoffStr = (String) expoBackoffParam.getValue();
+ loadExponentialBackoff(expoBackoffStr, propertyBean);
+
+ Parameter retransmissionIntParam = desc.getParameter(Sandesha2Constants.Properties.RetransmissionInterval);
+ String retransmissionIntStr = (String) retransmissionIntParam.getValue();
+ loadRetransmissionInterval(retransmissionIntStr, propertyBean);
+
+ Parameter acknowledgementIntParam = desc.getParameter(Sandesha2Constants.Properties.AcknowledgementInterval);
+ String acknowledgementIntStr = (String) acknowledgementIntParam.getValue();
+ loadAcknowledgementInterval(acknowledgementIntStr, propertyBean);
+
+ Parameter inactivityTimeoutParam = desc.getParameter(Sandesha2Constants.Properties.InactivityTimeout);
+ String inactivityTimeoutStr = (String) inactivityTimeoutParam.getValue();
+ Parameter inactivityTimeoutMeasureParam = desc
+ .getParameter(Sandesha2Constants.Properties.InactivityTimeoutMeasure);
+ String inactivityTimeoutMeasure = (String) inactivityTimeoutMeasureParam.getValue();
+ loadInactivityTimeout(inactivityTimeoutStr, inactivityTimeoutMeasure, propertyBean);
+
+ Parameter sequenceRemovalTimeoutParam = desc.getParameter(Sandesha2Constants.Properties.SequenceRemovalTimeout);
+ String sequenceRemovalTimeoutStr = (String) sequenceRemovalTimeoutParam.getValue();
+ Parameter sequenceRemovalTimeoutMeasureParam = desc
+ .getParameter(Sandesha2Constants.Properties.SequenceRemovalTimeoutMeasure);
+ String sequenceRemovalTimeoutMeasure = (String) sequenceRemovalTimeoutMeasureParam.getValue();
+ loadSequenceRemovalTimeout(sequenceRemovalTimeoutStr, sequenceRemovalTimeoutMeasure, propertyBean);
+
+ // Parameter storageMgrClassParam =
+ // desc.getParameter(Sandesha2Constants.Properties.StorageManager);
+ // String storageMgrClassStr = (String) storageMgrClassParam.getValue();
+ // loadStoragemanagerClass(storageMgrClassStr,propertyBean);
+
+ Parameter inMemoryStorageMgrClassParam = desc
+ .getParameter(Sandesha2Constants.Properties.InMemoryStorageManager);
+ String inMemoryStorageMgrClassStr = (String) inMemoryStorageMgrClassParam.getValue();
+ loadInMemoryStoragemanagerClass(inMemoryStorageMgrClassStr, propertyBean);
+
+ Parameter permanentStorageMgrClassParam = desc
+ .getParameter(Sandesha2Constants.Properties.PermanentStorageManager);
+ String permanentStorageMgrClassStr = (String) permanentStorageMgrClassParam.getValue();
+ loadPermanentStoragemanagerClass(permanentStorageMgrClassStr, propertyBean);
+
+ Parameter inOrderInvocationParam = desc.getParameter(Sandesha2Constants.Properties.InOrderInvocation);
+ String inOrderInvocation = (String) inOrderInvocationParam.getValue();
+ loadInOrderInvocation(inOrderInvocation, propertyBean);
+
+ Parameter enableMakeConnectionParam = desc.getParameter(Sandesha2Constants.Properties.EnableMakeConnection);
+ String enableMakeConnection = (String) enableMakeConnectionParam.getValue();
+ loadEnableMakeConnection(enableMakeConnection, propertyBean);
+
+ Parameter useSerializationParam = desc.getParameter(Sandesha2Constants.Properties.UseMessageSerialization);
+ String useSerialization = (String) useSerializationParam.getValue();
+ loadUseSerialization(useSerialization, propertyBean);
+
+ Parameter messageTypesToDropParam = desc.getParameter(Sandesha2Constants.Properties.MessageTypesToDrop);
+ String messageTypesToDrop = (String) messageTypesToDropParam.getValue();
+ loadMessageTypesToDrop(messageTypesToDrop, propertyBean);
+
+ Parameter securityManagerClassParam = desc.getParameter(Sandesha2Constants.Properties.SecurityManager);
+ String securityManagerClassStr = (String) securityManagerClassParam.getValue();
+ loadSecurityManagerClass(securityManagerClassStr,propertyBean);
+
+ return propertyBean;
+ }
+
+ public static SandeshaPolicyBean loadPropertiesFromModuleDescPolicy(AxisModule desc,
+ SandeshaPolicyBean parentPropertyBean) throws SandeshaException {
+
+ SandeshaPolicyBean propertyBean = new SandeshaPolicyBean();
+
+ Policy policy = desc.getPolicyInclude().getEffectivePolicy();
+
+ if (policy == null) {
+ return null; // no pilicy is available in the module description
+ }
+
+ Iterator iterator = policy.getAlternatives();
+ if (! iterator.hasNext()) {
+ throw new SandeshaException("No Policy Alternative found");
+ }
+
+ List assertionList = (List) iterator.next();
+ Assertion assertion = null;
+
+ boolean found = false;
+
+ for (Iterator assertions = assertionList.iterator(); assertions.hasNext();) {
+ assertion = (Assertion) assertions.next();
+
+ if (assertion instanceof SandeshaPolicyBean) {
+ found = true;
+ break;
+ }
+ }
+
+ if (! found) {
+ // no RMAssertion found
+ return null;
+ }
+
+ propertyBean = (SandeshaPolicyBean) assertion;
+ propertyBean.setParent(parentPropertyBean);
+
+ return propertyBean;
+ }
+
+ public static SandeshaPolicyBean loadPropertiesFromAxisDescription(AxisDescription desc,
+ SandeshaPolicyBean parentPropertyBean) throws SandeshaException {
+
+ SandeshaPolicyBean propertyBean = new SandeshaPolicyBean();
+
+ Policy policy = desc.getPolicyInclude().getEffectivePolicy();
+
+ if (policy == null) {
+ return null; // no pilicy is available in the module description
+ }
+
+ Iterator iterator = policy.getAlternatives();
+ if (! iterator.hasNext()) {
+ throw new SandeshaException("No Policy Alternative found");
+ }
+
+ List assertionList = (List) iterator.next();
+ Assertion assertion = null;
+
+ boolean found = false;
+
+ for (Iterator assertions = assertionList.iterator(); assertions.hasNext();) {
+ assertion = (Assertion) assertions.next();
+
+ if (assertion instanceof SandeshaPolicyBean) {
+ found = true;
+ break;
+ }
+ }
+
+ if (! found) {
+ // no RMAssertion found
+ return null;
+ }
+
+ propertyBean = (SandeshaPolicyBean) assertion;
+
+ if (propertyBean!=parentPropertyBean) {
+ propertyBean.setParent(parentPropertyBean);
+ return propertyBean;
+ } else {
+ //propertyBean and parent being the same object means that there is no policy in this level, this is simply the reflection of
+ //the parent.
+ return null;
+ }
+
+ }
+
+ public static void reloadFromPropertyFile(InputStream stream) throws SandeshaException {
+ loadPropertiesFromPropertyFile(stream);
+ }
+
+ /**
+ * Loads wsp:exponentianbackoff.
+ *
+ * @param properties
+ */
+ private static void loadExponentialBackoff(String expoBackoffStr, SandeshaPolicyBean propertyBean) {
+
+ if (expoBackoffStr != null) {
+ expoBackoffStr = expoBackoffStr.trim();
+ if (expoBackoffStr.equals("true")) {
+ propertyBean.setExponentialBackoff(true);
+ } else if (expoBackoffStr.equals("false")) {
+ propertyBean.setExponentialBackoff(false);
+ }
+ }
+ }
+
+ /**
+ * Loads wsp:retransmissionInterval.
+ *
+ * @param properties
+ */
+ private static void loadRetransmissionInterval(String retransmissionIntStr, SandeshaPolicyBean propertyBean)
+ throws SandeshaException {
+
+ if (retransmissionIntStr != null) {
+ try {
+ retransmissionIntStr = retransmissionIntStr.trim();
+ int retransmissionInterval = Integer.parseInt(retransmissionIntStr);
+ if (retransmissionInterval > 0) {
+ propertyBean.setRetransmissionInterval(retransmissionInterval);
+ }
+ } catch (NumberFormatException e) {
+ String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.cannotDerriveRetransInterval);
+ throw new SandeshaException(message, e);
+ }
+ }
+ }
+
+ /**
+ * Loads wsp:acknowldgementInterval.
+ *
+ * @param properties
+ */
+ private static void loadAcknowledgementInterval(String acknowledgementIntStr, SandeshaPolicyBean propertyBean)
+ throws SandeshaException {
+
+ if (acknowledgementIntStr != null) {
+ try {
+ acknowledgementIntStr = acknowledgementIntStr.trim();
+ int acknowledgementInt = Integer.parseInt(acknowledgementIntStr);
+ if (acknowledgementInt > 0) {
+ propertyBean.setAcknowledgementInterval(acknowledgementInt);
+ }
+ } catch (NumberFormatException e) {
+ String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.cannotDerriveAckInterval);
+ throw new SandeshaException(message, e);
+ }
+ }
+ }
+
+ /**
+ * Loads wsp:inactivityInterval.
+ *
+ * @param properties
+ */
+ private static void loadInactivityTimeout(String inactivityTimeoutStr, String inactivityTimeoutMeasure,
+ SandeshaPolicyBean propertyBean) throws SandeshaException {
+
+ if (inactivityTimeoutStr != null && inactivityTimeoutMeasure != null) {
+ try {
+ inactivityTimeoutStr = inactivityTimeoutStr.trim();
+ inactivityTimeoutMeasure = inactivityTimeoutMeasure.trim();
+
+ int inactivityTimeoutVal = Integer.parseInt(inactivityTimeoutStr);
+ if (inactivityTimeoutVal > 0) {
+ propertyBean.setInactiveTimeoutInterval(inactivityTimeoutVal, inactivityTimeoutMeasure);
+ }
+ } catch (NumberFormatException e) {
+ String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.cannotDerriveInactivityTimeout);
+ throw new SandeshaException(message, e);
+ }
+ }
+ }
+
+ /**
+ * Loads wsp:inactivityInterval.
+ *
+ * @param properties
+ */
+ private static void loadSequenceRemovalTimeout(String sequenceRemovalTimeoutStr, String sequenceRemovalTimeoutMeasure,
+ SandeshaPolicyBean propertyBean) throws SandeshaException {
+
+ if (sequenceRemovalTimeoutStr != null && sequenceRemovalTimeoutMeasure != null) {
+ try {
+ sequenceRemovalTimeoutStr = sequenceRemovalTimeoutStr.trim();
+ sequenceRemovalTimeoutMeasure = sequenceRemovalTimeoutMeasure.trim();
+
+ int sequenceRemovalTimeoutVal = Integer.parseInt(sequenceRemovalTimeoutStr);
+ if (sequenceRemovalTimeoutVal > 0) {
+ propertyBean.setSequenceRemovalTimeoutInterval(sequenceRemovalTimeoutVal, sequenceRemovalTimeoutMeasure);
+ }
+ } catch (NumberFormatException e) {
+ String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.cannotDerriveInactivityTimeout);
+ throw new SandeshaException(message, e);
+ }
+ }
+ }
+
+ /**
+ * Loads the InMemoryStorageManager class name.
+ *
+ * @param properties
+ */
+ private static void loadInMemoryStoragemanagerClass(String inMemoryStorageMgrClassStr,
+ SandeshaPolicyBean propertyBean){
+ if (inMemoryStorageMgrClassStr != null) {
+ inMemoryStorageMgrClassStr = inMemoryStorageMgrClassStr.trim();
+ propertyBean.setInMemoryStorageManagerClass(inMemoryStorageMgrClassStr);
+ }
+ }
+
+ /**
+ * Loads the PermanentStorageManager class name.
+ *
+ * @param properties
+ */
+ private static void loadPermanentStoragemanagerClass(String permanentStorageMgrClassStr,
+ SandeshaPolicyBean propertyBean) {
+ if (permanentStorageMgrClassStr != null) {
+ permanentStorageMgrClassStr = permanentStorageMgrClassStr.trim();
+ propertyBean.setPermanentStorageManagerClass(permanentStorageMgrClassStr);
+ }
+ }
+
+ private static void loadInOrderInvocation(String inOrderInvocation, SandeshaPolicyBean propertyBean) {
+
+ if (inOrderInvocation != null) {
+ inOrderInvocation = inOrderInvocation.trim();
+ if (inOrderInvocation.equalsIgnoreCase("true")) {
+ propertyBean.setInOrder(true);
+ } else if (inOrderInvocation.equalsIgnoreCase("false")) {
+ propertyBean.setInOrder(false);
+ }
+ }
+ }
+
+ private static void loadEnableMakeConnection(String enableMakeConnection, SandeshaPolicyBean propertyBean) {
+
+ if (enableMakeConnection != null) {
+ enableMakeConnection = enableMakeConnection.trim();
+ if (enableMakeConnection.equalsIgnoreCase("true")) {
+ propertyBean.setEnableMakeConnection(true);
+ } else if (enableMakeConnection.equalsIgnoreCase("false")) {
+ propertyBean.setEnableMakeConnection(false);
+ }
+ }
+ }
+
+ private static void loadUseSerialization(String useSerialization, SandeshaPolicyBean propertyBean) {
+
+ if (useSerialization != null) {
+ useSerialization = useSerialization.trim();
+ if (useSerialization.equalsIgnoreCase("true")) {
+ propertyBean.setUseMessageSerialization(true);
+ } else if (useSerialization.equalsIgnoreCase("false")) {
+ propertyBean.setUseMessageSerialization(false);
+ }
+ }
+ }
+
+ private static void loadMessageTypesToDrop(String messageTypesToDrop, SandeshaPolicyBean propertyBean)
+ throws SandeshaException {
+
+ try {
+ if (messageTypesToDrop != null && !Sandesha2Constants.VALUE_NONE.equals(messageTypesToDrop)) {
+ messageTypesToDrop = messageTypesToDrop.trim();
+ messageTypesToDrop = "[" + messageTypesToDrop + "]";
+ ArrayList messageTypesLst = SandeshaUtil.getArrayListFromString(messageTypesToDrop);
+
+ Iterator itr = messageTypesLst.iterator();
+ while (itr.hasNext()) {
+ String typeStr = (String) itr.next();
+ Integer typeNo = new Integer(typeStr);
+ propertyBean.addMsgTypeToDrop(typeNo);
+ }
+ }
+ } catch (NumberFormatException e) {
+ String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.propertyInvalidValue,
+ Sandesha2Constants.Properties.MessageTypesToDrop);
+ throw new SandeshaException(message, e);
+ }
+ }
+
+ /**
+ * Loads the SecurityManager class name.
+ *
+ * @param properties
+ */
+ private static void loadSecurityManagerClass(String securityManagerClassStr, SandeshaPolicyBean propertyBean) {
+ if (securityManagerClassStr != null) {
+ securityManagerClassStr = securityManagerClassStr.trim();
+ propertyBean.setSecurityManagerClass(securityManagerClassStr);
+ }
+ }
+
+}
Added: webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/RMMsgCreator.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/RMMsgCreator.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/RMMsgCreator.java (added)
+++ webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/RMMsgCreator.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,538 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ *
+ */
+
+package org.apache.sandesha2.util;
+
+import java.util.ArrayList;
+
+import org.apache.axiom.om.OMElement;
+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.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.AxisService;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.util.Utils;
+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.security.SecurityManager;
+import org.apache.sandesha2.security.SecurityToken;
+import org.apache.sandesha2.storage.StorageManager;
+import org.apache.sandesha2.storage.beans.RMDBean;
+import org.apache.sandesha2.storage.beans.RMSBean;
+import org.apache.sandesha2.storage.beans.RMSequenceBean;
+import org.apache.sandesha2.wsrm.Accept;
+import org.apache.sandesha2.wsrm.AckFinal;
+import org.apache.sandesha2.wsrm.AcksTo;
+import org.apache.sandesha2.wsrm.Address;
+import org.apache.sandesha2.wsrm.CloseSequence;
+import org.apache.sandesha2.wsrm.CloseSequenceResponse;
+import org.apache.sandesha2.wsrm.CreateSequence;
+import org.apache.sandesha2.wsrm.CreateSequenceResponse;
+import org.apache.sandesha2.wsrm.Endpoint;
+import org.apache.sandesha2.wsrm.IOMRMPart;
+import org.apache.sandesha2.wsrm.Identifier;
+import org.apache.sandesha2.wsrm.MakeConnection;
+import org.apache.sandesha2.wsrm.SequenceAcknowledgement;
+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.
+ */
+
+public class RMMsgCreator {
+
+ private static Log log = LogFactory.getLog(RMMsgCreator.class);
+
+ /**
+ * Create a new CreateSequence message.
+ *
+ * @param applicationRMMsg
+ * @param internalSequenceId
+ * @param acksToEPR
+ * @return
+ * @throws SandeshaException
+ */
+ public static RMMsgContext createCreateSeqMsg(RMSBean rmsBean, RMMsgContext applicationRMMsg) throws AxisFault {
+
+ MessageContext applicationMsgContext = applicationRMMsg.getMessageContext();
+ if (applicationMsgContext == null)
+ throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.appMsgIsNull));
+ ConfigurationContext context = applicationMsgContext.getConfigurationContext();
+ if (context == null)
+ throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.configContextNotSet));
+
+ // creating by copying common contents. (this will not set contexts
+ // except for configCtx).
+ AxisOperation createSequenceOperation = SpecSpecificConstants.getWSRMOperation(
+ Sandesha2Constants.MessageTypes.CREATE_SEQ,
+ rmsBean.getRMVersion(),
+ applicationMsgContext.getAxisService());
+
+ MessageContext createSeqmsgContext = SandeshaUtil
+ .createNewRelatedMessageContext(applicationRMMsg, createSequenceOperation);
+
+ OperationContext createSeqOpCtx = createSeqmsgContext.getOperationContext();
+ String createSeqMsgId = SandeshaUtil.getUUID();
+ createSeqmsgContext.setMessageID(createSeqMsgId);
+ context.registerOperationContext(createSeqMsgId, createSeqOpCtx);
+
+ RMMsgContext createSeqRMMsg = new RMMsgContext(createSeqmsgContext);
+
+ String rmNamespaceValue = SpecSpecificConstants.getRMNamespaceValue(rmsBean.getRMVersion());
+
+ // Decide which addressing version to use. We copy the version that the application
+ // is already using (if set), and fall back to the level in the spec if that isn't
+ // found.
+ String addressingNamespace = (String) applicationMsgContext.getProperty(AddressingConstants.WS_ADDRESSING_VERSION);
+ Boolean disableAddressing = (Boolean) applicationMsgContext.getProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES);
+ if(addressingNamespace == null) {
+ // Addressing may still be enabled, as it defaults to the final spec. The only time
+ // we follow the RM spec is when addressing has been explicitly disabled.
+ if(disableAddressing != null && disableAddressing.booleanValue())
+ addressingNamespace = SpecSpecificConstants.getAddressingNamespace(rmNamespaceValue);
+ else
+ addressingNamespace = AddressingConstants.Final.WSA_NAMESPACE;
+ }
+
+ // If acksTo has not been set, then default to anonymous, using the correct spec level
+ EndpointReference acksToEPR = null;
+ String acksToAddress = rmsBean.getAcksToEPR();
+ if(acksToAddress != null) {
+ acksToEPR = new EndpointReference(acksToAddress);
+ } else {
+ acksToEPR = new EndpointReference(SpecSpecificConstants.getAddressingAnonymousURI(addressingNamespace));
+ }
+
+ CreateSequence createSequencePart = new CreateSequence(rmNamespaceValue);
+
+ // Adding sequence offer - if present. We send an offer if the client has assigned an
+ // id, or if we are using WS-RM 1.0 and the service contains out-in MEPs
+ boolean autoOffer = false;
+ if(Sandesha2Constants.SPEC_2005_02.NS_URI.equals(rmNamespaceValue)) {
+ AxisService service = applicationMsgContext.getAxisService();
+ if(service != null) {
+ Parameter p = service.getParameter(Sandesha2Constants.SERVICE_CONTAINS_OUT_IN_MEPS);
+ if(p != null && p.getValue() != null) {
+ autoOffer = ((Boolean) p.getValue()).booleanValue();
+ }
+ }
+ }
+ String offeredSequenceId = (String) applicationMsgContext.getProperty(SandeshaClientConstants.OFFERED_SEQUENCE_ID);
+
+ if(autoOffer ||
+ (offeredSequenceId != null && offeredSequenceId.length() > 0)) {
+
+ if (offeredSequenceId == null || offeredSequenceId.length() == 0) {
+ offeredSequenceId = SandeshaUtil.getUUID();
+ }
+
+ SequenceOffer offerPart = new SequenceOffer(rmNamespaceValue);
+ Identifier identifier = new Identifier(rmNamespaceValue);
+ identifier.setIndentifer(offeredSequenceId);
+ offerPart.setIdentifier(identifier);
+ createSequencePart.setSequenceOffer(offerPart);
+
+ if (Sandesha2Constants.SPEC_2007_02.NS_URI.equals(rmNamespaceValue)) {
+ // We are going to send an offer, so decide which endpoint to include
+ EndpointReference offeredEndpoint = (EndpointReference) applicationMsgContext.getProperty(SandeshaClientConstants.OFFERED_ENDPOINT);
+ if (offeredEndpoint==null) {
+ EndpointReference replyTo = applicationMsgContext.getReplyTo(); //using replyTo as the Endpoint if it is not specified
+
+ if (replyTo!=null) {
+ offeredEndpoint = SandeshaUtil.cloneEPR(replyTo);
+ }
+ }
+ // Finally fall back to using an anonymous endpoint
+ if (offeredEndpoint==null) {
+ offeredEndpoint = new EndpointReference(SpecSpecificConstants.getAddressingAnonymousURI(addressingNamespace));
+ }
+ Endpoint endpoint = new Endpoint (offeredEndpoint, rmNamespaceValue, addressingNamespace);
+ offerPart.setEndpoint(endpoint);
+ }
+ }
+
+ String to = rmsBean.getToEPR();
+ String replyTo = rmsBean.getReplyToEPR();
+
+ if (to == null) {
+ String message = SandeshaMessageHelper
+ .getMessage(SandeshaMessageKeys.toBeanNotSet);
+ throw new SandeshaException(message);
+ }
+
+ // TODO store and retrieve a full EPR instead of just the address.
+ EndpointReference toEPR = new EndpointReference(to);
+ createSeqRMMsg.setTo(toEPR);
+
+ if(replyTo != null) {
+ EndpointReference replyToEPR = new EndpointReference(replyTo);
+ createSeqRMMsg.setReplyTo(replyToEPR);
+ }
+
+ AcksTo acksTo = new AcksTo(acksToEPR, rmNamespaceValue, addressingNamespace);
+ 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.
+ SecurityManager secMgr = SandeshaUtil.getSecurityManager(context);
+ SecurityToken token = secMgr.getSecurityToken(applicationMsgContext);
+ if(token != null) {
+ OMElement str = secMgr.createSecurityTokenReference(token, createSeqmsgContext);
+ createSequencePart.setSecurityTokenReference(str);
+ createSeqRMMsg.setProperty(Sandesha2Constants.MessageContextProperties.SECURITY_TOKEN, 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_2007_02.NS_URI)) {
+ UsesSequenceSTR header = new UsesSequenceSTR(null, Sandesha2Constants.SPEC_2007_02.NS_URI);
+ header.toSOAPEnvelope(createSeqmsgContext.getEnvelope());
+ }
+
+ // 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(rmsBean.getRMVersion()));
+ createSeqRMMsg.setSOAPAction(SpecSpecificConstants.getCreateSequenceSOAPAction(rmsBean.getRMVersion()));
+
+ createSeqRMMsg.addSOAPEnvelope();
+
+ return createSeqRMMsg;
+ }
+
+ /**
+ * Creates a new TerminateSequence message.
+ *
+ * @param referenceRMMessage
+ * @return
+ * @throws SandeshaException
+ */
+ public static RMMsgContext createTerminateSequenceMessage(RMMsgContext referenceRMMessage, RMSBean rmsBean,
+ StorageManager storageManager) throws AxisFault {
+ MessageContext referenceMessage = referenceRMMessage.getMessageContext();
+ if (referenceMessage == null)
+ throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.msgContextNotSet));
+
+ AxisOperation terminateOperation = SpecSpecificConstants.getWSRMOperation(
+ Sandesha2Constants.MessageTypes.TERMINATE_SEQ,
+ rmsBean.getRMVersion(),
+ referenceMessage.getAxisService());
+
+ ConfigurationContext configCtx = referenceMessage.getConfigurationContext();
+ if (configCtx == null)
+ throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.configContextNotSet));
+
+ MessageContext terminateMessage = SandeshaUtil.createNewRelatedMessageContext(referenceRMMessage,
+ terminateOperation);
+
+ if (terminateMessage.getMessageID()==null) {
+ terminateMessage.setMessageID(SandeshaUtil.getUUID());
+ }
+
+ OperationContext operationContext = terminateMessage.getOperationContext();
+ // to receive terminate sequence response messages correctly
+ configCtx.registerOperationContext(terminateMessage.getMessageID(), operationContext);
+
+ String rmNamespaceValue = SpecSpecificConstants.getRMNamespaceValue(rmsBean.getRMVersion());
+
+ RMMsgContext terminateRMMessage = MsgInitializer.initializeMessage(terminateMessage);
+
+ if (terminateMessage == null)
+ throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.msgContextNotSet));
+
+ TerminateSequence terminateSequencePart = new TerminateSequence(rmNamespaceValue);
+ Identifier identifier = new Identifier(rmNamespaceValue);
+ identifier.setIndentifer(rmsBean.getSequenceID());
+ terminateSequencePart.setIdentifier(identifier);
+ terminateRMMessage.setMessagePart(Sandesha2Constants.MessageParts.TERMINATE_SEQ, terminateSequencePart);
+
+ // no need for an incoming transport for a terminate
+ // message. If this is put, sender will look for an response.
+ terminateMessage.setProperty(MessageContext.TRANSPORT_IN, null);
+
+ terminateMessage.setTo(new EndpointReference (rmsBean.getToEPR()));
+
+ // Ensure the correct token is used to secure the terminate sequence
+ secureOutboundMessage(rmsBean, terminateMessage);
+
+ return terminateRMMessage;
+ }
+
+ /**
+ * Create a new CreateSequenceResponse message.
+ *
+ * @param createSeqMessage
+ * @param outMessage
+ * @param newSequenceID
+ * @return
+ * @throws AxisFault
+ */
+ public static RMMsgContext createCreateSeqResponseMsg(RMMsgContext createSeqMessage, RMSequenceBean rmSequenceBean) throws AxisFault {
+
+ CreateSequence cs = (CreateSequence) createSeqMessage.getMessagePart(Sandesha2Constants.MessageParts.CREATE_SEQ);
+ String namespace = createSeqMessage.getRMNamespaceValue();
+
+ CreateSequenceResponse response = new CreateSequenceResponse(namespace);
+ Identifier identifier = new Identifier(namespace);
+ identifier.setIndentifer(rmSequenceBean.getSequenceID());
+ response.setIdentifier(identifier);
+
+ SequenceOffer offer = cs.getSequenceOffer();
+ if (offer != null) {
+ String outSequenceId = offer.getIdentifer().getIdentifier();
+
+ if (outSequenceId != null && !"".equals(outSequenceId)) {
+
+ Accept accept = new Accept(namespace);
+
+ // Putting the To EPR as the AcksTo for the response sequence. We echo back the
+ // addressing version that the create used.
+ String addressingNamespace = cs.getAddressingNamespaceValue();
+ EndpointReference acksToEPR = createSeqMessage.getTo();
+ if(acksToEPR != null) {
+ acksToEPR = SandeshaUtil.cloneEPR(acksToEPR);
+ } else {
+ String anon = SpecSpecificConstants.getAddressingAnonymousURI(addressingNamespace);
+ acksToEPR = new EndpointReference(anon);
+ }
+
+ AcksTo acksTo = new AcksTo(acksToEPR, namespace, cs.getAddressingNamespaceValue());
+ accept.setAcksTo(acksTo);
+ response.setAccept(accept);
+ }
+ }
+
+ String version = SpecSpecificConstants.getSpecVersionString(namespace);
+ String action = SpecSpecificConstants.getCreateSequenceResponseAction(version);
+
+ return createResponseMsg(createSeqMessage, rmSequenceBean, response,
+ Sandesha2Constants.MessageParts.CREATE_SEQ_RESPONSE,action);
+ }
+
+ public static RMMsgContext createTerminateSeqResponseMsg(RMMsgContext terminateSeqRMMsg, RMSequenceBean rmSequenceBean) throws AxisFault {
+
+ TerminateSequence terminateSequence = (TerminateSequence) terminateSeqRMMsg
+ .getMessagePart(Sandesha2Constants.MessageParts.TERMINATE_SEQ);
+ String sequenceID = terminateSequence.getIdentifier().getIdentifier();
+
+ String namespace = terminateSeqRMMsg.getRMNamespaceValue();
+
+ TerminateSequenceResponse terminateSequenceResponse = new TerminateSequenceResponse(namespace);
+ Identifier identifier = new Identifier(namespace);
+ identifier.setIndentifer(sequenceID);
+ terminateSequenceResponse.setIdentifier(identifier);
+
+ String version = SpecSpecificConstants.getSpecVersionString(namespace);
+ String action = SpecSpecificConstants.getTerminateSequenceResponseAction(version);
+
+ return createResponseMsg(terminateSeqRMMsg, rmSequenceBean, terminateSequenceResponse,
+ Sandesha2Constants.MessageParts.TERMINATE_SEQ_RESPONSE, action);
+ }
+
+ public static RMMsgContext createCloseSeqResponseMsg(RMMsgContext closeSeqRMMsg, RMSequenceBean rmSequenceBean) throws AxisFault {
+
+ CloseSequence closeSequence = (CloseSequence) closeSeqRMMsg
+ .getMessagePart(Sandesha2Constants.MessageParts.CLOSE_SEQUENCE);
+ String sequenceID = closeSequence.getIdentifier().getIdentifier();
+
+ String namespace = closeSeqRMMsg.getRMNamespaceValue();
+
+ CloseSequenceResponse closeSequenceResponse = new CloseSequenceResponse(namespace);
+ Identifier identifier = new Identifier(namespace);
+ identifier.setIndentifer(sequenceID);
+ closeSequenceResponse.setIdentifier(identifier);
+
+ String version = SpecSpecificConstants.getSpecVersionString(namespace);
+ String action = SpecSpecificConstants.getCloseSequenceResponseAction(version);
+
+ return createResponseMsg(closeSeqRMMsg, rmSequenceBean, closeSequenceResponse,
+ Sandesha2Constants.MessageParts.CLOSE_SEQUENCE_RESPONSE, action);
+ }
+
+ private static RMMsgContext createResponseMsg(RMMsgContext requestMsg, RMSequenceBean rmSequenceBean, IOMRMPart part,
+ int messagePartId, String action) throws AxisFault {
+
+ MessageContext outMessage = Utils.createOutMessageContext(requestMsg.getMessageContext());
+ RMMsgContext responseRMMsg = new RMMsgContext(outMessage);
+ SOAPFactory factory = SOAPAbstractFactory.getSOAPFactory(SandeshaUtil.getSOAPVersion(requestMsg.getSOAPEnvelope()));
+
+ String namespace = requestMsg.getRMNamespaceValue();
+ responseRMMsg.setRMNamespaceValue(namespace);
+
+ SOAPEnvelope envelope = factory.getDefaultEnvelope();
+ responseRMMsg.setSOAPEnvelop(envelope);
+ responseRMMsg.setMessagePart(messagePartId, part);
+
+ outMessage.setWSAAction(action);
+ outMessage.setSoapAction(action);
+
+ responseRMMsg.addSOAPEnvelope();
+ responseRMMsg.getMessageContext().setServerSide(true);
+
+ // Ensure the correct token is used to secure the message
+ secureOutboundMessage(rmSequenceBean, outMessage);
+
+ return responseRMMsg;
+ }
+
+ /**
+ * Adds an ack message to the given application message.
+ *
+ * @param applicationMsg
+ * @param sequenceId
+ * @throws SandeshaException
+ */
+ public static void addAckMessage(RMMsgContext applicationMsg, String sequenceId, RMDBean rmdBean)
+ throws SandeshaException {
+ if(log.isDebugEnabled())
+ log.debug("Entry: RMMsgCreator::addAckMessage " + sequenceId);
+
+ String rmVersion = rmdBean.getRMVersion();
+ String rmNamespaceValue = SpecSpecificConstants.getRMNamespaceValue(rmVersion);
+
+ SequenceAcknowledgement sequenceAck = new SequenceAcknowledgement(rmNamespaceValue);
+ Identifier id = new Identifier(rmNamespaceValue);
+ id.setIndentifer(sequenceId);
+ sequenceAck.setIdentifier(id);
+
+ ArrayList ackRangeArrayList = SandeshaUtil.getAckRangeArrayList(rmdBean.getServerCompletedMessages(), rmNamespaceValue);
+ sequenceAck.setAckRanges(ackRangeArrayList);
+
+ if (rmdBean.isClosed()) {
+ // sequence is closed. so add the 'Final' part.
+ if (SpecSpecificConstants.isAckFinalAllowed(rmVersion)) {
+ AckFinal ackFinal = new AckFinal(rmNamespaceValue);
+ sequenceAck.setAckFinal(ackFinal);
+ }
+ }
+
+ applicationMsg.setMessagePart(Sandesha2Constants.MessageParts.SEQ_ACKNOWLEDGEMENT, sequenceAck);
+
+ if (applicationMsg.getWSAAction()==null) {
+ applicationMsg.setAction(SpecSpecificConstants.getSequenceAcknowledgementAction(rmVersion));
+ applicationMsg.setSOAPAction(SpecSpecificConstants.getSequenceAcknowledgementSOAPAction(rmVersion));
+ }
+ if(applicationMsg.getMessageId() == null) {
+ applicationMsg.setMessageId(SandeshaUtil.getUUID());
+ }
+
+ // Write the ack into the soap envelope
+ try {
+ applicationMsg.addSOAPEnvelope();
+ } catch(AxisFault e) {
+ if(log.isDebugEnabled()) log.debug("Caught AxisFault", e);
+ throw new SandeshaException(e.getMessage(), e);
+ }
+
+ // Ensure the message also contains the token that needs to be used
+ secureOutboundMessage(rmdBean, applicationMsg.getMessageContext());
+
+ if(log.isDebugEnabled())
+ log.debug("Exit: RMMsgCreator::addAckMessage");
+ }
+
+
+ public static RMMsgContext createMakeConnectionMessage (RMMsgContext referenceRMMessage,
+ RMSequenceBean bean,
+ String makeConnectionSeqId,
+ String makeConnectionAnonURI,
+ StorageManager storageManager)
+ throws AxisFault
+ {
+
+ MessageContext referenceMessage = referenceRMMessage.getMessageContext();
+ String rmNamespaceValue = referenceRMMessage.getRMNamespaceValue();
+ String rmVersion = referenceRMMessage.getRMSpecVersion();
+
+ AxisOperation makeConnectionOperation = SpecSpecificConstants.getWSRMOperation(
+ Sandesha2Constants.MessageTypes.MAKE_CONNECTION_MSG,
+ rmVersion,
+ referenceMessage.getAxisService());
+
+ MessageContext makeConnectionMessageCtx = SandeshaUtil.createNewRelatedMessageContext(referenceRMMessage,makeConnectionOperation);
+ RMMsgContext makeConnectionRMMessageCtx = MsgInitializer.initializeMessage(makeConnectionMessageCtx);
+
+ MakeConnection makeConnection = new MakeConnection (Sandesha2Constants.SPEC_2007_02.MC_NS_URI);
+ if (makeConnectionSeqId!=null) {
+ Identifier identifier = new Identifier (rmNamespaceValue);
+ identifier.setIndentifer(makeConnectionSeqId);
+ makeConnection.setIdentifier(identifier);
+ }
+
+ if (makeConnectionAnonURI!=null) {
+ Address address = new Address (Sandesha2Constants.SPEC_2007_02.MC_NS_URI);
+ address.setAddress (makeConnectionAnonURI);
+ makeConnection.setAddress(address);
+ }
+
+ // Setting the addressing properties. As this is a poll we must send it to an non-anon
+ // EPR, so we check both To and ReplyTo from the reference message
+ EndpointReference epr = referenceMessage.getTo();
+ if(epr.hasAnonymousAddress()) epr = referenceMessage.getReplyTo();
+
+ makeConnectionMessageCtx.setTo(epr);
+ makeConnectionMessageCtx.setWSAAction(SpecSpecificConstants.getMakeConnectionAction(rmVersion));
+ makeConnectionMessageCtx.setMessageID(SandeshaUtil.getUUID());
+ makeConnectionRMMessageCtx.setMessagePart(Sandesha2Constants.MessageParts.MAKE_CONNECTION,
+ makeConnection);
+
+ //generating the SOAP Envelope.
+ makeConnectionRMMessageCtx.addSOAPEnvelope();
+
+ // Secure the message using the correct token for the sequence that we are polling
+ secureOutboundMessage(bean, makeConnectionMessageCtx);
+
+ return makeConnectionRMMessageCtx;
+ }
+
+ public static void secureOutboundMessage(RMSequenceBean rmBean, MessageContext message)
+ throws SandeshaException
+ {
+ if(log.isDebugEnabled()) log.debug("Entry: RMMsgCreator::secureOutboundMessage");
+
+ ConfigurationContext configCtx = message.getConfigurationContext();
+
+ if(rmBean.getSecurityTokenData() != null) {
+ if(log.isDebugEnabled()) log.debug("Securing outbound message");
+ SecurityManager secManager = SandeshaUtil.getSecurityManager(configCtx);
+ SecurityToken token = secManager.recoverSecurityToken(rmBean.getSecurityTokenData());
+ secManager.applySecurityToken(token, message);
+ }
+
+ if(log.isDebugEnabled()) log.debug("Exit: RMMsgCreator::secureOutboundMessage");
+ }
+
+}
Added: webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/Range.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/Range.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/Range.java (added)
+++ webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/Range.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,113 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.sandesha2.util;
+
+import java.io.Serializable;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.sandesha2.i18n.SandeshaMessageHelper;
+import org.apache.sandesha2.i18n.SandeshaMessageKeys;
+
+/**
+ * Data structure to represent a range of values from lowerValue->upperValue inclusive.
+ */
+public class Range implements Serializable{
+
+ private static final long serialVersionUID = 1701339894096240940L;
+
+ private static final Log log = LogFactory.getLog(Range.class);
+
+ long lowerValue;
+ long upperValue;
+
+ /**
+ * Create a range for a single number
+ * @param value
+ */
+ public Range(long value){
+ this(value, value);
+ }
+
+ /**
+ *
+ * @param low
+ * @param high
+ *
+ * NOTE: low and high can be equal
+ */
+ public Range(long low, long high){
+ if(high<low || high<0 || low<0){
+ throw new IllegalArgumentException(SandeshaMessageHelper.getMessage(
+ SandeshaMessageKeys.invalidRange, ""+(low), ""+(high)));
+ }
+ lowerValue = low;
+ upperValue = high;
+ }
+
+ /**
+ * Construct a range from a String object
+ * @param s a String of the form [lower, upper]
+ * NOTE: lower and upper can be equal
+ */
+ public Range(String s){
+ s = s.trim();
+
+ int length = s.length();
+
+ if (s.charAt(0) != '[' || s.charAt(length - 1) != ']') {
+ String message = SandeshaMessageHelper.getMessage(
+ SandeshaMessageKeys.invalidStringArray, s);
+ log.debug(message);
+ throw new IllegalArgumentException(message);
+ }
+
+ //remove the braces on either end
+ String subStr = s.substring(1, length - 1);
+
+ String[] parts = subStr.split(",");
+
+ if(parts.length!=2){
+ String message = SandeshaMessageHelper.getMessage(
+ SandeshaMessageKeys.invalidStringArray, s);
+ log.debug(message);
+ throw new IllegalArgumentException(message);
+ }
+
+ lowerValue = Long.parseLong(parts[0]);
+ upperValue = Long.parseLong(parts[1]);
+ }
+
+
+ /**
+ * Value is considered to be "in range" if it is with the limits set by the
+ * upper and lower values.
+ * e.g. [x, x+n] would return true for all values in the set [x...x+n]
+ */
+ public boolean rangeContainsValue(long value){
+ if(value<=upperValue && value>=lowerValue){
+ return true;
+ }
+ else return false;
+ }
+
+ public String toString(){
+ return "[" + lowerValue + "," + upperValue + "]";
+ }
+
+}
Added: webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/RangeString.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/RangeString.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/RangeString.java (added)
+++ webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/RangeString.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,302 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.sandesha2.util;
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+
+/**
+ * Helper class.
+ * Enables conversion to from a list of Range objects to a String representation
+ * of that list.
+ * Also performs task such as aggregation of ranges
+ *
+ */
+public class RangeString implements Serializable{
+
+ private static final long serialVersionUID = -3487094584241136861L;
+ /**
+ * Each entry in this map is a range
+ * The key to each range entry is range.lowerValue
+ */
+ private final Map rangeMap;
+
+ /**
+ * Creates an empty range string
+ */
+ public RangeString(){
+ this(null);
+ }
+
+ /**
+ * Expects a String of the form
+ * [x1,y1][x2,y2]...[xn,yn]
+ * @param s
+ */
+ public RangeString(String s){
+
+ rangeMap = Collections.synchronizedMap(new HashMap());
+
+ if(s!=null && !s.equals("")){
+ //Walk the string building range objects as we go, and
+ //put them in the map
+ Pattern p = Pattern.compile("\\[(.+?),(.+?)\\]");
+ Matcher m = p.matcher(s);
+ while(m.find()){
+ String token = m.group();
+ addRange(new Range(token));
+ }
+ }
+
+ }
+
+
+ private Range getNextRangeBelow(long msgNumber){
+ //start at the specified index and work down the list of ranges
+ //util we find one
+ Iterator iterator = rangeMap.keySet().iterator();
+
+ long cachedKey = -1;
+ while (iterator.hasNext()) {
+ long key = ((Long)iterator.next()).longValue();
+
+ if (key > cachedKey && key <= msgNumber) {
+ cachedKey = key;
+ }
+ }
+
+ if (cachedKey != -1) {
+ //this is the next range below
+ Range r = (Range)rangeMap.get(new Long(cachedKey));
+ return r;
+ }
+
+ //no range below this one
+ return null;
+ }
+
+ /**
+ * If the passed in evelopeRange encompasses several ranges, these are
+ * removed from the map
+ * @param currentRange
+ * @return
+ */
+ private void cleanUpRangesEnveloped(Range envelopeRange){
+ //see if there are any ranges that start at some point between
+ //immediately above the start of the envelope range up to
+ //its end
+ long startOfRangeLookup = envelopeRange.lowerValue + 1;
+ long endOfRangeLookup = envelopeRange.upperValue;
+ // Iterator over the available ranges.
+ Iterator ranges = rangeMap.keySet().iterator();
+ while (ranges.hasNext()) {
+ // Get the key
+ long key = ((Long)ranges.next()).longValue();
+ if (key >= startOfRangeLookup && key <= endOfRangeLookup) {
+ Range removedRange = (Range)rangeMap.get(new Long(key));
+
+ if(removedRange!=null && removedRange.upperValue>envelopeRange.upperValue){
+ //this range started in our envelope but stretched out beyond it so we
+ //can absorb its upper value
+ envelopeRange.upperValue = removedRange.upperValue;
+ }
+ // Remove the current range from the HashMap.
+ ranges.remove();
+ }
+ }
+ }
+
+ /**
+ * Looks to see if there is a range that starts immediately above
+ * this one. If so, that range is returned
+ * @param targetRange
+ * @return
+ */
+ private Range getRangeImmediatelyAbove(Range targetRange){
+ return (Range)rangeMap.get(new Long(targetRange.upperValue + 1));
+ }
+
+
+ public boolean isMessageNumberInRanges(long messageNumber){
+ if(getRangeForMessageNumber(messageNumber)!=null){
+ return true;
+ }
+
+ return false;
+ }
+
+ public Range getRangeForMessageNumber(long messageNumber){
+ Range below = getNextRangeBelow(messageNumber);
+ if(below!=null){
+ if(below.rangeContainsValue(messageNumber)){
+ //this range contains our value
+ return below;
+ }
+ }
+
+ //if we made it here then we are not in any ranges
+ return null;
+ }
+
+ /**
+ * Returns true if the numbers are contained in a single range
+ * @param interestedRange
+ * @return
+ */
+ public boolean isRangeCompleted(Range interestedRange){
+ Range containingRange = getNextRangeBelow(interestedRange.lowerValue);
+ if(containingRange!=null){
+ //so we know there is a range below us, check to see if it
+ //stretches to us or over above us
+ if(containingRange.upperValue>=interestedRange.upperValue){
+ //it does, so this range is contained
+ return true;
+ }
+ }
+ //either their was no range at all or it did not reach high enough
+ return false;
+ }
+
+ /**
+ * Returns a String representation of the ranges contained in this object
+ * @return a String of the form [x1,y1][x2,y2]...[xn,yn]
+ */
+ public String toString(){
+ List sortedList = getSortedKeyList();
+ String returnString = "";
+ for(int i=0; i<sortedList.size(); i++){
+ returnString = returnString + (rangeMap.get(sortedList.get(i))).toString();
+ }
+
+ return returnString;
+ }
+
+ /**
+ * @return ordered array of each range object in the string
+ */
+ public Range[] getRanges(){
+ List sortedKeyList = getSortedKeyList();
+ Range[] ranges = new Range[sortedKeyList.size()];
+ for(int i=0; i<ranges.length; i++){
+ ranges[i] = (Range)rangeMap.get(sortedKeyList.get(i));
+ }
+ return ranges;
+ }
+
+
+ private List getSortedKeyList(){
+ Set keySet = rangeMap.keySet();
+ //sort the set
+ List sortedList = new LinkedList(keySet);
+ Collections.sort(sortedList);
+ return sortedList;
+ }
+
+ /**
+ * Returns a List of the form
+ * [x1,x2,x3....xn] listing each discrete number contained in all of the ranges
+ * in order
+ * NOTE: inefficient, should be avoided
+ */
+ public List getContainedElementsAsNumbersList(){
+ List returnList = new LinkedList();
+ Range[] ranges = getRanges();
+ for(int i=0; i<ranges.length; i++){
+ for(long current = ranges[i].lowerValue; current<=ranges[i].upperValue; current++){
+ returnList.add(new Long(current));
+ }
+ }
+ return returnList;
+ }
+
+ public void addRange(Range r){
+
+ Range finalRange = r; //we use this to keep track of the final range
+ //as we might aggregate this new range with existing ranges
+
+ //first we try to aggregate existing ranges
+ boolean rangeAdded = false;
+ long indexKey = r.lowerValue;
+ //see if there is a range below that we can extend up
+ Range below = getNextRangeBelow(indexKey);
+ if(below!=null){
+ if(below.upperValue == (r.lowerValue -1)){
+ //we can extend this range up
+ below.upperValue = r.upperValue;
+ //we do not quit yet, as maybe this has plugged a gap between
+ //an upper range. But we should mark the range as added.
+ rangeAdded = true;
+ finalRange = below; //as below now encompasses both ranges agrregated together
+ }
+ else if(below.upperValue > r.lowerValue){
+ //the range below extends over this one - this range
+ //is already complete, so we do not need to add it at all.
+ return;
+ }
+ }
+
+ //see if we can extend another range down
+ Range above = getRangeImmediatelyAbove(r);
+ if(above!=null){
+ //we can extend this down
+ //first remove it. Then we will either add it under its new key or
+ //keep it removed
+ rangeMap.remove(new Long(above.lowerValue));
+ above.lowerValue = r.lowerValue; //extend down
+ if(rangeAdded){
+ //we extend down and up - join two ranges together
+ //Sicne we have removed the upper, we simply do not add it again and set the
+ //below range to encompass both of them
+ below.upperValue = above.upperValue;
+ //NOTE: finalRange has already been set when extending up
+ }
+ else{
+ //we did not extend up but we can extend down.
+ //Add the upper range back under its new key
+ rangeAdded = true;
+ rangeMap.put(new Long(above.lowerValue), above);
+ finalRange = above;
+ }
+
+ }
+
+ if(!rangeAdded){
+ //if we got here and did not add a range then we need to
+ //genuinely add a new range object
+ rangeMap.put(new Long(r.lowerValue), r);
+ }
+
+ //finally, we go through the new range we have added to make sure it
+ //does not now encompass any smaller ranges that were there before (but
+ //that could not be extended up or down)
+ cleanUpRangesEnveloped(finalRange);
+
+ }
+
+
+
+}
Added: webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/SOAPAbstractFactory.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/SOAPAbstractFactory.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/SOAPAbstractFactory.java (added)
+++ webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/SOAPAbstractFactory.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,38 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.sandesha2.util;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.sandesha2.Sandesha2Constants;
+
+/**
+ * A wrapper for SOA11 and SOAP12 factories of OM.
+ */
+
+public class SOAPAbstractFactory {
+
+ public static SOAPFactory getSOAPFactory(int SOAPVersion) {
+
+ if (SOAPVersion == Sandesha2Constants.SOAPVersion.v1_1)
+ return OMAbstractFactory.getSOAP11Factory();
+ else
+ return OMAbstractFactory.getSOAP12Factory();
+
+ }
+}
\ No newline at end of file
Added: webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/SOAPFaultEnvelopeCreator.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/SOAPFaultEnvelopeCreator.java?view=auto&rev=531400
==============================================================================
--- webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/SOAPFaultEnvelopeCreator.java (added)
+++ webservices/sandesha/trunk/java/modules/core/src/main/java/org/apache/sandesha2/util/SOAPFaultEnvelopeCreator.java Mon Apr 23 02:54:53 2007
@@ -0,0 +1,219 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.sandesha2.util;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.SOAPFault;
+import org.apache.axiom.soap.SOAPFaultCode;
+import org.apache.axiom.soap.SOAPFaultDetail;
+import org.apache.axiom.soap.SOAPFaultReason;
+import org.apache.axiom.soap.SOAPFaultSubCode;
+import org.apache.axiom.soap.SOAPFaultText;
+import org.apache.axiom.soap.SOAPFaultValue;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.context.MessageContext;
+import org.apache.sandesha2.FaultData;
+import org.apache.sandesha2.Sandesha2Constants;
+import org.apache.sandesha2.SandeshaException;
+import org.apache.sandesha2.i18n.SandeshaMessageHelper;
+import org.apache.sandesha2.i18n.SandeshaMessageKeys;
+import org.apache.sandesha2.wsrm.FaultCode;
+import org.apache.sandesha2.wsrm.SequenceFault;
+
+/**
+ * Used to create an SOAP Envelope for a RM Related Fault.
+ * Support both SOAP 1.1 and SOAP 1.2 encoding.
+ */
+
+public class SOAPFaultEnvelopeCreator {
+
+ /**
+ * Adding the SOAP Fault Envelope.
+ *
+ * @param faultMsgContext
+ * @param SOAPVersion
+ * @param faultData
+ * @throws SandeshaException
+ */
+ public static void addSOAPFaultEnvelope(MessageContext faultMsgContext,
+ int SOAPVersion, FaultData faultData, String rmNamespaceValue) throws SandeshaException {
+
+ SOAPFactory factory = SOAPAbstractFactory.getSOAPFactory(SOAPVersion);
+ SOAPEnvelope env = factory.getDefaultFaultEnvelope();
+
+ try {
+ faultMsgContext.setEnvelope(env);
+ } catch (AxisFault e) {
+ throw new SandeshaException(e.getMessage());
+ }
+
+ if (SOAPVersion == Sandesha2Constants.SOAPVersion.v1_1)
+ doSOAP11Encoding(faultMsgContext, faultData, rmNamespaceValue);
+ else
+ doSOAP12Encoding(faultMsgContext, faultData, rmNamespaceValue);
+
+ }
+
+ /**
+ * To find out weather this is a sequence fault. These faults are handeled differently
+ * according to the RM spec.
+ *
+ * @param faultData
+ * @return
+ */
+ private static boolean isSequenceFault(FaultData faultData) {
+
+ boolean sequenceFault = false;
+
+ int faultType = faultData.getType();
+
+ if (faultType <= 0)
+ return false;
+
+ if (faultType == Sandesha2Constants.SOAPFaults.FaultType.CREATE_SEQUENCE_REFUSED)
+ sequenceFault = true;
+ else if (faultType == Sandesha2Constants.SOAPFaults.FaultType.UNKNOWN_SEQUENCE)
+ sequenceFault = true;
+ else if (faultType == Sandesha2Constants.SOAPFaults.FaultType.INVALID_ACKNOWLEDGEMENT)
+ sequenceFault = true;
+ else if (faultType == Sandesha2Constants.SOAPFaults.FaultType.MESSAGE_NUMBER_ROLLOVER)
+ sequenceFault = true;
+ else if (faultType == Sandesha2Constants.SOAPFaults.FaultType.SEQUENCE_CLOSED)
+ sequenceFault = true;
+ else if (faultType == Sandesha2Constants.SOAPFaults.FaultType.SEQUENCE_TERMINATED)
+ sequenceFault = true;
+
+ return sequenceFault;
+
+ }
+
+ /**
+ * Adding the SequenceFault header. Only for Sequence faults.
+ *
+ * @param faultMessageContext
+ * @param faultData
+ * @param factory
+ */
+ private static void addSequenceFaultHeader(
+ MessageContext faultMessageContext, FaultData faultData,
+ SOAPFactory factory, String rmNamespaceValue) throws SandeshaException {
+
+ SequenceFault sequenceFault = new SequenceFault(rmNamespaceValue);
+
+ FaultCode faultCode = new FaultCode(rmNamespaceValue);
+ faultCode.setFaultCode(faultData.getSubcode());
+ if (faultData.getDetailString() != null)
+ faultCode.setDetail(faultData.getDetailString());
+ else {
+ faultCode.setDetailOMElement(faultData.getDetail());
+ faultCode.setExtendedDetailOMElement(faultData.getDetail2());
+ }
+ sequenceFault.setFaultCode(faultCode);
+
+ sequenceFault.toOMElement(faultMessageContext.getEnvelope().getHeader());
+ }
+
+ /**
+ * Building the envelope with SOAP 1.1
+ *
+ * @param faultMsgContext
+ * @param data
+ * @throws SandeshaException
+ */
+ private static void doSOAP11Encoding(MessageContext faultMsgContext,
+ FaultData data, String rmNamespaceValue) throws SandeshaException {
+
+ SOAPEnvelope faultMsgEnvelope = faultMsgContext.getEnvelope();
+ if (faultMsgEnvelope == null)
+ throw new SandeshaException(SandeshaMessageHelper.getMessage(
+ SandeshaMessageKeys.soapEnvNotSet));
+
+ SOAPFactory factory = SOAPAbstractFactory.getSOAPFactory(SandeshaUtil
+ .getSOAPVersion(faultMsgEnvelope));
+
+ SOAPFault fault = faultMsgEnvelope.getBody().getFault();
+
+ if (data.getExceptionString() != null)
+ fault.getDetail().setText(data.getExceptionString());
+
+ //SequenceFault header is added only for SOAP 1.1
+ if (isSequenceFault(data))
+ addSequenceFaultHeader(faultMsgContext, data, factory, rmNamespaceValue);
+
+ }
+
+ /**
+ * Building the envelope with SOAP 1.2
+ *
+ * @param faultMsgContext
+ * @param data
+ * @throws SandeshaException
+ */
+ private static void doSOAP12Encoding(MessageContext faultMsgContext,
+ FaultData data, String rmNamespaceValue) throws SandeshaException {
+
+ SOAPEnvelope faultEnvelope = faultMsgContext.getEnvelope();
+ if (faultEnvelope == null)
+ throw new SandeshaException(SandeshaMessageHelper.getMessage(
+ SandeshaMessageKeys.soapEnvNotSet));
+
+ SOAPFactory factory = SOAPAbstractFactory.getSOAPFactory(SandeshaUtil
+ .getSOAPVersion(faultEnvelope));
+
+ SOAPFault fault = faultEnvelope.getBody().getFault();
+ if (fault == null)
+ throw new SandeshaException(SandeshaMessageHelper.getMessage(
+ SandeshaMessageKeys.noFaultCode,
+ faultEnvelope.toString()));
+
+ SOAPFaultCode faultCode = fault.getCode();
+ SOAPFaultValue codeValue = faultCode.getValue();
+ codeValue.setText(data.getCode());
+
+ SOAPFaultSubCode faultSubCode = factory
+ .createSOAPFaultSubCode(faultCode);
+ SOAPFaultValue subCodeValue = factory
+ .createSOAPFaultValue(faultSubCode);
+ subCodeValue.setText(data.getSubcode());
+
+ SOAPFaultReason faultReason = fault.getReason();
+ SOAPFaultText faultText = faultReason.getSOAPFaultText("en");
+
+ if (faultText==null) {
+ faultText = factory.createSOAPFaultText();
+ faultReason.addSOAPText(faultText);
+ }
+
+ if (data!=null && data.getReason()!=null)
+ faultText.setText(data.getReason());
+
+ SOAPFaultDetail faultDetail = fault.getDetail();
+
+ OMElement detailElement = data.getDetail();
+
+ if (detailElement != null)
+ faultDetail.addChild(detailElement);
+
+
+ faultMsgContext.setWSAAction(AddressingConstants.Final.WSA_FAULT_ACTION);
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: sandesha-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: sandesha-dev-help@ws.apache.org