- fixed "yacy2yacy no proxy"-problem

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5058 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
danielr 17 years ago
parent 6450a51473
commit be28af50f5

@ -151,7 +151,7 @@ public final class HTTPLoader {
requestHeader.put(httpHeader.ACCEPT_ENCODING, sb.getConfig("crawler.http.acceptEncoding", DEFAULT_ENCODING)); requestHeader.put(httpHeader.ACCEPT_ENCODING, sb.getConfig("crawler.http.acceptEncoding", DEFAULT_ENCODING));
// HTTP-Client // HTTP-Client
final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(socketTimeout, requestHeader, null); final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(socketTimeout, requestHeader);
JakartaCommonsHttpResponse res = null; JakartaCommonsHttpResponse res = null;
try { try {

@ -514,7 +514,7 @@ public class RobotsTxt {
// setup http-client // setup http-client
//TODO: adding Traffic statistic for robots download? //TODO: adding Traffic statistic for robots download?
final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(10000, reqHeaders, null); final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(10000, reqHeaders);
JakartaCommonsHttpResponse res = null; JakartaCommonsHttpResponse res = null;
try { try {
// sending the get request // sending the get request

@ -154,7 +154,7 @@ public class SitemapParser extends DefaultHandler {
// download document // download document
final httpHeader header = new httpHeader(); final httpHeader header = new httpHeader();
header.put(httpHeader.USER_AGENT, HTTPLoader.crawlerUserAgent); header.put(httpHeader.USER_AGENT, HTTPLoader.crawlerUserAgent);
final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(5000, header, null); final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(5000, header);
JakartaCommonsHttpResponse res = null; JakartaCommonsHttpResponse res = null;
try { try {
res = client.GET(siteMapURL.toString()); res = client.GET(siteMapURL.toString());

@ -94,7 +94,7 @@ public abstract class HttpClient {
public static byte[] wget(final String uri, final httpHeader header, final int timeout, final String vhost) { public static byte[] wget(final String uri, final httpHeader header, final int timeout, final String vhost) {
assert uri != null : "precondition violated: uri != null"; assert uri != null : "precondition violated: uri != null";
addHostHeader(header, vhost); addHostHeader(header, vhost);
final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(timeout, header, null); final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(timeout, header);
// do the request // do the request
try { try {
@ -141,7 +141,7 @@ public abstract class HttpClient {
* @return null on error * @return null on error
*/ */
public static httpHeader whead(final String uri, final httpHeader header) { public static httpHeader whead(final String uri, final httpHeader header) {
final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(10000, header, null); final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(10000, header);
JakartaCommonsHttpResponse response = null; JakartaCommonsHttpResponse response = null;
try { try {
response = client.HEAD(uri); response = client.HEAD(uri);

@ -32,6 +32,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map.Entry;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
import org.apache.commons.httpclient.ConnectMethod; import org.apache.commons.httpclient.ConnectMethod;
@ -139,14 +140,39 @@ public class JakartaCommonsHttpClient {
private Header[] headers = new Header[0]; private Header[] headers = new Header[0];
private httpRemoteProxyConfig proxyConfig = null; private httpRemoteProxyConfig proxyConfig = null;
private boolean useGlobalProxyConfig = true;
private boolean followRedirects = true; private boolean followRedirects = true;
private boolean ignoreCookies = false; private boolean ignoreCookies = false;
/**
* creates a new JakartaCommonsHttpClient with given timeout using global remoteProxyConfig
*
* @param timeout in milliseconds
*/
public JakartaCommonsHttpClient(final int timeout) {
this(timeout, null);
}
/** /**
* constructs a new Client with given parameters * creates a new JakartaCommonsHttpClient with given timeout and requestHeader using global remoteProxyConfig
*
* @param timeout in milliseconds
* @param header header options to send
*/
public JakartaCommonsHttpClient(final int timeout, final httpHeader header) {
super();
setTimeout(timeout);
setHeader(header);
}
/**
* creates a new JakartaCommonsHttpClient with given timeout and requestHeader using given remoteProxyConfig
*
* if proxyConfig is null, then no proxy is used
* *
* @param timeout in milliseconds * @param timeout in milliseconds
* @param header * @param header header options to send
* @param proxyConfig * @param proxyConfig
*/ */
public JakartaCommonsHttpClient(final int timeout, final httpHeader header, final httpRemoteProxyConfig proxyConfig) { public JakartaCommonsHttpClient(final int timeout, final httpHeader header, final httpRemoteProxyConfig proxyConfig) {
@ -161,9 +187,8 @@ public class JakartaCommonsHttpClient {
* @see de.anomic.http.HttpClient#setProxy(de.anomic.http.httpRemoteProxyConfig) * @see de.anomic.http.HttpClient#setProxy(de.anomic.http.httpRemoteProxyConfig)
*/ */
public void setProxy(final httpRemoteProxyConfig proxyConfig) { public void setProxy(final httpRemoteProxyConfig proxyConfig) {
if (proxyConfig != null && proxyConfig.useProxy()) { this.useGlobalProxyConfig = false;
this.proxyConfig = proxyConfig; this.proxyConfig = proxyConfig;
}
} }
/* /*
@ -381,8 +406,8 @@ public class JakartaCommonsHttpClient {
} else { } else {
headers = new Header[requestHeader.size()]; headers = new Header[requestHeader.size()];
int i = 0; int i = 0;
for (final String name : requestHeader.keySet()) { for (final Entry<String, String> header : requestHeader.entrySet()) {
headers[i] = new Header(name, requestHeader.get(name)); headers[i] = new Header(header.getKey(), header.getValue());
i++; i++;
} }
} }
@ -520,13 +545,17 @@ public class JakartaCommonsHttpClient {
/** /**
* *
* @param hostname * @param hostname
* @return * @return null if no proxy should be used
*/ */
private httpRemoteProxyConfig getProxyConfig(final String hostname) { private httpRemoteProxyConfig getProxyConfig(final String hostname) {
final httpRemoteProxyConfig hostProxyConfig; final httpRemoteProxyConfig hostProxyConfig;
if (proxyConfig != null) { if (!useGlobalProxyConfig) {
// client specific // client specific
hostProxyConfig = proxyConfig.useForHost(hostname) ? proxyConfig : null; if(proxyConfig == null) {
hostProxyConfig = null;
} else {
hostProxyConfig = proxyConfig.useForHost(hostname) ? proxyConfig : null;
}
} else { } else {
// default settings // default settings
hostProxyConfig = httpRemoteProxyConfig.getProxyConfigForHost(hostname); hostProxyConfig = httpRemoteProxyConfig.getProxyConfigForHost(hostname);
@ -603,7 +632,7 @@ public class JakartaCommonsHttpClient {
files.add(new FilePart("anotherfile.raw", new ByteArrayPartSource("anotherfile.raw", files.add(new FilePart("anotherfile.raw", new ByteArrayPartSource("anotherfile.raw",
"this is not a binary file ;)".getBytes()))); "this is not a binary file ;)".getBytes())));
System.out.println("POST " + files.size() + " elements to " + url); System.out.println("POST " + files.size() + " elements to " + url);
final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(1000, null, null); final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(1000);
resp = client.POST(url, files); resp = client.POST(url, files);
System.out.println("----- Header: -----"); System.out.println("----- Header: -----");
System.out.println(resp.getResponseHeader().toString()); System.out.println(resp.getResponseHeader().toString());

@ -70,7 +70,7 @@ public final class httpRemoteProxyConfig {
/** /**
* @return the remoteProxyConfig * @return the remoteProxyConfig
*/ */
public static httpRemoteProxyConfig getRemoteProxyConfig() { public static synchronized httpRemoteProxyConfig getRemoteProxyConfig() {
return remoteProxyConfig; return remoteProxyConfig;
} }

@ -45,6 +45,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.Map.Entry;
import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory; import org.apache.commons.fileupload.FileItemFactory;
@ -89,7 +90,7 @@ public final class httpd implements serverHandler, Cloneable {
public static final int ERRORCASE_MESSAGE = 4; public static final int ERRORCASE_MESSAGE = 4;
public static final int ERRORCASE_FILE = 5; public static final int ERRORCASE_FILE = 5;
public static httpdAlternativeDomainNames alternativeResolver = null; private static httpdAlternativeDomainNames alternativeResolver = null;
/** /**
* A hashset containing extensions that indicate content that should not be transported * A hashset containing extensions that indicate content that should not be transported
@ -349,8 +350,8 @@ public final class httpd implements serverHandler, Cloneable {
// user = addressed peer name // user = addressed peer name
// pw = addressed peer hash (b64-hash) // pw = addressed peer hash (b64-hash)
final String auth = (String) header.get(httpHeader.PROXY_AUTHORIZATION,"xxxxxx"); final String auth = (String) header.get(httpHeader.PROXY_AUTHORIZATION,"xxxxxx");
if (alternativeResolver != null) { if (getAlternativeResolver() != null) {
final String test = kelondroBase64Order.standardCoder.encodeString(alternativeResolver.myName() + ":" + alternativeResolver.myID()); final String test = kelondroBase64Order.standardCoder.encodeString(getAlternativeResolver().myName() + ":" + getAlternativeResolver().myID());
if (!test.equals(auth.trim().substring(6))) return false; if (!test.equals(auth.trim().substring(6))) return false;
} }
@ -1311,15 +1312,15 @@ public final class httpd implements serverHandler, Cloneable {
} }
// if peer has public address it will be used // if peer has public address it will be used
if (alternativeResolver != null) { if (getAlternativeResolver() != null) {
tp.put("extAddress", alternativeResolver.myIP() + ":" + alternativeResolver.myPort()); tp.put("extAddress", getAlternativeResolver().myIP() + ":" + getAlternativeResolver().myPort());
} }
// otherwise the local ip address will be used // otherwise the local ip address will be used
else { else {
tp.put("extAddress", tp.get("host", "127.0.0.1") + ":" + tp.get("port", "8080")); tp.put("extAddress", tp.get("host", "127.0.0.1") + ":" + tp.get("port", "8080"));
} }
tp.put("peerName", (alternativeResolver == null) ? "" : alternativeResolver.myName()); tp.put("peerName", (getAlternativeResolver() == null) ? "" : getAlternativeResolver().myName());
tp.put("errorMessageType", errorcase); tp.put("errorMessageType", errorcase);
tp.put("httpStatus", Integer.toString(httpStatusCode) + " " + httpStatusText); tp.put("httpStatus", Integer.toString(httpStatusCode) + " " + httpStatusText);
tp.put("requestMethod", conProp.getProperty(httpHeader.CONNECTION_PROP_METHOD)); tp.put("requestMethod", conProp.getProperty(httpHeader.CONNECTION_PROP_METHOD));
@ -1330,10 +1331,8 @@ public final class httpd implements serverHandler, Cloneable {
tp.put("errorMessageType_file", (detailedErrorMsgFile == null) ? "" : detailedErrorMsgFile.toString()); tp.put("errorMessageType_file", (detailedErrorMsgFile == null) ? "" : detailedErrorMsgFile.toString());
if ((detailedErrorMsgValues != null) && (detailedErrorMsgValues.size() > 0)) { if ((detailedErrorMsgValues != null) && (detailedErrorMsgValues.size() > 0)) {
// rewriting the value-names and add the proper name prefix: // rewriting the value-names and add the proper name prefix:
final Iterator<String> nameIter = detailedErrorMsgValues.keySet().iterator(); for(Entry<String, String> entry: detailedErrorMsgValues.entrySet()) {
while (nameIter.hasNext()) { tp.put("errorMessageType_" + entry.getKey(), entry.getValue());
final String name = nameIter.next();
tp.put("errorMessageType_" + name, detailedErrorMsgValues.get(name));
} }
} }
break; break;
@ -1385,11 +1384,9 @@ public final class httpd implements serverHandler, Cloneable {
serverFileUtils.copy(result, respond); serverFileUtils.copy(result, respond);
} }
respond.flush(); respond.flush();
} catch (final Exception e) {
throw new IOException(e.getMessage());
} finally { } finally {
if (fis != null) try { fis.close(); } catch (final Exception e) {} if (fis != null) try { fis.close(); } catch (final Exception e) { e.printStackTrace(); }
if (o != null) try { o.close(); } catch (final Exception e) {} if (o != null) try { o.close(); } catch (final Exception e) { e.printStackTrace(); }
} }
} }
@ -1622,10 +1619,10 @@ public final class httpd implements serverHandler, Cloneable {
if ((hostName == null) || (hostName.length() == 0)) return false; if ((hostName == null) || (hostName.length() == 0)) return false;
// getting ip address and port of this seed // getting ip address and port of this seed
if (alternativeResolver == null) return false; if (getAlternativeResolver() == null) return false;
// resolve ip addresses // resolve ip addresses
final InetAddress seedInetAddress = serverDomains.dnsResolve(alternativeResolver.myIP()); final InetAddress seedInetAddress = serverDomains.dnsResolve(getAlternativeResolver().myIP());
final InetAddress hostInetAddress = serverDomains.dnsResolve(hostName); final InetAddress hostInetAddress = serverDomains.dnsResolve(hostName);
if (seedInetAddress == null || hostInetAddress == null) return false; if (seedInetAddress == null || hostInetAddress == null) return false;
@ -1682,7 +1679,7 @@ public final class httpd implements serverHandler, Cloneable {
final Integer dstPort = (idx != -1) ? Integer.valueOf(hostName.substring(idx+1).trim()) : Integer.valueOf(80); final Integer dstPort = (idx != -1) ? Integer.valueOf(hostName.substring(idx+1).trim()) : Integer.valueOf(80);
// if the hostname endswith thisPeerName.yacy ... // if the hostname endswith thisPeerName.yacy ...
final String alternativeAddress = (alternativeResolver == null) ? null : alternativeResolver.myAlternativeAddress(); final String alternativeAddress = (getAlternativeResolver() == null) ? null : getAlternativeResolver().myAlternativeAddress();
if ((alternativeAddress != null) && (dstHost.endsWith(alternativeAddress))) { if ((alternativeAddress != null) && (dstHost.endsWith(alternativeAddress))) {
return true; return true;
/* /*
@ -1703,5 +1700,19 @@ public final class httpd implements serverHandler, Cloneable {
} }
} catch (final Exception e) {} } catch (final Exception e) {}
return false; return false;
}
/**
* @param alternativeResolver the alternativeResolver to set
*/
public static void setAlternativeResolver(httpdAlternativeDomainNames alternativeResolver) {
httpd.alternativeResolver = alternativeResolver;
}
/**
* @return the alternativeResolver
*/
static httpdAlternativeDomainNames getAlternativeResolver() {
return alternativeResolver;
} }
} }

@ -1068,7 +1068,7 @@ public final class httpdProxyHandler {
* @return * @return
*/ */
private static String resolveYacyDomains(final String host) { private static String resolveYacyDomains(final String host) {
return (httpd.alternativeResolver == null) ? null : httpd.alternativeResolver.resolve(host); return (httpd.getAlternativeResolver() == null) ? null : httpd.getAlternativeResolver().resolve(host);
} }
/** /**
@ -1121,7 +1121,7 @@ public final class httpdProxyHandler {
*/ */
private static JakartaCommonsHttpClient setupHttpClient(final httpHeader requestHeader, final String connectHost) { private static JakartaCommonsHttpClient setupHttpClient(final httpHeader requestHeader, final String connectHost) {
// setup HTTP-client // setup HTTP-client
final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(timeout, requestHeader, null); final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(timeout, requestHeader);
client.setFollowRedirects(false); client.setFollowRedirects(false);
// cookies are handled by the user's browser // cookies are handled by the user's browser
client.setIgnoreCookies(true); client.setIgnoreCookies(true);
@ -1244,7 +1244,7 @@ public final class httpdProxyHandler {
private static void setViaHeader(final httpHeader header, final String httpVer) { private static void setViaHeader(final httpHeader header, final String httpVer) {
if (!switchboard.getConfigBool("proxy.sendViaHeader", true)) return; if (!switchboard.getConfigBool("proxy.sendViaHeader", true)) return;
final String myAddress = (httpd.alternativeResolver == null) ? null : httpd.alternativeResolver.myAlternativeAddress(); final String myAddress = (httpd.getAlternativeResolver() == null) ? null : httpd.getAlternativeResolver().myAlternativeAddress();
if (myAddress != null) { if (myAddress != null) {
// getting header set by other proxies in the chain // getting header set by other proxies in the chain

@ -248,7 +248,7 @@ public final class indexRepositoryReference {
final yacyURL newUrl = new yacyURL(newUrlStr, null); final yacyURL newUrl = new yacyURL(newUrlStr, null);
// doing a http head request to test if the url is correct // doing a http head request to test if the url is correct
final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(10000, null, null); final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(10000);
client.setProxy(proxyConfig); client.setProxy(proxyConfig);
JakartaCommonsHttpResponse res = null; JakartaCommonsHttpResponse res = null;
try { try {

@ -888,7 +888,7 @@ public final class plasmaParser {
contentURL = new yacyURL(args[1], null); contentURL = new yacyURL(args[1], null);
// downloading the document content // downloading the document content
final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(5000, null, null); final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(5000);
res = client.GET(args[1]); res = client.GET(args[1]);
if (res.getStatusCode() != 200) { if (res.getStatusCode() != 200) {

@ -46,11 +46,11 @@ public final class serverSystem {
public static final String blankTypeString = "____"; public static final String blankTypeString = "____";
// system-identification statics // system-identification statics
public static int systemOS = systemUnknown; public static final int systemOS;
public static boolean isMacArchitecture = false; public static final boolean isMacArchitecture;
public static boolean isUnixFS = false; public static final boolean isUnixFS;
public static boolean canExecUnix = false; public static final boolean canExecUnix;
public static boolean isWindows = false; public static final boolean isWindows;
// calculated system constants // calculated system constants
public static int maxPathLength = 65535; public static int maxPathLength = 65535;
@ -317,6 +317,7 @@ public final class serverSystem {
} }
} }
} catch (final Exception e) { } catch (final Exception e) {
System.err.println("ERROR "+ e.getClass() +" in openBrowser(): "+ e.getMessage());
System.out.println("please start your browser and open the following location: " + url); System.out.println("please start your browser and open the following location: " + url);
} }
} }

@ -270,7 +270,7 @@ public final class yacyClient {
final httpHeader header = new httpHeader(); final httpHeader header = new httpHeader();
header.put(httpHeader.USER_AGENT, HTTPLoader.yacyUserAgent); header.put(httpHeader.USER_AGENT, HTTPLoader.yacyUserAgent);
header.put(httpHeader.HOST, vhost); header.put(httpHeader.HOST, vhost);
final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(timeout, header, null); final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(timeout, header);
client.setProxy(proxyConfig()); client.setProxy(proxyConfig());
JakartaCommonsHttpResponse res = null; JakartaCommonsHttpResponse res = null;

@ -127,7 +127,7 @@ public final class yacySeedDB implements httpdAlternativeDomainNames {
lastSeedUpload_seedDBSize = sizeConnected(); lastSeedUpload_seedDBSize = sizeConnected();
// tell the httpdProxy how to find this table as address resolver // tell the httpdProxy how to find this table as address resolver
httpd.alternativeResolver = this; httpd.setAlternativeResolver(this);
} }
private synchronized void initMySeed() { private synchronized void initMySeed() {
@ -850,7 +850,7 @@ public final class yacySeedDB implements httpdAlternativeDomainNames {
reqHeader.put(httpHeader.USER_AGENT, HTTPLoader.yacyUserAgent); reqHeader.put(httpHeader.USER_AGENT, HTTPLoader.yacyUserAgent);
// init http-client // init http-client
final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(10000, reqHeader, null); final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(10000, reqHeader);
byte[] content = null; byte[] content = null;
JakartaCommonsHttpResponse res = null; JakartaCommonsHttpResponse res = null;
try { try {

@ -340,7 +340,7 @@ public final class yacyVersion implements Comparator<yacyVersion>, Comparable<ya
File download = null; File download = null;
final httpHeader header = new httpHeader(); final httpHeader header = new httpHeader();
header.put(httpHeader.USER_AGENT, HTTPLoader.yacyUserAgent); header.put(httpHeader.USER_AGENT, HTTPLoader.yacyUserAgent);
final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(120000, header, null); final JakartaCommonsHttpClient client = new JakartaCommonsHttpClient(120000, header);
JakartaCommonsHttpResponse res = null; JakartaCommonsHttpResponse res = null;
final String name = release.url.getFileName(); final String name = release.url.getFileName();
try { try {

@ -568,7 +568,7 @@ public final class yacy {
// send 'wget' to web interface // send 'wget' to web interface
final httpHeader requestHeader = new httpHeader(); final httpHeader requestHeader = new httpHeader();
requestHeader.put(httpHeader.AUTHORIZATION, "realm=" + encodedPassword); // for http-authentify requestHeader.put(httpHeader.AUTHORIZATION, "realm=" + encodedPassword); // for http-authentify
final JakartaCommonsHttpClient con = new JakartaCommonsHttpClient(10000, requestHeader, null); final JakartaCommonsHttpClient con = new JakartaCommonsHttpClient(10000, requestHeader);
JakartaCommonsHttpResponse res = null; JakartaCommonsHttpResponse res = null;
try { try {
res = con.GET("http://localhost:"+ port +"/Steering.html?shutdown="); res = con.GET("http://localhost:"+ port +"/Steering.html?shutdown=");

Loading…
Cancel
Save