Skip to content

Commit 8037b47

Browse files
vavishalsenivam
authored andcommitted
Last-Modified header is garbled when accessing wadl document on Japanese locale (eclipse-ee4j#5698)
* Last-Modified header is garbled when accessing wadl document on Japanese locale Signed-off-by: Vaibhav Vishal <vaibhav.vishal@oracle.com>
1 parent c9924cf commit 8037b47

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

core-server/src/main/java/org/glassfish/jersey/server/wadl/internal/WadlResource.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2024 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -21,6 +21,7 @@
2121
import java.net.URI;
2222
import java.text.SimpleDateFormat;
2323
import java.util.Date;
24+
import java.util.Locale;
2425

2526
import javax.ws.rs.GET;
2627
import javax.ws.rs.Path;
@@ -62,7 +63,7 @@ public final class WadlResource {
6263

6364

6465
public WadlResource() {
65-
this.lastModified = new SimpleDateFormat(HTTPDATEFORMAT).format(new Date());
66+
this.lastModified = new SimpleDateFormat(HTTPDATEFORMAT, Locale.US).format(new Date());
6667
}
6768

6869
private boolean isCached(UriInfo uriInfo, boolean detailedWadl) {
@@ -81,7 +82,7 @@ public synchronized Response getWadl(@Context UriInfo uriInfo) {
8182
if ((wadlXmlRepresentation == null) || (!isCached(uriInfo, detailedWadl))) {
8283
this.lastBaseUri = uriInfo.getBaseUri();
8384
lastDetailedWadl = detailedWadl;
84-
this.lastModified = new SimpleDateFormat(HTTPDATEFORMAT).format(new Date());
85+
this.lastModified = new SimpleDateFormat(HTTPDATEFORMAT, Locale.US).format(new Date());
8586

8687
ApplicationDescription applicationDescription = wadlContext.getApplication(uriInfo,
8788
detailedWadl);

tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/wadl/WadlResourceTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2022 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2024 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -30,6 +30,7 @@
3030
import java.util.Collections;
3131
import java.util.HashMap;
3232
import java.util.List;
33+
import java.util.Locale;
3334
import java.util.Map;
3435
import java.util.Properties;
3536
import java.util.concurrent.ExecutionException;
@@ -108,6 +109,7 @@
108109
import static org.hamcrest.CoreMatchers.is;
109110
import static org.hamcrest.CoreMatchers.notNullValue;
110111
import static org.hamcrest.MatcherAssert.assertThat;
112+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
111113
import static org.junit.jupiter.api.Assertions.assertEquals;
112114
import static org.junit.jupiter.api.Assertions.assertTrue;
113115

@@ -399,6 +401,20 @@ public void testLastModifiedGET() {
399401
assertTrue(r.getHeaders().containsKey("Last-modified"));
400402
}
401403

404+
@Test
405+
public void testLastModifiedGETOnJPLocale() {
406+
Locale defaultLocale = Locale.getDefault();
407+
try {
408+
Locale.setDefault(new Locale("ja", "JP"));
409+
final WebTarget target = target("/application.wadl");
410+
411+
final Response r = target.queryParam(WadlUtils.DETAILED_WADL_QUERY_PARAM, "true").request().get(Response.class);
412+
assertDoesNotThrow(() -> r.getLastModified());
413+
} finally {
414+
Locale.setDefault(defaultLocale);
415+
}
416+
}
417+
402418
@Test
403419
public void testLastModifiedOPTIONS() {
404420
final WebTarget target = target("/widgets/3/verbose");

0 commit comments

Comments
 (0)