Skip to content

Commit

Permalink
MOSIP-37921 Fixed subscription issue in migrated resident service. (#…
Browse files Browse the repository at this point in the history
…1365)

* MOSIP-35611 Fixed subscription issue in resident service

Signed-off-by: kameshsr <[email protected]>

* MOSIP-35611 Fixed websub issue

Signed-off-by: kameshsr <[email protected]>

* MOSIP-35611 Fixed websub issue

Signed-off-by: kameshsr <[email protected]>

* MOSIP-35611 Fixed websub issue

Signed-off-by: kameshsr <[email protected]>

* Corrected version

Signed-off-by: kameshsr <[email protected]>

* MOSIP-35611 Comment postconstruct for testing

Signed-off-by: kameshsr <[email protected]>

* MOSIP-35611 Corrected task sceduler

Signed-off-by: kameshsr <[email protected]>

* MOSIP-35611 Fixed websub issue

Signed-off-by: kameshsr <[email protected]>

* MOSIP-35611 Made thread pool values configurable

Signed-off-by: kameshsr <[email protected]>

* MOSIP-35611 Fixed websub issue

Signed-off-by: kameshsr <[email protected]>

* MOSIP-35611 Fixed startup issue

Signed-off-by: kameshsr <[email protected]>

* MOSIP-35611 Fixed startup issue

Signed-off-by: kameshsr <[email protected]>

* Mosip-35611 Fixed websub issue

Signed-off-by: kameshsr <[email protected]>

---------

Signed-off-by: kameshsr <[email protected]>
  • Loading branch information
kameshsr authored Dec 2, 2024
1 parent b3ff443 commit 892fc80
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 45 deletions.
4 changes: 2 additions & 2 deletions resident/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<name>resident</name>
<description>Parent project of MOSIP Resident</description>
<url>https://github.com/mosip/resident-services</url>

<licenses>
<license>
<name>MPL 2.0</name>
Expand Down Expand Up @@ -79,6 +78,7 @@
**/constant/**,**/config/**,**/httpfilter/**,**/cache/**,**/dto/**,**/entity/**,**/model/**,**/exception/**,**/repository/**,**/security/**,**/*Config.java,**/*BootApplication.java,**/*VertxApplication.java,**/cbeffutil/**,**/mock/**,**/OrderCard*,**/testrig/**
</sonar.coverage.exclusions>
<sonar.cpd.exclusions>**/dto/**,**/entity/**,**/config/**</sonar.cpd.exclusions>
<kernel-bom.version>1.3.0-SNAPSHOT</kernel-bom.version>
</properties>

<modules>
Expand All @@ -89,7 +89,7 @@
<dependency>
<groupId>io.mosip.kernel</groupId>
<artifactId>kernel-bom</artifactId>
<version>1.2.1-SNAPSHOT</version>
<version>${kernel-bom.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
33 changes: 18 additions & 15 deletions resident/resident-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,24 @@
<name>resident-service</name>
<version>1.2.1-SNAPSHOT</version>
<properties>
<commons.packet.manager.version>1.2.1-SNAPSHOT</commons.packet.manager.version>
<kernel.core.version>1.2.1-SNAPSHOT</kernel.core.version>
<kernel.virusscanner.clamav.version>1.2.1-SNAPSHOT</kernel.virusscanner.clamav.version>
<kernel-keymanager-service.version>1.2.1-SNAPSHOT</kernel-keymanager-service.version>
<kernel.authcodeflowproxy.api.version>1.2.1-SNAPSHOT</kernel.authcodeflowproxy.api.version>
<kernel.parent.version>1.2.1-SNAPSHOT</kernel.parent.version>
<commons.packet.manager.version>1.3.0-SNAPSHOT</commons.packet.manager.version>
<kernel.core.version>1.3.0-SNAPSHOT</kernel.core.version>
<kernel.virusscanner.clamav.version>1.3.0-SNAPSHOT</kernel.virusscanner.clamav.version>
<kernel-keymanager-service.version>1.3.0-SNAPSHOT</kernel-keymanager-service.version>
<kernel.authcodeflowproxy.api.version>1.3.0-SNAPSHOT</kernel.authcodeflowproxy.api.version>
<kernel.parent.version>1.3.0-SNAPSHOT</kernel.parent.version>
<kernel-cbeffutil-api.version>${kernel.parent.version}</kernel-cbeffutil-api.version>
<kernel.khazana.version>1.2.1-SNAPSHOT</kernel.khazana.version>
<kernel-openid-bridge-api.version>1.2.1-SNAPSHOT</kernel-openid-bridge-api.version>
<kernel.khazana.version>1.3.0-SNAPSHOT</kernel.khazana.version>
<kernel-openid-bridge-api.version>1.3.0-SNAPSHOT</kernel-openid-bridge-api.version>
<maven.jacoco.plugin.version>0.8.11</maven.jacoco.plugin.version>
<kernel.idobjectvalidator.version>1.2.1-SNAPSHOT</kernel.idobjectvalidator.version>
<pre-registration-application-service.version>1.2.1-SNAPSHOT</pre-registration-application-service.version>
<kernel.idobjectvalidator.version>1.3.0-SNAPSHOT</kernel.idobjectvalidator.version>
<pre-registration-application-service.version>1.3.0-SNAPSHOT</pre-registration-application-service.version>
<jacoco.maven.plugin.version>0.8.11</jacoco.maven.plugin.version>
<id-repository-core.version>1.2.1-SNAPSHOT</id-repository-core.version>

<kernel-websubclient-api.version>1.3.0-SNAPSHOT</kernel-websubclient-api.version>
<kernel-pdfgenerator-itext.version>1.3.0-SNAPSHOT</kernel-pdfgenerator-itext.version>
<kernel-ref-idobjectvalidato.version>1.3.0-SNAPSHOT</kernel-ref-idobjectvalidato.version>
<kernel-auth-adpater.version>1.3.0-SNAPSHOT</kernel-auth-adpater.version>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -254,7 +257,7 @@
<dependency>
<groupId>io.mosip.kernel</groupId>
<artifactId>kernel-websubclient-api</artifactId>
<version>${project.version}</version>
<version>${kernel-websubclient-api.version}</version>
</dependency>
<dependency>
<groupId>org.mvel</groupId>
Expand Down Expand Up @@ -299,7 +302,7 @@
<dependency>
<groupId>io.mosip.kernel</groupId>
<artifactId>kernel-pdfgenerator-itext</artifactId>
<version>1.2.1-SNAPSHOT</version>
<version>${kernel-pdfgenerator-itext.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
Expand All @@ -319,12 +322,12 @@
<dependency>
<groupId>io.mosip.kernel</groupId>
<artifactId>kernel-auth-adapter</artifactId>
<version>1.2.1-SNAPSHOT</version>
<version>${kernel-auth-adpater.version}</version>
</dependency>
<dependency>
<groupId>io.mosip.kernel</groupId>
<artifactId>kernel-ref-idobjectvalidator</artifactId>
<version>1.2.1-SNAPSHOT</version>
<version>${kernel-ref-idobjectvalidato.version}</version>
</dependency>
</dependencies>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import io.mosip.kernel.pdfgenerator.itext.impl.PDFGeneratorImpl;
import io.mosip.kernel.templatemanager.velocity.builder.TemplateManagerBuilderImpl;
import io.mosip.kernel.transliteration.icu4j.impl.TransliterationImpl;
import io.mosip.kernel.websub.api.client.PublisherClientImpl;
import io.mosip.kernel.websub.api.client.SubscriberClientImpl;
import io.mosip.kernel.websub.api.config.WebSubClientConfig;
import io.mosip.kernel.websub.api.config.publisher.RestTemplateHelper;
import io.mosip.kernel.websub.api.config.publisher.WebSubPublisherClientConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand All @@ -37,14 +37,16 @@
"io.mosip.kernel.virusscanner.*",
"io.mosip.commons.khazana.*",
"io.mosip.idrepository.core.util.*",
"io.mosip.kernel.authcodeflowproxy.*"}
"io.mosip.kernel.authcodeflowproxy.*",
"io.mosip.kernel.websub.api.config"}
)
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class })
@Import({TokenIDGenerator.class, ValidateTokenUtil.class, CbeffImpl.class, TransliterationService.class, TransliterationServiceUtil.class
, PDFGeneratorImpl.class, UinValidatorImpl.class, VidValidatorImpl.class, RidValidatorImpl.class, TemplateManagerBuilderImpl.class,
SubscriberClientImpl.class, RestTemplateHelper.class, TransliterationImpl.class, PublisherClientImpl.class, IdObjectValidatorConfig.class
, RestTemplate.class, KeyStoreImpl.class})
RestTemplateHelper.class, TransliterationImpl.class, IdObjectValidatorConfig.class
, RestTemplate.class, KeyStoreImpl.class, WebSubPublisherClientConfig.class,
WebSubClientConfig.class,})
public class ResidentBootApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.Properties;

import io.mosip.kernel.websub.api.config.WebSubClientConfig;
import jakarta.servlet.Filter;

import org.apache.commons.collections.CollectionUtils;
Expand All @@ -22,6 +23,7 @@
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;
Expand Down Expand Up @@ -49,6 +51,7 @@
@Configuration
@EnableScheduling
@EnableAsync
@Import(WebSubClientConfig.class)
public class Config {
private String defaultEncoding = StandardCharsets.UTF_8.name();
/** The resource loader. */
Expand All @@ -68,7 +71,15 @@ public class Config {

@Value("${" + ResidentConstants.RESIDENT_REST_TEMPLATE_METRICS_INTERCEPTOR_FILTER_ENABLED + ":false}")
private boolean isResidentMetricsInterceptorFilterEnabled;


@Value("${task.scheduler.pool-size:10}")
private int poolSize;

@Value("${task.scheduler.await-termination-seconds:30}")
private int awaitTerminationSeconds;

@Value("${task.scheduler.wait-for-tasks-to-complete-on-shutdown:true}")
private boolean waitForTasksToCompleteOnShutdown;

@Autowired(required = false)
private RestTemplateLoggingInterceptor restTemplateLoggingInterceptor;
Expand Down Expand Up @@ -172,8 +183,10 @@ private void addInterceptors(RestTemplate restTemplate) {
@Bean
public ThreadPoolTaskScheduler threadPoolTaskScheduler() {
ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
threadPoolTaskScheduler.setPoolSize(5);
threadPoolTaskScheduler.setPoolSize(poolSize);
threadPoolTaskScheduler.setThreadNamePrefix("ThreadPoolTaskScheduler");
threadPoolTaskScheduler.setWaitForTasksToCompleteOnShutdown(waitForTasksToCompleteOnShutdown);
threadPoolTaskScheduler.setAwaitTerminationSeconds(awaitTerminationSeconds);
return threadPoolTaskScheduler;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

import java.io.IOException;

/**
@author Kamesh Shekhar Prasad
*/

@Component
public class TrailingSlashRedirectFilter implements Filter {

Expand All @@ -16,9 +20,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha

HttpServletRequest httpRequest = (HttpServletRequest) request;
String path = httpRequest.getRequestURI();

// For other types of requests, handle the trailing slash redirection
if (path.endsWith("/")) {
if (path.endsWith("/") && !path.endsWith("status/")) {
String newPath = path.substring(0, path.length() - 1);
HttpServletRequest newRequest = new CustomHttpServletRequestWrapper(httpRequest, newPath);
chain.doFilter(newRequest, response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,53 @@ public class BaseWebSubInitializer implements ApplicationListener<ApplicationRea

@Value("${resident.websub.regproc.workflow.complete.secret}")
private String regProcWorkFlowCompleteSecret;



@Value("${task.scheduler.pool-size:10}")
private int poolSize;

@Value("${task.scheduler.thread-name-prefix:TaskScheduler-}")
private String threadNamePrefix;

@Value("${task.scheduler.await-termination-seconds:30}")
private int awaitTerminationSeconds;

@Value("${task.scheduler.wait-for-tasks-to-complete-on-shutdown:true}")
private boolean waitForTasksToCompleteOnShutdown;

@Override
public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
logger.info("onApplicationEvent", "BaseWebSubInitializer", "Application is ready");
logger.info("Scheduling event subscriptions after (milliseconds): " + taskSubscriptionInitialDelay);
logger.info("Scheduling event subscriptions after (milliseconds): " + taskSubscriptionInitialDelay);
taskScheduler.setPoolSize(poolSize);
taskScheduler.setThreadNamePrefix(threadNamePrefix);
taskScheduler.setWaitForTasksToCompleteOnShutdown(waitForTasksToCompleteOnShutdown);
taskScheduler.setAwaitTerminationSeconds(awaitTerminationSeconds);

taskScheduler.schedule(() -> {
//Invoke topic registrations. This is done only once.
//Note: With authenticated websub, only register topics which are only published by IDA
tryRegisteringTopics();
//Init topic subscriptions
initTopicSubscriptions();
}, new Date(System.currentTimeMillis() + taskSubscriptionInitialDelay));

if (reSubscriptionIntervalSecs > 0) {
logger.info("Work around for web-sub notification issue after some time.");
scheduleRetrySubscriptions();
} else {
logger.info("Scheduling for re-subscription is Disabled as the re-subsctription delay value is: "
+ reSubscriptionIntervalSecs);
}
try {
// Invoke topic registrations (done only once)
tryRegisteringTopics();
// Initialize topic subscriptions
initTopicSubscriptions();
} catch (Exception e) {
logger.error("Error while scheduling topic registrations and subscriptions", e);
}
}, trigger -> {
// Schedule task to execute once after the initial delay
return new Date(System.currentTimeMillis() + taskSubscriptionInitialDelay).toInstant();
});

if (reSubscriptionIntervalSecs > 0) {
logger.info("Workaround for web-sub notification issue after some time.");
scheduleRetrySubscriptions();
} else {
logger.info("Re-subscription scheduling is disabled as the re-subscription interval is: "
+ reSubscriptionIntervalSecs);
}
}

private void initTopicSubscriptions() {

private void initTopicSubscriptions() {
authTypStatusTopicSubsriptions();
authTransactionTopicSubscription();
credentialStatusUpdateTopicSubscription();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ mosipbox.public.url=http://localhost:8099
openapi.residentServiceServer.servers[0].url=${mosipbox.public.url}/resident/v1
openapi.residentServiceServer.servers[0].description=Resident Service
spring.devtools.restart.enabled = false

logging.level.root=DEBUG

0 comments on commit 892fc80

Please sign in to comment.