You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@wink.apache.org by Paulo Borges <ab...@hotmail.com> on 2010/07/20 00:48:06 UTC

Posting an xml document

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

RE: Posting an xml document

Posted by Paulo Borges <ab...@hotmail.com>.
I believe, I must have been a typo in the xml header. I ran tcpMon on my xml file with firefox poster and then replaced my header with the one taken from tcpMon view and I then ran my junit test and it worked. I must have been a long day yesterday. I do apologize for the inconvience that I should have caught. I guess I had a long busy day yesterday and though I spent a few hours checking the xml string still not able to catch it.

Good thing RAD 7.5.5 comes with TCPMON and I loved it!! thank you for reminding me of that

________________________________
> Subject: RE: Posting an xml document
> To: wink-user@incubator.apache.org
> From: nlgallar@us.ibm.com
> Date: Tue, 20 Jul 2010 09:20:06 -0500
>
>
>
> Paulo, just to clarify, does that mean everything is fine with the XML
>
> declaration as well? Or, do you only see content in tcpmon without the
>
> declaration?
>
>
>
> -Nick
>
>
>
>
>
>
>
>
>
>
>
> [Inactive hide details for Paulo Borges ---07/20/2010 09:13:15 AM---Thank you for the hint, I ran tcpMon and everything is fine]Paulo Borges ---07/20/2010 09:13:15 AM---Thank you for the hint, I ran tcpMon and everything is fine now.
>
>
>
>
>
>
>
>
>
> Paulo Borges
>
> 07/20/2010 09:11 AM
>
> Please respond to
>
> wink-user@incubator.apache.org
>
>
>
>
>
>
>
>
>
>
>
> To
>
>
> Wink user group
>
>
>
>
> cc
>
>
>
>
>
>
>
> Subject
>
>
> RE: Posting an xml document
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Thank you for the hint, I ran tcpMon and everything is fine now.
>
> ----------------------------------------
>
>> From: abudar63@hotmail.com
>
>> To: wink-user@incubator.apache.org
>
>> Subject: RE: Posting an xml document
>
>> Date: Tue, 20 Jul 2010 13:35:14 +0000
>
>>
>
>>
>
>> Hi:
>
>>
>
>> After some trial and error, I noticed that if I remove
>
>> from my xml, then
>
>> everything works. However, adding that header will cause the code to
>
>> crash. is there a reason that the above xml header causes it to fail?
>
>> (It is included in all my server responses when I use build on an
>
>> object). My client builds the xml into a stringbuffer and then sends is
>
>> as string.
>
>>
>
>>
>
>>
>
>> ----------------------------------------
>
>>> Date: Mon, 19 Jul 2010 22:08:38 -0500
>
>>> Subject: Re: Posting an xml document
>
>>> From: rott@apache.org
>
>>> To: wink-user@incubator.apache.org
>
>>>
>
>>> 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 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 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
>
>>>>
>
>>
>
>> _________________________________________________________________
>
>> Learn more ways to connect with your buddies now
>
>> http://go.microsoft.com/?linkid=9734388
>
>
>
> _________________________________________________________________
>
> Turn down-time into play-time with Messenger games
>
> http://go.microsoft.com/?linkid=9734385
 		 	   		  
_________________________________________________________________
Game on: Challenge friends to great games on Messenger
http://go.microsoft.com/?linkid=9734387

RE: Posting an xml document

Posted by Nicholas L Gallardo <nl...@us.ibm.com>.
Paulo, just to clarify, does that mean everything is fine with the XML
declaration as well?  Or, do you only see content in tcpmon without the
declaration?

-Nick






                                                                           
             Paulo Borges                                                  
             <abudar63@hotmail                                             
             .com>                                                      To 
                                       Wink user group                     
             07/20/2010 09:11          <wi...@incubator.apache.org>    
             AM                                                         cc 
                                                                           
                                                                   Subject 
             Please respond to         RE: Posting an xml document         
             wink-user@incubat                                             
               or.apache.org                                               
                                                                           
                                                                           
                                                                           
                                                                           






Thank you for the hint, I ran tcpMon and everything is fine now.
----------------------------------------
> From: abudar63@hotmail.com
> To: wink-user@incubator.apache.org
> Subject: RE: Posting an xml document
> Date: Tue, 20 Jul 2010 13:35:14 +0000
>
>
> Hi:
>
> After some trial and error, I noticed that if I remove
>  from my xml, then
> everything works. However, adding that header will cause the code to
> crash. is there a reason that the above xml header causes it to fail?
> (It is included in all my server responses when I use build on an
> object). My client builds the xml into a stringbuffer and then sends is
> as string.
>
>
>
> ----------------------------------------
>> Date: Mon, 19 Jul 2010 22:08:38 -0500
>> Subject: Re: Posting an xml document
>> From: rott@apache.org
>> To: wink-user@incubator.apache.org
>>
>> 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 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 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
>>>
>
> _________________________________________________________________
> Learn more ways to connect with your buddies now
> http://go.microsoft.com/?linkid=9734388

_________________________________________________________________
Turn down-time into play-time with Messenger games
http://go.microsoft.com/?linkid=9734385

RE: Posting an xml document

Posted by Paulo Borges <ab...@hotmail.com>.

Thank you for the hint, I ran tcpMon and everything is fine now.
----------------------------------------
> From: abudar63@hotmail.com
> To: wink-user@incubator.apache.org
> Subject: RE: Posting an xml document
> Date: Tue, 20 Jul 2010 13:35:14 +0000
>
>
> Hi:
>
> After some trial and error, I noticed that if I remove
>  from my xml, then
> everything works. However, adding that header will cause the code to
> crash. is there a reason that the above xml header causes it to fail?
> (It is included in all my server responses when I use build on an
> object). My client builds the xml into a stringbuffer and then sends is
> as string.
>
>
>
> ----------------------------------------
>> Date: Mon, 19 Jul 2010 22:08:38 -0500
>> Subject: Re: Posting an xml document
>> From: rott@apache.org
>> To: wink-user@incubator.apache.org
>>
>> 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 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 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
>>>
>
> _________________________________________________________________
> Learn more ways to connect with your buddies now
> http://go.microsoft.com/?linkid=9734388
 		 	   		  
_________________________________________________________________
Turn down-time into play-time with Messenger games
http://go.microsoft.com/?linkid=9734385

RE: Posting an xml document

Posted by Paulo Borges <ab...@hotmail.com>.
Hi:

After some trial and error, I noticed that if I remove 
<?xml version="1.0" encoding="UTF-8"?> from my xml, then 
everything works. However, adding that header will cause the code to 
crash. is there a reason that the above xml header causes it to fail? 
(It is included in all my server responses when I use build on an 
object). My client builds the xml into a stringbuffer and then sends is 
as string. 



----------------------------------------
> Date: Mon, 19 Jul 2010 22:08:38 -0500
> Subject: Re: Posting an xml document
> From: rott@apache.org
> To: wink-user@incubator.apache.org
>
> 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  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  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
>>
 		 	   		  
_________________________________________________________________
Learn more ways to connect with your buddies now
http://go.microsoft.com/?linkid=9734388

Re: Posting an xml document

Posted by Mike Rheinheimer <ro...@apache.org>.
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 <br...@gmail.com> 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 <ab...@hotmail.com> 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
>

Re: Posting an xml document

Posted by Bryant Luk <br...@gmail.com>.
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 <ab...@hotmail.com> 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