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 8371757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:14:23+00:00 2026-06-09T14:14:23+00:00

I am using Jersey restful web services for the Application development. <servlet> <servlet-name>Jersey Web

  • 0

I am using Jersey restful web services for the Application development.

 <servlet>
   <servlet-name>Jersey Web Application</servlet-name>
   <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
   <init-param>
     <param-name>com.sun.jersey.config.property.packages</param-name>
     <param-value>com.services</param-value>
   </init-param>
   <load-on-startup>1</load-on-startup>
 </servlet>

I have some service classes configured under com.services package.

Basically my requirement is that, before Jersey calling my Service classes, i want to do some initial check.

Basically my requirement is that before invoking the service, i want to check if a input hidden variable passed from UI is present or not.

So is it possible to extend the Jersey Framework for acheving this?

Could you please tell me how can i use this inside my service class ??

@Path("/hello")
public class HelloService extends AbstractService {

    @GET
    @Produces("application/text")
    public String sayPlainTextHello() {


        return "Hello json";
    }

}
  • 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-09T14:14:24+00:00Added an answer on June 9, 2026 at 2:14 pm

    Introduction

    Here’s a simple solution that should suit your use case pretty well. What I’m showing here is not how to perform operations before a service is called but rather, immediately after the service is called and before the code of your resource methods is executed. Still, it seems like a good thing to do, judging by your description of the problem.

    You can create your own parameter classes to do whatever you wish with form input (parsing strings, validation, etc.). Just make sure you have a constructor that takes a String parameter and you’ll be able to inject appropriate objects into the calls of the methods of your resource classes. If the value is incorrect, throw an exception specifying the message and status code for Jersey to return to the client.

    Example

    Given the form

    <form action="http://example.com/rest/" method="post">
      <!-- some inputs -->
      <input type="hidden" name="hiddenParam" value="Some value you set on client side" />
    </form>
    

    create a parameter class like this:

    public class MyParameter{
    
      //some fields
    
      public MyParameter(String param){        
        //parse the string however you want, check if the value is correct
        if(param is correct){
          //set the fields 
        } else {
          throw new WebApplicationException(new InvalidArgumentException("Invalid parameter XYZ"), Response.Status.BAD_REQUEST);
        }
      }
    
      //some getters for fields
    }
    

    Then, in you resource class, inject the parameter:

    @POST
    public Response postData(@FormParam("hiddenParam") MyParameter hidden){
       //use getters on "hidden" to extract some data if needed
    }
    

    Notice that you don’t have to do anything to hidden in the code of this method. You can perform all validation in a transparent manner within the code of your parameter class. The checks don’t have to be repeated over and over, they don’t pollute your resource classes.

    It also makes for an easily testable solution, which can be made even simpler by using a generic parameter class (less code repetition).

    Such classes can be used with @QueryParam and @PathParam annotations as well.

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

Sidebar

Related Questions

I am deploying a restful web services using Netbeans EE6 and jersey libraries with
I'm writing a mule application that implements some web services using Jersey. I'd like
I am building a RESTful web service in java using JAX-RS and jersey and
I have a Maven 2 RESTful application using Jersey/JAXB. I generate the JAXB beans
I created a simple XML web service using NetBeans 7's RESTful Web Services from
I'm using jersey API for some REST web services with apache Tomcat. I need
I'm building a RESTful web service using Jersey that relies on MongoDB for persistence.
I am using Jersey to do the URL binding for my web application. Hence,
I have a web services written in java using jersey framework when i call
I want make RESTful services using embedded jetty with JAX-RS (either resteasy or jersey).

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.