Error 415 while sending an XML to REST WS

gurutrvesri

New Member
I am trying to mock a WS. I have created following method in WS\[code\]@POST@Consumes (MediaType.APPLICATION_XML)public void dataIn (InputStream inXml){ System.out.println ("data received"); BufferedReader br = new BufferedReader(new InputStreamReader(inXml)); String xml = null; try { while ((xml = br.readLine())!=null){ System.out.println(xml); } } catch (IOException e) { System.out.println ("ouch"); }}\[/code\]and i am sending an XML using my Java client by this code\[code\] String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><rootElem name=\"xml_type\"><info>this_is_test</info></rootElem>"; service.accept(MediaType.APPLICATION_XML).post(xml);\[/code\]But i am getting this exception\[code\]Exception in thread "main" com.sun.jersey.api.client.UniformInterfaceException: POST http://localhost:8080/project/ws/services/1.0/savedata returned a response status of 415\[/code\]I am pretty sure that I am not sending my XML properly. After doing couple of Googling, I couldn't figure out what is wrong i am doing. Since most of the tutorials/help i am finding online is using OBJ > JAXB > XML > JAXB > OBJ translation from client to server. I want to send raw xml and to read raw xml. Can someone suggest me what is wrong i am doing here? I am not sure if answering own questions would result in -ve reputation or not. but after stumbling upon and figuring out things, I used Apache httpclient to send the request and it worked fine. I would request to close the question. \[code\]DefaultHttpClient dhc = new DefaultHttpClient();HttpPost postRequest = new HttpPost("http://localhost:8080/project/ws/services/1.0/savedata");StringEntity se = new StringEntity("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><rootElem name=\"xml_type\"><info>this_is_test</info></rootElem>");se.setContentType("application/xml");postRequest.setEntity(se);HttpResponse response = dhc.execute(postRequest);System.out.println (response.getStatusLine().getStatusCode());\[/code\]
 
Back
Top