public void writeTo(final NormalizedNodeContext context, final Class<?> type, final Type genericType,
final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders,
final OutputStream entityStream) throws IOException, WebApplicationException {
- for (final Entry<String, Object> entry : context.getNewHeaders().entrySet()) {
- httpHeaders.add(entry.getKey(), entry.getValue());
+ if (httpHeaders != null) {
+ for (final Entry<String, Object> entry : context.getNewHeaders().entrySet()) {
+ httpHeaders.add(entry.getKey(), entry.getValue());
+ }
}
final NormalizedNode<?, ?> data = context.getData();
if (data == null) {
import com.google.common.base.Optional;
import javax.annotation.Nonnull;
+import javax.ws.rs.core.MultivaluedMap;
+
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.yangtools.yang.common.OperationFailedException;
+
/**
* Provides restconf CRUD operations via code with input/output data in JSON format.
*
* @throws OperationFailedException if the request fails.
*/
Optional<String> patch(@Nonnull String uriPath, @Nonnull String payload) throws OperationFailedException;
+
+ /**
+ * Subscribe to a stream.
+ * @param identifier the identifier of the stream, e.g., "data-change-event-subscription/neutron:neutron/...
+ * ...neutron:ports/datastore=OPERATIONAL/scope=SUBTREE".
+ * @param params HTTP query parameters or null.
+ * @return On optional containing the JSON response.
+ * @throws OperationFailedException if the requests fails.
+ */
+ Optional<String> subscribeToStream(@Nonnull String identifier, MultivaluedMap<String, String> params)
+ throws OperationFailedException;
}
import java.lang.annotation.Annotation;
import java.nio.charset.StandardCharsets;
import java.util.List;
+import javax.annotation.Nonnull;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.UriInfo;
+
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.netconf.sal.rest.api.RestconfService;
import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.restconf.common.patch.PatchStatusContext;
+import org.opendaylight.restconf.common.util.MultivaluedHashMap;
import org.opendaylight.restconf.common.util.SimpleUriInfo;
import org.opendaylight.yangtools.yang.common.OperationFailedException;
import org.opendaylight.yangtools.yang.common.RpcError;
return Optional.fromNullable(output);
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
+ @Override
+ public Optional<String> subscribeToStream(@Nonnull String identifier,
+ MultivaluedMap<String, String> params) throws OperationFailedException {
+ //Note: We use http://127.0.0.1 because the Uri parser requires something there though it does nothing
+ String uri = new StringBuilder("http://127.0.0.1:8081/restconf/streams/stream/").append(identifier).toString();
+ MultivaluedMap queryParams = (params != null) ? params : new MultivaluedHashMap<String, String>();
+ UriInfo uriInfo = new SimpleUriInfo(uri, queryParams);
+
+ String jsonRes = null;
+ try {
+ NormalizedNodeContext res = restconfService.subscribeToStream(identifier, uriInfo);
+ jsonRes = toJson(res);
+ } catch (final Exception e) {
+ propagateExceptionAs(identifier, e, "RPC");
+ }
+
+ return Optional.fromNullable(jsonRes);
+ }
+
@Override
public void close() {
}