0

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?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
SECI
  • 103
  • 2
  • 10

2 Answers2

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.

ali4j
  • 522
  • 3
  • 15
0

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

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 28 '22 at 04:32