Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8082615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:10:19+00:00 2026-06-05T17:10:19+00:00

I’m currently experimenting with some RESTful JAX and I want to validate a custom

  • 0

I’m currently experimenting with some RESTful JAX and I want to validate a custom input. Normally regex would be fine but I need to do a more extensive check (~10 different regex patterns). I found this page when searching for jaxrs validation. I noted it says “Draft” but I thought I’d give it a try.

I wrote my parameter annotation like this:

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = FooBarValidator.class)
public @interface FooBarParam
{
}

The validator looks like this:

@Provider
public class FooBarValidator
        implements ConstraintValidator<FooBar, Long>
{
    @Override
    public void initialize(FooBar constraintAnnotation)
    {
    }

    @Override
    public boolean isValid(Long value, ConstraintValidatorContext context)
    {
        // validation goes here, this is a test validation
        return (value > 50);
    }
}

The web service looks like this:

@javax.ejb.Stateless
@Path("test")
public class testRS
{
    @GET
    @Path("foobar/{fooBar: [0-9]+}")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.TEXT_PLAIN)
    public String testService(@FooBar @PathParam("fooBar") Long fooBar)
    {
        return "tested with: " + fooBar;
    }
}

But if I call my web service with my browser using “http://localhost:8080/jaxtest/rest/test/foobar/11&#8221; the web service gets called and I’m presented with “tested with: 11”. The web service works fine, except the validator doesn’t get called.

I’ve tried setting breakpoints in the validator class and the annotation interface but none are hit.

I’ve got a sneaking suspicion that I’m doing something that isn’t possible because of the “Draft” header in the referenced documentation. So if I’m doing something wrong or if there are alternatives, I’m glad to hear it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:10:21+00:00Added an answer on June 5, 2026 at 5:10 pm

    Thanks to the hint @PiotrKochański gave me I’ve successfully implemented exactly what I wanted. The biggest problem was that I’m bound to using Glassfish. By default Glassfish uses Jersey to handle JAX stuff.

    It took me well over 10 hours of struggling to complete this so let this be a time saver for anyone who stumbles upon this.

    First of all, use Maven, this makes your life so much easier.

    Second step, add the JBoss repo to your pom.xml

    <repositories>
        <repository>
            <id>jboss-public-repository-group</id>
            <name>JBoss Public Maven Repository Group</name>
            <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
            <layout>default</layout>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </snapshots>
        </repository>
    </repositories>
    

    Third step, add dependencies to pom.xml

    <!-- Needed for validator interceptors -->
    <dependency>
        <groupId>org.jboss.seam.rest</groupId>
        <artifactId>seam-rest</artifactId>
        <version>3.1.0.Final</version>
    </dependency>
    <!-- JBoss' RS implementation -->
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxrs</artifactId>
        <version>2.3.4.Final</version>
    </dependency>
    <!-- Because I use JSON I need RESTeasy be able to handle this --> 
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jettison-provider</artifactId>
        <version>2.3.4.Final</version>
    </dependency>
    <!-- This is THE part that integrates validation in RESTeasy -->
    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-hibernatevalidator-provider</artifactId>
        <version>2.3.4.Final</version>
    </dependency>
    

    The last dependency took me quite a while. The docs @PiotrKochański pointed to didn’t mention this. However in another version of the docs I found this:

    The integration between the API implementation and RESTEasy is done through the resteasy-hibernatevalidator-provider component. In order to integrate, we need to add resteasy-hibernatevalidator-provider and hibernate-validator to the classpath. With maven it’s just a matter of including the following dependency:

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-hibernatevalidator-provider</artifactId>
        <version>2.3-RC1</version>
    </dependency>
    

    The fourth step was to add this to web.xml

    <context-param>
        <param-name>resteasy.scan</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>resteasy.servlet.mapping.prefix</param-name>
        <param-value>/rest</param-value>
    </context-param>
    <listener>
        <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
    </listener>
    <servlet>
        <servlet-name>REST Service</servlet-name>
        <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>REST Service</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
    

    The fifth step was to modify the web service class like this:

    @javax.ejb.Stateless
    @Path("test")
    public class testRS
    {
        @GET
        @Path("foobar/{fooBar}")
        @Produces(MediaType.APPLICATION_JSON)
        @org.jboss.resteasy.spi.validation.ValidateRequest
        public String testService(@FooBar @PathParam("fooBar") Long fooBar)
        {
            return "tested with: " + fooBar;
        }
    }
    

    The sixth step was to modify the @interface to this:

    @Target(ElementType.PARAMETER)
    @Retention(RetentionPolicy.RUNTIME)
    @Constraint(validatedBy = FooBarValidator.class)
    public @interface FooBarParam
    {
        String message() default "{constraint.FooBar}";
        Class<?>[] groups() default {};
        Class<? extends Payload>[] payload() default {};
    }
    

    Also as a bonus; I came across a presentation about Bean Validation by Emmanuel Bernard I thought I might share as this explains a lot of interesting stuff.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I need to clean up various Word 'smart' characters in user input, including but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a small JavaScript validation script that validates inputs based on Regex. I
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.