qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kw...@apache.org
Subject svn commit: r1436876 - in /qpid/proton/branches/jni-binding: proton-c/bindings/java/ proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/ proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/jni/ proton-j/proton-api/sr...
Date Tue, 22 Jan 2013 12:43:22 GMT
Author: kwall
Date: Tue Jan 22 12:43:21 2013
New Revision: 1436876

URL: http://svn.apache.org/viewvc?rev=1436876&view=rev
Log:
PROTON-193: Add setPeerHostname/getPeerHostname to Proton Java API and implement with JNI
layer only. Test SslTest.test_server_hostname_authentication now
no longer skips when run with proton-c profile.

Added:
    qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/jni/ExceptionHelper.java
      - copied, changed from r1436875, qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/TransportException.java
    qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/jni/JNIException.java
      - copied, changed from r1436875, qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/ProtonException.java
    qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/ProtonException.java
      - copied, changed from r1436875, qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/ProtonException.java
    qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/ProtonUnsupportedOperationException.java
      - copied, changed from r1436875, qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/TransportException.java
Removed:
    qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/ProtonException.java
Modified:
    qpid/proton/branches/jni-binding/proton-c/bindings/java/java.i
    qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISsl.java
    qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISslDomain.java
    qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/Ssl.java
    qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/TransportException.java
    qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/scripts/proton.py
    qpid/proton/branches/jni-binding/proton-j/proton/src/main/java/org/apache/qpid/proton/engine/impl/ssl/SslDomainImpl.java
    qpid/proton/branches/jni-binding/proton-j/proton/src/main/java/org/apache/qpid/proton/engine/impl/ssl/SslImpl.java

Modified: qpid/proton/branches/jni-binding/proton-c/bindings/java/java.i
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-c/bindings/java/java.i?rev=1436876&r1=1436875&r2=1436876&view=diff
==============================================================================
--- qpid/proton/branches/jni-binding/proton-c/bindings/java/java.i (original)
+++ qpid/proton/branches/jni-binding/proton-c/bindings/java/java.i Tue Jan 22 12:43:21 2013
@@ -425,7 +425,8 @@ bool pn_ssl_get_cipher_name(pn_ssl_t *ss
 bool pn_ssl_get_protocol_name(pn_ssl_t *ssl, char *DATA, size_t SIZE);
 %ignore pn_ssl_get_protocol_name;
 
-
+int pn_ssl_get_peer_hostname(pn_ssl_t *ssl, char *DATA, size_t *SIZE);
+%ignore pn_ssl_get_peer_hostname;
 
 
 %include "proton/cproton.i"

Modified: qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISsl.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISsl.java?rev=1436876&r1=1436875&r2=1436876&view=diff
==============================================================================
--- qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISsl.java
(original)
+++ qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISsl.java
Tue Jan 22 12:43:21 2013
@@ -21,6 +21,8 @@
 
 package org.apache.qpid.proton.engine.jni;
 
+import static org.apache.qpid.proton.jni.ExceptionHelper.checkProtonCReturnValue;
+
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
 
@@ -52,7 +54,14 @@ class JNISsl implements Ssl
     {
         int i = -1;
         while(data[++i] != 0);
-        return new String(data,0,i,Charset.forName("US-ASCII"));
+        if(i == 0)
+        {
+            return null;
+        }
+        else
+        {
+            return new String(data,0,i,Charset.forName("US-ASCII"));
+        }
     }
 
     @Override
@@ -63,4 +72,20 @@ class JNISsl implements Ssl
         boolean b = Proton.pn_ssl_get_protocol_name(_impl, ByteBuffer.wrap(data));
         return b ? asString(data) : null;
     }
+
+    @Override
+    public void setPeerHostname(String hostname)
+    {
+        int retVal = Proton.pn_ssl_set_peer_hostname(_impl, hostname);
+        checkProtonCReturnValue(retVal);
+    }
+
+    @Override
+    public String getPeerHostname()
+    {
+        byte[] data = new byte[256]; // hostnames are a maximum of 255 characters long (see
http://tools.ietf.org/html/rfc1034#section-3.1)
+        int retVal = Proton.pn_ssl_get_peer_hostname(_impl, ByteBuffer.wrap(data));
+        checkProtonCReturnValue(retVal);
+        return asString(data);
+    }
 }

Modified: qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISslDomain.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISslDomain.java?rev=1436876&r1=1436875&r2=1436876&view=diff
==============================================================================
--- qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISslDomain.java
(original)
+++ qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/engine/jni/JNISslDomain.java
Tue Jan 22 12:43:21 2013
@@ -19,12 +19,10 @@
  */
 package org.apache.qpid.proton.engine.jni;
 
-import java.util.logging.Level;
-import java.util.logging.Logger;
+import static org.apache.qpid.proton.jni.ExceptionHelper.checkProtonCReturnValue;
 
 import org.apache.qpid.proton.ProtonCEquivalent;
 import org.apache.qpid.proton.engine.SslDomain;
-import org.apache.qpid.proton.engine.TransportException;
 import org.apache.qpid.proton.jni.Proton;
 import org.apache.qpid.proton.jni.SWIGTYPE_p_pn_ssl_domain_t;
 import org.apache.qpid.proton.jni.pn_ssl_mode_t;
@@ -32,8 +30,6 @@ import org.apache.qpid.proton.jni.pn_ssl
 
 public class JNISslDomain implements SslDomain
 {
-    private static final Logger LOGGER = Logger.getLogger(JNISslDomain.class.getName());
-
     private SWIGTYPE_p_pn_ssl_domain_t _impl;
     private Mode _mode;
     private VerifyMode _verifyMode;
@@ -83,18 +79,6 @@ public class JNISslDomain implements Ssl
         checkProtonCReturnValue(retVal);
     }
 
-    private void checkProtonCReturnValue(int retVal)
-    {
-        if(retVal != 0)
-        {
-            if(LOGGER.isLoggable(Level.FINE))
-            {
-                LOGGER.log(Level.FINE, "Non-zero return value: " + retVal, new Exception("<dummy
exception to generate stack trace>"));
-            }
-            throw new TransportException("Unexpected return value: " + retVal);
-        }
-    }
-
     @Override
     public String getPrivateKeyFile()
     {

Copied: qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/jni/ExceptionHelper.java
(from r1436875, qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/TransportException.java)
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/jni/ExceptionHelper.java?p2=qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/jni/ExceptionHelper.java&p1=qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/TransportException.java&r1=1436875&r2=1436876&rev=1436876&view=diff
==============================================================================
--- qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/TransportException.java
(original)
+++ qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/jni/ExceptionHelper.java
Tue Jan 22 12:43:21 2013
@@ -1,5 +1,4 @@
 /*
- *
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -18,28 +17,29 @@
  * under the License.
  *
  */
+package org.apache.qpid.proton.jni;
 
-package org.apache.qpid.proton.engine;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
-public class TransportException extends ProtonException
+public class ExceptionHelper
 {
-    public TransportException()
-    {
-    }
-
-    public TransportException(String message)
-    {
-        super(message);
-    }
+    private static final Logger LOGGER = Logger.getLogger(ExceptionHelper.class.getName());
 
-    public TransportException(String message, Throwable cause)
+    /**
+     * Check the return value from a Proton function call and throw
+     * an exception if it's non-zero.
+     * @throws JNIException
+     */
+    public static void checkProtonCReturnValue(int retVal)
     {
-        super(message, cause);
+        if(retVal != 0)
+        {
+            if(LOGGER.isLoggable(Level.FINE))
+            {
+                LOGGER.log(Level.FINE, "Non-zero return value: " + retVal, new Exception("<dummy
exception to generate stack trace>"));
+            }
+            throw new JNIException(retVal);
+        }
     }
-
-    public TransportException(Throwable cause)
-    {
-        super(cause);
-    }
-
 }

Copied: qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/jni/JNIException.java
(from r1436875, qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/ProtonException.java)
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/jni/JNIException.java?p2=qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/jni/JNIException.java&p1=qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/ProtonException.java&r1=1436875&r2=1436876&rev=1436876&view=diff
==============================================================================
--- qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/ProtonException.java
(original)
+++ qpid/proton/branches/jni-binding/proton-c/bindings/java/jni/src/main/java/org/apache/qpid/proton/jni/JNIException.java
Tue Jan 22 12:43:21 2013
@@ -1,5 +1,4 @@
 /*
- *
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -18,28 +17,17 @@
  * under the License.
  *
  */
+package org.apache.qpid.proton.jni;
 
-package org.apache.qpid.proton.engine;
+import org.apache.qpid.proton.ProtonException;
 
-public class ProtonException extends RuntimeException
+/**
+ * Indicates that a Proton function called via JNI returned an error code.
+ */
+public class JNIException extends ProtonException
 {
-    public ProtonException()
-    {
-    }
-
-    public ProtonException(String message)
-    {
-        super(message);
-    }
-
-    public ProtonException(String message, Throwable cause)
-    {
-        super(message, cause);
-    }
-
-    public ProtonException(Throwable cause)
+    public JNIException(int returnValue)
     {
-        super(cause);
+        super("Unexpected Proton C return value: " + returnValue);
     }
-
 }

Copied: qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/ProtonException.java
(from r1436875, qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/ProtonException.java)
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/ProtonException.java?p2=qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/ProtonException.java&p1=qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/ProtonException.java&r1=1436875&r2=1436876&rev=1436876&view=diff
==============================================================================
--- qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/ProtonException.java
(original)
+++ qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/ProtonException.java
Tue Jan 22 12:43:21 2013
@@ -19,7 +19,7 @@
  *
  */
 
-package org.apache.qpid.proton.engine;
+package org.apache.qpid.proton;
 
 public class ProtonException extends RuntimeException
 {

Copied: qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/ProtonUnsupportedOperationException.java
(from r1436875, qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/TransportException.java)
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/ProtonUnsupportedOperationException.java?p2=qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/ProtonUnsupportedOperationException.java&p1=qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/TransportException.java&r1=1436875&r2=1436876&rev=1436876&view=diff
==============================================================================
--- qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/TransportException.java
(original)
+++ qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/ProtonUnsupportedOperationException.java
Tue Jan 22 12:43:21 2013
@@ -1,5 +1,4 @@
 /*
- *
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -18,26 +17,29 @@
  * under the License.
  *
  */
+package org.apache.qpid.proton;
 
-package org.apache.qpid.proton.engine;
-
-public class TransportException extends ProtonException
+/**
+ * Use to indicate that a feature of the Proton API is not supported by a particular implementation
+ * (e.g. proton-j or proton-c-via-JNI).
+ */
+public class ProtonUnsupportedOperationException extends UnsupportedOperationException
 {
-    public TransportException()
+    public ProtonUnsupportedOperationException()
     {
     }
 
-    public TransportException(String message)
+    public ProtonUnsupportedOperationException(String message)
     {
         super(message);
     }
 
-    public TransportException(String message, Throwable cause)
+    public ProtonUnsupportedOperationException(String message, Throwable cause)
     {
         super(message, cause);
     }
 
-    public TransportException(Throwable cause)
+    public ProtonUnsupportedOperationException(Throwable cause)
     {
         super(cause);
     }

Modified: qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/Ssl.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/Ssl.java?rev=1436876&r1=1436875&r2=1436876&view=diff
==============================================================================
--- qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/Ssl.java
(original)
+++ qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/Ssl.java
Tue Jan 22 12:43:21 2013
@@ -44,4 +44,8 @@ public interface Ssl
      * @return the name of the protocol in use, or null if none
      */
     String getProtocolName();
+
+    void setPeerHostname(String hostname);
+
+    String getPeerHostname();
 }

Modified: qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/TransportException.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/TransportException.java?rev=1436876&r1=1436875&r2=1436876&view=diff
==============================================================================
--- qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/TransportException.java
(original)
+++ qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/java/org/apache/qpid/proton/engine/TransportException.java
Tue Jan 22 12:43:21 2013
@@ -21,6 +21,8 @@
 
 package org.apache.qpid.proton.engine;
 
+import org.apache.qpid.proton.ProtonException;
+
 public class TransportException extends ProtonException
 {
     public TransportException()

Modified: qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/scripts/proton.py
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/scripts/proton.py?rev=1436876&r1=1436875&r2=1436876&view=diff
==============================================================================
--- qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/scripts/proton.py (original)
+++ qpid/proton/branches/jni-binding/proton-j/proton-api/src/main/scripts/proton.py Tue Jan
22 12:43:21 2013
@@ -18,7 +18,7 @@
 
 from uuid import UUID
 
-from org.apache.qpid.proton import ProtonFactoryLoader
+from org.apache.qpid.proton import ProtonFactoryLoader, ProtonUnsupportedOperationException
 from org.apache.qpid.proton.engine import \
     EngineFactory, Transport as JTransport, Sender as JSender, Receiver as JReceiver, \
     Sasl, SslDomain as JSslDomain, \
@@ -886,9 +886,17 @@ class SSL(object):
     return self._ssl.getProtocolName()
 
   def _set_peer_hostname(self, hostname):
-    raise Skipped()
+    try:
+      self._ssl.setPeerHostname(hostname)
+    except ProtonUnsupportedOperationException:
+      raise Skipped()
+
   def _get_peer_hostname(self):
-    raise Skipped()
+    try:
+      return self._ssl.getPeerHostname()
+    except ProtonUnsupportedOperationException:
+      raise Skipped()
+
   peer_hostname = property(_get_peer_hostname, _set_peer_hostname)
 
 __all__ = [

Modified: qpid/proton/branches/jni-binding/proton-j/proton/src/main/java/org/apache/qpid/proton/engine/impl/ssl/SslDomainImpl.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-j/proton/src/main/java/org/apache/qpid/proton/engine/impl/ssl/SslDomainImpl.java?rev=1436876&r1=1436875&r2=1436876&view=diff
==============================================================================
--- qpid/proton/branches/jni-binding/proton-j/proton/src/main/java/org/apache/qpid/proton/engine/impl/ssl/SslDomainImpl.java
(original)
+++ qpid/proton/branches/jni-binding/proton-j/proton/src/main/java/org/apache/qpid/proton/engine/impl/ssl/SslDomainImpl.java
Tue Jan 22 12:43:21 2013
@@ -18,6 +18,7 @@
  */
 package org.apache.qpid.proton.engine.impl.ssl;
 
+import org.apache.qpid.proton.ProtonUnsupportedOperationException;
 import org.apache.qpid.proton.engine.SslDomain;
 import org.apache.qpid.proton.engine.SslPeerDetails;
 
@@ -71,6 +72,10 @@ public class SslDomainImpl implements Ss
     @Override
     public void setPeerAuthentication(VerifyMode verifyMode)
     {
+        if(verifyMode == VerifyMode.VERIFY_PEER_NAME)
+        {
+            throw new ProtonUnsupportedOperationException();
+        }
         _verifyMode = verifyMode;
         _sslEngineFacadeFactory.resetCache();
     }

Modified: qpid/proton/branches/jni-binding/proton-j/proton/src/main/java/org/apache/qpid/proton/engine/impl/ssl/SslImpl.java
URL: http://svn.apache.org/viewvc/qpid/proton/branches/jni-binding/proton-j/proton/src/main/java/org/apache/qpid/proton/engine/impl/ssl/SslImpl.java?rev=1436876&r1=1436875&r2=1436876&view=diff
==============================================================================
--- qpid/proton/branches/jni-binding/proton-j/proton/src/main/java/org/apache/qpid/proton/engine/impl/ssl/SslImpl.java
(original)
+++ qpid/proton/branches/jni-binding/proton-j/proton/src/main/java/org/apache/qpid/proton/engine/impl/ssl/SslImpl.java
Tue Jan 22 12:43:21 2013
@@ -20,6 +20,7 @@
  */
 package org.apache.qpid.proton.engine.impl.ssl;
 
+import org.apache.qpid.proton.ProtonUnsupportedOperationException;
 import org.apache.qpid.proton.engine.Ssl;
 import org.apache.qpid.proton.engine.SslDomain;
 import org.apache.qpid.proton.engine.SslPeerDetails;
@@ -156,4 +157,24 @@ public class SslImpl implements Ssl
             }
         }
     }
+
+    /**
+     * {@inheritDoc}
+     * @throws ProtonUnsupportedOperationException
+     */
+    @Override
+    public void setPeerHostname(String hostname)
+    {
+        throw new ProtonUnsupportedOperationException();
+    }
+
+    /**
+     * {@inheritDoc}
+     * @throws ProtonUnsupportedOperationException
+     */
+    @Override
+    public String getPeerHostname()
+    {
+        throw new ProtonUnsupportedOperationException();
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message