You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@xml.apache.org by sa...@locus.apache.org on 2000/11/14 08:33:24 UTC
cvs commit: xml-soap/java/src/org/apache/soap/util/net HTTPUtils.java
sanjiva 00/11/13 23:33:24
Modified: java/src/org/apache/soap/util/net HTTPUtils.java
Log:
adds support for making SOAP calls through an HTTP proxy server.
Submitted by: Akinori ITO <ak...@paso.fujitsu.co.jp>
Reviewed by: Sanjiva Weerawarana <sa...@watson.ibm.com>
Revision Changes Path
1.8 +26 -3 xml-soap/java/src/org/apache/soap/util/net/HTTPUtils.java
Index: HTTPUtils.java
===================================================================
RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/util/net/HTTPUtils.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- HTTPUtils.java 2000/10/23 19:55:35 1.7
+++ HTTPUtils.java 2000/11/14 07:33:24 1.8
@@ -74,6 +74,8 @@
private static final String HEADER_CONTENT_TYPE = "Content-Type";
private static final String HEADER_CONTENT_LENGTH = "Content-Length";
private static final int HTTP_DEFAULT_PORT = 80;
+ private static String HTTP_PROXY_HOST = null;
+ private static int HTTP_PROXY_PORT = 80;
/**
* An instance of this class is returned by post.
@@ -119,7 +121,12 @@
if (port < 0) // No port given..use HTTP default which is pry 80 :-)
port = HTTP_DEFAULT_PORT;
- Socket s = new Socket (url.getHost (), port);
+ Socket s;
+ if (HTTP_PROXY_HOST == null) {
+ s = new Socket (url.getHost (), port);
+ } else {
+ s = new Socket (HTTP_PROXY_HOST, HTTP_PROXY_PORT);
+ }
s.setSoTimeout(timeout);
out = new PrintWriter (s.getOutputStream ());
in = new BufferedReader (new InputStreamReader (s.getInputStream ()));
@@ -129,8 +136,13 @@
}
/* send it out */
- out.print (HTTP_POST + " " + url.getFile() + " HTTP/" + HTTP_VERSION +
- "\r\n");
+ if (HTTP_PROXY_HOST == null) {
+ out.print (HTTP_POST + " " + url.getFile() + " HTTP/" + HTTP_VERSION +
+ "\r\n");
+ } else {
+ out.print (HTTP_POST + " " + url.toString() + " HTTP/" + HTTP_VERSION +
+ "\r\n");
+ }
out.print (HEADER_HOST + ": " + url.getHost () + ':' + port + "\r\n");
out.print (HEADER_CONTENT_TYPE + ": " + contentType + "\r\n");
out.print (HEADER_CONTENT_LENGTH + ": " + content.length () + "\r\n");
@@ -194,5 +206,16 @@
/* all done */
return new Response (statusCode, statusString, respHeaders,
respContentLength, respContentType, in);
+ }
+
+ /**
+ * Set HTTP proxy.
+ *
+ * @param host the HTTP proxy host or null if no proxy.
+ * @param port the HTTP proxy port
+ */
+ public static void setProxy (String host, int port) {
+ HTTP_PROXY_HOST = host;
+ HTTP_PROXY_PORT = port;
}
}