harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r390236 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/ test/java/tests/api/java/net/
Date Thu, 30 Mar 2006 20:57:18 GMT
Author: tellison
Date: Thu Mar 30 12:57:15 2006
New Revision: 390236

URL: http://svn.apache.org/viewcvs?rev=390236&view=rev
Log:
Apply patch HARMONY-215 (java.net new classes: Four J2SE 5 new classes are not implemented
in java.net package)

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CacheRequest.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CacheResponse.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ResponseCache.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SecureCacheResponse.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/ResponseCacheTest.java
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/AllTests.java

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CacheRequest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CacheRequest.java?rev=390236&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CacheRequest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CacheRequest.java
Thu Mar 30 12:57:15 2006
@@ -0,0 +1,55 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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 java.net;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * CacheRequest provides channels for storing resource data in the <code>ResponseCache</code>.
+ * Protocol handler calls the <code>OutputStream</code> which is supplied by
CachedRequest 
+ * object, to store the resource data into the cache. It also allows the user to interrupt

+ * and abort the current store operation by calling method <code>abort</code>.

+ * If IOException occurs while reading the response or writing data to the cache, 
+ * the current cache store operation will be abandoned.
+ *
+ */
+public abstract class CacheRequest {
+	
+	/**
+	 * Constructor method. 
+	 */
+	public CacheRequest() {
+		super();
+	}
+
+	/**
+	 * Aborts the current cache operation.
+	 * If an IOException occurs while reading the response or writing resource data to the cache,
+	 * the current cache store operation will be aborted. 
+	 */
+	public abstract void abort();
+	
+	/**
+	 * <p>
+	 * Returns an <code>OutputStream</code>, which is used to write the response
body.
+	 * </p>
+	 * @return an <code>OutputStream</code> which is used to write the response
body. 
+	 * @throws IOException
+	 *             if an I/O error is encountered during writing response body operation.
+	 */
+	public abstract OutputStream getBody() throws IOException;
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CacheResponse.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CacheResponse.java?rev=390236&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CacheResponse.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/CacheResponse.java
Thu Mar 30 12:57:15 2006
@@ -0,0 +1,58 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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 java.net;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+
+/**
+ * CacheResponse is used for getting resource from the ResponseCache. 
+ * An CacheResponse object provides an <code>InputStream</code> to access the
response body,
+ * and also a method <code>getHeaders()</code> to fetch the response headers.
+ * 
+ */
+public abstract class CacheResponse {
+	/**
+	 * Constructor method
+	 */
+	public CacheResponse() {
+		super();
+	}
+
+	/**
+	 * <p>
+	 * Returns an <code>InputStream</code> for the respsonse body access.
+	 * </p>
+	 * @return an <code>InputStream</code>, which can be used to fetch the response
body.
+	 * @throws IOException
+	 *             if an I/O error is encounted while retrieving the response body.
+	 */
+	public abstract InputStream getBody() throws IOException;
+
+	/**
+	 * <p>
+	 * Returns an immutable <code>Map</code>, which contains the response headers
information.
+	 * @return an immutable <code>Map</code>, which contains the response headers.

+	 * The map is from response header field names to lists of field values.
+	 * Field name is a <code>String</code>, and the field values list is a <code>List</code>
+	 * of <code>String</code>.The status line as its field name has null as its
list of field values.
+	 * </p> 
+	 * @throws IOException
+	 *             if an I/O error is encounted while retrieving the response headers.
+	 */
+	public abstract Map getHeaders() throws IOException;
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ResponseCache.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ResponseCache.java?rev=390236&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ResponseCache.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/ResponseCache.java
Thu Mar 30 12:57:15 2006
@@ -0,0 +1,144 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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 java.net;
+
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * ResponseCache implements URLConnection caches. 
+ * System default cache can be registered by invoking ResponseCache.<code>setDefault</code>(ResponseCache),
+ * and can be retrieved by invoking ResponseCache.<code>getDefault</code>.  
+ * If URLConnection#useCaches is set, <code>URLConnection</code> class will use
<code>ResponseCache</code>
+ * to store and get resources. Whether the resource is cached depends on <code>ResponseCache</code>
implementation.
+ * If a request resource is cached, protocol handler will fecth it from the cache. If the
protocol handler fails 
+ * to get resource from the cache, it turns to get the resource from its original location.
+ *
+ */
+public abstract class ResponseCache {
+	
+	/*
+	 *  _defaultResponseCache is used to store default response cache. 
+	 */
+	private static ResponseCache _defaultResponseCache = null;
+	
+	/*
+	 * "getResponseCache" permission. getDefault method requires this permission. 
+	 */
+	private static NetPermission getResponseCachepermission = new NetPermission("getResponseCache");
+	
+	/*
+	 * "setResponseCache" permission. setDefault method requires this permission. 
+	 */
+	private static NetPermission setResponseCachepermission = new NetPermission("setResponseCache");
+	
+	/*
+	 * check getResponseCache permission.
+	 * getDefault method requires "getResponseCache" permission
+	 * if a security manager is installed. 
+	 */
+	private static void checkGetResponseCachePermission(){
+		SecurityManager sm = System.getSecurityManager();
+		if(null != sm){
+			sm.checkPermission(getResponseCachepermission);
+		}
+	}
+	/*
+	 * check setResponseCache permission.
+	 * setDefault method requires "setResponseCache" permission
+	 * if a security manager is installed. 
+	 */
+	private static void checkSetResponseCachePermission(){
+		SecurityManager sm = System.getSecurityManager();
+		if(null != sm){
+			sm.checkPermission(setResponseCachepermission);
+		}
+	}
+	
+	/**
+	 * Constructor method.
+	 */
+	public ResponseCache() {
+		super();
+	}
+
+	/**
+	 * Gets system default response cache.
+	 * @return default <code>ResponseCache</code>.
+	 * @throws SecurityException
+	 *             If a security manager is installed
+	 *             and it doesn't have <code>NetPermission</code>("getResponseCache").
 
+	 */
+	public static ResponseCache getDefault() {
+		checkGetResponseCachePermission();
+		return _defaultResponseCache;
+	}
+
+	/**
+	 * Sets the system default response cache when responseCache is not null.
+	 * Otherwise, the method unsets the system default response cache.
+	 * This setting may be ignored by some non-standard protocols.  
+	 * @param responseCache
+	 *            Set default <code>ResponseCache</code>. 
+	 *            If responseCache is null, it unsets the cache.
+	 * @throws SecurityException
+	 *             If a security manager is installed
+	 *             and it doesn't have <code>NetPermission</code>("setResponseCache").
+	 */
+	public static void setDefault(ResponseCache responseCache) {
+		checkSetResponseCachePermission();
+		_defaultResponseCache = responseCache;
+	}
+
+	
+	/**
+	 * Gets the cached response according to requesting uri,method and headers. 
+	 * @param uri
+	 *            A <code>URL</code>  represents requesting uri.
+	 * @param rqstMethod
+	 *            A <code>String</code> represents requesting method.
+	 * @param rqstHeaders
+	 *            A <code>Map</code> from request header field names 
+	 *            to lists of field values represents requesting headers.
+	 * @return A <code>CacheResponse</code> object if the request is available in
the cache.
+	 *         Otherwise, this method returns null.
+	 * @throws IOException
+	 *              If an I/O error is encountered.
+	 * @throws IllegalArgumentException
+	 *             If any one of the parameters is null
+	 */
+	public abstract CacheResponse get(URI uri, String rqstMethod,
+			Map rqstHeaders) throws IOException;
+
+	/**
+	 * Protocol handler calls this method after retrieving resources.
+	 * The <code>ResponseCache</code> decides whether the resource should be cached.
+	 * If the resource needs to be cached, this method will return a <code>CacheRequest</code>
+	 * with a <code>WriteableByteChannel</code>, and then, protocol handler will
use this 
+	 * channel to write the resource data into the cache. Otherwise, if the resource doesn't

+	 * need to be cached, it returns null.
+	 *     
+	 * @param uri
+	 * @param conn
+	 * @return a <code>CacheRequest</code> which contains <code>WriteableByteChannel</code>
+	 *         if the resource is cached. Otherwise, it returns null. 
+	 * @throws IOException
+	 *             If an I/O error is encountered.
+	 * @throws IllegalArgumentException
+	 *             If any one of the parameters is null.
+	 */
+	public abstract CacheRequest put(URI uri, URLConnection conn)
+			throws IOException;
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SecureCacheResponse.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SecureCacheResponse.java?rev=390236&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SecureCacheResponse.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/SecureCacheResponse.java
Thu Mar 30 12:57:15 2006
@@ -0,0 +1,92 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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 java.net;
+
+import java.security.Principal;
+import java.util.List;
+
+import javax.net.ssl.SSLPeerUnverifiedException;
+
+/**
+ * A secure cache response, which is orignally retrieved through secure ways. 
+ */
+public abstract class SecureCacheResponse extends CacheResponse {
+	/**
+	 * Constructor method
+	 */
+	public SecureCacheResponse() {
+		super();
+	}
+
+	/**
+	 * <p>
+	 * Gets the cipher suite string on the connection 
+	 * which is originally used to retrieve the network resource.
+	 * </p>
+	 * @return the cipher suite string
+	 */
+	public abstract String getCipherSuite();
+
+	/**
+	 * <p>
+	 * Gets local certificate chain. When the original connection retrieved the resource data,
+	 * certificate chain was sent to the server during handshaking process. This method only

+	 * takes effect when certificate-based cipher suite is enabled.
+	 * </p> 
+	 * @return the certificate chain that was sent to the server. The certificate chain is represented

+	 * as a <code>List</code> of <code>Certificate</code>. If no certificate
chain was sent, 
+	 * the method returns null.
+	 */
+	public abstract List getLocalCertificateChain();
+
+	/**
+	 * <p>
+	 * Gets server's certificate chain from cache. As part of defining the session,
+	 * the certificate chain was established when the original connection retrieved network
resource.
+	 * This method can only be invoked when certificated-based cypher suites is enable. 
+	 * Otherwise, it throws an <code>SSLPeerUnverifiedException</code>.
+	 * </p>
+	 * @return The server's certificate chain, which is represented as a <code>List</code>
of <code>Certificate</code>.
+	 * @throws SSLPeerUnverifiedException
+	 *             If the peer is unverified.
+	 */
+	public abstract List getServerCertificateChain()
+			throws SSLPeerUnverifiedException;
+
+	/**
+	 * <p>
+	 * Gets the server's <code>Principle</code>. When the original connection 
+	 * retrieved network resource, the principle was established when defining 
+	 * the session. 
+	 * </p>
+	 * @return an <code>Principal</code> represents the server's principal. 
+	 * @throws SSLPeerUnverifiedException
+	 *             If the peer is unverified.
+	 */
+	public abstract Principal getPeerPrincipal()
+			throws SSLPeerUnverifiedException;
+
+	/**
+	 * <p>
+	 * Gets the <code>Principle</code> that the original connection sent to the
server. 
+	 * When the original connection fetched the network resource, the <code>Principle</code>

+	 * was sent to the server during handshaking process.
+	 * </p>
+	 * @return the <code>principal</code> sent to the server. 
+	 *         Returns an <code>X500Principal</code> for X509-based cipher suites.
+	 *         If no principal was sent, it returns null.
+	 */
+	public abstract Principal getLocalPrincipal();
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/AllTests.java?rev=390236&r1=390235&r2=390236&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/AllTests.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/AllTests.java
Thu Mar 30 12:57:15 2006
@@ -47,6 +47,7 @@
 		suite.addTestSuite(NoRouteToHostExceptionTest.class);
 		suite.addTestSuite(PasswordAuthenticationTest.class);
 		suite.addTestSuite(ProtocolExceptionTest.class);
+		suite.addTestSuite(ResponseCacheTest.class);
 		suite.addTestSuite(ServerSocketTest.class);
 		suite.addTestSuite(SocketTest.class);
 		suite.addTestSuite(SocketExceptionTest.class);

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/ResponseCacheTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/ResponseCacheTest.java?rev=390236&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/ResponseCacheTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/ResponseCacheTest.java
Thu Mar 30 12:57:15 2006
@@ -0,0 +1,140 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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 tests.api.java.net;
+
+import java.io.IOException;
+import java.net.CacheRequest;
+import java.net.CacheResponse;
+import java.net.NetPermission;
+import java.net.ResponseCache;
+import java.net.URI;
+import java.net.URLConnection;
+import java.security.Permission;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+public class ResponseCacheTest extends TestCase {
+
+	/**
+	 * @tests java.net.ResponseCache#getDefault()
+	 */
+	public void test_GetDefault() throws Exception {
+		assertNull(ResponseCache.getDefault());
+	}
+
+	/**
+	 * @tests java.net.ResponseCache#setDefault(ResponseCache)
+	 */
+	public void test_SetDefaultLjava_net_ResponseCache_Normal()
+			throws Exception {
+		ResponseCache rc1 = new MockResponseCache();
+		ResponseCache rc2 = new MockResponseCache();
+		ResponseCache.setDefault(rc1);
+		assertSame(ResponseCache.getDefault(), rc1);
+		ResponseCache.setDefault(rc2);
+		assertSame(ResponseCache.getDefault(), rc2);
+		ResponseCache.setDefault(null);
+		assertNull(ResponseCache.getDefault());
+	}
+
+	/**
+	 * @tests java.net.ResponseCache#getDefault()
+	 */
+	public void test_GetDefault_Security() {
+		SecurityManager old = System.getSecurityManager();
+		try {
+			System.setSecurityManager(new MockSM());
+		} catch (SecurityException e) {
+			System.err.println("No setSecurityManager permission.");
+			System.err.println("test_setDefaultLjava_net_ResponseCache_NoPermission is not tested");
+			return;
+		}
+		try {
+			ResponseCache.getDefault();
+			fail("should throw SecurityException");
+		} catch (SecurityException e) {
+			// expected
+		} finally {
+			System.setSecurityManager(old);
+		}
+	}
+
+	/**
+	 * @tests java.net.ResponseCache#setDefault(ResponseCache)
+	 */
+	public void test_setDefaultLjava_net_ResponseCache_NoPermission() {
+		ResponseCache rc = new MockResponseCache();
+		SecurityManager old = System.getSecurityManager();
+		try {
+			System.setSecurityManager(new MockSM());
+		} catch (SecurityException e) {
+			System.err.println("No setSecurityManager permission.");
+			System.err.println("test_setDefaultLjava_net_ResponseCache_NoPermission is not tested");
+			return;
+		}
+		try {
+			ResponseCache.setDefault(rc);
+			fail("should throw SecurityException");
+		} catch (SecurityException e) {
+			// expected
+		} finally {
+			System.setSecurityManager(old);
+		}
+	}
+
+	/*
+	 * MockResponseCache for testSetDefault(ResponseCache)
+	 */
+	class MockResponseCache extends ResponseCache {
+
+		public CacheResponse get(URI arg0, String arg1, Map arg2)
+				throws IOException {
+			return null;
+		}
+
+		public CacheRequest put(URI arg0, URLConnection arg1)
+				throws IOException {
+			return null;
+		}
+	}
+
+	/*
+	 * MockSecurityMaanger. It denies NetPermission("getResponseCache") and
+	 * NetPermission("setResponseCache").
+	 */
+	class MockSM extends SecurityManager {
+		public void checkPermission(Permission permission) {
+			if (permission instanceof NetPermission) {
+				if ("setResponseCache".equals(permission.getName())) {
+					throw new SecurityException();
+				}
+			}
+
+			if (permission instanceof NetPermission) {
+				if ("getResponseCache".equals(permission.getName())) {
+					throw new SecurityException();
+				}
+			}
+
+			if (permission instanceof RuntimePermission) {
+				if ("setSecurityManager".equals(permission.getName())) {
+					return;
+				}
+			}
+		}
+	}
+}



Mime
View raw message