i use wiremock for recording but i have this error...
# wiremock-java
a
i use wiremock for recording but i have this error : Unable to generate a certificate authority 2024-11-18T090928.746061074Z 2024-11-18T090928.746062735Z com.github.tomakehurst.wiremock.http.ssl.CertificateGenerationUnsupportedException: Your runtime does not support generating certificates at runtime. Any solution ?
l
Hi, what version of Java are you using?
a
java 19
knowing that I consulted this link : https://community.wiremock.io/t/18860254/does-any-have-how-to-resolve-this-issue-2024-05-30-14-33-12-. Should I generate CA certificates?
l
I have seen the same error with java 17 before. This is something we need to look at when we baseline on java 17. You could try adding this to your Java startup command:
Copy code
--add-exports=java.base/sun.security.x509=ALL-UNNAMED
a
i use gradle for build of my image what can i add ?
l
It is difficult to know without seeing your gradle build
a
Copy code
dependencies {
 
    //lombok
    compileOnly 'org.projectlombok:lombok'
    implementation 'org.springframework.boot:spring-boot-devtools'
    annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
    annotationProcessor 'org.projectlombok:lombok'

    //mapstruct
    implementation 'org.mapstruct:mapstruct:1.5.2.Final'
    annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.2.Final'

    compileOnly 'jakarta.annotation:jakarta.annotation-api:2.1.1'

    // wiremock
    implementation 'org.wiremock:wiremock:3.6.0'
    implementation 'org.eclipse.jetty:jetty-server'
    implementation 'org.eclipse.jetty:jetty-servlet'

    // flyway
    implementation 'org.flywaydb:flyway-core'

    // casbin
    implementation 'org.casbin:casbin-spring-boot-starter:0.4.4'
    implementation "org.casbin:jdbc-adapter:2.4.1"

    // start keycloak dependency
    implementation 'org.keycloak:keycloak-spring-boot-starter:25.0.3'
    implementation 'org.keycloak:keycloak-admin-client:25.0.3'
    // end keycloak dependency

    // <https://mvnrepository.com/artifact/com.google.code.gson/gson>
    implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1'

    //Jwt
    implementation 'io.jsonwebtoken:jjwt:0.9.1'

    // start unit test dependencies
    implementation 'junit:junit:4.13.1'

    testImplementation "com.intuit.karate:karate-apache:0.9.6"
    testImplementation 'com.intuit.karate:karate-junit5:1.1.0'

    testImplementation 'com.auth0:java-jwt:3.19.1'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'

    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.2'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.2'

    testCompileOnly 'org.projectlombok:lombok:1.18.24'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.24'
}
this is my build.gradle
l
Is that the whole file? It just looks like the dependencies section ?
a
Sorry , this is the completed file :
Copy code
buildscript {
    ext {
       protobufVersion = '3.14.0'
       protobufPluginVersion = '0.8.18'
       grpcVersion = '1.49.2'
    }
    repositories {
       mavenCentral()
       google()
    }
    dependencies {
       classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.14'
       classpath("org.springframework.boot:spring-boot-gradle-plugin:2.4.1")
    }
}

plugins {
    id 'java-library'
    id 'com.google.protobuf' version "${protobufPluginVersion}"
    id 'org.springframework.boot' version '3.2.4'
    id 'io.spring.dependency-management' version '1.0.15.RELEASE'
    id 'java'
}
version = '0.0.1-SNAPSHOT'

java {
    sourceCompatibility = '17.0.8'
}

configurations {
    compileOnly {
       extendsFrom annotationProcessor
    }
}
repositories {
    mavenCentral()
}

dependencyManagement {
    imports {
       mavenBom 'org.eclipse.jetty:jetty-bom:11.0.20'
    }
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'io.micrometer:micrometer-registry-prometheus'
    runtimeOnly 'org.postgresql:postgresql:42.7.3'
    implementation 'org.apache.commons:commons-lang3:3.12.0'
    implementation 'org.graalvm.js:js:21.3.0'
    implementation 'org.graalvm.js:js-scriptengine:21.3.0'
    implementation 'org.hibernate.validator:hibernate-validator:8.0.1.Final'
    implementation "io.grpc:grpc-protobuf:${grpcVersion}"
    implementation "io.grpc:grpc-stub:${grpcVersion}"
    implementation 'javax.annotation:javax.annotation-api:1.3.2'
    implementation 'com.google.protobuf:protobuf-java:3.24.4'
    implementation 'net.devh:grpc-spring-boot-starter:2.15.0.RELEASE'
    implementation 'net.devh:grpc-server-spring-boot-starter:2.15.0.RELEASE'
    api "io.grpc:grpc-netty:${grpcVersion}"
    api "io.grpc:grpc-protobuf:${grpcVersion}"
    api "io.grpc:grpc-stub:${grpcVersion}"
    api "io.grpc:grpc-all:${grpcVersion}"
    api "io.grpc:grpc-okhttp:${grpcVersion}"
    api('org.springframework.boot:spring-boot-starter')


    //lombok
    compileOnly 'org.projectlombok:lombok'
    implementation 'org.springframework.boot:spring-boot-devtools'
    annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
    annotationProcessor 'org.projectlombok:lombok'

    //mapstruct
    implementation 'org.mapstruct:mapstruct:1.5.2.Final'
    annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.2.Final'

    compileOnly 'jakarta.annotation:jakarta.annotation-api:2.1.1'

    // wiremock
    implementation 'org.wiremock:wiremock:3.6.0'
    implementation 'org.eclipse.jetty:jetty-server'
    implementation 'org.eclipse.jetty:jetty-servlet'

    // flyway
    implementation 'org.flywaydb:flyway-core'

    // casbin
    implementation 'org.casbin:casbin-spring-boot-starter:0.4.4'
    implementation "org.casbin:jdbc-adapter:2.4.1"

    // start keycloak dependency
    implementation 'org.keycloak:keycloak-spring-boot-starter:25.0.3'
    implementation 'org.keycloak:keycloak-admin-client:25.0.3'
    // end keycloak dependency

    // <https://mvnrepository.com/artifact/com.google.code.gson/gson>
    implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1'

    //Jwt
    implementation 'io.jsonwebtoken:jjwt:0.9.1'

    // start unit test dependencies
    implementation 'junit:junit:4.13.1'

    testImplementation "com.intuit.karate:karate-apache:0.9.6"
    testImplementation 'com.intuit.karate:karate-junit5:1.1.0'

    testImplementation 'com.auth0:java-jwt:3.19.1'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'

    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.2'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.2'

    testCompileOnly 'org.projectlombok:lombok:1.18.24'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.24'
}



jar {
    enabled = false
}

protobuf {
    protoc {
       artifact = "com.google.protobuf:protoc:${protobufVersion}"
    }

    plugins {
       grpc {
          artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
       }
    }
    generateProtoTasks {
       all()*.plugins {
          grpc {}
       }
    }
}


sourceSets {
    main {
       java {
          srcDirs 'build/generated/source/proto/main/grpc'
          srcDirs 'build/generated/source/proto/main/java'
       }
    }

    test {
       resources {
          srcDir file('src/test/java')
          exclude '**/*.java'
       }
    }
}

// to lunch build: ./gradlew build
test {
    useJUnitPlatform {
       finalizedBy jacocoTestReport // report is always generated after tests run
       excludeTags("karateLocal")
       excludeTags("karateITG")
       exclude '**/*IntegrationTest*'
       //  exclude any test class whose name contains the string "IntegrationTest" from running during the build process
    }
}


task integrationTest(type: Test) {
    useJUnitPlatform {
       include '**/*IntegrationTest*'
    }

}
// to lunch karate tests on ITG env: ./gradlew karateITG
task karateITGTest(type: Test) {
    useJUnitPlatform {
       includeTags('karateITG')
    }
}

// to lunch karate tests on Local env: ./gradlew karateLocal
task karateLocalTest(type: Test) {
    useJUnitPlatform {
       includeTags('karateLocal')
    }
}
}
l
That doesn't give us much to go on unfortunately. Is is the Spring functionality that you are using to build the image?
Do you have a
DockerFile
in your project?
Also, when do you see the error you described above? Is this when your tests are running? Just wondering if we are barking up the wrong tree here because the image build is for when you are running you app, not executing the tests ?
a
Yes, I am using Spring. The error does not occur when I test, but it happens when I call 'start recording.' According to my research, the error is caused by this code :
Copy code
public WireMockServer createRecording(int port, String targetBaseUrl) {
    <http://log.info|log.info>("enter in Component");
    WireMockServer wireMockServer = new WireMockServer(
            WireMockConfiguration.wireMockConfig()
                    .port(port)
                    .enableBrowserProxying(true)
    );
    wireMockServer.startRecording(targetBaseUrl);
    return wireMockServer;
}
yes i have a DockerFile
this is my DockerFile :
Copy code
#First stage: build jar
FROM gradle:8.5-jdk17 AS builder
# add build files
WORKDIR /app
COPY  build.gradle settings.gradle ./
COPY  src/ src/
# build application
RUN gradle clean build --no-daemon
# Second stage: build docker image
FROM openjdk:17-jdk-alpine
# Copy the application JAR into the Docker image
COPY --from=builder /app/build/libs/*.jar app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]
l
How are you starting wiremock to then perform the recording?
a
I added the following dependency to my
build.gradle
file:
implementation 'org.wiremock:wiremock:3.6.0'
. Afterward, I created a new WireMock instance for recording.