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

  • Home
  • SEARCH
  • 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 6604663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:11:12+00:00 2026-05-25T19:11:12+00:00

For some reason, I haven’t found any normal way to do the following: I

  • 0

For some reason, I haven’t found any normal way to do the following:

I want to Post a json object, and add additional parameters to the call (in this case, an authentication token).
This is a simple RESTful server in myUrl/server, which should give access to different resources of a “person” in the url myUrl/server/person/personCode/resourceName.

GET is easy, and requires no object, only parameters.
The problem arrises when I get to POST – how do I attach the JSON, and keep the other parameters as well?

The class (much has been removed for clarity and proprietary reasons…):

//Handles the person's resources
@Path("/person/{personCode}/{resourceName}")
public class PersonResourceProvider {

@GET
@Produces("application/json")
public String getPersonResource(@PathParam("personCode") String personCode, @PathParam("resourceName") String resourceName, @DefaultValue("") @QueryParam("auth_token") String auth_token) throws UnhandledResourceException, UnauthorizedAccessException {

    //Authenticates the user in some way, throwing an exception when needed...
    authenticate(personCode, auth_token, resourceName);

    //Returns the resource somehow...
}

@POST
@Produces("application/json")
public String postPersonResource(@PathParam("personCode") String personCode, @PathParam("resourceName") String resourceName, @DefaultValue("") @QueryParam("resourceData") String resourceData, @DefaultValue("") @QueryParam("auth_token") String auth_token) throws UnhandledResourceException, UnauthorizedAccessException {

    //Again, authenticating
    authenticate(personCode, auth_token, resourceName);

    //Post the given resource
    }
}

Now, the GET method works perfectly, when you go to
myUrl/person/personCode/resourceName, it gives me the correct resource.
The auth_token is used with every single call to the server (for now, authentication is done by comparing with a predefined string), so it’s needed. All the other parameters are provided through the path, except for the authentication token, which should not be in the path as it does not relate to the identity of the required resource.

When I get to POST, it’s a problem.
I know there’s a way to tell the method it consumes a JSON, but in that case, what will happen to the other parameters (auth_token is one of them)?
Should I use Multipart?

Another related question, this is the first time I’ve designed such a server, is this design correct?

Thanks!

  • 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-05-25T19:11:13+00:00Added an answer on May 25, 2026 at 7:11 pm

    Found!

    Client side:

    Client c = Client.create();
    WebResource service = c.resource("www.yourserver.com/");
    String s = service.path("test/personCode/resourceName")
                    .queryParam("auth_token", "auth")
                    .type("text/plain")
                    .post(String.class, jsonString);
    

    Server side:

    import com.sun.jersey.api.client.Client;
    import com.sun.jersey.api.client.WebResource;
    
    @Path("/test/{personCode}/{resourceName}")
    public class TestResourceProvider {
    
    @POST
    @Consumes("text/plain")
    @Produces("application/json")
    public String postUserResource(String jsonString,                                              
                                   @PathParam("personCode") String personCode,                                                                                      
                                   @PathParam("resourceName") String resourceName,                                                   
                                   @QueryParam("auth_token") String auth_token)                                                  
                                   throws UnhandledResourceException {
    
        //Do whatever...    
    
        }
    }
    

    In my case, I will parse the json I get in the server depending on the resource name, but you can also pass the object itself, and make the server consume an “application/json”.

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

Sidebar

Related Questions

For some reason, I can't add new gems (which haven't been donwloaded/used before) to
I searched (trust me!) but for some reason, haven't quite found the answer I'm
I have a following program but for some reason it is throwing an error
for some reason, the following code doesn't work. I don't understand where the issue
Fiddle: http://jsfiddle.net/YbfZG/4/ For some reason the toggleDiv/removeDiv functions aren't working (I haven't used jsfiddle
For some reason I can no longer post a comment as an Anonymous user
I know there are similar questions to this one, but I haven't found any
For some reason I haven't quite gotten the hang of how Rails interacts with
We haven't changed anything and for some reason wordpress will no longer keep the
I haven't seen a very clear answer on this one. For some reason I

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.