简体   繁体   中英

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 wich 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 thou 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?

Thanks in advance

@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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM