PROTON-205: Set target and source correctly when establishing links

git-svn-id: https://svn.apache.org/repos/asf/qpid/proton/trunk@1441383 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/proton-j/proton/src/main/java/org/apache/qpid/proton/messenger/impl/MessengerImpl.java b/proton-j/proton/src/main/java/org/apache/qpid/proton/messenger/impl/MessengerImpl.java
index c3085d6..14fce6f 100644
--- a/proton-j/proton/src/main/java/org/apache/qpid/proton/messenger/impl/MessengerImpl.java
+++ b/proton-j/proton/src/main/java/org/apache/qpid/proton/messenger/impl/MessengerImpl.java
@@ -144,7 +144,7 @@
                 throw new MessengerException("unable to send to address: " + m.getAddress());
             }
             int port = address.getPort() < 0 ? defaultPort(address.getScheme()) : address.getPort();
-            Sender sender = getLink(address.getHost(), port, new SenderFinder(address.getPath()));
+            Sender sender = getLink(address.getHost(), port, new SenderFinder(cleanPath(address.getPath())));
 
             adjustReplyTo(m);
 
@@ -232,7 +232,7 @@
             }
             else
             {
-                getLink(address.getHost(), port, new ReceiverFinder(address.getPath()));
+                getLink(address.getHost(), port, new ReceiverFinder(cleanPath(address.getPath())));
             }
         }
         catch (URISyntaxException e)
@@ -688,7 +688,11 @@
 
         public Sender create(Session session)
         {
-            return session.sender(_path);
+            Sender sender = session.sender(_path);
+            Target target = new Target();
+            target.setAddress(_path);
+            sender.setTarget(target);
+            return sender;
         }
     }
 
@@ -715,7 +719,11 @@
 
         public Receiver create(Session session)
         {
-            return session.receiver(_path);
+            Receiver receiver = session.receiver(_path);
+            Source source = new Source();
+            source.setAddress(_path);
+            receiver.setSource(source);
+            return receiver;
         }
     }
 
@@ -876,6 +884,19 @@
         }
     }
 
+    private static String cleanPath(String path)
+    {
+        //remove leading '/'
+        if (path != null && path.length() > 0 && path.charAt(0) == '/')
+        {
+            return path.substring(1);
+        }
+        else
+        {
+            return path;
+        }
+    }
+
     private static boolean matchTarget(Target target, String path)
     {
         if (target == null) return path.isEmpty();