From: Robert Varga Date: Sun, 19 May 2024 15:23:26 +0000 (+0200) Subject: Use ServerException in JaxRsRestconfCallback.transform() X-Git-Tag: v7.0.5~2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=5e372964139e86f4f2a558c82bcdcc0ebf40cc4e;p=netconf.git Use ServerException in JaxRsRestconfCallback.transform() We have only a single implementation which throws, convert it to ServerException. JIRA: NETCONF-1188 Change-Id: I8127549346956632c311252c57e1dcb4c9d587e6 Signed-off-by: Robert Varga --- diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/jaxrs/JaxRsRestconf.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/jaxrs/JaxRsRestconf.java index e24dc222f9..79ad7bfddc 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/jaxrs/JaxRsRestconf.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/jaxrs/JaxRsRestconf.java @@ -50,7 +50,6 @@ import org.opendaylight.restconf.api.HttpStatusCode; import org.opendaylight.restconf.api.MediaTypes; import org.opendaylight.restconf.api.QueryParameters; import org.opendaylight.restconf.api.query.PrettyPrintParam; -import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.errors.RestconfFuture; import org.opendaylight.restconf.nb.rfc8040.ErrorTagMapping; import org.opendaylight.restconf.nb.rfc8040.URLConstants; @@ -72,6 +71,7 @@ import org.opendaylight.restconf.server.api.OperationInputBody; import org.opendaylight.restconf.server.api.PatchStatusContext; import org.opendaylight.restconf.server.api.RestconfServer; import org.opendaylight.restconf.server.api.ServerError; +import org.opendaylight.restconf.server.api.ServerException; import org.opendaylight.restconf.server.api.ServerRequest; import org.opendaylight.restconf.server.api.XmlChildBody; import org.opendaylight.restconf.server.api.XmlDataPostBody; @@ -869,12 +869,12 @@ public final class JaxRsRestconf implements ParamConverterProvider { private static void completeModulesGET(final RestconfFuture future, final AsyncResponse ar) { future.addCallback(new JaxRsRestconfCallback<>(ar) { @Override - Response transform(final ModulesGetResult result) { + Response transform(final ModulesGetResult result) throws ServerException { final Reader reader; try { reader = result.source().openStream(); } catch (IOException e) { - throw new RestconfDocumentedException("Cannot open source", e); + throw new ServerException("Cannot open source", e); } return Response.ok(reader).build(); } diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/jaxrs/JaxRsRestconfCallback.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/jaxrs/JaxRsRestconfCallback.java index b60f348113..4aa03289e6 100644 --- a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/jaxrs/JaxRsRestconfCallback.java +++ b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/jaxrs/JaxRsRestconfCallback.java @@ -13,6 +13,7 @@ import javax.ws.rs.container.AsyncResponse; import javax.ws.rs.core.Response; import org.opendaylight.restconf.common.errors.RestconfCallback; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; +import org.opendaylight.restconf.server.api.ServerException; /** * A {@link RestconfCallback} completing an {@link AsyncResponse}. @@ -31,8 +32,8 @@ abstract class JaxRsRestconfCallback extends RestconfCallback { final Response response; try { response = transform(result); - } catch (RestconfDocumentedException e) { - onFailure(e); + } catch (ServerException e) { + onFailure(e.toLegacy()); return; } ar.resume(response); @@ -43,5 +44,5 @@ abstract class JaxRsRestconfCallback extends RestconfCallback { ar.resume(failure); } - abstract Response transform(V result) throws RestconfDocumentedException; + abstract Response transform(V result) throws ServerException; }