-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GEOT-6608] Fix user-agent for OSM tiles #2954
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,14 @@ | |
import java.awt.Graphics2D; | ||
import java.awt.image.BufferedImage; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URL; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import org.geotools.data.ows.HTTPClient; | ||
import org.geotools.data.ows.SimpleHttpClient; | ||
import org.geotools.geometry.jts.ReferencedEnvelope; | ||
import org.geotools.image.io.ImageIOExt; | ||
import org.geotools.util.logging.Logging; | ||
|
@@ -171,8 +176,19 @@ public BufferedImage getBufferedImage() { | |
} | ||
} | ||
|
||
@Override | ||
public BufferedImage loadImageTileImage(Tile tile) throws IOException { | ||
return ImageIOExt.readBufferedImage(getUrl()); | ||
|
||
Map<String, String> headers = new HashMap<>(); | ||
headers.put("User-Agent", "Geotools Http client"); | ||
try (InputStream is = setupInputStream(getUrl(), headers)) { | ||
return ImageIOExt.readBufferedImage(is); | ||
} | ||
} | ||
|
||
private InputStream setupInputStream(URL url, Map<String, String> headers) throws IOException { | ||
HTTPClient client = new SimpleHttpClient(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering if SimpleHttpClient should default to the new user agent. It's not the first time I see cascading blocked because servers don't like the Java user agent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that might be an even better fix - I guess. |
||
return client.get(url, headers).getResponseStream(); | ||
} | ||
|
||
/** | ||
|
@@ -372,6 +388,7 @@ public boolean equals(Object other) { | |
return getUrl().equals(((Tile) other).getUrl()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.getId(); // this.getUrl().toString(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:-p