Author: dain
Date: Tue Jul 1 23:25:05 2008
New Revision: 673292
URL: http://svn.apache.org/viewvc?rev=673292&view=rev
Log:
Change URL handling code so JVM uses keep-alive
Modified:
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
Modified:
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java?rev=673292&r1=673291&r2=673292&view=diff
==============================================================================
---
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java
(original)
+++
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java
Tue Jul 1 23:25:05 2008
@@ -46,11 +46,7 @@
if (server == null)
throw new IllegalArgumentException("Server instance cannot be
null");
- OutputStream out = null;
- ObjectOutput objectOut = null;
- ObjectInput objectIn = null;
Connection conn = null;
-
try {
/*----------------------------*/
/* Get a connection to server */
@@ -60,6 +56,7 @@
/*----------------------------------*/
/* Get output streams */
/*----------------------------------*/
+ OutputStream out;
try {
out = conn.getOuputStream();
@@ -99,6 +96,7 @@
/*----------------------------------*/
/* Get output streams */
/*----------------------------------*/
+ ObjectOutput objectOut;
try {
objectOut = new ObjectOutputStream(out);
@@ -132,7 +130,7 @@
/*----------------------------------*/
/* Get input streams */
/*----------------------------------*/
- InputStream in = null;
+ InputStream in;
try {
in = conn.getInputStream();
@@ -151,6 +149,7 @@
throw new RemoteException("Cannot deternmine server protocol
version: Received "+protocolMetaData.getSpec() , e );
}
+ ObjectInput objectIn;
try{
objectIn = new EjbObjectInputStream(in);
Modified:
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java?rev=673292&r1=673291&r2=673292&view=diff
==============================================================================
---
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
(original)
+++
openejb/trunk/openejb3/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
Tue Jul 1 23:25:05 2008
@@ -23,6 +23,7 @@
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
+import java.net.NoRouteToHostException;
import java.util.Properties;
/**
@@ -40,11 +41,10 @@
public static class HttpConnection implements Connection {
private HttpURLConnection httpURLConnection;
+ private InputStream inputStream;
+ private OutputStream outputStream;
public HttpConnection(URI uri) throws IOException {
- String host = "localhost";
-// String host = server.getLocation().getHost();
- // TODO: Use the URI for making the URL
URL url = uri.toURL();
httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setDoOutput(true);
@@ -52,15 +52,45 @@
}
public void close() throws IOException {
- httpURLConnection.disconnect();
+ IOException exception = null;
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (IOException e) {
+ exception = e;
+ }
+ }
+ if (outputStream != null) {
+ try {
+ outputStream.close();
+ } catch (IOException e) {
+ if (exception == null) {
+ exception = e;
+ }
+ }
+ }
+
+ inputStream = null;
+ outputStream = null;
+ httpURLConnection = null;
+
+ if (exception != null) {
+ throw exception;
+ }
}
- public InputStream getInputStream() throws IOException {
- return httpURLConnection.getInputStream();
+ public OutputStream getOuputStream() throws IOException {
+ if (outputStream == null) {
+ outputStream = httpURLConnection.getOutputStream();
+ }
+ return outputStream;
}
- public OutputStream getOuputStream() throws IOException {
- return httpURLConnection.getOutputStream();
+ public InputStream getInputStream() throws IOException {
+ if (inputStream == null) {
+ inputStream = httpURLConnection.getInputStream();
+ }
+ return inputStream;
}
}
}