forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved the swagger servlet registration to its own component (openhab#156
) This should avoid potential circular dependencies at startup as the dashboard tile does not depend on HttpService anymore. Signed-off-by: Kai Kreuzer <[email protected]>
- Loading branch information
1 parent
83d1217
commit 8797846
Showing
4 changed files
with
67 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
bundles/org.openhab.io.rest.docs/OSGI-INF/swaggerservice.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2015-2017 by the respective copyright holders. | ||
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 | ||
--> | ||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="org.openhab.io.rest.docs.swaggerservice"> | ||
<implementation class="org.openhab.io.rest.docs.internal.SwaggerService"/> | ||
<reference bind="setHttpService" cardinality="1..1" interface="org.osgi.service.http.HttpService" name="HttpService" policy="static" unbind="unsetHttpService"/> | ||
</scr:component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
....openhab.io.rest.docs/src/main/java/org/openhab/io/rest/docs/internal/SwaggerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright (c) 2015-2017 by the respective copyright holders. | ||
* | ||
* 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.openhab.io.rest.docs.internal; | ||
|
||
import org.osgi.service.http.HttpService; | ||
import org.osgi.service.http.NamespaceException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* This service registers the Swagger UI as a web resource on the HTTP service. | ||
* | ||
* @author Kai Kreuzer | ||
* | ||
*/ | ||
public class SwaggerService { | ||
|
||
private static final String ALIAS = "/doc"; | ||
|
||
private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
|
||
private HttpService httpService; | ||
|
||
protected void setHttpService(HttpService httpService) { | ||
this.httpService = httpService; | ||
} | ||
|
||
protected void unsetHttpService(HttpService httpService) { | ||
this.httpService = null; | ||
} | ||
|
||
protected void activate() { | ||
try { | ||
httpService.registerResources(ALIAS, "swagger", httpService.createDefaultHttpContext()); | ||
} catch (NamespaceException e) { | ||
logger.error("Could not start up REST documentation service: {}", e.getMessage()); | ||
} | ||
} | ||
|
||
protected void deactivate() { | ||
httpService.unregister(ALIAS); | ||
} | ||
|
||
} |