Skip to content

Commit

Permalink
Merge pull request #62 from vinscom/develop
Browse files Browse the repository at this point in the history
rel
  • Loading branch information
vinscom authored Jan 17, 2019
2 parents 9df8aa2 + e9bcd89 commit b44aaf2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>in.erail</groupId>
<artifactId>api-framework</artifactId>
<version>2.4.4</version>
<version>2.4.5</version>
<packaging>jar</packaging>
<developers>
<developer>
Expand Down Expand Up @@ -183,7 +183,7 @@
<dependency>
<groupId>in.erail</groupId>
<artifactId>glue</artifactId>
<version>2.4.3</version>
<version>2.4.5</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/in/erail/route/OpenAPI3RouteBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.codahale.metrics.Metered;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
import com.google.common.base.Strings;
import com.google.common.net.HttpHeaders;
import com.google.common.net.MediaType;
import java.io.File;
Expand Down Expand Up @@ -31,6 +32,7 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.Optional;
import java.util.UUID;
import org.apache.commons.lang3.exception.ExceptionUtils;

/**
Expand All @@ -39,14 +41,16 @@
*/
public class OpenAPI3RouteBuilder extends AbstractRouterBuilderImpl {

private static final String HEADER_X_REQUEST_ID = "X-Request-ID";
private static final String FAIL_SUFFIX = ".fail";
private RESTService[] mServices;
private File mOpenAPI3File;
private DeliveryOptions mDeliveryOptions;
private boolean mSecurityEnable = true;
private HashMap<String, Metered> mMetrics = new HashMap<>();
private MetricRegistry mMetricRegistry;

private String mRequestIdHeaderName = HEADER_X_REQUEST_ID;

public File getOpenAPI3File() {
return mOpenAPI3File;
}
Expand Down Expand Up @@ -83,6 +87,15 @@ public void process(RoutingContext pRequestContext, String pServiceUniqueId) {

Timer.Context timerCtx = ((Timer) getMetrics().get(pServiceUniqueId)).time();

String requestId = pRequestContext.request().getHeader(getRequestIdHeaderName());

if (Strings.isNullOrEmpty(requestId)) {
requestId = UUID.randomUUID().toString();
pRequestContext.request().headers().add(getRequestIdHeaderName(), UUID.randomUUID().toString());
}

pRequestContext.response().putHeader(getRequestIdHeaderName(), requestId);

getVertx()
.eventBus()
.send(pServiceUniqueId,
Expand Down Expand Up @@ -320,4 +333,12 @@ public void setMetricRegistry(MetricRegistry pMetricRegistry) {
this.mMetricRegistry = pMetricRegistry;
}

public String getRequestIdHeaderName() {
return mRequestIdHeaderName;
}

public void setRequestIdHeaderName(String pRequestIdHeaderName) {
this.mRequestIdHeaderName = pRequestIdHeaderName;
}

}

0 comments on commit b44aaf2

Please sign in to comment.