You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "KARR, DAVID (ATTCINW)" <dk...@att.com> on 2010/01/09 20:30:29 UTC

How can I make WebClient in test return raw XML or JSON?

I'm moving forward with my unit tests with the embedded
JAXRSServerFactoryBean.  On almost the first try, I got back the object
that I expected.  I'm using Mockito to mock the physical resources that
my content controller uses.

Although it's nice that the server unmarshalled the XML back into my
Java object, I'd actually like to have some testing where I examine the
raw XML or JSON that I get back.  I don't see an obvious way to do that
with the WebClient class.  Perhaps I shouldn't even be trying, and just
use HttpClient for this kind of test?

Re: How can I make WebClient in test return raw XML or JSON?

Posted by Sergey Beryozkin <sb...@progress.com>.
By the way, doing something like

Response response = webclient.get(Response.class)

(assuming get is used)

may be a better option for testing as one can get to the entity stream, the response status code and the headers easily from 
Response
----- Original Message ----- 
From: "Sergey Beryozkin" <sb...@progress.com>
To: <us...@cxf.apache.org>; <us...@cxf.apache.org>; <us...@cxf.apache.org>
Sent: Monday, January 11, 2010 9:11 AM
Subject: RE: How can I make WebClient in test return raw XML or JSON?


Though using String.class will only work if the content type of the response is set to text/plain. It is possible to configure 
JAXB/JSON providers to recognize text/plain but perhaps it would be simpler to use say InputStream.class and then CXF IOUtils to 
easily copy it into String, for JSON at least.

cheers, Sergey


-----Original Message-----
From: Sergey Beryozkin [mailto:sberyozk@progress.com]
Sent: Mon 1/11/2010 2:16 AM
To: users@cxf.apache.org; users@cxf.apache.org
Subject: RE: How can I make WebClient in test return raw XML or JSON?


Hi

indeed, XMLSource could be a good option for handling the raw XML. String.class should help in retrieving raw XML/JSON...

Document.class and JSONObject are not supported out of the box. I will update the (JAXP) Source provider to support Documents as 
well with a bit of indirection, or may add a new provider...Not sure about JSONObject, but given that Jettison uses it internally, 
may be it would be possible to return it too...

thanks, Sergey

-----Original Message-----
From: Rob Schoening [mailto:robschoening@gmail.com]
Sent: Sun 1/10/2010 12:25 AM
To: users@cxf.apache.org
Subject: Re: How can I make WebClient in test return raw XML or JSON?

Just ask for the kind of object you want, and CXF will abide:

webClient.get(String.class);
webClient.get(InputStream.class);
webClient.get(Document.class);
webClient.get(XMLSource.class);  // probably what you want for picking
through XML output in unit tests
webClient.get(JSONObject.class);  // this one actually might not be
registered by default...

RS


On Sat, Jan 9, 2010 at 11:30 AM, KARR, DAVID (ATTCINW) <dk...@att.com>wrote:

> I'm moving forward with my unit tests with the embedded
> JAXRSServerFactoryBean.  On almost the first try, I got back the object
> that I expected.  I'm using Mockito to mock the physical resources that
> my content controller uses.
>
> Although it's nice that the server unmarshalled the XML back into my
> Java object, I'd actually like to have some testing where I examine the
> raw XML or JSON that I get back.  I don't see an obvious way to do that
> with the WebClient class.  Perhaps I shouldn't even be trying, and just
> use HttpClient for this kind of test?
>




RE: How can I make WebClient in test return raw XML or JSON?

Posted by Sergey Beryozkin <sb...@progress.com>.
Though using String.class will only work if the content type of the response is set to text/plain. It is possible to configure JAXB/JSON providers to recognize text/plain but perhaps it would be simpler to use say InputStream.class and then CXF IOUtils to easily copy it into String, for JSON at least. 

cheers, Sergey  


-----Original Message-----
From: Sergey Beryozkin [mailto:sberyozk@progress.com]
Sent: Mon 1/11/2010 2:16 AM
To: users@cxf.apache.org; users@cxf.apache.org
Subject: RE: How can I make WebClient in test return raw XML or JSON?
 

Hi

indeed, XMLSource could be a good option for handling the raw XML. String.class should help in retrieving raw XML/JSON...

Document.class and JSONObject are not supported out of the box. I will update the (JAXP) Source provider to support Documents as well with a bit of indirection, or may add a new provider...Not sure about JSONObject, but given that Jettison uses it internally, may be it would be possible to return it too...

thanks, Sergey

-----Original Message-----
From: Rob Schoening [mailto:robschoening@gmail.com]
Sent: Sun 1/10/2010 12:25 AM
To: users@cxf.apache.org
Subject: Re: How can I make WebClient in test return raw XML or JSON?
 
Just ask for the kind of object you want, and CXF will abide:

webClient.get(String.class);
webClient.get(InputStream.class);
webClient.get(Document.class);
webClient.get(XMLSource.class);  // probably what you want for picking
through XML output in unit tests
webClient.get(JSONObject.class);  // this one actually might not be
registered by default...

RS


On Sat, Jan 9, 2010 at 11:30 AM, KARR, DAVID (ATTCINW) <dk...@att.com>wrote:

> I'm moving forward with my unit tests with the embedded
> JAXRSServerFactoryBean.  On almost the first try, I got back the object
> that I expected.  I'm using Mockito to mock the physical resources that
> my content controller uses.
>
> Although it's nice that the server unmarshalled the XML back into my
> Java object, I'd actually like to have some testing where I examine the
> raw XML or JSON that I get back.  I don't see an obvious way to do that
> with the WebClient class.  Perhaps I shouldn't even be trying, and just
> use HttpClient for this kind of test?
>



RE: How can I make WebClient in test return raw XML or JSON?

Posted by Sergey Beryozkin <sb...@progress.com>.
Hi

indeed, XMLSource could be a good option for handling the raw XML. String.class should help in retrieving raw XML/JSON...

Document.class and JSONObject are not supported out of the box. I will update the (JAXP) Source provider to support Documents as well with a bit of indirection, or may add a new provider...Not sure about JSONObject, but given that Jettison uses it internally, may be it would be possible to return it too...

thanks, Sergey

-----Original Message-----
From: Rob Schoening [mailto:robschoening@gmail.com]
Sent: Sun 1/10/2010 12:25 AM
To: users@cxf.apache.org
Subject: Re: How can I make WebClient in test return raw XML or JSON?
 
Just ask for the kind of object you want, and CXF will abide:

webClient.get(String.class);
webClient.get(InputStream.class);
webClient.get(Document.class);
webClient.get(XMLSource.class);  // probably what you want for picking
through XML output in unit tests
webClient.get(JSONObject.class);  // this one actually might not be
registered by default...

RS


On Sat, Jan 9, 2010 at 11:30 AM, KARR, DAVID (ATTCINW) <dk...@att.com>wrote:

> I'm moving forward with my unit tests with the embedded
> JAXRSServerFactoryBean.  On almost the first try, I got back the object
> that I expected.  I'm using Mockito to mock the physical resources that
> my content controller uses.
>
> Although it's nice that the server unmarshalled the XML back into my
> Java object, I'd actually like to have some testing where I examine the
> raw XML or JSON that I get back.  I don't see an obvious way to do that
> with the WebClient class.  Perhaps I shouldn't even be trying, and just
> use HttpClient for this kind of test?
>


Re: How can I make WebClient in test return raw XML or JSON?

Posted by Rob Schoening <ro...@gmail.com>.
Just ask for the kind of object you want, and CXF will abide:

webClient.get(String.class);
webClient.get(InputStream.class);
webClient.get(Document.class);
webClient.get(XMLSource.class);  // probably what you want for picking
through XML output in unit tests
webClient.get(JSONObject.class);  // this one actually might not be
registered by default...

RS


On Sat, Jan 9, 2010 at 11:30 AM, KARR, DAVID (ATTCINW) <dk...@att.com>wrote:

> I'm moving forward with my unit tests with the embedded
> JAXRSServerFactoryBean.  On almost the first try, I got back the object
> that I expected.  I'm using Mockito to mock the physical resources that
> my content controller uses.
>
> Although it's nice that the server unmarshalled the XML back into my
> Java object, I'd actually like to have some testing where I examine the
> raw XML or JSON that I get back.  I don't see an obvious way to do that
> with the WebClient class.  Perhaps I shouldn't even be trying, and just
> use HttpClient for this kind of test?
>