@Override public void post(final String uriPath, final String payload, final UriInfo uriInfo) throws OperationFailedException { Preconditions.checkNotNull(payload, "payload can't be null"); LOG.debug("post: uriPath: {}, payload: {}", uriPath, payload); final InputStream entityStream = new ByteArrayInputStream(payload.getBytes(StandardCharsets.UTF_8)); final NormalizedNodeContext context = JsonNormalizedNodeBodyReader.readFrom(uriPath, entityStream, true); LOG.debug( "Parsed YangInstanceIdentifier: {}", context.getInstanceIdentifierContext().getInstanceIdentifier()); LOG.debug("Parsed NormalizedNode: {}", context.getData()); try { RestconfImpl.getInstance().createConfigurationData(uriPath, context, uriInfo); } catch (final Exception e) { propagateExceptionAs(uriPath, e, "POST"); } }
@Override public Optional<String> invokeRpc(final String uriPath, final Optional<String> input) throws OperationFailedException { Preconditions.checkNotNull(uriPath, "uriPath can't be null"); final String actualInput = input.isPresent() ? input.get() : null; LOG.debug("invokeRpc: uriPath: {}, input: {}", uriPath, actualInput); String output = null; try { NormalizedNodeContext outputContext; if (actualInput != null) { final InputStream entityStream = new ByteArrayInputStream(actualInput.getBytes(StandardCharsets.UTF_8)); final NormalizedNodeContext inputContext = JsonNormalizedNodeBodyReader.readFrom(uriPath, entityStream, true); LOG.debug( "Parsed YangInstanceIdentifier: {}", inputContext.getInstanceIdentifierContext().getInstanceIdentifier()); LOG.debug("Parsed NormalizedNode: {}", inputContext.getData()); outputContext = RestconfImpl.getInstance().invokeRpc(uriPath, inputContext, null); } else { outputContext = RestconfImpl.getInstance().invokeRpc(uriPath, "", null); } if (outputContext.getData() != null) { output = toJson(outputContext); } } catch (final Exception e) { propagateExceptionAs(uriPath, e, "RPC"); } return Optional.fromNullable(output); }