Author: hiranya
Date: Tue Oct 5 18:00:48 2010
New Revision: 1004739
URL: http://svn.apache.org/viewvc?rev=1004739&view=rev
Log:
Adding a test case for simple map impl
Refactoring
Added:
synapse/branches/2.0/modules/core/src/test/java/org/apache/synapse/util/SimpleMapTest.java
Modified:
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractMediatorFactory.java
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/config/xml/ProxyServiceSerializer.java
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/deployers/EventSourceDeployer.java
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/endpoints/EndpointView.java
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/mediators/builtin/CalloutMediator.java
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/mediators/ext/AnnotatedCommandMediator.java
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/mediators/filters/router/ConditionalRouterMediator.java
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/mediators/transform/url/RewriteRule.java
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/message/store/MessageStore.java
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/message/store/RedeliveryProcessor.java
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/ClasspathURLStreamHandler.java
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/PayloadHelper.java
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/SimpleMapImpl.java
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/UUIDGenerator.java
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseXPath.java
Modified:
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
URL:
http://svn.apache.org/viewvc/synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java?rev=1004739&r1=1004738&r2=1004739&view=diff
==============================================================================
---
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
(original)
+++
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
Tue Oct 5 18:00:48 2010
@@ -297,7 +297,8 @@ public class SynapseConfigUtils {
} finally {
try {
inStream.close();
- } catch (IOException ignore) {
+ } catch (IOException e) {
+ log.warn("Error while closing the input stream to: " + url, e);
}
}
}
Modified:
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractMediatorFactory.java
URL:
http://svn.apache.org/viewvc/synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractMediatorFactory.java?rev=1004739&r1=1004738&r2=1004739&view=diff
==============================================================================
---
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractMediatorFactory.java
(original)
+++
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractMediatorFactory.java
Tue Oct 5 18:00:48 2010
@@ -43,7 +43,7 @@ import java.util.Properties;
public abstract class AbstractMediatorFactory implements MediatorFactory {
/** the standard log for mediators, will assign the logger for the actual
subclass */
- protected static Log log;
+ static Log log;
protected static final QName ATT_NAME = new QName("name");
protected static final QName ATT_VALUE = new QName("value");
protected static final QName ATT_XPATH = new QName("xpath");
Modified:
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/config/xml/ProxyServiceSerializer.java
URL:
http://svn.apache.org/viewvc/synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/config/xml/ProxyServiceSerializer.java?rev=1004739&r1=1004738&r2=1004739&view=diff
==============================================================================
---
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/config/xml/ProxyServiceSerializer.java
(original)
+++
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/config/xml/ProxyServiceSerializer.java
Tue Oct 5 18:00:48 2010
@@ -67,7 +67,7 @@ public class ProxyServiceSerializer {
if (transports != null && !transports.isEmpty()) {
String transportStr = "" + transports.get(0);
for (int i = 1; i < transports.size(); i++) {
- transportStr = transportStr + " " + transports.get(i);
+ transportStr = transportStr.concat(" " + transports.get(i));
}
proxy.addAttribute(fac.createOMAttribute("transports", nullNS,
transportStr));
}
@@ -81,7 +81,7 @@ public class ProxyServiceSerializer {
if (pinnedServers != null && !pinnedServers.isEmpty()) {
String pinnedServersStr = "" + pinnedServers.get(0);
for (int i = 1; i < pinnedServers.size(); i++) {
- pinnedServersStr = pinnedServersStr + " " + pinnedServers.get(i);
+ pinnedServersStr = pinnedServersStr.concat(" " +
pinnedServers.get(i));
}
proxy.addAttribute(fac.createOMAttribute("pinnedServers", nullNS,
pinnedServersStr));
}
Modified:
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java
URL:
http://svn.apache.org/viewvc/synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java?rev=1004739&r1=1004738&r2=1004739&view=diff
==============================================================================
---
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java
(original)
+++
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java
Tue Oct 5 18:00:48 2010
@@ -53,7 +53,7 @@ import java.util.*;
*/
public abstract class EndpointFactory implements XMLToObjectMapper {
- protected static Log log;
+ static Log log;
protected EndpointFactory() {
log = LogFactory.getLog(this.getClass());
Modified:
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/deployers/EventSourceDeployer.java
URL:
http://svn.apache.org/viewvc/synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/deployers/EventSourceDeployer.java?rev=1004739&r1=1004738&r2=1004739&view=diff
==============================================================================
---
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/deployers/EventSourceDeployer.java
(original)
+++
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/deployers/EventSourceDeployer.java
Tue Oct 5 18:00:48 2010
@@ -26,6 +26,8 @@ import org.apache.synapse.config.xml.Mul
import org.apache.synapse.config.xml.eventing.EventSourceFactory;
import org.apache.synapse.config.xml.eventing.EventSourceSerializer;
import org.apache.synapse.eventing.SynapseEventSource;
+import org.apache.axis2.deployment.DeploymentException;
+import org.apache.axis2.AxisFault;
import java.io.File;
import java.util.Properties;
@@ -117,9 +119,11 @@ public class EventSourceDeployer extends
handleSynapseArtifactDeploymentError("EventSource Update
Failed. The artifact " +
"described in the file " + fileName + " is not a
EventSource");
}
- } catch (Exception e) {
+ } catch (DeploymentException e) {
handleSynapseArtifactDeploymentError(
"EventSource Update from the file : " + fileName + " :
Failed.", e);
+ } catch (AxisFault e) {
+ handleSynapseArtifactDeploymentError("Error while initializing the
event source", e);
}
return null;
Modified:
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/endpoints/EndpointView.java
URL:
http://svn.apache.org/viewvc/synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/endpoints/EndpointView.java?rev=1004739&r1=1004738&r2=1004739&view=diff
==============================================================================
---
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/endpoints/EndpointView.java
(original)
+++
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/endpoints/EndpointView.java
Tue Oct 5 18:00:48 2010
@@ -685,9 +685,8 @@ public class EndpointView implements End
* Is the endpoint considered to be in the given state?
* @param state the state to consider
* @return true if all endpoints in a group are of the given state, or if
a leaf endpoint is in the given state
- * @throws Exception
*/
- public boolean isEndpointInState(int state) throws Exception {
+ public boolean isEndpointInState(int state) {
if (endpoint.getChildren() != null) {
int count = 0, total = 0;
for (Endpoint e : endpoint.getChildren()) {
Modified:
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/mediators/builtin/CalloutMediator.java
URL:
http://svn.apache.org/viewvc/synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/mediators/builtin/CalloutMediator.java?rev=1004739&r1=1004738&r2=1004739&view=diff
==============================================================================
---
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/mediators/builtin/CalloutMediator.java
(original)
+++
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/mediators/builtin/CalloutMediator.java
Tue Oct 5 18:00:48 2010
@@ -140,9 +140,12 @@ public class CalloutMediator extends Abs
synLog.traceOrDebug("Service returned a null response");
}
- } catch (Exception e) {
+ } catch (AxisFault e) {
handleException("Error invoking service : " + serviceURL +
(action != null ? " with action : " + action : ""), e, synCtx);
+ } catch (JaxenException e) {
+ handleException("Error while evaluating the XPath expression: " +
targetXPath,
+ e, synCtx);
}
synLog.traceOrDebug("End : Callout mediator");
Modified:
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/mediators/ext/AnnotatedCommandMediator.java
URL:
http://svn.apache.org/viewvc/synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/mediators/ext/AnnotatedCommandMediator.java?rev=1004739&r1=1004738&r2=1004739&view=diff
==============================================================================
---
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/mediators/ext/AnnotatedCommandMediator.java
(original)
+++
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/mediators/ext/AnnotatedCommandMediator.java
Tue Oct 5 18:00:48 2010
@@ -206,9 +206,9 @@ public class AnnotatedCommandMediator ex
try {
SynapseXPath axiomXPath = new SynapseXPath(xpath);
-
- for (String prefix : namespaces.keySet()) {
- axiomXPath.addNamespace(prefix, namespaces.get(prefix));
+
+ for (Map.Entry<String, String> entry : namespaces.entrySet()) {
+ axiomXPath.addNamespace(entry.getKey(), entry.getValue());
}
return axiomXPath;
Modified:
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/mediators/filters/router/ConditionalRouterMediator.java
URL:
http://svn.apache.org/viewvc/synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/mediators/filters/router/ConditionalRouterMediator.java?rev=1004739&r1=1004738&r2=1004739&view=diff
==============================================================================
---
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/mediators/filters/router/ConditionalRouterMediator.java
(original)
+++
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/mediators/filters/router/ConditionalRouterMediator.java
Tue Oct 5 18:00:48 2010
@@ -55,9 +55,10 @@ public class ConditionalRouterMediator e
if (headers != null && headers instanceof Map) {
Map headersMap = (Map) headers;
- for (Object key : headersMap.keySet()) {
- if (key instanceof String && headersMap.get(key) instanceof
String) {
- evaluatorHeaders.put((String) key, (String)
headersMap.get(key));
+ for (Object entryObj : headersMap.entrySet()) {
+ Map.Entry entry = (Map.Entry) entryObj;
+ if (entry.getKey() instanceof String && entry.getValue()
instanceof String) {
+ evaluatorHeaders.put((String) entry.getKey(), (String)
entry.getValue());
}
}
}
Modified:
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/mediators/transform/url/RewriteRule.java
URL:
http://svn.apache.org/viewvc/synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/mediators/transform/url/RewriteRule.java?rev=1004739&r1=1004738&r2=1004739&view=diff
==============================================================================
---
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/mediators/transform/url/RewriteRule.java
(original)
+++
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/mediators/transform/url/RewriteRule.java
Tue Oct 5 18:00:48 2010
@@ -95,9 +95,10 @@ public class RewriteRule {
if (headers != null && headers instanceof Map) {
Map headersMap = (Map) headers;
- for (Object key : headersMap.keySet()) {
- if (key instanceof String && headersMap.get(key) instanceof
String) {
- evaluatorHeaders.put((String) key, (String)
headersMap.get(key));
+ for (Object entryObj : headersMap.entrySet()) {
+ Map.Entry entry = (Map.Entry) entryObj;
+ if (entry.getKey() instanceof String && entry.getValue()
instanceof String) {
+ evaluatorHeaders.put((String) entry.getKey(), (String)
entry.getValue());
}
}
}
Modified:
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/message/store/MessageStore.java
URL:
http://svn.apache.org/viewvc/synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/message/store/MessageStore.java?rev=1004739&r1=1004738&r2=1004739&view=diff
==============================================================================
---
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/message/store/MessageStore.java
(original)
+++
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/message/store/MessageStore.java
Tue Oct 5 18:00:48 2010
@@ -21,15 +21,16 @@ package org.apache.synapse.message.store
import org.apache.synapse.config.SynapseConfiguration;
import org.apache.synapse.SynapseArtifact;
+import org.apache.synapse.Nameable;
import java.util.List;
import java.util.Map;
/**
* This is the interface for the Synapse Message Store
- * Message Store used to store failed Messages.
+ * Message Store is used to store failed Messages.
*/
-public interface MessageStore extends SynapseArtifact {
+public interface MessageStore extends SynapseArtifact, Nameable {
/**
* store the Message in the Message Store
@@ -39,20 +40,6 @@ public interface MessageStore extends Sy
public void store(StorableMessage storableMessage);
/**
- * get the Message Store name.
- * Each Message Store must have a unique name.
- * @return name
- */
- public String getName();
-
- /**
- * Set the Message Store Name
- *
- * @param name Name of the message store
- */
- public void setName(String name);
-
- /**
* Store the Message in schedule queue to redeliver
*
* @param storableMessage A StorableMessage instance
@@ -159,13 +146,14 @@ public interface MessageStore extends Sy
/**
* Set the name of the file that the Message store is configured
*
- * @param filename
+ * @param filename Name of the file where this artifact is defined
*/
public void setFileName(String filename);
/**
* get the file name that the message store is configured
- * @return
+ *
+ * @return Name of the file where this artifact is defined
*/
public String getFileName();
Modified:
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/message/store/RedeliveryProcessor.java
URL:
http://svn.apache.org/viewvc/synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/message/store/RedeliveryProcessor.java?rev=1004739&r1=1004738&r2=1004739&view=diff
==============================================================================
---
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/message/store/RedeliveryProcessor.java
(original)
+++
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/message/store/RedeliveryProcessor.java
Tue Oct 5 18:00:48 2010
@@ -174,13 +174,12 @@ public class RedeliveryProcessor {
public void run() {
while (start) {
- synchronized (this) {
+ synchronized (messageStore) {
int delay = redeliveryDelay;
StorableMessage storableMessage;
storableMessage = messageStore.getFirstSheduledMessage();
-
if (storableMessage == null ||
storableMessage.getEndpoint() == null ||
!storableMessage.getEndpoint().readyToSend()) {
continue;
@@ -195,38 +194,35 @@ public class RedeliveryProcessor {
delay = redeliveryDelay;
} else {
- String numberS = (String) synCtx.getProperty(
+ String redeliveryCountStr = (String)
synCtx.getProperty(
SynapseConstants.MESSAGE_STORE_REDELIVERY_COUNT);
- int number = Integer.parseInt(numberS);
+ int redeliveryCount =
Integer.parseInt(redeliveryCountStr);
- if (number >= maxRedeleveries) {
+ if (redeliveryCount >= maxRedeleveries) {
if (log.isDebugEnabled()) {
log.debug("Maximum number of redelivery
attempts has exceeded " +
"for the message: " +
synCtx.getMessageID() + " - " +
"Message will be put back to the
message store.");
-
}
messageStore.store(storableMessage);
continue;
}
synCtx.setProperty(SynapseConstants.MESSAGE_STORE_REDELIVERY_COUNT, "" +
- (number + 1));
- if (maxRedeleveries <= (number+1)) {
+ (redeliveryCount + 1));
+ if (maxRedeleveries <= (redeliveryCount + 1)) {
synCtx.setProperty(SynapseConstants.MESSAGE_STORE_REDELIVERED, "true");
}
if (exponentialBackoff && backOffMultiplier == -1) {
- delay = (number + 1) * redeliveryDelay;
-
+ delay = (redeliveryCount + 1) * redeliveryDelay;
} else if (exponentialBackoff) {
- delay = (int) Math.pow(backOffMultiplier, number)
* redeliveryDelay;
-
+ delay = (int) Math.pow(backOffMultiplier,
redeliveryCount) * redeliveryDelay;
}
}
try {
- Thread.sleep(delay);
+ messageStore.wait(delay);
} catch (InterruptedException ignored) {
}
Modified:
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/ClasspathURLStreamHandler.java
URL:
http://svn.apache.org/viewvc/synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/ClasspathURLStreamHandler.java?rev=1004739&r1=1004738&r2=1004739&view=diff
==============================================================================
---
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/ClasspathURLStreamHandler.java
(original)
+++
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/ClasspathURLStreamHandler.java
Tue Oct 5 18:00:48 2010
@@ -42,10 +42,13 @@ public final class ClasspathURLStreamHan
public void connect() {}
public InputStream getInputStream() throws IOException {
- if (url != null && url.getHost() != null) {
+ if (url == null) {
+ throw new MalformedURLException("Null or empty classpath URL");
+ } else if (url.getHost() != null) {
throw new MalformedURLException("No host available in
classpath URLs");
}
- InputStream is =
ClasspathURLStreamHandler.class.getClassLoader().getResourceAsStream(url.getFile());
+ InputStream is = ClasspathURLStreamHandler.class.getClassLoader().
+ getResourceAsStream(url.getFile());
if (is == null) {
throw new IOException("Classpath resource not found: " + url);
}
Modified:
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/PayloadHelper.java
URL:
http://svn.apache.org/viewvc/synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/PayloadHelper.java?rev=1004739&r1=1004738&r2=1004739&view=diff
==============================================================================
---
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/PayloadHelper.java
(original)
+++
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/PayloadHelper.java
Tue Oct 5 18:00:48 2010
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.synapse.util;
import java.util.Iterator;
@@ -21,7 +40,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.MessageContext;
import org.apache.synapse.SynapseException;
-import org.apache.synapse.util.SimpleMap;
public class PayloadHelper {
@@ -46,14 +64,15 @@ public class PayloadHelper {
// the payload is set
public static int getPayloadType(SOAPEnvelope envelope) {
OMElement el = getXMLPayload(envelope);
- if (el.getQName().equals(BINARYELT))
+ if (el.getQName().equals(BINARYELT)) {
return BINARYPAYLOADTYPE;
- else if (el.getQName().equals(TEXTELT))
+ } else if (el.getQName().equals(TEXTELT)) {
return TEXTPAYLOADTYPE;
- else if (el.getQName().equals(MAPELT))
+ } else if (el.getQName().equals(MAPELT)) {
return MAPPAYLOADTYPE;
- else
+ } else {
return XMLPAYLOADTYPE; // default XML
+ }
}
public static int getPayloadType(MessageContext mc) {
@@ -173,7 +192,7 @@ public class PayloadHelper {
if (el == null)
return null;
if (!el.getQName().equals(TEXTELT)) {
- log.error("Wrong QName" + el.getQName());
+ log.error("Wrong QName " + el.getQName());
return null;
}
OMNode textNode = el.getFirstOMChild();
@@ -269,6 +288,7 @@ public class PayloadHelper {
}
return el.getXMLStreamReader();
}
+
public static XMLStreamReader getStAXPayload(MessageContext mc) {
if (mc.getEnvelope() == null) {
log.error("null envelope");
@@ -276,23 +296,21 @@ public class PayloadHelper {
}
return getStAXPayload(mc.getEnvelope());
}
+
public static void setStAXPayload(SOAPEnvelope envelope,
XMLStreamReader streamReader) {
StAXOMBuilder builder = new
StAXOMBuilder(envelope.getOMFactory(), streamReader);
OMElement el = builder.getDocumentElement();
setXMLPayload(envelope, el);
}
+
public static void setStAXPayload(MessageContext mc, XMLStreamReader
streamReader) {
if (mc.getEnvelope() == null) {
try {
-
mc.setEnvelope(OMAbstractFactory.getSOAP12Factory()
- .createSOAPEnvelope());
+
mc.setEnvelope(OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope());
} catch (Exception e) {
throw new SynapseException(e);
}
setStAXPayload(mc.getEnvelope(), streamReader);
}
-
}
-
-
}
Modified:
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/SimpleMapImpl.java
URL:
http://svn.apache.org/viewvc/synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/SimpleMapImpl.java?rev=1004739&r1=1004738&r2=1004739&view=diff
==============================================================================
---
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/SimpleMapImpl.java
(original)
+++
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/SimpleMapImpl.java
Tue Oct 5 18:00:48 2010
@@ -1,9 +1,11 @@
package org.apache.synapse.util;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import javax.activation.DataHandler;
import javax.xml.namespace.QName;
@@ -18,209 +20,203 @@ import org.apache.axiom.om.OMText;
public class SimpleMapImpl extends HashMap implements SimpleMap {
- private static final OMNamespace attrNS =
OMAbstractFactory.getOMFactory().createOMNamespace("", "");
- private static final String TYPE = "type";
- private static final String NAME = "name";
+ private static final OMNamespace attrNS =
OMAbstractFactory.getOMFactory().createOMNamespace("", "");
+ private static final String TYPE = "type";
- private static final String ENTRY = "entry";
+ private static final String NAME = "name";
- private static final String SHORT = "short";
+ private static final String ENTRY = "entry";
- private static final String LONG = "long";
-
- private static final String DOUBLE = "double";
- private static final String INTEGER = "int";
- private static final String FLOAT = "float";
-
- private static final String BYTEARRAY = "byte[]";
-
- private static final String BYTE = "byte";
-
- private static final String STRING = "string";
-
- private static final String BOOLEAN = "boolean";
-
- private static final String CHAR = "char";
-
- private static final long serialVersionUID = 1L;
-
- public SimpleMapImpl() {
- super();
- }
-
- public Object get(String name) {
- return this.get((Object) name);
- }
-
- public boolean getBoolean(String name) {
- Object o = this.get((Object) name);
- if (o instanceof Boolean) {
- return (Boolean) o;
- } else {
- throw new RuntimeException("getBoolean(" + name + "): "
- + o.getClass().getName() + " is not an
instance of Boolean");
- }
- }
-
- public byte getByte(String name) {
- Object o = this.get((Object) name);
- if (o instanceof Byte) {
- return (Byte) o;
- } else {
- throw new RuntimeException("getByte(" + name + "): "
- + o.getClass().getName() + " is not an
instance of Byte");
- }
- }
-
- public byte[] getBytes(String name) {
- Object o = this.get((Object) name);
- if (o instanceof byte[]) {
- return (byte[]) o;
- } else {
- throw new RuntimeException("getByteArray(" + name + "):
"
- + o.getClass().getName() + " is not an
instance of byte[]");
- }
- }
-
- public char getChar(String name) {
- Object o = this.get((Object) name);
- if (o instanceof Character) {
- return (Character) o;
- } else {
- throw new RuntimeException("getChar(" + name + "): "
- + o.getClass().getName()
- + " is not an instance of Character");
- }
- }
-
- public double getDouble(String name) {
- Object o = this.get((Object) name);
- if (o instanceof Double) {
- return (Double) o;
- } else {
- throw new RuntimeException("getDouble(" + name + "): "
- + o.getClass().getName() + " is not an
instance of Double");
- }
- }
-
- public float getFloat(String name) {
- Object o = this.get((Object) name);
- if (o instanceof Float) {
- return (Float) o;
- } else {
- throw new RuntimeException("getFloat(" + name + "): "
- + o.getClass().getName() + " is not an
instance of Float");
- }
- }
-
- public int getInt(String name) {
- Object o = this.get((Object) name);
- if (o instanceof Integer) {
- return (Integer) o;
- } else {
- throw new RuntimeException("getInt(" + name + "): "
- + o.getClass().getName() + " is not an
instance of Integer");
- }
- }
-
- public long getLong(String name) {
- Object o = this.get((Object) name);
- if (o instanceof Long) {
- return (Long) o;
- } else {
- throw new RuntimeException("getLong(" + name + "): "
- + o.getClass().getName() + " is not an
instance of Long");
- }
- }
-
- public short getShort(String name) {
- Object o = this.get((Object) name);
- if (o instanceof Short) {
- return (Short) o;
- } else {
- throw new RuntimeException("getShort(" + name + "): "
- + o.getClass().getName() + " is not an
instance of Short");
- }
- }
-
- public String getString(String name) {
- Object o = this.get((Object) name);
- if (o instanceof String) {
- return ((String) o);
- } else {
- throw new RuntimeException("getString(" + name + "): "
- + o.getClass().getName() + " is not an
instance of String");
- }
- }
-
- public void put(String name, Object value) {
- this.put((Object) name, value);
- }
-
- public void putBoolean(String name, boolean b) {
- this.put((Object) name, b);
-
- }
-
- public void putByte(String name, byte b) {
- this.put((Object) name, b);
-
- }
-
- public void putBytes(String name, byte[] bytes) {
- this.put((Object) name, bytes);
-
- }
-
- public void putChar(String name, char c) {
- this.put((Object) name, c);
-
- }
-
- public void putDouble(String name, double d) {
- this.put((Object) name, d);
-
- }
-
- public void putFloat(String name, float fl) {
- this.put((Object) name, fl);
-
- }
-
- public void putInt(String name, int i) {
- this.put((Object) name, i);
-
- }
-
- public void putLong(String name, long l) {
- this.put((Object) name, l);
-
- }
-
- public void putShort(String name, short s) {
- this.put((Object) name, s);
-
- }
-
- public void putString(String name, String value) {
- this.put((Object) name, value);
-
- }
-
- public OMElement getOMElement() {
- return getOMElement(OMAbstractFactory.getOMFactory());
- }
+ private static final String SHORT = "short";
- public OMElement getOMElement(OMFactory fac) {
- OMElement mapElement =
fac.createOMElement(PayloadHelper.MAPELT);
+ private static final String LONG = "long";
+
+ private static final String DOUBLE = "double";
+ private static final String INTEGER = "int";
+ private static final String FLOAT = "float";
+
+ private static final String BYTEARRAY = "byte[]";
+
+ private static final String BYTE = "byte";
+
+ private static final String STRING = "string";
+
+ private static final String BOOLEAN = "boolean";
+
+ private static final String CHAR = "char";
+
+ private static final long serialVersionUID = 1L;
+
+ public SimpleMapImpl() {
+ super();
+ }
+
+ public Object get(String name) {
+ return this.get((Object) name);
+ }
+
+ public boolean getBoolean(String name) {
+ Object o = this.get((Object) name);
+ if (o instanceof Boolean) {
+ return (Boolean) o;
+ } else {
+ throw new RuntimeException("getBoolean(" + name + "): "
+ + o.getClass().getName() + " is not an instance of
Boolean");
+ }
+ }
+
+ public byte getByte(String name) {
+ Object o = this.get((Object) name);
+ if (o instanceof Byte) {
+ return (Byte) o;
+ } else {
+ throw new RuntimeException("getByte(" + name + "): "
+ + o.getClass().getName() + " is not an instance of Byte");
+ }
+ }
+
+ public byte[] getBytes(String name) {
+ Object o = this.get((Object) name);
+ if (o instanceof byte[]) {
+ return (byte[]) o;
+ } else {
+ throw new RuntimeException("getByteArray(" + name + "): "
+ + o.getClass().getName() + " is not an instance of
byte[]");
+ }
+ }
+
+ public char getChar(String name) {
+ Object o = this.get((Object) name);
+ if (o instanceof Character) {
+ return (Character) o;
+ } else {
+ throw new RuntimeException("getChar(" + name + "): "
+ + o.getClass().getName()
+ + " is not an instance of Character");
+ }
+ }
+
+ public double getDouble(String name) {
+ Object o = this.get((Object) name);
+ if (o instanceof Double) {
+ return (Double) o;
+ } else {
+ throw new RuntimeException("getDouble(" + name + "): "
+ + o.getClass().getName() + " is not an instance of
Double");
+ }
+ }
+
+ public float getFloat(String name) {
+ Object o = this.get((Object) name);
+ if (o instanceof Float) {
+ return (Float) o;
+ } else {
+ throw new RuntimeException("getFloat(" + name + "): "
+ + o.getClass().getName() + " is not an instance of Float");
+ }
+ }
+
+ public int getInt(String name) {
+ Object o = this.get((Object) name);
+ if (o instanceof Integer) {
+ return (Integer) o;
+ } else {
+ throw new RuntimeException("getInt(" + name + "): "
+ + o.getClass().getName() + " is not an instance of
Integer");
+ }
+ }
+
+ public long getLong(String name) {
+ Object o = this.get((Object) name);
+ if (o instanceof Long) {
+ return (Long) o;
+ } else {
+ throw new RuntimeException("getLong(" + name + "): "
+ + o.getClass().getName() + " is not an instance of Long");
+ }
+ }
+
+ public short getShort(String name) {
+ Object o = this.get((Object) name);
+ if (o instanceof Short) {
+ return (Short) o;
+ } else {
+ throw new RuntimeException("getShort(" + name + "): "
+ + o.getClass().getName() + " is not an instance of Short");
+ }
+ }
+
+ public String getString(String name) {
+ Object o = this.get((Object) name);
+ if (o instanceof String) {
+ return ((String) o);
+ } else {
+ throw new RuntimeException("getString(" + name + "): "
+ + o.getClass().getName() + " is not an instance of
String");
+ }
+ }
+
+ public void put(String name, Object value) {
+ this.put((Object) name, value);
+ }
+
+ public void putBoolean(String name, boolean b) {
+ this.put((Object) name, b);
+ }
+
+ public void putByte(String name, byte b) {
+ this.put((Object) name, b);
+ }
+
+ public void putBytes(String name, byte[] bytes) {
+ this.put((Object) name, bytes);
+ }
+
+ public void putChar(String name, char c) {
+ this.put((Object) name, c);
+ }
+
+ public void putDouble(String name, double d) {
+ this.put((Object) name, d);
+ }
+
+ public void putFloat(String name, float fl) {
+ this.put((Object) name, fl);
+ }
+
+ public void putInt(String name, int i) {
+ this.put((Object) name, i);
+ }
+
+ public void putLong(String name, long l) {
+ this.put((Object) name, l);
+ }
+
+ public void putShort(String name, short s) {
+ this.put((Object) name, s);
+ }
+
+ public void putString(String name, String value) {
+ this.put((Object) name, value);
+ }
+
+ public OMElement getOMElement() {
+ return getOMElement(OMAbstractFactory.getOMFactory());
+ }
+
+ public OMElement getOMElement(OMFactory fac) {
+ OMElement mapElement = fac.createOMElement(PayloadHelper.MAPELT);
+
+ for (Object entryObj : this.entrySet()) {
+ Object key = ((Map.Entry) entryObj).getKey();
+ Object o = ((Map.Entry) entryObj).getValue();
- for (Object key : this.keySet()) {
if (key instanceof String) {
OMElement entry = fac.createOMElement(new QName(
PayloadHelper.AXIOMPAYLOADNS, ENTRY), mapElement);
- Object o = this.get(key);
entry.addAttribute(NAME, (String) key, attrNS);
+
if (o instanceof Character) {
entry.addAttribute(TYPE, CHAR, attrNS);
entry.setText(o.toString());
@@ -232,7 +228,7 @@ public class SimpleMapImpl extends HashM
entry.setText(o.toString());
} else if (o instanceof Byte) {
entry.addAttribute(TYPE, BYTE, attrNS);
- entry.setText(((Byte) o).toString());
+ entry.setText(o.toString());
} else if (o instanceof byte[]) {
entry.addAttribute(TYPE, BYTEARRAY, attrNS);
OMText text = fac.createOMText(new DataHandler(
@@ -260,58 +256,56 @@ public class SimpleMapImpl extends HashM
}
}
- return mapElement;
- }
+ return mapElement;
+ }
- // create an instance from an OMElement (if its the right shape!!!)
- public SimpleMapImpl(OMElement el) {
- super();
- if (el.getQName().equals(PayloadHelper.MAPELT)) {
- for (Iterator it = el.getChildElements(); it.hasNext();
) {
- OMElement child = (OMElement)it.next();
- if (child.getLocalName().equals(ENTRY)) {
- String name =
child.getAttributeValue(new QName("",NAME));
- String type =
child.getAttributeValue(new QName("", TYPE));
- try {
- if (type==null || name == null) {
- //bad!
- continue;
- }
- OMNode data = child.getFirstOMChild();
- if (data.getType()!=OMNode.TEXT_NODE) {
- continue; // BAD!
- }
- OMText text = (OMText)data;
- if (type.equals(INTEGER)) {
- this.put((Object)name, new
Integer(text.getText()));
- } else if (type.equals(CHAR)) {
- this.put((Object)name,
(text.getText().charAt(0)));
- } else if (type.equals(DOUBLE)) {
- this.put((Object)name, new
Double(text.getText()));
- } else if (type.equals(FLOAT)) {
- this.put((Object)name, new
Float(text.getText()));
- } else if (type.equals(BYTE)) {
- this.put((Object)name,
text.getText().getBytes()[0]);
- } else if (type.equals(SHORT)) {
- this.put((Object)name, new
Short(text.getText()));
- } else if (type.equals(LONG)) {
- this.put((Object)name, new
Long(text.getText()));
- } else if (type.equals(STRING)) {
- this.put((Object)name,
text.getText());
- } else if (type.equals(BYTEARRAY)) {
- DataHandler dh =
(DataHandler)text.getDataHandler();
- ByteArrayOutputStream baos =
new ByteArrayOutputStream();
- dh.writeTo(baos);
- this.put((Object)name,
baos.toByteArray());
- }
- } catch (Exception e) {
- e.printStackTrace();
- // ignore errors
- }
-
- }
- }
- }
- }
+ // create an instance from an OMElement (if its the right shape!!!)
+ public SimpleMapImpl(OMElement el) {
+ super();
+ if (el.getQName().equals(PayloadHelper.MAPELT)) {
+ for (Iterator it = el.getChildElements(); it.hasNext(); ) {
+ OMElement child = (OMElement)it.next();
+ if (child.getLocalName().equals(ENTRY)) {
+ String name = child.getAttributeValue(new QName("",NAME));
+ String type = child.getAttributeValue(new QName("", TYPE));
+ if (type == null || name == null) {
+ //bad!
+ continue;
+ }
+ OMNode data = child.getFirstOMChild();
+ if (data.getType() != OMNode.TEXT_NODE) {
+ continue; // BAD!
+ }
+ OMText text = (OMText)data;
+ if (type.equals(INTEGER)) {
+ this.put(name, new Integer(text.getText()));
+ } else if (type.equals(CHAR)) {
+ this.put(name, (text.getText().charAt(0)));
+ } else if (type.equals(DOUBLE)) {
+ this.put(name, new Double(text.getText()));
+ } else if (type.equals(FLOAT)) {
+ this.put(name, new Float(text.getText()));
+ } else if (type.equals(BYTE)) {
+ this.put(name, text.getText().getBytes()[0]);
+ } else if (type.equals(SHORT)) {
+ this.put(name, new Short(text.getText()));
+ } else if (type.equals(LONG)) {
+ this.put(name, new Long(text.getText()));
+ } else if (type.equals(STRING)) {
+ this.put(name, text.getText());
+ } else if (type.equals(BYTEARRAY)) {
+ DataHandler dh = (DataHandler) text.getDataHandler();
+ ByteArrayOutputStream baos = new
ByteArrayOutputStream();
+ try {
+ dh.writeTo(baos);
+ this.put(name, baos.toByteArray());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+ }
}
Modified:
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/UUIDGenerator.java
URL:
http://svn.apache.org/viewvc/synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/UUIDGenerator.java?rev=1004739&r1=1004738&r2=1004739&view=diff
==============================================================================
---
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/UUIDGenerator.java
(original)
+++
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/UUIDGenerator.java
Tue Oct 5 18:00:48 2010
@@ -85,12 +85,13 @@ public class UUIDGenerator {
sb.append(sid);
sb.append(":");
sb.append(Long.toString(rand));
- MessageDigest md5 = null;
+ MessageDigest md5;
try {
md5 = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
//System.out.println("Error: " + e);
//todo have to be properly handled
+ return null;
}
md5.update(sb.toString().getBytes());
byte[] array = md5.digest();
Modified:
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseXPath.java
URL:
http://svn.apache.org/viewvc/synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseXPath.java?rev=1004739&r1=1004738&r2=1004739&view=diff
==============================================================================
---
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseXPath.java
(original)
+++
synapse/branches/2.0/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseXPath.java
Tue Oct 5 18:00:48 2010
@@ -22,7 +22,6 @@ package org.apache.synapse.util.xpath;
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.apache.axiom.om.impl.llom.OMDocumentImpl;
import org.apache.axiom.om.impl.llom.OMElementImpl;
import org.apache.axiom.om.impl.llom.OMTextImpl;
@@ -154,8 +153,8 @@ public class SynapseXPath extends AXIOMX
}
SynapseXPath synXPath = new SynapseXPath(newXPath.toString());
- for (String prefix : nameSpaces.keySet()) {
- synXPath.addNamespace(prefix, nameSpaces.get(prefix));
+ for (Map.Entry<String,String> entry : nameSpaces.entrySet()) {
+ synXPath.addNamespace(entry.getKey(), entry.getValue());
}
return synXPath;
}
Added:
synapse/branches/2.0/modules/core/src/test/java/org/apache/synapse/util/SimpleMapTest.java
URL:
http://svn.apache.org/viewvc/synapse/branches/2.0/modules/core/src/test/java/org/apache/synapse/util/SimpleMapTest.java?rev=1004739&view=auto
==============================================================================
---
synapse/branches/2.0/modules/core/src/test/java/org/apache/synapse/util/SimpleMapTest.java
(added)
+++
synapse/branches/2.0/modules/core/src/test/java/org/apache/synapse/util/SimpleMapTest.java
Tue Oct 5 18:00:48 2010
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.synapse.util;
+
+import junit.framework.TestCase;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.util.AXIOMUtil;
+
+import java.util.Map;
+
+public class SimpleMapTest extends TestCase {
+
+ public void testConstructionFromXML() throws Exception {
+ String xml = "<map xmlns=\"http://ws.apache.org/commons/ns/payload\">"
+
+ "<entry name=\"key1\" type=\"int\">525</entry>" +
+ "<entry name=\"key2\" type=\"char\">d</entry>" +
+ "<entry name=\"key3\" type=\"double\">23.45</entry>" +
+ "<entry name=\"key4\" type=\"float\">-3.45</entry>" +
+ "<entry name=\"key5\"
type=\"long\">1234567890</entry>" +
+ "<entry name=\"key6\" type=\"short\">123</entry>" +
+ "<entry name=\"key7\" type=\"byte\">a</entry>" +
+ "<entry name=\"key8\" type=\"string\">hello
world</entry>" +
+ "</map>";
+ OMElement mapElement = AXIOMUtil.stringToOM(xml);
+
+ SimpleMap map = new SimpleMapImpl(mapElement);
+ assertEquals(525, map.getInt("key1"));
+ assertEquals('d', map.getChar("key2"));
+ assertEquals(23.45D, map.getDouble("key3"));
+ assertEquals(-3.45F, map.getFloat("key4"));
+ assertEquals(1234567890L, map.getLong("key5"));
+ assertEquals(123, map.getShort("key6"));
+ assertEquals("a".getBytes()[0], map.getByte("key7"));
+ assertEquals("hello world", map.getString("key8"));
+
+ map.putString("key1", "test");
+ assertEquals("test", map.getString("key1"));
+ }
+
+ public void testSerialization() {
+ SimpleMapImpl map = new SimpleMapImpl();
+ map.putInt("key1", 123);
+ map.putDouble("key2", 23.45D);
+ map.putString("key3", "hello");
+ map.putByte("key4", "s".getBytes()[0]);
+
+ OMElement mapElement = map.getOMElement();
+ System.out.println(mapElement.toString());
+
+ SimpleMap copy = new SimpleMapImpl(mapElement);
+ assertEquals(map.size(), copy.size());
+ for (Object entryObj : map.entrySet()) {
+ Map.Entry entry = (Map.Entry) entryObj;
+ assertTrue(copy.containsKey(entry.getKey()) &&
entry.getValue().equals(
+ map.get(entry.getKey())));
+ }
+ }
+}