user2821894
user2821894

Reputation: 1088

Consuming spring Rest api

I want to create a restful webservice with spring mvc. I followed some tutorials and could work out how to create a webservice with spring. But I am not understanding how to make it work for my requirement. My requirement is a company xyz sends an xml file with its usage details to my company abc. NOw my company has to consume that xml file with spring rest api and store the details in database.Any help is appreciated. In spring webservices I have only seen examples like crud opeartion for employees,persons but how to match it with my requirement. Thanks in advance. Here are sample example I looked into:

"https://www.ibm.com/developerworks/webservices/library/wa-spring3webserv/" "http://spring.io/guides/gs/consuming-rest/"

suppose the following is the xml my rest api is consuming and I want to put those details in a database, how can I do it.

<Usage xmlns="http://www.abc.com/abc/It/schema"       
xmlns:id="http://standards.iso.org/iso/19770/-2/2009/schema.xsd">    
    <timestamp>2010-01-01T12:38:11.123Z</timestamp>    
   <proxy>        
  <address>host address</address>        
 <platforms>xyz</platform>    
 </proxy>    
  <as> <label>Label name</label><name>sdff</name>        
  <id><a_id>34D87XHF72122</a_id><line>sadf</line>                                            
   <title>adffdn<title>
  <version>3.1</version> <creator>abc Corp.</creator>
  <license>abcCorp. </license></id>

Upvotes: 0

Views: 596

Answers (1)

acvcu
acvcu

Reputation: 2506

If the company xyz is sending an XML file to your server, you would want to use a method similar to this to handle the request and not return any content back:

@RequestMapping(value="/xyz", method = RequestMethod.POST, consumes = {"text/xml"})
@ResponseStatus(HttpStatus.OK)
public void processXML(@RequestBody Object someObject) {

}

EDIT: See the Spring docs on @RequestBody: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-ann-requestbody

Upvotes: 1

Related Questions