Savio Coelho
Savio Coelho

Reputation: 53

Creating a PROXY service in Spring Boot, that listens on multiple ports, and redirects the GET requests to a new URL

Creating a PROXY service in Spring Boot, that listens on multiple ports, and redirects the GET requests to a new URL

Old URL from where requests will still be coming from - http://localhost:7010/DNTService?cptyXXX=89959623213123&portfolioXXX=03880774324234 To the new URL - http://wasp-uat-na.net/DNTService?cptyXXX=89959623213123&portfolioXXX=03880774324234

Is there a way in Spring that can help me achieve this???

So far using the steps in this "https://bitbucket.org/asimio/springboot-tomcat-multiple-ports/src/master/" I am able to listen on multiple ports but on adding the implementation for spring-cloud-gateway i get the below error:

Blockquote 2021-09-08 17:48:21.737 INFO 22192 --- [ main] c.p.wasp.proxyservice.WaspProxyService : The following profiles are active: local 2021-09-08 17:48:22.281 INFO 22192 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=092bb2d8-41fb-3da8-943b-0ff67624e05e 2021-09-08 17:48:22.287 INFO 22192 --- [ main] faultConfiguringBeanFactoryPostProcessor : No bean named 'errorChannel' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created. 2021-09-08 17:48:22.296 INFO 22192 --- [ main] faultConfiguringBeanFactoryPostProcessor : No bean named 'taskScheduler' has been explicitly defined. Therefore, a default ThreadPoolTaskScheduler will be created. 2021-09-08 17:48:22.301 INFO 22192 --- [ main] faultConfiguringBeanFactoryPostProcessor : No bean named 'integrationHeaderChannelRegistry' has been explicitly defined. Therefore, a default DefaultHeaderChannelRegistry will be created. 2021-09-08 17:48:22.365 INFO 22192 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.integration.config.IntegrationManagementConfiguration' of type [org.springframework.integration.config.IntegrationManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2021-09-08 17:48:22.369 INFO 22192 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration$IntegrationJmxConfiguration' of type [org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration$IntegrationJmxConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2021-09-08 17:48:22.375 INFO 22192 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration' of type [org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2021-09-08 17:48:22.378 INFO 22192 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'mbeanServer' of type [com.sun.jmx.mbeanserver.JmxMBeanServer] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2021-09-08 17:48:22.387 INFO 22192 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'integrationChannelResolver' of type [org.springframework.integration.support.channel.BeanFactoryChannelResolver] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2021-09-08 17:48:22.388 INFO 22192 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'integrationDisposableAutoCreatedBeans' of type [org.springframework.integration.config.annotation.Disposables] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2021-09-08 17:48:22.396 INFO 22192 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$fd890f3c] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 2021-09-08 17:48:22.586 INFO 22192 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 7010 (http) 7001 (http) 7002 (http) 7011 (http) 6152 (http) 6151 (http) 6158 (http) 6156 (http) 2021-09-08 17:48:22.609 INFO 22192 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2021-09-08 17:48:22.610 INFO 22192 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.31] 2021-09-08 17:48:22.739 INFO 22192 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2021-09-08 17:48:22.739 INFO 22192 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 990 ms 2021-09-08 17:48:22.782 INFO 22192 --- [ main] c.p.wasp.proxyservice.WaspProxyService : *** Initialization was completed successfully *** 2021-09-08 17:48:22.790 WARN 22192 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'globalErrorWebExceptionHandler' defined in file [C:\wasp-proxy-service\target\classes\com\potty\wasp\proxyservice\webservices\GlobalErrorWebExceptionHandler.class]: Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.http.codec.ServerCodecConfigurer' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} 2021-09-08 17:48:22.791 INFO 22192 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2021-09-08 17:48:22.800 INFO 22192 --- [ main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2021-09-08 17:48:22.944 ERROR 22192 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :


APPLICATION FAILED TO START


Description:

Parameter 2 of constructor in com.potty.wasp.proxyservice.webservices.GlobalErrorWebExceptionHandler required a bean of type 'org.springframework.http.codec.ServerCodecConfigurer' that could not be found.

Action:

Consider defining a bean of type 'org.springframework.http.codec.ServerCodecConfigurer' in your configuration.

Process finished with exit code 1

POM File:

<?xml version="1.0" encoding="UTF-8"?>
<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>com.potty.wasp</groupId>
    <artifactId>wasp-proxy-service</artifactId>
    <version>5.0.0-SNAPSHOT</version>
    <description>Proxy service used to route calls to WASP on GKP</description>

    <properties>
        <project.artifactId>wasp-proxy-service</project.artifactId>
        <project.version>5.0.0-SNAPSHOT</project.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <janus.janusweb-j2ee-version-gaia>5.0.0.0</janus.janusweb-j2ee-version-gaia>
        <janus.janusweb-j2ee-version>6.0.0.1</janus.janusweb-j2ee-version>
        <janus.giam-ip-common.version>14.10.19</janus.giam-ip-common.version>
        <commons-beanutils.version>1.9.3</commons-beanutils.version>
        <json.version>20140107</json.version>
        <spring-data-geode.version>2.1.0.RELEASE</spring-data-geode.version>
        <spring-shell.version>1.2.0.RELEASE</spring-shell.version>
        <jackson.version>2.9.10.20200103</jackson.version>
        <xstream.version>1.4.11.1</xstream.version>
        <tomcat.version>9.0.31</tomcat.version>
        <sonar.coverage.exclusions>
            **/db/model/*,
            **/json/model/*,
            **/datamodel/**/*,
            **/enumeration/*,
            **/*Literals.*,
            **/*Constants.*
        </sonar.coverage.exclusions>
        <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
        <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
        <sonar.jacoco.reportPath>${project.basedir}/target/jacoco.exec</sonar.jacoco.reportPath>
        <sonar.language>java</sonar.language>
        <spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
        <jacoco.version>0.8.6</jacoco.version>
        <jacoco.skip.instrument>true</jacoco.skip.instrument>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
    </parent>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.jacoco</groupId>
                <artifactId>org.jacoco.agent</artifactId>
                <version>${jacoco.version}</version>
                <classifier>runtime</classifier>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-to-slf4j</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-jcl</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!--<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <type>pom</type>
        </dependency>-->
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.28</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>com.vaadin.external.google</groupId>
                    <artifactId>android-json</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.jacoco</groupId>
            <artifactId>org.jacoco.agent</artifactId>
            <classifier>runtime</classifier>
            <scope>test</scope>
        </dependency>
        <!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>14.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
        </dependency>
        <!--~~~~~~~~~~~~~~~SPRING CLOUD~~~~~~~~~~~~~~~-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-contract-stub-runner</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>spring-boot-starter-web</artifactId>
                    <groupId>org.springframework.boot</groupId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <directory>target</directory>
        <outputDirectory>target/classes</outputDirectory>
        <finalName>${artifactId}-${version}</finalName>
        <testOutputDirectory>target/test-classes</testOutputDirectory>
        <sourceDirectory>src/main/java</sourceDirectory>
        <testSourceDirectory>src/test/java</testSourceDirectory>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <systemPropertyVariables>
                        <jacoco-agent.destfile>${project.build.directory}/jacoco.exec</jacoco-agent.destfile>
                    </systemPropertyVariables>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco.version}</version>
                <executions>
                    <execution>
                        <id>default-instrument</id>
                        <goals>
                            <goal>instrument</goal>
                        </goals>
                        <configuration>
                            <skip>${jacoco.skip.instrument}</skip>
                        </configuration>
                    </execution>
                    <execution>
                        <id>default-restore-instrumented-classes</id>
                        <goals>
                            <goal>restore-instrumented-classes</goal>
                        </goals>
                        <configuration>
                            <skip>${jacoco.skip.instrument}</skip>
                        </configuration>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <skip>${jacoco.skip.instrument}</skip>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>build-info</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

Upvotes: 0

Views: 941

Answers (1)

Alexander.Furer
Alexander.Furer

Reputation: 1869

spring-cloud-gateway is what you are looking for

Upvotes: 0

Related Questions