Hi, Jochen!

Thanks for the advice, it does work! But I had to use a bit different 
approach with custom class annotation, like:

My configuration class (all code below in Kotlin):
@CheckApplicationContextPath
class MyConfiguration(
  val project: String,
  val env: String,
  ...
) : io.dropwizard:Configuration()

CheckApplicationContextPath.kt:
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
@Constraint(validatedBy = [ApplicationContextPathValidator::class])
annotation class CheckApplicationContextPath(
  val message: String = "Please correct applicationContextPath in the 
config file",
  val groups: Array<KClass<*>> = [],
  val payload: Array<KClass<out Payload>> = []
)

ApplicationContextPathValidator.kt: 
class ApplicationContextPathValidator : ConstraintValidator<
CheckApplicationContextPath,  MyConfiguration > {
   override fun isValid(value: MyConfiguration , context: 
ConstraintValidatorContext): Boolean {
     val applicationContextPath = (value.serverFactory as 
SimpleServerFactory).applicationContextPath
     println("Config's applicationContextPath is $applicationContextPath")
     return applicationContextPath == "/myCorrectApplicationContextPath "
   }
}

Thanks again,
Innokentiy
On Sunday, September 18, 2022 at 4:29:08 AM UTC+7 [email protected] wrote:

> Hi,
>
> You could (mis-) use Hibernate Validator for this and add a validation 
> method with @AssertTrue to your configuration file in which you check the 
> applicationContextPath.
>
> @AssertTrue
> public boolean validateApplicationContextPath() {
> return server.getApplicationContextPath().equals("…“);
> }
>
> Cheers,
> Jochen
>
> > Am 12.09.2022 um 18:16 schrieb Innokentiy Struchkov <
> [email protected]>:
> > 
> > Hi! I'm upgrading an old server to newer version of Dropwizard (1.x.x to 
> 2.1.0) and other dependencies too. Now I have to explicitly check if user 
> set the only correct applicationContextPath in server section of 
> configuration file. Is there a way to do this in our Configuration 
> implementation in constructor code (or within init block in Kotlin) or 
> bootstrap initialization?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dropwizard-user/8c159aab-d297-47d7-b858-983105d9ddf7n%40googlegroups.com.

Reply via email to