Changeset 4228 in josm for trunk/src/org


Ignore:
Timestamp:
2011-07-11T15:53:09+02:00 (13 years ago)
Author:
stoecker
Message:

support non-standard headers for some WMS servers

File:
1 edited

Legend:

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

    r4184 r4228  
    1919import java.text.NumberFormat;
    2020import java.util.ArrayList;
     21import java.util.Map.Entry;
    2122import java.util.Locale;
     23import java.util.Map;
     24import java.util.HashMap;
    2225import java.util.regex.Matcher;
    2326import java.util.regex.Pattern;
     
    4447    protected String baseURL;
    4548    private final boolean urlWithPatterns;
     49    private Map<String, String> props = new HashMap<String, String>();
    4650
    4751    public WMSGrabber(MapView mv, WMSLayer layer) {
     
    5054        /* URL containing placeholders? */
    5155        urlWithPatterns = ImageryInfo.isUrlWithPatterns(baseURL);
     56        if(layer.getInfo().getCookies() != null && !layer.getInfo().getCookies().equals("")) {
     57            props.put("Cookie", layer.getInfo().getCookies());
     58        }
     59        props.put("User-Agent", Main.pref.get("imagery.wms.user_agent", Version.getInstance().getAgentString()));
     60        Pattern pattern = Pattern.compile("\\{header\\(([^,]+),([^}]+)\\)\\}");
     61        StringBuffer output = new StringBuffer();
     62        Matcher matcher = pattern.matcher(this.baseURL);
     63        while (matcher.find()) {
     64            props.put(matcher.group(1),matcher.group(2));
     65            matcher.appendReplacement(output, "");
     66        }
     67        matcher.appendTail(output);
     68        this.baseURL = output.toString();
    5269    }
    5370
     
    211228
    212229        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    213         if(layer.getInfo().getCookies() != null && !layer.getInfo().getCookies().equals("")) {
    214             conn.setRequestProperty("Cookie", layer.getInfo().getCookies());
    215         }
    216         conn.setRequestProperty("User-Agent", Main.pref.get("imagery.wms.user_agent", Version.getInstance().getAgentString()));
     230        for(Entry<String, String> e : props.entrySet()) {
     231            conn.setRequestProperty(e.getKey(), e.getValue());
     232        }
    217233        conn.setConnectTimeout(Main.pref.getInteger("socket.timeout.connect",15) * 1000);
    218234        conn.setReadTimeout(Main.pref.getInteger("socket.timeout.read", 30) * 1000);
Note: See TracChangeset for help on using the changeset viewer.