Changeset 35060 in osm for applications/editors


Ignore:
Timestamp:
2019-07-09T02:24:55+02:00 (5 years ago)
Author:
donvip
Message:

fix #josm17888 - fix errors met during upload test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/http2/src/org/openstreetmap/josm/plugins/http2/Http2Client.java

    r35059 r35060  
    1414import java.net.http.HttpResponse.BodyHandlers;
    1515import java.time.Duration;
    16 import java.time.LocalDateTime;
    17 import java.time.ZoneOffset;
     16import java.time.Instant;
     17import java.time.ZoneId;
     18import java.time.ZonedDateTime;
    1819import java.time.format.DateTimeFormatter;
    1920import java.time.temporal.ChronoField;
     
    2526import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    2627import org.openstreetmap.josm.tools.JosmRuntimeException;
     28import org.openstreetmap.josm.tools.Logging;
    2729import org.openstreetmap.josm.tools.Utils;
    2830
     
    4244    @Override
    4345    protected void setupConnection(ProgressMonitor progressMonitor) throws IOException {
    44         clientBuilder = HttpClient.newBuilder()
    45                 .connectTimeout(Duration.ofMillis(getConnectTimeout()))
    46                 .followRedirects(Redirect.NEVER); // we do that ourselves
     46        clientBuilder = HttpClient.newBuilder().followRedirects(Redirect.NEVER); // we do that ourselves
     47        int timeout = getConnectTimeout();
     48        if (timeout > 0) {
     49            clientBuilder.connectTimeout(Duration.ofMillis(timeout));
     50        }
    4751        try {
    4852            requestBuilder = HttpRequest.newBuilder()
     
    5155                              ? BodyPublishers.ofByteArray(getRequestBody())
    5256                              : BodyPublishers.noBody())
    53                       .header("User-Agent", Version.getInstance().getFullAgentString())
    54                       .timeout(Duration.ofMillis(getReadTimeout()));
     57                      .header("User-Agent", Version.getInstance().getFullAgentString());
    5558        } catch (URISyntaxException e) {
    5659            throw new IOException(e);
    5760        }
     61        timeout = getReadTimeout();
     62        if (timeout > 0) {
     63            requestBuilder.timeout(Duration.ofMillis(timeout));
     64        }
    5865        if (getIfModifiedSince() > 0) {
    5966            requestBuilder.header("If-Modified-Since", DateTimeFormatter.RFC_1123_DATE_TIME.format(
    60                     LocalDateTime.ofEpochSecond(getIfModifiedSince() / 1000, 0, ZoneOffset.UTC)));
     67                    ZonedDateTime.ofInstant(Instant.ofEpochMilli(getIfModifiedSince()), ZoneId.systemDefault())));
    6168        }
    6269        if (!isUseCache()) {
     
    6572        for (Map.Entry<String, String> header : getHeaders().entrySet()) {
    6673            if (header.getValue() != null) {
    67                 requestBuilder.header(header.getKey(), header.getValue());
     74                try {
     75                    requestBuilder.header(header.getKey(), header.getValue());
     76                } catch (IllegalArgumentException e) {
     77                    Logging.warn(e.getMessage());
     78                }
    6879            }
    6980        }
Note: See TracChangeset for help on using the changeset viewer.