Author: mturk
Date: Tue Sep 20 09:09:09 2011
New Revision: 1173040
URL: http://svn.apache.org/viewvc?rev=1173040&view=rev
Log:
Add needed exceptions and disposable interface
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ClosedObjectException.java
(with props)
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Disposable.java
(with props)
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ObjectNotInitializedException.java
(with props)
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Mutex.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Semaphore.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/OperationNotSupportedException.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/LocalStrings.properties
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/NativePointer.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/PasswordCallback.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSL.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLBio.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCertificate.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLContext.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLEngine.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLKey.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLServer.java
commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h
commons/sandbox/runtime/trunk/src/main/native/modules/openssl/server.c
commons/sandbox/runtime/trunk/src/main/native/shared/error.c
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestOpenSSL.java
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ClosedObjectException.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ClosedObjectException.java?rev=1173040&view=auto
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ClosedObjectException.java
(added)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ClosedObjectException.java
Tue Sep 20 09:09:09 2011
@@ -0,0 +1,38 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime;
+
+/**
+ * ClosedObjectException thrown when an attempt is made to
+ * invoke an operation on closed operating system {@code object}.
+ *
+ * @since Runtime 1.0
+ */
+
+public class ClosedObjectException extends IllegalStateException
+{
+
+ public ClosedObjectException()
+ {
+ super();
+ }
+
+ public ClosedObjectException(String msg)
+ {
+ super(msg);
+ }
+}
Propchange:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ClosedObjectException.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Disposable.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Disposable.java?rev=1173040&view=auto
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Disposable.java
(added)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Disposable.java
Tue Sep 20 09:09:09 2011
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.commons.runtime;
+
+/**
+ * The base class for all classes offerering
+ * dispose method to it's child objects.
+ */
+public interface Disposable
+{
+
+ /**
+ * Release all of the native resources used by this object.
+ *
+ * @throws IllegalStateException if the object cannot be disposed.
+ */
+ public void dispose()
+ throws IllegalStateException;
+
+}
Propchange:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Disposable.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Mutex.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Mutex.java?rev=1173040&r1=1173039&r2=1173040&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Mutex.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Mutex.java
Tue Sep 20 09:09:09 2011
@@ -15,6 +15,7 @@
*/
package org.apache.commons.runtime;
+import java.io.Closeable;
import java.io.IOException;
/**
@@ -24,7 +25,7 @@ import java.io.IOException;
*
* @since Runtime 1.0
*/
-public abstract class Mutex
+public abstract class Mutex implements Closeable
{
protected Mutex()
@@ -132,6 +133,7 @@ public abstract class Mutex
* Closes the semaphore.
*
*/
+ @Override
public abstract void close()
throws IOException;
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ObjectNotInitializedException.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ObjectNotInitializedException.java?rev=1173040&view=auto
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ObjectNotInitializedException.java
(added)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ObjectNotInitializedException.java
Tue Sep 20 09:09:09 2011
@@ -0,0 +1,39 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime;
+
+/**
+ * ObjectNotInitializedException thrown when an attempt is made to
+ * invoke an operation on operating system {@code object} that wasn't
+ * initialized.
+ *
+ * @since Runtime 1.0
+ */
+
+public class ObjectNotInitializedException extends IllegalStateException
+{
+
+ public ObjectNotInitializedException()
+ {
+ super();
+ }
+
+ public ObjectNotInitializedException(String msg)
+ {
+ super(msg);
+ }
+}
Propchange:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ObjectNotInitializedException.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Semaphore.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Semaphore.java?rev=1173040&r1=1173039&r2=1173040&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Semaphore.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Semaphore.java
Tue Sep 20 09:09:09 2011
@@ -15,6 +15,7 @@
*/
package org.apache.commons.runtime;
+import java.io.Closeable;
import java.io.IOException;
/**
@@ -24,7 +25,7 @@ import java.io.IOException;
*
* @since Runtime 1.0
*/
-public abstract class Semaphore
+public abstract class Semaphore implements Closeable
{
protected Semaphore()
@@ -113,6 +114,7 @@ public abstract class Semaphore
* Closes the semaphore.
*
*/
+ @Override
public abstract void close()
throws IOException;
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/OperationNotSupportedException.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/OperationNotSupportedException.java?rev=1173040&r1=1173039&r2=1173040&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/OperationNotSupportedException.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/OperationNotSupportedException.java
Tue Sep 20 09:09:09 2011
@@ -19,7 +19,7 @@ import java.io.IOException;
/**
* OperationNotSupportedException is thrown when an attempt is made to
- * invoke an non supported operation.
+ * invoke an non supported I/O operation.
* This exception is usually thrown when the stream does not
* support read or write opperations.
*
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/LocalStrings.properties
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/LocalStrings.properties?rev=1173040&r1=1173039&r2=1173040&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/LocalStrings.properties
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/LocalStrings.properties
Tue Sep 20 09:09:09 2011
@@ -14,6 +14,7 @@
# limitations under the License.
openssl.EINIT=OpenSSL subsytem was not initialized
+openssl.ENOENGINE=OpenSSL has no ENGINE support
fips.ENOTIMPL=FIPS was not available at build time. You will need an OpenSSL
with FIPS support.
password.PROMPT=Some of your private key files are encrypted for security
reasons.\
\nIn order to read them you have to provide the pass phrases.\
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/NativePointer.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/NativePointer.java?rev=1173040&r1=1173039&r2=1173040&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/NativePointer.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/NativePointer.java
Tue Sep 20 09:09:09 2011
@@ -16,7 +16,7 @@
package org.apache.commons.runtime.ssl;
-import org.apache.commons.runtime.Callback;
+import org.apache.commons.runtime.Disposable;
/**
* Abstract native pointer envelope.
@@ -30,7 +30,7 @@ import org.apache.commons.runtime.Callba
* the correct native object.
* </p>
*/
-abstract class NativePointer
+abstract class NativePointer implements Disposable
{
public long pointer;
@@ -51,4 +51,7 @@ abstract class NativePointer
this.pointer = pointer;
}
+ @Override
+ public abstract void dispose()
+ throws IllegalStateException;
}
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/PasswordCallback.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/PasswordCallback.java?rev=1173040&r1=1173039&r2=1173040&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/PasswordCallback.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/PasswordCallback.java
Tue Sep 20 09:09:09 2011
@@ -114,6 +114,16 @@ public abstract class PasswordCallback
protected abstract String getPassword(String desc)
throws Exception;
+ @Override
+ public synchronized final void dispose()
+ throws IllegalStateException
+ {
+ if (super.pointer != 0L) {
+ del0(super.pointer);
+ super.pointer = 0L;
+ }
+ }
+
/**
* Called by the garbage collector when the object is destroyed.
* The class will free internal resources allocated by the
@@ -127,7 +137,7 @@ public abstract class PasswordCallback
protected final void finalize()
throws Throwable
{
- del0(super.pointer);
+ dispose();
}
}
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSL.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSL.java?rev=1173040&r1=1173039&r2=1173040&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSL.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSL.java
Tue Sep 20 09:09:09 2011
@@ -17,6 +17,7 @@
package org.apache.commons.runtime.ssl;
import org.apache.commons.runtime.InvalidArgumentException;
+import org.apache.commons.runtime.OperationNotImplementedException;
import org.apache.commons.runtime.Status;
import org.apache.commons.runtime.SystemException;
@@ -68,14 +69,16 @@ public final class SSL
public static native boolean hasFipsMode();
public static void enableFipsMode(boolean enable)
- throws IllegalStateException,
+ throws RuntimeException,
UnsupportedOperationException
{
- if (!hasFipsMode())
- throw new
UnsupportedOperationException(Local.sm.get("fips.ENOTIMPL"));
- if (!inited)
- throw new IllegalStateException();
- fipsmode0(enable);
+ synchronized(lock) {
+ if (!inited)
+ throw new RuntimeException(Local.sm.get("openssl.EINIT"));
+ if (!hasFipsMode())
+ throw new
UnsupportedOperationException(Local.sm.get("fips.ENOTIMPL"));
+ fipsmode0(enable);
+ }
}
}
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLBio.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLBio.java?rev=1173040&r1=1173039&r2=1173040&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLBio.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLBio.java
Tue Sep 20 09:09:09 2011
@@ -48,6 +48,13 @@ public abstract class SSLBio extends Nat
super.pointer = new0(this);
}
+ @Override
+ public synchronized void dispose()
+ throws IllegalStateException
+ {
+ close0(super.pointer);
+ super.pointer = 0L;
+ }
/**
* Free the allocated resource by the Operating system.
* <p>
@@ -61,8 +68,7 @@ public abstract class SSLBio extends Nat
public final void close()
throws IOException
{
- close0(super.pointer);
- super.pointer = 0L;
+ dispose();
}
/**
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCertificate.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCertificate.java?rev=1173040&r1=1173039&r2=1173040&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCertificate.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLCertificate.java
Tue Sep 20 09:09:09 2011
@@ -92,7 +92,9 @@ public final class SSLCertificate extend
return format;
}
- public synchronized void free()
+ @Override
+ public synchronized void dispose()
+ throws IllegalStateException
{
if (super.pointer != 0L) {
free0(super.pointer);
@@ -113,7 +115,7 @@ public final class SSLCertificate extend
protected final void finalize()
throws Throwable
{
- free();
+ dispose();
}
}
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLContext.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLContext.java?rev=1173040&r1=1173039&r2=1173040&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLContext.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLContext.java
Tue Sep 20 09:09:09 2011
@@ -19,6 +19,7 @@ package org.apache.commons.runtime.ssl;
import org.apache.commons.runtime.InvalidArgumentException;
import org.apache.commons.runtime.InvalidDataException;
import org.apache.commons.runtime.InvalidRangeException;
+import org.apache.commons.runtime.ObjectNotInitializedException;
import org.apache.commons.runtime.OperationNotImplementedException;
import org.apache.commons.runtime.Status;
import org.apache.commons.runtime.SystemException;
@@ -71,6 +72,7 @@ public final class SSLContext extends Na
*
* @throws OperationNotImplementedException if method or mode is not
* supported by the OpenSSL library.
+ * @throws RuntimeException if SSL was not initialized.
*/
public SSLContext(SSLProtocolMethod method, SSLProtocolMode mode)
throws OperationNotImplementedException
@@ -88,10 +90,10 @@ public final class SSLContext extends Na
* @param id unique context id string.
*/
public synchronized void setSessionContextId(String id)
- throws IllegalStateException, NullPointerException
+ throws ObjectNotInitializedException, NullPointerException
{
if (super.pointer == 0L)
- throw new IllegalStateException();
+ throw new ObjectNotInitializedException();
if (id == null)
throw new NullPointerException();
setid0(super.pointer, id);
@@ -102,13 +104,13 @@ public final class SSLContext extends Na
*
* @param size cache size to use. If {@code zero} the session
* cache is turned off.
- * @throws IllegalStateException if this context is closed.
+ * @throws ObjectNotInitializedException if this context is closed.
*/
public synchronized void setSessionCacheSize(int size)
- throws IllegalStateException
+ throws ObjectNotInitializedException
{
if (super.pointer == 0L)
- throw new IllegalStateException();
+ throw new ObjectNotInitializedException();
setscachesize0(super.pointer, size);
}
@@ -129,10 +131,10 @@ public final class SSLContext extends Na
* @param path PEM format file of CA's.
*/
public synchronized void setCACertificateFile(String path)
- throws SSLException, IllegalStateException
+ throws SSLException, ObjectNotInitializedException
{
if (super.pointer == 0L)
- throw new IllegalStateException();
+ throw new ObjectNotInitializedException();
if (path == null)
throw new NullPointerException();
setcafile0(super.pointer, path);
@@ -157,14 +159,14 @@ public final class SSLContext extends Na
* the verification of a peer certificate.
* </p>
* @param path PEM format directory of CA's.
- * @throws IllegalStateException if context is invalid
+ * @throws ObjectNotInitializedException if context is invalid
* @throws SSLException if path cannot be set
*/
public synchronized void setCACertificatePath(String path)
- throws SSLException, IllegalStateException
+ throws SSLException, ObjectNotInitializedException
{
if (super.pointer == 0L)
- throw new IllegalStateException();
+ throw new ObjectNotInitializedException();
if (path == null)
throw new NullPointerException();
setcapath0(super.pointer, path);
@@ -180,14 +182,14 @@ public final class SSLContext extends Na
* to {@code setCARevocationPath}.
*
* @param path file containg PEM-encoded CRL list.
- * @throws IllegalStateException if context is invalid
+ * @throws ObjectNotInitializedException if context is invalid
* @throws SSLException if path cannot be set.
*/
public synchronized void setCARevocationFile(String path)
- throws SSLException, IllegalStateException
+ throws SSLException, ObjectNotInitializedException
{
if (super.pointer == 0L)
- throw new IllegalStateException();
+ throw new ObjectNotInitializedException();
if (path == null)
throw new NullPointerException();
setcacrlfile0(super.pointer, path);
@@ -201,14 +203,14 @@ public final class SSLContext extends Na
* Authentication.
*
* @param path directory containg CRL list.
- * @throws IllegalStateException if context is invalid
+ * @throws ObjectNotInitializedException if context is invalid
* @throws SSLException if path cannot be set.
*/
public synchronized void setCARevocationPath(String path)
- throws SSLException, IllegalStateException
+ throws SSLException, ObjectNotInitializedException
{
if (super.pointer == 0L)
- throw new IllegalStateException();
+ throw new ObjectNotInitializedException();
if (path == null)
throw new NullPointerException();
setcacrlpath0(super.pointer, path);
@@ -222,14 +224,15 @@ public final class SSLContext extends Na
* must be configured before calling this method.
* </p>
* @param mode revocation mode to set.
- * @throws IllegalStateException if this context is invalid or if
- * neither setCARevocationFile or setCARevocationPath was set up.
+ * @throws ObjectNotInitializedException if context is invalid
+ * @throws IllegalStateException if neither setCARevocationFile or
+ * setCARevocationPath was set up before calling this method.
*/
public synchronized void setCARevocationCheck(SSLCARevocationCheckMode
mode)
- throws IllegalStateException
+ throws ObjectNotInitializedException
{
if (super.pointer == 0L)
- throw new IllegalStateException();
+ throw new ObjectNotInitializedException();
if (!has_crlset)
throw new IllegalStateException(Local.sm.get("sslctx.ENOCRLLOC"));
setcrlcheck0(super.pointer, mode.valueOf());
@@ -241,13 +244,13 @@ public final class SSLContext extends Na
* @param mode verification mode to use.
* @param depth sets the maximum depth for the certificate chain
* verification that shall be allowed for this context.
- * @throws IllegalStateException if context is invalid
+ * @throws ObjectNotInitializedException if context is invalid
*/
public synchronized void setClientVerification(SSLClientVerifyMode mode,
int depth)
- throws SSLException, IllegalStateException
+ throws SSLException, ObjectNotInitializedException
{
if (super.pointer == 0L)
- throw new IllegalStateException();
+ throw new ObjectNotInitializedException();
setvmode0(super.pointer, mode.valueOf(), depth);
}
@@ -272,10 +275,10 @@ public final class SSLContext extends Na
* @throws InvalidRangeException if the length of the prefix is too large.
*/
public synchronized void setSessionIdPrefix(String prefix)
- throws InvalidRangeException, IllegalStateException
+ throws InvalidRangeException, ObjectNotInitializedException
{
if (super.pointer == 0L)
- throw new IllegalStateException();
+ throw new ObjectNotInitializedException();
if (prefix.length() > 31)
throw new InvalidRangeException();
setsprefix0(super.pointer, prefix);
@@ -286,17 +289,18 @@ public final class SSLContext extends Na
* operating system.
* Closing the context will close all attached keys and certificates.
* After the context is closed furter attempts to use the context will
- * throw {@code IllegalStateException} exception.
+ * throw {@code ObjectNotInitializedException} exception.
*/
- public synchronized void free()
+ public synchronized void dispose()
+ throws IllegalStateException
{
for (int i = 0; i < keys.length; i++) {
if (keys[i] != null) {
- keys[i].free();
+ keys[i].dispose();
keys[i] = null;
}
if (cert[i] != null) {
- cert[i].free();
+ cert[i].dispose();
cert[i] = null;
}
}
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLEngine.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLEngine.java?rev=1173040&r1=1173039&r2=1173040&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLEngine.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLEngine.java
Tue Sep 20 09:09:09 2011
@@ -73,10 +73,26 @@ public final class SSLEngine extends Nat
public SSLEngine(String name)
throws SystemException
{
+ if (!initialized()) {
+ throw new RuntimeException(Local.sm.get("openssl.ENOENGINE"));
+ }
super.pointer = init0(name);
}
/**
+ * Close this engine and free resources allocated by the
+ * operating system.
+ */
+ public synchronized void dispose()
+ throws IllegalStateException
+ {
+ if (super.pointer != 0L) {
+ free0(super.pointer);
+ super.pointer = 0L;
+ }
+ }
+
+ /**
* Called by the garbage collector when the object is destroyed.
* The class will free internal resources allocated by the
* Operating system only if there are no additional references
@@ -89,7 +105,7 @@ public final class SSLEngine extends Nat
protected final void finalize()
throws Throwable
{
- free0(super.pointer);
+ dispose();
}
}
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLKey.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLKey.java?rev=1173040&r1=1173039&r2=1173040&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLKey.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLKey.java
Tue Sep 20 09:09:09 2011
@@ -97,7 +97,9 @@ public final class SSLKey extends Native
return format;
}
- public synchronized void free()
+ @Override
+ public synchronized void dispose()
+ throws IllegalStateException
{
if (super.pointer != 0L) {
free0(super.pointer);
@@ -118,7 +120,7 @@ public final class SSLKey extends Native
protected final void finalize()
throws Throwable
{
- free();
+ dispose();
}
}
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLServer.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLServer.java?rev=1173040&r1=1173039&r2=1173040&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLServer.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/ssl/SSLServer.java
Tue Sep 20 09:09:09 2011
@@ -16,8 +16,10 @@
package org.apache.commons.runtime.ssl;
+import org.apache.commons.runtime.ClosedObjectException;
import org.apache.commons.runtime.InvalidArgumentException;
import org.apache.commons.runtime.OperationNotImplementedException;
+import org.apache.commons.runtime.ObjectNotInitializedException;
import org.apache.commons.runtime.Status;
import org.apache.commons.runtime.SystemException;
@@ -35,7 +37,8 @@ public final class SSLServer extends Nat
// Hide NativePointer
private final long pointer = 0L;
private final String hostId;
- private static native long new0(String name);
+ private static native long new0(String name)
+ throws OutOfMemoryError;
private static native void close0(long srv);
private static native void setctx0(long srv, long ctx);
private static native void setservname0(long src, String name);
@@ -60,6 +63,7 @@ public final class SSLServer extends Nat
*
* @param hostId server's host id
* @throws NullPointerException if hostId is {@code null}.
+ * @throws RuntimeException if SSL was not initialized.
*/
public SSLServer(String hostId)
throws NullPointerException
@@ -72,6 +76,25 @@ public final class SSLServer extends Nat
super.pointer = new0(this.hostId);
}
+ public synchronized final void dispose()
+ throws IllegalStateException
+ {
+ if (super.pointer == 0L)
+ return;
+ if (ctx1 != null) {
+ ctx1.dispose();
+ ctx1 = null;
+ }
+ if (ctx2 != null) {
+ ctx2.dispose();
+ ctx2 = null;
+ }
+ if (super.pointer != 0L) {
+ close0(super.pointer);
+ super.pointer = 0L;
+ }
+ }
+
/**
* Free the allocated resource by the Operating system.
* <p>
@@ -85,19 +108,7 @@ public final class SSLServer extends Nat
public synchronized final void close()
throws IOException
{
-
- if (ctx1 != null) {
- ctx1.free();
- ctx1 = null;
- }
- if (ctx2 != null) {
- ctx2.free();
- ctx2 = null;
- }
- if (super.pointer != 0L) {
- close0(super.pointer);
- super.pointer = 0L;
- }
+ dispose();
}
/**
@@ -118,13 +129,13 @@ public final class SSLServer extends Nat
* @param ctx the context to set
* @return previous context or {@code null} if the context
* was not set already.
- * @throws IllegalStateException if server is invalid or closed.
+ * @throws ClosedObjectException if server is closed.
*/
public synchronized final SSLContext setContext(SSLContext ctx)
throws IllegalStateException
{
if (super.pointer == 0L)
- throw new IllegalStateException();
+ throw new ClosedObjectException();
SSLContext org = ctx1;
ctx1 = ctx;
setctx0(super.pointer, ((NativePointer)ctx).pointer);
@@ -137,13 +148,13 @@ public final class SSLServer extends Nat
* @param name name to set.
*
* @throws NullPointerException if name is {@code null}.
- * @throws IllegalStateException if server is invalid or closed.
+ * @throws ClosedObjectException if server is closed.
*/
public void setServerName(String name)
throws IllegalStateException
{
if (super.pointer == 0L)
- throw new IllegalStateException();
+ throw new ClosedObjectException();
if (name == null)
throw new NullPointerException();
serverName = name;
@@ -154,25 +165,25 @@ public final class SSLServer extends Nat
* Sets compression support.
*
* @param on if {@code true} don't use compression even if supported.
- * @throws IllegalStateException if server is invalid or closed.
+ * @throws ClosedObjectException if server is closed.
*/
public void setNoCompression(boolean on)
throws IllegalStateException
{
if (super.pointer == 0L)
- throw new IllegalStateException();
+ throw new ClosedObjectException();
setoption0(super.pointer, SSL_COPT_NO_COMPRESSION, on);
}
/**
* Disable use of RFC4507bis session tickets.
- * @throws IllegalStateException if server is invalid or closed.
+ * @throws ClosedObjectException if server is closed.
*/
public void setNoTicket(boolean on)
throws IllegalStateException
{
if (super.pointer == 0L)
- throw new IllegalStateException();
+ throw new ClosedObjectException();
setoption0(super.pointer, SSL_COPT_NO_TICKET, on);
}
@@ -180,13 +191,13 @@ public final class SSLServer extends Nat
* Enable use of legacy renegotiation (dangerous).
*
* @param on if {@code true} legacy renegotiation will be enabled.
- * @throws IllegalStateException if server is invalid or closed.
+ * @throws ClosedObjectException if server is closed.
*/
public void allowLegacyRenegotiation(boolean on)
throws IllegalStateException
{
if (super.pointer == 0L)
- throw new IllegalStateException();
+ throw new ClosedObjectException();
setoption0(super.pointer, SSL_COPT_ALLOW_UNSAFE_RENEG, on);
}
@@ -195,14 +206,13 @@ public final class SSLServer extends Nat
*
* @param on if {@code true} server will respond with fatal
* alert on servername mismatch.
- * @throws IllegalStateException if server instance is invalid.
- * @throws IllegalStateException if server is invalid or closed.
+ * @throws ClosedObjectException if server is closed.
*/
public void setServerNameFatal(boolean on)
throws IllegalStateException
{
if (super.pointer == 0L)
- throw new IllegalStateException();
+ throw new ClosedObjectException();
setoption0(super.pointer, SSL_COPT_TLSEXT_ALERT_FATAL, on);
}
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h?rev=1173040&r1=1173039&r2=1173040&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/error.h Tue Sep
20 09:09:09 2011
@@ -64,6 +64,8 @@ enum {
ACR_EX_ENET, /* NetworkException */
ACR_EX_EOVERFLOW, /* OverflowException */
ACR_EX_ENORES, /* OutOfResourcesException */
+ ACR_EX_ECLOSED, /* ClosedObjectException */
+ ACR_EX_EINIT, /* ObjectNotInitializedException */
ACR_EX_ECONNABORTED, /* ConnectionAbortedException */
ACR_EX_ECONNRESET, /* ConnectionResetException */
ACR_EX_ESSL, /* SSLException */
Modified: commons/sandbox/runtime/trunk/src/main/native/modules/openssl/server.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/modules/openssl/server.c?rev=1173040&r1=1173039&r2=1173040&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/modules/openssl/server.c
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/modules/openssl/server.c Tue
Sep 20 09:09:09 2011
@@ -113,7 +113,7 @@ ACR_SSL_EXPORT(void, SSLServer, setoptio
ACR_SSL_EXPORT(void, SSLServer, setservname0)(JNI_STDARGS, jlong srv, jstring
name)
{
acr_ssl_srv_t *s = J2P(srv, acr_ssl_srv_t *);
-
+ /* Guard agains multiple invocations */
AcrFree(s->servname);
s->servname = AcrGetJavaStringA(env, name, 0);
}
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/error.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.c?rev=1173040&r1=1173039&r2=1173040&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Tue Sep 20
09:09:09 2011
@@ -58,6 +58,8 @@ static struct {
{ 0, ACR_NET_CP "NetworkException" }, /* ENET
*/
{ 0, ACR_CLASS_PATH "OverflowException" }, /*
EOVERFLOW */
{ 0, ACR_CLASS_PATH "OutOfResourcesException" }, /* ENORES
*/
+ { 0, ACR_CLASS_PATH "ClosedObjectException" }, /* ECLOSED
*/
+ { 0, ACR_CLASS_PATH "ObjectNotInitializedException" }, /* EINIT
*/
{ 0, ACR_NET_CP "ConnectionAbortedException" }, /*
ECONNABORTED */
{ 0, ACR_NET_CP "ConnectionResetException" }, /*
ECONNRESET */
{ 0, ACR_SSL_CP "SSLException" }, /* ESSL
*/
Modified:
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestOpenSSL.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestOpenSSL.java?rev=1173040&r1=1173039&r2=1173040&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestOpenSSL.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestOpenSSL.java
Tue Sep 20 09:09:09 2011
@@ -57,7 +57,10 @@ public class TestOpenSSL extends Assert
{
super.pointer = 1234L;
}
-
+ public void dispose()
+ {
+ super.pointer = 0L;
+ }
}
@BeforeSuite(groups = { "openssl" })