diff options
Diffstat (limited to 'framework/src/onos/core/api/src/main/java/org/onosproject/rest')
6 files changed, 0 insertions, 405 deletions
diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/rest/AbstractApiDocRegistrator.java b/framework/src/onos/core/api/src/main/java/org/onosproject/rest/AbstractApiDocRegistrator.java deleted file mode 100644 index 7349c69e..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/rest/AbstractApiDocRegistrator.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.rest; - -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; - -/** - * Self-registering REST API provider. - */ -@Component(immediate = true, componentAbstract = true) -public abstract class AbstractApiDocRegistrator { - - protected final ApiDocProvider provider; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected ApiDocService service; - - /** - * Creates registrator for the specified REST API doc provider. - * - * @param provider REST API provider - */ - protected AbstractApiDocRegistrator(ApiDocProvider provider) { - this.provider = provider; - } - - @Activate - protected void activate() { - service.register(provider); - } - - @Deactivate - protected void deactivate() { - service.unregister(provider); - } -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/rest/AbstractInjectionResource.java b/framework/src/onos/core/api/src/main/java/org/onosproject/rest/AbstractInjectionResource.java deleted file mode 100644 index de182f03..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/rest/AbstractInjectionResource.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.rest; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.util.Enumeration; -import java.util.Iterator; -import java.util.List; - -import static com.google.common.base.Preconditions.checkArgument; - -/** - * Resource for serving semi-static resources. - */ -public class AbstractInjectionResource extends AbstractWebResource { - - /** - * Returns the index into the supplied string where the end of the - * specified pattern is located. - * - * @param string string to split - * @param start index where to start looking for pattern - * @param stopPattern optional pattern where to stop - * @return index where the split should occur - */ - protected int split(String string, int start, String stopPattern) { - int i = stopPattern != null ? string.indexOf(stopPattern, start) : string.length(); - checkArgument(i >= 0, "Unable to locate pattern %s", stopPattern); - return i + (stopPattern != null ? stopPattern.length() : 0); - } - - /** - * Produces an input stream from the bytes of the specified sub-string. - * - * @param string source string - * @param start index where to start stream - * @param end index where to end stream - * @return input stream - */ - protected InputStream stream(String string, int start, int end) { - return new ByteArrayInputStream(string.substring(start, end).getBytes()); - } - - /** - * Auxiliary enumeration to sequence input streams. - */ - protected class StreamEnumeration implements Enumeration<InputStream> { - private final Iterator<InputStream> iterator; - - public StreamEnumeration(List<InputStream> streams) { - this.iterator = streams.iterator(); - } - - @Override - public boolean hasMoreElements() { - return iterator.hasNext(); - } - - @Override - public InputStream nextElement() { - return iterator.next(); - } - } -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/rest/AbstractWebResource.java b/framework/src/onos/core/api/src/main/java/org/onosproject/rest/AbstractWebResource.java deleted file mode 100644 index d3249ba5..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/rest/AbstractWebResource.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.rest; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.onlab.rest.BaseResource; -import org.onosproject.codec.CodecContext; -import org.onosproject.codec.CodecService; -import org.onosproject.codec.JsonCodec; - -/** - * Abstract REST resource. - */ -public class AbstractWebResource extends BaseResource implements CodecContext { - - private final ObjectMapper mapper = new ObjectMapper(); - - @Override - public ObjectMapper mapper() { - return mapper; - } - - /** - * Returns the JSON codec for the specified entity class. - * - * @param entityClass entity class - * @param <T> entity type - * @return JSON codec - */ - public <T> JsonCodec<T> codec(Class<T> entityClass) { - return get(CodecService.class).getCodec(entityClass); - } - - /** - * Returns JSON object wrapping the array encoding of the specified - * collection of items. - * - * @param codecClass codec item class - * @param field field holding the array - * @param items collection of items to be encoded into array - * @param <T> item type - * @return JSON object - */ - protected <T> ObjectNode encodeArray(Class<T> codecClass, String field, - Iterable<T> items) { - ObjectNode result = mapper().createObjectNode(); - result.set(field, codec(codecClass).encode(items, this)); - return result; - } - - @Override - public <T> T getService(Class<T> serviceClass) { - return get(serviceClass); - } - - /** - * Creates and returns a new child object within the specified parent and - * bound to the given key. - * - * @param parent parent object - * @param key key for the new child object - * @return child object - */ - public ObjectNode newObject(ObjectNode parent, String key) { - ObjectNode node = mapper.createObjectNode(); - parent.set(key, node); - return node; - } - - /** - * Creates and returns a new child array within the specified parent and - * bound to the given key. - * - * @param parent parent object - * @param key key for the new child array - * @return child array - */ - public ArrayNode newArray(ObjectNode parent, String key) { - ArrayNode node = mapper.createArrayNode(); - parent.set(key, node); - return node; - } -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/rest/ApiDocProvider.java b/framework/src/onos/core/api/src/main/java/org/onosproject/rest/ApiDocProvider.java deleted file mode 100644 index 50cac4cd..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/rest/ApiDocProvider.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.rest; - -import com.google.common.annotations.Beta; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.InputStream; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * Entity capable of providing REST API documentation resources. - */ -@Beta -public class ApiDocProvider { - - private final Logger log = LoggerFactory.getLogger(getClass()); - - private static final String DOCS = "/apidoc/swagger.json"; - private static final String MODEL = "/apidoc/model.json"; - - private final String key; - private final String name; - private final ClassLoader classLoader; - - /** - * Creates a new REST API documentation provider. - * - * @param key REST API key - * @param name REST API name - * @param classLoader class loader - */ - public ApiDocProvider(String key, String name, ClassLoader classLoader) { - this.key = checkNotNull(key, "Key cannot be null"); - this.name = checkNotNull(name, "Name cannot be null"); - this.classLoader = checkNotNull(classLoader, "Class loader cannot be null"); - } - - /** - * Returns the REST API key. - * - * @return REST API key - */ - public String key() { - return key; - } - - /** - * Returns the REST API name. - * - * @return REST API name - */ - public String name() { - return name; - } - - /** - * Returns input stream containing Swagger UI compatible JSON. - * - * @return input stream with Swagger JSON data - */ - public InputStream docs() { - return get(DOCS); - } - - /** - * Returns input stream containing JSON model schema. - * - * @return input stream with JSON model schema - */ - public InputStream model() { - return get(MODEL); - } - - private InputStream get(String resource) { - InputStream stream = classLoader.getResourceAsStream(resource); - if (stream == null) { - log.warn("Unable to find JSON resource {}", resource); - } - return stream; - } - -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/rest/ApiDocService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/rest/ApiDocService.java deleted file mode 100644 index f7268532..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/rest/ApiDocService.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.rest; - -import com.google.common.annotations.Beta; - -import java.util.Set; - -/** - * Service for registering REST API documentation resources. - */ -@Beta -public interface ApiDocService { - - /** - * Registers the specified REST API documentation provider. - * - * @param provider REST API documentation provider - */ - void register(ApiDocProvider provider); - - /** - * Unregisters the specified REST API documentation provider. - * - * @param provider REST API documentation provider - */ - void unregister(ApiDocProvider provider); - - /** - * Returns the set of all registered REST API documentation providers. - * - * @return set of registered documentation providers - */ - Set<ApiDocProvider> getDocProviders(); - - /** - * Returns the specified REST API documentation provider with the specified - * key. - * - * @param key REST API key - * @return documentation provider - */ - ApiDocProvider getDocProvider(String key); - -} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/rest/package-info.java b/framework/src/onos/core/api/src/main/java/org/onosproject/rest/package-info.java deleted file mode 100644 index 15e5d20d..00000000 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/rest/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Base abstractions and utilities for developing REST APIs. - */ -package org.onosproject.rest;
\ No newline at end of file |