From: <jbo...@li...> - 2006-05-04 13:13:09
|
Author: mar...@jb... Date: 2006-05-04 09:12:55 -0400 (Thu, 04 May 2006) New Revision: 4088 Added: labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/addressing/EPR.java labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/addressing/PortReference.java labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/addressing/XMLUtil.java labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/exceptions/MarshalException.java labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/internal/esbcore/addressing/PortReferenceHelper.java Removed: labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/addressing/EPR.java labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/internal/esbcore/addressing/EPRImpl.java Modified: labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/impl/tcp/plugin/infrastructure/receiver/ReceiverPluginImpl.java labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/impl/tcp/plugin/infrastructure/sender/SenderPluginImpl.java labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Attachment.java labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Body.java labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Context.java labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Fault.java labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Header.java labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Message.java labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/tests/tcp/TcpClient.java labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/tests/tcp/TcpService.java Log: Added initial addressing implementation and updated tests and dispatchers accordingly. http://jira.jboss.com/jira/browse/JBESB-9 Deleted: labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/addressing/EPR.java =================================================================== --- labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/addressing/EPR.java 2006-05-04 10:47:38 UTC (rev 4087) +++ labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/addressing/EPR.java 2006-05-04 13:12:55 UTC (rev 4088) @@ -1,55 +0,0 @@ -package org.jboss.soa.esbcore.addressing; - -/* - * JBoss, Home of Professional Open Source - * Copyright 2006, JBoss Inc., and others contributors as indicated - * by the @authors tag. All rights reserved. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU Lesser General Public License, v. 2.1. - * This program is distributed in the hope that it will be useful, but WITHOUT A - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License, - * v.2.1 along with this distribution; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * (C) 2005-2006, - * @author mar...@jb... - */ - -/** - * This class represents the endpoint reference for services. - */ - -import java.net.URI; - -public interface EPR -{ - public void setTo (URI uri); - public URI getTo (); - public void setFrom (URI uri); - public URI getFrom (); - public void setReplyTo (URI uri); - public URI getReplyTo (); - public void setFaultTo (URI uri); - public URI getFaultTo (); - public void setAction (URI uri); - public URI getAction (); - public void setMessageID (URI uri); - public URI getMessageID (); -// public void setMetaData (MetaData md); -// public MetaData getMetaData (); -// public void addReferenceParameter (...); - - public void copy (EPR from); - - /* - * In lieu of toXML and fromXML - */ - public byte[] toBytes(); - public void fromBytes (byte[] b); -} \ No newline at end of file Added: labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/addressing/EPR.java =================================================================== --- labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/addressing/EPR.java 2006-05-04 10:47:38 UTC (rev 4087) +++ labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/addressing/EPR.java 2006-05-04 13:12:55 UTC (rev 4088) @@ -0,0 +1,302 @@ +package org.jboss.soa.esbcore.addressing; + +/* + * JBoss, Home of Professional Open Source + * Copyright 2006, JBoss Inc., and others contributors as indicated + * by the @authors tag. All rights reserved. + * See the copyright.txt in the distribution for a + * full listing of individual contributors. + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License, v. 2.1. + * This program is distributed in the hope that it will be useful, but WITHOUT A + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License, + * v.2.1 along with this distribution; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * (C) 2005-2006, + * @author mar...@jb... + */ + +import org.jboss.soa.esbcore.addressing.PortReference.Extension; +import org.jboss.soa.internal.esbcore.addressing.PortReferenceHelper; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * This class represents the endpoint reference for services. + */ + +import java.net.URI; +import java.net.URISyntaxException; + +public class EPR +{ + public EPR () + { + _to = new PortReference(); + + _from = _replyTo = _relatesTo = _faultTo = null; + _action = _messageID = null; + } + + public EPR (URI uri) + { + _to = new PortReference(uri.toString()); + + _from = _replyTo = _relatesTo = _faultTo = null; + _action = _messageID = null; + } + + public void setTo (PortReference uri) + { + _to = uri; + } + + public PortReference getTo () throws URISyntaxException + { + return _to; + } + + public void setFrom (PortReference uri) + { + _from = uri; + } + + public PortReference getFrom () throws URISyntaxException + { + return _from; + } + + public void setReplyTo (PortReference uri) + { + _replyTo = uri; + } + + public PortReference getReplyTo () throws URISyntaxException + { + return _replyTo; + } + + public void setFaultTo (PortReference uri) + { + _faultTo = uri; + } + + public PortReference getFaultTo () throws URISyntaxException + { + return _faultTo; + } + + public void setRelatesTo (PortReference uri) + { + _relatesTo = uri; + } + + public PortReference getRelatesTo () throws URISyntaxException + { + return _relatesTo; + } + + public void setAction (URI uri) + { + _action = uri; + } + + public URI getAction () throws URISyntaxException + { + return _action; + } + + public void setMessageID (URI uri) + { + _messageID = uri; + } + + public URI getMessageID () throws URISyntaxException + { + return _messageID; + } + + public void copy (EPR from) + { + EPR fromImpl = (EPR) from; + + _to = fromImpl._to; + _from = fromImpl._from; + _replyTo = fromImpl._replyTo; + _relatesTo = fromImpl._relatesTo; + _faultTo = fromImpl._faultTo; + _action = fromImpl._action; + _messageID = fromImpl._messageID; + } + +// public void setMetaData (MetaData md); +// public MetaData getMetaData (); +// public void addReferenceParameter (...); + + public String toString () + { + return "To: "+_to+" From: "+_from+" ReplyTo: "+_replyTo+" FaultTo: "+_faultTo+" Action: "+_action; + } + + + public Element toXML (Document doc, Element header) + { + try + { + Element toElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.TO_TAG); + PortReferenceHelper.toXML(header, doc, toElement, _to, true); + header.appendChild(toElement); + + Element fromElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.FROM_TAG); + PortReferenceHelper.toXML(header, doc, fromElement, _from, false); + header.appendChild(fromElement); + + Element replyToElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.REPLY_TO_TAG); + PortReferenceHelper.toXML(header, doc, replyToElement, _from, false); + header.appendChild(replyToElement); + + Element relatesToElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.RELATES_TO_TAG); + PortReferenceHelper.toXML(header, doc, relatesToElement, _from, false); + header.appendChild(relatesToElement); + + Element faultToElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.FAULT_TO_TAG); + PortReferenceHelper.toXML(header, doc, faultToElement, _from, false); + header.appendChild(faultToElement); + + Element actionElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.ACTION_TAG); + actionElement.setNodeValue(_action.toString()); + header.appendChild(actionElement); + + Element messageIDElement = doc.createElementNS(XMLUtil.WSA_NAMESPACE_URI, XMLUtil.WSA_PREFIX+":"+XMLUtil.MESSAGE_IDENTIFIER_TAG); + messageIDElement.setNodeValue(_messageID.toString()); + header.appendChild(messageIDElement); + + return header; + } + catch (Exception ex) + { + ex.printStackTrace(); + + return null; + } + } + + public void fromXML (Element header) + { + try + { + NodeList nl = header.getChildNodes(); + + for (int i = 0; i < nl.getLength(); i++) + { + Node n = nl.item(i); + + if (n.getNodeName().equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.TO_TAG)) + { + try + { + _to = PortReferenceHelper.fromXML((Element) n, true); + } + catch (Exception ex) + { + + } + } + + if (n.getNodeName().equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.FROM_TAG)) + { + try + { + _from = PortReferenceHelper.fromXML((Element) n, false); + } + catch (Exception ex) + { + + } + } + + if (n.getNodeName().equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.REPLY_TO_TAG)) + { + try + { + _replyTo = PortReferenceHelper.fromXML((Element) n, false); + } + catch (Exception ex) + { + + } + } + + if (n.getNodeName().equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.RELATES_TO_TAG)) + { + try + { + _relatesTo = PortReferenceHelper.fromXML((Element) n, false); + } + catch (Exception ex) + { + + } + } + + if (n.getNodeName().equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.FAULT_TO_TAG)) + { + try + { + _faultTo = PortReferenceHelper.fromXML((Element) n, false); + } + catch (Exception ex) + { + + } + } + + if (n.getNodeName().equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.ACTION_TAG)) + { + try + { + _action = new URI(n.getNodeValue()); + } + catch (Exception ex) + { + + } + } + + if (n.getNodeName().equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.MESSAGE_IDENTIFIER_TAG)) + { + try + { + _messageID = new URI(n.getNodeValue()); + } + catch (Exception ex) + { + + } + } + } + } + catch (Exception ex) + { + // TODO error checking!! + + ex.printStackTrace(); + } + } + + private PortReference _to; + private PortReference _from; + private PortReference _faultTo; + private PortReference _replyTo; + private PortReference _relatesTo; + private URI _action; + private URI _messageID; + +} \ No newline at end of file Added: labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/addressing/PortReference.java =================================================================== --- labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/addressing/PortReference.java 2006-05-04 10:47:38 UTC (rev 4087) +++ labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/addressing/PortReference.java 2006-05-04 13:12:55 UTC (rev 4088) @@ -0,0 +1,331 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2006, JBoss Inc., and others contributors as indicated + * by the @authors tag. All rights reserved. + * See the copyright.txt in the distribution for a + * full listing of individual contributors. + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License, v. 2.1. + * This program is distributed in the hope that it will be useful, but WITHOUT A + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License, + * v.2.1 along with this distribution; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * (C) 2005-2006, + * @author mar...@jb... + */ + +/* + * Copyright (c) 2002, 2003, Arjuna Technologies Limited. + * + * PortReference.java + */ + +package org.jboss.soa.esbcore.addressing; + +import java.util.Iterator; +import java.util.List; +import java.util.LinkedList; +import java.util.HashMap; + + +/** + * An implementation of a WS-Addressing EPR. It needs completely rewriting after + * the interoperability workshop as it is not extensible and not guaranteed to + * work in the general case. It's morphed with the changing WS-C/WS-T and + * WS-Addr specifications and their quirks; now that WS-Addr is finalized the + * old quirks no longer need to be supported so it's best to rewrite this from + * scratch. + * + * An instance of a PortReference represents a single element in WS-A. + */ + +public class PortReference { + public PortReference() { + } + + public PortReference(String address) { + setAddress(address); + } + + public void setAddress(String address) { + _address = address; + } + + public String getAddress() { + return _address; + } + + public void addExtension(PortReference.Extension extension) { + _extensions.add(extension); + } + + // all extensions are added as the Arjuna namespace. + + public void addExtension(String value) { + addExtension(XMLUtil.INSTANCE_IDENTIFIER_TAG, XMLUtil.WSARJADDR_PREFIX, + XMLUtil.WSARJADDR_NAMESPACE_URI, value, + Extension.REFERENCE_PROPERTIES); + } + + public void addExtension(String tag, String value) { + addExtension(tag, XMLUtil.WSARJADDR_PREFIX, + XMLUtil.WSARJADDR_NAMESPACE_URI, value, + Extension.REFERENCE_PROPERTIES); + } + + /** + * Define the tag, prefix and namespace URI for the extension value. The + * parent is a refProperty. + */ + + public void addExtension(String tag, String prefix, String uri, String value) { + _extensions.add(new Extension(tag, prefix, uri, value, + Extension.REFERENCE_PROPERTIES)); + } + + /** + * Define the tag, prefix and namespace URI for the extension value. The + * parent field defines whether the attribute has a refParam, refProp or + * neither as its parent. + */ + + public void addExtension(String tag, String prefix, String uri, + String value, int parent) { + _extensions.add(new Extension(tag, prefix, uri, value, parent)); + } + + // placeholders only + + public void addPortType(String qName) { + } + + public void addServiceName(String portName, String qName) { + } + + public void addPolicy() { + } + + public String getExtensionValue(String tag) { + String extensionValue = null; + Iterator iterator = _extensions.iterator(); + + while (iterator.hasNext() && (extensionValue == null)) { + Extension extension = (Extension) iterator.next(); + + if (tag.equals(extension.getTag())) + extensionValue = extension.getValue(); + } + + return extensionValue; + } + + public Iterator getExtensions() { + return _extensions.iterator(); + } + + public void clearExtensions() { + _extensions.clear(); + } + + public String toString() { + return "PortReference < " + _address + " >"; + } + + public String extendedToString() { + String addr = "<" + XMLUtil.WSA_PREFIX + ":Address " + _address + "/>"; + + Iterator extensions = getExtensions(); + + while (extensions.hasNext()) { + Extension ext = (Extension) extensions.next(); + + addr += ", <" + XMLUtil.WSA_PREFIX + ":" + + XMLUtil.REFERENCE_PROPERTIES_TAG + " " + ext.getPrefix() + + ":" + ext.getTag() + " : " + ext.getValue() + "/>"; + } + + return "PortReference : " + addr; + } + + /** + * Is this object equal to the specified parameter? + * + * @param rhs + * The rhs object. + * @return true if the specified object is equal, false otherwise. + */ + public boolean equals(final Object rhs) { + if ((rhs != null) && (rhs.getClass() == getClass())) { + // This should really only include reference property extensions + final PortReference rhsPortReference = (PortReference) rhs; + return (equalsObject(_address, rhsPortReference._address) + && equalsObject(_extensions, rhsPortReference._extensions) + && equalsObject(_portType, rhsPortReference._portType) + && equalsObject(_serviceName, rhsPortReference._serviceName) && equalsObject( + _policies, rhsPortReference._policies)); + } + return false; + } + + /** + * Return the hash code for this object. + * + * @return the hash code value. + */ + public int hashCode() { + // Not checked for spread. + return (objectHashCode(_address, 0x1) + ^ objectHashCode(_extensions, 0x2) + ^ objectHashCode(_portType, 0x4) + ^ objectHashCode(_serviceName, 0x8) ^ objectHashCode(_policies, + 0x10)); + } + + public static class Extension { + public static final int REFERENCE_PROPERTIES = 0; + public static final int REFERENCE_PARAMETERS = 1; + public static final int NEITHER = 2; + + public Extension(String tag, String prefix, String uri) { + this(tag, prefix, uri, null, REFERENCE_PROPERTIES); + } + + public Extension(String tag, String prefix, String uri, String value) { + this(tag, prefix, uri, value, REFERENCE_PROPERTIES); + } + + public Extension(String tag, String prefix, String uri, String value, + int parent) { + _tag = tag; + _prefix = prefix; + _uri = uri; + _value = value; + _parent = parent; + } + + public int getParent() { + return _parent; + } + + public String getTag() { + return _tag; + } + + public String getPrefix() { + return _prefix; + } + + public String getURI() { + return _uri; + } + + public String getValue() { + return _value; + } + + public LinkedList getChildren() { + return _extensions; + } + + public HashMap getAttributes() { + return _attributes; + } + + public void addAttributes(HashMap props) { + _attributes = props; + } + + public void addChild(Extension child) { + if (_extensions == null) + _extensions = new LinkedList(); + + _extensions.add(child); + } + + public String toString() { + return new String("< " + _tag + ", " + _prefix + ", " + _uri + ", " + + _value + " >"); + } + + /** + * Is this object equal to the specified parameter (ignoring prefix)? + * + * @param rhs + * The rhs object. + * @return true if the specified object is equal, false otherwise. + */ + public boolean equals(final Object rhs) { + if ((rhs != null) && (rhs.getClass() == getClass())) { + final Extension rhsExtension = (Extension) rhs; + return (equalsObject(_tag, rhsExtension._tag) + && equalsObject(_uri, rhsExtension._uri) + && equalsObject(_value, rhsExtension._value) + && equalsObject(_extensions, rhsExtension._extensions) && (_parent == rhsExtension._parent)); + } + return false; + } + + /** + * Return the hash code for this object. + * + * @return the hash code value. + */ + public int hashCode() { + // Not checked for spread. + return (_parent ^ objectHashCode(_tag, 0x4) + ^ objectHashCode(_uri, 0x8) ^ objectHashCode(_value, 0x10) ^ objectHashCode( + _extensions, 0x20)); + } + + private String _tag = null; + private String _prefix = null; + private String _uri = null; + private String _value = null; + private int _parent = NEITHER; + private LinkedList _extensions = null; + private HashMap _attributes = null; + + } + + /** + * Get the hash code from the object or use the default if null. + * + * @param obj + * The object. + * @param defaultHashCode + * The default hash code. + * @return The hash code. + */ + static int objectHashCode(final Object obj, final int defaultHashCode) { + return (obj == null ? defaultHashCode : obj.hashCode()); + } + + /** + * Are the two objects equal? + * + * @param lhs + * The lhs object. + * @param rhs + * The rhs object. + * @return true if equal or both null, false otherwise. + */ + static boolean equalsObject(final Object lhs, final Object rhs) { + if (lhs == null) { + return (rhs == null); + } else { + return lhs.equals(rhs); + } + } + + private String _address = null; + private LinkedList _extensions = new LinkedList(); + private Extension _portType = null; + private Extension _serviceName = null; + private List _policies = null; + +} Added: labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/addressing/XMLUtil.java =================================================================== --- labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/addressing/XMLUtil.java 2006-05-04 10:47:38 UTC (rev 4087) +++ labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/addressing/XMLUtil.java 2006-05-04 13:12:55 UTC (rev 4088) @@ -0,0 +1,62 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2006, JBoss Inc., and others contributors as indicated + * by the @authors tag. All rights reserved. + * See the copyright.txt in the distribution for a + * full listing of individual contributors. + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License, v. 2.1. + * This program is distributed in the hope that it will be useful, but WITHOUT A + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License, + * v.2.1 along with this distribution; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * (C) 2005-2006, + * @author mar...@jb... + */ + +/* + * Copyright (c) 2002, 2003, Arjuna Technologies Limited. + * + * XMLUtil.java + */ + +package org.jboss.soa.esbcore.addressing; + +public class XMLUtil +{ + // WS-Addr + + public static final String WSA_PREFIX = "wsa"; + public static final String WSA_NAMESPACE_URI = "http://schemas.xmlsoap.org/ws/2004/08/addressing"; + + public static final String ENDPOINT_REFERENCE_TAG = "EndpointReference"; + public static final String MESSAGE_IDENTIFIER_TAG = "MessageID"; + public static final String REFERENCE_PROPERTIES_TAG = "ReferenceProperties"; + public static final String REFERENCE_PARAMETERS_TAG = "ReferenceParameters"; + public static final String REPLY_TO_TAG = "ReplyTo"; + public static final String FROM_TAG = "From"; + + public static final String TO_TAG = "To"; + public static final String ADDRESS_TAG = "Address"; + public static final String ACTION_TAG = "Action"; + public static final String RELATES_TO_TAG = "RelatesTo"; + public static final String FAULT_TO_TAG = "FaultTo"; + + // WS-ARJADDR + + public static final String WSARJADDR_PREFIX = "wsarjaddr"; + public static final String WSARJADDR_NAMESPACE_URI = "http://schemas.arjuna.com/ws/2004/06/wsarjaddr"; + + public static final String INSTANCE_IDENTIFIER_TAG = "InstanceIdentifier"; + + public static final String UNKNOWNERROR_ERROR_CODE = "UnknownError"; + + // XML Namespace + public static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/" ; + public static final String XMLNS_PREFIX = "xmlns:" ; +} Added: labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/exceptions/MarshalException.java =================================================================== --- labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/exceptions/MarshalException.java 2006-05-04 10:47:38 UTC (rev 4087) +++ labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/exceptions/MarshalException.java 2006-05-04 13:12:55 UTC (rev 4088) @@ -0,0 +1,36 @@ +package org.jboss.soa.esbcore.exceptions; + +/* + * JBoss, Home of Professional Open Source + * Copyright 2006, JBoss Inc., and others contributors as indicated + * by the @authors tag. All rights reserved. + * See the copyright.txt in the distribution for a + * full listing of individual contributors. + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License, v. 2.1. + * This program is distributed in the hope that it will be useful, but WITHOUT A + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License, + * v.2.1 along with this distribution; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * (C) 2005-2006, + * @author mar...@jb... + */ + +import java.lang.Exception; + +public class MarshalException extends Exception { + + public MarshalException () { + super(); + } + + public MarshalException (String s) { + super(s); + } + +} Modified: labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/impl/tcp/plugin/infrastructure/receiver/ReceiverPluginImpl.java =================================================================== --- labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/impl/tcp/plugin/infrastructure/receiver/ReceiverPluginImpl.java 2006-05-04 10:47:38 UTC (rev 4087) +++ labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/impl/tcp/plugin/infrastructure/receiver/ReceiverPluginImpl.java 2006-05-04 13:12:55 UTC (rev 4088) @@ -24,6 +24,8 @@ import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.InputStream; +import java.io.StringReader; +import java.io.StringWriter; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; @@ -32,85 +34,71 @@ import java.net.URI; import java.net.URL; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.jboss.soa.esbcore.addressing.EPR; import org.jboss.soa.esbcore.messaging.Body; import org.jboss.soa.esbcore.messaging.Message; import org.jboss.soa.esbcore.plugin.infrastructure.receiver.ReceiverPlugin; -import org.jboss.soa.internal.esbcore.addressing.EPRImpl; +import org.w3c.dom.Document; +import com.sun.org.apache.xml.internal.serialize.OutputFormat; +import com.sun.org.apache.xml.internal.serialize.XMLSerializer; + public class ReceiverPluginImpl implements ReceiverPlugin { // TODO to and from XML - + // TODO ports (topics etc) should be setup in the contract. - - public Message receive () + + public Message receive() { try { // get the URL from the contract? - + URL listener = new URL("http://localhost:8080"); - + ServerSocket serverSocket = new ServerSocket(listener.getPort()); Socket theSocket = serverSocket.accept(); - DataInputStream inputStream = new DataInputStream(theSocket.getInputStream()); - - int headerSize = inputStream.readInt(); - - if (headerSize <= 0) + DataInputStream inputStream = new DataInputStream(theSocket + .getInputStream()); + + int msgSize = inputStream.readInt(); + + if (msgSize <= 0) { // error!!!! } else { - byte[] hdr = new byte[headerSize]; + byte[] content = new byte[msgSize]; + + inputStream.read(content, 0, msgSize); - inputStream.read(hdr, 0, headerSize); - - int contentSize = inputStream.readInt(); - byte[] content = null; + theSocket.close(); + serverSocket.close(); - if (contentSize <= 0) - { - // error! - - // TODO Exceptions!! - } - else - { - content = new byte[contentSize]; - - inputStream.read(content, 0, contentSize); + ByteArrayInputStream byteStream = new ByteArrayInputStream(content); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder docBuilder = factory.newDocumentBuilder(); + Document doc = docBuilder.parse(byteStream); - InetSocketAddress sender = (InetSocketAddress) theSocket.getRemoteSocketAddress(); - EPRImpl epr = new EPRImpl(); - - epr.fromBytes(hdr); - epr.setFrom(new URI("tcp://"+sender.getHostName()+":"+sender.getPort())); - - Message msg = new Message(); - - msg.getBody().setContents(content); - msg.getHeader().setEPR(epr); - - theSocket.close(); - serverSocket.close(); - - return msg; - } + Message msg = new Message(); + + msg.fromXML(doc); + + return msg; } - } - catch (SocketException ex) - { + } catch (SocketException ex) { // TODO EXCEPTIONS!!!!! - + return null; - } - catch (Exception ex) - { + } catch (Exception ex) { ex.printStackTrace(); } - + return null; } } Modified: labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/impl/tcp/plugin/infrastructure/sender/SenderPluginImpl.java =================================================================== --- labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/impl/tcp/plugin/infrastructure/sender/SenderPluginImpl.java 2006-05-04 10:47:38 UTC (rev 4087) +++ labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/impl/tcp/plugin/infrastructure/sender/SenderPluginImpl.java 2006-05-04 13:12:55 UTC (rev 4088) @@ -31,11 +31,11 @@ import org.jboss.soa.esbcore.messaging.Message; import org.jboss.soa.esbcore.addressing.EPR; +import org.jboss.soa.esbcore.addressing.PortReference; import org.jboss.soa.esbcore.common.Protocols; import org.jboss.soa.esbcore.exceptions.*; import java.net.InetAddress; -import java.net.InetSocketAddress; import java.net.MalformedURLException; import java.net.Socket; import java.net.URI; @@ -44,7 +44,16 @@ import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; +import java.io.StringWriter; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.w3c.dom.Document; + +import com.sun.org.apache.xml.internal.serialize.OutputFormat; +import com.sun.org.apache.xml.internal.serialize.XMLSerializer; + public class SenderPluginImpl implements SenderPlugin { public SenderPluginImpl () @@ -73,7 +82,7 @@ // get the destination from the EPR EPR epr = msg.getHeader().getEPR(); - URI destination = epr.getTo(); + URI destination = new URI(epr.getTo().getAddress()); // probably shouldn't happen by the time we get here, but ... @@ -89,20 +98,41 @@ URI from = new URI(Protocols.TCP+"://"+localAddress.getHostName()+":"+sender.getLocalPort()); ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); DataOutputStream dataStream = new DataOutputStream(byteStream); + PortReference returnEndpoint = new PortReference(from.toString()); - epr.setFrom(from); - epr.setFaultTo(from); - epr.setReplyTo(from); - epr.setAction(SenderPluginImpl._action); + epr.setFrom(returnEndpoint); + epr.setFaultTo(returnEndpoint); + epr.setReplyTo(returnEndpoint); + epr.setAction(SenderPluginImpl._action); + + // TODO remove magic strings and numbers! + + epr.setMessageID(new URI(new String("tcp:msgid:"+System.currentTimeMillis()))); - byte[] header = msg.getHeader().toBytes(); + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + + Document doc = builder.newDocument(); + + msg.toXML(doc); + + StringWriter sWriter = new StringWriter(); + OutputFormat format = new OutputFormat(); + format.setIndenting(true); - dataStream.writeInt(header.length); - dataStream.write(header, 0, header.length); - dataStream.writeInt(contents.length); - dataStream.write(contents, 0, contents.length); + XMLSerializer xmlS = new XMLSerializer(sWriter, format); + + xmlS.asDOMSerializer(); + xmlS.serialize(doc); + + String documentAsString = sWriter.toString(); + byte[] docAsBytes = documentAsString.getBytes(); + + dataStream.writeInt(docAsBytes.length); + dataStream.write(docAsBytes, 0, docAsBytes.length); dataStream.flush(); byteStream.writeTo(sender.getOutputStream()); + byteStream.flush(); sender.close(); } @@ -111,7 +141,14 @@ } catch (MalformedURLException ex) { - throw new InvalidParameterException("Malformed URL "+msg.getHeader().getEPR().getTo()); + try + { + throw new InvalidParameterException("Malformed URL "+msg.getHeader().getEPR().getTo()); + } + catch (Exception exp) + { + throw new InvalidParameterException("Malformed URL"); + } } catch (IOException ex) { @@ -121,6 +158,12 @@ { throw new SendFailedException(ex); } + catch (Exception ex) + { + ex.printStackTrace(); + + throw new SendFailedException(ex); + } } public void sendAsync (Message msg) throws ProtocolNotSupportedException Modified: labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Attachment.java =================================================================== --- labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Attachment.java 2006-05-04 10:47:38 UTC (rev 4087) +++ labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Attachment.java 2006-05-04 13:12:55 UTC (rev 4088) @@ -1,5 +1,9 @@ package org.jboss.soa.esbcore.messaging; +import org.jboss.soa.esbcore.addressing.EPR; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + /* * JBoss, Home of Professional Open Source * Copyright 2006, JBoss Inc., and others contributors as indicated @@ -30,4 +34,17 @@ public class Attachment { + public Element toXML (Document doc, Element envelope) + { + Element attachmentElement = doc.createElement("attachment"); + + envelope.appendChild(attachmentElement); + + return attachmentElement; + } + + public void fromXML (Element envelope) + { + } + } Modified: labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Body.java =================================================================== --- labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Body.java 2006-05-04 10:47:38 UTC (rev 4087) +++ labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Body.java 2006-05-04 13:12:55 UTC (rev 4088) @@ -2,6 +2,12 @@ import java.security.InvalidParameterException; +import org.jboss.soa.esbcore.addressing.EPR; +import org.w3c.dom.CDATASection; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + /* * JBoss, Home of Professional Open Source * Copyright 2006, JBoss Inc., and others contributors as indicated @@ -34,6 +40,34 @@ _content = null; } + public Element toXML (Document doc, Element envelope) + { + Element bodyElement = doc.createElement("body"); + + envelope.appendChild(bodyElement); + + bodyElement.appendChild(doc.createCDATASection(new String(_content))); + + return bodyElement; + } + + public void fromXML (Element envelope) + { + NodeList nl = envelope.getChildNodes(); + + for (int i = 0; i < nl.getLength(); i++) + { + if (nl.item(i).getNodeName().equals("body")) + { + CDATASection cdata = (CDATASection) nl.item(i).getFirstChild(); + + _content = cdata.getWholeText().getBytes(); + + break; + } + } + } + public void setContents (byte[] content) { _content = content; Modified: labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Context.java =================================================================== --- labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Context.java 2006-05-04 10:47:38 UTC (rev 4087) +++ labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Context.java 2006-05-04 13:12:55 UTC (rev 4088) @@ -1,5 +1,9 @@ package org.jboss.soa.esbcore.messaging; +import org.jboss.soa.esbcore.addressing.EPR; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + /* * JBoss, Home of Professional Open Source * Copyright 2006, JBoss Inc., and others contributors as indicated @@ -23,4 +27,16 @@ public class Context { + public Element toXML (Document doc, Element envelope) + { + Element contextElement = doc.createElement("context"); + + envelope.appendChild(contextElement); + + return contextElement; + } + + public void fromXML (Element envelope) + { + } } \ No newline at end of file Modified: labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Fault.java =================================================================== --- labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Fault.java 2006-05-04 10:47:38 UTC (rev 4087) +++ labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Fault.java 2006-05-04 13:12:55 UTC (rev 4088) @@ -1,5 +1,9 @@ package org.jboss.soa.esbcore.messaging; +import org.jboss.soa.esbcore.addressing.EPR; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + /* * JBoss, Home of Professional Open Source * Copyright 2006, JBoss Inc., and others contributors as indicated @@ -23,4 +27,17 @@ public class Fault { + public Element toXML (Document doc, Element envelope) + { + Element faultElement = doc.createElement("fault"); + + envelope.appendChild(faultElement); + + return faultElement; + } + + public void fromXML (Element envelope) + { + } + } \ No newline at end of file Modified: labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Header.java =================================================================== --- labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Header.java 2006-05-04 10:47:38 UTC (rev 4087) +++ labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Header.java 2006-05-04 13:12:55 UTC (rev 4088) @@ -22,6 +22,11 @@ */ import org.jboss.soa.esbcore.addressing.EPR; +import org.jboss.soa.esbcore.addressing.EPR; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; /** * The message header. Contains such things as routing information. @@ -46,10 +51,40 @@ _epr = addr; } - public byte[] toBytes () + public Element toXML (Document doc, Element envelope) { - return _epr.toBytes(); + // TODO remove MAGIC strings!! + + Element headerElement = doc.createElement("header"); + + envelope.appendChild(headerElement); + + return _epr.toXML(doc, headerElement); } + public void fromXML (Element envelope) + { + _epr = new EPR(); + + NodeList nl = envelope.getChildNodes(); + Element headerElement = null; + + for (int i = 0; i < nl.getLength(); i++) + { + Node n = nl.item(i); + + if (n.getNodeName().equals("header")) + { + headerElement = (Element) n; + break; + } + } + + // TODO error handling!! + + if (headerElement != null) + _epr.fromXML(headerElement); + } + private EPR _epr; } \ No newline at end of file Modified: labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Message.java =================================================================== --- labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Message.java 2006-05-04 10:47:38 UTC (rev 4087) +++ labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/messaging/Message.java 2006-05-04 13:12:55 UTC (rev 4088) @@ -1,5 +1,17 @@ package org.jboss.soa.esbcore.messaging; +import org.jboss.soa.esbcore.addressing.EPR; +import org.w3c.dom.DOMImplementation; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.bootstrap.DOMImplementationRegistry; +import org.w3c.dom.ls.DOMImplementationLS; +import org.w3c.dom.ls.LSSerializer; + +import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler; + /* * JBoss, Home of Professional Open Source * Copyright 2006, JBoss Inc., and others contributors as indicated @@ -88,6 +100,66 @@ return _theAttachment; } + // to/from XML here, rather than on individual elements + + public Document toXML (Document doc) + { + try + { + // TODO remove magic strings! + + Element envelope = doc.createElement("envelope"); + + doc.appendChild(envelope); + + _theHeader.toXML(doc, envelope); + _theContext.toXML(doc, envelope); + _theBody.toXML(doc, envelope); + _theFault.toXML(doc, envelope); + _theAttachment.toXML(doc, envelope); + + return doc; + } + catch (Exception ex) + { + // TODO error handling + + ex.printStackTrace(); + + return null; + } + } + + public void fromXML (Document doc) + { + try + { + NodeList nl = doc.getChildNodes(); + Element envelope = null; + + for (int i = 0; i < nl.getLength(); i++) + { + Node n = nl.item(i); + + if (n.getNodeName().equals("envelope")) + { + envelope = (Element) n; + break; + } + } + + _theHeader.fromXML(envelope); + _theContext.fromXML(envelope); + _theBody.fromXML(envelope); + _theFault.fromXML(envelope); + _theAttachment.fromXML(envelope); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + private Header _theHeader = new Header(); private Context _theContext = new Context(); private Body _theBody = new Body(); Modified: labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/tests/tcp/TcpClient.java =================================================================== --- labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/tests/tcp/TcpClient.java 2006-05-04 10:47:38 UTC (rev 4087) +++ labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/tests/tcp/TcpClient.java 2006-05-04 13:12:55 UTC (rev 4088) @@ -2,6 +2,7 @@ import java.net.URI; +import org.jboss.soa.esbcore.addressing.EPR; import org.jboss.soa.esbcore.contract.basic.DispatcherContractImpl; import org.jboss.soa.esbcore.contract.basic.client.ClientPluginContractImpl; import org.jboss.soa.esbcore.contract.basic.client.ContractDefinitionImpl; @@ -12,7 +13,6 @@ import org.jboss.soa.esbcore.messaging.Body; import org.jboss.soa.esbcore.plugin.infrastructure.DispatcherFactory; import org.jboss.soa.esbcore.plugin.infrastructure.sender.SenderPluginFactory; -import org.jboss.soa.internal.esbcore.addressing.EPRImpl; /* * JBoss, Home of Professional Open Source @@ -79,7 +79,7 @@ * Create a reference to the endpoint service we want to talk to. */ - EPRImpl epr = new EPRImpl(destination); + EPR epr = new EPR(destination); /* * Now create the contract definition we need to assemble the right components Modified: labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/tests/tcp/TcpService.java =================================================================== --- labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/tests/tcp/TcpService.java 2006-05-04 10:47:38 UTC (rev 4087) +++ labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/esbcore/tests/tcp/TcpService.java 2006-05-04 13:12:55 UTC (rev 4088) @@ -2,6 +2,7 @@ import java.net.URI; +import org.jboss.soa.esbcore.addressing.EPR; import org.jboss.soa.esbcore.contract.basic.DispatcherContractImpl; import org.jboss.soa.esbcore.contract.basic.service.ServicePluginContractImpl; import org.jboss.soa.esbcore.contract.basic.service.ContractDefinitionImpl; @@ -12,7 +13,6 @@ import org.jboss.soa.esbcore.messaging.Body; import org.jboss.soa.esbcore.plugin.infrastructure.DispatcherFactory; import org.jboss.soa.esbcore.plugin.infrastructure.receiver.ReceiverPluginFactory; -import org.jboss.soa.internal.esbcore.addressing.EPRImpl; /* * JBoss, Home of Professional Open Source @@ -132,7 +132,7 @@ try { - EPRImpl from = new EPRImpl(); + EPR from = new EPR(); Body payload = httpServicePlugin.receive(from); String message = new String(payload.getContents()); Deleted: labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/internal/esbcore/addressing/EPRImpl.java =================================================================== --- labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/internal/esbcore/addressing/EPRImpl.java 2006-05-04 10:47:38 UTC (rev 4087) +++ labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/internal/esbcore/addressing/EPRImpl.java 2006-05-04 13:12:55 UTC (rev 4088) @@ -1,191 +0,0 @@ -package org.jboss.soa.internal.esbcore.addressing; - -/* - * JBoss, Home of Professional Open Source - * Copyright 2006, JBoss Inc., and others contributors as indicated - * by the @authors tag. All rights reserved. - * See the copyright.txt in the distribution for a - * full listing of individual contributors. - * This copyrighted material is made available to anyone wishing to use, - * modify, copy, or redistribute it subject to the terms and conditions - * of the GNU Lesser General Public License, v. 2.1. - * This program is distributed in the hope that it will be useful, but WITHOUT A - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * You should have received a copy of the GNU Lesser General Public License, - * v.2.1 along with this distribution; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - * - * (C) 2005-2006, - * @author mar...@jb... - */ - -import org.jboss.soa.esbcore.addressing.EPR; - -/** - * This class represents the endpoint reference for services. - */ - -import java.net.URI; - -public class EPRImpl implements EPR -{ - public EPRImpl () - { - this(null); - } - - public EPRImpl (URI uri) - { - _to = uri; - _from = _replyTo = _faultTo = _action = _messageID = null; - } - - public void setTo (URI uri) - { - _to = uri; - } - - public URI getTo () - { - return _to; - } - - public void setFrom (URI uri) - { - _from = uri; - } - - public URI getFrom () - { - return _from; - } - - public void setReplyTo (URI uri) - { - _replyTo = uri; - } - public URI getReplyTo () - { - return _replyTo; - } - - public void setFaultTo (URI uri) - { - _faultTo = uri; - } - - public URI getFaultTo () - { - return _faultTo; - } - - public void setAction (URI uri) - { - _action = uri; - } - - public URI getAction () - { - return _action; - } - - public void setMessageID (URI uri) - { - _messageID = uri; - } - - public URI getMessageID () - { - return _messageID; - } - - public void copy (EPR from) - { - _to = from.getTo(); - _from = from.getFrom(); - _replyTo = from.getReplyTo(); - _faultTo = from.getFaultTo(); - _action = from.getAction(); - } - -// public void setMetaData (MetaData md); -// public MetaData getMetaData (); -// public void addReferenceParameter (...); - - public String toString () - { - return "To: "+_to+" From: "+_from+" ReplyTo: "+_replyTo+" FaultTo: "+_faultTo+" Action: "+_action; - } - - /* - * In lieu of toXML and fromXML - * - * @see org.jboss.soa.esbcore.addressing.EPR#toBytes() - */ - - public byte[] toBytes () - { - return toString().getBytes(); - } - - public void fromBytes (byte[] buff) - { - String fullBuffer = new String(buff); - - try - { - int fromStart = fullBuffer.indexOf(" From: "); - String toField = fullBuffer.substring(0, fromStart); - - if (!toField.equals("null")) - { - _to = new URI(toField.substring(4)); - } - - int replyToStart = fullBuffer.indexOf(" ReplyTo: ", fromStart); - String fromField = fullBuffer.substring(fromStart+7, replyToStart); - - if (!fromField.equals("null")) - { - _from = new URI(fromField.substring(7)); - } - - int faultToStart = fullBuffer.indexOf(" FaultTo: ", replyToStart); - String replyToField = fullBuffer.substring(replyToStart+10, faultToStart); - - if (!replyToField.equals("null")) - { - _replyTo = new URI(replyToField.substring(0)); - } - - int actionStart = fullBuffer.indexOf(" Action: ", faultToStart); - String faultToField = fullBuffer.substring(faultToStart+10, actionStart); - - if (!faultToField.equals("null")) - { - _faultTo = new URI(faultToField.substring(0)); - } - - String actionField = fullBuffer.substring(actionStart+9); - - if (!actionField.equals("null")) - { - _action = new URI(actionField.substring(0)); - } - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } - - private URI _to; - private URI _from; - private URI _replyTo; - private URI _faultTo; - private URI _action; - private URI _messageID; - -} \ No newline at end of file Added: labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/internal/esbcore/addressing/PortReferenceHelper.java =================================================================== --- labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/internal/esbcore/addressing/PortReferenceHelper.java 2006-05-04 10:47:38 UTC (rev 4087) +++ labs/jbossesb/trunk/ESBCore/classes/org/jboss/soa/internal/esbcore/addressing/PortReferenceHelper.java 2006-05-04 13:12:55 UTC (rev 4088) @@ -0,0 +1,373 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2006, JBoss Inc., and others contributors as indicated + * by the @authors tag. All rights reserved. + * See the copyright.txt in the distribution for a + * full listing of individual contributors. + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License, v. 2.1. + * This program is distributed in the hope that it will be useful, but WITHOUT A + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License, + * v.2.1 along with this distribution; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * (C) 2005-2006, + * @author mar...@jb... + */ + +/* + * Copyright (c) 2002, 2003, Arjuna Technologies Limited. + * + * PortReferenceHelper.java + */ + +package org.jboss.soa.internal.esbcore.addressing; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.HashMap; +import java.util.Map; + +import org.w3c.dom.Attr; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; + +import org.jboss.soa.esbcore.addressing.PortReference; +import org.jboss.soa.esbcore.addressing.XMLUtil; +import org.jboss.soa.esbcore.addressing.PortReference.Extension; +import org.jboss.soa.esbcore.exceptions.MarshalException; + +/* + * This should pack the PortReference into an ERP. + * + * It would be better if PortReference had a packToXML and unpackFromXML. + * + * This needs rewriting after the interoperability workshop! + */ + +public class PortReferenceHelper { + /** + * WS-Addressing is broken in that the To field is a URI, even if the From + * field was an EPR! You have to use the EPR bits separately. So, the + * toField is used to indicate whether we are packing this address as a To + * field (when we need to treat it differently) or as an EPR. + */ + + /** ************************************************** */ + public static void toXML(org.w3c.dom.Element header, + org.w3c.dom.Document document, + org.w3c.dom.Element portReferenceElement, + PortReference portReference, boolean toField) + throws MarshalException { + try { + if (!toField) { + Element addressElement = document.createElementNS( + XMLUtil.WSA_NAMESPACE_URI, XMLUtil.ADDRESS_TAG); + addressElement.setPrefix(XMLUtil.WSA_PREFIX); + addressElement.appendChild(document + .createTextNode(portReference.getAddress())); + portReferenceElement.appendChild(addressElement); + } else { + portReferenceElement.appendChild(document + .createTextNode(portReference.getAddress())); + } + + Iterator extensions = portReference.getExtensions(); + Element referenceProperties = null; + + while (extensions.hasNext()) { + PortReference.Extension extension = (PortReference.Extension) extensions + .next(); + + /* + * WS-Addressing is broken in that the To field is a URI, even + * if the From field was an EPR! You have to use the EPR bits + * separately. Doh! + */ + + if (!toField) { + if (referenceProperties == null) { + referenceProperties = document.createElementNS( + XMLUtil.WSA_NAMESPACE_URI, + XMLUtil.REFERENCE_PROPERTIES_TAG); + referenceProperties.setPrefix(XMLUtil.WSA_PREFIX); + portReferenceElement.appendChild(referenceProperties); + } + } else + referenceProperties = header; + + extensionToXML(referenceProperties, document, extension); + } + } catch (Exception exception) { + exception.printStackTrace(); + throw new MarshalException("Marshal failure: " + exception); + } + } + + /** **************************** */ + public static PortReference fromXML(org.w3c.dom.Element portReferenceElement, boolean toField) + throws MarshalException { + PortReference portReference = new PortReference();; + + if (toField) + portReference.setAddress(portReferenceElement.getTextContent()); + + org.w3c.dom.NodeList elements = portReferenceElement.getChildNodes(); + + for (int i = 1; i < elements.getLength(); i++) { + final Object extensionObject = elements.item(i); + + if (extensionObject instanceof Element) { + int parentNodeType = PortReference.Extension.NEITHER; + Element extensionElement = (Element) extensionObject; + NodeList children = extensionElement.getChildNodes(); + String parentName = extensionElement.getNodeName(); + boolean haveChildren = false; + + if (parentName.equals(XMLUtil.REFERENCE_PROPERTIES_TAG)) + parentNodeType = PortReference.Extension.REFERENCE_PROPERTIES; + else { + if (parentName.equals(XMLUtil.REFERENCE_PARAMETERS_TAG)) + parentNodeType = PortReference.Extension.REFERENCE_PARAMETERS; + else + { + if (!toField && parentName.equals(XMLUtil.WSA_PREFIX+":"+XMLUtil.ADDRESS_TAG)) + { + portReference.setAddress(extensionElement.getTextContent()); + } + } + } + + final int numChildren = children.getLength(); + for (int count = 0; count < numChildren; count++) { + final Object childObject = children.item(count); + + if (childObject instanceof Element) { + Element childElement = (Element) childObject; + portReference + .addExtension(childrenFromXML(childElement)); + haveChildren = true; + } + } + + if (!haveChildren) { + PortReference.Extension ext = new PortReference.Extension( + extensionElement.getNodeName(), null, null, + extensionElement.getNodeValue(), parentNodeType); + + portReference.addExtension(ext); + + final NamedNodeMap attrs = extensionElement.getAttributes(); + final int numAttrs = attrs.getLength(); + if (numAttrs > 0) { + final HashMap p = new HashMap(); + for (int count = 0; count < numAttrs; count++) { + final Attr attr = (Attr) attrs.item(count); + if (!"http://www.w3.org/2000/xmlns/".equals(attr + .getNamespaceURI())) { + final ArjunaName name = generateName(attr); + p.put(name, attr.getValue()); + } + } + + ext.addAttributes(p); + } + } + } + } + + return portReference; + } + + private final static PortReference.Extension childrenFromXML( + Element childRoot) { + final NodeList children = childRoot.getChildNodes(); + final int numChildNodes = children.getLength(); + + final PortReference.Extension extension; + if (numChildNodes > 0) { + Object childObject = children.item(0); + if (childObject instanceof Element) { + extension = new PortReference.Extension(childRoot + .getNodeName(), childRoot.getPrefix(), childRoot + .getNamespaceURI()); + for (int count = 1; count < numChildNodes; count++) { + extension.addChild(childrenFromXML((Element) childObject)); + childObject = children.item(count); + } + } else { + extension = new PortReference.Extension(childRoot + .getNodeName(), childRoot.getPrefix(), childRoot + .getNamespaceURI(), ((Node) childObject).getNodeValue()); + } + } else { + extension = new PortReference.Extension(childRoot.getNodeName(), + childRoot.getPrefix(), childRoot.getNamespaceURI(), + childRoot.getNodeValue()); + } + + final NamedNodeMap attrs = childRoot.getAttributes(); + final int numAttrs = attrs.getLength(); + if (numAttrs > 0) { + final HashMap p = new HashMap(); + for (int count = 0; count < numAttrs; count++) { + final Attr attr = (Attr) attrs.item(count); + if (!"http://www.w3.org/2000/xmlns/".equals(attr + .getNamespaceURI())) { + final ArjunaName name = generateName(attr); + p.put(name, attr.getValue()); + } + } + + extension.addAttributes(p); + } + return extension; + } + + private final static Element extensionToXML(Element packInto, + org.w3c.dom.Document document, PortReference.Extension toPack) + throws MarshalException { + final String uri = toPack.getURI(); + final Element element; + if (uri == null) { + element = document.createElement(toPack.getTag()); + } else { + final String prefix = toPack.getPrefix(); + element = document.createElementNS(uri, toPack.getTag()); + element.setPrefix(prefix); + element.setAttributeNS(XMLUtil.XMLNS_URI, XMLUtil.XMLNS_PREFIX + + toPack.getPrefix(), uri); + } + packInto.appendChild(element); + + if (toPack.getValue() != null) { + final Text text = document.createTextNode(toPack.getValue()); + element.appendChild(text); + } + + LinkedList extensions = toPack.getChildren(); + + if (extensions != null) { + for (int i = 0; i < extensions.size(); i++) { + PortReference.Extension ext = (PortReference.Extension) extensions + .get(i); + + extensionToXML(element, document, ext); + } + } + + HashMap attrs = toPack.getAttributes(); + + if (attrs != null) { + Iterator names = attrs.entrySet().iterator(); + + while (names.hasNext()) { + Map.Entry entry = (Map.Entry) names.next(); + ArjunaName name = (ArjunaName) entry.getKey(); + final String value = (String) entry.getValue(); + final String attrURI = name.toString(); + if (attrURI != null) { + element.setAttributeNS(attrURI, name.getQualifiedName(), + value); + } else { + element.setAttribute(name.getQualifiedName(), value); + } + } + } + + return element; + } + + /** + * Generate a name based on the attribute. + * + * @param attr + * The current attribute. + * @return The name + */ + private static ArjunaName generateName(final Attr attr) { + final String localName = attr.getNodeName(); + final String uri = attr.getNamespaceURI(); + final String prefix = attr.getPrefix(); + + return new ArjunaName(uri, prefix, localName); + } + + private static class ArjunaName + { + /** + * The uri. + */ + private final String uri; + + /** + * The prefix. + */ + private final String prefix; + + /** + * The local name. + */ + private... [truncated message content] |