Skip to content

Commit

Permalink
Serve angular UI from current jaxrs API
Browse files Browse the repository at this point in the history
  • Loading branch information
jotak committed Jul 17, 2017
1 parent 39fdc23 commit b65f17a
Show file tree
Hide file tree
Showing 83 changed files with 194,421 additions and 19 deletions.
5 changes: 5 additions & 0 deletions api/metrics-api-jaxrs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-servlet</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jboss.logging</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 Red Hat, Inc. and/or its affiliates
* Copyright 2014-2017 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.hawkular.metrics.api.jaxrs.filter;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
Expand Down Expand Up @@ -56,7 +55,10 @@ public void filter(ContainerRequestContext requestContext) throws IOException {
UriInfo uriInfo = requestContext.getUriInfo();
String path = uriInfo.getPath();

if (path.startsWith("/tenants") || path.startsWith(StatusHandler.PATH) || path.equals(BaseHandler.PATH)) {
if (path.startsWith("/tenants")
|| path.startsWith(StatusHandler.PATH)
|| path.startsWith("/ui")
|| path.equals(BaseHandler.PATH)) {
// Some handlers do not check the tenant header
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
Expand Down Expand Up @@ -66,8 +65,7 @@ public Response baseJSON() {
@GET
@Produces({APPLICATION_XHTML_XML, TEXT_HTML})
public void baseHTML(@Context ServletContext context) throws Exception {
HttpServletRequest request = ResteasyProviderFactory.getContextData(HttpServletRequest.class);
HttpServletResponse response = ResteasyProviderFactory.getContextData(HttpServletResponse.class);
request.getRequestDispatcher("/static/index.html").forward(request, response);
response.sendRedirect("/hawkular/metrics/ui/index.html");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2014-2017 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* 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.hawkular.metrics.api.jaxrs.handler;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import io.undertow.servlet.handlers.DefaultServlet;

/**
* Servlet used for delivering static data as undertow's DefaultServlet and preserves url for client-side router
* such as Angular's in single-page app context
* @author Joel Takvorian
*/
public class ClientRouterDispatchingServlet extends DefaultServlet {

@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
String path = req.getPathInfo();
// FIXME: find a safer & more generic way.
// Beware, urls could be like "hawkular/metrics/ui/something/file/abc.json" which is not necessarily static content
// Maybe put all in "assets", but need to find how to do it with dynamically loaded fonts
if (path.endsWith(".js")
|| path.endsWith(".css")
|| path.endsWith(".woff2")
|| path.endsWith(".ttf")
|| path.endsWith(".html")
|| path.endsWith(".png")
|| path.endsWith(".jpg")) {
super.doGet(req, resp);
return;
}
req.getRequestDispatcher("/ui/index.html").forward(req, resp);
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
19,028 changes: 19,028 additions & 0 deletions ...etrics-api-jaxrs/src/main/webapp/OpenSans-Bold-webfont.99c9f24dd717e50a36d0.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19,036 changes: 19,036 additions & 0 deletions ...-api-jaxrs/src/main/webapp/OpenSans-BoldItalic-webfont.04b273bca14cbdba6b0b.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
19,030 changes: 19,030 additions & 0 deletions ...s-api-jaxrs/src/main/webapp/OpenSans-ExtraBold-webfont.c13d9e6d9d5e10ed7891.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
19,036 changes: 19,036 additions & 0 deletions ...jaxrs/src/main/webapp/OpenSans-ExtraBoldItalic-webfont.6be75e80b3b60ec7e673.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
19,043 changes: 19,043 additions & 0 deletions ...rics-api-jaxrs/src/main/webapp/OpenSans-Italic-webfont.3e2b2e91221492e315c4.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
19,026 changes: 19,026 additions & 0 deletions ...trics-api-jaxrs/src/main/webapp/OpenSans-Light-webfont.41ef8e5d0ac536545113.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
19,039 changes: 19,039 additions & 0 deletions ...api-jaxrs/src/main/webapp/OpenSans-LightItalic-webfont.b348357e35677da79b5c.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
19,030 changes: 19,030 additions & 0 deletions ...ics-api-jaxrs/src/main/webapp/OpenSans-Regular-webfont.d9bee607e42329e3ae45.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
19,030 changes: 19,030 additions & 0 deletions ...cs-api-jaxrs/src/main/webapp/OpenSans-Semibold-webfont.400ab808e8b3ba053d41.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
19,043 changes: 19,043 additions & 0 deletions ...-jaxrs/src/main/webapp/OpenSans-SemiboldItalic-webfont.7350876ed9eaf44d9555.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 11 additions & 9 deletions api/metrics-api-jaxrs/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2014-2016 Red Hat, Inc. and/or its affiliates
Copyright 2014-2017 Red Hat, Inc. and/or its affiliates
and other contributors as indicated by the @author tags.
Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -35,16 +35,18 @@
</resource-env-ref>

<servlet>
<servlet-name>staticContent</servlet-name>
<servlet-class>io.undertow.servlet.handlers.DefaultServlet</servlet-class>
<init-param>
<param-name>resolve-against-context-root</param-name>
<param-value>true</param-value>
</init-param>
<servlet-name>angularRoutes</servlet-name>
<servlet-class>org.hawkular.metrics.api.jaxrs.handler.ClientRouterDispatchingServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>staticContent</servlet-name>
<url-pattern>/static/*</url-pattern>
<servlet-name>angularRoutes</servlet-name>
<url-pattern>/ui</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>angularRoutes</servlet-name>
<url-pattern>/ui/*</url-pattern>
</servlet-mapping>

</web-app>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added api/metrics-api-jaxrs/src/main/webapp/favicon.ico
Binary file not shown.
Binary file not shown.

0 comments on commit b65f17a

Please sign in to comment.