Generate new jax-rs Response for every /.well-known/* request 28/95128/1
authorMichal Banik <michal.banik@pantheon.tech>
Wed, 10 Feb 2021 20:07:36 +0000 (21:07 +0100)
committerMichal Banik <michal.banik@pantheon.tech>
Wed, 10 Feb 2021 21:24:34 +0000 (22:24 +0100)
Generate new javax.ws.rs.core.Response every single time when
 request on `/.well-known/*` is processed, so the new output-stream
 will be used for every response.

javax.ws.rs.core.Response.status(Status.OK) creates new
 OutboundMessageContext with CommittingOutputStream, which is
 closed during the process of sending the response to client.
 Closed output-stream caused
 `java.lang.IllegalStateException: The output stream has already
 been closed.` when `/.well-known/*` endpoint was requesting
 multiple times, which made the endpoint working only once.

JIRA: NETCONF-757
Change-Id: Id8759602261333976337b11aa2c0fbfd1d3b04b9
Signed-off-by: Michal Banik <michal.banik@pantheon.tech>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/RootResourceDiscoveryServiceImpl.java

index 3f982f63b07a9fc829e816c1ef500c5006057cfb..f650729e888591e5b1d7e256e0e3d14a7a3bdde5 100644 (file)
@@ -15,30 +15,28 @@ import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
 
 @Path("/")
 public final class RootResourceDiscoveryServiceImpl implements RootResourceDiscoveryService {
-    private final Response xrdData = Response.status(Status.OK)
-        .entity("<?xml version='1.0' encoding='UTF-8'?>\n"
-            + "<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>\n"
-            + "     <Link rel='restconf' href='/" + RestconfConstants.BASE_URI_PATTERN + "'/>\n"
-            + "</XRD>")
-        .build();
-    private final Response jsonData = Response.status(Status.OK)
-        .entity("{\n"
-            + " \"links\" :\n"
-            + " {\n"
-            + "     \"rel\" : \"restconf\",\n"
-            + "     \"href\" : \"/" + RestconfConstants.BASE_URI_PATTERN + "/\"\n"
-            + " }\n"
-            + "}")
-        .build();
 
     @Override
     public Response readXrdData() {
-        return xrdData;
+        return Response.status(Status.OK)
+                .entity("<?xml version='1.0' encoding='UTF-8'?>\n"
+                        + "<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'>\n"
+                        + "     <Link rel='restconf' href='/" + RestconfConstants.BASE_URI_PATTERN + "'/>\n"
+                        + "</XRD>")
+                .build();
     }
 
     @Override
     public Response readJsonData() {
-        return jsonData;
+        return Response.status(Status.OK)
+                .entity("{\n"
+                        + " \"links\" :\n"
+                        + " {\n"
+                        + "     \"rel\" : \"restconf\",\n"
+                        + "     \"href\" : \"/" + RestconfConstants.BASE_URI_PATTERN + "/\"\n"
+                        + " }\n"
+                        + "}")
+                .build();
     }
 }