-1

Hello I have an API and I created a POST method that sends an xml and if everything is ok it saves the data from xml to database.

I would like to get the xml that the user inputs (for the test case the data that I input in Postman) to check it against xsd schema so no extra tags are in the xml. The second part I figured it out...I just want to know how to get xml from post request

Thanks in advance

SECI
  • 103
  • 2
  • 10
  • No I need to get the data that is being send thru the post method not how to send post request – SECI Nov 13 '19 at 09:50
  • 2
    How do you develop the app that will receive the request? do you use a java web server like Tomcat ? Do you use a framework like Spring, Hibernate ? – JHDev Nov 13 '19 at 10:09
  • The server is ibm liberty and its developed in eclipse as rest app no framwork – SECI Nov 13 '19 at 10:11
  • Do you use EJB? (Enterprise Java Beans) or Java Servlet? – JHDev Nov 13 '19 at 10:24

1 Answers1

1
@GET
@Produces(MediaType.APPLICATION_XML)
@Path("/getXmlObject")
public XmlObject getXmlObject()
{
  XmlObject x = new XmlObject();
  x.setId(1);
  x.setName("XmlObject");
  return x;
}

To be sur that your object is well produced :

@XmlRootElement
public class  XmlObject
{
  private String name;
  private int id;

  public XmlObject()
  {
  }
  // getters and setters
}

The same for your POST method

@POST @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public Object XmlObject(Object object){ //.... }

========================================================================

Real world
  • 11
  • 1