From 4b5b03100bdf6a01762c7f739ae54101860cdb5e Mon Sep 17 00:00:00 2001 From: skdhitman Date: Fri, 12 Nov 2021 10:43:34 +0530 Subject: [PATCH 1/3] First Commit after Adding Gateway Layer successfully --- .github/workflows/gradle.yml | 44 --- .gitignore | 35 -- .vscode/launch.json | 8 + build.gradle | 302 ------------------ src/main/docker/app.yml | 28 -- .../provisioning/dashboards/dashboard.yml | 11 - .../provisioning/datasources/datasource.yml | 50 --- src/main/docker/jhipster-control-center.yml | 52 --- src/main/docker/monitoring.yml | 31 -- src/main/docker/mysql.yml | 15 - src/main/docker/prometheus/prometheus.yml | 31 -- src/main/docker/sonar.yml | 13 - .../port/api/HttpGatewayServicePort.java | 15 + .../port/api/SampleEntityServicePort.java | 1 - .../port/spi/HttpGatewayPersistencePort.java | 14 + .../domain/service/HttpGatewayService.java | 36 +++ .../rest/gateway/FullResponseBuilder.java | 37 +++ .../springboot/rest/gateway/HttpGateway.java | 165 ++++++++++ .../rest/gateway/ParameterStringBuilder.java | 22 ++ .../adaptor/HttpGatewayJPAAdaptor.java | 43 +++ .../infrastructure/entity/SampleEntity.java | 1 + .../rest/rest/HttpGatewayResource.java | 90 ++++++ .../springboot/rest/rest/TestResource.java | 17 + src/main/resources/config/application-dev.yml | 111 ------- .../resources/config/application-prod.yml | 133 -------- src/main/resources/config/application-tls.yml | 19 -- src/main/resources/config/application.yml | 193 ----------- src/main/resources/public/home.jsp | 16 + src/main/resources/public/index.jsp | 16 + src/main/resources/public/login.jsp | 15 + src/main/resources/public/testpost.php | 9 + src/main/resources/public/user.jsp | 12 + src/main/resources/templates/error.html | 92 ------ .../templates/mail/activationEmail.html | 20 -- .../templates/mail/creationEmail.html | 20 -- .../templates/mail/passwordResetEmail.html | 22 -- .../config/application-testcontainers.yml | 27 -- src/test/resources/config/application.yml | 114 ------- .../resources/templates/mail/testEmail.html | 1 - 39 files changed, 516 insertions(+), 1365 deletions(-) delete mode 100644 .github/workflows/gradle.yml delete mode 100644 .gitignore create mode 100644 .vscode/launch.json delete mode 100644 build.gradle delete mode 100644 src/main/docker/app.yml delete mode 100644 src/main/docker/grafana/provisioning/dashboards/dashboard.yml delete mode 100644 src/main/docker/grafana/provisioning/datasources/datasource.yml delete mode 100644 src/main/docker/jhipster-control-center.yml delete mode 100644 src/main/docker/monitoring.yml delete mode 100644 src/main/docker/mysql.yml delete mode 100644 src/main/docker/prometheus/prometheus.yml delete mode 100644 src/main/docker/sonar.yml create mode 100644 src/main/java/com/springboot/rest/domain/port/api/HttpGatewayServicePort.java create mode 100644 src/main/java/com/springboot/rest/domain/port/spi/HttpGatewayPersistencePort.java create mode 100644 src/main/java/com/springboot/rest/domain/service/HttpGatewayService.java create mode 100644 src/main/java/com/springboot/rest/gateway/FullResponseBuilder.java create mode 100644 src/main/java/com/springboot/rest/gateway/HttpGateway.java create mode 100644 src/main/java/com/springboot/rest/gateway/ParameterStringBuilder.java create mode 100644 src/main/java/com/springboot/rest/infrastructure/adaptor/HttpGatewayJPAAdaptor.java create mode 100644 src/main/java/com/springboot/rest/rest/HttpGatewayResource.java create mode 100644 src/main/java/com/springboot/rest/rest/TestResource.java delete mode 100644 src/main/resources/config/application-dev.yml delete mode 100644 src/main/resources/config/application-prod.yml delete mode 100644 src/main/resources/config/application-tls.yml delete mode 100644 src/main/resources/config/application.yml create mode 100644 src/main/resources/public/home.jsp create mode 100644 src/main/resources/public/index.jsp create mode 100644 src/main/resources/public/login.jsp create mode 100644 src/main/resources/public/testpost.php create mode 100644 src/main/resources/public/user.jsp delete mode 100644 src/main/resources/templates/error.html delete mode 100644 src/main/resources/templates/mail/activationEmail.html delete mode 100644 src/main/resources/templates/mail/creationEmail.html delete mode 100644 src/main/resources/templates/mail/passwordResetEmail.html delete mode 100644 src/test/resources/config/application-testcontainers.yml delete mode 100644 src/test/resources/config/application.yml delete mode 100644 src/test/resources/templates/mail/testEmail.html diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml deleted file mode 100644 index e1faa46..0000000 --- a/.github/workflows/gradle.yml +++ /dev/null @@ -1,44 +0,0 @@ -# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle - -name: CI - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - build: - - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - # Shallow clones should be disabled for a better relevancy of analysis - fetch-depth: 0 - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - java-version: 11 - - name: Cache Gradle packages - uses: actions/cache@v1 - with: - path: ~/.gradle/caches - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} - restore-keys: ${{ runner.os }}-gradle - - name: Cache SonarCloud packages - uses: actions/cache@v1 - with: - path: ~/.sonar/cache - key: ${{ runner.os }}-sonar - restore-keys: ${{ runner.os }}-sonar - - name: Build and analyze - run: ./gradlew build jacocoTestReport sonarqube --info - env: - # Needed to get some information about the pull request, if any - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # SonarCloud access token should be generated from https://sonarcloud.io/account/security/ - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - diff --git a/.gitignore b/.gitignore deleted file mode 100644 index a208f79..0000000 --- a/.gitignore +++ /dev/null @@ -1,35 +0,0 @@ - -# Eclipse Files -.settings/ -.project -.classpath - -# Idea Files -.idea/ -.iml/ -*.iml -*.ipr -*.iws -*.idea - -# Package Files # -*.war -*.ear - -# build dir -.gradle/ -build/ -target/ -bin/ -out/ - -# Others -hs_err_pid* -*.sw? -.#* -*# -*~ -*.sublime-* -.svn/ -*.jks -data/ diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..b8d2d84 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,8 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + ] +} \ No newline at end of file diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 12368d9..0000000 --- a/build.gradle +++ /dev/null @@ -1,302 +0,0 @@ -buildscript { - repositories { - gradlePluginPortal() - } - dependencies { - - } -} - -plugins { - id "java" - id "maven-publish" - id "idea" - id "eclipse" - id "jacoco" - id "org.springframework.boot" - id "com.google.cloud.tools.jib" - id "com.gorylenko.gradle-git-properties" - id "org.liquibase.gradle" - id "org.sonarqube" - id "io.spring.nohttp" - //jhipster-needle-gradle-plugins - JHipster will add additional gradle plugins here -} - -group = "com.springboot.rest" -version = "0.0.1-SNAPSHOT" - -description = "" - -sourceCompatibility=1.8 -targetCompatibility=1.8 -assert System.properties["java.specification.version"] == "1.8" || "1.9" || "10" || "11" || "12" || "13" || "14" || "15" || "16" - -apply from: "gradle/docker.gradle" -apply from: "gradle/sonar.gradle" -//jhipster-needle-gradle-apply-from - JHipster will add additional gradle scripts to be applied here -apply plugin: "eclipse" - -if (project.hasProperty("prod") || project.hasProperty("gae")) { - apply from: "gradle/profile_prod.gradle" -} else { - apply from: "gradle/profile_dev.gradle" -} - -if (project.hasProperty("war")) { - apply from: "gradle/war.gradle" -} - -if (project.hasProperty("gae")) { - apply plugin: 'maven' - apply plugin: 'org.springframework.boot.experimental.thin-launcher' - apply plugin: 'io.spring.dependency-management' - - dependencyManagement { - imports { - mavenBom "tech.jhipster:jhipster-dependencies:${jhipsterDependenciesVersion}" - } - } - appengineStage.dependsOn thinResolve -} - - -idea { - module { - excludeDirs += files("node_modules") - } -} - -eclipse { - sourceSets { - main { - java { - srcDirs += ["build/generated/sources/annotationProcessor/java/main"] - } - } - } -} - -defaultTasks "bootRun" - -springBoot { - mainClassName = "com.springboot.rest.BasicSampleApp" -} - -test { - useJUnitPlatform() - exclude "**/*IT*", "**/*IntTest*" - testLogging { - events 'FAILED', 'SKIPPED' - } - jvmArgs += '-Djava.security.egd=file:/dev/./urandom -Xmx256m' - // uncomment if the tests reports are not generated - // see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484 - // ignoreFailures true - reports.html.enabled = false -} - -task integrationTest(type: Test) { - useJUnitPlatform() - description = "Execute integration tests." - group = "verification" - include "**/*IT*", "**/*IntTest*" - testLogging { - events 'FAILED', 'SKIPPED' - } - jvmArgs += '-Djava.security.egd=file:/dev/./urandom -Xmx256m' - if (project.hasProperty('testcontainers')) { - environment 'spring.profiles.active', 'testcontainers' - } - - // uncomment if the tests reports are not generated - // see https://github.com/jhipster/generator-jhipster/pull/2771 and https://github.com/jhipster/generator-jhipster/pull/4484 - // ignoreFailures true - reports.html.enabled = false -} - -check.dependsOn integrationTest -task testReport(type: TestReport) { - destinationDir = file("$buildDir/reports/tests") - reportOn test -} - -task integrationTestReport(type: TestReport) { - destinationDir = file("$buildDir/reports/tests") - reportOn integrationTest -} - -if (!project.hasProperty("runList")) { - project.ext.runList = "main" -} - -project.ext.diffChangelogFile = "src/main/resources/config/liquibase/changelog/" + new Date().format("yyyyMMddHHmmss") + "_changelog.xml" - -liquibase { - activities { - main { - driver "com.mysql.cj.jdbc.Driver" - url "jdbc:mysql://localhost:3306/basicSample" - username "root" - password "admin" - - changeLogFile "src/main/resources/config/liquibase/master.xml" - defaultSchemaName "basicSample" - logLevel "debug" - classpath "src/main/resources/" - } - diffLog { - driver "com.mysql.cj.jdbc.Driver" - url "jdbc:mysql://localhost:3306/basicSample" - username "root" - password "admin" - - changeLogFile project.ext.diffChangelogFile - referenceUrl "hibernate:spring:com.springboot.rest.domain?dialect=org.hibernate.dialect.MySQL8Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy" - defaultSchemaName "basicSample" - logLevel "debug" - classpath "$buildDir/classes/java/main" - } - } - - runList = project.ext.runList -} - -gitProperties { - failOnNoGitDirectory = false - keys = ["git.branch", "git.commit.id.abbrev", "git.commit.id.describe"] -} - -checkstyle { - toolVersion "${checkstyleVersion}" - configFile file("checkstyle.xml") - checkstyleTest.enabled = false -} -nohttp { - source.include "build.gradle", "README.md" -} - -configurations { - providedRuntime - implementation.exclude module: "spring-boot-starter-tomcat" - all { - resolutionStrategy { - // Inherited version from Spring Boot can't be used because of regressions: - // To be removed as soon as spring-boot use the same version - force 'org.liquibase:liquibase-core:4.3.5' - } - } -} - -repositories { - mavenLocal() - mavenCentral() - //jhipster-needle-gradle-repositories - JHipster will add additional repositories -} - -dependencies { - // import JHipster dependencies BOM - if (!project.hasProperty("gae")) { - implementation platform("tech.jhipster:jhipster-dependencies:${jhipsterDependenciesVersion}") - } - - // Use ", version: jhipsterDependenciesVersion, changing: true" if you want - // to use a SNAPSHOT release instead of a stable release - implementation group: "tech.jhipster", name: "jhipster-framework" - implementation "javax.annotation:javax.annotation-api" - implementation "org.springframework.boot:spring-boot-starter-cache" - implementation "io.dropwizard.metrics:metrics-core" - implementation "io.micrometer:micrometer-registry-prometheus" - implementation "com.fasterxml.jackson.datatype:jackson-datatype-hppc" - implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" - implementation "com.fasterxml.jackson.module:jackson-module-jaxb-annotations" - implementation "com.fasterxml.jackson.datatype:jackson-datatype-hibernate5" - implementation "com.fasterxml.jackson.core:jackson-annotations" - implementation "com.fasterxml.jackson.core:jackson-databind" - implementation "javax.cache:cache-api" - implementation "org.hibernate:hibernate-core" - implementation "com.zaxxer:HikariCP" - implementation "org.apache.commons:commons-lang3" - implementation "javax.transaction:javax.transaction-api" - implementation "org.ehcache:ehcache" - implementation "org.hibernate:hibernate-jcache" - implementation "org.hibernate:hibernate-entitymanager" - implementation "org.hibernate.validator:hibernate-validator" - implementation "org.liquibase:liquibase-core" - liquibaseRuntime "org.liquibase:liquibase-core" - liquibaseRuntime "org.liquibase.ext:liquibase-hibernate5:${liquibaseHibernate5Version}" - liquibaseRuntime sourceSets.main.compileClasspath - implementation "org.springframework.boot:spring-boot-loader-tools" - implementation "org.springframework.boot:spring-boot-starter-mail" - implementation "org.springframework.boot:spring-boot-starter-logging" - implementation "org.springframework.boot:spring-boot-starter-actuator" - implementation "org.springframework.boot:spring-boot-starter-data-jpa" - testImplementation "org.testcontainers:mysql" - implementation "org.springframework.boot:spring-boot-starter-security" - implementation ("org.springframework.boot:spring-boot-starter-web") { - exclude module: "spring-boot-starter-tomcat" - } - implementation "org.springframework.boot:spring-boot-starter-undertow" - implementation "org.springframework.boot:spring-boot-starter-thymeleaf" - implementation "org.zalando:problem-spring-web" - implementation "org.springframework.security:spring-security-config" - implementation "org.springframework.security:spring-security-data" - implementation "org.springframework.security:spring-security-web" - implementation "io.jsonwebtoken:jjwt-api" - if (!project.hasProperty("gae")) { - runtimeOnly "io.jsonwebtoken:jjwt-impl" - runtimeOnly "io.jsonwebtoken:jjwt-jackson" - } else { - implementation "io.jsonwebtoken:jjwt-impl" - implementation "io.jsonwebtoken:jjwt-jackson" - } - implementation ("io.springfox:springfox-oas") - implementation ("io.springfox:springfox-swagger2") - implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.5.10' - implementation "io.springfox:springfox-bean-validators" - implementation "mysql:mysql-connector-java" - liquibaseRuntime "mysql:mysql-connector-java" - implementation "org.mapstruct:mapstruct:${mapstructVersion}" - annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" - annotationProcessor "org.hibernate:hibernate-jpamodelgen:${hibernateVersion}" - annotationProcessor "org.glassfish.jaxb:jaxb-runtime:${jaxbRuntimeVersion}" - annotationProcessor "org.springframework.boot:spring-boot-configuration-processor:${springBootVersion}" - testImplementation "org.springframework.boot:spring-boot-starter-test" - testImplementation "org.springframework.security:spring-security-test" - testImplementation "org.springframework.boot:spring-boot-test" - testImplementation "com.tngtech.archunit:archunit-junit5-api:${archunitJunit5Version}" - testRuntimeOnly "com.tngtech.archunit:archunit-junit5-engine:${archunitJunit5Version}" - testImplementation "com.h2database:h2" - developmentOnly "org.springframework.boot:spring-boot-devtools:${springBootVersion}" - //jhipster-needle-gradle-dependency - JHipster will add additional dependencies here - // https://mvnrepository.com/artifact/org.modelmapper/modelmapper - implementation "org.modelmapper:modelmapper:2.4.4" - - compileOnly 'org.projectlombok:lombok:1.18.22' - annotationProcessor 'org.projectlombok:lombok:1.18.22' - - testCompileOnly 'org.projectlombok:lombok:1.18.22' - testAnnotationProcessor 'org.projectlombok:lombok:1.18.22' -} - -if (project.hasProperty("gae")) { - task createPom { - def basePath = 'build/resources/main/META-INF/maven' - doLast { - pom { - withXml(dependencyManagement.pomConfigurer) - }.writeTo("${basePath}/${project.group}/${project.name}/pom.xml") - } - } - bootJar.dependsOn = [createPom] -} - -task cleanResources(type: Delete) { - delete "build/resources" -} - -wrapper { - gradleVersion = "7.0.2" -} - -compileJava.dependsOn processResources -processResources.dependsOn bootBuildInfo diff --git a/src/main/docker/app.yml b/src/main/docker/app.yml deleted file mode 100644 index 0b94d58..0000000 --- a/src/main/docker/app.yml +++ /dev/null @@ -1,28 +0,0 @@ -# This configuration is intended for development purpose, it's **your** responsibility to harden it for production -version: '3.8' -services: - basicsample-app: - image: basicsample - environment: - - _JAVA_OPTIONS=-Xmx512m -Xms256m - - SPRING_PROFILES_ACTIVE=prod,api-docs - - MANAGEMENT_METRICS_EXPORT_PROMETHEUS_ENABLED=true - - SPRING_DATASOURCE_URL=jdbc:mysql://basicsample-mysql:3306/basicsample?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC&createDatabaseIfNotExist=true - - SPRING_LIQUIBASE_URL=jdbc:mysql://basicsample-mysql:3306/basicsample?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC&createDatabaseIfNotExist=true - - JHIPSTER_SLEEP=30 # gives time for other services to boot before the application - # If you want to expose these ports outside your dev PC, - # remove the "127.0.0.1:" prefix - ports: - - 127.0.0.1:8080:8080 - basicsample-mysql: - image: mysql:8.0.25 - # volumes: - # - ~/volumes/jhipster/basicSample/mysql/:/var/lib/mysql/ - environment: - - MYSQL_ALLOW_EMPTY_PASSWORD=yes - - MYSQL_DATABASE=basicsample - # If you want to expose these ports outside your dev PC, - # remove the "127.0.0.1:" prefix - ports: - - 127.0.0.1:3306:3306 - command: mysqld --lower_case_table_names=1 --skip-ssl --character_set_server=utf8mb4 --explicit_defaults_for_timestamp diff --git a/src/main/docker/grafana/provisioning/dashboards/dashboard.yml b/src/main/docker/grafana/provisioning/dashboards/dashboard.yml deleted file mode 100644 index 4817a83..0000000 --- a/src/main/docker/grafana/provisioning/dashboards/dashboard.yml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: 1 - -providers: - - name: 'Prometheus' - orgId: 1 - folder: '' - type: file - disableDeletion: false - editable: true - options: - path: /etc/grafana/provisioning/dashboards diff --git a/src/main/docker/grafana/provisioning/datasources/datasource.yml b/src/main/docker/grafana/provisioning/datasources/datasource.yml deleted file mode 100644 index 57b2bb3..0000000 --- a/src/main/docker/grafana/provisioning/datasources/datasource.yml +++ /dev/null @@ -1,50 +0,0 @@ -apiVersion: 1 - -# list of datasources that should be deleted from the database -deleteDatasources: - - name: Prometheus - orgId: 1 - -# list of datasources to insert/update depending -# whats available in the database -datasources: - # name of the datasource. Required - - name: Prometheus - # datasource type. Required - type: prometheus - # access mode. direct or proxy. Required - access: proxy - # org id. will default to orgId 1 if not specified - orgId: 1 - # url - # On MacOS, replace localhost by host.docker.internal - url: http://localhost:9090 - # database password, if used - password: - # database user, if used - user: - # database name, if used - database: - # enable/disable basic auth - basicAuth: false - # basic auth username - basicAuthUser: admin - # basic auth password - basicAuthPassword: admin - # enable/disable with credentials headers - withCredentials: - # mark as default datasource. Max one per org - isDefault: true - # fields that will be converted to json and stored in json_data - jsonData: - graphiteVersion: '1.1' - tlsAuth: false - tlsAuthWithCACert: false - # json object of data that will be encrypted. - secureJsonData: - tlsCACert: '...' - tlsClientCert: '...' - tlsClientKey: '...' - version: 1 - # allow users to edit datasources from the UI. - editable: true diff --git a/src/main/docker/jhipster-control-center.yml b/src/main/docker/jhipster-control-center.yml deleted file mode 100644 index b2399f3..0000000 --- a/src/main/docker/jhipster-control-center.yml +++ /dev/null @@ -1,52 +0,0 @@ -## How to use JHCC docker compose -# To allow JHCC to reach JHipster application from a docker container note that we set the host as host.docker.internal -# To reach the application from a browser, you need to add '127.0.0.1 host.docker.internal' to your hosts file. -### Discovery mode -# JHCC support 3 kinds of discovery mode: Consul, Eureka and static -# In order to use one, please set SPRING_PROFILES_ACTIVE to one (and only one) of this values: consul,eureka,static -### Discovery properties -# According to the discovery mode choose as Spring profile, you have to set the right properties -# please note that current properties are set to run JHCC with default values, personalize them if needed -# and remove those from other modes. You can only have one mode active. -#### Eureka -# - EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE=http://admin:admin@host.docker.internal:8761/eureka/ -#### Consul -# - SPRING_CLOUD_CONSUL_HOST=host.docker.internal -# - SPRING_CLOUD_CONSUL_PORT=8500 -#### Static -# Add instances to "MyApp" -# - SPRING_CLOUD_DISCOVERY_CLIENT_SIMPLE_INSTANCES_MYAPP_0_URI=http://host.docker.internal:8081 -# - SPRING_CLOUD_DISCOVERY_CLIENT_SIMPLE_INSTANCES_MYAPP_1_URI=http://host.docker.internal:8082 -# Or add a new application named MyNewApp -# - SPRING_CLOUD_DISCOVERY_CLIENT_SIMPLE_INSTANCES_MYNEWAPP_0_URI=http://host.docker.internal:8080 -# This configuration is intended for development purpose, it's **your** responsibility to harden it for production - -#### IMPORTANT -# If you choose Consul or Eureka mode: -# Do not forget to remove the prefix "127.0.0.1" in front of their port in order to expose them. -# This is required because JHCC need to communicate with Consul or Eureka. -# - In Consul mode, the ports are in the consul.yml file. -# - In Eureka mode, the ports are in the jhipster-registry.yml file. - -version: '3.8' -services: - jhipster-control-center: - image: 'jhipster/jhipster-control-center:v0.5.0' - command: - - /bin/sh - - -c - # Patch /etc/hosts to support resolving host.docker.internal to the internal IP address used by the host in all OSes - - echo "`ip route | grep default | cut -d ' ' -f3` host.docker.internal" | tee -a /etc/hosts > /dev/null && java -jar /jhipster-control-center.jar - environment: - - _JAVA_OPTIONS=-Xmx512m -Xms256m - - SPRING_PROFILES_ACTIVE=prod,api-docs,static - - JHIPSTER_SLEEP=30 # gives time for other services to boot before the application - - SPRING_SECURITY_USER_PASSWORD=admin - # The token should have the same value than the one declared in you Spring configuration under the jhipster.security.authentication.jwt.base64-secret configuration's entry - - JHIPSTER_SECURITY_AUTHENTICATION_JWT_BASE64_SECRET=MDllZDU1YzRkZmUxYWM1MWVjN2JjMzA0NDVhNmViNGZmYjgyN2NmZGRjN2VkZjNkYjFlYTQ3NGY4MGY3N2Q3NDkxNzBiYzYzZjZmOWQwNjZiMGNiYmRlMGZjZGE5NWQwOTIwZjY3ZThlMjY0YTk4YjNiZGViNzZjMGQ5M2MwYjQ= - - SPRING_CLOUD_DISCOVERY_CLIENT_SIMPLE_INSTANCES_BASICSAMPLE_0_URI=http://host.docker.internal:8080 - - LOGGING_FILE_NAME=/tmp/jhipster-control-center.log - # If you want to expose these ports outside your dev PC, - # remove the "127.0.0.1:" prefix - ports: - - 127.0.0.1:7419:7419 diff --git a/src/main/docker/monitoring.yml b/src/main/docker/monitoring.yml deleted file mode 100644 index b90ae10..0000000 --- a/src/main/docker/monitoring.yml +++ /dev/null @@ -1,31 +0,0 @@ -# This configuration is intended for development purpose, it's **your** responsibility to harden it for production -version: '3.8' -services: - basicsample-prometheus: - image: prom/prometheus:v2.27.1 - volumes: - - ./prometheus/:/etc/prometheus/ - command: - - '--config.file=/etc/prometheus/prometheus.yml' - # If you want to expose these ports outside your dev PC, - # remove the "127.0.0.1:" prefix - ports: - - 127.0.0.1:9090:9090 - # On MacOS, remove next line and replace localhost by host.docker.internal in prometheus/prometheus.yml and - # grafana/provisioning/datasources/datasource.yml - network_mode: 'host' # to test locally running service - basicsample-grafana: - image: grafana/grafana:8.0.1 - volumes: - - ./grafana/provisioning/:/etc/grafana/provisioning/ - environment: - - GF_SECURITY_ADMIN_PASSWORD=admin - - GF_USERS_ALLOW_SIGN_UP=false - - GF_INSTALL_PLUGINS=grafana-piechart-panel - # If you want to expose these ports outside your dev PC, - # remove the "127.0.0.1:" prefix - ports: - - 127.0.0.1:3000:3000 - # On MacOS, remove next line and replace localhost by host.docker.internal in prometheus/prometheus.yml and - # grafana/provisioning/datasources/datasource.yml - network_mode: 'host' # to test locally running service diff --git a/src/main/docker/mysql.yml b/src/main/docker/mysql.yml deleted file mode 100644 index 6027f04..0000000 --- a/src/main/docker/mysql.yml +++ /dev/null @@ -1,15 +0,0 @@ -# This configuration is intended for development purpose, it's **your** responsibility to harden it for production -version: '3.8' -services: - basicsample-mysql: - image: mysql:8.0.25 - # volumes: - # - ~/volumes/jhipster/basicSample/mysql/:/var/lib/mysql/ - environment: - - MYSQL_ALLOW_EMPTY_PASSWORD=yes - - MYSQL_DATABASE=basicsample - # If you want to expose these ports outside your dev PC, - # remove the "127.0.0.1:" prefix - ports: - - 127.0.0.1:3306:3306 - command: mysqld --lower_case_table_names=1 --skip-ssl --character_set_server=utf8mb4 --explicit_defaults_for_timestamp diff --git a/src/main/docker/prometheus/prometheus.yml b/src/main/docker/prometheus/prometheus.yml deleted file mode 100644 index b370a2f..0000000 --- a/src/main/docker/prometheus/prometheus.yml +++ /dev/null @@ -1,31 +0,0 @@ -# Sample global config for monitoring JHipster applications -global: - scrape_interval: 15s # By default, scrape targets every 15 seconds. - evaluation_interval: 15s # By default, scrape targets every 15 seconds. - # scrape_timeout is set to the global default (10s). - - # Attach these labels to any time series or alerts when communicating with - # external systems (federation, remote storage, Alertmanager). - external_labels: - monitor: 'jhipster' - -# A scrape configuration containing exactly one endpoint to scrape: -# Here it's Prometheus itself. -scrape_configs: - # The job name is added as a label `job=` to any timeseries scraped from this config. - - job_name: 'prometheus' - - # Override the global default and scrape targets from this job every 5 seconds. - scrape_interval: 5s - - # scheme defaults to 'http' enable https in case your application is server via https - #scheme: https - # basic auth is not needed by default. See https://www.jhipster.tech/monitoring/#configuring-metrics-forwarding for details - #basic_auth: - # username: admin - # password: admin - metrics_path: /management/prometheus - static_configs: - - targets: - # On MacOS, replace localhost by host.docker.internal - - localhost:8080 diff --git a/src/main/docker/sonar.yml b/src/main/docker/sonar.yml deleted file mode 100644 index 73e88cc..0000000 --- a/src/main/docker/sonar.yml +++ /dev/null @@ -1,13 +0,0 @@ -# This configuration is intended for development purpose, it's **your** responsibility to harden it for production -version: '3.8' -services: - basicsample-sonar: - image: sonarqube:8.9.1-community - # Authentication is turned off for out of the box experience while trying out SonarQube - # For real use cases delete sonar.forceAuthentication variable or set sonar.forceAuthentication=true - environment: - - sonar.forceAuthentication=false - # If you want to expose these ports outside your dev PC, - # remove the "127.0.0.1:" prefix - ports: - - 127.0.0.1:9001:9000 diff --git a/src/main/java/com/springboot/rest/domain/port/api/HttpGatewayServicePort.java b/src/main/java/com/springboot/rest/domain/port/api/HttpGatewayServicePort.java new file mode 100644 index 0000000..c678393 --- /dev/null +++ b/src/main/java/com/springboot/rest/domain/port/api/HttpGatewayServicePort.java @@ -0,0 +1,15 @@ +package com.springboot.rest.domain.port.api; + + +import java.io.IOException; +import java.util.Map; + + +public interface HttpGatewayServicePort { + + String performGHR(Map httpHeader) throws IOException; + + String performPHR(Map httpHeader) throws IOException; + + +} diff --git a/src/main/java/com/springboot/rest/domain/port/api/SampleEntityServicePort.java b/src/main/java/com/springboot/rest/domain/port/api/SampleEntityServicePort.java index 8d0a37f..0e42efc 100644 --- a/src/main/java/com/springboot/rest/domain/port/api/SampleEntityServicePort.java +++ b/src/main/java/com/springboot/rest/domain/port/api/SampleEntityServicePort.java @@ -6,7 +6,6 @@ import java.util.List; import java.util.Optional; -import org.springframework.stereotype.Service; public interface SampleEntityServicePort { diff --git a/src/main/java/com/springboot/rest/domain/port/spi/HttpGatewayPersistencePort.java b/src/main/java/com/springboot/rest/domain/port/spi/HttpGatewayPersistencePort.java new file mode 100644 index 0000000..fa92290 --- /dev/null +++ b/src/main/java/com/springboot/rest/domain/port/spi/HttpGatewayPersistencePort.java @@ -0,0 +1,14 @@ +package com.springboot.rest.domain.port.spi; + + +import java.io.IOException; +import java.util.Map; + + +public interface HttpGatewayPersistencePort { + + String performGHR(Map httpHeader) throws IOException; + + String performPHR(Map httpHeader) throws IOException; + +} \ No newline at end of file diff --git a/src/main/java/com/springboot/rest/domain/service/HttpGatewayService.java b/src/main/java/com/springboot/rest/domain/service/HttpGatewayService.java new file mode 100644 index 0000000..c929197 --- /dev/null +++ b/src/main/java/com/springboot/rest/domain/service/HttpGatewayService.java @@ -0,0 +1,36 @@ +package com.springboot.rest.domain.service; + +import com.springboot.rest.domain.port.api.HttpGatewayServicePort; +import com.springboot.rest.domain.port.spi.HttpGatewayPersistencePort; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.io.IOException; +import java.util.Map; + + +@Service +@Transactional +public class HttpGatewayService implements HttpGatewayServicePort { + + + private final HttpGatewayPersistencePort httpGatewayPersistencePort; + + public HttpGatewayService(HttpGatewayPersistencePort httpGatewayPersistencePort) { + this.httpGatewayPersistencePort = httpGatewayPersistencePort; + } + + @Override + public String performGHR(Map httpHeader) throws IOException { + + return httpGatewayPersistencePort.performGHR(httpHeader); + } + + @Override + public String performPHR(Map httpHeader) throws IOException { + + return httpGatewayPersistencePort.performPHR(httpHeader); + } + + +} \ No newline at end of file diff --git a/src/main/java/com/springboot/rest/gateway/FullResponseBuilder.java b/src/main/java/com/springboot/rest/gateway/FullResponseBuilder.java new file mode 100644 index 0000000..bcdfa3b --- /dev/null +++ b/src/main/java/com/springboot/rest/gateway/FullResponseBuilder.java @@ -0,0 +1,37 @@ +package com.springboot.rest.gateway; + +import java.net.HttpURLConnection; +import java.util.Iterator; +import java.util.List; +import java.io.IOException; + +public class FullResponseBuilder { + public static StringBuilder getFullResponse(HttpURLConnection con) throws IOException { + StringBuilder fullResponseBuilder = new StringBuilder(); + + // read status and message + fullResponseBuilder.append(con.getResponseCode()) + .append(" ") + .append(con.getResponseMessage()) + .append("\n"); + + // read headers + con.getHeaderFields().entrySet().stream().filter(entry -> entry.getKey() != null).forEach(entry -> { + fullResponseBuilder.append(entry.getKey()).append(": "); + List headerValues = entry.getValue(); + Iterator it = headerValues.iterator(); + if (it.hasNext()) { + fullResponseBuilder.append(it.next()); + while (it.hasNext()) { + fullResponseBuilder.append(", ").append(it.next()); + } + } + fullResponseBuilder.append("\n"); + }); + + // read response content + + + return fullResponseBuilder; + } +} diff --git a/src/main/java/com/springboot/rest/gateway/HttpGateway.java b/src/main/java/com/springboot/rest/gateway/HttpGateway.java new file mode 100644 index 0000000..3352c1a --- /dev/null +++ b/src/main/java/com/springboot/rest/gateway/HttpGateway.java @@ -0,0 +1,165 @@ +package com.springboot.rest.gateway; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +import org.springframework.stereotype.Service; + +@Service +public class HttpGateway { + + private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"; + + private static final String params = "hero=IronMan&power=BeingRich"; + + public String performGETHttpReq( + String acceptHeader, String authHeader, String urlHeader) throws IOException { + Map httpHeader = new HashMap<>(); + httpHeader.put("Accept", acceptHeader); + httpHeader.put("Auth", authHeader); + httpHeader.put("ExternalURL", urlHeader); + + // Set up the connection: creating request :--- + URL url = new URL(urlHeader + "?" + params); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestMethod("GET"); + + + // Adding request parameters :--- + Map parameters = new HashMap<>(); + parameters.put("param1", "value1"); + + // Setting Request Headers :--- + con.setRequestProperty("User-Agent", USER_AGENT); + + + // Setting the timeouts :--- + con.setConnectTimeout(5000); + con.setReadTimeout(6000); + + + // Reading the response (handling the failed requests) :--- + int status = con.getResponseCode(); + System.out.println("'GET' request to URL : " + url); + System.out.println("Response Code : " + status); + System.out.println("Response Body : "); + + Reader streamReader = null; + if(status > 299) { + streamReader = new InputStreamReader(con.getErrorStream()); + } else { + streamReader = new InputStreamReader(con.getInputStream()); + } + + // read response content + BufferedReader in = new BufferedReader(streamReader); + String inputLine; + StringBuilder content = new StringBuilder(); + while ((inputLine = in.readLine()) != null) { + content.append(inputLine); + } + in.close(); + + // print content on console + System.out.println(content.toString()); + + // Retrieve "full response" + StringBuilder fullResponseContent; + fullResponseContent = FullResponseBuilder.getFullResponse(con); + + // Add response content + fullResponseContent.append("\n"+content); + + // Perform connection disconnection + con.disconnect(); + + System.out.println("GET done.\n"); + + return fullResponseContent.toString(); + } + + + public String performPOSTHttpReq( + String acceptHeader, String authHeader, String urlHeader) throws IOException { + + Map httpHeader = new HashMap<>(); + httpHeader.put("Accept", acceptHeader); + httpHeader.put("Auth", authHeader); + httpHeader.put("ExternalURL", urlHeader); + + // Set up the connection: creating request :--- + URL url = new URL(urlHeader); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestMethod("GET"); + + + // Adding request parameters :--- + Map parameters = new HashMap<>(); + parameters.put("param1", "value1"); + + // Setting Request Headers :--- + con.setRequestProperty("User-Agent", USER_AGENT); + + con.setDoOutput(true); + DataOutputStream out = new DataOutputStream(con.getOutputStream()); +// out.writeBytes(ParameterStringBuilder.getParamsString(parameters)); + out.writeBytes(params); + out.flush(); + out.close(); + + // Setting the timeouts :--- + con.setConnectTimeout(5000); + con.setReadTimeout(6000); + + + // Reading the response (handling the failed requests) :--- + int status = con.getResponseCode(); + System.out.println("'POST' request to URL : " + url); + System.out.println("Response Code : " + status); + System.out.println("Response Body : "); + Reader streamReader = null; + + if(status > 299) { + streamReader = new InputStreamReader(con.getErrorStream()); + } else { + streamReader = new InputStreamReader(con.getInputStream()); + } + + // read response content + BufferedReader in = new BufferedReader(streamReader); + String inputLine; + StringBuilder content = new StringBuilder(); + while ((inputLine = in.readLine()) != null) { + content.append(inputLine); + } + in.close(); + + // print content on console + System.out.println(content.toString()); + + // Retrieve "full response" + StringBuilder fullResponseContent; + fullResponseContent = FullResponseBuilder.getFullResponse(con); + + // Add response content + fullResponseContent.append("\n"+content); + + // Perform connection disconnection + con.disconnect(); + + System.out.println("POST done.\n"); + + return fullResponseContent.toString(); + + } +} diff --git a/src/main/java/com/springboot/rest/gateway/ParameterStringBuilder.java b/src/main/java/com/springboot/rest/gateway/ParameterStringBuilder.java new file mode 100644 index 0000000..64053f2 --- /dev/null +++ b/src/main/java/com/springboot/rest/gateway/ParameterStringBuilder.java @@ -0,0 +1,22 @@ +package com.springboot.rest.gateway; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.Map; + +public class ParameterStringBuilder { + public static String getParamsString(Map params) throws UnsupportedEncodingException { + StringBuilder result = new StringBuilder(); + + for (Map.Entry entry : params.entrySet()) { + result.append(URLEncoder.encode(entry.getKey(), "UTF-8")); + result.append("="); + result.append(URLEncoder.encode(entry.getValue(), "UTF-8")); + result.append("&"); + } + + String resultString = result.toString(); + return resultString.length() > 0 ? resultString.substring(0, resultString.length() - 1) : resultString; + } + +} diff --git a/src/main/java/com/springboot/rest/infrastructure/adaptor/HttpGatewayJPAAdaptor.java b/src/main/java/com/springboot/rest/infrastructure/adaptor/HttpGatewayJPAAdaptor.java new file mode 100644 index 0000000..ed6a8bf --- /dev/null +++ b/src/main/java/com/springboot/rest/infrastructure/adaptor/HttpGatewayJPAAdaptor.java @@ -0,0 +1,43 @@ +package com.springboot.rest.infrastructure.adaptor; + +import com.springboot.rest.domain.port.spi.HttpGatewayPersistencePort; +import com.springboot.rest.gateway.HttpGateway; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.io.IOException; +import java.util.Map; + +@Service +@Transactional +public class HttpGatewayJPAAdaptor implements HttpGatewayPersistencePort { + + private final HttpGateway httpGateway; + + public HttpGatewayJPAAdaptor(HttpGateway httpGateway) { + this.httpGateway = httpGateway; + } + + + // Implementations + + @Override + public String performGHR(Map httpHeader) throws IOException { + + return httpGateway.performGETHttpReq(httpHeader.get("Accept") + , httpHeader.get("Auth") + , httpHeader.get("ExternalURL")); + } + + @Override + public String performPHR(Map httpHeader) throws IOException { + + return httpGateway.performPOSTHttpReq(httpHeader.get("Accept") + , httpHeader.get("Auth") + , httpHeader.get("ExternalURL")); + } + + +} \ No newline at end of file diff --git a/src/main/java/com/springboot/rest/infrastructure/entity/SampleEntity.java b/src/main/java/com/springboot/rest/infrastructure/entity/SampleEntity.java index 8c964b4..2d13352 100644 --- a/src/main/java/com/springboot/rest/infrastructure/entity/SampleEntity.java +++ b/src/main/java/com/springboot/rest/infrastructure/entity/SampleEntity.java @@ -3,6 +3,7 @@ import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; +import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/springboot/rest/rest/HttpGatewayResource.java b/src/main/java/com/springboot/rest/rest/HttpGatewayResource.java new file mode 100644 index 0000000..c195917 --- /dev/null +++ b/src/main/java/com/springboot/rest/rest/HttpGatewayResource.java @@ -0,0 +1,90 @@ +package com.springboot.rest.rest; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.springboot.rest.domain.port.api.HttpGatewayServicePort; +import com.springboot.rest.domain.port.api.SampleEntityServicePort; + +@RestController +@RequestMapping("/httpreq") +public class HttpGatewayResource { + + private final Logger log = LoggerFactory.getLogger(HttpGatewayResource.class); + + private static final String accept = "Accept"; + + @Value("${jhipster.clientApp.name}") + private String applicationName; + + private final HttpGatewayServicePort httpGatewayServicePort; + public HttpGatewayResource(HttpGatewayServicePort httpGatewayServicePort) { + this.httpGatewayServicePort = httpGatewayServicePort; + } + + + // API calls' methods + + @GetMapping("/message") + public String message() { + return "Message from XXXXXXXXXXX HttpGatewayResource......"; + } + + @PostMapping("/testHR") + public ResponseEntity> testHttpReq( + @RequestHeader(value=accept) String acceptHeader, + @RequestHeader(value="Auth") String authHeader + ) { + Map returnValue = new HashMap<>(); + returnValue.put(accept, acceptHeader); + returnValue.put("Auth", authHeader); + + return ResponseEntity.status(HttpStatus.OK).body(returnValue); + } + + @PostMapping("/getHR") + public ResponseEntity createGETHttpReq( + @RequestHeader(value=accept) String acceptHeader, + @RequestHeader(value="Auth") String authHeader, + @RequestHeader(value="ExternalURL") String urlHeader + ) throws IOException { + + Map returnValue = new HashMap<>(); + returnValue.put(accept, acceptHeader); + returnValue.put("Auth", authHeader); + returnValue.put("ExternalURL", urlHeader); + + String httpHeader = httpGatewayServicePort.performGHR(returnValue); + + return ResponseEntity.status(HttpStatus.OK).body(httpHeader); + } + + @PostMapping("/postHR") + public ResponseEntity createPOSTHttpReq( + @RequestHeader(value=accept) String acceptHeader, + @RequestHeader(value="Auth") String authHeader, + @RequestHeader(value="ExternalURL") String urlHeader + ) throws IOException { + + Map returnValue = new HashMap<>(); + returnValue.put(accept, acceptHeader); + returnValue.put("Auth", authHeader); + returnValue.put("ExternalURL", urlHeader); + + String httpHeader = httpGatewayServicePort.performPHR(returnValue); + + return ResponseEntity.status(HttpStatus.OK).body(httpHeader); + } +} diff --git a/src/main/java/com/springboot/rest/rest/TestResource.java b/src/main/java/com/springboot/rest/rest/TestResource.java new file mode 100644 index 0000000..df0daa2 --- /dev/null +++ b/src/main/java/com/springboot/rest/rest/TestResource.java @@ -0,0 +1,17 @@ +package com.springboot.rest.rest; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/test") +public class TestResource { + + @GetMapping("/message") + public String message() { + return "Testing..........###\nTest2..........\ntest3...........#####"; + } + + +} diff --git a/src/main/resources/config/application-dev.yml b/src/main/resources/config/application-dev.yml deleted file mode 100644 index f0f0515..0000000 --- a/src/main/resources/config/application-dev.yml +++ /dev/null @@ -1,111 +0,0 @@ -# =================================================================== -# Spring Boot configuration for the "dev" profile. -# -# This configuration overrides the application.yml file. -# -# More information on profiles: https://www.jhipster.tech/profiles/ -# More information on configuration properties: https://www.jhipster.tech/common-application-properties/ -# =================================================================== - -# =================================================================== -# Standard Spring Boot properties. -# Full reference is available at: -# http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html -# =================================================================== - -logging: - level: - ROOT: DEBUG - tech.jhipster: DEBUG - org.hibernate.SQL: DEBUG - com.springboot.rest: DEBUG - -spring: - devtools: - restart: - enabled: true - additional-exclude: static/** - livereload: - enabled: false # we use Webpack dev server + BrowserSync for livereload - jackson: - serialization: - indent-output: true - datasource: - type: com.zaxxer.hikari.HikariDataSource - url: jdbc:mysql://localhost:3306/basicSample?allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC&createDatabaseIfNotExist=true - username: root - password: admin - hikari: - poolName: Hikari - auto-commit: false - data-source-properties: - cachePrepStmts: true - prepStmtCacheSize: 250 - prepStmtCacheSqlLimit: 2048 - useServerPrepStmts: true - jpa: - generate-ddl: true - # test - liquibase: - # Remove 'faker' if you do not want the sample data to be loaded automatically - contexts: dev, faker - mail: - host: localhost - port: 25 - username: - password: - messages: - cache-duration: PT1S # 1 second, see the ISO 8601 standard - thymeleaf: - cache: false - -server: - port: 8080 - -# =================================================================== -# JHipster specific properties -# -# Full reference is available at: https://www.jhipster.tech/common-application-properties/ -# =================================================================== - -jhipster: - cache: # Cache configuration - ehcache: # Ehcache configuration - time-to-live-seconds: 3600 # By default objects stay 1 hour in the cache - max-entries: 100 # Number of objects in each cache entry - # CORS is only enabled by default with the "dev" profile - cors: - # Allow Ionic for JHipster by default (* no longer allowed in Spring Boot 2.4+) - allowed-origins: 'http://localhost:8100,http://localhost:9000' - allowed-methods: '*' - allowed-headers: '*' - exposed-headers: 'Authorization,Link,X-Total-Count,X-${jhipster.clientApp.name}-alert,X-${jhipster.clientApp.name}-error,X-${jhipster.clientApp.name}-params' - allow-credentials: true - max-age: 1800 - security: - authentication: - jwt: - # This token must be encoded using Base64 and be at least 256 bits long (you can type `openssl rand -base64 64` on your command line to generate a 512 bits one) - base64-secret: MDllZDU1YzRkZmUxYWM1MWVjN2JjMzA0NDVhNmViNGZmYjgyN2NmZGRjN2VkZjNkYjFlYTQ3NGY4MGY3N2Q3NDkxNzBiYzYzZjZmOWQwNjZiMGNiYmRlMGZjZGE5NWQwOTIwZjY3ZThlMjY0YTk4YjNiZGViNzZjMGQ5M2MwYjQ= - # Token is valid 24 hours - token-validity-in-seconds: 86400 - token-validity-in-seconds-for-remember-me: 2592000 - mail: # specific JHipster mail property, for standard properties see MailProperties - base-url: http://127.0.0.1:8090 - logging: - use-json-format: false # By default, logs are not in Json format - logstash: # Forward logs to logstash over a socket, used by LoggingConfiguration - enabled: false - host: localhost - port: 5000 - queue-size: 512 -# =================================================================== -# Application specific properties -# Add your own application properties here, see the ApplicationProperties class -# to have type-safe configuration, like in the JHipsterProperties above -# -# More documentation is available at: -# https://www.jhipster.tech/common-application-properties/ -# =================================================================== - -# application: \ No newline at end of file diff --git a/src/main/resources/config/application-prod.yml b/src/main/resources/config/application-prod.yml deleted file mode 100644 index 91bc4df..0000000 --- a/src/main/resources/config/application-prod.yml +++ /dev/null @@ -1,133 +0,0 @@ -# =================================================================== -# Spring Boot configuration for the "prod" profile. -# -# This configuration overrides the application.yml file. -# -# More information on profiles: https://www.jhipster.tech/profiles/ -# More information on configuration properties: https://www.jhipster.tech/common-application-properties/ -# =================================================================== - -# =================================================================== -# Standard Spring Boot properties. -# Full reference is available at: -# http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html -# =================================================================== - -server.port: 8090 - -logging: - level: - ROOT: INFO - tech.jhipster: INFO - com.springboot.rest: INFO - -management: - metrics: - export: - prometheus: - enabled: false - -spring: - devtools: - restart: - enabled: false - livereload: - enabled: false - datasource: - type: com.zaxxer.hikari.HikariDataSource - url: jdbc:mysql://localhost:3306/basicSample?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC&createDatabaseIfNotExist=true - username: root - password: achhadata - hikari: - poolName: Hikari - auto-commit: false - data-source-properties: - cachePrepStmts: true - prepStmtCacheSize: 250 - prepStmtCacheSqlLimit: 2048 - useServerPrepStmts: true - jpa: - sql: true - # Replace by 'prod, faker' to add the faker context and have sample data loaded in production - liquibase: - contexts: prod - mail: - host: localhost - port: 25 - username: - password: - thymeleaf: - cache: true - -# =================================================================== -# To enable TLS in production, generate a certificate using: -# keytool -genkey -alias basicsample -storetype PKCS12 -keyalg RSA -keysize 2048 -keystore keystore.p12 -validity 3650 -# -# You can also use Let's Encrypt: -# https://maximilian-boehm.com/hp2121/Create-a-Java-Keystore-JKS-from-Let-s-Encrypt-Certificates.htm -# -# Then, modify the server.ssl properties so your "server" configuration looks like: -# -# server: -# port: 443 -# ssl: -# key-store: classpath:config/tls/keystore.p12 -# key-store-password: password -# key-store-type: PKCS12 -# key-alias: selfsigned -# # The ciphers suite enforce the security by deactivating some old and deprecated SSL cipher, this list was tested against SSL Labs (https://www.ssllabs.com/ssltest/) -# ciphers: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 ,TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 ,TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 ,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_RSA_WITH_AES_256_CBC_SHA256,TLS_DHE_RSA_WITH_AES_256_CBC_SHA,TLS_RSA_WITH_AES_128_GCM_SHA256,TLS_RSA_WITH_AES_256_GCM_SHA384,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_256_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA,TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA,TLS_RSA_WITH_CAMELLIA_256_CBC_SHA,TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA,TLS_RSA_WITH_CAMELLIA_128_CBC_SHA -# =================================================================== -server: - port: 8090 - shutdown: graceful # see https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-graceful-shutdown - compression: - enabled: true - mime-types: text/html,text/xml,text/plain,text/css, application/javascript, application/json - min-response-size: 1024 - -# =================================================================== -# JHipster specific properties -# -# Full reference is available at: https://www.jhipster.tech/common-application-properties/ -# =================================================================== - -jhipster: - http: - cache: # Used by the CachingHttpHeadersFilter - timeToLiveInDays: 1461 - cache: # Cache configuration - ehcache: # Ehcache configuration - time-to-live-seconds: 3600 # By default objects stay 1 hour in the cache - max-entries: 1000 # Number of objects in each cache entry - security: - authentication: - jwt: - # This token must be encoded using Base64 and be at least 256 bits long (you can type `openssl rand -base64 64` on your command line to generate a 512 bits one) - # As this is the PRODUCTION configuration, you MUST change the default key, and store it securely: - # - In the JHipster Registry (which includes a Spring Cloud Config server) - # - In a separate `application-prod.yml` file, in the same folder as your executable JAR file - # - In the `JHIPSTER_SECURITY_AUTHENTICATION_JWT_BASE64_SECRET` environment variable - base64-secret: MDllZDU1YzRkZmUxYWM1MWVjN2JjMzA0NDVhNmViNGZmYjgyN2NmZGRjN2VkZjNkYjFlYTQ3NGY4MGY3N2Q3NDkxNzBiYzYzZjZmOWQwNjZiMGNiYmRlMGZjZGE5NWQwOTIwZjY3ZThlMjY0YTk4YjNiZGViNzZjMGQ5M2MwYjQ= - # Token is valid 24 hours - token-validity-in-seconds: 86400 - token-validity-in-seconds-for-remember-me: 2592000 - mail: # specific JHipster mail property, for standard properties see MailProperties - base-url: http://my-server-url-to-change # Modify according to your server's URL - logging: - use-json-format: false # By default, logs are not in Json format - logstash: # Forward logs to logstash over a socket, used by LoggingConfiguration - enabled: false - host: localhost - port: 5000 - queue-size: 512 -# =================================================================== -# Application specific properties -# Add your own application properties here, see the ApplicationProperties class -# to have type-safe configuration, like in the JHipsterProperties above -# -# More documentation is available at: -# https://www.jhipster.tech/common-application-properties/ -# =================================================================== - -# application: diff --git a/src/main/resources/config/application-tls.yml b/src/main/resources/config/application-tls.yml deleted file mode 100644 index 27c9cd8..0000000 --- a/src/main/resources/config/application-tls.yml +++ /dev/null @@ -1,19 +0,0 @@ -# =================================================================== -# Activate this profile to enable TLS and HTTP/2. -# -# JHipster has generated a self-signed certificate, which will be used to encrypt traffic. -# As your browser will not understand this certificate, you will need to import it. -# -# Another (easiest) solution with Chrome is to enable the "allow-insecure-localhost" flag -# at chrome://flags/#allow-insecure-localhost -# =================================================================== -server: - ssl: - key-store: classpath:config/tls/keystore.p12 - key-store-password: password - key-store-type: PKCS12 - key-alias: selfsigned - ciphers: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 - enabled-protocols: TLSv1.2 - http2: - enabled: true diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml deleted file mode 100644 index 2294e8a..0000000 --- a/src/main/resources/config/application.yml +++ /dev/null @@ -1,193 +0,0 @@ -# =================================================================== -# Spring Boot configuration. -# -# This configuration will be overridden by the Spring profile you use, -# for example application-dev.yml if you use the "dev" profile. -# -# More information on profiles: https://www.jhipster.tech/profiles/ -# More information on configuration properties: https://www.jhipster.tech/common-application-properties/ -# =================================================================== - -# =================================================================== -# Standard Spring Boot properties. -# Full reference is available at: -# http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html -# =================================================================== - -#server.port: 8090 - -management: - endpoints: - web: - base-path: /management - exposure: - include: - ['configprops', 'env', 'health', 'info', 'jhimetrics', 'logfile', 'loggers', 'prometheus', 'threaddump', 'caches', 'liquibase'] - endpoint: - health: - show-details: when-authorized - roles: 'ROLE_ADMIN' - probes: - enabled: true - jhimetrics: - enabled: true - info: - git: - mode: full - health: - group: - liveness: - include: livenessState - readiness: - include: readinessState,datasource - mail: - enabled: false # When using the MailService, configure an SMTP server and set this to true - metrics: - export: - # Prometheus is the default metrics backend - prometheus: - enabled: true - step: 60 - enable: - http: true - jvm: true - logback: true - process: true - system: true - distribution: - percentiles-histogram: - all: true - percentiles: - all: 0, 0.5, 0.75, 0.95, 0.99, 1.0 - tags: - application: ${spring.application.name} - web: - server: - request: - autotime: - enabled: true - -spring: - application: - name: basicSample - profiles: - # The commented value for `active` can be replaced with valid Spring profiles to load. - # Otherwise, it will be filled in by gradle when building the JAR file - # Either way, it can be overridden by `--spring.profiles.active` value passed in the commandline or `-Dspring.profiles.active` set in `JAVA_OPTS` - active: dev - group: - dev: - - dev - #- api-docs - # Uncomment to activate TLS for the dev profile - #- tls - - jmx: - enabled: false - data: - jpa: - repositories: - bootstrap-mode: deferred - jpa: - open-in-view: false - properties: - hibernate.jdbc.time_zone: UTC - hibernate.id.new_generator_mappings: true - hibernate.connection.provider_disables_autocommit: true - hibernate.cache.use_second_level_cache: true - hibernate.cache.use_query_cache: false - hibernate.generate_statistics: false - # modify batch size as necessary - hibernate.jdbc.batch_size: 25 - hibernate.order_inserts: true - hibernate.order_updates: true - hibernate.query.fail_on_pagination_over_collection_fetch: true - hibernate.query.in_clause_parameter_padding: true - hibernate: - ddl-auto: none - naming: - physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy - implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy - messages: - basename: i18n/messages - main: - allow-bean-definition-overriding: true - task: - execution: - thread-name-prefix: basic-sample-task- - pool: - core-size: 2 - max-size: 50 - queue-capacity: 10000 - scheduling: - thread-name-prefix: basic-sample-scheduling- - pool: - size: 2 - thymeleaf: - mode: HTML - output: - ansi: - console-available: true - -server: - servlet: - session: - cookie: - http-only: true - -# Properties to be exposed on the /info management endpoint -info: - # Comma separated list of profiles that will trigger the ribbon to show - display-ribbon-on-profiles: 'dev' - -# =================================================================== -# JHipster specific properties -# -# Full reference is available at: https://www.jhipster.tech/common-application-properties/ -# =================================================================== -springdoc: - swagger-ui: - disable-swagger-default-url: true - documentation: - auto-startup: false - -jhipster: - clientApp: - name: 'basicSampleApp' - # By default CORS is disabled. Uncomment to enable. - # cors: - # allowed-origins: "http://localhost:8100,http://localhost:9000" - # allowed-methods: "*" - # allowed-headers: "*" - # exposed-headers: "Authorization,Link,X-Total-Count,X-${jhipster.clientApp.name}-alert,X-${jhipster.clientApp.name}-error,X-${jhipster.clientApp.name}-params" - # allow-credentials: true - # max-age: 1800 - mail: - from: basicSample@localhost - api-docs: - default-include-pattern: ${server.servlet.context-path:}/api/.* - management-include-pattern: ${server.servlet.context-path:}/management/.* - title: basicSample API - description: basicSample API documentation - version: 0.0.1 - terms-of-service-url: - contact-name: - contact-url: - contact-email: - license: unlicensed - license-url: - security: - content-security-policy: "default-src 'self'; frame-src 'self' data:; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://storage.googleapis.com; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:" -# =================================================================== -# Application specific properties -# Add your own application properties here, see the ApplicationProperties class -# to have type-safe configuration, like in the JHipsterProperties above -# -# More documentation is available at: -# https://www.jhipster.tech/common-application-properties/ -# =================================================================== - -# application: -# There is an application.yml in test module also -user-registration: - setActivationKey: true \ No newline at end of file diff --git a/src/main/resources/public/home.jsp b/src/main/resources/public/home.jsp new file mode 100644 index 0000000..5fe0f6b --- /dev/null +++ b/src/main/resources/public/home.jsp @@ -0,0 +1,16 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@ taglib uri="https://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ page session="false" %> + + + Home + + +

+ Hello world! +

+ +

The time on the server is ${serverTime}.

+ + \ No newline at end of file diff --git a/src/main/resources/public/index.jsp b/src/main/resources/public/index.jsp new file mode 100644 index 0000000..fe6c053 --- /dev/null +++ b/src/main/resources/public/index.jsp @@ -0,0 +1,16 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Insert title here + + + +

Hello, Dear SKD!

+ +

Current date: <%= new java.util.Date() %>

+ + + \ No newline at end of file diff --git a/src/main/resources/public/login.jsp b/src/main/resources/public/login.jsp new file mode 100644 index 0000000..e586cea --- /dev/null +++ b/src/main/resources/public/login.jsp @@ -0,0 +1,15 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + +Login Page + + +
+
+ +
+ + \ No newline at end of file diff --git a/src/main/resources/public/testpost.php b/src/main/resources/public/testpost.php new file mode 100644 index 0000000..5d4d6b4 --- /dev/null +++ b/src/main/resources/public/testpost.php @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/src/main/resources/public/user.jsp b/src/main/resources/public/user.jsp new file mode 100644 index 0000000..afc5584 --- /dev/null +++ b/src/main/resources/public/user.jsp @@ -0,0 +1,12 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + +User Home Page + + +

Hi ${username}

+ + \ No newline at end of file diff --git a/src/main/resources/templates/error.html b/src/main/resources/templates/error.html deleted file mode 100644 index 690e856..0000000 --- a/src/main/resources/templates/error.html +++ /dev/null @@ -1,92 +0,0 @@ - - - - - - Your request cannot be processed - - - -
-

Your request cannot be processed :(

- -

Sorry, an error has occurred.

- - Status:  ()
- - Message: 
-
-
- - diff --git a/src/main/resources/templates/mail/activationEmail.html b/src/main/resources/templates/mail/activationEmail.html deleted file mode 100644 index 0bb53a2..0000000 --- a/src/main/resources/templates/mail/activationEmail.html +++ /dev/null @@ -1,20 +0,0 @@ - - - - JHipster activation - - - - -

Dear

-

Your JHipster account has been created, please click on the URL below to activate it:

-

- Activation link -

-

- Regards, -
- JHipster. -

- - diff --git a/src/main/resources/templates/mail/creationEmail.html b/src/main/resources/templates/mail/creationEmail.html deleted file mode 100644 index 4e52898..0000000 --- a/src/main/resources/templates/mail/creationEmail.html +++ /dev/null @@ -1,20 +0,0 @@ - - - - JHipster creation - - - - -

Dear

-

Your JHipster account has been created, please click on the URL below to access it:

-

- Login link -

-

- Regards, -
- JHipster. -

- - diff --git a/src/main/resources/templates/mail/passwordResetEmail.html b/src/main/resources/templates/mail/passwordResetEmail.html deleted file mode 100644 index 290ca6d..0000000 --- a/src/main/resources/templates/mail/passwordResetEmail.html +++ /dev/null @@ -1,22 +0,0 @@ - - - - JHipster password reset - - - - -

Dear

-

- For your JHipster account a password reset was requested, please click on the URL below to reset it: -

-

- Login link -

-

- Regards, -
- JHipster. -

- - diff --git a/src/test/resources/config/application-testcontainers.yml b/src/test/resources/config/application-testcontainers.yml deleted file mode 100644 index bbc14a5..0000000 --- a/src/test/resources/config/application-testcontainers.yml +++ /dev/null @@ -1,27 +0,0 @@ -# =================================================================== -# Spring Boot configuration. -# -# This configuration is used for unit/integration tests with testcontainers database containers. -# -# To activate this configuration launch integration tests with the 'testcontainers' profile -# -# More information on database containers: https://www.testcontainers.org/modules/databases/ -# =================================================================== - -spring: - datasource: - type: com.zaxxer.hikari.HikariDataSource - driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver - url: jdbc:tc:mysql:8.0.25:///basicSample?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=${user.timezone}&TC_TMPFS=/testtmpfs:rw - username: root - password: - hikari: - poolName: Hikari - auto-commit: false - data-source-properties: - cachePrepStmts: true - prepStmtCacheSize: 250 - prepStmtCacheSqlLimit: 2048 - useServerPrepStmts: true - jpa: - database-platform: org.hibernate.dialect.MySQL8Dialect diff --git a/src/test/resources/config/application.yml b/src/test/resources/config/application.yml deleted file mode 100644 index bf50e74..0000000 --- a/src/test/resources/config/application.yml +++ /dev/null @@ -1,114 +0,0 @@ -# =================================================================== -# Spring Boot configuration. -# -# This configuration is used for unit/integration tests. -# -# More information on profiles: https://www.jhipster.tech/profiles/ -# More information on configuration properties: https://www.jhipster.tech/common-application-properties/ -# =================================================================== - -# =================================================================== -# Standard Spring Boot properties. -# Full reference is available at: -# http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html -# =================================================================== - -spring: - profiles: - # Uncomment the following line to enable tests against production database type rather than H2, using Testcontainers - #active: testcontainers - application: - name: basicSample - datasource: - type: com.zaxxer.hikari.HikariDataSource - url: jdbc:h2:mem:basicsample;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE - name: - username: - password: - hikari: - auto-commit: false - jackson: - serialization: - write-durations-as-timestamps: false - jpa: - database-platform: tech.jhipster.domain.util.FixedH2Dialect - open-in-view: false - hibernate: - ddl-auto: none - naming: - physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy - implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy - properties: - hibernate.id.new_generator_mappings: true - hibernate.connection.provider_disables_autocommit: true - hibernate.cache.use_second_level_cache: false - hibernate.cache.use_query_cache: false - hibernate.generate_statistics: false - hibernate.hbm2ddl.auto: validate - hibernate.jdbc.time_zone: UTC - hibernate.query.fail_on_pagination_over_collection_fetch: true - liquibase: - contexts: test - mail: - host: localhost - main: - allow-bean-definition-overriding: true - messages: - basename: i18n/messages - task: - execution: - thread-name-prefix: basic-sample-task- - pool: - core-size: 1 - max-size: 50 - queue-capacity: 10000 - scheduling: - thread-name-prefix: basic-sample-scheduling- - pool: - size: 1 - thymeleaf: - mode: HTML - -server: - port: 10344 - address: localhost - -# =================================================================== -# JHipster specific properties -# -# Full reference is available at: https://www.jhipster.tech/common-application-properties/ -# =================================================================== - -jhipster: - clientApp: - name: 'basicSampleApp' - logging: - # To test json console appender - use-json-format: false - logstash: - enabled: false - host: localhost - port: 5000 - queue-size: 512 - mail: - from: test@localhost - base-url: http://127.0.0.1:8080 - security: - authentication: - jwt: - # This token must be encoded using Base64 (you can type `echo 'secret-key'|base64` on your command line) - base64-secret: MDllZDU1YzRkZmUxYWM1MWVjN2JjMzA0NDVhNmViNGZmYjgyN2NmZGRjN2VkZjNkYjFlYTQ3NGY4MGY3N2Q3NDkxNzBiYzYzZjZmOWQwNjZiMGNiYmRlMGZjZGE5NWQwOTIwZjY3ZThlMjY0YTk4YjNiZGViNzZjMGQ5M2MwYjQ= - # Token is valid 24 hours - token-validity-in-seconds: 86400 -# =================================================================== -# Application specific properties -# Add your own application properties here, see the ApplicationProperties class -# to have type-safe configuration, like in the JHipsterProperties above -# -# More documentation is available at: -# https://www.jhipster.tech/common-application-properties/ -# =================================================================== - -# application: -user-registration: - setActivationKey: true \ No newline at end of file diff --git a/src/test/resources/templates/mail/testEmail.html b/src/test/resources/templates/mail/testEmail.html deleted file mode 100644 index a4ca16a..0000000 --- a/src/test/resources/templates/mail/testEmail.html +++ /dev/null @@ -1 +0,0 @@ - From 025ccd0b9f7312537f1f0fbee75b95cdb8e90f34 Mon Sep 17 00:00:00 2001 From: skdhitman Date: Fri, 12 Nov 2021 11:35:25 +0530 Subject: [PATCH 2/3] Add JUnit test cases for Gateway Layer --- .../springboot/rest/gateway/HttpGateway.java | 3 + .../rest/rest/HttpGatewayResource.java | 2 +- .../gateway/HttpGatewayGetRequestTest.java | 133 ++++++++++++++++++ 3 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/springboot/rest/gateway/HttpGatewayGetRequestTest.java diff --git a/src/main/java/com/springboot/rest/gateway/HttpGateway.java b/src/main/java/com/springboot/rest/gateway/HttpGateway.java index 3352c1a..04c2d77 100644 --- a/src/main/java/com/springboot/rest/gateway/HttpGateway.java +++ b/src/main/java/com/springboot/rest/gateway/HttpGateway.java @@ -14,8 +14,10 @@ import java.util.Map; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service +@Transactional public class HttpGateway { private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"; @@ -31,6 +33,7 @@ public String performGETHttpReq( // Set up the connection: creating request :--- URL url = new URL(urlHeader + "?" + params); +// URL url = new URL(urlHeader); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); diff --git a/src/main/java/com/springboot/rest/rest/HttpGatewayResource.java b/src/main/java/com/springboot/rest/rest/HttpGatewayResource.java index c195917..23694a4 100644 --- a/src/main/java/com/springboot/rest/rest/HttpGatewayResource.java +++ b/src/main/java/com/springboot/rest/rest/HttpGatewayResource.java @@ -39,7 +39,7 @@ public HttpGatewayResource(HttpGatewayServicePort httpGatewayServicePort) { @GetMapping("/message") public String message() { - return "Message from XXXXXXXXXXX HttpGatewayResource......"; + return "Message from HttpGatewayResource......"; } @PostMapping("/testHR") diff --git a/src/test/java/com/springboot/rest/gateway/HttpGatewayGetRequestTest.java b/src/test/java/com/springboot/rest/gateway/HttpGatewayGetRequestTest.java new file mode 100644 index 0000000..119922f --- /dev/null +++ b/src/test/java/com/springboot/rest/gateway/HttpGatewayGetRequestTest.java @@ -0,0 +1,133 @@ +package com.springboot.rest.gateway; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import org.apache.commons.lang3.RandomStringUtils; +import org.hamcrest.core.IsInstanceOf; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import com.springboot.rest.domain.dto.AdminUserDTO; +import com.springboot.rest.domain.dto.SampleEntityDTO; +import com.springboot.rest.domain.port.api.HttpGatewayServicePort; +import com.springboot.rest.domain.port.api.UserServicePort; +import com.springboot.rest.domain.port.spi.HttpGatewayPersistencePort; +import com.springboot.rest.domain.port.spi.UserPersistencPort; +import com.springboot.rest.domain.service.UserService; +import com.springboot.rest.infrastructure.entity.User; +import com.springboot.rest.mapper.UserMapper; +import com.springboot.rest.security.AuthoritiesConstants; + +@ExtendWith(MockitoExtension.class) +@ExtendWith(SpringExtension.class) +class HttpGatewayGetRequestTest { + + private String testAccept = ""; + private String testAuth = ""; + private String testUrl = ""; + Map testHttpHeader = new HashMap<>(); + + @Autowired + @MockBean + private HttpGatewayServicePort httpGatewayServicePort; + + @MockBean + private HttpGatewayPersistencePort httpGatewayPersistencePort; + + @InjectMocks + private HttpGateway httpGateway; + + @BeforeEach + public void init() { +// sampleEntity = new SampleEntity(); +// sampleEntity.setId(99l); +// sampleEntity.setAge(20); +// sampleEntity.setName("Test Sample"); +// sampleEntity.setPhone(2848); +// sampleEntity.setPassword("Test@123"); +// +// sampleEntityDto = new SampleEntityDTO(sampleEntity); + + testAccept = "application/json"; + testAuth = "Bearer jshdakjfkjegdiufedbkckjds64bh87432bkjcbds"; + testUrl = "http://httpbin.org/get"; + testHttpHeader.put("Accept", testAccept); + testHttpHeader.put("Auth", testAuth); + testHttpHeader.put("ExternalURL", testUrl); + + + httpGateway = new HttpGateway(); + } + + @Test + void contextLoads() { + assertThat(httpGatewayServicePort).isNotNull(); + } + + @Test + void performGHRTest() throws IOException { + Mockito.when(httpGatewayPersistencePort + .performGHR(testHttpHeader)) + .thenReturn(null); + String fetchedGetResponse = httpGateway.performGETHttpReq(testAccept, testAuth, testUrl); + + assertNotNull(fetchedGetResponse); + } + + @Test + void performPHRTest() throws IOException { + Mockito.when(httpGatewayPersistencePort + .performPHR(testHttpHeader)) + .thenReturn(null); + String fetchedPostResponse = httpGateway.performPOSTHttpReq(testAccept, testAuth, testUrl); + + assertNotNull(fetchedPostResponse); + } + +// @Test +// void findSampleEntitiesTest() { +// List entities = new ArrayList(); +// +// Mockito.when(httpGatewayServicePort.findAll().size() > 0) +// .thenReturn(null); +// +// entities = httpGateway.findAll(); +// // testing +// // System.out.println("Auths: "+authorities); +// +// assertNull(entities); +// } + +// @Test +// void findSampleEntityByIdTest() { +// Mockito.when(httpGatewayPersistencePort +// .findById(sampleEntityDto.getId()) +// .isPresent()) +// .thenReturn(null); +// Optional fetchedSampleEntity = httpGateway.findById(sampleEntity.getId()); +// +// assertNull(fetchedSampleEntity); +// } + +} \ No newline at end of file From adb9d6b27634762065241898d72940d2e95a0305 Mon Sep 17 00:00:00 2001 From: skdhitman Date: Fri, 12 Nov 2021 18:54:04 +0530 Subject: [PATCH 3/3] Final Commit after adding Gateway Layer. Update Resource File and Test Cases for Gateway Layer. --- .../port/api/HttpGatewayServicePort.java | 4 +- .../port/spi/HttpGatewayPersistencePort.java | 4 +- .../domain/service/HttpGatewayService.java | 11 +- .../rest/gateway/GetHttpHeaderInfo.java | 23 ++++ .../springboot/rest/gateway/HttpGateway.java | 108 +++++++++--------- .../adaptor/HttpGatewayJPAAdaptor.java | 21 +--- .../rest/rest/HttpGatewayResource.java | 63 +++++----- .../gateway/HttpGatewayGetRequestTest.java | 50 ++------ 8 files changed, 131 insertions(+), 153 deletions(-) create mode 100644 src/main/java/com/springboot/rest/gateway/GetHttpHeaderInfo.java diff --git a/src/main/java/com/springboot/rest/domain/port/api/HttpGatewayServicePort.java b/src/main/java/com/springboot/rest/domain/port/api/HttpGatewayServicePort.java index c678393..03d0ade 100644 --- a/src/main/java/com/springboot/rest/domain/port/api/HttpGatewayServicePort.java +++ b/src/main/java/com/springboot/rest/domain/port/api/HttpGatewayServicePort.java @@ -7,9 +7,9 @@ public interface HttpGatewayServicePort { - String performGHR(Map httpHeader) throws IOException; + String makeGetRequest(Map httpHeader) throws IOException; - String performPHR(Map httpHeader) throws IOException; + String makePostRequest(Map httpHeader) throws IOException; } diff --git a/src/main/java/com/springboot/rest/domain/port/spi/HttpGatewayPersistencePort.java b/src/main/java/com/springboot/rest/domain/port/spi/HttpGatewayPersistencePort.java index fa92290..fce9abf 100644 --- a/src/main/java/com/springboot/rest/domain/port/spi/HttpGatewayPersistencePort.java +++ b/src/main/java/com/springboot/rest/domain/port/spi/HttpGatewayPersistencePort.java @@ -7,8 +7,8 @@ public interface HttpGatewayPersistencePort { - String performGHR(Map httpHeader) throws IOException; + String makeGetRequest(Map httpHeader) throws IOException; - String performPHR(Map httpHeader) throws IOException; + String makePostRequest(Map httpHeader) throws IOException; } \ No newline at end of file diff --git a/src/main/java/com/springboot/rest/domain/service/HttpGatewayService.java b/src/main/java/com/springboot/rest/domain/service/HttpGatewayService.java index c929197..c3b5842 100644 --- a/src/main/java/com/springboot/rest/domain/service/HttpGatewayService.java +++ b/src/main/java/com/springboot/rest/domain/service/HttpGatewayService.java @@ -21,16 +21,13 @@ public HttpGatewayService(HttpGatewayPersistencePort httpGatewayPersistencePort) } @Override - public String performGHR(Map httpHeader) throws IOException { - - return httpGatewayPersistencePort.performGHR(httpHeader); + public String makeGetRequest(Map httpHeader) throws IOException { + return httpGatewayPersistencePort.makeGetRequest(httpHeader); } @Override - public String performPHR(Map httpHeader) throws IOException { - - return httpGatewayPersistencePort.performPHR(httpHeader); + public String makePostRequest(Map httpHeader) throws IOException { + return httpGatewayPersistencePort.makePostRequest(httpHeader); } - } \ No newline at end of file diff --git a/src/main/java/com/springboot/rest/gateway/GetHttpHeaderInfo.java b/src/main/java/com/springboot/rest/gateway/GetHttpHeaderInfo.java new file mode 100644 index 0000000..186a98d --- /dev/null +++ b/src/main/java/com/springboot/rest/gateway/GetHttpHeaderInfo.java @@ -0,0 +1,23 @@ +package com.springboot.rest.gateway; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; + +import org.springframework.stereotype.Service; + +@Service +public class GetHttpHeaderInfo { + + /* + * public static void main(String[] args) throws IOException { URL urlObj = new + * URL("http://httpbin.org/get"); HttpURLConnection conn = (HttpURLConnection) + * urlObj.openConnection(); + * + * // Accessing header info for(int i=1; i<=8; i++) { + * System.out.println(conn.getHeaderFieldKey(i) + " : " + + * conn.getHeaderField(i)); } conn.disconnect(); + * + * } + */ +} diff --git a/src/main/java/com/springboot/rest/gateway/HttpGateway.java b/src/main/java/com/springboot/rest/gateway/HttpGateway.java index 04c2d77..f41b920 100644 --- a/src/main/java/com/springboot/rest/gateway/HttpGateway.java +++ b/src/main/java/com/springboot/rest/gateway/HttpGateway.java @@ -7,10 +7,7 @@ import java.io.Reader; import java.net.HttpURLConnection; import java.net.URL; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.Map; import org.springframework.stereotype.Service; @@ -22,35 +19,37 @@ public class HttpGateway { private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"; - private static final String params = "hero=IronMan&power=BeingRich"; + private static String accept = ""; + private static String auth = ""; + private static String externalUrl = ""; + private static String params = ""; + - public String performGETHttpReq( - String acceptHeader, String authHeader, String urlHeader) throws IOException { - Map httpHeader = new HashMap<>(); - httpHeader.put("Accept", acceptHeader); - httpHeader.put("Auth", authHeader); - httpHeader.put("ExternalURL", urlHeader); + // Gateway for GET API call + public String performGETRequest(Map httpHeader) + throws IOException { + + accept = httpHeader.get("Accept"); + auth = httpHeader.get("Auth"); + externalUrl = httpHeader.get("ExternalURL"); + params = httpHeader.get("Params"); // Set up the connection: creating request :--- - URL url = new URL(urlHeader + "?" + params); -// URL url = new URL(urlHeader); + URL url = new URL(externalUrl + "?" + params); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); - - + // Adding request parameters :--- Map parameters = new HashMap<>(); parameters.put("param1", "value1"); - + // Setting Request Headers :--- con.setRequestProperty("User-Agent", USER_AGENT); - - + // Setting the timeouts :--- con.setConnectTimeout(5000); con.setReadTimeout(6000); - - + // Reading the response (handling the failed requests) :--- int status = con.getResponseCode(); System.out.println("'GET' request to URL : " + url); @@ -58,12 +57,12 @@ public String performGETHttpReq( System.out.println("Response Body : "); Reader streamReader = null; - if(status > 299) { + if (status > 299) { streamReader = new InputStreamReader(con.getErrorStream()); } else { streamReader = new InputStreamReader(con.getInputStream()); } - + // read response content BufferedReader in = new BufferedReader(streamReader); String inputLine; @@ -72,72 +71,68 @@ public String performGETHttpReq( content.append(inputLine); } in.close(); - + // print content on console System.out.println(content.toString()); - + // Retrieve "full response" StringBuilder fullResponseContent; fullResponseContent = FullResponseBuilder.getFullResponse(con); - + // Add response content - fullResponseContent.append("\n"+content); - + fullResponseContent.append("\n" + content); + // Perform connection disconnection con.disconnect(); - + System.out.println("GET done.\n"); - return fullResponseContent.toString(); } - - public String performPOSTHttpReq( - String acceptHeader, String authHeader, String urlHeader) throws IOException { - - Map httpHeader = new HashMap<>(); - httpHeader.put("Accept", acceptHeader); - httpHeader.put("Auth", authHeader); - httpHeader.put("ExternalURL", urlHeader); - + public String performPOSTRequest(Map httpHeader) + throws IOException { + + accept = httpHeader.get("Accept"); + auth = httpHeader.get("Auth"); + externalUrl = httpHeader.get("ExternalURL"); + params = httpHeader.get("Params"); + // Set up the connection: creating request :--- - URL url = new URL(urlHeader); + URL url = new URL(externalUrl); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("GET"); - - + // Adding request parameters :--- Map parameters = new HashMap<>(); parameters.put("param1", "value1"); - + // Setting Request Headers :--- con.setRequestProperty("User-Agent", USER_AGENT); - + con.setDoOutput(true); DataOutputStream out = new DataOutputStream(con.getOutputStream()); -// out.writeBytes(ParameterStringBuilder.getParamsString(parameters)); + // out.writeBytes(ParameterStringBuilder.getParamsString(parameters)); out.writeBytes(params); out.flush(); out.close(); - + // Setting the timeouts :--- con.setConnectTimeout(5000); con.setReadTimeout(6000); - - + // Reading the response (handling the failed requests) :--- int status = con.getResponseCode(); System.out.println("'POST' request to URL : " + url); System.out.println("Response Code : " + status); System.out.println("Response Body : "); Reader streamReader = null; - - if(status > 299) { + + if (status > 299) { streamReader = new InputStreamReader(con.getErrorStream()); } else { streamReader = new InputStreamReader(con.getInputStream()); } - + // read response content BufferedReader in = new BufferedReader(streamReader); String inputLine; @@ -146,23 +141,22 @@ public String performPOSTHttpReq( content.append(inputLine); } in.close(); - + // print content on console System.out.println(content.toString()); - + // Retrieve "full response" StringBuilder fullResponseContent; fullResponseContent = FullResponseBuilder.getFullResponse(con); - + // Add response content - fullResponseContent.append("\n"+content); - + fullResponseContent.append("\n" + content); + // Perform connection disconnection con.disconnect(); - + System.out.println("POST done.\n"); - return fullResponseContent.toString(); - } + } diff --git a/src/main/java/com/springboot/rest/infrastructure/adaptor/HttpGatewayJPAAdaptor.java b/src/main/java/com/springboot/rest/infrastructure/adaptor/HttpGatewayJPAAdaptor.java index ed6a8bf..92b4288 100644 --- a/src/main/java/com/springboot/rest/infrastructure/adaptor/HttpGatewayJPAAdaptor.java +++ b/src/main/java/com/springboot/rest/infrastructure/adaptor/HttpGatewayJPAAdaptor.java @@ -15,29 +15,20 @@ public class HttpGatewayJPAAdaptor implements HttpGatewayPersistencePort { private final HttpGateway httpGateway; - public HttpGatewayJPAAdaptor(HttpGateway httpGateway) { this.httpGateway = httpGateway; } - // Implementations - @Override - public String performGHR(Map httpHeader) throws IOException { - - return httpGateway.performGETHttpReq(httpHeader.get("Accept") - , httpHeader.get("Auth") - , httpHeader.get("ExternalURL")); + public String makeGetRequest(Map httpHeader) throws IOException { + return httpGateway.performGETRequest(httpHeader); } - + + @Override - public String performPHR(Map httpHeader) throws IOException { - - return httpGateway.performPOSTHttpReq(httpHeader.get("Accept") - , httpHeader.get("Auth") - , httpHeader.get("ExternalURL")); + public String makePostRequest(Map httpHeader) throws IOException { + return httpGateway.performPOSTRequest(httpHeader); } - } \ No newline at end of file diff --git a/src/main/java/com/springboot/rest/rest/HttpGatewayResource.java b/src/main/java/com/springboot/rest/rest/HttpGatewayResource.java index 23694a4..9febb50 100644 --- a/src/main/java/com/springboot/rest/rest/HttpGatewayResource.java +++ b/src/main/java/com/springboot/rest/rest/HttpGatewayResource.java @@ -18,6 +18,9 @@ import com.springboot.rest.domain.port.api.HttpGatewayServicePort; import com.springboot.rest.domain.port.api.SampleEntityServicePort; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; + @RestController @RequestMapping("/httpreq") public class HttpGatewayResource { @@ -25,6 +28,9 @@ public class HttpGatewayResource { private final Logger log = LoggerFactory.getLogger(HttpGatewayResource.class); private static final String accept = "Accept"; + private static final String auth = "Auth"; + private static final String url = "ExternalURL"; + private static final String params = "Params"; @Value("${jhipster.clientApp.name}") private String applicationName; @@ -37,54 +43,51 @@ public HttpGatewayResource(HttpGatewayServicePort httpGatewayServicePort) { // API calls' methods + // Test API call @GetMapping("/message") + @Operation(summary = "/message", security = @SecurityRequirement(name = "bearerAuth")) public String message() { return "Message from HttpGatewayResource......"; } - @PostMapping("/testHR") - public ResponseEntity> testHttpReq( - @RequestHeader(value=accept) String acceptHeader, - @RequestHeader(value="Auth") String authHeader - ) { - Map returnValue = new HashMap<>(); - returnValue.put(accept, acceptHeader); - returnValue.put("Auth", authHeader); - - return ResponseEntity.status(HttpStatus.OK).body(returnValue); - } - - @PostMapping("/getHR") - public ResponseEntity createGETHttpReq( + // GET Request API call to external URL + @PostMapping("/get-request") + @Operation(summary = "/get-request", security = @SecurityRequirement(name = "bearerAuth")) + public ResponseEntity createGETRequest( @RequestHeader(value=accept) String acceptHeader, - @RequestHeader(value="Auth") String authHeader, - @RequestHeader(value="ExternalURL") String urlHeader + @RequestHeader(value=auth) String authHeader, + @RequestHeader(value=url) String urlHeader, + @RequestHeader(value=params) String paramsHeader ) throws IOException { - Map returnValue = new HashMap<>(); returnValue.put(accept, acceptHeader); - returnValue.put("Auth", authHeader); - returnValue.put("ExternalURL", urlHeader); + returnValue.put(auth, authHeader); + returnValue.put(url, urlHeader); + returnValue.put(params, paramsHeader); + + String httpHeader = httpGatewayServicePort.makeGetRequest(returnValue); - String httpHeader = httpGatewayServicePort.performGHR(returnValue); - return ResponseEntity.status(HttpStatus.OK).body(httpHeader); } - @PostMapping("/postHR") - public ResponseEntity createPOSTHttpReq( + // POST Request API call to external URL + @PostMapping("/post-request") + @Operation(summary = "/post-request", security = @SecurityRequirement(name = "bearerAuth")) + public ResponseEntity createPOSTRequest( @RequestHeader(value=accept) String acceptHeader, - @RequestHeader(value="Auth") String authHeader, - @RequestHeader(value="ExternalURL") String urlHeader + @RequestHeader(value=auth) String authHeader, + @RequestHeader(value=url) String urlHeader, + @RequestHeader(value=params) String paramsHeader ) throws IOException { - Map returnValue = new HashMap<>(); returnValue.put(accept, acceptHeader); - returnValue.put("Auth", authHeader); - returnValue.put("ExternalURL", urlHeader); + returnValue.put(auth, authHeader); + returnValue.put(url, urlHeader); + returnValue.put(params, paramsHeader); + + String httpHeader = httpGatewayServicePort.makePostRequest(returnValue); - String httpHeader = httpGatewayServicePort.performPHR(returnValue); - return ResponseEntity.status(HttpStatus.OK).body(httpHeader); } + } diff --git a/src/test/java/com/springboot/rest/gateway/HttpGatewayGetRequestTest.java b/src/test/java/com/springboot/rest/gateway/HttpGatewayGetRequestTest.java index 119922f..6c2ad28 100644 --- a/src/test/java/com/springboot/rest/gateway/HttpGatewayGetRequestTest.java +++ b/src/test/java/com/springboot/rest/gateway/HttpGatewayGetRequestTest.java @@ -46,36 +46,29 @@ class HttpGatewayGetRequestTest { private String testAccept = ""; private String testAuth = ""; private String testUrl = ""; + private String testParams = ""; Map testHttpHeader = new HashMap<>(); @Autowired @MockBean private HttpGatewayServicePort httpGatewayServicePort; - @MockBean private HttpGatewayPersistencePort httpGatewayPersistencePort; - @InjectMocks private HttpGateway httpGateway; @BeforeEach public void init() { -// sampleEntity = new SampleEntity(); -// sampleEntity.setId(99l); -// sampleEntity.setAge(20); -// sampleEntity.setName("Test Sample"); -// sampleEntity.setPhone(2848); -// sampleEntity.setPassword("Test@123"); -// -// sampleEntityDto = new SampleEntityDTO(sampleEntity); testAccept = "application/json"; testAuth = "Bearer jshdakjfkjegdiufedbkckjds64bh87432bkjcbds"; testUrl = "http://httpbin.org/get"; + testParams = "hero=IronMan&power=BeingRich"; + testHttpHeader.put("Accept", testAccept); testHttpHeader.put("Auth", testAuth); testHttpHeader.put("ExternalURL", testUrl); - + testHttpHeader.put("Params", testParams); httpGateway = new HttpGateway(); } @@ -85,49 +78,26 @@ void contextLoads() { assertThat(httpGatewayServicePort).isNotNull(); } + // Test case for GET Http Request @Test void performGHRTest() throws IOException { Mockito.when(httpGatewayPersistencePort - .performGHR(testHttpHeader)) + .makeGetRequest(testHttpHeader)) .thenReturn(null); - String fetchedGetResponse = httpGateway.performGETHttpReq(testAccept, testAuth, testUrl); + String fetchedGetResponse = httpGateway.performGETRequest(testHttpHeader); assertNotNull(fetchedGetResponse); } + // Test case for POST Http Request @Test void performPHRTest() throws IOException { Mockito.when(httpGatewayPersistencePort - .performPHR(testHttpHeader)) + .makePostRequest(testHttpHeader)) .thenReturn(null); - String fetchedPostResponse = httpGateway.performPOSTHttpReq(testAccept, testAuth, testUrl); + String fetchedPostResponse = httpGateway.performPOSTRequest(testHttpHeader); assertNotNull(fetchedPostResponse); } - -// @Test -// void findSampleEntitiesTest() { -// List entities = new ArrayList(); -// -// Mockito.when(httpGatewayServicePort.findAll().size() > 0) -// .thenReturn(null); -// -// entities = httpGateway.findAll(); -// // testing -// // System.out.println("Auths: "+authorities); -// -// assertNull(entities); -// } - -// @Test -// void findSampleEntityByIdTest() { -// Mockito.when(httpGatewayPersistencePort -// .findById(sampleEntityDto.getId()) -// .isPresent()) -// .thenReturn(null); -// Optional fetchedSampleEntity = httpGateway.findById(sampleEntity.getId()); -// -// assertNull(fetchedSampleEntity); -// } } \ No newline at end of file