You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by jbright <jo...@gmail.com> on 2012/10/19 10:46:46 UTC

Testing JAX-RS which @Consumes ("application/xml") and @Produces ("application/xml")

I've a JAX-RS service operation designed which need to *Consume XML * and
*product XML*.

I gave the annotations like this:

@Path ("/getEmployee")
@Produces ("application/xml")
@Consumes ("application/xml")
public Employee getEmployee(EmpRequest req) {......}

Now, how do I test this?  Is there a testing tool to test this?

Help please...



--
View this message in context: http://cxf.547215.n5.nabble.com/Testing-JAX-RS-which-Consumes-application-xml-and-Produces-application-xml-tp5716985.html
Sent from the cxf-user mailing list archive at Nabble.com.

RE: Testing JAX-RS which @Consumes ("application/xml") and @Produces ("application/xml")

Posted by "KARR, DAVID" <dk...@att.com>.
> -----Original Message-----
> From: jbright [mailto:johnbright.j@gmail.com]
> Sent: Sunday, October 21, 2012 11:09 PM
> To: users@cxf.apache.org
> Subject: RE: Testing JAX-RS which @Consumes ("application/xml") and
> @Produces ("application/xml")
> 
> David,
> 
> I tried using SOAPUI which I'm already using for SOAP service.
> 
> How do I provide the XML input for my REST service operation which have
> the
> annotation @Consumes ("application/xml") ?

I'd say you need to read the SoapUI documentation.  If you've created the testing project from your project's WADL, it will create templates for tests for all of your operations.  Just open up the "request" object and paste your XML content into the outgoing content and submit it.


RE: Testing JAX-RS which @Consumes ("application/xml") and @Produces ("application/xml")

Posted by jbright <jo...@gmail.com>.
David, 

I tried using SOAPUI which I'm already using for SOAP service.

How do I provide the XML input for my REST service operation which have the
annotation @Consumes ("application/xml") ?

I couldn't follow this 



--
View this message in context: http://cxf.547215.n5.nabble.com/Testing-JAX-RS-which-Consumes-application-xml-and-Produces-application-xml-tp5716985p5717085.html
Sent from the cxf-user mailing list archive at Nabble.com.

RE: [JAX-RS] StreamingOutput implementation - must I close the outputstream?

Posted by "Muller, Anthony" <an...@sap.com>.
Perfect, thanks Sergey :)

-----Original Message-----
From: Sergey Beryozkin [mailto:sberyozkin@gmail.com] 
Sent: lundi 22 octobre 2012 16:35
To: users@cxf.apache.org
Subject: Re: [JAX-RS] StreamingOutput implementation - must I close the outputstream?

Hi
On 22/10/12 14:39, Muller, Anthony wrote:
> Hello,
>
> When implementing a StreamingOutput, must I close the outputstream at the end of the  write(OutputStream) method?

I think you should do flush() on the output stream whenever the data has 
been written, close() itself is optional, it will be up to the container 
to close it...

Cheers, Sergey

>
> Thanks and regards,
> Anthony


Re: [JAX-RS] StreamingOutput implementation - must I close the outputstream?

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 22/10/12 14:39, Muller, Anthony wrote:
> Hello,
>
> When implementing a StreamingOutput, must I close the outputstream at the end of the  write(OutputStream) method?

I think you should do flush() on the output stream whenever the data has 
been written, close() itself is optional, it will be up to the container 
to close it...

Cheers, Sergey

>
> Thanks and regards,
> Anthony


[JAX-RS] StreamingOutput implementation - must I close the outputstream?

Posted by "Muller, Anthony" <an...@sap.com>.
Hello,

When implementing a StreamingOutput, must I close the outputstream at the end of the  write(OutputStream) method?

Thanks and regards,
Anthony

RE: Testing JAX-RS which @Consumes ("application/xml") and @Produces ("application/xml")

Posted by "KARR, DAVID" <dk...@att.com>.
> -----Original Message-----
> From: jbright [mailto:johnbright.j@gmail.com]
> Sent: Friday, October 19, 2012 1:47 AM
> To: users@cxf.apache.org
> Subject: Testing JAX-RS which @Consumes ("application/xml") and
> @Produces ("application/xml")
> 
> I've a JAX-RS service operation designed which need to *Consume XML *
> and
> *product XML*.
> 
> I gave the annotations like this:
> 
> @Path ("/getEmployee")
> @Produces ("application/xml")
> @Consumes ("application/xml")
> public Employee getEmployee(EmpRequest req) {......}
> 
> Now, how do I test this?  Is there a testing tool to test this?

Sergey pointed you to examples of how you could write automated tests for this.  If you're simply looking for an application that can help you manually test this, then SoapUI from SmartBear software is a good tool for this (there is a free version).


Re: Testing JAX-RS which @Consumes ("application/xml") and @Produces ("application/xml")

Posted by jbright <jo...@gmail.com>.
I tried as you suggested.... 

sf.setResourceProvider(SalesRequest.class, 
                                    new SingletonResourceProvider(new
SalesRequest(), true)); 


Ended with below 

Oct 22, 2012 2:37:40 PM org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean
checkResources
SEVERE: No resource classes found



--
View this message in context: http://cxf.547215.n5.nabble.com/Testing-JAX-RS-which-Consumes-application-xml-and-Produces-application-xml-tp5716985p5717111.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Testing JAX-RS which @Consumes ("application/xml") and @Produces ("application/xml")

Posted by jbright <jo...@gmail.com>.
Sergey / David

Could you please help me by a sample.... I'm having hard time with this..

my xml will be exactly like this

<SalesRequest>
  <Credentials>
    <AppId>SALESTALK</AppId>
    <Password>Gimmick</Password>
    <SecurityToken>Gimmick</SecurityToken>
  </Credentials>
  <Params>
    <FirstName>SIMON</FirstName>
  </Params>
</SalesRequest>

Hence SalesRequest is the class that gets passed in the service operation
method as parameter...
So how do I send the request?



--
View this message in context: http://cxf.547215.n5.nabble.com/Testing-JAX-RS-which-Consumes-application-xml-and-Produces-application-xml-tp5716985p5717174.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Testing JAX-RS which @Consumes ("application/xml") and @Produces ("application/xml")

Posted by jbright <jo...@gmail.com>.
The annotation is there as like this...

@XmlRootElement (name = "SalesRequest")



--
View this message in context: http://cxf.547215.n5.nabble.com/Testing-JAX-RS-which-Consumes-application-xml-and-Produces-application-xml-tp5716985p5717115.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Testing JAX-RS which @Consumes ("application/xml") and @Produces ("application/xml")

Posted by Sergey Beryozkin <sb...@gmail.com>.
On 22/10/12 10:05, jbright wrote:
> So if the Schema renders an XML like this:
>
> <SalesRequest>
>    <Credentials>
>      <AppId>SALESTALK</AppId>
>      <Password>Gimmick</Password>
>      <SecurityToken>Gimmick</SecurityToken>
>    </Credentials>
>    <Params>
>      <FirstName>SIMON</FirstName>
>    </Params>
> </SalesRequest>
>
> The root resource becomes SalesRequest. - right?
>
> So I can substitute as like this?
>
> sf.setResourceProvider(SalesRequest.class,
> 	                            new SingletonResourceProvider(new
> SalesRequest(), true));
>
> - right?
>
No, the above is some specific representation, JAX-RS root resource 
class is the one that you'd like to test, the one that has that signature

Sergey

>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Testing-JAX-RS-which-Consumes-application-xml-and-Produces-application-xml-tp5716985p5717107.html
> Sent from the cxf-user mailing list archive at Nabble.com.


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Re: Testing JAX-RS which @Consumes ("application/xml") and @Produces ("application/xml")

Posted by jbright <jo...@gmail.com>.
So if the Schema renders an XML like this:

<SalesRequest>
  <Credentials>
    <AppId>SALESTALK</AppId>
    <Password>Gimmick</Password>
    <SecurityToken>Gimmick</SecurityToken>
  </Credentials>
  <Params>
    <FirstName>SIMON</FirstName>
  </Params>
</SalesRequest>

The root resource becomes SalesRequest. - right?

So I can substitute as like this?

sf.setResourceProvider(SalesRequest.class,
	                            new SingletonResourceProvider(new
SalesRequest(), true));

- right?



--
View this message in context: http://cxf.547215.n5.nabble.com/Testing-JAX-RS-which-Consumes-application-xml-and-Produces-application-xml-tp5716985p5717107.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Testing JAX-RS which @Consumes ("application/xml") and @Produces ("application/xml")

Posted by Sergey Beryozkin <sb...@gmail.com>.
On 22/10/12 07:23, jbright wrote:
> I looked at what you said, but pls explain me this:
>
> sf.setResourceProvider(MyJaxrsResource.class.class,
> 	                            new SingletonResourceProvider(*new
> MyJaxrsResource()*, true));
>
> Which class is that *new MyJaxrsResource()* ?

This is a root resource class

Sergey

>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Testing-JAX-RS-which-Consumes-application-xml-and-Produces-application-xml-tp5716985p5717086.html
> Sent from the cxf-user mailing list archive at Nabble.com.

Re: Testing JAX-RS which @Consumes ("application/xml") and @Produces ("application/xml")

Posted by jbright <jo...@gmail.com>.
Hi Selva, 

I tried your suggestion earlier and ended up with Respose-Codes 406, 415
etc...  which never goes.. :(

My request object is like this.

<SalesRequest>
  <Credentials>
    <AppId>SALESTALK</AppId>
    <Password>Gimmick</Password>
    <SecurityToken>Gimmick</SecurityToken>
  </Credentials>
  <Params>
    <FirstName>SIMON</FirstName>
  </Params>
</SalesRequest>

If you have an id to chat (gTalk) ... please let me know... 
Hope you have very good experience in this.



--
View this message in context: http://cxf.547215.n5.nabble.com/Testing-JAX-RS-which-Consumes-application-xml-and-Produces-application-xml-tp5716985p5717098.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Testing JAX-RS which @Consumes ("application/xml") and @Produces ("application/xml")

Posted by selvakumar netaji <vv...@gmail.com>.
Hi John,

Can you please try it with the RestClient. With rest client you can send a
xml request payload by making use of the JAXB2.0 annotated classes.

On Mon, Oct 22, 2012 at 11:53 AM, jbright <jo...@gmail.com> wrote:

> I looked at what you said, but pls explain me this:
>
> sf.setResourceProvider(MyJaxrsResource.class.class,
>                                     new SingletonResourceProvider(*new
> MyJaxrsResource()*, true));
>
> Which class is that *new MyJaxrsResource()* ?
>
>
>
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/Testing-JAX-RS-which-Consumes-application-xml-and-Produces-application-xml-tp5716985p5717086.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>

Re: Testing JAX-RS which @Consumes ("application/xml") and @Produces ("application/xml")

Posted by jbright <jo...@gmail.com>.
I looked at what you said, but pls explain me this:

sf.setResourceProvider(MyJaxrsResource.class.class,
	                            new SingletonResourceProvider(*new
MyJaxrsResource()*, true));

Which class is that *new MyJaxrsResource()* ?



--
View this message in context: http://cxf.547215.n5.nabble.com/Testing-JAX-RS-which-Consumes-application-xml-and-Produces-application-xml-tp5716985p5717086.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Testing JAX-RS which @Consumes ("application/xml") and @Produces ("application/xml")

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 19/10/12 09:46, jbright wrote:
> I've a JAX-RS service operation designed which need to *Consume XML * and
> *product XML*.
>
> I gave the annotations like this:
>
> @Path ("/getEmployee")
> @Produces ("application/xml")
> @Consumes ("application/xml")
> public Employee getEmployee(EmpRequest req) {......}
>
> Now, how do I test this?  Is there a testing tool to test this?
>

Have a look at

https://cwiki.apache.org/confluence/display/CXF20DOC/JAXRS+Testing

Cheers, Sergey

> Help please...
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Testing-JAX-RS-which-Consumes-application-xml-and-Produces-application-xml-tp5716985.html
> Sent from the cxf-user mailing list archive at Nabble.com.