diff --git a/nut-archetype/pom.xml b/nut-archetype/pom.xml
new file mode 100644
index 0000000..68627bb
--- /dev/null
+++ b/nut-archetype/pom.xml
@@ -0,0 +1,47 @@
+
+
+ 4.0.0
+
+ com.nutcore
+ nut-archetype
+ 1.0-SNAPSHOT
+ maven-archetype
+
+ nut-archetype
+ A maven archetype to create a microservice component using OrientDB, Resteasy, Undertow, Metrics and Swagger
+ https://github.com/jesty/orientdb-microservices
+
+
+
+ Apache License, Version 2.0
+ http://www.apache.org/licenses/LICENSE-2.0.txt
+ repo
+
+
+
+
+ https://github.com/jesty/orientdb-microservices
+ scm:git:git://github.com/jesty/orientdb-microservices.git
+ scm:git:git@github.com:jesty/orientdb-microservices.git
+
+
+
+
+
+ org.apache.maven.archetype
+ archetype-packaging
+ 2.4
+
+
+
+
+
+
+ maven-archetype-plugin
+ 2.4
+
+
+
+
+
+
diff --git a/src/main/resources/META-INF/maven/archetype-metadata.xml b/nut-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
similarity index 100%
rename from src/main/resources/META-INF/maven/archetype-metadata.xml
rename to nut-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
diff --git a/src/main/resources/archetype-resources/pom.xml b/nut-archetype/src/main/resources/archetype-resources/pom.xml
similarity index 85%
rename from src/main/resources/archetype-resources/pom.xml
rename to nut-archetype/src/main/resources/archetype-resources/pom.xml
index 6adbb82..60071d0 100644
--- a/src/main/resources/archetype-resources/pom.xml
+++ b/nut-archetype/src/main/resources/archetype-resources/pom.xml
@@ -13,13 +13,33 @@
1.3.5.Final
2.2.12
2.4.0.Final
+ 1.1.7
+ 1.7.21
+ 3.0.1
+ 1.0-SNAPSHOT
+ 1.0
com.nutcore
orientdb-javaee
- 1.0
+ ${orientdb-javaee.version}
+
+
+ com.nutcore
+ nut-corelationid
+ ${nut.version}
+
+
+ com.nutcore
+ nut-metrics
+ ${nut.version}
+
+
+ com.nutcore
+ nut-utils
+ ${nut.version}
org.jboss.resteasy
@@ -140,7 +160,7 @@
- ${groupId}.Main
+ ${package}.Main
diff --git a/src/main/resources/archetype-resources/src/main/java/Main.java b/nut-archetype/src/main/resources/archetype-resources/src/main/java/Main.java
similarity index 63%
rename from src/main/resources/archetype-resources/src/main/java/Main.java
rename to nut-archetype/src/main/resources/archetype-resources/src/main/java/Main.java
index 1f1a919..515f8b0 100644
--- a/src/main/resources/archetype-resources/src/main/java/Main.java
+++ b/nut-archetype/src/main/resources/archetype-resources/src/main/java/Main.java
@@ -3,6 +3,8 @@
#set( $symbol_escape = '\' )
package ${package};
+import com.nutcore.nut.correlationid.CorrelationIdFilter;
+import com.nutcore.nut.metrics.MetricsListener;
import com.nutcore.orientdb.javaee.orientdb.OrientDBFilter;
import com.nutcore.orientdb.javaee.orientdb.OrientDBJacksonProvider;
import com.nutcore.orientdb.javaee.orientdb.OrientDBServletContextListener;
@@ -12,10 +14,14 @@
import io.undertow.servlet.api.FilterInfo;
import org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer;
import org.jboss.resteasy.spi.ResteasyDeployment;
+import org.jboss.weld.environment.servlet.Listener;
import javax.servlet.DispatcherType;
import java.util.Arrays;
+import static com.nutcore.nut.correlationid.CorrelationIdFilter.CORRELATION_ID_FILTER;
+import static com.nutcore.nut.metrics.MetricsListener.METRICS_LISTENER;
+
public class Main
{
private static final String ORIENTDB_FILTER = "orientdb";
@@ -43,18 +49,28 @@ private static void startWebServer(String[] args)
deployment.setInjectorFactoryClass("org.jboss.resteasy.cdi.CdiInjectorFactory");
deployment.setApplicationClass(MyApplication.class.getName());
- Undertow.Builder builder = Undertow.builder().addHttpListener(port, host);
+ Undertow.Builder builder = Undertow
+ .builder()
+ .addHttpListener(port, host);
UndertowJaxrsServer server = new UndertowJaxrsServer().start(builder);
DeploymentInfo deploymentInfo = server
.undertowDeployment(deployment)
.setClassLoader(Main.class.getClassLoader())
.addListener(Servlets.listener(OrientDBServletContextListener.class))
- .addListeners(Servlets.listener(org.jboss.weld.environment.servlet.Listener.class))
- .setContextPath("/api")
- .setDeploymentName("${artifactId}")
+ .addFilter(Servlets.filter(METRICS_LISTENER, MetricsListener.class))
+ .addFilterUrlMapping(METRICS_LISTENER, "/*", DispatcherType.REQUEST)
+ .addListeners(Servlets.listener(Listener.class))
+ .addServlets(
+ Servlets.servlet(com.codahale.metrics.servlets.MetricsServlet.class)
+ .addMapping("/metrics"))
.addFilter(new FilterInfo(ORIENTDB_FILTER, OrientDBFilter.class))
- .addFilterUrlMapping(ORIENTDB_FILTER, "/*", DispatcherType.REQUEST);
+ .addFilterUrlMapping(ORIENTDB_FILTER, "/*", DispatcherType.REQUEST)
+ .addFilter(new FilterInfo(CORRELATION_ID_FILTER, CorrelationIdFilter.class))
+ .addFilterUrlMapping(CORRELATION_ID_FILTER, "/*", DispatcherType.REQUEST)
+ .setContextPath("/api")
+ .setDeploymentName("${artifactId}");
+
server.deploy(deploymentInfo);
}
diff --git a/src/main/resources/archetype-resources/src/main/java/MyApplication.java b/nut-archetype/src/main/resources/archetype-resources/src/main/java/MyApplication.java
similarity index 95%
rename from src/main/resources/archetype-resources/src/main/java/MyApplication.java
rename to nut-archetype/src/main/resources/archetype-resources/src/main/java/MyApplication.java
index 134d39a..e8c5548 100644
--- a/src/main/resources/archetype-resources/src/main/java/MyApplication.java
+++ b/nut-archetype/src/main/resources/archetype-resources/src/main/java/MyApplication.java
@@ -9,6 +9,7 @@
import javax.ws.rs.core.Application;
import java.util.HashSet;
import java.util.Set;
+import com.nutcore.nut.httputils.CORSFilter;
public class MyApplication extends Application
{
diff --git a/src/main/resources/archetype-resources/src/main/java/domain/User.java b/nut-archetype/src/main/resources/archetype-resources/src/main/java/domain/User.java
similarity index 100%
rename from src/main/resources/archetype-resources/src/main/java/domain/User.java
rename to nut-archetype/src/main/resources/archetype-resources/src/main/java/domain/User.java
diff --git a/src/main/resources/archetype-resources/src/main/java/resource/HelloResource.java b/nut-archetype/src/main/resources/archetype-resources/src/main/java/resource/HelloResource.java
similarity index 100%
rename from src/main/resources/archetype-resources/src/main/java/resource/HelloResource.java
rename to nut-archetype/src/main/resources/archetype-resources/src/main/java/resource/HelloResource.java
diff --git a/src/main/resources/archetype-resources/src/main/resources/META-INF/beans.xml b/nut-archetype/src/main/resources/archetype-resources/src/main/resources/META-INF/beans.xml
similarity index 100%
rename from src/main/resources/archetype-resources/src/main/resources/META-INF/beans.xml
rename to nut-archetype/src/main/resources/archetype-resources/src/main/resources/META-INF/beans.xml
diff --git a/src/main/resources/archetype-resources/src/main/resources/db.config.xml b/nut-archetype/src/main/resources/archetype-resources/src/main/resources/db.config.xml
similarity index 100%
rename from src/main/resources/archetype-resources/src/main/resources/db.config.xml
rename to nut-archetype/src/main/resources/archetype-resources/src/main/resources/db.config.xml
diff --git a/src/main/resources/archetype-resources/src/main/resources/orientdb.properties b/nut-archetype/src/main/resources/archetype-resources/src/main/resources/orientdb.properties
similarity index 100%
rename from src/main/resources/archetype-resources/src/main/resources/orientdb.properties
rename to nut-archetype/src/main/resources/archetype-resources/src/main/resources/orientdb.properties
diff --git a/src/test/resources/projects/basic/archetype.properties b/nut-archetype/src/test/resources/projects/basic/archetype.properties
similarity index 100%
rename from src/test/resources/projects/basic/archetype.properties
rename to nut-archetype/src/test/resources/projects/basic/archetype.properties
diff --git a/src/test/resources/projects/basic/goal.txt b/nut-archetype/src/test/resources/projects/basic/goal.txt
similarity index 100%
rename from src/test/resources/projects/basic/goal.txt
rename to nut-archetype/src/test/resources/projects/basic/goal.txt
diff --git a/nut-corelationid/pom.xml b/nut-corelationid/pom.xml
new file mode 100644
index 0000000..2c89973
--- /dev/null
+++ b/nut-corelationid/pom.xml
@@ -0,0 +1,31 @@
+
+
+
+ nut
+ com.nutcore
+ 1.0-SNAPSHOT
+
+ 4.0.0
+
+ nut-corelationid
+
+
+
+ javax
+ javaee-api
+
+
+ org.slf4j
+ slf4j-api
+
+
+
+ ch.qos.logback
+ logback-classic
+
+
+
+
+
\ No newline at end of file
diff --git a/nut-corelationid/src/main/java/com/nutcore/nut/correlationid/CorrelationId.java b/nut-corelationid/src/main/java/com/nutcore/nut/correlationid/CorrelationId.java
new file mode 100644
index 0000000..9d80d9c
--- /dev/null
+++ b/nut-corelationid/src/main/java/com/nutcore/nut/correlationid/CorrelationId.java
@@ -0,0 +1,33 @@
+package com.nutcore.nut.correlationid;
+
+/**
+ * Created by davidecerbo on 07/11/2016.
+ */
+public class CorrelationId
+{
+ private final String id;
+ private final String source;
+ private final Long creationTime;
+
+ public CorrelationId(String id, String source, Long creationTime)
+ {
+ this.id = id;
+ this.source = source;
+ this.creationTime = creationTime;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public String getSource()
+ {
+ return source;
+ }
+
+ public Long getCreationTime()
+ {
+ return creationTime;
+ }
+}
diff --git a/nut-corelationid/src/main/java/com/nutcore/nut/correlationid/CorrelationIdFilter.java b/nut-corelationid/src/main/java/com/nutcore/nut/correlationid/CorrelationIdFilter.java
new file mode 100644
index 0000000..fe37247
--- /dev/null
+++ b/nut-corelationid/src/main/java/com/nutcore/nut/correlationid/CorrelationIdFilter.java
@@ -0,0 +1,131 @@
+package com.nutcore.nut.correlationid;
+
+import org.slf4j.MDC;
+
+import javax.servlet.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * Created by davidecerbo on 07/11/2016.
+ */
+public class CorrelationIdFilter implements Filter
+{
+
+ public static final String CORRELATION_ID_FILTER = "correlationIDFilter";
+
+ public static final int CORRELLATION_ID_MAX_LENGTH = 36;
+
+ public static final String CORRELATION_ID_HEADER = "X-Correlation-Id";
+ public static final String CORRELATION_ID_SOURCE_HEADER = "X-Correlation-Id-source";
+
+ public static final String CORRELATION_ID_TIME_HEADER = "X-Correlation-Id-time";
+
+ private static final String CORELLATION_ID_LOG_KEY = "correlationId";
+ private static final String CORELLATION_ID_SOURCE_LOG_KEY = "correlationIdSource";
+ private static final String CORELLATION_ID_TIME_LOG_KEY = "correlationIdTime";
+
+
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException
+ {
+
+ }
+
+ @Override
+ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException
+ {
+ HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
+ String correlationId = httpServletRequest.getHeader(CORRELATION_ID_HEADER);
+ String source = httpServletRequest.getHeader(CORRELATION_ID_SOURCE_HEADER);
+ Long creationDate = getCreationTime(httpServletRequest);
+ if (correlationId == null || correlationId.isEmpty())
+ {
+ correlationId = generateCorrelationID();
+ source = getFullURL(httpServletRequest);
+ creationDate = System.currentTimeMillis();
+ }
+ CorrelationId correlationIdObj = new CorrelationId(correlationId, source, creationDate);
+ setCorellationId((HttpServletResponse) servletResponse, correlationIdObj);
+
+ filterChain.doFilter(servletRequest, servletResponse);
+ }
+
+ protected String generateCorrelationID()
+ {
+ return UUID.randomUUID().toString();
+ }
+
+ private void setCorellationId(HttpServletResponse servletResponse, CorrelationId correlationIdObj)
+ {
+ correlationIdObj = truncIfTooLong(correlationIdObj);
+ setInHeader(servletResponse, correlationIdObj);
+ setInLog(correlationIdObj);
+ setInThreadLocal(correlationIdObj);
+ }
+
+ private void setInThreadLocal(CorrelationId correlationIdObj)
+ {
+ CorrelationIdUtil.setId(correlationIdObj);
+ }
+
+ private void setInHeader(HttpServletResponse servletResponse, CorrelationId correlationIdObj)
+ {
+ servletResponse.setHeader(CORRELATION_ID_HEADER, correlationIdObj.getId());
+ servletResponse.setHeader(CORRELATION_ID_SOURCE_HEADER, correlationIdObj.getSource());
+ servletResponse.setHeader(CORRELATION_ID_TIME_HEADER, correlationIdObj.getCreationTime().toString());
+ }
+
+ private void setInLog(CorrelationId correlationIdObj)
+ {
+ Map map = new HashMap<>();
+ map.put(CORELLATION_ID_LOG_KEY, correlationIdObj.getId());
+ map.put(CORELLATION_ID_SOURCE_LOG_KEY, correlationIdObj.getSource());
+ map.put(CORELLATION_ID_TIME_LOG_KEY, correlationIdObj.getCreationTime().toString());
+ MDC.setContextMap(map);
+ }
+
+ private String getFullURL(HttpServletRequest request) {
+ StringBuffer requestURL = request.getRequestURL();
+ String queryString = request.getQueryString();
+
+ if (queryString == null) {
+ return requestURL.toString();
+ } else {
+ return requestURL.append('?').append(queryString).toString();
+ }
+ }
+
+ private CorrelationId truncIfTooLong(CorrelationId correlationIdObj)
+ {
+ String correlationId = correlationIdObj.getId();
+ if (correlationId.length() > CORRELLATION_ID_MAX_LENGTH)
+ {
+ return new CorrelationId(correlationId.substring(0, CORRELLATION_ID_MAX_LENGTH), correlationIdObj.getSource(), correlationIdObj.getCreationTime());
+ }
+ return correlationIdObj;
+ }
+
+ private long getCreationTime(HttpServletRequest httpServletRequest)
+ {
+ long time = 0;
+ try
+ {
+ time = Long.parseLong(httpServletRequest.getHeader(CORRELATION_ID_TIME_HEADER));
+ } catch (NumberFormatException e)
+ {
+ //log
+ }
+ return time;
+ }
+
+ @Override
+ public void destroy()
+ {
+
+ }
+}
diff --git a/nut-corelationid/src/main/java/com/nutcore/nut/correlationid/CorrelationIdProducer.java b/nut-corelationid/src/main/java/com/nutcore/nut/correlationid/CorrelationIdProducer.java
new file mode 100644
index 0000000..bbaa3a2
--- /dev/null
+++ b/nut-corelationid/src/main/java/com/nutcore/nut/correlationid/CorrelationIdProducer.java
@@ -0,0 +1,16 @@
+package com.nutcore.nut.correlationid;
+
+import javax.enterprise.inject.Produces;
+
+
+/**
+ * Created by davidecerbo on 05/11/2016.
+ */
+public class CorrelationIdProducer
+{
+ @Produces
+ public CorrelationId getCorrelationId() {
+ return CorrelationIdUtil.getId();
+ }
+
+}
diff --git a/nut-corelationid/src/main/java/com/nutcore/nut/correlationid/CorrelationIdUtil.java b/nut-corelationid/src/main/java/com/nutcore/nut/correlationid/CorrelationIdUtil.java
new file mode 100644
index 0000000..21335a2
--- /dev/null
+++ b/nut-corelationid/src/main/java/com/nutcore/nut/correlationid/CorrelationIdUtil.java
@@ -0,0 +1,21 @@
+package com.nutcore.nut.correlationid;
+
+/**
+ * Created by davidecerbo on 04/11/2016.
+ */
+public class CorrelationIdUtil
+{
+
+ private static final ThreadLocal db = new ThreadLocal<>();
+
+ public static CorrelationId getId()
+ {
+ return db.get();
+ }
+
+ static void setId(CorrelationId oObjectDatabaseTx)
+ {
+ db.set(oObjectDatabaseTx);
+ }
+
+}
diff --git a/nut-corelationid/src/main/resources/META-INF/beans.xml b/nut-corelationid/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..8ebcd1a
--- /dev/null
+++ b/nut-corelationid/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,6 @@
+
+
\ No newline at end of file
diff --git a/nut-corelationid/src/main/resources/logback.xml b/nut-corelationid/src/main/resources/logback.xml
new file mode 100644
index 0000000..9a41e42
--- /dev/null
+++ b/nut-corelationid/src/main/resources/logback.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg %cyan([CID: %X{correlationId:-default} from %X{correlationIdSource:-System}]) %n
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/nut-metrics/pom.xml b/nut-metrics/pom.xml
new file mode 100644
index 0000000..437ce9b
--- /dev/null
+++ b/nut-metrics/pom.xml
@@ -0,0 +1,46 @@
+
+
+
+ nut
+ com.nutcore
+ 1.0-SNAPSHOT
+
+ 4.0.0
+
+ nut-metrics
+
+
+
+ com.codahale.metrics
+ metrics-core
+
+
+ com.codahale.metrics
+ metrics-servlets
+
+
+ com.codahale.metrics
+ metrics-annotation
+
+
+ javax
+ javaee-api
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 1.8
+
+
+
+
+
+
\ No newline at end of file
diff --git a/nut-metrics/src/main/java/com/nutcore/nut/metrics/MeterInterceptor.java b/nut-metrics/src/main/java/com/nutcore/nut/metrics/MeterInterceptor.java
new file mode 100644
index 0000000..50daab7
--- /dev/null
+++ b/nut-metrics/src/main/java/com/nutcore/nut/metrics/MeterInterceptor.java
@@ -0,0 +1,21 @@
+package com.nutcore.nut.metrics;
+
+import com.codahale.metrics.Meter;
+
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import java.io.IOException;
+
+public class MeterInterceptor implements ContainerRequestFilter {
+
+ private final Meter meter;
+
+ public MeterInterceptor(Meter meter) {
+ this.meter = meter;
+ }
+
+ @Override
+ public void filter(ContainerRequestContext requestContext) throws IOException {
+ if(meter != null) meter.mark();
+ }
+}
diff --git a/nut-metrics/src/main/java/com/nutcore/nut/metrics/MetricRegistryProducer.java b/nut-metrics/src/main/java/com/nutcore/nut/metrics/MetricRegistryProducer.java
new file mode 100644
index 0000000..4ac80dc
--- /dev/null
+++ b/nut-metrics/src/main/java/com/nutcore/nut/metrics/MetricRegistryProducer.java
@@ -0,0 +1,20 @@
+package com.nutcore.nut.metrics;
+
+import com.codahale.metrics.MetricRegistry;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+
+
+/**
+ * Created by davidecerbo on 05/11/2016.
+ */
+public class MetricRegistryProducer
+{
+ @Produces
+ @ApplicationScoped
+ public MetricRegistry getMetricRegistry() {
+ return new MetricRegistry();
+ }
+
+}
diff --git a/nut-metrics/src/main/java/com/nutcore/nut/metrics/MetricsFeature.java b/nut-metrics/src/main/java/com/nutcore/nut/metrics/MetricsFeature.java
new file mode 100644
index 0000000..bdf8fba
--- /dev/null
+++ b/nut-metrics/src/main/java/com/nutcore/nut/metrics/MetricsFeature.java
@@ -0,0 +1,97 @@
+package com.nutcore.nut.metrics;
+
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.Timer;
+import com.codahale.metrics.annotation.Metered;
+import com.codahale.metrics.annotation.Timed;
+
+import javax.inject.Inject;
+import javax.ws.rs.*;
+import javax.ws.rs.container.DynamicFeature;
+import javax.ws.rs.container.ResourceInfo;
+import javax.ws.rs.core.FeatureContext;
+import javax.ws.rs.ext.Provider;
+import java.lang.reflect.Method;
+import java.util.StringJoiner;
+
+import static com.codahale.metrics.MetricRegistry.name;
+
+@Provider
+@ConstrainedTo(RuntimeType.SERVER)
+public class MetricsFeature implements DynamicFeature {
+
+ @Inject
+ MetricRegistry registry;
+
+ @Override
+ public void configure(ResourceInfo resourceInfo, FeatureContext context) {
+ Method resourceMethod = resourceInfo.getResourceMethod();
+ if (resourceMethod.isAnnotationPresent(Timed.class)) {
+ final Timed annotation = resourceMethod.getAnnotation(Timed.class);
+ final String name = chooseName(annotation.name(), annotation.absolute(), resourceInfo);
+ final Timer timer = registry.timer(name);
+ context.register(new TimedInterceptor(timer));
+ }
+
+ if (resourceMethod.isAnnotationPresent(Metered.class)) {
+ final Metered annotation = resourceMethod.getAnnotation(Metered.class);
+ final String name = chooseName(annotation.name(), annotation.absolute(), resourceInfo);
+ final Meter meter = registry.meter(name);
+ context.register(new MeterInterceptor(meter));
+ }
+ }
+
+ private String chooseName(String explicitName, boolean absolute, ResourceInfo resourceInfo) {
+ if (explicitName != null && !explicitName.isEmpty()) {
+ if (absolute) {
+ return explicitName;
+ }
+ return name(getName(resourceInfo), explicitName);
+ }
+
+ return getName(resourceInfo);
+ }
+
+ private String getName(ResourceInfo resourceInfo) {
+ return getMethod(resourceInfo.getResourceMethod()) + " - " + getPath(resourceInfo);
+ }
+
+ private String getPath(ResourceInfo resourceInfo) {
+ String rootPath = null;
+ String methodPath = null;
+
+ if (resourceInfo.getResourceClass().isAnnotationPresent(Path.class)) {
+ rootPath = resourceInfo.getResourceClass().getAnnotation(Path.class).value();
+ }
+
+ if (resourceInfo.getResourceMethod().isAnnotationPresent(Path.class)) {
+ methodPath = resourceInfo.getResourceMethod().getAnnotation(Path.class).value();
+ }
+
+ return new StringJoiner("/").add(rootPath).add(methodPath).toString();
+ }
+
+ private String getMethod(Method resourceMethod) {
+ if (resourceMethod.isAnnotationPresent(GET.class)) {
+ return HttpMethod.GET;
+ }
+ if (resourceMethod.isAnnotationPresent(POST.class)) {
+ return HttpMethod.POST;
+ }
+ if (resourceMethod.isAnnotationPresent(PUT.class)) {
+ return HttpMethod.PUT;
+ }
+ if (resourceMethod.isAnnotationPresent(DELETE.class)) {
+ return HttpMethod.DELETE;
+ }
+ if (resourceMethod.isAnnotationPresent(HEAD.class)) {
+ return HttpMethod.HEAD;
+ }
+ if (resourceMethod.isAnnotationPresent(OPTIONS.class)) {
+ return HttpMethod.OPTIONS;
+ }
+
+ throw new IllegalStateException("Resource method without GET, POST, PUT, DELETE, HEAD or OPTIONS annotation");
+ }
+}
diff --git a/nut-metrics/src/main/java/com/nutcore/nut/metrics/MetricsListener.java b/nut-metrics/src/main/java/com/nutcore/nut/metrics/MetricsListener.java
new file mode 100644
index 0000000..6ae33be
--- /dev/null
+++ b/nut-metrics/src/main/java/com/nutcore/nut/metrics/MetricsListener.java
@@ -0,0 +1,40 @@
+package com.nutcore.nut.metrics;
+
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.servlets.MetricsServlet;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.servlet.*;
+import java.io.IOException;
+
+/**
+ * Created by davidecerbo on 09/11/2016.
+ */
+public class MetricsListener implements Filter
+{
+
+ public static final String METRICS_LISTENER = "MetricsListener";
+
+ @Inject
+ private MetricRegistry metricRegistry;
+
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException
+ {
+ ServletContext context = filterConfig.getServletContext();
+ context.setAttribute(MetricsServlet.METRICS_REGISTRY, metricRegistry);
+ }
+
+ @Override
+ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException
+ {
+ filterChain.doFilter(servletRequest, servletResponse);
+ }
+
+ @Override
+ public void destroy()
+ {
+
+ }
+}
diff --git a/nut-metrics/src/main/java/com/nutcore/nut/metrics/TimedInterceptor.java b/nut-metrics/src/main/java/com/nutcore/nut/metrics/TimedInterceptor.java
new file mode 100644
index 0000000..0482afa
--- /dev/null
+++ b/nut-metrics/src/main/java/com/nutcore/nut/metrics/TimedInterceptor.java
@@ -0,0 +1,33 @@
+package com.nutcore.nut.metrics;
+
+import com.codahale.metrics.Timer;
+
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.ext.Provider;
+import java.io.IOException;
+
+@Provider
+public class TimedInterceptor implements ContainerRequestFilter, ContainerResponseFilter {
+
+ private final Timer timer;
+
+ private static final ThreadLocal threadLocal = new ThreadLocal<>();
+
+
+ public TimedInterceptor(Timer timer) {
+ this.timer = timer;
+ }
+
+ @Override
+ public void filter(ContainerRequestContext requestContext) throws IOException {
+ threadLocal.set(timer.time());
+ }
+
+ @Override
+ public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
+ threadLocal.get().stop();
+ }
+}
diff --git a/nut-metrics/src/main/resources/META-INF/beans.xml b/nut-metrics/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..8ebcd1a
--- /dev/null
+++ b/nut-metrics/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,6 @@
+
+
\ No newline at end of file
diff --git a/nut-utils/pom.xml b/nut-utils/pom.xml
new file mode 100644
index 0000000..7ca4564
--- /dev/null
+++ b/nut-utils/pom.xml
@@ -0,0 +1,21 @@
+
+
+
+ nut
+ com.nutcore
+ 1.0-SNAPSHOT
+
+ 4.0.0
+
+ nut-utils
+
+
+
+ javax
+ javaee-api
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/archetype-resources/src/main/java/CORSFilter.java b/nut-utils/src/main/java/com/nutcore/nut/httputils/CORSFilter.java
similarity index 89%
rename from src/main/resources/archetype-resources/src/main/java/CORSFilter.java
rename to nut-utils/src/main/java/com/nutcore/nut/httputils/CORSFilter.java
index 8abe23d..48744fa 100644
--- a/src/main/resources/archetype-resources/src/main/java/CORSFilter.java
+++ b/nut-utils/src/main/java/com/nutcore/nut/httputils/CORSFilter.java
@@ -1,7 +1,4 @@
-#set( $symbol_pound = '#' )
-#set( $symbol_dollar = '$' )
-#set( $symbol_escape = '\' )
-package ${package};
+package com.nutcore.nut.httputils;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
diff --git a/pom.xml b/pom.xml
index 3c6e3b1..5e6301e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,47 +1,173 @@
- 4.0.0
-
- com.nutcore
- orientdb-microservices-archetype
- 1.0-SNAPSHOT
- maven-archetype
-
- orientdb-microservices-archetype
- A maven archetype to create a microservice component using OrientDB, Resteasy, Undertow and Swagger
- https://github.com/jesty/orientdb-microservices
-
-
-
- Apache License, Version 2.0
- http://www.apache.org/licenses/LICENSE-2.0.txt
- repo
-
-
-
-
- https://github.com/jesty/orientdb-microservices
- scm:git:git://github.com/jesty/orientdb-microservices.git
- scm:git:git@github.com:jesty/orientdb-microservices.git
-
-
-
-
-
- org.apache.maven.archetype
- archetype-packaging
- 2.4
-
-
-
-
-
-
- maven-archetype-plugin
- 2.4
-
-
-
-
+ 4.0.0
+
+ com.nutcore
+ nut
+ pom
+ 1.0-SNAPSHOT
+
+ nut-corelationid
+ nut-metrics
+ nut-utils
+ nut-archetype
+
+
+
+ 3.0.13.Final
+ 1.3.5.Final
+ 2.2.12
+ 2.4.0.Final
+ 1.1.7
+ 1.7.21
+ 3.0.1
+
+
+
+
+
+ com.nutcore
+ orientdb-javaee
+ 1.0
+
+
+ org.slf4j
+ slf4j-api
+ ${slf4j.version}
+
+
+
+ ch.qos.logback
+ logback-classic
+ ${logback.version}
+
+
+ org.jboss.resteasy
+ resteasy-jaxrs
+ ${resteasy.version}
+
+
+ org.jboss.resteasy
+ async-http-servlet-3.0
+ ${resteasy.version}
+
+
+ io.undertow
+ undertow-servlet
+ ${undertow.version}
+
+
+ org.jboss.resteasy
+ resteasy-undertow
+ ${resteasy.version}
+
+
+ org.jboss.resteasy
+ resteasy-cdi
+ ${resteasy.version}
+
+
+ org.jboss.resteasy
+ resteasy-jackson-provider
+ ${resteasy.version}
+
+
+ io.undertow
+ undertow-core
+ ${undertow.version}
+
+
+ com.orientechnologies
+ orientdb-core
+ ${orientdb.version}
+
+
+ com.orientechnologies
+ orientdb-graphdb
+ ${orientdb.version}
+
+
+ com.orientechnologies
+ orientdb-server
+ ${orientdb.version}
+
+
+ com.orientechnologies
+ orientdb-tools
+ ${orientdb.version}
+
+
+ com.orientechnologies
+ orientdb-client
+ ${orientdb.version}
+
+
+ com.orientechnologies
+ orientdb-object
+ ${orientdb.version}
+
+
+ javassist
+ org.javassist
+
+
+
+
+ javax
+ javaee-api
+ 7.0
+
+
+ javassist
+ org.javassist
+ 3.18.2-GA
+
+
+ org.jboss.weld
+ weld-core
+ ${weld.version}
+
+
+ org.jboss.weld.servlet
+ weld-servlet-core
+ ${weld.version}
+
+
+ io.swagger
+ swagger-jaxrs
+ 1.5.0
+
+
+ com.codahale.metrics
+ metrics-core
+ ${metrics.version}
+
+
+ com.codahale.metrics
+ metrics-servlets
+ ${metrics.version}
+
+
+ com.codahale.metrics
+ metrics-annotation
+ ${metrics.version}
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 1.8
+
+
+
+
+
+