import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
-import org.opendaylight.restconf.Draft18;
+import org.opendaylight.restconf.Rfc8040;
import org.opendaylight.restconf.utils.RestconfConstants;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
import org.slf4j.LoggerFactory;
@Provider
-@Consumes({ Draft18.MediaTypes.DATA + RestconfConstants.JSON, MediaType.APPLICATION_JSON })
-public class JsonNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsProvider implements MessageBodyReader<NormalizedNodeContext> {
+@Consumes({ Rfc8040.MediaTypes.DATA + RestconfConstants.JSON, MediaType.APPLICATION_JSON })
+public class JsonNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsProvider
+ implements MessageBodyReader<NormalizedNodeContext> {
- private final static Logger LOG = LoggerFactory.getLogger(JsonNormalizedNodeBodyReader.class);
+ private static final Logger LOG = LoggerFactory.getLogger(JsonNormalizedNodeBodyReader.class);
@Override
public boolean isReadable(final Class<?> type, final Type genericType, final Annotation[] annotations,
return true;
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
@Override
public NormalizedNodeContext readFrom(final Class<NormalizedNodeContext> type, final Type genericType,
final Annotation[] annotations, final MediaType mediaType,
}
}
- private static void propagateExceptionAs(final Exception e) throws RestconfDocumentedException {
- if(e instanceof RestconfDocumentedException) {
- throw (RestconfDocumentedException)e;
- }
-
- if(e instanceof ResultAlreadySetException) {
- LOG.debug("Error parsing json input:", e);
-
- throw new RestconfDocumentedException("Error parsing json input: Failed to create new parse result data. " +
- "Are you creating multiple resources/subresources in POST request?");
- }
-
- LOG.debug("Error parsing json input", e);
-
- throw new RestconfDocumentedException("Error parsing input: " + e.getMessage(), ErrorType.PROTOCOL,
- ErrorTag.MALFORMED_MESSAGE, e);
- }
-
- private static NormalizedNodeContext readFrom(final InstanceIdentifierContext<?> path, final InputStream entityStream,
- final boolean isPost) throws IOException {
+ private static NormalizedNodeContext readFrom(
+ final InstanceIdentifierContext<?> path, final InputStream entityStream, final boolean isPost)
+ throws IOException {
if (entityStream.available() < 1) {
return new NormalizedNodeContext(path, null);
}
final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder);
final SchemaNode parentSchema;
- if(isPost) {
+ if (isPost) {
parentSchema = path.getSchemaNode();
- } else if(path.getSchemaNode() instanceof SchemaContext) {
+ } else if (path.getSchemaNode() instanceof SchemaContext) {
parentSchema = path.getSchemaContext();
} else {
if (SchemaPath.ROOT.equals(path.getSchemaNode().getPath().getParent())) {
parentSchema = path.getSchemaContext();
} else {
- parentSchema = SchemaContextUtil.findDataSchemaNode(path.getSchemaContext(), path.getSchemaNode().getPath().getParent());
+ parentSchema = SchemaContextUtil
+ .findDataSchemaNode(path.getSchemaContext(), path.getSchemaNode().getPath().getParent());
}
}
final List<YangInstanceIdentifier.PathArgument> iiToDataList = new ArrayList<>();
InstanceIdentifierContext<? extends SchemaNode> newIIContext;
- while ((result instanceof AugmentationNode) || (result instanceof ChoiceNode)) {
- final Object childNode = ((DataContainerNode) result).getValue().iterator().next();
+ while (result instanceof AugmentationNode || result instanceof ChoiceNode) {
+ final Object childNode = ((DataContainerNode<?>) result).getValue().iterator().next();
if (isPost) {
iiToDataList.add(result.getIdentifier());
}
return new NormalizedNodeContext(newIIContext, result);
}
+ private static void propagateExceptionAs(final Exception exception) throws RestconfDocumentedException {
+ if (exception instanceof RestconfDocumentedException) {
+ throw (RestconfDocumentedException)exception;
+ }
+
+ if (exception instanceof ResultAlreadySetException) {
+ LOG.debug("Error parsing json input:", exception);
+
+ throw new RestconfDocumentedException("Error parsing json input: Failed to create new parse result data. "
+ + "Are you creating multiple resources/subresources in POST request?");
+ }
+
+ LOG.debug("Error parsing json input", exception);
+
+ throw new RestconfDocumentedException("Error parsing input: " + exception.getMessage(), ErrorType.PROTOCOL,
+ ErrorTag.MALFORMED_MESSAGE, exception);
+ }
+
public void injectParams(final UriInfo uriInfo, final Request request) {
setUriInfo(uriInfo);
setRequest(request);