import org.opendaylight.restconf.nb.rfc8040.jersey.providers.YangSchemaExportBodyWriter;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.YinSchemaExportBodyWriter;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.errors.RestconfDocumentedExceptionMapper;
+import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.JsonPatchStatusBodyWriter;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.JsonToPatchBodyReader;
-import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.PatchJsonBodyWriter;
-import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.PatchXmlBodyWriter;
+import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.XmlPatchStatusBodyWriter;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.XmlToPatchBodyReader;
/**
return Set.of(
JsonNormalizedNodeBodyWriter.class, XmlNormalizedNodeBodyWriter.class,
YinSchemaExportBodyWriter.class, YangSchemaExportBodyWriter.class,
- PatchJsonBodyWriter.class, PatchXmlBodyWriter.class);
+ JsonPatchStatusBodyWriter.class, XmlPatchStatusBodyWriter.class);
}
@Override
--- /dev/null
+/*
+ * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.ext.MessageBodyWriter;
+import org.opendaylight.restconf.common.patch.PatchStatusContext;
+
+abstract class AbstractPatchStatusBodyWriter implements MessageBodyWriter<PatchStatusContext> {
+ @Override
+ public final boolean isWriteable(final Class<?> type, final Type genericType, final Annotation[] annotations,
+ final MediaType mediaType) {
+ return type.equals(PatchStatusContext.class);
+ }
+}
import java.nio.charset.StandardCharsets;
import java.util.List;
import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
import org.opendaylight.restconf.common.errors.RestconfError;
import org.opendaylight.restconf.common.patch.PatchStatusContext;
@Provider
@Produces(MediaTypes.APPLICATION_YANG_DATA_JSON)
-public class PatchJsonBodyWriter implements MessageBodyWriter<PatchStatusContext> {
-
- @Override
- public boolean isWriteable(final Class<?> type, final Type genericType,
- final Annotation[] annotations, final MediaType mediaType) {
- return type.equals(PatchStatusContext.class);
- }
-
+public class JsonPatchStatusBodyWriter extends AbstractPatchStatusBodyWriter {
@Override
public void writeTo(final PatchStatusContext patchStatusContext, final Class<?> type, final Type genericType,
final Annotation[] annotations, final MediaType mediaType,
final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream)
- throws IOException, WebApplicationException {
+ throws IOException {
final JsonWriter jsonWriter = createJsonWriter(entityStream);
jsonWriter.beginObject().name("ietf-yang-patch:yang-patch-status");
*/
package org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch;
+import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.util.List;
import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
-import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
@Provider
@Produces(MediaTypes.APPLICATION_YANG_DATA_XML)
-public class PatchXmlBodyWriter implements MessageBodyWriter<PatchStatusContext> {
-
+public class XmlPatchStatusBodyWriter extends AbstractPatchStatusBodyWriter {
private static final XMLOutputFactory XML_FACTORY;
static {
XML_FACTORY.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true);
}
- @Override
- public boolean isWriteable(final Class<?> type, final Type genericType,
- final Annotation[] annotations, final MediaType mediaType) {
- return type.equals(PatchStatusContext.class);
- }
-
@Override
public void writeTo(final PatchStatusContext patchStatusContext, final Class<?> type, final Type genericType,
final Annotation[] annotations, final MediaType mediaType,
final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream)
- throws WebApplicationException {
-
+ throws IOException {
try {
final XMLStreamWriter xmlWriter =
XML_FACTORY.createXMLStreamWriter(entityStream, StandardCharsets.UTF_8.name());
writeDocument(xmlWriter, patchStatusContext);
- } catch (final XMLStreamException | FactoryConfigurationError e) {
- throw new IllegalStateException(e);
+ } catch (final XMLStreamException e) {
+ throw new IOException("Failed to write body", e);
}
}