[jboss-svn-commits] JBL Code SVN: r8762 - in labs/jbossesb/trunk: product/core/listeners/src/org/jboss/soa/esb/listeners product/core/listeners/src/org/jboss/soa/esb/listeners/config/mappers product/core/listeners/src/org/jboss/soa/esb/listeners/gateway product/core/listeners/src/org/jboss/soa/esb/listeners/message product/core/listeners/tests/src/org/jboss/soa/esb/listeners product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/helpers product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs product/core/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/tests product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/tests product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/tests product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests qa/junit/src/org/jboss/soa/esb/listeners/gateway
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Jan 8 10:25:15 EST 2007
Author: mark.little at jboss.com
Date: 2007-01-08 10:24:39 -0500 (Mon, 08 Jan 2007)
New Revision: 8762
Modified:
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerUtil.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/mappers/JmsListenerMapper.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java
labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/JmsQueueListener.java
labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerFTPIntegrationTest.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/helpers/CallHelper.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/helpers/EPRHelper.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/EmailEpr.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/FTPEpr.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/FileEpr.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/HTTPEpr.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/JDBCEpr.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/JMSEpr.java
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/SFTPEpr.java
labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/tests/CourierUtilUnitTest.java
labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/tests/EPRUnitTest.java
labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/tests/EPRHelperUnitTest.java
labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/tests/EPRManagerUnitTest.java
labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/BaseTest.java
labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/MessageUnitTest.java
labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/SerializedMessageUnitTest.java
labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/XMLMessageUnitTest.java
labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListenerUnitTest.java
Log:
Fixed serialization on EPRs to maintain type information across boundaries.
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerUtil.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerUtil.java 2007-01-08 14:45:14 UTC (rev 8761)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/ListenerUtil.java 2007-01-08 15:24:39 UTC (rev 8762)
@@ -197,7 +197,7 @@
String jndiURL = getAttrAndWarn(tree, JMSEpr.JNDI_URL_TAG,
"localhost");
String jndiContextFactory = getAttrAndWarn(tree,
- JMSEpr.JNDI_CONTEXT_FACTORY,
+ JMSEpr.JNDI_CONTEXT_FACTORY_TAG,
NamingContext.JBOSS_INITIAL_CONTEXT_FACTORY);
String jndiPkgPrefix = getAttrAndWarn(tree,
JMSEpr.JNDI_PKG_PREFIX_TAG,
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/mappers/JmsListenerMapper.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/mappers/JmsListenerMapper.java 2007-01-08 14:45:14 UTC (rev 8761)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/config/mappers/JmsListenerMapper.java 2007-01-08 15:24:39 UTC (rev 8762)
@@ -109,7 +109,7 @@
toElement.setAttribute(JMSEpr.DESTINATION_NAME_TAG, messageFilter.getDestName());
toElement.setAttribute(JMSEpr.MESSAGE_SELECTOR_TAG, messageFilter.getSelector());
toElement.setAttribute(JMSEpr.CONNECTION_FACTORY_TAG, provider.getConnectionFactory());
- toElement.setAttribute(JMSEpr.JNDI_CONTEXT_FACTORY, provider.getJndiContextFactory());
+ toElement.setAttribute(JMSEpr.JNDI_CONTEXT_FACTORY_TAG, provider.getJndiContextFactory());
toElement.setAttribute(JMSEpr.JNDI_PKG_PREFIX_TAG, provider.getJndiPkgPrefix());
toElement.setAttribute(JMSEpr.JNDI_URL_TAG, provider.getJndiURL());
}
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java 2007-01-08 14:45:14 UTC (rev 8761)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListener.java 2007-01-08 15:24:39 UTC (rev 8762)
@@ -222,9 +222,9 @@
if (null==_config.getAttribute(JMSEpr.JNDI_URL_TAG))
_logger.debug("No value specified for "+JMSEpr.JNDI_URL_TAG+" attribute"
+" - Using default of: '"+sJndiURL+"'");
- String sJndiContextFactory = _controller.obtainAtt(_config, JMSEpr.JNDI_CONTEXT_FACTORY,NamingContext.JBOSS_INITIAL_CONTEXT_FACTORY);
- if (null==_config.getAttribute(JMSEpr.JNDI_CONTEXT_FACTORY))
- _logger.debug("No value specified for "+JMSEpr.JNDI_CONTEXT_FACTORY+" attribute"
+ String sJndiContextFactory = _controller.obtainAtt(_config, JMSEpr.JNDI_CONTEXT_FACTORY_TAG,NamingContext.JBOSS_INITIAL_CONTEXT_FACTORY);
+ if (null==_config.getAttribute(JMSEpr.JNDI_CONTEXT_FACTORY_TAG))
+ _logger.debug("No value specified for "+JMSEpr.JNDI_CONTEXT_FACTORY_TAG+" attribute"
+" - Using default of: '"+sJndiContextFactory+"'");
String sJndiPkgPrefix = _controller.obtainAtt(_config, JMSEpr.JNDI_PKG_PREFIX_TAG,NamingContext.JBOSS_PROVIDER_URL);
if (null==_config.getAttribute(JMSEpr.JNDI_PKG_PREFIX_TAG))
Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/JmsQueueListener.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/JmsQueueListener.java 2007-01-08 14:45:14 UTC (rev 8761)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/listeners/message/JmsQueueListener.java 2007-01-08 15:24:39 UTC (rev 8762)
@@ -163,9 +163,9 @@
if (null==_config.getAttribute(JMSEpr.JNDI_URL_TAG))
_logger.debug("No value specified for "+JMSEpr.JNDI_URL_TAG+" attribute"
+" - Using default of: '"+_jndiURL+"'");
- _jndiContextFactory = obtainAttribute (JMSEpr.JNDI_CONTEXT_FACTORY ,NamingContext.JBOSS_INITIAL_CONTEXT_FACTORY);
- if (null==_config.getAttribute(JMSEpr.JNDI_CONTEXT_FACTORY))
- _logger.debug("No value specified for "+JMSEpr.JNDI_CONTEXT_FACTORY+" attribute"
+ _jndiContextFactory = obtainAttribute (JMSEpr.JNDI_CONTEXT_FACTORY_TAG ,NamingContext.JBOSS_INITIAL_CONTEXT_FACTORY);
+ if (null==_config.getAttribute(JMSEpr.JNDI_CONTEXT_FACTORY_TAG))
+ _logger.debug("No value specified for "+JMSEpr.JNDI_CONTEXT_FACTORY_TAG+" attribute"
+" - Using default of: '"+_jndiContextFactory+"'");
_jndiPkgPrefix = obtainAttribute (JMSEpr.JNDI_PKG_PREFIX_TAG ,NamingContext.JBOSS_URL_PKG_PREFIX);
if (null==_config.getAttribute(JMSEpr.JNDI_PKG_PREFIX_TAG))
Modified: labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerFTPIntegrationTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerFTPIntegrationTest.java 2007-01-08 14:45:14 UTC (rev 8761)
+++ labs/jbossesb/trunk/product/core/listeners/tests/src/org/jboss/soa/esb/listeners/ListenerManagerFTPIntegrationTest.java 2007-01-08 15:24:39 UTC (rev 8762)
@@ -48,7 +48,7 @@
protected void oneTest () throws Exception
{
- // Write wome messages to EPR obtained from configuration file
+ // Write some messages to EPR obtained from configuration file
String configFile = getClass().getResource(_file).getFile();
ConfigTree tree = ConfigTree.fromInputStream(new FileInputStream(
configFile));
@@ -96,12 +96,7 @@
_returnFile.delete();
// launch listener manager in a child thread
- final ConfigTree newTree = ConfigTree.fromInputStream(new FileInputStream(
- configFile));
- final ConfigTree newTreeEPRElement = newTree.getAllChildren()[0].getFirstChild("EPR");
- newTreeEPRElement.setAttribute(ListenerTagNames.URL_TAG, url) ;
-
- _manager = ListenerUtil.launchManager(newTree, true);
+ _manager = ListenerUtil.launchManager(tree, true);
_logger.debug("Waiting for all child listeners to start");
_manager.waitUntilReady();
_logger.debug(" All child listeners ready");
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/helpers/CallHelper.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/helpers/CallHelper.java 2007-01-08 14:45:14 UTC (rev 8761)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/helpers/CallHelper.java 2007-01-08 15:24:39 UTC (rev 8762)
@@ -45,21 +45,21 @@
if (call.getTo() != null)
{
Element toElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.TO_TAG);
- PortReferenceHelper.toXML(header, doc, toElement, call.getTo().getAddr(), true);
+ EPRHelper.toXML(call.getTo(), doc, header, toElement, true);
header.appendChild(toElement);
}
if (call.getFrom() != null)
{
Element fromElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.FROM_TAG);
- PortReferenceHelper.toXML(header, doc, fromElement, call.getFrom().getAddr(), false);
+ EPRHelper.toXML(call.getTo(), doc, header, fromElement, false);
header.appendChild(fromElement);
}
if (call.getReplyTo() != null)
{
Element replyToElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.REPLY_TO_TAG);
- PortReferenceHelper.toXML(header, doc, replyToElement, call.getReplyTo().getAddr(), false);
+ EPRHelper.toXML(call.getTo(), doc, header, replyToElement, false);
header.appendChild(replyToElement);
}
@@ -73,7 +73,7 @@
if (call.getFaultTo() != null)
{
Element faultToElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.FAULT_TO_TAG);
- PortReferenceHelper.toXML(header, doc, faultToElement, call.getFaultTo().getAddr(), false);
+ EPRHelper.toXML(call.getTo(), doc, header, faultToElement, false);
header.appendChild(faultToElement);
}
@@ -124,7 +124,7 @@
{
try
{
- call.setTo(new EPR(PortReferenceHelper.fromXML((Element) n, true)));
+ call.setTo(EPRHelper.fromXML((Element) header, true));
}
catch (Exception ex)
{
@@ -136,7 +136,7 @@
{
try
{
- call.setFrom(new EPR(PortReferenceHelper.fromXML((Element) n, false)));
+ call.setFrom(EPRHelper.fromXML((Element) n, false));
}
catch (Exception ex)
{
@@ -148,7 +148,7 @@
{
try
{
- call.setReplyTo(new EPR(PortReferenceHelper.fromXML((Element) n, false)));
+ call.setReplyTo(EPRHelper.fromXML((Element) n, false));
}
catch (Exception ex)
{
@@ -172,7 +172,7 @@
{
try
{
- call.setFaultTo(new EPR(PortReferenceHelper.fromXML((Element) n, false)));
+ call.setFaultTo(EPRHelper.fromXML((Element) n, false));
}
catch (Exception ex)
{
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/helpers/EPRHelper.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/helpers/EPRHelper.java 2007-01-08 14:45:14 UTC (rev 8761)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/internal/soa/esb/addressing/helpers/EPRHelper.java 2007-01-08 15:24:39 UTC (rev 8762)
@@ -33,6 +33,7 @@
import org.jboss.soa.esb.MarshalException;
import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.XMLUtil;
import org.jboss.soa.esb.addressing.eprs.EmailEpr;
import org.jboss.soa.esb.addressing.eprs.FTPEpr;
import org.jboss.soa.esb.addressing.eprs.FileEpr;
@@ -42,6 +43,8 @@
import org.jboss.soa.esb.addressing.eprs.SFTPEpr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import com.sun.org.apache.xml.internal.serialize.OutputFormat;
@@ -49,238 +52,402 @@
public class EPRHelper
{
- public static final String ELEMENT_NAME = "epr";
- public static final String EPR_TYPE = "type";
+ public static final String EPR_TYPE = "type";
- /**
- * Serialize the EPR to an XML representation.
- *
- * @param epr
- * @param doc
- * @param header
- * @return
- */
-
- public static final Element toXML (EPR epr, Document doc, Element header)
- {
- if (epr == null)
- throw new InvalidParameterException();
+ /**
+ * Serialize the EPR to an XML representation.
+ *
+ * @param epr
+ * @param doc
+ * @param header
+ * @return
+ */
- try
+ public static final Element toXML (EPR epr, Document doc, Element header, Element packElement)
{
- PortReferenceHelper.toXML(null, doc, header, epr.getAddr(), false);
-
- return header;
+ return toXML(epr, doc, header, packElement, false);
}
- catch (URISyntaxException ex)
- {
- ex.printStackTrace();
+
+ /**
+ * Serialize the EPR to an XML representation. Specify
+ * whether this is a To node in the Call.
+ *
+ * @param epr
+ * @param doc
+ * @param header
+ * @return
+ */
- return null;
- }
- catch (MarshalException ex)
+ public static final Element toXML (EPR epr, Document doc, Element header, Element packElement, boolean to)
{
- ex.printStackTrace();
+ if (epr == null)
+ throw new InvalidParameterException();
- return null;
+ try
+ {
+ // TODO
+ // The EPR type really should be doing this itself.
+
+ setSpecificEPR(epr);
+
+ PortReferenceHelper.toXML(header, doc, packElement, epr.getAddr(), to);
+
+ return header;
+ }
+ catch (URISyntaxException ex)
+ {
+ ex.printStackTrace();
+
+ return null;
+ }
+ catch (MarshalException ex)
+ {
+ ex.printStackTrace();
+
+ return null;
+ }
}
- }
- /**
- * Deserialize the EPR from an XML representation.
- *
- * @param header
- * @return
- */
-
- public static final EPR fromXML (Element header)
- {
- if (header == null)
- throw new InvalidParameterException();
+ /**
+ * Deserialize the EPR from an XML representation.
+ *
+ * @param header
+ * @return
+ */
- try
+ public static final EPR fromXML(Element header)
{
- if (header.getNodeName().equals(ELEMENT_NAME))
- return getSpecificEPR(new EPR(PortReferenceHelper.fromXML(header, false)), header);
- else
- return new EPR(PortReferenceHelper.fromXML(header, false));
+ return fromXML(header, false);
}
- catch (MarshalException ex)
+
+ /**
+ * Deserialize the EPR from an XML representation. Specify
+ * whether this is a To node in the Call.
+ *
+ * @param header
+ * @return
+ */
+
+ public static final EPR fromXML(Element header, boolean to)
{
- ex.printStackTrace();
+ if (header == null)
+ throw new InvalidParameterException();
- return null;
+ try
+ {
+ NodeList children = header.getChildNodes();
+
+ for (int i = 0; i < children.getLength(); i++)
+ {
+ Node n = children.item(i);
+
+ if (n instanceof Element)
+ {
+ Element el = (Element) n;
+
+ if (el.getNodeName().equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.TO_TAG))
+ return getSpecificEPR(new EPR(PortReferenceHelper.fromXML(el, true)), header);
+ else
+ {
+ if (el.getNodeName().contains(XMLUtil.WSA_PREFIX+":"))
+ return getSpecificEPR(new EPR(PortReferenceHelper.fromXML(el, false)));
+ }
+ }
+ }
+
+ return getSpecificEPR(new EPR(PortReferenceHelper.fromXML(header, to)));
+ }
+ catch (MarshalException ex)
+ {
+ ex.printStackTrace();
+
+ return null;
+ }
}
- }
- /**
- * Create a string version of the XML representation for this EPR.
- * If the EPR is a specific type (e.g., JMSEpr) then that type information
- * will also be encoded.
- *
- * @param epr
- * @return
- */
-
- public static final String toXMLString (EPR epr)
- {
- if (epr == null)
- throw new InvalidParameterException();
+ /**
+ * Create a string version of the XML representation for this EPR. If the
+ * EPR is a specific type (e.g., JMSEpr) then that type information will
+ * also be encoded.
+ *
+ * @param epr
+ * @return
+ */
- try
+ public static final String toXMLString(EPR epr)
{
- DocumentBuilderFactory factory = DocumentBuilderFactory
- .newInstance();
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document doc = builder.newDocument();
- Element portReferenceElement = doc.createElement(ELEMENT_NAME);
+ return toXMLString(epr, false, XMLUtil.FROM_TAG);
+ }
+
+ /**
+ * Create a string version of the XML representation for this EPR. If the
+ * EPR is a specific type (e.g., JMSEpr) then that type information will
+ * also be encoded. Specify whether this is a To node in the Call.
+ *
+ * @param epr
+ * @return
+ */
- setSpecificEPR(epr, portReferenceElement);
-
- doc.appendChild(portReferenceElement);
+ public static final String toXMLString(EPR epr, boolean to, String tag)
+ {
+ if (epr == null)
+ throw new InvalidParameterException();
- toXML(epr, doc, portReferenceElement);
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.newDocument();
+ Element header = doc.createElement("header");
+ Element portReferenceElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+tag);
+
+ setSpecificEPR(epr);
- StringWriter sWriter = new StringWriter();
- OutputFormat format = new OutputFormat();
- format.setIndenting(true);
+ doc.appendChild(header);
- XMLSerializer xmlS = new XMLSerializer(sWriter, format);
+ toXML(epr, doc, header, portReferenceElement, to);
+
+ header.appendChild(portReferenceElement);
+
+ StringWriter sWriter = new StringWriter();
+ OutputFormat format = new OutputFormat();
+ format.setIndenting(true);
- xmlS.asDOMSerializer();
- xmlS.serialize(doc);
+ XMLSerializer xmlS = new XMLSerializer(sWriter, format);
- return sWriter.toString();
- }
- catch (IOException ex)
- {
- ex.printStackTrace();
+ xmlS.asDOMSerializer();
+ xmlS.serialize(doc);
- return null;
- }
- catch (ParserConfigurationException ex)
- {
- ex.printStackTrace();
+ return sWriter.toString();
+ }
+ catch (IOException ex)
+ {
+ ex.printStackTrace();
- return null;
+ return null;
+ }
+ catch (ParserConfigurationException ex)
+ {
+ ex.printStackTrace();
+
+ return null;
+ }
}
- }
- /**
- * Get the EPR from the string representation. If the EPR was a specific
- * type (e.g., JMSEpr) then it will be returned as an instance of the appropriate
- * class.
- *
- * @param xml
- * @return
- */
-
- public static final EPR fromXMLString (String xml)
- {
- if (xml == null)
- throw new InvalidParameterException();
+ /**
+ * Get the EPR from the string representation. If the EPR was a specific
+ * type (e.g., JMSEpr) then it will be returned as an instance of the
+ * appropriate class.
+ *
+ * @param xml
+ * @return
+ */
- try
+ public static final EPR fromXMLString(String xml)
{
- DocumentBuilderFactory factory = DocumentBuilderFactory
- .newInstance();
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document doc = builder.parse(new ByteArrayInputStream(xml
- .getBytes()));
- Element rootElement = doc.getDocumentElement();
-
- return getSpecificEPR(new EPR(PortReferenceHelper.fromXML(rootElement, false)), rootElement);
+ return fromXMLString(xml, false);
}
- catch (MarshalException ex)
+
+ /**
+ * Get the EPR from the string representation. If the EPR was a specific
+ * type (e.g., JMSEpr) then it will be returned as an instance of the
+ * appropriate class. Specify whether this is a To node in the Call.
+ *
+ * @param xml
+ * @return
+ */
+
+ public static final EPR fromXMLString (String xml, boolean to)
{
- ex.printStackTrace();
+ if (xml == null)
+ throw new InvalidParameterException();
- return null;
- }
- catch (SAXException ex)
- {
- ex.printStackTrace();
+ try
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.parse(new ByteArrayInputStream(xml.getBytes()));
+ Element rootElement = (Element) doc.getDocumentElement();
- return null;
- }
- catch (IOException ex)
- {
- ex.printStackTrace();
+ NodeList children = rootElement.getChildNodes();
- return null;
- }
- catch (ParserConfigurationException ex)
- {
- ex.printStackTrace();
+ for (int i = 0; i < children.getLength(); i++)
+ {
+ Node n = children.item(i);
+
+ if (n instanceof Element)
+ {
+ Element el = (Element) n;
+
+ if (el.getNodeName().equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.TO_TAG))
+ return getSpecificEPR(new EPR(PortReferenceHelper.fromXML(el, true)), rootElement);
+ else
+ return getSpecificEPR(new EPR(PortReferenceHelper.fromXML(el, false)));
+ }
+ }
+
+ return getSpecificEPR(new EPR(PortReferenceHelper.fromXML(rootElement, to)));
+ }
+ catch (MarshalException ex)
+ {
+ ex.printStackTrace();
- return null;
+ return null;
+ }
+ catch (SAXException ex)
+ {
+ ex.printStackTrace();
+
+ return null;
+ }
+ catch (IOException ex)
+ {
+ ex.printStackTrace();
+
+ return null;
+ }
+ catch (ParserConfigurationException ex)
+ {
+ ex.printStackTrace();
+
+ return null;
+ }
}
- }
- private final static void setSpecificEPR (EPR epr, Element header)
- {
- try
+ private final static void setSpecificEPR(EPR epr)
{
- String eprType = null;
+ try
+ {
+ String eprType = null;
- if (epr instanceof EmailEpr)
- eprType = EmailEpr.type().toString();
- else if (epr instanceof FTPEpr)
- eprType = FTPEpr.type().toString();
- else if (epr instanceof HTTPEpr)
- eprType = HTTPEpr.type().toString();
- else if (epr instanceof JDBCEpr)
- eprType = JDBCEpr.type().toString();
- else if (epr instanceof JMSEpr)
- eprType = JMSEpr.type().toString();
- else if (epr instanceof FileEpr)
- eprType = FileEpr.type().toString();
- else if (epr instanceof SFTPEpr)
- eprType = SFTPEpr.type().toString();
-
- if (eprType != null)
- header.setAttribute(EPR_TYPE, eprType);
+ /*
+ * Do not re-order.
+ */
+
+ if (epr instanceof EmailEpr)
+ eprType = EmailEpr.type().toString();
+ else if (epr instanceof SFTPEpr)
+ eprType = SFTPEpr.type().toString();
+ else if (epr instanceof HTTPEpr)
+ eprType = HTTPEpr.type().toString();
+ else if (epr instanceof JDBCEpr)
+ eprType = JDBCEpr.type().toString();
+ else if (epr instanceof JMSEpr)
+ eprType = JMSEpr.type().toString();
+ else if (epr instanceof FTPEpr)
+ eprType = FTPEpr.type().toString();
+ else if (epr instanceof FileEpr)
+ eprType = FileEpr.type().toString();
+
+ if (eprType != null)
+ {
+ if (epr.getAddr().getExtensionValue(EPR_TYPE) == null)
+ epr.getAddr().addExtension(EPR_TYPE, eprType);
+ }
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
}
- catch (Exception ex)
+
+ private final static EPR getSpecificEPR (EPR epr)
{
- ex.printStackTrace();
- }
- }
+ try
+ {
+ String eprType = epr.getAddr().getExtensionValue(EPR_TYPE);
+
+ if (eprType != null)
+ {
+ /*
+ * Do not re-order.
+ */
+
+ if (eprType.equals(EmailEpr.type().toString()))
+ return new EmailEpr(epr);
+ else if (eprType.equals(SFTPEpr.type().toString()))
+ return new SFTPEpr(epr);
+ else if (eprType.equals(HTTPEpr.type().toString()))
+ return new HTTPEpr(epr);
+ else if (eprType.equals(JDBCEpr.type().toString()))
+ return new JDBCEpr(epr);
+ else if (eprType.equals(JMSEpr.type().toString()))
+ return new JMSEpr(epr);
+ else if (eprType.equals(FTPEpr.type().toString()))
+ return new FTPEpr(epr);
+ else if (eprType.equals(FileEpr.type().toString()))
+ return new FileEpr(epr);
+ else
+ return epr;
+ }
+ else
+ return epr;
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
- private final static EPR getSpecificEPR (EPR epr, Element header)
- {
- try
- {
- String eprType = header.getAttribute(EPR_TYPE);
-
- if (eprType != null)
- {
- if (eprType.equals(EmailEpr.type().toString()))
- return new EmailEpr(epr);
- else if (eprType.equals(FTPEpr.type().toString()))
- return new FTPEpr(epr);
- else if (eprType.equals(HTTPEpr.type().toString()))
- return new HTTPEpr(epr);
- else if (eprType.equals(JDBCEpr.type().toString()))
- return new JDBCEpr(epr);
- else if (eprType.equals(JMSEpr.type().toString()))
- return new JMSEpr(epr);
- else if (eprType.equals(FileEpr.type().toString()))
- return new FileEpr(epr);
- else if (eprType.equals(SFTPEpr.type().toString()))
- return new SFTPEpr(epr);
- else
- return epr;
- }
- else
- return epr;
+ return epr;
+ }
}
- catch (Exception ex)
+
+ /**
+ * Because of WS-A rules, if this was a To node then all of the elements within
+ * the EPR are now at top-level in the header and not easily obtained. We need
+ * to ask each EPR type to reconstitute itself.
+ *
+ * @param epr
+ * @param header
+ * @return
+ */
+
+ private final static EPR getSpecificEPR (EPR epr, Element header)
{
- ex.printStackTrace();
+ try
+ {
+ NodeList children = header.getChildNodes();
+ String eprType = null;
+
+ for (int i = 0; i < children.getLength(); i++)
+ {
+ if (children.item(i).getNodeName().equals(XMLUtil.WSARJADDR_PREFIX+":"+EPR_TYPE))
+ eprType = children.item(i).getTextContent();
+ }
- return epr;
+ if (eprType != null)
+ {
+ /*
+ * Do not re-order.
+ */
+
+ if (eprType.equals(EmailEpr.type().toString()))
+ return new EmailEpr(epr, header);
+ else if (eprType.equals(SFTPEpr.type().toString()))
+ return new SFTPEpr(epr, header);
+ else if (eprType.equals(HTTPEpr.type().toString()))
+ return new HTTPEpr(epr, header);
+ else if (eprType.equals(JDBCEpr.type().toString()))
+ return new JDBCEpr(epr, header);
+ else if (eprType.equals(JMSEpr.type().toString()))
+ return new JMSEpr(epr, header);
+ else if (eprType.equals(FTPEpr.type().toString()))
+ return new FTPEpr(epr, header);
+ else if (eprType.equals(FileEpr.type().toString()))
+ return new FileEpr(epr, header);
+ else
+ return epr;
+ }
+ else
+ return epr;
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ return epr;
+ }
}
- }
}
\ No newline at end of file
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/EmailEpr.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/EmailEpr.java 2007-01-08 14:45:14 UTC (rev 8761)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/EmailEpr.java 2007-01-08 15:24:39 UTC (rev 8762)
@@ -32,6 +32,9 @@
import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.addressing.PortReference;
+import org.jboss.soa.esb.addressing.XMLUtil;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
/**
* A helper class for using email style EPRs. Simply create and use instances of
@@ -60,6 +63,35 @@
copy(epr);
}
+ public EmailEpr (EPR epr, Element header)
+ {
+ copy(epr);
+
+ NodeList nl = header.getChildNodes();
+
+ for (int i = 0; i < nl.getLength(); i++)
+ {
+ String nodeName = nl.item(i).getNodeName();
+
+ try
+ {
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+USERNAME_TAG))
+ {
+ getAddr().addExtension(USERNAME_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+PASSWORD_TAG))
+ {
+ getAddr().addExtension(PASSWORD_TAG, nl.item(i).getTextContent());
+ }
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+
/**
* Create a new email EPR. The port number will be assumed to be 25,
* and there are no values for username and password.
@@ -124,7 +156,7 @@
*/
public final String getHost () throws URISyntaxException
- {
+ {
URI addr = new URI(getAddr().getAddress());
return addr.getHost();
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/FTPEpr.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/FTPEpr.java 2007-01-08 14:45:14 UTC (rev 8761)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/FTPEpr.java 2007-01-08 15:24:39 UTC (rev 8762)
@@ -33,6 +33,9 @@
import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.addressing.PortReference;
+import org.jboss.soa.esb.addressing.XMLUtil;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
/**
* A helper class for using FTP style EPRs. Simply create instances of this
@@ -55,6 +58,42 @@
copy(epr);
}
+ public FTPEpr (EPR epr, Element header)
+ {
+ super(epr, header);
+
+ copy(epr);
+
+ NodeList nl = header.getChildNodes();
+
+ for (int i = 0; i < nl.getLength(); i++)
+ {
+ String nodeName = nl.item(i).getNodeName();
+
+ try
+ {
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+USERNAME_TAG))
+ {
+ getAddr().addExtension(USERNAME_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+PASSWORD_TAG))
+ {
+ getAddr().addExtension(PASSWORD_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+PASSIVE_TAG))
+ {
+ getAddr().addExtension(PASSIVE_TAG, nl.item(i).getTextContent());
+ }
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+
public FTPEpr (URL url) throws URISyntaxException
{
super(new URI(url.toString()));
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/FileEpr.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/FileEpr.java 2007-01-08 14:45:14 UTC (rev 8761)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/FileEpr.java 2007-01-08 15:24:39 UTC (rev 8762)
@@ -33,6 +33,9 @@
import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.addressing.PortReference;
+import org.jboss.soa.esb.addressing.XMLUtil;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
/**
* A helper class for using file based EPRs. Simply create instances of this
@@ -52,13 +55,67 @@
public static final String ERROR_DIR_TAG = "errorDir";
public static final String ERROR_SUFFIX_TAG = "errorSuffix";
public static final String ERROR_DEL_TAG = "errorDelete";
- public static final String URL_TAG = "URL";
+ public static final String URL_TAG = "URL";
public FileEpr (EPR epr)
{
copy(epr);
}
+ public FileEpr (EPR epr, Element header)
+ {
+ copy(epr);
+
+ NodeList nl = header.getChildNodes();
+
+ for (int i = 0; i < nl.getLength(); i++)
+ {
+ String nodeName = nl.item(i).getNodeName();
+
+ try
+ {
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+INPUT_SUFFIX_TAG))
+ {
+ getAddr().addExtension(INPUT_SUFFIX_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+POST_DIR_TAG))
+ {
+ getAddr().addExtension(POST_DIR_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+POST_SUFFIX_TAG))
+ {
+ getAddr().addExtension(POST_SUFFIX_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+POST_DEL_TAG))
+ {
+ getAddr().addExtension(POST_DEL_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+ERROR_DIR_TAG))
+ {
+ getAddr().addExtension(ERROR_DIR_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+ERROR_SUFFIX_TAG))
+ {
+ getAddr().addExtension(ERROR_SUFFIX_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+ERROR_DEL_TAG))
+ {
+ getAddr().addExtension(ERROR_DEL_TAG, nl.item(i).getTextContent());
+ }
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+
public FileEpr (URL url) throws URISyntaxException
{
super(new URI(url.toString()));
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/HTTPEpr.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/HTTPEpr.java 2007-01-08 14:45:14 UTC (rev 8761)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/HTTPEpr.java 2007-01-08 15:24:39 UTC (rev 8762)
@@ -33,6 +33,7 @@
import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.addressing.PortReference;
+import org.w3c.dom.Element;
/**
* A helper class for using HTTP style EPRs. Simply create instances of this
@@ -49,6 +50,11 @@
copy(epr);
}
+ public HTTPEpr (EPR epr, Element header)
+ {
+ copy(epr);
+ }
+
public HTTPEpr (URL url) throws URISyntaxException
{
super(new URI(url.toString()));
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/JDBCEpr.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/JDBCEpr.java 2007-01-08 14:45:14 UTC (rev 8761)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/JDBCEpr.java 2007-01-08 15:24:39 UTC (rev 8762)
@@ -31,6 +31,9 @@
import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.addressing.PortReference;
+import org.jboss.soa.esb.addressing.XMLUtil;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
/**
* A helper class for using database style EPRs. Simply create instances of this
@@ -55,14 +58,93 @@
public static final String STATUS_COLUMN_TAG = "status_column";
public static final String DATA_COLUMN_TAG = "message_column";
public static final String TIMESTAMP_COLUMN_TAG = "insert_timestamp_column";
- public static final String POST_DEL_TAG = FileEpr.POST_DEL_TAG;
- public static final String ERROR_DEL_TAG = FileEpr.ERROR_DEL_TAG;
+ public static final String POST_DEL_TAG = "postDelete";
+ public static final String ERROR_DEL_TAG = "errorDelete";
public JDBCEpr (EPR epr)
{
copy(epr);
}
+ public JDBCEpr (EPR epr, Element header)
+ {
+ copy(epr);
+
+ NodeList nl = header.getChildNodes();
+
+ for (int i = 0; i < nl.getLength(); i++)
+ {
+ String nodeName = nl.item(i).getNodeName();
+
+ try
+ {
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+USERNAME_TAG))
+ {
+ getAddr().addExtension(USERNAME_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+PASSWORD_TAG))
+ {
+ getAddr().addExtension(PASSWORD_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+SQL_TAG))
+ {
+ getAddr().addExtension(SQL_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+DRIVER_TAG))
+ {
+ getAddr().addExtension(DRIVER_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+URL_TAG))
+ {
+ getAddr().addExtension(URL_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+TABLE_NAME_TAG))
+ {
+ getAddr().addExtension(TABLE_NAME_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+MESSAGE_ID_COLUMN_TAG))
+ {
+ getAddr().addExtension(MESSAGE_ID_COLUMN_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+STATUS_COLUMN_TAG))
+ {
+ getAddr().addExtension(STATUS_COLUMN_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+DATA_COLUMN_TAG))
+ {
+ getAddr().addExtension(DATA_COLUMN_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+TIMESTAMP_COLUMN_TAG))
+ {
+ getAddr().addExtension(TIMESTAMP_COLUMN_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+POST_DEL_TAG))
+ {
+ getAddr().addExtension(POST_DEL_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+ERROR_DEL_TAG))
+ {
+ getAddr().addExtension(ERROR_DEL_TAG, nl.item(i).getTextContent());
+ }
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+
public JDBCEpr (String url, String sql) throws URISyntaxException
{
super(new URI(url));
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/JMSEpr.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/JMSEpr.java 2007-01-08 14:45:14 UTC (rev 8761)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/JMSEpr.java 2007-01-08 15:24:39 UTC (rev 8762)
@@ -30,7 +30,10 @@
import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.addressing.PortReference;
+import org.jboss.soa.esb.addressing.XMLUtil;
import org.jboss.soa.esb.helpers.NamingContext;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
/**
* A helper class for using JMS style EPRs. Simply create and use instances of
@@ -62,7 +65,7 @@
public static final String JNDI_URL_TAG = "jndi-URL";
- public static final String JNDI_CONTEXT_FACTORY = "jndi-context-factory";
+ public static final String JNDI_CONTEXT_FACTORY_TAG = "jndi-context-factory";
public static final String MESSAGE_SELECTOR_TAG = "message-selector";
@@ -74,7 +77,61 @@
{
copy(epr);
}
+
+ public JMSEpr(EPR epr, Element header)
+ {
+ copy(epr);
+
+ NodeList nl = header.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++)
+ {
+ String nodeName = nl.item(i).getNodeName();
+
+ try
+ {
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+SPECIFICATION_VERSION_TAG))
+ {
+ getAddr().addExtension(SPECIFICATION_VERSION_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+DESTINATION_NAME_TAG))
+ {
+ getAddr().addExtension(DESTINATION_NAME_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+CONNECTION_FACTORY_TAG))
+ {
+ getAddr().addExtension(CONNECTION_FACTORY_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+JNDI_CONTEXT_FACTORY_TAG))
+ {
+ getAddr().addExtension(JNDI_CONTEXT_FACTORY_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+JNDI_PKG_PREFIX_TAG))
+ {
+ getAddr().addExtension(JNDI_PKG_PREFIX_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+JNDI_URL_TAG))
+ {
+ getAddr().addExtension(JNDI_URL_TAG, nl.item(i).getTextContent());
+ }
+ else
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+MESSAGE_SELECTOR_TAG))
+ {
+ getAddr().addExtension(MESSAGE_SELECTOR_TAG, nl.item(i).getTextContent());
+ }
+ }
+ catch (URISyntaxException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+
/**
* Create a new JMS EPR. The protocol version is assumed to be 1.1. ,
* jndi_type=jboss, jndi_url=localhost, messageSelector=null
@@ -170,7 +227,7 @@
addr.addExtension(CONNECTION_FACTORY_TAG, connection);
if (jndiContextFactory != null)
- addr.addExtension(JNDI_CONTEXT_FACTORY, jndiContextFactory);
+ addr.addExtension(JNDI_CONTEXT_FACTORY_TAG, jndiContextFactory);
if (jndiPkgPrefix != null)
addr.addExtension(JNDI_PKG_PREFIX_TAG, jndiPkgPrefix);
@@ -184,7 +241,7 @@
setAddr(addr);
}
else
- throw new IllegalArgumentException("Invalid destination type!");
+ throw new IllegalArgumentException("Invalid destination type! "+destinationType);
}
else
throw new IllegalArgumentException("Invalid specification version!");
@@ -250,7 +307,7 @@
public final String getJndiContextFactory() throws URISyntaxException
{
- return getAddr().getExtensionValue(JNDI_CONTEXT_FACTORY);
+ return getAddr().getExtensionValue(JNDI_CONTEXT_FACTORY_TAG);
}
/**
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/SFTPEpr.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/SFTPEpr.java 2007-01-08 14:45:14 UTC (rev 8761)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/addressing/eprs/SFTPEpr.java 2007-01-08 15:24:39 UTC (rev 8762)
@@ -31,6 +31,9 @@
import java.net.URL;
import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.XMLUtil;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
/**
* A helper class for using FTP style EPRs. Simply create instances of this
@@ -50,7 +53,33 @@
copy(epr);
}
+
+ public SFTPEpr (EPR epr, Element header)
+ {
+ super(epr, header);
+
+ copy(epr);
+
+ NodeList nl = header.getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++)
+ {
+ String nodeName = nl.item(i).getNodeName();
+
+ try
+ {
+ if (nodeName.equals(XMLUtil.WSARJADDR_PREFIX+":"+CERTIFICATE_TAG))
+ {
+ getAddr().addExtension(CERTIFICATE_TAG, nl.item(i).getTextContent());
+ }
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+
public SFTPEpr(URL url) throws URISyntaxException
{
super(url);
@@ -59,11 +88,15 @@
public SFTPEpr(URL url, URL cert) throws URISyntaxException
{
super(url);
+
+ setCertificateURL(cert);
}
- public SFTPEpr(String url, String cert) throws URISyntaxException
+ public SFTPEpr(String url, String cert) throws URISyntaxException, MalformedURLException
{
- super(url);
+ super(url);
+
+ setCertificateURL(new URL(cert));
}
/**
Modified: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/tests/CourierUtilUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/tests/CourierUtilUnitTest.java 2007-01-08 14:45:14 UTC (rev 8761)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/internal/soa/esb/couriers/tests/CourierUtilUnitTest.java 2007-01-08 15:24:39 UTC (rev 8762)
@@ -74,6 +74,8 @@
msg1.getHeader().getCall().setTo(new HTTPEpr("http://foo.bar"));
msg1.getHeader().getCall().setMessageID(new URI("urn:1234"));
+ Assert.assertEquals(msg1.getHeader().getCall().getTo().getAddr().toString(), "PortReference < http://foo.bar >");
+
File theFile = new File(".");
File tmpFile = CourierUtil.messageToLocalFile(theFile, msg1);
@@ -85,8 +87,8 @@
Assert.assertNotNull(msg2);
Assert.assertEquals(msg2.getBody().get("foo"), "bar");
- Assert.assertEquals(msg2.getHeader().getCall().getTo().toString(), "EPR: PortReference < http://foo.bar >");
Assert.assertEquals(msg2.getHeader().getCall().getMessageID().toString(), "urn:1234");
+ Assert.assertEquals(msg2.getHeader().getCall().getTo().getAddr().toString(), "PortReference < http://foo.bar >");
}
}
Modified: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/tests/EPRUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/tests/EPRUnitTest.java 2007-01-08 14:45:14 UTC (rev 8761)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/tests/EPRUnitTest.java 2007-01-08 15:24:39 UTC (rev 8762)
@@ -22,13 +22,25 @@
package org.jboss.soa.esb.addressing.tests;
+import java.io.StringWriter;
import java.net.URI;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
import junit.framework.TestCase;
+import org.jboss.internal.soa.esb.addressing.helpers.PortReferenceHelper;
import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.addressing.PortReference;
+import org.jboss.soa.esb.addressing.XMLUtil;
+import org.jboss.soa.esb.addressing.eprs.EmailEpr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import com.sun.org.apache.xml.internal.serialize.OutputFormat;
+import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
+
/**
* Unit tests for the EPR class.
*
@@ -96,6 +108,47 @@
}
}
+ public void testToFromXML ()
+ {
+ try
+ {
+ EmailEpr email = new EmailEpr(EmailEpr.SMTP_PROTOCOL, "foobar", "25", "me", "letmein");
+
+ final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ final DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.newDocument();
+ Element header = doc.createElement("header");
+ Element fromElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.FROM_TAG);
+
+ doc.appendChild(header);
+ header.appendChild(fromElement);
+
+ PortReferenceHelper.toXML(header, doc, fromElement, email.getAddr(), false);
+
+ final StringWriter sWriter = new StringWriter() ;
+ final OutputFormat format = new OutputFormat() ;
+ format.setIndenting(true) ;
+
+ final XMLSerializer xmlS = new XMLSerializer(sWriter, format) ;
+
+ xmlS.asDOMSerializer() ;
+ xmlS.serialize(doc) ;
+
+ System.err.println("Exported XML: "+sWriter.toString());
+
+ PortReference pr = PortReferenceHelper.fromXML(fromElement, false);
+
+ EPR basicEpr = new EPR(pr);
+ EmailEpr nEpr = new EmailEpr(basicEpr);
+
+ assertEquals(nEpr.getAddr().getAddress(), email.getAddr().getAddress());
+ }
+ catch (Exception ex)
+ {
+ fail();
+ }
+ }
+
public void testEquals ()
{
try
Modified: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/tests/EPRHelperUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/tests/EPRHelperUnitTest.java 2007-01-08 14:45:14 UTC (rev 8761)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/tests/EPRHelperUnitTest.java 2007-01-08 15:24:39 UTC (rev 8762)
@@ -43,7 +43,7 @@
String xmlString = EPRHelper.toXMLString(email);
- System.err.println(xmlString);
+ System.err.println("xmlString is: "+xmlString);
EPR epr = EPRHelper.fromXMLString(xmlString);
Modified: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/tests/EPRManagerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/tests/EPRManagerUnitTest.java 2007-01-08 14:45:14 UTC (rev 8761)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/addressing/util/tests/EPRManagerUnitTest.java 2007-01-08 15:24:39 UTC (rev 8762)
@@ -22,12 +22,25 @@
package org.jboss.soa.esb.addressing.util.tests;
+import java.io.StringWriter;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
import junit.framework.TestCase;
+import org.jboss.internal.soa.esb.addressing.helpers.PortReferenceHelper;
import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.PortReference;
+import org.jboss.soa.esb.addressing.XMLUtil;
import org.jboss.soa.esb.addressing.eprs.EmailEpr;
import org.jboss.soa.esb.addressing.util.EPRManager;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import com.sun.org.apache.xml.internal.serialize.OutputFormat;
+import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
+
/**
* Unit tests for the Class class.
*
@@ -36,7 +49,6 @@
public class EPRManagerUnitTest extends TestCase
{
-
public void testCreate ()
{
EPRManager manager1 = EPRManager.getInstance(null);
Modified: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/BaseTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/BaseTest.java 2007-01-08 14:45:14 UTC (rev 8761)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/common/tests/BaseTest.java 2007-01-08 15:24:39 UTC (rev 8762)
@@ -122,7 +122,7 @@
.getProperty(FTP_DIR, "/pub/DNS");
String ftpPwd = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CONNECTION_MODULE)
.getProperty(FTP_PWD, "");
-
+
// Setting the paremeters in the HashMap
HashMap<String, String> systemParameters = new HashMap<String, String>();
systemParameters.put(DB_DRIVER, dbDriver);
Modified: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/MessageUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/MessageUnitTest.java 2007-01-08 14:45:14 UTC (rev 8761)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/MessageUnitTest.java 2007-01-08 15:24:39 UTC (rev 8762)
@@ -24,6 +24,7 @@
import junit.framework.TestCase;
+import org.jboss.soa.esb.addressing.eprs.JMSEpr;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageFactory;
import org.jboss.soa.esb.message.format.MessageType;
Modified: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/SerializedMessageUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/SerializedMessageUnitTest.java 2007-01-08 14:45:14 UTC (rev 8761)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/SerializedMessageUnitTest.java 2007-01-08 15:24:39 UTC (rev 8762)
@@ -26,11 +26,20 @@
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.net.URL;
import junit.framework.TestCase;
import org.jboss.internal.soa.esb.message.format.serialized.MessageImpl;
import org.jboss.soa.esb.addressing.Call;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.eprs.EmailEpr;
+import org.jboss.soa.esb.addressing.eprs.FTPEpr;
+import org.jboss.soa.esb.addressing.eprs.FileEpr;
+import org.jboss.soa.esb.addressing.eprs.HTTPEpr;
+import org.jboss.soa.esb.addressing.eprs.JDBCEpr;
+import org.jboss.soa.esb.addressing.eprs.JMSEpr;
+import org.jboss.soa.esb.addressing.eprs.SFTPEpr;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageFactory;
import org.jboss.soa.esb.message.format.MessageType;
@@ -333,4 +342,268 @@
}
}
+ public void testJmsEPRType ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ JMSEpr epr = new JMSEpr(JMSEpr.TOPIC_TYPE, "foo", "bar");
+
+ msg.getHeader().getCall().setTo(epr);
+
+ try
+ {
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(s);
+
+ o.writeObject(msg);
+ o.close();
+
+ ByteArrayInputStream is = new ByteArrayInputStream(s.toByteArray());
+ ObjectInputStream io = new ObjectInputStream(is);
+
+ MessageImpl nImpl = (MessageImpl) io.readObject();
+
+ o.close();
+
+ EPR theEpr = nImpl.getHeader().getCall().getTo();
+
+ assertEquals(theEpr instanceof JMSEpr, true);
+
+ assertEquals(((JMSEpr) theEpr).getConnectionFactory(), "bar");
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ fail(ex.toString());
+ }
+ }
+
+ public void testHttpEPRType ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+
+ try
+ {
+ HTTPEpr epr = new HTTPEpr("http://www.foo.bar");
+
+ msg.getHeader().getCall().setTo(epr);
+
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(s);
+
+ o.writeObject(msg);
+ o.close();
+
+ ByteArrayInputStream is = new ByteArrayInputStream(s.toByteArray());
+ ObjectInputStream io = new ObjectInputStream(is);
+
+ MessageImpl nImpl = (MessageImpl) io.readObject();
+
+ o.close();
+
+ EPR theEpr = nImpl.getHeader().getCall().getTo();
+
+ assertEquals(theEpr instanceof HTTPEpr, true);
+
+ assertEquals(((HTTPEpr) theEpr).getURL().toString(), "http://www.foo.bar");
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ fail(ex.toString());
+ }
+ }
+
+ public void testEmailEPRType ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+
+ try
+ {
+ EmailEpr epr = new EmailEpr(EmailEpr.SMTP_PROTOCOL, "foo.bar", "25", "me", "password");
+
+ msg.getHeader().getCall().setTo(epr);
+
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(s);
+
+ o.writeObject(msg);
+ o.close();
+
+ ByteArrayInputStream is = new ByteArrayInputStream(s.toByteArray());
+ ObjectInputStream io = new ObjectInputStream(is);
+
+ MessageImpl nImpl = (MessageImpl) io.readObject();
+
+ o.close();
+
+ EPR theEpr = nImpl.getHeader().getCall().getTo();
+
+ assertEquals(theEpr instanceof EmailEpr, true);
+
+ assertEquals(((EmailEpr) theEpr).getPassword(), "password");
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ fail(ex.toString());
+ }
+ }
+
+ public void testFtpEPRType ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+
+ try
+ {
+ FTPEpr epr = new FTPEpr("http://www.foo.bar");
+
+ epr.setPassive(true);
+
+ msg.getHeader().getCall().setTo(epr);
+
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(s);
+
+ o.writeObject(msg);
+ o.close();
+
+ ByteArrayInputStream is = new ByteArrayInputStream(s.toByteArray());
+ ObjectInputStream io = new ObjectInputStream(is);
+
+ MessageImpl nImpl = (MessageImpl) io.readObject();
+
+ o.close();
+
+ EPR theEpr = nImpl.getHeader().getCall().getTo();
+
+ assertEquals(theEpr instanceof FTPEpr, true);
+
+ assertEquals(((FTPEpr) theEpr).getPassive(), true);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ fail(ex.toString());
+ }
+ }
+
+ public void testJdbcEPRType ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+
+ try
+ {
+ JDBCEpr epr = new JDBCEpr("http://www.foo.bar", "SOME FAKE SQL");
+
+ msg.getHeader().getCall().setTo(epr);
+
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(s);
+
+ o.writeObject(msg);
+ o.close();
+
+ ByteArrayInputStream is = new ByteArrayInputStream(s.toByteArray());
+ ObjectInputStream io = new ObjectInputStream(is);
+
+ MessageImpl nImpl = (MessageImpl) io.readObject();
+
+ o.close();
+
+ EPR theEpr = nImpl.getHeader().getCall().getTo();
+
+ assertEquals(theEpr instanceof JDBCEpr, true);
+
+ assertEquals(((JDBCEpr) theEpr).getSQL(), "SOME FAKE SQL");
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ fail(ex.toString());
+ }
+ }
+
+ public void testFileEPRType ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+
+ try
+ {
+ FileEpr epr = new FileEpr("file://tmp/bar.txt");
+
+ epr.setErrorDelete(true);
+
+ msg.getHeader().getCall().setTo(epr);
+
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(s);
+
+ o.writeObject(msg);
+ o.close();
+
+ ByteArrayInputStream is = new ByteArrayInputStream(s.toByteArray());
+ ObjectInputStream io = new ObjectInputStream(is);
+
+ MessageImpl nImpl = (MessageImpl) io.readObject();
+
+ o.close();
+
+ EPR theEpr = nImpl.getHeader().getCall().getTo();
+
+ assertEquals(theEpr instanceof FileEpr, true);
+
+ assertEquals(((FileEpr) theEpr).getErrorDelete(), true);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ fail(ex.toString());
+ }
+ }
+
+ public void testSFtpEPRType ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+
+ try
+ {
+ SFTPEpr epr = new SFTPEpr(new URL("http://www.foo.bar"), new URL("http://www.bar.foo"));
+
+ assertEquals(epr.getCertificateURL().toString(), "http://www.bar.foo");
+
+ msg.getHeader().getCall().setTo(epr);
+
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+ ObjectOutputStream o = new ObjectOutputStream(s);
+
+ o.writeObject(msg);
+ o.close();
+
+ ByteArrayInputStream is = new ByteArrayInputStream(s.toByteArray());
+ ObjectInputStream io = new ObjectInputStream(is);
+
+ MessageImpl nImpl = (MessageImpl) io.readObject();
+
+ o.close();
+
+ EPR theEpr = nImpl.getHeader().getCall().getTo();
+
+ assertEquals(theEpr instanceof SFTPEpr, true);
+
+ assertEquals(((SFTPEpr) theEpr).getCertificateURL().toString(), "http://www.bar.foo");
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+
+ fail(ex.toString());
+ }
+ }
+
}
Modified: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/XMLMessageUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/XMLMessageUnitTest.java 2007-01-08 14:45:14 UTC (rev 8761)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/message/tests/XMLMessageUnitTest.java 2007-01-08 15:24:39 UTC (rev 8762)
@@ -24,6 +24,7 @@
import java.io.StringReader;
import java.io.StringWriter;
+import java.net.URL;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -32,6 +33,14 @@
import org.jboss.internal.soa.esb.message.format.xml.MessageImpl;
import org.jboss.soa.esb.addressing.Call;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.eprs.EmailEpr;
+import org.jboss.soa.esb.addressing.eprs.FTPEpr;
+import org.jboss.soa.esb.addressing.eprs.FileEpr;
+import org.jboss.soa.esb.addressing.eprs.HTTPEpr;
+import org.jboss.soa.esb.addressing.eprs.JDBCEpr;
+import org.jboss.soa.esb.addressing.eprs.JMSEpr;
+import org.jboss.soa.esb.addressing.eprs.SFTPEpr;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageFactory;
import org.jboss.soa.esb.message.format.MessageType;
@@ -284,6 +293,200 @@
}
}
+ public void testJmsEPRType ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
+ JMSEpr epr = new JMSEpr(JMSEpr.TOPIC_TYPE, "foo", "bar");
+
+ msg.getHeader().getCall().setTo(epr);
+
+ try
+ {
+ final String xmlRepresentation = msgToXML((MessageImpl)msg) ;
+ System.err.println("Document is "+xmlRepresentation);
+
+ final MessageImpl nImpl = msgFromXML(xmlRepresentation) ;
+
+ EPR theEpr = nImpl.getHeader().getCall().getTo();
+
+ assertEquals(theEpr instanceof JMSEpr, true);
+
+ assertEquals(((JMSEpr) theEpr).getConnectionFactory(), "bar");
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testHttpEPRType ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
+
+ try
+ {
+ HTTPEpr epr = new HTTPEpr("http://www.foo.bar");
+
+ msg.getHeader().getCall().setTo(epr);
+
+ final String xmlRepresentation = msgToXML((MessageImpl)msg) ;
+ System.err.println("Document is "+xmlRepresentation);
+
+ final MessageImpl nImpl = msgFromXML(xmlRepresentation) ;
+
+ EPR theEpr = nImpl.getHeader().getCall().getTo();
+
+ assertEquals(theEpr instanceof HTTPEpr, true);
+
+ assertEquals(((HTTPEpr) theEpr).getURL().toString(), "http://www.foo.bar");
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testEmailEPRType ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
+
+ try
+ {
+ EmailEpr epr = new EmailEpr(EmailEpr.SMTP_PROTOCOL, "foo.bar", "25", "me", "password");
+
+ msg.getHeader().getCall().setTo(epr);
+
+ final String xmlRepresentation = msgToXML((MessageImpl)msg) ;
+ System.err.println("Document is "+xmlRepresentation);
+
+ final MessageImpl nImpl = msgFromXML(xmlRepresentation) ;
+
+ EPR theEpr = nImpl.getHeader().getCall().getTo();
+
+ assertEquals(theEpr instanceof EmailEpr, true);
+
+ assertEquals(((EmailEpr) theEpr).getPassword(), "password");
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testFtpEPRType ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
+
+ try
+ {
+ FTPEpr epr = new FTPEpr("http://www.foo.bar");
+
+ epr.setPassive(true);
+
+ msg.getHeader().getCall().setTo(epr);
+
+ final String xmlRepresentation = msgToXML((MessageImpl)msg) ;
+ System.err.println("Document is "+xmlRepresentation);
+
+ final MessageImpl nImpl = msgFromXML(xmlRepresentation) ;
+
+ EPR theEpr = nImpl.getHeader().getCall().getTo();
+
+ assertEquals(theEpr instanceof FTPEpr, true);
+
+ assertEquals(((FTPEpr) theEpr).getPassive(), true);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testJdbcEPRType ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
+
+ try
+ {
+ JDBCEpr epr = new JDBCEpr("http://www.foo.bar", "SOME FAKE SQL");
+
+ msg.getHeader().getCall().setTo(epr);
+
+ final String xmlRepresentation = msgToXML((MessageImpl)msg) ;
+ System.err.println("Document is "+xmlRepresentation);
+
+ final MessageImpl nImpl = msgFromXML(xmlRepresentation) ;
+
+ EPR theEpr = nImpl.getHeader().getCall().getTo();
+
+ assertEquals(theEpr instanceof JDBCEpr, true);
+
+ assertEquals(((JDBCEpr) theEpr).getSQL(), "SOME FAKE SQL");
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testFileEPRType ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
+
+ try
+ {
+ FileEpr epr = new FileEpr("file://tmp/bar.txt");
+
+ epr.setErrorDelete(true);
+
+ msg.getHeader().getCall().setTo(epr);
+
+ final String xmlRepresentation = msgToXML((MessageImpl)msg) ;
+ System.err.println("Document is "+xmlRepresentation);
+
+ final MessageImpl nImpl = msgFromXML(xmlRepresentation) ;
+
+ EPR theEpr = nImpl.getHeader().getCall().getTo();
+
+ assertEquals(theEpr instanceof FileEpr, true);
+
+ assertEquals(((FileEpr) theEpr).getErrorDelete(), true);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
+ public void testSFtpEPRType ()
+ {
+ Message msg = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
+
+ try
+ {
+ SFTPEpr epr = new SFTPEpr(new URL("http://www.foo.bar"), new URL("http://www.bar.foo"));
+
+ assertEquals(epr.getCertificateURL().toString(), "http://www.bar.foo");
+
+ msg.getHeader().getCall().setTo(epr);
+
+ final String xmlRepresentation = msgToXML((MessageImpl)msg) ;
+ System.err.println("Document is "+xmlRepresentation);
+
+ final MessageImpl nImpl = msgFromXML(xmlRepresentation) ;
+
+ EPR theEpr = nImpl.getHeader().getCall().getTo();
+
+ assertEquals(theEpr instanceof SFTPEpr, true);
+
+ assertEquals(((SFTPEpr) theEpr).getCertificateURL().toString(), "http://www.bar.foo");
+ }
+ catch (Exception ex)
+ {
+ fail(ex.toString());
+ }
+ }
+
private String msgToXML(final MessageImpl msg)
throws Exception
{
Modified: labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListenerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListenerUnitTest.java 2007-01-08 14:45:14 UTC (rev 8761)
+++ labs/jbossesb/trunk/qa/junit/src/org/jboss/soa/esb/listeners/gateway/JmsGatewayListenerUnitTest.java 2007-01-08 15:24:39 UTC (rev 8762)
@@ -60,57 +60,68 @@
import org.junit.BeforeClass;
import org.junit.Test;
-public class JmsGatewayListenerUnitTest
+public class JmsGatewayListenerUnitTest
{
- private static final String TMP_DIR = System.getProperty("java.io.tmpdir","/tmp");
+ private static final String TMP_DIR = System.getProperty("java.io.tmpdir",
+ "/tmp");
- private static Logger _logger = Logger.getLogger(JmsGatewayListenerUnitTest.class);
- static String _gatewayConfig = "jmsGatewayConfig.xml";
- static String _esbListenerConfig = "jmsEsbListenerConfig.xml";
- static File _returnFile = new File(TMP_DIR,"jmsMessageBack.txt");
+ private static Logger _logger = Logger
+ .getLogger(JmsGatewayListenerUnitTest.class);
-
- static String SERVICE_NAME = "testJmsGateway";
- static String THE_TEXT = "This is the JMS text that will travel around";
+ static String _gatewayConfig = "jmsGatewayConfig.xml";
- EsbListenerController _esbListController;
+ static String _esbListenerConfig = "jmsEsbListenerConfig.xml";
+
+ static File _returnFile = new File(TMP_DIR, "jmsMessageBack.txt");
+
+ static String SERVICE_NAME = "testJmsGateway";
+
+ static String THE_TEXT = "This is the JMS text that will travel around";
+
+ EsbListenerController _esbListController;
+
GatewayListenerController _gatewayController;
- private static String mDbDriver;
+ private static String mDbDriver;
+
private static String mDbUrl;
+
private static String mDbUsername;
+
private static String mDbPassword;
@BeforeClass
public static void setUp() throws Exception
{
- _logger.info("Writing temp files to "+TMP_DIR);
+ _logger.info("Writing temp files to " + TMP_DIR);
- // delete this one just to make sure asserts take the new ones
- _returnFile.delete();
-
- // initialize registry
- runBeforeAllTests();
+ // delete this one just to make sure asserts take the new ones
+ _returnFile.delete();
- // send a message so when gateway comes up, it will have something waiting
- sendJmsMessage(THE_TEXT);
+ // initialize registry
+ runBeforeAllTests();
+
+ // send a message so when gateway comes up, it will have something
+ // waiting
+ sendJmsMessage(THE_TEXT);
}
-
+
@AfterClass
public static void tearDown() throws Exception
{
- _returnFile.delete();
+ _returnFile.delete();
- Thread.sleep(2000);
- if ("org.hsqldb.jdbcDriver".equals(mDbDriver))
+ Thread.sleep(2000);
+ if ("org.hsqldb.jdbcDriver".equals(mDbDriver))
HsqldbUtil.stopHsqldb(mDbUrl, mDbUsername, mDbPassword);
}
-
+
@Test
- public void jmsGatewayListener() throws Exception
- {
- InputStream inStream = getClass().getResourceAsStream(_esbListenerConfig);
+ public void jmsGatewayListener() throws Exception
+ {
+ InputStream inStream = getClass().getResourceAsStream(
+ _esbListenerConfig);
ConfigTree tree = ConfigTree.fromInputStream(inStream);
_esbListController = EsbListenerControllerFactory.getInstance(tree);
@@ -121,21 +132,26 @@
Thread.sleep(4000);
_esbListController.requestEnd();
- _gatewayController.requestEnd();
-
+ _gatewayController.requestEnd();
+
assertEquals(THE_TEXT, stringFromFile(_returnFile));
- }
-
- public static class MockMessageAwareAction
+ }
+
+ public static class MockMessageAwareAction
{
- ConfigTree _config;
- public MockMessageAwareAction(ConfigTree config) { _config = config; }
- public Message writeToDisk (Message message) throws Exception
- {
- bytesToFile(_returnFile, message.getBody().getContents());
- return message;
- } // ________________________________
+ ConfigTree _config;
+ public MockMessageAwareAction(ConfigTree config)
+ {
+ _config = config;
+ }
+
+ public Message writeToDisk(Message message) throws Exception
+ {
+ bytesToFile(_returnFile, message.getBody().getContents());
+ return message;
+ } // ________________________________
+
} // ___________________________________________________
private static void bytesToFile(File file, byte[] text) throws Exception
@@ -149,100 +165,139 @@
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
- FileInputStream inp = new FileInputStream(file);
+ FileInputStream inp = new FileInputStream(file);
byte[] ba = new byte[1000];
int iQ;
- while (-1 != (iQ=inp.read(ba)))
+ while (-1 != (iQ = inp.read(ba)))
if (iQ > 0)
- out.write(ba,0,iQ);
+ out.write(ba, 0, iQ);
inp.close();
-
+
out.close();
return out.toString();
}
-
+
private static void sendJmsMessage(String text) throws Exception
{
- InputStream inStream = JmsGatewayListenerUnitTest.class.getResourceAsStream(_gatewayConfig);
- ConfigTree tree = ConfigTree.fromInputStream(inStream)
- .getAllChildren()[0];
- String sJndiContextFactory = tree.getAttribute(JMSEpr.JNDI_CONTEXT_FACTORY);
- String sJndiURL = tree.getAttribute(JMSEpr.JNDI_URL_TAG);
- String sJndiPkgPrefix = tree.getAttribute(JMSEpr.JNDI_PKG_PREFIX_TAG);
-
- Context oJndiCtx = NamingContext.getServerContext(sJndiURL,sJndiContextFactory,sJndiPkgPrefix);
- String sFactoryClass = tree.getAttribute(JMSEpr.CONNECTION_FACTORY_TAG);
- if (Util.isNullString(sFactoryClass))
- sFactoryClass = "ConnectionFactory";
- Object tmp = oJndiCtx.lookup(sFactoryClass);
-
- String sQname = tree.getAttribute(JMSEpr.DESTINATION_NAME_TAG);
- javax.jms.Queue queue = (javax.jms.Queue) oJndiCtx.lookup(sQname);
- QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
- QueueConnection qConn = qcf.createQueueConnection();
- QueueSession qSess = qConn.createQueueSession(false,QueueSession.AUTO_ACKNOWLEDGE);
- javax.jms.Message jMess = qSess.createTextMessage(THE_TEXT);
- String[] sa = tree.getAttribute(JMSEpr.MESSAGE_SELECTOR_TAG).split("=");
- // strip apostrophes
- String sVal = sa[1].substring(1).substring(0,-2+sa[1].length());
- jMess.setStringProperty(sa[0],sVal);
- MessageProducer producer = qSess.createProducer(queue);
+ InputStream inStream = JmsGatewayListenerUnitTest.class
+ .getResourceAsStream(_gatewayConfig);
+ ConfigTree tree = ConfigTree.fromInputStream(inStream).getAllChildren()[0];
+ String sJndiContextFactory = tree
+ .getAttribute(JMSEpr.JNDI_CONTEXT_FACTORY_TAG);
+ String sJndiURL = tree.getAttribute(JMSEpr.JNDI_URL_TAG);
+ String sJndiPkgPrefix = tree.getAttribute(JMSEpr.JNDI_PKG_PREFIX_TAG);
- producer.send(jMess);
-
+ Context oJndiCtx = NamingContext.getServerContext(sJndiURL,
+ sJndiContextFactory, sJndiPkgPrefix);
+ String sFactoryClass = tree.getAttribute(JMSEpr.CONNECTION_FACTORY_TAG);
+ if (Util.isNullString(sFactoryClass))
+ sFactoryClass = "ConnectionFactory";
+ Object tmp = oJndiCtx.lookup(sFactoryClass);
+
+ String sQname = tree.getAttribute(JMSEpr.DESTINATION_NAME_TAG);
+ javax.jms.Queue queue = (javax.jms.Queue) oJndiCtx.lookup(sQname);
+ QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
+ QueueConnection qConn = qcf.createQueueConnection();
+ QueueSession qSess = qConn.createQueueSession(false,
+ QueueSession.AUTO_ACKNOWLEDGE);
+ javax.jms.Message jMess = qSess.createTextMessage(THE_TEXT);
+ String[] sa = tree.getAttribute(JMSEpr.MESSAGE_SELECTOR_TAG).split("=");
+ // strip apostrophes
+ String sVal = sa[1].substring(1).substring(0, -2 + sa[1].length());
+ jMess.setStringProperty(sa[0], sVal);
+ MessageProducer producer = qSess.createProducer(queue);
+
+ producer.send(jMess);
+
if (null != producer)
- try { producer.close(); }
- catch (JMSException e) {/* OK do nothing */ }
+ try
+ {
+ producer.close();
+ }
+ catch (JMSException e)
+ {/* OK do nothing */
+ }
if (null != qSess)
- try { qSess.close(); }
- catch (JMSException e) {/* OK do nothing */ }
+ try
+ {
+ qSess.close();
+ }
+ catch (JMSException e)
+ {/* OK do nothing */
+ }
if (null != qConn)
- try { qConn.close(); }
- catch (JMSException e) {/* OK do nothing */ }
-
- } //________________________________
-
+ try
+ {
+ qConn.close();
+ }
+ catch (JMSException e)
+ {/* OK do nothing */
+ }
+
+ } // ________________________________
+
public static void runBeforeAllTests()
{
- try {
- DOMConfigurator.configure(TestEnvironmentUtil.getUserDir("product","../product") + "etc/test/resources/log4j.xml");
- TestEnvironmentUtil.setESBPropertiesFileToUse("product","../product");
- //Set the juddi properties file in System so juddi will pick it up later and use the test values.
+ try
+ {
+ DOMConfigurator.configure(TestEnvironmentUtil.getUserDir("product",
+ "../product")
+ + "etc/test/resources/log4j.xml");
+ TestEnvironmentUtil.setESBPropertiesFileToUse("product",
+ "../product");
+ // Set the juddi properties file in System so juddi will pick it up
+ // later and use the test values.
String juddiPropertiesFile = "/org/jboss/soa/esb/services/registry/juddi-qatest.properties";
System.setProperty("juddi.propertiesFile", juddiPropertiesFile);
- //Read this properties file to get the db connection string
+ // Read this properties file to get the db connection string
Properties props = new Properties();
- InputStream inStream = Class.class.getResourceAsStream(juddiPropertiesFile);
+ InputStream inStream = Class.class
+ .getResourceAsStream(juddiPropertiesFile);
props.load(inStream);
- mDbDriver = props.getProperty("juddi.jdbcDriver");
- mDbUrl = props.getProperty("juddi.jdbcUrl");
- mDbUsername = props.getProperty("juddi.jdbcUsername");
- mDbPassword = props.getProperty("juddi.jdbcPassword");
-
- String database="not tested yet";
- if ("org.hsqldb.jdbcDriver".equals(mDbDriver)) {
+ mDbDriver = props.getProperty("juddi.jdbcDriver");
+ mDbUrl = props.getProperty("juddi.jdbcUrl");
+ mDbUsername = props.getProperty("juddi.jdbcUsername");
+ mDbPassword = props.getProperty("juddi.jdbcPassword");
+
+ String database = "not tested yet";
+ if ("org.hsqldb.jdbcDriver".equals(mDbDriver))
+ {
database = "hsqldb";
- //Bring up hsql on default port 9001
- HsqldbUtil.startHsqldb(TestEnvironmentUtil.getUserDir("product","../product") + "build/hsqltestdb", "juddi");
- } else if ("com.mysql.jdbc.Driver".equals(mDbDriver)) {
+ // Bring up hsql on default port 9001
+ HsqldbUtil.startHsqldb(TestEnvironmentUtil.getUserDir(
+ "product", "../product")
+ + "build/hsqltestdb", "juddi");
+ }
+ else if ("com.mysql.jdbc.Driver".equals(mDbDriver))
+ {
database = "mysql";
- } //add and test your own database..
-
- //Get the registry-schema create scripts
- String sqlDir = TestEnvironmentUtil.getUserDir("product","../product") + "install/jUDDI-registry/sql/" + database + "/";
- //Drop what is there now, if exists. We want to start fresh.
- String sqlDropCmd = FileUtil.readTextFile(new File(sqlDir + "drop_database.sql"));
- String sqlCreateCmd = FileUtil.readTextFile(new File(sqlDir + "create_database.sql"));
- String sqlInsertPubCmd = FileUtil.readTextFile(new File(sqlDir + "insert_publishers.sql"));
-
- try {
+ } // add and test your own database..
+
+ // Get the registry-schema create scripts
+ String sqlDir = TestEnvironmentUtil.getUserDir("product",
+ "../product")
+ + "install/jUDDI-registry/sql/" + database + "/";
+ // Drop what is there now, if exists. We want to start fresh.
+ String sqlDropCmd = FileUtil.readTextFile(new File(sqlDir
+ + "drop_database.sql"));
+ String sqlCreateCmd = FileUtil.readTextFile(new File(sqlDir
+ + "create_database.sql"));
+ String sqlInsertPubCmd = FileUtil.readTextFile(new File(sqlDir
+ + "insert_publishers.sql"));
+
+ try
+ {
Class.forName(mDbDriver);
- } catch (Exception e) {
- System.out.println("ERROR: failed to load " + database + " JDBC driver.");
+ }
+ catch (Exception e)
+ {
+ System.out.println("ERROR: failed to load " + database
+ + " JDBC driver.");
e.printStackTrace();
return;
}
- java.sql.Connection con = DriverManager.getConnection(mDbUrl, mDbUsername, mDbPassword);
+ java.sql.Connection con = DriverManager.getConnection(mDbUrl,
+ mDbUsername, mDbPassword);
Statement stmnt = con.createStatement();
System.out.println("Dropping the schema if exist");
stmnt.execute(sqlDropCmd);
@@ -250,14 +305,19 @@
stmnt.execute(sqlCreateCmd);
System.out.println("Adding the jbossesb publisher");
stmnt.execute(sqlInsertPubCmd);
-
- } catch (Throwable e) {
+
+ }
+ catch (Throwable e)
+ {
e.printStackTrace();
- System.out.println("We should stop testing, since we don't have a db.");
+ System.out
+ .println("We should stop testing, since we don't have a db.");
assertTrue(false);
}
}
- public static junit.framework.Test suite() {
+
+ public static junit.framework.Test suite()
+ {
return new JUnit4TestAdapter(JmsGatewayListenerUnitTest.class);
}
More information about the jboss-svn-commits
mailing list