This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move custom consumer from core services to utilities (#20)
* Custom consumer mvn changes (#245) * add new consumer * Adding build config for egov-custom-consumer service * added kafka host * add client for financial signout * Update CustomConsumerApplication.java * Fixed serialization error in zuul * [PBERP-456] - Extracted url to properties. * Merging from old repo to new repo * maven upgrade changes * Jackson version and kafka issue fix Co-authored-by: GhanshyamRawat <[email protected]> Co-authored-by: sivaprakash123 <[email protected]> Co-authored-by: venki <[email protected]> * Merging from core services repo to utilities repo * Adding custom consumer to build configuration Co-authored-by: GhanshyamRawat <[email protected]> Co-authored-by: sivaprakash123 <[email protected]> Co-authored-by: venki <[email protected]>
- Loading branch information
1 parent
009661c
commit 015d704
Showing
10 changed files
with
328 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Changelog | ||
All notable changes to this module will be documented in this file. | ||
|
||
## 1.1.0 - 2020-06-22 | ||
|
||
- Upgraded to `tracer:2.0.0-SNAPSHOT` | ||
- Upgraded to `Spring boot 2.2.6` | ||
|
||
## 1.0.0 | ||
|
||
- Base version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
FROM egovio/apline-jre:8u121-mdms-1.0 | ||
|
||
MAINTAINER Sivaprakash<[email protected]> | ||
|
||
|
||
# INSTRUCTIONS ON HOW TO BUILD JAR: | ||
# Move to the location where pom.xml is exist in project and build project using below command | ||
# "mvn clean package" | ||
|
||
#RUN cd /opt/mdms && git pull origin master | ||
|
||
#RUN cd /opt && wget "https://codeload.github.com/egovernments/egov-mdms-data/zip/master" -O master.zip && unzip master.zip && rm -rf master.zip mdms && mv egov-mdms-data-master mdms | ||
|
||
COPY /target/egov-custom-consumer-0.0.1-SNAPSHOT.jar /opt/egov/egov-custom-consumer.jar | ||
|
||
COPY start.sh /usr/bin/start.sh | ||
|
||
RUN chmod +x /usr/bin/start.sh | ||
|
||
CMD ["/usr/bin/start.sh"] | ||
|
||
# NOTE: the two 'RUN' commands can probably be combined inside of a single | ||
# script (i.e. RUN build-and-install-app.sh) so that we can also clean up the | ||
# extra files created during the `mvn package' command. that step inflates the | ||
# resultant image by almost 1.0GB. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<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> | ||
<groupId>org.egov</groupId> | ||
<artifactId>egov-custom-consumer</artifactId> | ||
<version>1.1.0-SNAPSHOT</version> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.2.6.RELEASE</version> | ||
<relativePath /> <!-- lookup parent from repository --> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<java.version>1.8</java.version> | ||
<commons-lang-version>2.6</commons-lang-version> | ||
<maven.version>3.3.9</maven.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-lang</groupId> | ||
<artifactId>commons-lang</artifactId> | ||
<version>${commons-lang-version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
<version>3.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.egov.services</groupId> | ||
<artifactId>tracer</artifactId> | ||
<version>2.0.0-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.egov.services</groupId> | ||
<artifactId>services-common</artifactId> | ||
<version>1.0.0-RELEASE</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.jayway.jsonpath</groupId> | ||
<artifactId>json-path</artifactId> | ||
<version>2.2.0</version> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/org.json/json --> | ||
<dependency> | ||
<groupId>org.json</groupId> | ||
<artifactId>json</artifactId> | ||
<version>20160810</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.fasterxml.jackson.dataformat</groupId> | ||
<artifactId>jackson-dataformat-yaml</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-devtools</artifactId> | ||
<scope>runtime</scope> | ||
</dependency> | ||
</dependencies> | ||
<repositories> | ||
<repository> | ||
<id>repo.egovernments.org</id> | ||
<name>eGov ERP Releases Repository</name> | ||
<url>https://nexus-repo.egovernments.org/nexus/content/repositories/releases/</url> | ||
</repository> | ||
<repository> | ||
<id>repo.egovernments.org.snapshots</id> | ||
<name>eGov ERP Releases Repository</name> | ||
<url>https://nexus-repo.egovernments.org/nexus/content/repositories/snapshots/</url> | ||
</repository> | ||
<repository> | ||
<id>repo.egovernments.org.public</id> | ||
<name>eGov Public Repository Group</name> | ||
<url>https://nexus-repo.egovernments.org/nexus/content/groups/public/</url> | ||
</repository> | ||
</repositories> | ||
|
||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
|
||
</project> | ||
|
27 changes: 27 additions & 0 deletions
27
egov-custom-consumer/src/main/java/org/egov/CustomConsumerApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.egov; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
@SpringBootApplication | ||
public class CustomConsumerApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(CustomConsumerApplication.class, args); | ||
} | ||
|
||
@Bean | ||
public RestTemplate restTemplate() { | ||
return new RestTemplate(); | ||
} | ||
|
||
@Bean | ||
public ObjectMapper objectMapper() { | ||
return new ObjectMapper(); | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
egov-custom-consumer/src/main/java/org/egov/cosumer/CustomConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.egov.cosumer; | ||
|
||
import java.util.HashMap; | ||
|
||
import org.egov.service.SignOutService; | ||
import org.egov.utils.JsonPathConstant; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.kafka.annotation.KafkaListener; | ||
import org.springframework.kafka.support.KafkaHeaders; | ||
import org.springframework.messaging.handler.annotation.Header; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.jayway.jsonpath.DocumentContext; | ||
import com.jayway.jsonpath.JsonPath; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Component | ||
@Slf4j | ||
public class CustomConsumer { | ||
|
||
@Autowired | ||
private SignOutService signOutService; | ||
|
||
@Autowired | ||
private ObjectMapper objectMapper; | ||
|
||
@KafkaListener(topics = { "${egov.custom.async.filter.topic}" }) | ||
public void listen(final HashMap<String, Object> record, @Header(KafkaHeaders.RECEIVED_TOPIC) String topic) { | ||
|
||
log.info("CustomConsumer received request from topic: " + topic); | ||
log.info("data: " + record); | ||
log.info(record.keySet().toString()); | ||
|
||
try { | ||
//String inputJson = objectMapper.writeValueAsString(record); | ||
DocumentContext documentContext = JsonPath.parse(record); | ||
String sourceUri = documentContext.read(JsonPathConstant.signOutUriJsonPath); | ||
|
||
if(sourceUri.equals(JsonPathConstant.signOutUri)) | ||
signOutService.callFinanceForSignOut(documentContext); | ||
|
||
} catch (Exception ex) { | ||
ex.printStackTrace(); | ||
} | ||
|
||
// ObjectMapper mapper = new ObjectMapper(); | ||
|
||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
egov-custom-consumer/src/main/java/org/egov/service/SignOutService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.egov.service; | ||
|
||
import java.util.LinkedHashMap; | ||
|
||
import org.egov.utils.JsonPathConstant; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.HttpClientErrorException; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import com.jayway.jsonpath.DocumentContext; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Service | ||
@Slf4j | ||
public class SignOutService { | ||
|
||
@Autowired | ||
private RestTemplate restTemplate; | ||
|
||
@Value("${egov.coexistence.hostname}") | ||
private String coexistencehost; | ||
|
||
@Value("${egov.coexistence.singout.uri}") | ||
private String coexistencelogoutUri; | ||
|
||
public void callFinanceForSignOut(DocumentContext documentContext) { | ||
ResponseEntity<?> response = null; | ||
try { | ||
; | ||
String accessToken = documentContext.read(JsonPathConstant.signOutAccessToken); | ||
documentContext = documentContext.delete(JsonPathConstant.userInfo); | ||
documentContext = documentContext.put(JsonPathConstant.requestInfo, "authToken", accessToken); | ||
LinkedHashMap<String, Object> jsonRequest = documentContext.read(JsonPathConstant.request); | ||
|
||
response = restTemplate.exchange(coexistencehost + coexistencelogoutUri, HttpMethod.POST, | ||
new HttpEntity<>(jsonRequest), | ||
ResponseEntity.class); | ||
log.info("SignOutService response :" + response.getStatusCode()); | ||
} catch (HttpClientErrorException ex) { | ||
log.error(ex.getResponseBodyAsString()); | ||
ex.printStackTrace(); | ||
} catch (Exception ex) { | ||
ex.printStackTrace(); | ||
} | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
egov-custom-consumer/src/main/java/org/egov/utils/JsonPathConstant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.egov.utils; | ||
|
||
public class JsonPathConstant { | ||
|
||
public static final String signOutAccessToken = "$.queryParamMap.access_token[0]"; | ||
public static final String request = "$.request"; | ||
public static final String userInfo = "$.request.RequestInfo.userInfo"; | ||
public static final String requestInfo = "$.request.RequestInfo"; | ||
public static final String accessTokenKey = "authToken"; | ||
public static final String signOutUri = "/user/_logout"; | ||
public static final String signOutUriJsonPath = "$.sourceUri"; | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
egov-custom-consumer/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
spring.main.web-environment=false | ||
server.context-path=/egov-custom-consumer | ||
server.servlet.context-path=/egov-custom-consumer | ||
|
||
# KAFKA SERVER CONFIGURATIONS | ||
kafka.config.bootstrap_server_config=kafka-0.kafka.backbone:9092 | ||
spring.kafka.consumer.value-deserializer=org.egov.tracer.kafka.deserializer.HashMapDeserializer | ||
spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer | ||
spring.kafka.consumer.group-id=egov-api-gateway-1 | ||
|
||
spring.kafka.listener.missing-topics-fatal=false | ||
|
||
egov.custom.async.filter.topic=res-custom-filter | ||
egov.coexistence.hostname=https://jalandhar-dev.egovernments.org | ||
egov.coexistence.singout.uri=/services/EGF/rest/ClearToken |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/sh | ||
|
||
if [[ -z "${JAVA_OPTS}" ]];then | ||
export JAVA_OPTS="-Xmx64m -Xms64m" | ||
fi | ||
|
||
java ${JAVA_OPTS} -jar /opt/egov/egov-custom-consumer.jar |