Skip to content

Commit

Permalink
Merge pull request #841 from jotak/angular-ui
Browse files Browse the repository at this point in the history
Since everyone seems ok, I merge it. Anyway it's a specific branch.
  • Loading branch information
jotak committed Jul 19, 2017
2 parents ed5c239 + 5b85064 commit ef99526
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 154 deletions.
34 changes: 32 additions & 2 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 Expand Up @@ -151,6 +156,29 @@
<build>
<finalName>hawkular-metric-rest</finalName>
<plugins>
<plugin>
<artifactId>maven-scm-plugin</artifactId>
<version>1.9.5</version>
<executions>
<execution>
<id>Pull hawkular-ui webapp</id>
<goals>
<goal>checkout</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<connectionUrl>scm:git:git://github.com/jotak/hawkular-ui</connectionUrl>
<scmVersion>release</scmVersion>
<scmVersionType>branch</scmVersionType>
<checkoutDirectory>${project.build.directory}/hawkular-ui</checkoutDirectory>
<includes>
metrics/ngapp/dist/**
</includes>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
Expand All @@ -164,20 +192,22 @@
<!-- Exclude Swagger output customization classes from the WAR file -->
<packagingExcludes>WEB-INF/classes/org/hawkular/metrics/api/jaxrs/swagger/**/*</packagingExcludes>
<webResources>
<resource>
<filtering>false</filtering>
<directory>${project.build.directory}/hawkular-ui/metrics/ngapp/dist</directory>
</resource>
<resource>
<filtering>false</filtering>
<directory>${basedir}/src/main/webapp</directory>
<excludes>
<exclude>WEB-INF/web.xml</exclude>
<exclude>static/index.html</exclude>
</excludes>
</resource>
<resource>
<filtering>true</filtering>
<directory>${basedir}/src/main/webapp</directory>
<includes>
<include>WEB-INF/web.xml</include>
<include>static/index.html</include>
</includes>
</resource>
</webResources>
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);
}
}
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>
Binary file not shown.
Binary file not shown.
41 changes: 0 additions & 41 deletions api/metrics-api-jaxrs/src/main/webapp/static/index.html

This file was deleted.

46 changes: 0 additions & 46 deletions api/metrics-api-jaxrs/src/main/webapp/static/status.js

This file was deleted.

49 changes: 0 additions & 49 deletions api/metrics-api-jaxrs/src/main/webapp/static/welcome.css

This file was deleted.

8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>org.hawkular</groupId>
<artifactId>hawkular-parent</artifactId>
<version>55</version>
<version>56-SNAPSHOT</version>
</parent>

<groupId>org.hawkular.metrics</groupId>
Expand Down Expand Up @@ -325,6 +325,12 @@
<exclude>src/main/docker/standalone.xml</exclude>
<!-- Exclude ANTLR token files -->
<exclude>**/.*.tokens</exclude>
<!-- Exclude node.js dependencies -->
<exclude>**/node_modules/**</exclude>
<!-- Exclude front-end fonts -->
<exclude>**/*.woff2</exclude>
<!-- Exclude front-end JS maps -->
<exclude>**/*.map</exclude>
</excludes>
</configuration>
</plugin>
Expand Down

0 comments on commit ef99526

Please sign in to comment.