You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by py...@apache.org on 2007/07/03 11:03:02 UTC
svn commit: r552748 - in /harmony/enhanced/classlib/branches/java6: make/
modules/archive/src/main/java/java/util/jar/
modules/awt/src/main/native/fontlib/shared/
modules/beans/src/main/java/java/beans/beancontext/
modules/beans/src/test/java/org/apach...
Author: pyang
Date: Tue Jul 3 02:02:59 2007
New Revision: 552748
URL: http://svn.apache.org/viewvc?view=rev&rev=552748
Log:
Merge updates from classlib trunk@552679 since r550097
Added:
harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpConfiguration.java
- copied unchanged from r552679, harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpConfiguration.java
harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpConnection.java
- copied unchanged from r552679, harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpConnection.java
harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpConnectionManager.java
- copied unchanged from r552679, harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpConnectionManager.java
harmony/enhanced/classlib/branches/java6/modules/luni/src/test/impl/
- copied from r552679, harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/
harmony/enhanced/classlib/branches/java6/modules/luni/src/test/impl/org/
- copied from r552679, harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/org/
harmony/enhanced/classlib/branches/java6/modules/luni/src/test/impl/org/apache/
- copied from r552679, harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/org/apache/
harmony/enhanced/classlib/branches/java6/modules/luni/src/test/impl/org/apache/harmony/
- copied from r552679, harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/org/apache/harmony/
harmony/enhanced/classlib/branches/java6/modules/luni/src/test/impl/org/apache/harmony/tests/
- copied from r552679, harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/org/apache/harmony/tests/
harmony/enhanced/classlib/branches/java6/modules/luni/src/test/impl/org/apache/harmony/tests/internal/
- copied from r552679, harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/org/apache/harmony/tests/internal/
harmony/enhanced/classlib/branches/java6/modules/luni/src/test/impl/org/apache/harmony/tests/internal/net/
- copied from r552679, harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/org/apache/harmony/tests/internal/net/
harmony/enhanced/classlib/branches/java6/modules/luni/src/test/impl/org/apache/harmony/tests/internal/net/www/
- copied from r552679, harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/org/apache/harmony/tests/internal/net/www/
harmony/enhanced/classlib/branches/java6/modules/luni/src/test/impl/org/apache/harmony/tests/internal/net/www/protocol/
- copied from r552679, harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/org/apache/harmony/tests/internal/net/www/protocol/
harmony/enhanced/classlib/branches/java6/modules/luni/src/test/impl/org/apache/harmony/tests/internal/net/www/protocol/http/
- copied from r552679, harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/org/apache/harmony/tests/internal/net/www/protocol/http/
harmony/enhanced/classlib/branches/java6/modules/luni/src/test/impl/org/apache/harmony/tests/internal/net/www/protocol/http/PersistenceTest.java
- copied unchanged from r552679, harmony/enhanced/classlib/trunk/modules/luni/src/test/impl/org/apache/harmony/tests/internal/net/www/protocol/http/PersistenceTest.java
Modified:
harmony/enhanced/classlib/branches/java6/make/depends.properties
harmony/enhanced/classlib/branches/java6/modules/archive/src/main/java/java/util/jar/InitManifest.java
harmony/enhanced/classlib/branches/java6/modules/awt/src/main/native/fontlib/shared/T1Font.cpp
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/beancontext/BeanContextSupport.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextSupportTest.java
harmony/enhanced/classlib/branches/java6/modules/luni/.classpath
harmony/enhanced/classlib/branches/java6/modules/luni/build.xml
harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java
harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnection.java
harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/fdlibm/unix/makefile
harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java
harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/https/HttpsURLConnectionTest.java
harmony/enhanced/classlib/branches/java6/modules/prefs/make/exclude.linux.x86.drl
harmony/enhanced/classlib/branches/java6/modules/prefs/make/exclude.linux.x86_64.drl
Modified: harmony/enhanced/classlib/branches/java6/make/depends.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/make/depends.properties?view=diff&rev=552748&r1=552747&r2=552748
==============================================================================
--- harmony/enhanced/classlib/branches/java6/make/depends.properties (original)
+++ harmony/enhanced/classlib/branches/java6/make/depends.properties Tue Jul 3 02:02:59 2007
@@ -15,12 +15,12 @@
depends.dir=depends
depends.jars=${depends.dir}/jars
-mirror.base=http://mirrors.ibiblio.org/pub/mirrors/maven2
+maven2.base=http://repo1.maven.org/maven2
sf.base=http://internap.dl.sourceforge.net/sourceforge
xalan.dir=${depends.jars}/xalan-j_2.7.0
xalan.jar=${xalan.dir}/xalan.jar
-xalan.url=${mirror.base}/xalan/xalan/2.7.0/xalan-2.7.0.jar
+xalan.url=${maven2.base}/xalan/xalan/2.7.0/xalan-2.7.0.jar
xalan.md5=a018d032c21a873225e702b36b171a10
xerces.dir=${depends.jars}/xerces_2.9.0
@@ -35,7 +35,7 @@
junit.dir=${depends.jars}/junit_3.8.2
junit.jar=${junit.dir}/junit.jar
-junit.url=${mirror.base}/junit/junit/3.8.2/junit-3.8.2.jar
+junit.url=${maven2.base}/junit/junit/3.8.2/junit-3.8.2.jar
junit.md5=28e7eb9eeefe31a657c68755bfccc541
bcprov.dir=${depends.jars}/bcprov-jdk15-136
@@ -56,12 +56,11 @@
msvcr.dll.x86_64=${msvcr.dir.x86_64}/msvcr80.dll
msvcr.dll.file.x86_64=msvcr80.dll
msvcr.url.x86_64=file:///${hyenv.SystemRoot}/system32/msvcr80.dll
-#msvcr.url.x86_64=file:///C:/Program%20Files%20(x86)/Microsoft%20Visual%20Studio%208/VC/redist/amd64/Microsoft.VC80.CRT/msvcr80.dll
msvcr.md5.x86_64=465cebd7da2ceaba5e552fc9118a1415
icu4j.dir=${depends.jars}/icu4j_3.4.4
icu4j.jar=${icu4j.dir}/icu4j_3_4_4.jar
-icu4j.url=${mirror.base}/com/ibm/icu/icu4j/3.4.4/icu4j-3.4.4.jar
+icu4j.url=${maven2.base}/com/ibm/icu/icu4j/3.4.4/icu4j-3.4.4.jar
icu4j.md5=92422a9465ccc608bc7a8ae9cf594509
mx4j.dir=${depends.jars}/mx4j_3.0.2
@@ -91,25 +90,24 @@
yoko-rmi-spec.url=http://people.apache.org/maven-snapshot-repository/org/apache/yoko/yoko-rmi-spec/1.0-incubating-M2-SNAPSHOT/yoko-rmi-spec-1.0-incubating-M2-20070130.104323-6.jar
yoko-rmi-spec.md5=532438a96cbb6948c37f0f7650aa1d5e
-
# bcel is needed by yoko-rmi
bcel.dir=${depends.jars}/bcel-5.2
bcel.jar=${bcel.dir}/bcel-5.2.jar
-bcel.url=${mirror.base}/org/apache/bcel/bcel/5.2/bcel-5.2.jar
+bcel.url=${maven2.base}/org/apache/bcel/bcel/5.2/bcel-5.2.jar
bcel.md5=43d54687362fc2991d61201c453a8286
jetty.dir=${depends.jars}/jetty
jetty.jar=${jetty.dir}/jetty-6.0.0.jar
jetty.md5=930507973c9ad19a874af06f10be7223
-jetty.url=${mirror.base}/jetty/jetty/6.0.0/jetty-6.0.0.jar
+jetty.url=${maven2.base}/jetty/jetty/6.0.0/jetty-6.0.0.jar
jetty-util.jar=${jetty.dir}/jetty-util-6.0.0.jar
jetty-util.md5=7cf65d83814718afdd1d3bd74f8799fc
-jetty-util.url=${mirror.base}/jetty/jetty-util/6.0.0/jetty-util-6.0.0.jar
+jetty-util.url=${maven2.base}/jetty/jetty-util/6.0.0/jetty-util-6.0.0.jar
servlet-api.jar=${jetty.dir}/servlet-api-2.5-6.0.0.jar
servlet-api.md5=c27c02fb0a00cc3a7d05ea993a9bf56e
-servlet-api.url=${mirror.base}/jetty/servlet-api/2.5-6.0.0/servlet-api-2.5-6.0.0.jar
+servlet-api.url=${maven2.base}/jetty/servlet-api/2.5-6.0.0/servlet-api-2.5-6.0.0.jar
awtdeps.base.x86=http://people.apache.org/~geirm/harmony/
awtdeps.dir.x86=${depends.dir}/libs/windows.x86
@@ -126,5 +124,4 @@
awtdeps.md5.x86_64=f2bbb1f4f23100393783fd02a77fcc68
awtdeps.extract.dir.x86_64=${depends.dir}/libs/build
awtdeps.testfile.x86_64=${awtdeps.extract.dir.x86_64}/win64_2007-02-08.txt
-
Modified: harmony/enhanced/classlib/branches/java6/modules/archive/src/main/java/java/util/jar/InitManifest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/archive/src/main/java/java/util/jar/InitManifest.java?view=diff&rev=552748&r1=552747&r2=552748
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/archive/src/main/java/java/util/jar/InitManifest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/archive/src/main/java/java/util/jar/InitManifest.java Tue Jul 3 02:02:59 2007
@@ -77,8 +77,10 @@
list.clear();
byte[] chunk = null;
- while (chunks == null ? readLines(is, list) : (chunk = nextChunk(is,
- list)) != null) {
+ while (chunks == null ? readLines(is, list) : (chunk = nextChunk(is, list)) != null) {
+ if (list.size() == 0) {
+ continue;
+ }
it = list.iterator();
String line = it.next();
if (line.length() < 7
Modified: harmony/enhanced/classlib/branches/java6/modules/awt/src/main/native/fontlib/shared/T1Font.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/awt/src/main/native/fontlib/shared/T1Font.cpp?view=diff&rev=552748&r1=552747&r2=552748
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/awt/src/main/native/fontlib/shared/T1Font.cpp (original)
+++ harmony/enhanced/classlib/branches/java6/modules/awt/src/main/native/fontlib/shared/T1Font.cpp Tue Jul 3 02:02:59 2007
@@ -20,7 +20,9 @@
*/
#include <string>
-
+#if defined(LINUX)
+#include <ctype.h>
+#endif
#include "T1Font.h"
#include "T1Glyph.h"
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/beancontext/BeanContextSupport.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/beancontext/BeanContextSupport.java?view=diff&rev=552748&r1=552747&r2=552748
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/beancontext/BeanContextSupport.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/beancontext/BeanContextSupport.java Tue Jul 3 02:02:59 2007
@@ -699,7 +699,7 @@
throw new IllegalArgumentException("Not a child of this context");
}
- return getClass().getClassLoader().getResource(resourceName);
+ return ClassLoader.getSystemResource(resourceName);
}
/* (non-Javadoc)
@@ -714,7 +714,7 @@
throw new IllegalArgumentException("Not a child of this context");
}
- return getClass().getClassLoader().getResourceAsStream(resourceName);
+ return ClassLoader.getSystemResourceAsStream(resourceName);
}
/**
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextSupportTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextSupportTest.java?view=diff&rev=552748&r1=552747&r2=552748
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextSupportTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextSupportTest.java Tue Jul 3 02:02:59 2007
@@ -1165,6 +1165,11 @@
final String RESOURCE_NAME = "org/apache/harmony/beans/tests/support/beancontext/mock/mockdata.txt";
URL url = support.getResource(RESOURCE_NAME, child);
assertTrue(url.toString().endsWith(RESOURCE_NAME));
+
+ BeanContextSupport beanContextSupport = new BeanContextSupport();
+ beanContextSupport.add(child);
+ url = beanContextSupport.getResource(RESOURCE_NAME, child);
+ assertTrue(url.toString().endsWith(RESOURCE_NAME));
}
public void testGetResourceAsStream_NullParam() {
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/.classpath
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/.classpath?view=diff&rev=552748&r1=552747&r2=552748
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/.classpath (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/.classpath Tue Jul 3 02:02:59 2007
@@ -6,6 +6,7 @@
<classpathentry output="bin/test" kind="src" path="src/test/api/unix"/>
<classpathentry output="bin/main" kind="src" path="src/main/resources"/>
<classpathentry output="bin/test" kind="src" path="src/test/resources"/>
+ <classpathentry kind="src" path="src/test/impl"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
<accessrules>
<accessrule kind="accessible" pattern="**/*"/>
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/build.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/build.xml?view=diff&rev=552748&r1=552747&r2=552748
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/build.xml (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/build.xml Tue Jul 3 02:02:59 2007
@@ -283,6 +283,7 @@
<src>
<pathelement location="${hy.luni.src.test.api}/common"/>
<pathelement location="${hy.luni.src.test.api.java.platform}"/>
+ <pathelement location="${hy.luni.src.test}/impl"/>
</src>
<include name="**/*.java" />
</javac-elements>
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java?view=diff&rev=552748&r1=552747&r2=552748
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java Tue Jul 3 02:02:59 2007
@@ -17,7 +17,6 @@
package org.apache.harmony.luni.internal.net.www.protocol.http;
-import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -33,8 +32,6 @@
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.ResponseCache;
-import java.net.Socket;
-import java.net.SocketAddress;
import java.net.SocketPermission;
import java.net.URI;
import java.net.URISyntaxException;
@@ -74,12 +71,12 @@
private int httpVersion = 1; // Assume HTTP/1.1
+ protected HttpConnection connection;
+
private InputStream is;
private InputStream uis;
- protected Socket socket;
-
private OutputStream socketOut;
private OutputStream cacheOut;
@@ -130,8 +127,12 @@
@Override
public void close() throws IOException {
- bytesRemaining = 0;
- closeSocket();
+ if(bytesRemaining > 0) {
+ bytesRemaining = 0;
+ disconnect(true); // Should close the socket if client hasn't read all the data
+ } else {
+ disconnect(false);
+ }
/*
* if user has set useCache to true and cache exists, aborts it when
* closing
@@ -153,6 +154,7 @@
@Override
public int read() throws IOException {
if (bytesRemaining <= 0) {
+ disconnect(false);
return -1;
}
int result = is.read();
@@ -162,6 +164,9 @@
cacheOut.write(result);
}
bytesRemaining--;
+ if (bytesRemaining <= 0) {
+ disconnect(false);
+ }
return result;
}
@@ -176,6 +181,7 @@
throw new ArrayIndexOutOfBoundsException();
}
if (bytesRemaining <= 0) {
+ disconnect(false);
return -1;
}
if (length > bytesRemaining) {
@@ -190,11 +196,15 @@
cacheOut.write(buf, offset, result);
}
}
+ if (bytesRemaining <= 0) {
+ disconnect(false);
+ }
return result;
}
public long skip(int amount) throws IOException {
if (bytesRemaining <= 0) {
+ disconnect(false);
return -1;
}
if (amount > bytesRemaining) {
@@ -204,6 +214,9 @@
if (result > 0) {
bytesRemaining -= result;
}
+ if (bytesRemaining <= 0) {
+ disconnect(false);
+ }
return result;
}
}
@@ -219,8 +232,12 @@
@Override
public void close() throws IOException {
+ if(!atEnd && available() > 0) {
+ disconnect(true);
+ } else {
+ disconnect(false);
+ }
atEnd = true;
- closeSocket();
// if user has set useCache to true and cache exists, abort
if (useCaches && null != cacheRequest) {
cacheRequest.abort();
@@ -261,6 +278,7 @@
readChunkSize();
}
if (atEnd) {
+ disconnect(false);
return -1;
}
bytesRemaining--;
@@ -286,6 +304,7 @@
readChunkSize();
}
if (atEnd) {
+ disconnect(false);
return -1;
}
if (length > bytesRemaining) {
@@ -305,6 +324,7 @@
public long skip(int amount) throws IOException {
if (atEnd) {
+ disconnect(false);
return -1;
}
if (bytesRemaining <= 0) {
@@ -428,6 +448,7 @@
}
sendCache(closed);
}
+ disconnect(false);
}
@Override
@@ -534,8 +555,8 @@
protected HttpURLConnection(URL url, int port) {
super(url);
defaultPort = port;
-
reqHeader = (Header) defaultReqHeader.clone();
+
try {
uri = url.toURI();
} catch (URISyntaxException e) {
@@ -584,14 +605,19 @@
if (getFromCache()) {
return;
}
+ try {
+ uri = url.toURI();
+ } catch (URISyntaxException e1) {
+ // ignore
+ }
// socket to be used for connection
- Socket socket = null;
+ connection = null;
// try to determine: to use the proxy or not
if (proxy != null) {
// try to make the connection to the proxy
// specified in constructor.
// IOException will be thrown in the case of failure
- socket = getHTTPConnection(proxy);
+ connection = getHTTPConnection(proxy);
} else {
// Use system-wide ProxySelect to select proxy list,
// then try to connect via elements in the proxy list.
@@ -604,7 +630,7 @@
continue;
}
try {
- socket = getHTTPConnection(selectedProxy);
+ connection = getHTTPConnection(selectedProxy);
proxy = selectedProxy;
break; // connected
} catch (IOException e) {
@@ -614,64 +640,38 @@
}
}
}
- if (socket == null) {
+ if (connection == null) {
// make direct connection
- socket = getHTTPConnection(null);
+ connection = getHTTPConnection(null);
}
- socket.setSoTimeout(getReadTimeout());
- setUpTransportIO(socket);
+ connection.setSoTimeout(getReadTimeout());
+ setUpTransportIO(connection);
connected = true;
}
/**
- * Returns connected socket to be used for this HTTP connection. TODO:
- * implement persistent connections.
+ * Returns connected socket to be used for this HTTP connection.
*/
- protected Socket getHTTPConnection(Proxy proxy) throws IOException {
- Socket socket;
+ protected HttpConnection getHTTPConnection(Proxy proxy) throws IOException {
+ HttpConnection connection;
if (proxy == null || proxy.type() == Proxy.Type.DIRECT) {
- this.proxy = null; // not using proxy
- socket = new Socket();
- socket.connect(new InetSocketAddress(getHostName(), getHostPort()),
- getConnectTimeout());
- } else if (proxy.type() == Proxy.Type.HTTP) {
- socket = new Socket();
-
- SocketAddress proxyAddr = proxy.address();
-
- if (!(proxyAddr instanceof InetSocketAddress)) {
- throw new IllegalArgumentException(Msg.getString(
- "K0316", proxyAddr.getClass())); //$NON-NLS-1$
- }
-
- InetSocketAddress iProxyAddr = (InetSocketAddress) proxyAddr;
-
- if( iProxyAddr.getAddress() == null ) {
- // Resolve proxy, see HARMONY-3113
- socket.connect(new InetSocketAddress((iProxyAddr.getHostName()),
- iProxyAddr.getPort()), getConnectTimeout());
- } else {
- socket.connect(iProxyAddr, getConnectTimeout());
- }
+ this.proxy = null; // not using proxy
+ connection = HttpConnectionManager.getDefault().getConnection(uri, getConnectTimeout());
} else {
- // using SOCKS proxy
- socket = new Socket(proxy);
- socket.connect(new InetSocketAddress(getHostName(), getHostPort()),
- getConnectTimeout());
+ connection = HttpConnectionManager.getDefault().getConnection(uri, proxy, getConnectTimeout());
}
- return socket;
+ return connection;
}
/**
* Sets up the data streams used to send request[s] and read response[s].
*
- * @param socket
- * socket to be used for connection
+ * @param connection
+ * HttpConnection to be used
*/
- protected void setUpTransportIO(Socket socket) throws IOException {
- this.socket = socket;
- socketOut = socket.getOutputStream();
- is = new BufferedInputStream(socket.getInputStream());
+ protected void setUpTransportIO(HttpConnection connection) throws IOException {
+ socketOut = connection.getOutputStream();
+ is = connection.getInputStream();
}
// Tries to get head and body from cache, return true if has got this time
@@ -721,16 +721,17 @@
*/
@Override
public void disconnect() {
- try {
- closeSocket();
- } catch (IOException e) {
- }
+ disconnect(true);
}
- void closeSocket() throws IOException {
- if (is != null) {
- is.close();
+ private void disconnect(boolean closeSocket) {
+ if(closeSocket && connection != null) {
+ connection.closeSocketAndStreams();
+ } else if (connection != null) {
+ HttpConnectionManager.getDefault().returnConnectionToPool(connection);
+ connection = null;
}
+ connection = null;
}
protected void endRequest() throws IOException {
@@ -868,7 +869,6 @@
// connect before sending requests
connect();
-
doRequest();
/*
@@ -1070,7 +1070,7 @@
if (method == HEAD || (responseCode >= 100 && responseCode < 200)
|| responseCode == HTTP_NO_CONTENT
|| responseCode == HTTP_NOT_MODIFIED) {
- closeSocket();
+ disconnect();
uis = new LimitedInputStream(0);
}
putToCache();
@@ -1163,8 +1163,7 @@
// if we are doing output make sure the appropriate headers are sent
if (os != null) {
if (reqHeader.get("Content-Type") == null) { //$NON-NLS-1$
- output
- .append("Content-Type: application/x-www-form-urlencoded\r\n"); //$NON-NLS-1$
+ output.append("Content-Type: application/x-www-form-urlencoded\r\n"); //$NON-NLS-1$
}
if (os.isCached()) {
if (reqHeader.get("Content-Length") == null) { //$NON-NLS-1$
@@ -1198,8 +1197,7 @@
* if both setFixedLengthStreamingMode and
* content-length are set, use fixedContentLength first
*/
- output
- .append((fixedContentLength >= 0) ? String
+ output.append((fixedContentLength >= 0) ? String
.valueOf(fixedContentLength)
: reqHeader.get(i));
} else {
@@ -1381,7 +1379,7 @@
// drop everything and reconnect, might not be required for
// HTTP/1.1
endRequest();
- closeSocket();
+ disconnect();
connected = false;
String credentials = getAuthorizationCredentials(challenge);
if (credentials == null) {
@@ -1404,7 +1402,7 @@
// drop everything and reconnect, might not be required for
// HTTP/1.1
endRequest();
- closeSocket();
+ disconnect();
connected = false;
String credentials = getAuthorizationCredentials(challenge);
if (credentials == null) {
@@ -1450,7 +1448,7 @@
hostPort = -1;
}
endRequest();
- closeSocket();
+ disconnect();
connected = false;
continue;
}
@@ -1467,7 +1465,7 @@
* authorization challenge
*
* @param challenge
- * @return
+ * @return authorization credentials
* @throws IOException
*/
private String getAuthorizationCredentials(String challenge)
@@ -1517,4 +1515,4 @@
}
}
}
-}
+}
\ No newline at end of file
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnection.java?view=diff&rev=552748&r1=552747&r2=552748
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnection.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnection.java Tue Jul 3 02:02:59 2007
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.harmony.luni.internal.net.www.protocol.https;
import java.io.IOException;
@@ -22,7 +21,6 @@
import java.io.OutputStream;
import java.net.ProtocolException;
import java.net.Proxy;
-import java.net.Socket;
import java.net.URL;
import java.security.Permission;
import java.security.Principal;
@@ -387,7 +385,7 @@
responseMessage, responseCode));
}
// if there are some remaining data in the stream - read it out
- InputStream is = socket.getInputStream();
+ InputStream is = connection.getInputStream();
while (is.available() != 0) {
is.read();
}
@@ -397,7 +395,8 @@
super.connect();
}
if (!makingSSLTunnel) {
- setUpTransportIO(wrapConnection(socket));
+ sslSocket = connection.getSecureSocket(getSSLSocketFactory(), getHostnameVerifier());
+ setUpTransportIO(connection);
}
}
@@ -420,21 +419,5 @@
return super.requestString();
}
- /**
- * Create the secure socket over the connected socket and verify remote
- * hostname.
- */
- private Socket wrapConnection(Socket socket) throws IOException {
- String hostname = url.getHost();
- // create the wrapper over connected socket
- sslSocket = (SSLSocket) getSSLSocketFactory().createSocket(socket,
- hostname, url.getPort(), true);
- sslSocket.setUseClientMode(true);
- sslSocket.startHandshake();
- if (!getHostnameVerifier().verify(hostname, sslSocket.getSession())) {
- throw new IOException(Messages.getString("luni.02", hostname)); //$NON-NLS-1$
- }
- return sslSocket;
- }
}
}
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/fdlibm/unix/makefile
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/fdlibm/unix/makefile?view=diff&rev=552748&r1=552747&r2=552748
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/fdlibm/unix/makefile (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/fdlibm/unix/makefile Tue Jul 3 02:02:59 2007
@@ -45,7 +45,7 @@
$(FDLIBM_DIST)w_scalb.o $(FDLIBM_DIST)w_sinh.o $(FDLIBM_DIST)w_sqrt.o
# OPTS is overriden
-OPTS := -O0 -ffloat-store -fpic
+OPT = -O0 -ffloat-store -fpic
DEFINES += -D_IEEE_LIBM
LIBNAME = $(LIBPATH)libhyfdlibm.a
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java?view=diff&rev=552748&r1=552747&r2=552748
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java Tue Jul 3 02:02:59 2007
@@ -14,13 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.harmony.luni.tests.internal.net.www.protocol.http;
import java.io.IOException;
+import java.io.InputStream;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
+import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
import java.net.Proxy;
import java.net.ProxySelector;
@@ -30,17 +31,18 @@
import java.net.SocketTimeoutException;
import java.net.URI;
import java.net.URL;
+import java.security.Permission;
import java.util.ArrayList;
import junit.framework.TestCase;
-
/**
- * Tests for <code>HTTPURLConnection</code> class constructors and methods.
- *
+ * Tests for <code>HttpURLConnection</code> class constructors and methods.
*/
public class HttpURLConnectionTest extends TestCase {
+ private static final boolean DEBUG = false;
+
private final static Object bound = new Object();
static class MockServer extends Thread {
@@ -51,7 +53,7 @@
public MockServer(String name) throws IOException {
super(name);
serverSocket = new ServerSocket(0);
- serverSocket.setSoTimeout(1000);
+ serverSocket.setSoTimeout(5000);
}
public int port() {
@@ -77,6 +79,128 @@
}
}
+ static class MockHTTPServer extends MockServer {
+ // HTTP response codes
+ static final int OK_CODE = 200;
+ static final int NOT_FOUND_CODE = 404;
+ // how many times persistent connection will be used
+ // by server
+ int persUses;
+ // result code to be sent to client
+ int responseCode;
+ // response content to be sent to client
+ String response = "<html></html>";
+ // client's POST message
+ String clientPost = "Hello from client!";
+
+ public MockHTTPServer(String name, int persUses) throws IOException {
+ this(name, persUses, OK_CODE);
+ }
+
+ public MockHTTPServer(String name, int persUses,
+ int responseCode) throws IOException {
+ super(name);
+ this.persUses = persUses;
+ this.responseCode = responseCode;
+ }
+
+ public int port() {
+ return serverSocket.getLocalPort();
+ }
+
+ @Override
+ public void run() {
+ try {
+ synchronized (bound) {
+ started = true;
+ bound.notify();
+ }
+ InputStream is = null;
+ Socket client = null;
+ try {
+ client = serverSocket.accept();
+ accepted = true;
+ for (int i=0; i<persUses; i++) {
+ if (DEBUG) {
+ System.out.println("*** Using connection for "
+ + (i+1) + " time ***");
+ }
+ byte[] buff = new byte[1024];
+ is = client.getInputStream();
+ int num = 0; // number of read bytes
+ int bytik; // read byte value
+ boolean wasEOL = false;
+ // read header (until empty string)
+ while (((bytik = is.read()) > 0)) {
+ if (bytik == '\r') {
+ bytik = is.read();
+ }
+ if (wasEOL && (bytik == '\n')) {
+ break;
+ }
+ wasEOL = (bytik == '\n');
+ buff[num++] = (byte) bytik;
+ }
+ //int num = is.read(buff);
+ String message = new String(buff, 0, num);
+ if (DEBUG) {
+ System.out.println("---- Server got request: ----\n"
+ + message + "-----------------------------");
+ }
+
+ // Act as Server (not Proxy) side
+ if (message.startsWith("POST")) {
+ // client connection sent some data
+ // if the data was not read with header
+ if (DEBUG) {
+ System.out.println(
+ "---- Server read client's data: ----");
+ }
+ num = is.read(buff);
+ message = new String(buff, 0, num);
+ if (DEBUG) {
+ System.out.println("'" + message + "'");
+ System.out.println(
+ "------------------------------------");
+ }
+ // check the received data
+ assertEquals(clientPost, message);
+ }
+
+ client.getOutputStream().write((
+ "HTTP/1.1 " + responseCode + " OK\n"
+ + "Content-type: text/html\n"
+ + "Content-length: "
+ + response.length() + "\n\n"
+ + response).getBytes());
+
+ if (responseCode != OK_CODE) {
+ // wait while test case check closed connection
+ // and interrupt this thread
+ try {
+ while (!isInterrupted()) {
+ Thread.sleep(1000);
+ }
+ } catch (Exception ignore) { }
+ }
+ }
+ } catch (SocketTimeoutException ignore) {
+ ignore.printStackTrace();
+ } finally {
+ if (is != null) {
+ is.close();
+ }
+ if (client != null) {
+ client.close();
+ }
+ serverSocket.close();
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
static class MockProxyServer extends MockServer {
boolean acceptedAuthorizedRequest;
@@ -89,18 +213,18 @@
public void run() {
try {
Socket socket = serverSocket.accept();
- socket.setSoTimeout(1000);
+ socket.setSoTimeout(5000);
byte[] buff = new byte[1024];
int num = socket.getInputStream().read(buff);
socket.getOutputStream().write((
- "HTTP/1.0 407 Proxy authentication required\n"
- + "Proxy-authenticate: Basic realm=\"remotehost\"\n\n")
+ "HTTP/1.0 407 Proxy authentication required\n"
+ + "Proxy-authenticate: Basic realm=\"remotehost\"\n\n")
.getBytes());
num = socket.getInputStream().read(buff);
if (num == -1) {
// this connection was closed, create new one:
socket = serverSocket.accept();
- socket.setSoTimeout(1000);
+ socket.setSoTimeout(5000);
num = socket.getInputStream().read(buff);
}
String request = new String(buff, 0, num);
@@ -114,7 +238,15 @@
}
}
}
-
+
+ public void setUp() {
+ if (DEBUG) {
+ System.out.println("\n==============================");
+ System.out.println("===== Execution: "+getName());
+ System.out.println("==============================");
+ }
+ }
+
/**
* ProxySelector implementation used in the test.
*/
@@ -256,7 +388,7 @@
server.join();
proxy.join();
- assertTrue("Connection does not use proxy",
+ assertTrue("Connection does not use proxy",
connection.usingProxy());
assertTrue("Proxy server was not used", proxy.accepted);
} finally {
@@ -274,17 +406,17 @@
"user", "password".toCharArray());
}
});
-
+
try {
MockProxyServer proxy = new MockProxyServer("ProxyServer");
URL url = new URL("http://remotehost:55555/requested.data");
- HttpURLConnection connection =
+ HttpURLConnection connection =
(HttpURLConnection) url.openConnection(
- new Proxy(Proxy.Type.HTTP,
+ new Proxy(Proxy.Type.HTTP,
new InetSocketAddress("localhost", proxy.port())));
- connection.setConnectTimeout(1000);
- connection.setReadTimeout(1000);
+ connection.setConnectTimeout(5000);
+ connection.setReadTimeout(5000);
proxy.start();
@@ -299,5 +431,398 @@
Authenticator.setDefault(null);
}
}
-
-}
+
+ /**
+ * Test that a connection is not closed if the client reads all the data
+ * but not closes input stream. read until -1.
+ */
+ public void testConnectionPersistence() throws Exception {
+ MockHTTPServer httpServer =
+ new MockHTTPServer("HTTP Server for persistence checking", 2);
+ httpServer.start();
+ synchronized(bound) {
+ if (!httpServer.started) {
+ bound.wait(5000);
+ }
+ }
+
+ HttpURLConnection c = (HttpURLConnection)
+ new URL("http://localhost:"+httpServer.port()).openConnection();
+ if (DEBUG) {
+ System.out.println("Actual connection class: "+c.getClass());
+ }
+
+ c.setDoInput(true);
+ c.setConnectTimeout(5000);
+ c.setReadTimeout(5000);
+ InputStream is = c.getInputStream();
+ byte[] buffer = new byte[128];
+ int totalBytes = 0;
+ int bytesRead = 0;
+ while((bytesRead = is.read(buffer)) > 0){
+ if (DEBUG) {
+ System.out.println("Client got response: '"
+ + new String(buffer, 0, bytesRead) + "'");
+ }
+ totalBytes += bytesRead;
+ }
+
+ HttpURLConnection c2 = (HttpURLConnection)
+ new URL("http://localhost:"+httpServer.port()).openConnection();
+ c2.setDoInput(true);
+ c2.setConnectTimeout(5000);
+ c2.setReadTimeout(5000);
+ is = c2.getInputStream();
+ buffer = new byte[128];
+ totalBytes = 0;
+ bytesRead = 0;
+ while((bytesRead = is.read(buffer)) > 0){
+ if (DEBUG) {
+ System.out.println("Client got response: '"
+ + new String(buffer, 0, bytesRead) + "'");
+ totalBytes += bytesRead;
+ }
+ }
+ }
+
+ /**
+ * Test that a connection is not closed if the client reads all the data
+ * but not closes input stream. read() not receives -1.
+ */
+ public void testConnectionPersistence2() throws Exception {
+ MockHTTPServer httpServer =
+ new MockHTTPServer("HTTP Server for persistence checking", 2);
+ httpServer.start();
+ synchronized(bound) {
+ if (!httpServer.started) {
+ bound.wait(5000);
+ }
+ }
+
+ HttpURLConnection c = (HttpURLConnection)
+ new URL("http://localhost:"+httpServer.port()).openConnection();
+ if (DEBUG) {
+ System.out.println("Actual connection class: "+c.getClass());
+ }
+
+ c.setDoInput(true);
+ c.setConnectTimeout(5000);
+ c.setReadTimeout(5000);
+ InputStream is = c.getInputStream();
+ int bytes2Read = httpServer.response.length();
+ byte[] buffer = new byte[httpServer.response.length()];
+ while((bytes2Read -= is.read(buffer)) > 0) { }
+ if (DEBUG) {
+ System.out.println("Client got response: '"
+ + new String(buffer) + "'");
+ }
+
+ HttpURLConnection c2 = (HttpURLConnection)
+ new URL("http://localhost:"+httpServer.port()).openConnection();
+ c2.setDoInput(true);
+ c2.setConnectTimeout(5000);
+ c2.setReadTimeout(5000);
+ is = c2.getInputStream();
+ buffer = new byte[httpServer.response.length()];
+ bytes2Read = httpServer.response.length();
+ while((bytes2Read -= is.read(buffer)) > 0) { }
+ if (DEBUG) {
+ System.out.println("Client got response: '"
+ + new String(buffer) + "'");
+ }
+ }
+
+ /**
+ * Test that a connection is not closed if it firstly does POST,
+ * and then does GET requests.
+ */
+ public void testConnectionPersistence3() throws Exception {
+ MockHTTPServer httpServer =
+ new MockHTTPServer("HTTP Server for persistence checking", 2);
+ httpServer.start();
+ synchronized(bound) {
+ if (!httpServer.started) {
+ bound.wait(5000);
+ }
+ }
+
+ HttpURLConnection c = (HttpURLConnection)
+ new URL("http://localhost:"+httpServer.port()).openConnection();
+ if (DEBUG) {
+ System.out.println("Actual connection class: "+c.getClass());
+ }
+
+ c.setDoInput(true);
+ c.setDoOutput(true);
+ c.setConnectTimeout(5000);
+ c.setReadTimeout(5000);
+ c.getOutputStream().write(httpServer.clientPost.getBytes());
+
+ InputStream is = c.getInputStream();
+ int bytes2Read = httpServer.response.length();
+ byte[] buffer = new byte[httpServer.response.length()];
+ while((bytes2Read -= is.read(buffer)) > 0) { }
+ if (DEBUG) {
+ System.out.println("Client got response: '"
+ + new String(buffer) + "'");
+ }
+
+ HttpURLConnection c2 = (HttpURLConnection)
+ new URL("http://localhost:"+httpServer.port()).openConnection();
+ c2.setDoInput(true);
+ c2.setConnectTimeout(5000);
+ c2.setReadTimeout(5000);
+ is = c2.getInputStream();
+ buffer = new byte[httpServer.response.length()];
+ bytes2Read = httpServer.response.length();
+ while((bytes2Read -= is.read(buffer)) > 0) { }
+ if (DEBUG) {
+ System.out.println("Client got response: '"
+ + new String(buffer) + "'");
+ }
+ }
+
+ /**
+ * Test that a connection is not closed if it firstly does GET,
+ * and then does POST requests.
+ */
+ public void testConnectionPersistence4() throws Exception {
+ MockHTTPServer httpServer =
+ new MockHTTPServer("HTTP Server for persistence checking", 2);
+ httpServer.start();
+ synchronized(bound) {
+ if (!httpServer.started) {
+ bound.wait(5000);
+ }
+ }
+
+ HttpURLConnection c = (HttpURLConnection)
+ new URL("http://localhost:"+httpServer.port()).openConnection();
+ if (DEBUG) {
+ System.out.println("Actual connection class: "+c.getClass());
+ }
+
+ c.setDoInput(true);
+ c.setConnectTimeout(5000);
+ c.setReadTimeout(5000);
+
+ InputStream is = c.getInputStream();
+ int bytes2Read = httpServer.response.length();
+ byte[] buffer = new byte[httpServer.response.length()];
+ while((bytes2Read = is.read(buffer)) > 0) { }
+ if (DEBUG) {
+ System.out.println("Client got response: '"
+ + new String(buffer) + "'");
+ }
+
+ HttpURLConnection c2 = (HttpURLConnection)
+ new URL("http://localhost:"+httpServer.port()).openConnection();
+ c2.setDoOutput(true);
+ c2.setDoInput(true);
+ c2.setConnectTimeout(5000);
+ c2.setReadTimeout(5000);
+ c2.getOutputStream().write(httpServer.clientPost.getBytes());
+ is = c2.getInputStream();
+ buffer = new byte[httpServer.response.length()];
+ bytes2Read = httpServer.response.length();
+ while((bytes2Read = is.read(buffer)) > 0) { }
+ if (DEBUG) {
+ System.out.println("Client got response: '"
+ + new String(buffer) + "'");
+ }
+ }
+
+ /**
+ * Test that a connection is not closed if it does POST for 2 times.
+ */
+ public void testConnectionPersistence5() throws Exception {
+ MockHTTPServer httpServer =
+ new MockHTTPServer("HTTP Server for persistence checking", 2);
+ httpServer.start();
+ synchronized(bound) {
+ if (!httpServer.started) {
+ bound.wait(5000);
+ }
+ }
+
+ HttpURLConnection c = (HttpURLConnection)
+ new URL("http://localhost:"+httpServer.port()).openConnection();
+ if (DEBUG) {
+ System.out.println("Actual connection class: "+c.getClass());
+ }
+ c.setDoOutput(true);
+ c.setDoInput(true);
+ c.setConnectTimeout(5000);
+ c.setReadTimeout(5000);
+ c.getOutputStream().write(httpServer.clientPost.getBytes());
+ InputStream is = c.getInputStream();
+ int bytes2Read = httpServer.response.length();
+ byte[] buffer = new byte[httpServer.response.length()];
+ while((bytes2Read = is.read(buffer)) > 0) { }
+ if (DEBUG) {
+ System.out.println("Client got response: '"
+ + new String(buffer) + "'");
+ }
+
+ HttpURLConnection c2 = (HttpURLConnection)
+ new URL("http://localhost:"+httpServer.port()).openConnection();
+ c2.setDoOutput(true);
+ c2.setDoInput(true);
+ c2.setConnectTimeout(5000);
+ c2.setReadTimeout(5000);
+ c2.getOutputStream().write(httpServer.clientPost.getBytes());
+ is = c2.getInputStream();
+ buffer = new byte[httpServer.response.length()];
+ bytes2Read = httpServer.response.length();
+ while((bytes2Read = is.read(buffer)) > 0) { }
+ if (DEBUG) {
+ System.out.println("Client got response: '"
+ + new String(buffer) + "'");
+ }
+ }
+
+ /**
+ * Test that a connection made through proxy will be reused
+ * for connection establishing without proxy.
+ */
+ public void testProxiedConnectionPersistence() throws Exception {
+ MockHTTPServer httpServer =
+ new MockHTTPServer("HTTP Server for persistence checking", 2);
+ httpServer.start();
+ synchronized(bound) {
+ if (!httpServer.started) {
+ bound.wait(5000);
+ }
+ }
+
+ HttpURLConnection c = (HttpURLConnection)
+ new URL("http://some.host:1234")
+ .openConnection(new Proxy(Proxy.Type.HTTP,
+ new InetSocketAddress("localhost",
+ httpServer.port())));
+ if (DEBUG) {
+ System.out.println("Actual connection class: "+c.getClass());
+ }
+ c.setDoOutput(true);
+ c.setDoInput(true);
+ c.setConnectTimeout(5000);
+ c.setReadTimeout(5000);
+ c.getOutputStream().write(httpServer.clientPost.getBytes());
+ InputStream is = c.getInputStream();
+ int bytes2Read = httpServer.response.length();
+ byte[] buffer = new byte[httpServer.response.length()];
+ while((bytes2Read = is.read(buffer)) > 0) { }
+ if (DEBUG) {
+ System.out.println("Client got response: '"
+ + new String(buffer) + "'");
+ }
+
+ HttpURLConnection c2 = (HttpURLConnection)
+ new URL("http://some.host:1234").openConnection();
+ c2.setDoOutput(true);
+ c2.setDoInput(true);
+ c2.setConnectTimeout(5000);
+ c2.setReadTimeout(5000);
+ c2.getOutputStream().write(httpServer.clientPost.getBytes());
+ is = c2.getInputStream();
+ buffer = new byte[httpServer.response.length()];
+ bytes2Read = httpServer.response.length();
+ while((bytes2Read = is.read(buffer)) > 0) { }
+ if (DEBUG) {
+ System.out.println("Client got response: '"
+ + new String(buffer) + "'");
+ }
+ }
+
+ public void testSecurityManager() throws MalformedURLException, IOException, InterruptedException {
+ try {
+ MockHTTPServer httpServer =
+ new MockHTTPServer("HTTP Server for persistence checking", 2);
+ httpServer.start();
+ synchronized(bound) {
+ if (!httpServer.started) {
+ bound.wait(5000);
+ }
+ }
+ MySecurityManager sm = new MySecurityManager();
+ System.setSecurityManager(sm);
+
+ // Check that a first connection calls checkConnect
+ try {
+ HttpURLConnection c = (HttpURLConnection)
+ new URL("http://localhost:"+httpServer.port()).openConnection();
+ if (DEBUG) {
+ System.out.println("Actual connection class: "+c.getClass());
+ }
+ c.connect();
+ fail("Should have thrown a SecurityException upon connection");
+
+ } catch (SecurityException e) {
+ }
+
+ // Now create a connection properly
+ System.setSecurityManager(null);
+ HttpURLConnection c = (HttpURLConnection)
+ new URL("http://localhost:"+httpServer.port()).openConnection();
+ c.setDoInput(true);
+ c.setConnectTimeout(5000);
+ c.setReadTimeout(5000);
+ InputStream is = c.getInputStream();
+ byte[] buffer = new byte[128];
+ int totalBytes = 0;
+ int bytesRead = 0;
+ while((bytesRead = is.read(buffer)) > 0){
+ if (DEBUG) {
+ System.out.println("Client got response: '"
+ + new String(buffer, 0, bytesRead) + "'");
+ }
+ totalBytes += bytesRead;
+ }
+
+ // Now check that a second connection also calls checkConnect
+ System.setSecurityManager(sm);
+ try {
+ HttpURLConnection c2 = (HttpURLConnection)
+ new URL("http://localhost:"+httpServer.port()).openConnection();
+ c2.setDoInput(true);
+ c2.setConnectTimeout(5000);
+ c2.setReadTimeout(5000);
+ is = c2.getInputStream();
+ buffer = new byte[128];
+ totalBytes = 0;
+ bytesRead = 0;
+ while((bytesRead = is.read(buffer)) > 0){
+ if (DEBUG) {
+ System.out.println("Client got response: '"
+ + new String(buffer, 0, bytesRead) + "'");
+ totalBytes += bytesRead;
+ }
+ }
+ fail("Expected a SecurityException to be thrown");
+ } catch (SecurityException e) {
+ }
+ } finally {
+ System.setSecurityManager(null);
+ }
+ }
+
+ private static class MySecurityManager extends SecurityManager {
+
+ @Override
+ public void checkConnect(String host, int port) {
+ throw new SecurityException();
+ }
+
+ @Override
+ public void checkConnect(String host, int port, Object context) {
+ throw new SecurityException();
+ }
+
+ @Override
+ public void checkPermission(Permission permission) {
+ // allows a new security manager to be set
+ }
+
+ }
+
+}
\ No newline at end of file
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/https/HttpsURLConnectionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/https/HttpsURLConnectionTest.java?view=diff&rev=552748&r1=552747&r2=552748
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/https/HttpsURLConnectionTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/internal/net/www/protocol/https/HttpsURLConnectionTest.java Tue Jul 3 02:02:59 2007
@@ -161,6 +161,48 @@
}
/**
+ * Checks if HTTPS connection performs initial SSL handshake with the
+ * server working over SSL, sends encrypted HTTP request,
+ * and receives expected HTTP response. After that it checks that the
+ * established connection is persistent.
+ * After HTTPS session if finished
+ * test checks connection state parameters established by
+ * HttpsURLConnection.
+ */
+ public void testHttpsPersistentConnection() throws Throwable {
+ // set up the properties defining the default values needed by SSL stuff
+ setUpStoreProperties();
+
+ try {
+ // create the SSL server socket acting as a server
+ SSLContext ctx = getContext();
+ ServerSocket ss = ctx.getServerSocketFactory()
+ .createServerSocket(0);
+
+ // create the HostnameVerifier to check hostname verification
+ TestHostnameVerifier hnv = new TestHostnameVerifier();
+ HttpsURLConnection.setDefaultHostnameVerifier(hnv);
+
+ // create url connection to be tested
+ URL url = new URL("https://localhost:" + ss.getLocalPort());
+ HttpsURLConnection connection = (HttpsURLConnection) url
+ .openConnection();
+
+ // perform the interaction between the peers
+ SSLSocket peerSocket = (SSLSocket) doPersistentInteraction(connection, ss);
+
+ // check the connection state
+ checkConnectionStateParameters(connection, peerSocket);
+
+ // should silently exit
+ connection.connect();
+ } finally {
+ // roll the properties back to system values
+ tearDownStoreProperties();
+ }
+ }
+
+ /**
* Tests the behaviour of HTTPS connection in case of unavailability
* of requested resource.
*/
@@ -408,6 +450,43 @@
}
/**
+ * Tests the behaviour in case of sending the data to the server
+ * over persistent connection.
+ */
+ public void testPersistence_doOutput() throws Throwable {
+ // setting up the properties pointing to the key/trust stores
+ setUpStoreProperties();
+
+ try {
+ // create the SSLServerSocket which will be used by server side
+ SSLServerSocket ss = (SSLServerSocket) getContext()
+ .getServerSocketFactory().createServerSocket(0);
+
+ // create the HostnameVerifier to check that Hostname verification
+ // is done
+ TestHostnameVerifier hnv = new TestHostnameVerifier();
+ HttpsURLConnection.setDefaultHostnameVerifier(hnv);
+
+ // create HttpsURLConnection to be tested
+ URL url = new URL("https://localhost:" + ss.getLocalPort());
+ HttpsURLConnection connection = (HttpsURLConnection) url
+ .openConnection();
+ connection.setDoOutput(true);
+
+ // perform the interaction between the peers and check the results
+ SSLSocket peerSocket = (SSLSocket)
+ doPersistentInteraction(connection, ss);
+ checkConnectionStateParameters(connection, peerSocket);
+
+ // should silently exit
+ connection.connect();
+ } finally {
+ // roll the properties back to system values
+ tearDownStoreProperties();
+ }
+ }
+
+ /**
* Tests HTTPS connection process made through the proxy server.
*/
public void testProxyConnection() throws Throwable {
@@ -444,6 +523,43 @@
/**
* Tests HTTPS connection process made through the proxy server.
+ * Checks that persistent connection to the host exists and can
+ * be used no in spite of explicit Proxy specifying.
+ */
+ public void testPersistentProxyConnection() throws Throwable {
+ // setting up the properties pointing to the key/trust stores
+ setUpStoreProperties();
+
+ try {
+ // create the SSLServerSocket which will be used by server side
+ ServerSocket ss = new ServerSocket(0);
+
+ // create the HostnameVerifier to check that Hostname verification
+ // is done
+ TestHostnameVerifier hnv = new TestHostnameVerifier();
+ HttpsURLConnection.setDefaultHostnameVerifier(hnv);
+
+ // create HttpsURLConnection to be tested
+ URL url = new URL("https://requested.host:55556/requested.data");
+ HttpsURLConnection connection = (HttpsURLConnection) url
+ .openConnection(new Proxy(Proxy.Type.HTTP,
+ new InetSocketAddress("localhost", ss
+ .getLocalPort())));
+
+ // perform the interaction between the peers and check the results
+ SSLSocket peerSocket = (SSLSocket) doPersistentInteraction(connection, ss);
+ checkConnectionStateParameters(connection, peerSocket);
+
+ // should silently exit
+ connection.connect();
+ } finally {
+ // roll the properties back to system values
+ tearDownStoreProperties();
+ }
+ }
+
+ /**
+ * Tests HTTPS connection process made through the proxy server.
* Proxy server needs authentication.
*/
public void testProxyAuthConnection() throws Throwable {
@@ -568,7 +684,7 @@
// perform the interaction between the peers and check the results
SSLSocket peerSocket = (SSLSocket) doInteraction(connection, ss,
- OK_CODE, true);
+ OK_CODE);
checkConnectionStateParameters(connection, peerSocket);
} finally {
// roll the properties back to system values
@@ -603,8 +719,7 @@
// perform the interaction between the peers and check the results
try {
- doInteraction(connection, ss, AUTHENTICATION_REQUIRED_CODE,
- true);
+ doInteraction(connection, ss, AUTHENTICATION_REQUIRED_CODE);
} catch (IOException e) {
// SSL Tunnelling failed
if (DO_LOG) {
@@ -704,10 +819,10 @@
}
/**
- * Returns the file name of the key/trust store. The key store file
+ * Returns the file name of the key/trust store. The key store file
* (named as "key_store." + extension equals to the default KeyStore
* type installed in the system in lower case) is searched in classpath.
- * @throws AssertionFailedError if property was not set
+ * @throws AssertionFailedError if property was not set
* or file does not exist.
*/
private static String getKeyStoreFileName() throws Exception {
@@ -826,7 +941,7 @@
public static Socket doInteraction(
final HttpURLConnection clientConnection,
final ServerSocket serverSocket) throws Throwable {
- return doInteraction(clientConnection, serverSocket, OK_CODE, false);
+ return doInteraction(clientConnection, serverSocket, OK_CODE, false, false);
}
/**
@@ -839,7 +954,31 @@
final ServerSocket serverSocket, final int responseCode)
throws Throwable {
return doInteraction(clientConnection, serverSocket, responseCode,
- false);
+ false, false);
+ }
+
+ /**
+ * Performs interaction between client's HttpURLConnection and
+ * servers side (ServerSocket) over persistent connection.
+ */
+ public static Socket doPersistentInteraction(
+ final HttpURLConnection clientConnection,
+ final ServerSocket serverSocket) throws Throwable {
+ return doInteraction(clientConnection, serverSocket, OK_CODE,
+ false, true);
+ }
+
+ /**
+ * Performs interaction between client's HttpURLConnection and
+ * servers side (ServerSocket) over persistent connection.
+ * Server will response with specified response code.
+ */
+ public static Socket doPersistentInteraction(
+ final HttpURLConnection clientConnection,
+ final ServerSocket serverSocket, final int responseCode)
+ throws Throwable {
+ return doInteraction(clientConnection, serverSocket, responseCode,
+ false, true);
}
/**
@@ -852,7 +991,8 @@
public static Socket doInteraction(
final HttpURLConnection clientConnection,
final ServerSocket serverSocket, final int responseCode,
- final boolean doAuthentication) throws Throwable {
+ final boolean doAuthentication,
+ final boolean checkPersistence) throws Throwable {
// set up the connection
clientConnection.setDoInput(true);
@@ -860,7 +1000,7 @@
clientConnection.setReadTimeout(TIMEOUT);
ServerWork server = new ServerWork(serverSocket, responseCode,
- doAuthentication);
+ doAuthentication, checkPersistence);
ClientConnectionWork client = new ClientConnectionWork(clientConnection);
@@ -868,8 +1008,6 @@
client.start();
client.join();
- server.join();
-
if (client.thrown != null) {
if (responseCode != OK_CODE) { // not OK response expected
// it is probably expected exception, keep it as is
@@ -883,6 +1021,30 @@
throw new Exception(client.thrown);
}
}
+
+ if (checkPersistence) {
+ ClientConnectionWork client2 =
+ new ClientConnectionWork((HttpURLConnection)
+ clientConnection.getURL().openConnection());
+ client2.start();
+ client2.join();
+ if (client2.thrown != null) {
+ if (responseCode != OK_CODE) { // not OK response expected
+ // it is probably expected exception, keep it as is
+ throw client2.thrown;
+ }
+ if ((client2.thrown instanceof SocketTimeoutException)
+ && (server.thrown != null)) {
+ // server's exception is more informative in this case
+ throw new Exception(server.thrown);
+ } else {
+ throw new Exception(client2.thrown);
+ }
+ }
+ }
+
+ server.join();
+
if (server.thrown != null) {
throw server.thrown;
}
@@ -998,6 +1160,9 @@
// indicates if the server needs proxy authentication
private boolean needProxyAuthentication;
+ // do we check for connection persistence
+ private boolean checkPersistence;
+
// response code to be send to the client peer
private int responseCode;
@@ -1007,7 +1172,7 @@
public ServerWork(ServerSocket serverSocket) {
// the server does not require proxy authentication
// and sends OK_CODE (OK) response code
- this(serverSocket, OK_CODE, false);
+ this(serverSocket, OK_CODE, false, false);
}
/**
@@ -1018,10 +1183,11 @@
* indicates if the server needs proxy authentication
*/
public ServerWork(ServerSocket serverSocket, int responseCode,
- boolean needProxyAuthentication) {
+ boolean needProxyAuthentication, boolean checkPersistence) {
this.serverSocket = serverSocket;
this.responseCode = responseCode;
this.needProxyAuthentication = needProxyAuthentication;
+ this.checkPersistence = checkPersistence;
// will act as a proxy server if the specified server socket
// is not a secure server socket
if (serverSocket instanceof SSLServerSocket) {
@@ -1073,105 +1239,120 @@
InputStream is = peerSocket.getInputStream();
OutputStream os = peerSocket.getOutputStream();
- num = is.read(buff);
- String message = new String(buff, 0, num);
- log("Got request:\n" + message);
- log("------------------");
-
- if (!actAsProxy) {
- // Act as Server (not Proxy) side
- if (message.startsWith("POST")) {
- // client connection sent some data
- log("try to read client data");
- num = is.read(buff);
- message = new String(buff, 0, num);
- log("client's data: '" + message + "'");
- // check the received data
- assertEquals(clientsData, message);
+ // how many times established connection will be used
+ int number_of_uses = checkPersistence ? 2 : 1;
+ for (int it=0; it<number_of_uses; it++) {
+ if (checkPersistence) {
+ log("==========================================");
+ log("Use established connection for "+(it+1)+" time");
}
- // just send the response
- os
- .write(("HTTP/1.1 " + responseCode + "\n" + httpsResponseTail)
- .getBytes());
- // and return
- log("Work is DONE");
- return;
- }
- // Do proxy work
- if (needProxyAuthentication) {
- log("Authentication required ...");
- // send Authentication Request
- os.write(respAuthenticationRequired.getBytes());
- // read response
num = is.read(buff);
- if (num == -1) {
- // this connection was closed,
- // do clean up and create new one:
- closeSocket(peerSocket);
- peerSocket = serverSocket.accept();
- peerSocket.setSoTimeout(TIMEOUT);
- log("New client connection ACCEPTED");
- is = peerSocket.getInputStream();
- os = peerSocket.getOutputStream();
+ String message = new String(buff, 0, num);
+ log("Got request:\n" + message);
+ log("------------------");
+
+ if (!actAsProxy) {
+ // Act as Server (not Proxy) side
+ if (message.startsWith("POST")) {
+ // client connection sent some data
+ log("try to read client data");
+ num = is.read(buff);
+ message = new String(buff, 0, num);
+ log("client's data: '" + message + "'");
+ // check the received data
+ assertEquals(clientsData, message);
+ }
+ // just send the response
+ os.write(("HTTP/1.1 " + responseCode + "\n"
+ + httpsResponseTail).getBytes());
+ log("Simple NON-Proxy work is DONE");
+ continue;
+ }
+
+ // Do proxy work
+ if (needProxyAuthentication) {
+ log("Authentication required ...");
+ // send Authentication Request
+ os.write(respAuthenticationRequired.getBytes());
+ // read response
num = is.read(buff);
+ if (num == -1) {
+ // this connection was closed,
+ // do clean up and create new one:
+ closeSocket(peerSocket);
+ peerSocket = serverSocket.accept();
+ peerSocket.setSoTimeout(TIMEOUT);
+ log("New client connection ACCEPTED");
+ is = peerSocket.getInputStream();
+ os = peerSocket.getOutputStream();
+ num = is.read(buff);
+ }
+ message = new String(buff, 0, num);
+ log("Got authenticated request:\n" + message);
+ log("------------------");
+ // check provided authorization credentials
+ assertTrue("Received message does not contain "
+ + "authorization credentials", message
+ .toLowerCase().indexOf("proxy-authorization:") > 0);
}
- message = new String(buff, 0, num);
- log("Got authenticated request:\n" + message);
- log("------------------");
- // check provided authorization credentials
- assertTrue("Received message does not contain "
- + "authorization credentials", message
- .toLowerCase().indexOf("proxy-authorization:") > 0);
- }
- // The content of this response will reach proxied HTTPUC
- // but will not reach proxied HTTPSUC
- // In case of HTTP connection it will be the final message,
- // in case of HTTPS connection this message will just indicate
- // that connection with remote host has been done
- // (i.e. SSL tunnel has been established).
- os.write(plainResponse.getBytes());
- log("Sent OK RESPONSE");
-
- if (message.startsWith("CONNECT")) { // request for SSL tunnel
- log("Perform SSL Handshake...");
- // create sslSocket acting as a remote server peer
- SSLSocket sslSocket = (SSLSocket) getContext()
- .getSocketFactory().createSocket(peerSocket,
- "localhost", peerSocket.getPort(), true); // do autoclose
- sslSocket.setUseClientMode(false);
- // demand client authentication
- sslSocket.setNeedClientAuth(true);
- sslSocket.startHandshake();
- peerSocket = sslSocket;
- is = peerSocket.getInputStream();
- os = peerSocket.getOutputStream();
+ if (peerSocket instanceof SSLSocket) {
+ // it will be so if we are have second iteration
+ // over persistent connection
+ os.write(("HTTP/1.1 " + OK_CODE
+ + "\n" + httpsResponseTail).getBytes());
+ log("Sent OK RESPONSE over SSL");
+ } else {
+ // The content of this response will reach proxied
+ // HTTPUC but will not reach proxied HTTPSUC
+ // In case of HTTP connection it will be the final
+ // message, in case of HTTPS connection this message
+ // will just indicate that connection with remote
+ // host has been done
+ // (i.e. SSL tunnel has been established).
+ os.write(plainResponse.getBytes());
+ log("Sent OK RESPONSE");
+ }
- // read the HTTP request sent by secure connection
- // (HTTPS request)
- num = is.read(buff);
- message = new String(buff, 0, num);
- log("[Remote Server] Request from SSL tunnel:\n" + message);
- log("------------------");
+ if (message.startsWith("CONNECT")) { // request for SSL tunnel
+ log("Perform SSL Handshake...");
+ // create sslSocket acting as a remote server peer
+ SSLSocket sslSocket = (SSLSocket) getContext()
+ .getSocketFactory().createSocket(peerSocket,
+ "localhost", peerSocket.getPort(), true); // do autoclose
+ sslSocket.setUseClientMode(false);
+ // demand client authentication
+ sslSocket.setNeedClientAuth(true);
+ sslSocket.startHandshake();
+ peerSocket = sslSocket;
+ is = peerSocket.getInputStream();
+ os = peerSocket.getOutputStream();
- if (message.startsWith("POST")) {
- // client connection sent some data
- log("[Remote Server] try to read client data");
+ // read the HTTP request sent by secure connection
+ // (HTTPS request)
num = is.read(buff);
message = new String(buff, 0, num);
- log("[Remote Server] client's data: '" + message + "'");
- // check the received data
- assertEquals(clientsData, message);
- }
+ log("[Remote Server] Request from SSL tunnel:\n" + message);
+ log("------------------");
- log("[Remote Server] Sending the response by SSL tunnel..");
- // send the response with specified response code
- os
- .write(("HTTP/1.1 " + responseCode + "\n" + httpsResponseTail)
- .getBytes());
- }
- log("Work is DONE");
+ if (message.startsWith("POST")) {
+ // client connection sent some data
+ log("[Remote Server] try to read client data");
+ num = is.read(buff);
+ message = new String(buff, 0, num);
+ log("[Remote Server] client's data: '" + message + "'");
+ // check the received data
+ assertEquals(clientsData, message);
+ }
+
+ log("[Remote Server] Sending the response by SSL tunnel..");
+ // send the response with specified response code
+ os.write(("HTTP/1.1 " + responseCode
+ + "\n" + httpsResponseTail).getBytes());
+ }
+ log("Work is DONE");
+ };
} catch (Throwable e) {
if (DO_LOG) {
e.printStackTrace();
@@ -1222,7 +1403,7 @@
}
// read the content of HTTP(s) response
InputStream is = connection.getInputStream();
- log("Input Stream obtained");
+ log("Input Stream obtained: "+is.getClass());
byte[] buff = new byte[2048];
int num = 0;
int byt = 0;
Modified: harmony/enhanced/classlib/branches/java6/modules/prefs/make/exclude.linux.x86.drl
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/prefs/make/exclude.linux.x86.drl?view=diff&rev=552748&r1=552747&r2=552748
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/prefs/make/exclude.linux.x86.drl (original)
+++ harmony/enhanced/classlib/branches/java6/modules/prefs/make/exclude.linux.x86.drl Tue Jul 3 02:02:59 2007
@@ -0,0 +1,2 @@
+#HARMONY-4289
+org/apache/harmony/prefs/tests/java/util/prefs/AbstractPreferencesTest.java
Modified: harmony/enhanced/classlib/branches/java6/modules/prefs/make/exclude.linux.x86_64.drl
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/prefs/make/exclude.linux.x86_64.drl?view=diff&rev=552748&r1=552747&r2=552748
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/prefs/make/exclude.linux.x86_64.drl (original)
+++ harmony/enhanced/classlib/branches/java6/modules/prefs/make/exclude.linux.x86_64.drl Tue Jul 3 02:02:59 2007
@@ -0,0 +1,2 @@
+#HARMONY-4289
+org/apache/harmony/prefs/tests/java/util/prefs/AbstractPreferencesTest.java