Ignore:
Timestamp:
2017-08-02T20:41:01+02:00 (7 years ago)
Author:
Don-vip
Message:

see #15102 - first batch of HTTP unit tests mocking, using WireMock 2.7.1

Location:
trunk/src/org/openstreetmap/josm/io
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/NameFinder.java

    r11746 r12557  
    1818import org.openstreetmap.josm.data.osm.PrimitiveId;
    1919import org.openstreetmap.josm.data.osm.SimplePrimitiveId;
     20import org.openstreetmap.josm.data.preferences.StringProperty;
    2021import org.openstreetmap.josm.tools.HttpClient;
     22import org.openstreetmap.josm.tools.HttpClient.Response;
    2123import org.openstreetmap.josm.tools.OsmUrlToBounds;
    2224import org.openstreetmap.josm.tools.UncheckedParseException;
     
    3436
    3537    /**
    36      * Nominatim URL.
     38     * Nominatim default URL.
    3739     */
    3840    public static final String NOMINATIM_URL = "https://nominatim.openstreetmap.org/search?format=xml&q=";
     41
     42    /**
     43     * Nominatim URL property.
     44     * @since xxx
     45     */
     46    public static final StringProperty NOMINATIM_URL_PROP = new StringProperty("nominatim-url", NOMINATIM_URL);
    3947
    4048    private NameFinder() {
     
    4856     */
    4957    public static List<SearchResult> queryNominatim(final String searchExpression) throws IOException {
    50         return query(new URL(NOMINATIM_URL + Utils.encodeUrl(searchExpression)));
     58        return query(new URL(NOMINATIM_URL_PROP.get() + Utils.encodeUrl(searchExpression)));
    5159    }
    5260
     
    5967    public static List<SearchResult> query(final URL url) throws IOException {
    6068        final HttpClient connection = HttpClient.create(url);
    61         connection.connect();
    62         try (Reader reader = connection.getResponse().getContentReader()) {
     69        Response response = connection.connect();
     70        if (response.getResponseCode() >= 400) {
     71            throw new IOException(response.getResponseMessage() + ": " + response.fetchContent());
     72        }
     73        try (Reader reader = response.getContentReader()) {
    6374            return parseSearchResults(reader);
    6475        } catch (ParserConfigurationException | SAXException ex) {
  • trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java

    r12475 r12557  
    3030import org.openstreetmap.josm.data.projection.Projections;
    3131import org.openstreetmap.josm.tools.HttpClient;
     32import org.openstreetmap.josm.tools.HttpClient.Response;
    3233import org.openstreetmap.josm.tools.Utils;
    3334import org.w3c.dom.Document;
     
    226227        }
    227228
    228         final String incomingData = HttpClient.create(getCapabilitiesUrl).connect().fetchContent();
     229        final Response response = HttpClient.create(getCapabilitiesUrl).connect();
     230        final String incomingData = response.fetchContent();
    229231        Main.debug("Server response to Capabilities request:");
    230232        Main.debug(incomingData);
     233
     234        if (response.getResponseCode() >= 400) {
     235            throw new WMSGetCapabilitiesException(response.getResponseMessage(), incomingData);
     236        }
    231237
    232238        try {
Note: See TracChangeset for help on using the changeset viewer.