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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:28:26+00:00 2026-06-09T02:28:26+00:00

Is there a way to have query parameter x be included in the URL

  • 0

Is there a way to have query parameter “x” be included in the URL with the default value if it is omitted, because currently what I need to do is the following below and I have to do that for each parameter with a default value; is there a better way to do this? I am using Jersey version 1.12

    public Response getResponse(@DefaultValue("test") @QueryParam("x") String x)
                UriBuilder uriBuilder = UriBuilder.fromUri(uriInfo.getRequestUri());
                uriBuilder = uriBuilder.replaceQueryParam(x);
                QueryContext.setUrl(uriBuilder.build().toString());

Thank you

  • 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-09T02:28:29+00:00Added an answer on June 9, 2026 at 2:28 am

    I’m not aware of a standard Jersey way to do this but you could intercept the method with AOP and do something like:

    public class UpdateQueryParamInterceptor implements MethodInterceptor {
    
      public Object invoke(MethodInvocation method) throws Throwable {
        UriBuilder builder = null;
        for (Object arg: method.getArguments()) {
          if (arg instanceof UriInfo) {
            UriInfo info = (UriInfo)arg;
            builder = UriBuilder.fromUri(info.getRequestUri());
          }
        }
    
        Annotation[][] annotations = method.getMethod().getParameterAnnotations();
        for (int i = 0; i < method.getArguments().length; i++) {
          if (annotations[i].length > 0) {
            DefaultValue def = null;
            QueryParam param = null;
    
            for (Annotation annotation: annotations[i]) {
              if (annotation instanceof DefaultValue) {
                def = (DefaultValue)annotation;
              } else if (annotation instanceof QueryParam) {
                param = (QueryParam)annotation;
              }
            }
            if ((null != def) && (null != param)) {
              builder = builder.replaceQueryParam(param.value(), method.getArguments()[i]);
            }
          }
        }
    
        //Do something with builder.build().toString()); 
    
        return method.proceed();
      }
    
    }
    

    I wasn’t sure what QueryContext class was in your code – but you could find that in the method also and perform the setUrl method in the interceptor…

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

Sidebar

Related Questions

I have some service that I can query: http://localhost/myservice/data?key=value Is there a way I
Is there any way to have a default MessageBox.Show() caption? Let says I would
Is there a way to get any query parameter without explicitly declaring its name
Is there any way to get RouteData from a url string? I have login
I have a showall query string parameter in the url, the parameter is being
Is there a way to have setup/teardown code automagically run before/after each test? Something
Is there a way to have a template specialization based on a range of
Is there a way to have ASP classic cdonts email, have an file attached
Is there a way to have hanging operators when indenting with tabs in Vim?
Is there a way to have rails print out a number with commas in

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.