How can i format xml input for restful web service and invoke the service

Hi All I expose a service using restFul web service Server side code is

@RequestMapping(value = "/getPerson", method = RequestMethod.POST) public ModelAndView getPerson(@RequestParam("inputXml") String inputXml) {
------------------------- ----------------------------
} return new ModelAndView("userXmlView", BindingResult.MODEL_KEY_PREFIX + String.class, "Test"); }

Client side implementation is:

        URL oracle = new URL("http://localhost:8081/testWeb/restServices/getPerson?inputXml=input");
         System.out.println("Oracle URl is "+oracle);
         HttpURLConnection connection = (HttpURLConnection)oracle.openConnection();
         connection.setDoOutput(true);
        connection.setRequestProperty("Content-type", "application/xml; charset:ISO-8859-1");
        connection.setRequestMethod("POST");
        BufferedReader in = new BufferedReader(new InputStreamReader(
                connection.getInputStream()));
        String inputLine;
       while ((inputLine = in.readLine()) != null) 
            System.out.println(inputLine);  
     in.close(); 

I able to access the service using the URL http://localhost:8081/testWeb/restServices/getPerson?inputXml="input" Actually my requirement is, i need to pass xml string as a input like this

http://localhost:8081/testWeb/restServices/getPerson?inputXml="<?xml%20version="1.0"%20encoding="UTF-8"%20standalone="yes"?><product><code>WI1</code><name>Widget%20Number%20One</name><price>300.0</price></product>"

please help me to find the solution


Maya, /getPerson is not a RESTful URI name. You should use something like /person instead. That way, you can GET it or DELETE it using HTTP.


take a look at RestAssured

given().
       formParam("formParamName", "value1").
       queryParam("queryParamName", "value2").
when().
       post("/something");

or spring RestTemplate

Map<String, String> vars = new HashMap<String, String>();
vars.put("count", "5");
restTemplate.getForObject(person, Person.class, vars);
链接地址: http://www.djcxy.com/p/8608.html

上一篇: 使用JRadioButton作为单元格渲染器停止JTable中的单元格编辑

下一篇: 我如何格式XML输入宁静的Web服务和调用服务