Skip to content

Commit ad24cfd

Browse files
committed
Entity Provider for java.nio.file.Path
1 parent c0a63aa commit ad24cfd

File tree

14 files changed

+336
-15
lines changed

14 files changed

+336
-15
lines changed

jaxrs-spec/src/main/asciidoc/chapters/appendix/_change-log.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
////
22
*******************************************************************
3-
* Copyright (c) 2019, 2024 Eclipse Foundation
3+
* Copyright (c) 2019 Eclipse Foundation
44
*
55
* This specification document is made available under the terms
66
* of the Eclipse Foundation Specification License v1.0, which is
@@ -12,6 +12,8 @@
1212
[[change-log]]
1313
== Change Log
1414

15+
include::_changes-since-4.0-release.adoc[]
16+
1517
include::_changes-since-3.1-release.adoc[]
1618

1719
include::_changes-since-3.0-release.adoc[]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
////
2+
*******************************************************************
3+
* Copyright (c) 2024 Eclipse Foundation
4+
*
5+
* This specification document is made available under the terms
6+
* of the Eclipse Foundation Specification License v1.0, which is
7+
* available at https://www.eclipse.org/legal/efsl.php.
8+
*******************************************************************
9+
////
10+
11+
[[changes-since-4.0-release]]
12+
=== Changes Since 4.0 Release
13+
14+
* <<standard_entity_providers>>: Added entity provider for `java.nio.file.Path`

jaxrs-spec/src/main/asciidoc/chapters/providers/_entity_providers.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
////
22
*******************************************************************
3-
* Copyright (c) 2019, 2021 Eclipse Foundation
3+
* Copyright (c) 2019 Eclipse Foundation
44
*
55
* This specification document is made available under the terms
66
* of the Eclipse Foundation Specification License v1.0, which is
@@ -138,6 +138,8 @@ type combinations:
138138
All media types (`\*/*`).
139139
`java.io.File`::
140140
All media types (`\*/*`).
141+
`java.nio.file.Path`::
142+
All media types (`\*/*`).
141143
`jakarta.activation.DataSource`::
142144
All media types (`\*/*`).
143145
`javax.xml.transform.Source`::

jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/jaxrs21/ee/sse/sseeventsink/MBWCheckResource.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2020 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017 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
@@ -133,6 +133,28 @@ public void sendFile(@Context SseEventSink sink, @Context Sse sse) {
133133
}
134134
}
135135

136+
@GET
137+
@Path("path")
138+
@Produces(MediaType.SERVER_SENT_EVENTS)
139+
public void sendPath(@Context SseEventSink sink, @Context Sse sse) {
140+
java.nio.file.Path p;
141+
try (SseEventSink s = sink) {
142+
try {
143+
p = Files.createTempFile("tck", "temppath");
144+
Files.write(p, MESSAGE.getBytes(), StandardOpenOption.CREATE,
145+
StandardOpenOption.APPEND);
146+
p.toFile().deleteOnExit();
147+
s.send(sse.newEventBuilder().data(p).mediaType(MediaType.WILDCARD_TYPE)
148+
.build());
149+
} catch (IOException e) {
150+
s.send(sse.newEvent(e.getMessage()));
151+
throw new RuntimeException(e); // log to server log
152+
}
153+
} catch (IOException e) {
154+
LOG.log(Level.WARNING, "Failed to close SseEventSink", e);
155+
}
156+
}
157+
136158
@GET
137159
@Path("inputstream")
138160
@Produces(MediaType.SERVER_SENT_EVENTS)

jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/spec/filter/interceptor/JAXRSClientIT.java

Lines changed: 107 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013 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
@@ -22,6 +22,7 @@
2222
import java.io.IOException;
2323
import java.io.InputStreamReader;
2424
import java.io.InputStream;
25+
import java.nio.file.Files;
2526

2627
import javax.xml.namespace.QName;
2728

@@ -548,7 +549,7 @@ public void fileReaderContainerInterceptorTest() throws Fault {
548549
@Test
549550
@Tag("xml_binding")
550551
public void fileReaderNoInterceptorTest() throws Fault {
551-
setProperty(Property.REQUEST, buildRequest(Request.POST, "postfile"));
552+
setProperty(Property.REQUEST, buildRequest(Request.POST, "postpath"));
552553
setRequestContentEntity(content);
553554
setProperty(Property.SEARCH_STRING, content);
554555
invoke();
@@ -620,6 +621,110 @@ public void fileWriterClientInterceptorTest() throws Fault {
620621
logMsg("JAXRS called registered writer interceptor for file provider");
621622
}
622623

624+
// ------------------------- Path -----------------------------------
625+
626+
/*
627+
* @testName: pathReaderContainerInterceptorTest
628+
*
629+
* @assertion_ids: JAXRS:SPEC:84;
630+
*
631+
* @test_Strategy: JAX-RS implementations are REQUIRED to call registered
632+
* interceptors when mapping representations to Java types and vice versa.
633+
*/
634+
@Test
635+
@Tag("xml_binding")
636+
public void pathReaderContainerInterceptorTest() throws Fault {
637+
addInterceptors(EntityReaderInterceptor.class);
638+
setProperty(Property.REQUEST, buildRequest(Request.POST, "postpath"));
639+
setRequestContentEntity(content);
640+
setProperty(Property.SEARCH_STRING,
641+
EntityReaderInterceptor.class.getName());
642+
setProperty(Property.UNEXPECTED_RESPONSE_MATCH, Resource.DIRECTION);
643+
invoke();
644+
logMsg("JAXRS called registered reader interceptor for path provider");
645+
}
646+
647+
/*
648+
* @testName: pathReaderNoInterceptorTest
649+
*
650+
* @assertion_ids: JAXRS:SPEC:84;
651+
*
652+
* @test_Strategy: JAX-RS implementations are REQUIRED to call registered
653+
* interceptors when mapping representations to Java types and vice versa.
654+
*/
655+
@Test
656+
@Tag("xml_binding")
657+
public void pathReaderNoInterceptorTest() throws Fault {
658+
setProperty(Property.REQUEST, buildRequest(Request.POST, "postpath"));
659+
setRequestContentEntity(content);
660+
setProperty(Property.SEARCH_STRING, content);
661+
invoke();
662+
}
663+
664+
/*
665+
* @testName: pathWriterContainerInterceptorTest
666+
*
667+
* @assertion_ids: JAXRS:SPEC:84;
668+
*
669+
* @test_Strategy: JAX-RS implementations are REQUIRED to call registered
670+
* interceptors when mapping representations to Java types and vice versa.
671+
*/
672+
@Test
673+
@Tag("xml_binding")
674+
public void pathWriterContainerInterceptorTest() throws Fault {
675+
addInterceptors(EntityWriterInterceptor.class);
676+
setProperty(Property.REQUEST, buildRequest(Request.GET, "getpath"));
677+
setProperty(Property.SEARCH_STRING,
678+
EntityWriterInterceptor.class.getName());
679+
setProperty(Property.SEARCH_STRING, Resource.DIRECTION);
680+
invoke();
681+
logMsg("JAXRS called registered writer interceptor for path provider");
682+
}
683+
684+
/*
685+
* @testName: pathWriterNoInterceptorTest
686+
*
687+
* @assertion_ids: JAXRS:SPEC:84;
688+
*
689+
* @test_Strategy: JAX-RS implementations are REQUIRED to call registered
690+
* interceptors when mapping representations to Java types and vice versa.
691+
*/
692+
@Test
693+
@Tag("xml_binding")
694+
public void pathWriterNoInterceptorTest() throws Fault {
695+
setProperty(Property.REQUEST, buildRequest(Request.GET, "getpath"));
696+
setProperty(Property.SEARCH_STRING, Resource.getName());
697+
invoke();
698+
}
699+
700+
/*
701+
* @testName: pathWriterClientInterceptorTest
702+
*
703+
* @assertion_ids: JAXRS:SPEC:84;
704+
*
705+
* @test_Strategy: JAX-RS implementations are REQUIRED to call registered
706+
* interceptors when mapping representations to Java types and vice versa.
707+
*/
708+
@Test
709+
@Tag("xml_binding")
710+
public void pathWriterClientInterceptorTest() throws Fault {
711+
try {
712+
java.nio.file.Path path = Files.createTempFile("temp", "tmp");
713+
Files.writeString(path, content);
714+
setRequestContentEntity(path);
715+
} catch (IOException e) {
716+
throw new Fault(e);
717+
}
718+
addProvider(EntityWriterInterceptor.class);
719+
addInterceptors(EntityWriterInterceptor.class);
720+
setProperty(Property.REQUEST, buildRequest(Request.POST, "poststring"));
721+
setProperty(Property.SEARCH_STRING,
722+
EntityWriterInterceptor.class.getName());
723+
setProperty(Property.UNEXPECTED_RESPONSE_MATCH, Resource.DIRECTION);
724+
invoke();
725+
logMsg("JAXRS called registered writer interceptor for path provider");
726+
}
727+
623728
// ------------------------- DataSource -----------------------------------
624729

625730
/*

jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/spec/filter/interceptor/Resource.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2021 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013 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
@@ -23,6 +23,7 @@
2323
import java.io.InputStream;
2424
import java.io.InputStreamReader;
2525
import java.io.Reader;
26+
import java.nio.file.Files;
2627
import java.util.List;
2728

2829
import javax.xml.namespace.QName;
@@ -133,6 +134,21 @@ public Response postFile(File file) throws IOException {
133134
return buildResponse(text);
134135
}
135136

137+
@GET
138+
@Path("getpath")
139+
public Response getPath() throws IOException {
140+
java.nio.file.Path path = Files.createTempFile("filter", "tmp");
141+
Files.writeString(path, getName());
142+
return buildResponse(path);
143+
}
144+
145+
@POST
146+
@Path("postpath")
147+
public Response postPath(java.nio.file.Path path) throws IOException {
148+
String text = Files.readString(path);
149+
return buildResponse(text);
150+
}
151+
136152
@GET
137153
@Path("getdatasource")
138154
public Response getDataSource() {

jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/spec/provider/overridestandard/JAXRSClientIT.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012 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
@@ -82,7 +82,7 @@ void setPropertyAndInvokeEncoded(String resourceMethod) throws Fault {
8282
}
8383

8484
String[] methodsAll = { "bytearray", "string", "inputstream", "reader",
85-
"file", "datasource", "source", "jaxb", "streamingoutput" };
85+
"file", "path", "datasource", "source", "jaxb", "streamingoutput" };
8686

8787

8888
@Deployment(testable = false)
@@ -94,7 +94,7 @@ public static WebArchive createDeployment() throws IOException{
9494
AbstractProvider.class, TckBooleanProvider.class,
9595
TckByteArrayProvider.class, TckCharacterProvider.class,
9696
TckDataSourceProvider.class, TckDataSourceProvider.class,
97-
TckFileProvider.class, TckInputStreamProvider.class,
97+
TckFileProvider.class, TckPathProvider.class, TckInputStreamProvider.class,
9898
TckJaxbProvider.class, TckMapProvider.class,
9999
TckNumberProvider.class, TckReaderProvider.class,
100100
TckSourceProvider.class, TckStreamingOutputProvider.class,
@@ -195,6 +195,22 @@ public void readWriteFileProviderTest() throws Fault {
195195
setPropertyAndInvoke("file", MediaType.APPLICATION_XML_TYPE);
196196
}
197197

198+
/*
199+
* @testName: readWritePathProviderTest
200+
*
201+
* @assertion_ids: JAXRS:SPEC:35
202+
*
203+
* @test_Strategy: An implementation MUST support application-provided entity
204+
* providers and MUST use those in preference to its own pre-packaged
205+
* providers when either could handle the same request.
206+
*
207+
*/
208+
@Test
209+
@Tag("xml_binding")
210+
public void readWritePathProviderTest() throws Fault {
211+
setPropertyAndInvoke("path", MediaType.APPLICATION_XML_TYPE);
212+
}
213+
198214
/*
199215
* @testName: readWriteDataSourceProviderTest
200216
*

jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/spec/provider/overridestandard/Resource.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012 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
@@ -63,6 +63,12 @@ public File file(File file) {
6363
return file;
6464
}
6565

66+
@Path("path")
67+
@POST
68+
public java.nio.file.Path path(java.nio.file.Path path) {
69+
return path;
70+
}
71+
6672
@Path("datasource")
6773
@POST
6874
public DataSource datasource(DataSource datasource) {

jaxrs-tck/src/main/java/ee/jakarta/tck/ws/rs/spec/provider/overridestandard/TSAppConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public java.util.Set<java.lang.Class<?>> getClasses() {
2929
resources.add(TckByteArrayProvider.class);
3030
resources.add(TckDataSourceProvider.class);
3131
resources.add(TckFileProvider.class);
32+
resources.add(TckPathProvider.class);
3233
resources.add(TckInputStreamProvider.class);
3334
resources.add(TckJaxbProvider.class);
3435
resources.add(TckMapProvider.class);

0 commit comments

Comments
 (0)