[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting/transport/http ...
Tom Elrod
tom.elrod at jboss.com
Fri Aug 25 15:50:01 EDT 2006
User: telrod
Date: 06/08/25 15:50:01
Modified: src/main/org/jboss/remoting/transport/http
HTTPClientInvoker.java
Log:
JBREM-569 - fix for http proxy
Revision Changes Path
1.27 +48 -45 JBossRemoting/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: HTTPClientInvoker.java
===================================================================
RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- HTTPClientInvoker.java 17 Jul 2006 05:34:38 -0000 1.26
+++ HTTPClientInvoker.java 25 Aug 2006 19:50:01 -0000 1.27
@@ -36,15 +36,20 @@
import org.jboss.remoting.marshal.compress.CompressingUnMarshaller;
import org.jboss.remoting.marshal.http.HTTPMarshaller;
import org.jboss.remoting.marshal.serializable.SerializableUnMarshaller;
+import org.jboss.remoting.serialization.ClassLoaderUtility;
import org.jboss.remoting.transport.web.WebUtil;
import org.jboss.util.Base64;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
@@ -453,8 +458,7 @@
// need to find out if need to use a proxy or not
String proxyHost = null;
String proxyportString = null;
- int proxyPort = -1;
- boolean proxyOn = true;
+ int proxyPort = 80;
if (metadata != null)
{
@@ -474,55 +478,54 @@
}
}
- // if not set in the metadata, try the system properties
- if (proxyHost == null)
- {
- // have found that the actual system property to be set can differ between VMs,
- // so will try all the ones I know of.
- proxyHost = System.getProperty("http.proxyHost");
- if (proxyHost == null)
+ // now determin if going to use proxy or not
+ if (proxyHost != null)
{
- proxyHost = System.getProperty("proxyHost");
- }
+ externalURL = new URL(url);
- // since not set by metadata, need to check if proxy turned off by property setting
- String proxyOnString = System.getProperty("http.proxySet");
- if (proxyOnString == null)
- {
- proxyOnString = System.getProperty("proxySet");
- }
- if (proxyOnString != null)
+ /**
+ * Since URL in jdk 1.4 does NOT have a openConnection(Proxy) method and
+ * the one in jdk 1.5 does, will have to use reflection to see if it exists before trying to set it.
+ */
+ try
{
- proxyOn = Boolean.getBoolean(proxyOnString);
- }
- }
- if (proxyPort < 0)
+ Class proxyClass = ClassLoaderUtility.loadClass("java.net.Proxy", HTTPClientInvoker.class);
+ InetSocketAddress proxyAddress = new InetSocketAddress(proxyHost, proxyPort);
+ Class[] decalredClasses = proxyClass.getDeclaredClasses();
+ Class proxyTypeClass = null;
+ for(int x = 0; x < decalredClasses.length; x++)
{
- String proxyPortString = System.getProperty("http.proxyPort");
- if (proxyPortString == null)
+ Class declaredClass = decalredClasses[x];
+ String className = declaredClass.getName();
+ if(className.endsWith("Type"))
{
- proxyPortString = System.getProperty("proxyPort");
+ proxyTypeClass = declaredClass;
+ break;
}
- if (proxyPortString != null)
- {
- try
- {
- proxyPort = Integer.parseInt(proxyPortString);
}
- catch (NumberFormatException e)
+ Object proxyType = null;
+ Field[] fields = proxyTypeClass.getDeclaredFields();
+ for(int i = 0; i < fields.length; i++)
{
- log.warn("Error converting proxy port specified (" + proxyportString + ") to a number.");
+ Field field = fields[i];
+ String fieldName = field.getName();
+ if(fieldName.endsWith("HTTP"))
+ {
+ proxyType = field.get(proxyTypeClass);
+ break;
}
}
+ Constructor proxyConstructor = proxyClass.getConstructor(new Class[] {proxyTypeClass, SocketAddress.class});
+ Object proxy = proxyConstructor.newInstance(new Object[] {proxyType, proxyAddress});
+ Method openConnection = externalURL.getClass().getMethod("openConnection", new Class[] {proxyClass});
+ httpURLConn = (HttpURLConnection)openConnection.invoke(externalURL, new Object[] {proxy});
}
-
- // now determin if going to use proxy or not
- if (proxyHost != null && proxyOn)
+ catch (Exception e)
{
- // is ok if port is -1 since URL constructor will use default port for protocol
- externalURL = new URL("http", proxyHost, proxyPort, url);
-
- httpURLConn = (HttpURLConnection) externalURL.openConnection();
+ log.error("Can not set proxy for http invocation (proxy host: " + proxyHost + ", proxy port: " + proxyPort + ") " +
+ "as this configuration requires JDK 1.5 or later. If running JDK 1.4, can use proxy by setting system properties.");
+ log.debug(e);
+ }
// since know it is a proxy being used, see if have proxy auth
String proxyAuth = getProxyAuth(metadata);
More information about the jboss-cvs-commits
mailing list