I'll echo Bryant's advice. In my experience, whenever I know my XML is good but still get that error, it means nothing was sent. I'd bet getXML() is returning an empty String.
mike On Mon, Jul 19, 2010 at 6:13 PM, Bryant Luk <[email protected]> wrote: > On casual inspection, I would double check what your getXML() method > is returning and if it is the right content. > > Another way you can inspect the message is to use a intermediary such > as TCPMon ( http://ws.apache.org/commons/tcpmon/tcpmontutorial.html ). > Set it up to listen on a port that targets your real service to > verify that the content being sent is correct. > > On Mon, Jul 19, 2010 at 5:48 PM, Paulo Borges <[email protected]> wrote: >> >> Hi: >> >> It seems I have some issues posting an xml document, and I was wondering if >> someone can kindly help or give a hint. My code works fine if I do a post of >> an xml file by using firefox add-on "Post" and unmarshalling from XML to the >> my object is done correctly as well. However, when I try to submit the same >> xml as a string through Wink client api, I get the error that >> >> javax.xml.bind.UnmarshalException: The root element is required in a >> well-formed document >> >> I am sure I am missing something. Here is my client code that does the post >> in the following line: >> >> ClientResponse response = >> getResource().contentType(MediaType.APPLICATION_XML).accept("*/*").post(getXML()); >> >> in the following execute method: >> >> >> public Result execute() { >> try { >> ClientConfig config = new ClientConfig(); >> BasicAuthSecurityHandler secHandler = new BasicAuthSecurityHandler(); >> secHandler.setUserName(getUserId()); >> secHandler.setPassword(getPassword()); >> config.handlers(secHandler); >> config.acceptHeaderAutoSet(true); >> RestClient client = new RestClient(config); >> setResource(client.resource(getServiceURL())); >> ClientResponse response = >> getResource().contentType(MediaType.APPLICATION_XML).accept("*/*").post(getXML()); >> if (response.getStatusCode() == >> Response.Status.SERVICE_UNAVAILABLE.getStatusCode()) >> return new Result(false, "", >> Utility.parseXMLMessage(response.getEntity(String.class))); >> return new Result(true, response.getEntity(String.class), ""); >> >> } catch (org.apache.wink.client.ClientAuthenticationException ae) { >> return new Result(false, "", "Invalid credentials."); >> } catch (Exception e) { >> e.printStackTrace(); >> return new Result(false, "", "An unexpected error was encountered."); >> } >> } >> >> The wink server side method signature is as follows: >> >> �...@post >> �...@path("/provision") >> �...@consumes({MediaType.APPLICATION_XML, MediaType.TEXT_XML}) >> �...@produces( { MediaType.APPLICATION_XML, MediaType.TEXT_XML }) >> public Response provision(Provision provision){ >> ......... >> } >> _________________________________________________________________ >> Learn more ways to connect with your buddies now >> http://go.microsoft.com/?linkid=9734388 >
