I m trying to post xml from client and consume xml from my service. When i try the following code i m getting unsupported media type exception. I tried to follow this example: http://examples.javacodegeeks.com/enterprise-java/rest/jersey/xml-example-with-jersey-jaxb/ What am i doing wrong ? Any ideas ?
Client side :
private void request(String url,Event event) throws IOException, SAXException { try { Client client = Client.create(); ClientResponse response = null; WebResource webResource = client .resource(url); if(event != null){ response = webResource.accept("application/xml") .post(ClientResponse.class,event); }else{ response = webResource.accept("application/xml") .get(ClientResponse.class); } if (response.getStatus() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatus()); } String output = response.getEntity(String.class); System.out.println("Output from Server .... \n"); System.out.println(output); }catch (Exception e) { e.printStackTrace(); } Server side :
@POST @Path("/created") @Consumes({"application/xml", MediaType.APPLICATION_FORM_URLENCODED,"text/html"}) @Produces ({"application/xml", MediaType.APPLICATION_FORM_URLENCODED,"text/html"}) public Response createEvent( @FormParam("eventtitle") String title, @FormParam("eventtype") String type, @FormParam("eventdescription") String description, @FormParam("eventlocation") String location, @FormParam("eventdate") String date, @FormParam("eventcreationdate") String creationdate, @FormParam("eventmodificationdate") String modificationdate, @Context HttpServletResponse servletResponse) throws IOException { final StringBuilder sb = new StringBuilder(); sb.append( "<h4>Event sucessfully created </h4>"); sb.append("<br></br><li><p><a href=\"/\">go back</a></p></li>"); Response.status(200).entity(sb.toString()).build(); Event event = eventWorker.createEvent(title,type,description,location,date, creationdate,modificationdate); return Response.ok(sb.toString()).cacheControl(CC).build(); }
No comments:
Post a Comment