Skip to content

Commit

Permalink
initial commit for servlet based impl of REST API
Browse files Browse the repository at this point in the history
This commit just puts the maven project in place with a ping servlet that
prints the date similar to PingHandler. It can be run/tested as follows,

  1) mvn jetty:run
  2) curl http://localhost:8080/ping
  • Loading branch information
John Sanda committed Aug 12, 2015
1 parent a444e9f commit 568263b
Show file tree
Hide file tree
Showing 4 changed files with 288 additions and 0 deletions.
212 changes: 212 additions & 0 deletions api/servlet-impl/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2014-2015 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>hawkular-metrics-parent</artifactId>
<groupId>org.hawkular.metrics</groupId>
<version>0.6.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>hawkular-metrics-api-servlet</artifactId>
<packaging>war</packaging>

<name>Hawkular Metrics REST-Servlets</name>
<description>The REST API of Hawkular-Metrics implemented via servlets</description>

<dependencies>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!--
I am not sure if we should use the above dependency or this one
<dependency>
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.1_spec</artifactId>
<scope>provided</scope>
</dependency>
-->
<dependency>
<groupId>org.hawkular.metrics</groupId>
<artifactId>hawkular-metrics-core-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.hawkular.metrics</groupId>
<artifactId>hawkular-metrics-core-impl</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.5.1</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.5.1</version>
</dependency>

<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>

<!-- documentation -->
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-annotations</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-core_2.10</artifactId>
<scope>provided</scope>
</dependency>

<!-- test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<finalName>hawkular-metric-rest</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<!-- <manifestEntries> <Build-Number>${buildNumber}</Build-Number>
</manifestEntries> -->
</archive>
<webResources>
<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>
</configuration>
</plugin>

<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.2.v20150730</version>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>docgen</id>

<build>
<!-- Document generation from the Swagger annotations on the REST-API. -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>process-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.hawkular</groupId>
<artifactId>hawkular-build-tools</artifactId>
<version>${version.org.hawkular.hawkular-build-tools}</version>
<type>jar</type>
<includes>**/*.mustache</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.kongchen</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<configuration>
<apiSources>
<apiSource>
<locations>org.hawkular.metrics.api.jaxrs</locations>
<apiVersion>1.0</apiVersion>
<basePath>http://localhost:8080/hawkular/metrics/</basePath>
<outputTemplate>${project.build.directory}/dependency/hawkular-documentation/asciidoc.mustache</outputTemplate>
<swaggerDirectory>${project.build.directory}/generated/swagger-ui</swaggerDirectory>
<swaggerInternalFilter>org.hawkular.metrics.api.jaxrs.swagger.filter.JaxRsFilter</swaggerInternalFilter>
<swaggerApiReader>com.wordnik.swagger.jaxrs.reader.DefaultJaxrsApiReader</swaggerApiReader>
<outputPath>${project.build.directory}/generated/rest-metrics.adoc</outputPath>
</apiSource>
</apiSources>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2014-2015 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.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* @author jsanda
*/
@WebServlet(urlPatterns = "/ping")
public class PingServlet extends HttpServlet {

@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {

PrintWriter writer = resp.getWriter();
resp.setStatus(HttpServletResponse.SC_OK);
writer.write(new Date().toString());
writer.close();
}
}
32 changes: 32 additions & 0 deletions api/servlet-impl/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2014-2015 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.
-->
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">

<display-name>Hawkular Metrics Rest interface</display-name>

<context-param>
<param-name>hawkular.metrics.version</param-name>
<param-value>${project.version}</param-value>
</context-param>

</web-app>
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<module>core/metrics-core-api</module>
<module>core/metrics-core-impl</module>
<module>api/metrics-api-jaxrs</module>
<module>api/servlet-impl</module>
<module>rest-tests</module>
<module>clients</module>
<module>containers</module>
Expand Down

0 comments on commit 568263b

Please sign in to comment.