'Sending POST request with POSTMAN to Java REST API and getting null values in the xml response

I am creating a REST Service in Java and now I am building the post method which has 2 parameters that has to be inputted as xml in postman (for test) and get a response as xml in java and insert it in database.

For starters I am trying to add the values as Query Params in POSTMAN with key and value. The response is 200 but the xml is CUI=null Mesaj=null

Both values are null even though I added values for both keys in Postman.

How can it see the values? This is the java code:

@Stateless
@Path("/cererepost")
public class HelloWorldResource {
    Resp x = new Resp();
    @EJB
    private NameStorageBean nameStorage;
    /**
     * Retrieves representation of an instance of    helloworld.HelloWorldResource
     * @return an instance of java.lang.String
     */
    @POST
    @Produces("application/xml")
    @Consumes(MediaType.APPLICATION_XML)
    public Response postMsg(@PathParam("cui") String cui,    @PathParam("mesaj") String mesaj)  {
      
        String xmlString = "CUI=" + cui + " Mesaj=" + mesaj;
        Response response = Response.status(200).type(MediaType.TEXT_XML).entity(xmlString).build();
        return response;
    }
}

What should I modify so I can see the parameter values that I send in the post in the xml that postman is generating?



Solution 1:[1]

@PathParam("cui") String cui this line shows that values from client side should be passed as path parameters, not query string, something like this:

correct: /cererepost/some_value

If you want to get them as query string params in server side, change @PathParam("cui") to @QueryParam("cui").

For understading the differences between query string and path variables take alook at this post.

Solution 2:[2]

in the postman you might miss typed the variables name. It might doesn't much with table that you created using java

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 mahbooba hashimi