You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by pa...@apache.org on 2011/09/22 05:20:38 UTC
svn commit: r1173945 - in /incubator/airavata/trunk/modules/ws-messenger: ./
commons/src/main/java/org/apache/airavata/wsmg/commons/storage/
messagebox/src/main/resources/
messagebroker/src/main/java/org/apache/airavata/wsmg/broker/subscription/
messag...
Author: patanachai
Date: Thu Sep 22 03:20:37 2011
New Revision: 1173945
URL: http://svn.apache.org/viewvc?rev=1173945&view=rev
Log:
AIRAVATA-108 remove log4j from ws-messenger
Removed:
incubator/airavata/trunk/modules/ws-messenger/messagebox/src/main/resources/log4j.properties
incubator/airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/exceptions/
incubator/airavata/trunk/modules/ws-messenger/messagebroker/src/main/resources/log4j.properties.txt
incubator/airavata/trunk/modules/ws-messenger/messenger/src/main/java/org/apache/airavata/wsmg/messenger/util/
incubator/airavata/trunk/modules/ws-messenger/messenger/src/main/resources/log4jconfig.xml
Modified:
incubator/airavata/trunk/modules/ws-messenger/commons/src/main/java/org/apache/airavata/wsmg/commons/storage/DatabaseCreator.java
incubator/airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/broker/subscription/SubscriptionState.java
incubator/airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/util/OMElementComparator.java
incubator/airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/util/BrokerUtil.java
incubator/airavata/trunk/modules/ws-messenger/messenger/pom.xml
incubator/airavata/trunk/modules/ws-messenger/messenger/src/main/java/org/apache/airavata/wsmg/messenger/MessengerServlet.java
incubator/airavata/trunk/modules/ws-messenger/pom.xml
Modified: incubator/airavata/trunk/modules/ws-messenger/commons/src/main/java/org/apache/airavata/wsmg/commons/storage/DatabaseCreator.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/ws-messenger/commons/src/main/java/org/apache/airavata/wsmg/commons/storage/DatabaseCreator.java?rev=1173945&r1=1173944&r2=1173945&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/ws-messenger/commons/src/main/java/org/apache/airavata/wsmg/commons/storage/DatabaseCreator.java (original)
+++ incubator/airavata/trunk/modules/ws-messenger/commons/src/main/java/org/apache/airavata/wsmg/commons/storage/DatabaseCreator.java Thu Sep 22 03:20:37 2011
@@ -140,7 +140,6 @@ public class DatabaseCreator {
statement = conn.createStatement();
ret = statement.execute(sql);
updateCount = statement.getUpdateCount();
- ResultSet resultSet = statement.getResultSet();
do {
if (!ret) {
if (updateCount != -1) {
@@ -150,7 +149,6 @@ public class DatabaseCreator {
ret = statement.getMoreResults();
if (ret) {
updateCount = statement.getUpdateCount();
- resultSet = statement.getResultSet();
}
} while (ret);
Modified: incubator/airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/broker/subscription/SubscriptionState.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/broker/subscription/SubscriptionState.java?rev=1173945&r1=1173944&r2=1173945&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/broker/subscription/SubscriptionState.java (original)
+++ incubator/airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/broker/subscription/SubscriptionState.java Thu Sep 22 03:20:37 2011
@@ -25,11 +25,11 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.util.Iterator;
import java.util.Map;
+import java.util.Map.Entry;
import javax.xml.namespace.QName;
import org.apache.airavata.wsmg.broker.ConsumerInfo;
-import org.apache.airavata.wsmg.commons.exceptions.XMLComparisonException;
import org.apache.airavata.wsmg.commons.util.OMElementComparator;
import org.apache.airavata.wsmg.messenger.OutGoingQueue;
import org.apache.airavata.wsmg.util.BrokerUtil;
@@ -140,7 +140,7 @@ public class SubscriptionState {
// String topicLocalString = topicExpressionQName.getLocalPart();
return localTopicString;
}
-
+
/**
* @return Returns the consumeReference.
*/
@@ -250,70 +250,52 @@ public class SubscriptionState {
@Override
public boolean equals(Object o) {
- boolean ret = false;
-
if (o instanceof SubscriptionState) {
SubscriptionState subscription = (SubscriptionState) o;
-
- ret = BrokerUtil.sameStringValue(subscription.getLocalTopic(), this.getLocalTopic())
+ return BrokerUtil.sameStringValue(subscription.getLocalTopic(), this.getLocalTopic())
&& BrokerUtil.sameStringValue(subscription.getXpathString(), this.getXpathString())
- && (subscription.getConsumerIPAddressStr().compareTo(this.getConsumerIPAddressStr())) == 0
+ && BrokerUtil.sameStringValue(subscription.getConsumerIPAddressStr(),
+ this.getConsumerIPAddressStr())
&& equalReferenceParameters(subscription);
-
}
-
- return ret;
+ return false;
}
-
- // TODO : find a better way to do this.
+
private boolean equalReferenceParameters(SubscriptionState anotherSubscription) {
Map<QName, OMElement> otherRefProperties = anotherSubscription.getConsumerReference()
.getAllReferenceParameters();
Map<QName, OMElement> myRefProperties = getConsumerReference().getAllReferenceParameters();
- if (otherRefProperties == null) {
-
- if (myRefProperties == null) {
- return true;
- }
+ /*
+ * Basic comparison
+ */
+ if (otherRefProperties == null && myRefProperties == null) {
+ return true;
+ } else if (otherRefProperties == null || myRefProperties == null) {
return false;
-
- }
-
- if (myRefProperties == null) {
- return false;
- }
-
- if (otherRefProperties.size() != myRefProperties.size()) {
+ } else if (otherRefProperties.size() != myRefProperties.size()) {
return false;
}
- Iterator<QName> iterator = otherRefProperties.keySet().iterator();
-
+ /*
+ * This OMElementComparator supports ignore list, but we don't use it here.
+ */
+ Iterator<Entry<QName, OMElement>> iterator = otherRefProperties.entrySet().iterator();
while (iterator.hasNext()) {
- QName key = iterator.next();
- OMElement myElement = myRefProperties.get(key);
- if (myElement == null) {
+ Entry<QName, OMElement> entry = iterator.next();
+ if (!myRefProperties.containsKey(entry.getKey())) {
return false;
}
- OMElement otherElement = otherRefProperties.get(key);
+ OMElement myElement = myRefProperties.get(entry.getKey());
+ OMElement otherElement = entry.getValue();
- // TODO : find out another way to compare two OMelements
- OMElementComparator comparator = new OMElementComparator();
- try {
- if (!comparator.compare(myElement, otherElement)) {
- return false;
- }
- } catch (XMLComparisonException e) {
-
- logger.info("unable to compare om elements", e);
+ if (!OMElementComparator.compare(myElement, otherElement)) {
return false;
}
}
-
return true;
}
Modified: incubator/airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/util/OMElementComparator.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/util/OMElementComparator.java?rev=1173945&r1=1173944&r2=1173945&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/util/OMElementComparator.java (original)
+++ incubator/airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/commons/util/OMElementComparator.java Thu Sep 22 03:20:37 2011
@@ -21,22 +21,33 @@
package org.apache.airavata.wsmg.commons.util;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
-import java.util.Vector;
+import java.util.List;
-import org.apache.airavata.wsmg.commons.exceptions.XMLComparisonException;
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.wsmg.util.BrokerUtil;
import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.OMNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class OMElementComparator {
+/**
+ * Compare two OMElement with its namespace, attributes, children, and text.
+ * Current implementation supports ignore namespace checking i.e. if the
+ * namespace is in the list, it is skipped and return as equals.
+ */
+public class OMElementComparator {
private static final Logger log = LoggerFactory.getLogger(OMElementComparator.class);
- private Vector<String> ignorableNamespaceList = new Vector<String>();
+ private static List<String> ignorableNamespaceList = new ArrayList<String>();
+
+ private OMElementComparator(){
+ }
public void addIgnorableNamespace(String nsURI) {
ignorableNamespaceList.add(nsURI);
@@ -44,55 +55,37 @@ public class OMElementComparator {
public void clearIgnorableNamespaces() {
ignorableNamespaceList.clear();
- }
+ }
- public boolean compare(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {
+ public static boolean compare(OMElement elementOne, OMElement elementTwo) {
- // ignore if the elements belong to any of the ignorable namespaces list
if (isIgnorable(elementOne) || isIgnorable(elementTwo)) {
+ // ignore if the elements belong to any of the ignorable namespaces
+ // list
return true;
- }
-
- if (elementOne == null && elementTwo == null) {
- log.info("Both Elements are null.");
+ } else if (elementOne == null && elementTwo == null) {
+ log.debug("Both Elements are null.");
return true;
+ } else if (elementOne == null || elementTwo == null) {
+ log.debug("One of item to compare is null");
+ return false;
}
- if (elementOne == null && elementTwo != null) {
- throw new XMLComparisonException("Element One is null and Element Two is not null");
- }
- if (elementOne != null && elementTwo == null) {
- throw new XMLComparisonException("Element Two is null and Element One is not null");
- }
-
- compare("Elements names are not equal. ", elementOne.getLocalName(), elementTwo.getLocalName());
- compare("Element namespaces are not equal", elementOne.getNamespace(), elementTwo.getNamespace());
-
- compareAllAttributes(elementOne, elementTwo);
-
- /*
- * Trimming the value of the XMLElement is not correct since this compare method cannot be used to compare
- * element contents with trailing and leading whitespaces BUT for the practicalltiy of tests and to get the
- * current tests working we have to trim() the contents
- */
- compare("Elements texts are not equal ", elementOne.getText().trim(), elementTwo.getText().trim());
-
- compareAllChildren(elementOne, elementTwo);
-
- return true;
- }
-
- private void compareAllAttributes(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {
- compareAttibutes(elementOne, elementTwo);
- compareAttibutes(elementTwo, elementOne);
+ return BrokerUtil.sameStringValue(elementOne.getLocalName(), elementTwo.getLocalName())
+ && compare(elementOne.getNamespace(), elementTwo.getNamespace())
+ && compareAttibutes(elementOne, elementTwo)
+ /*
+ * Trimming the value of the XMLElement is not correct since
+ * this compare method cannot be used to compare element
+ * contents with trailing and leading whitespaces BUT for the
+ * practical side of tests and to get the current tests working
+ * we have to trim() the contents
+ */
+ && BrokerUtil.sameStringValue(elementOne.getText().trim(), elementTwo.getText().trim())
+ && compareChildren(elementOne, elementTwo);
}
- private void compareAllChildren(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {
- compareChildren(elementOne, elementTwo);
- compareChildren(elementTwo, elementOne);
- }
-
- private boolean isIgnorable(OMElement elt) {
+ private static boolean isIgnorable(OMElement elt) {
if (elt != null) {
OMNamespace namespace = elt.getNamespace();
if (namespace != null) {
@@ -105,79 +98,84 @@ public class OMElementComparator {
}
}
- private void compareChildren(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {
- // ignore if the elements belong to any of the ignorable namespaces list
- if (isIgnorable(elementOne) || isIgnorable(elementTwo)) {
- return;
+ private static boolean compareChildren(OMElement elementOne, OMElement elementTwo) {
+ HashMap<QName, OMElement> map = new HashMap<QName, OMElement>();
+ Iterator oneIter = elementOne.getChildElements();
+ while (oneIter.hasNext()) {
+ OMElement elementOneChild = (OMElement) oneIter.next();
+ OMElement elementTwoChild = elementTwo.getFirstChildWithName(elementOneChild.getQName());
+ if (!compare(elementOneChild, elementTwoChild)) {
+ return false;
+ }
+
+ /*
+ * Cache for later access
+ */
+ map.put(elementOneChild.getQName(), elementOneChild);
}
- Iterator elementOneChildren = elementOne.getChildren();
- while (elementOneChildren.hasNext()) {
- OMNode omNode = (OMNode) elementOneChildren.next();
- if (omNode instanceof OMElement) {
- OMElement elementOneChild = (OMElement) omNode;
- OMElement elementTwoChild = null;
- // Do the comparison only if the element is not ignorable
- if (!isIgnorable(elementOneChild)) {
- elementTwoChild = elementTwo.getFirstChildWithName(elementOneChild.getQName());
- // Do the comparison only if the element is not ignorable
- if (!isIgnorable(elementTwoChild)) {
- if (elementTwoChild == null) {
- throw new XMLComparisonException(" There is no " + elementOneChild.getLocalName()
- + " element under " + elementTwo.getLocalName());
- }
- }
- }
- compare(elementOneChild, elementTwoChild);
+
+ /*
+ * Case the second element has more elements than the first
+ */
+ Iterator twoIter = elementTwo.getChildElements();
+ while (twoIter.hasNext()) {
+ OMElement elementTwoChild = (OMElement) twoIter.next();
+ if (!isIgnorable(elementTwoChild) && !map.containsKey(elementTwoChild.getQName())) {
+ return false;
}
}
+
+ return true;
}
- private void compareAttibutes(OMElement elementOne, OMElement elementTwo) throws XMLComparisonException {
+ private static boolean compareAttibutes(OMElement elementOne, OMElement elementTwo) {
int elementOneAtribCount = 0;
int elementTwoAtribCount = 0;
- Iterator attributes = elementOne.getAllAttributes();
- while (attributes.hasNext()) {
- OMAttribute omAttribute = (OMAttribute) attributes.next();
+ Iterator oneIter = elementOne.getAllAttributes();
+ while (oneIter.hasNext()) {
+
+ /*
+ * This catches a case where the first one has more items than the
+ * second one (one.attributes.size > two.attributes.size) and a case
+ * where the first and the second have a different attributes.
+ * (one.attributes.size == two.attributes.size)
+ */
+ OMAttribute omAttribute = (OMAttribute) oneIter.next();
OMAttribute attr = elementTwo.getAttribute(omAttribute.getQName());
if (attr == null) {
- throw new XMLComparisonException("Attributes are not the same in two elements. Attribute "
- + omAttribute.getLocalName() + " != ");
+ log.debug("Attribute " + omAttribute + " is not found in both elements.");
+ return false;
}
+ /*
+ * Count attributes in the first item
+ */
elementOneAtribCount++;
}
+ /*
+ * Count attributes in the second item
+ */
Iterator elementTwoIter = elementTwo.getAllAttributes();
while (elementTwoIter.hasNext()) {
elementTwoIter.next();
elementTwoAtribCount++;
-
- }
-
- if (elementOneAtribCount != elementTwoAtribCount) {
- throw new XMLComparisonException("Attributes are not the same in two elements.");
}
- }
- private void compare(String failureNotice, String one, String two) throws XMLComparisonException {
- if (!one.equals(two)) {
- throw new XMLComparisonException(failureNotice + one + " != " + two);
- }
+ /*
+ * This catches a case where the second one has more items than the
+ * first one. (two.attributes.size > one.attributes.size)
+ */
+ log.debug("Number of Attributes are equal? : " + (elementOneAtribCount == elementTwoAtribCount));
+ return elementOneAtribCount == elementTwoAtribCount;
}
- private void compare(String failureNotice, OMNamespace one, OMNamespace two) throws XMLComparisonException {
- if (one == null && two == null) {
- return;
- } else if (one != null && two == null) {
- throw new XMLComparisonException("First Namespace is NOT null. But the second is null");
- } else if (one == null && two != null) {
- throw new XMLComparisonException("First Namespace is null. But the second is NOT null");
- }
-
- if (!one.getNamespaceURI().equals(two.getNamespaceURI())) {
- throw new XMLComparisonException(failureNotice + one + " != " + two);
- }
-
- // Do we need to compare prefixes as well
+ /*
+ * Compare only URI not prefix
+ */
+ private static boolean compare(OMNamespace x, OMNamespace y) {
+ log.debug("Compare namespace:" + x + " with " + y);
+ return (x == null && y == null)
+ || (x != null && y != null && BrokerUtil.sameStringValue(x.getNamespaceURI(), y.getNamespaceURI()));
}
}
Modified: incubator/airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/util/BrokerUtil.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/util/BrokerUtil.java?rev=1173945&r1=1173944&r2=1173945&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/util/BrokerUtil.java (original)
+++ incubator/airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/util/BrokerUtil.java Thu Sep 22 03:20:37 2011
@@ -28,24 +28,20 @@ import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMElement;
import org.apache.axis2.AxisFault;
-public class BrokerUtil {
-
- public static boolean sameStringValue(String stringA, String stringB) {
- if (stringA == null) {
- if (stringB == null) {
- return true;
- }
- return false;
-
- }
- // StringA!=null
- if (stringB == null)
- return false;
- if (stringA.compareTo(stringB) == 0) {
- return true;
- }
- return false;
+public class BrokerUtil {
+ /**
+ * Compares String {@code x} with String {@code y}. The result is {@code true} if and only
+ * if both arguments are {@code null} or String {@code x} has the same sequence of
+ * characters as String {@code y}.
+ *
+ * @param x
+ * @param y
+ * @return {@code true} if the String {@code x} and String {@code y} are
+ * equivalent, {@code false} otherwise
+ */
+ public static boolean sameStringValue(String x, String y) {
+ return (x == null && y == null) || (x != null && y != null && x.equals(y));
}
public static String getTopicLocalString(String filterText) {
Modified: incubator/airavata/trunk/modules/ws-messenger/messenger/pom.xml
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/ws-messenger/messenger/pom.xml?rev=1173945&r1=1173944&r2=1173945&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/ws-messenger/messenger/pom.xml (original)
+++ incubator/airavata/trunk/modules/ws-messenger/messenger/pom.xml Thu Sep 22 03:20:37 2011
@@ -47,8 +47,6 @@
<groupId>airavata</groupId>
<artifactId>airavata-messagebroker</artifactId>
<version>${airavata.version}</version>
- <type>jar</type>
- <scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
@@ -72,16 +70,8 @@
<artifactId>axiom-impl</artifactId>
</dependency>
<dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- </dependency>
- <dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
</dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- </dependency>
</dependencies>
</project>
Modified: incubator/airavata/trunk/modules/ws-messenger/messenger/src/main/java/org/apache/airavata/wsmg/messenger/MessengerServlet.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/ws-messenger/messenger/src/main/java/org/apache/airavata/wsmg/messenger/MessengerServlet.java?rev=1173945&r1=1173944&r2=1173945&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/ws-messenger/messenger/src/main/java/org/apache/airavata/wsmg/messenger/MessengerServlet.java (original)
+++ incubator/airavata/trunk/modules/ws-messenger/messenger/src/main/java/org/apache/airavata/wsmg/messenger/MessengerServlet.java Thu Sep 22 03:20:37 2011
@@ -40,11 +40,12 @@ import org.apache.airavata.wsmg.messenge
import org.apache.airavata.wsmg.messenger.strategy.impl.ParallelSender;
import org.apache.airavata.wsmg.messenger.strategy.impl.SerialSender;
import org.apache.airavata.wsmg.util.RunTimeStatistics;
-import org.apache.log4j.Logger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class MessengerServlet extends HttpServlet {
- private static final Logger logger = Logger.getLogger(MessengerServlet.class);
+ private static final Logger logger = LoggerFactory.getLogger(MessengerServlet.class);
private static final long serialVersionUID = -7175511030332798604L;
@@ -138,7 +139,7 @@ public class MessengerServlet extends Ht
WsmgCommonConstants.CONFIG_STORAGE_TYPE);
if (WsmgCommonConstants.STORAGE_TYPE_IN_MEMORY.equalsIgnoreCase(type)) {
- logger.fatal("invalid storage type specified: " + type);
+ logger.error("invalid storage type specified: " + type);
throw new RuntimeException("invalid storage type specified: " + type);
}
Modified: incubator/airavata/trunk/modules/ws-messenger/pom.xml
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/ws-messenger/pom.xml?rev=1173945&r1=1173944&r2=1173945&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/ws-messenger/pom.xml (original)
+++ incubator/airavata/trunk/modules/ws-messenger/pom.xml Thu Sep 22 03:20:37 2011
@@ -78,31 +78,7 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>1.2.15</version>
- <scope>provided</scope>
- <exclusions>
- <exclusion>
- <groupId>javax.mail</groupId>
- <artifactId>mail</artifactId>
- </exclusion>
- <exclusion>
- <groupId>javax.jms</groupId>
- <artifactId>jms</artifactId>
- </exclusion>
- <exclusion>
- <groupId>com.sun.jdmk</groupId>
- <artifactId>jmxtools</artifactId>
- </exclusion>
- <exclusion>
- <groupId>com.sun.jmx</groupId>
- <artifactId>jmxri</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
+ </dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>