package org.proshin.blog.configuration;

import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
import com.amazonaws.services.dynamodbv2.document.DynamoDB;
import io.sentry.spring.SentryExceptionResolver;
import io.sentry.spring.SentryServletContextInitializer;
import lombok.extern.log4j.Log4j;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.HandlerExceptionResolver;

@Log4j
@Configuration
public class ApplicationContext {

    public ApplicationContext() {
        log.info("A new instance of application context has been instantiated");
    }

    @Bean
    public RestTemplate getRestTemplate() {
        return new RestTemplate();
    }

    @Bean
    public DynamoDB getDynamoDB(ConfigParameters configParameters) {
        ConfigParameters.Dynamo dynamoConfig = configParameters.getDynamo();

        AmazonDynamoDBClientBuilder clientBuilder =
                AmazonDynamoDBClientBuilder
                        .standard();

        if (dynamoConfig.getEndpoint() != null) {
            clientBuilder
                    .withEndpointConfiguration(
                            new EndpointConfiguration(
                                    dynamoConfig.getEndpoint(),
                                    dynamoConfig.getRegion()));
        } else {
            clientBuilder
                    .withRegion(dynamoConfig.getRegion());
        }

        if (dynamoConfig.getAccessKey() != null && dynamoConfig.getSecretKey() != null) {
            clientBuilder
                    .withCredentials(
                            new AWSStaticCredentialsProvider(
                                    new BasicAWSCredentials(
                                            dynamoConfig.getAccessKey(),
                                            dynamoConfig.getSecretKey())));
        }

        return new DynamoDB(clientBuilder.build());
    }

    @Bean
    public HandlerExceptionResolver sentryExceptionResolver() {
        return new SentryExceptionResolver();
    }

    @Bean
    public ServletContextInitializer sentryServletContextInitializer() {
        return new SentryServletContextInitializer();
    }
}

@@ -354,210 +354,33 @@
 ort 
-io.sentry.spring.SentryExceptionResolver;%0Aimport io.sentry.spring.SentryServletContextInitializer;%0Aimport lombok.extern.log4j.Log4j;%0Aimport org.springframework.boot.web.servlet.ServletContextInitializer
+lombok.extern.log4j.Log4j
 ;%0Aim
@@ -545,73 +545,8 @@
 ate;
-%0Aimport org.springframework.web.servlet.HandlerExceptionResolver;
 %0A%0A@L
@@ -2027,278 +2027,7 @@
    %7D
-%0A%0A    @Bean%0A    public HandlerExceptionResolver sentryExceptionResolver() %7B%0A        return new SentryExceptionResolver();%0A    %7D%0A%0A    @Bean%0A    public ServletContextInitializer sentryServletContextInitializer() %7B%0A        return new SentryServletContextInitializer();%0A    %7D
 %0A%7D%0A

Integrate Sentry for errors tracking - integrate via Logback conf