Skip to content

Commit

Permalink
Fix Filter Lifecycle (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
kingster authored Aug 10, 2024
1 parent 0369cd4 commit 98abf95
Show file tree
Hide file tree
Showing 7 changed files with 365 additions and 315 deletions.
12 changes: 10 additions & 2 deletions core/src/main/java/com/flipkart/gjex/core/Bundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Map;

import com.flipkart.gjex.core.filter.grpc.GrpcFilter;
import com.flipkart.gjex.core.filter.http.HttpFilter;
import com.flipkart.gjex.core.job.ScheduledJob;
import org.glassfish.jersey.server.ResourceConfig;

Expand Down Expand Up @@ -56,11 +57,18 @@ public interface Bundle<T extends GJEXConfiguration, U extends Map> {
List<Service> getServices();

/**
* Returns Filter instances loaded by this Bundle
* @return List containing Filter instances
* Returns GrpcFilter instances loaded by this Bundle
* @return List containing GrpcFilter instances
*/
List<GrpcFilter> getGrpcFilters();


/**
* Returns HTTPFilter instances loaded by this Bundle
* @return List containing HttpFilter instances
*/
List<HttpFilter> getHTTPFilters();

/**
* Returns HealthCheck instances loaded by this Bundle
* @return List containing HealthCheck instances
Expand Down
7 changes: 6 additions & 1 deletion core/src/main/java/com/flipkart/gjex/core/filter/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@
public abstract class Filter<Req, Res, M> {

/**
* Lifecycle methods for cleaning up resources used by this Filter
* Lifecycle method for initializing resources used by this Filter.
*/
public void init() {}

/**
* Lifecycle method for cleaning up resources used by this Filter.
*/
public void destroy() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.protobuf.GeneratedMessageV3;
import io.grpc.Metadata;
import io.grpc.Status;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;

import java.util.Map;
Expand Down Expand Up @@ -83,8 +84,8 @@ public void doProcessRequest(R req, RequestParams<Metadata> requestParamsInput)
.resourcePath(requestParamsInput.getResourcePath());

Map<String, String> headers = requestParamsInput.getMetadata().keys().stream()
.collect(Collectors.toMap(key -> key, key ->
Optional.ofNullable(requestParamsInput.getMetadata().get(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER))).orElse("")
.collect(Collectors.toMap(String::toLowerCase, key ->
Optional.ofNullable(requestParamsInput.getMetadata().get(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER))).orElse(StringUtils.EMPTY)
));

accessLogContextBuilder.headers(headers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
public abstract class GrpcFilter<Req extends GeneratedMessageV3, Res extends GeneratedMessageV3>
extends Filter<Req,Res, Metadata> {

/** Lifecycle methods for initializing and cleaning up resources used by this Filter*/
public void init(){}

/**
* Function for creating an instance of this {@link Filter}
* Use only this function to get the {@link Filter} instance
Expand Down
Loading

0 comments on commit 98abf95

Please sign in to comment.