Skip to content

Commit

Permalink
Locale and Build fixes (#679)
Browse files Browse the repository at this point in the history
* parse HTTP date correctly on JVM with non-EN default locale

E.g. https://tools.ietf.org/html/rfc822#section-5 defines the valid
tokens for such dates and those have to be in EN-locale

#622

Signed-off-by: Christian Nüssgens <[email protected]>
  • Loading branch information
nuessgens authored and jansupol committed Dec 18, 2019
1 parent 4ed2ec7 commit 825e872
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.glassfish.tyrus.container.jdk.client;

import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;

import javax.websocket.ContainerProvider;
Expand All @@ -33,6 +35,10 @@ public class UnknownHostTest {

private static final Logger LOG = Logger.getLogger(UnknownHostTest.class.getName());

@Before
public void assumeUnixOs() {
Assume.assumeTrue(isUnixOs());
}

@Test
public void testIncreaseFileDescriptorsOnTyrusImplementationInCaseOfUnresolvedAddressException() throws Exception {
Expand Down Expand Up @@ -82,6 +88,11 @@ private long getOpenFileDescriptorCount() {
.getOperatingSystemMXBean()).getOpenFileDescriptorCount());
}

private boolean isUnixOs() {
return (java.lang.management.ManagementFactory
.getOperatingSystemMXBean() instanceof com.sun.management.UnixOperatingSystemMXBean);
}

private static class WebSocketClientEndpoint extends Endpoint {

@Override
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/glassfish/tyrus/core/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,15 +452,15 @@ public static int getWsPort(URI uri, String scheme) {
* @throws ParseException if the specified string cannot be parsed in neither of all three HTTP date formats.
*/
public static Date parseHttpDate(String stringValue) throws ParseException {
SimpleDateFormat formatRfc1123 = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
SimpleDateFormat formatRfc1123 = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH);
try {
return formatRfc1123.parse(stringValue);
} catch (ParseException e) {
SimpleDateFormat formatRfc1036 = new SimpleDateFormat("EEE, dd-MMM-yy HH:mm:ss zzz");
SimpleDateFormat formatRfc1036 = new SimpleDateFormat("EEE, dd-MMM-yy HH:mm:ss zzz", Locale.ENGLISH);
try {
return formatRfc1036.parse(stringValue);
} catch (ParseException e1) {
SimpleDateFormat formatAnsiCAsc = new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy");
SimpleDateFormat formatAnsiCAsc = new SimpleDateFormat("EEE MMM d HH:mm:ss yyyy", Locale.ENGLISH);
return formatAnsiCAsc.parse(stringValue);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.IOException;
import java.net.URI;
import java.util.Date;
import java.util.Locale;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -72,7 +73,7 @@ public void testServiceUnavailableWithDate() throws InterruptedException, Deploy
server = startServer(RetryAfterEchoEndpoint.class);

testRetryAfter(
new java.text.SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz")
new java.text.SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH)
.format(new Date(System.currentTimeMillis() + 1000)));

} finally {
Expand Down

0 comments on commit 825e872

Please sign in to comment.