You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Dev1 <de...@gmail.com> on 2013/08/01 02:38:02 UTC
Re: CXF Web client test with mock URL
Thank you. I am able to get to connect to the mock url now. I start the
server and I am testing my service methods from the browser directly. But
now, I do not see the XSLT being used on the url path params or query params
- Basically the output of the method does not contain the xslt output. Not
sure what I am missing here.
When I debugged the xsltjabxprovider related stuff seem not to be picked up.
I am not sure if I missed any other setting??
Any help is highly appreciated.
Below is the code of the server and interface, Impl class and xslt.
*Server:*
private static void startServer() throws Exception {
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(<MyWSServiceInterface>.class);
List providers = new ArrayList();
// add custom providers if any
XSLTJaxbProvider provider = new XSLTJaxbProvider();
Map xsltMap = new HashMap();
xsltMap.put("text/xml", "classpath:/xslt/TextToFilterXML.xsl");
provider.setInMediaTemplates(xsltMap);
provider.setResolver(new URIResolverImpl());
providers.add(provider);
sf.setProviders(providers);
sf.setResourceProvider(<MyWSServiceInterface>.class, new
SingletonResourceProvider(
new MyWSServiceImpl(), true));
sf.setAddress(http://localhost:9000/);
server = sf.create();
}
*MyWSServiceInterface:*
public interface MyWSServiceInterface{
@GET
@Path("/myserviceMthd/{domain}/{userId}")
@Produces("text/xml")
public String myserviceMthd(@PathParam("domain") String domain,
@PathParam("userId") String userId;
}
*MyWSImpl:*
public interface MyWSServiceImpl{
@GET
@Path("/myserviceMthd/{domain}/{userId}")
@Produces("text/xml")
public String myserviceMthd(@PathParam("domain") String domain,
@PathParam("userId") String userId
{
//I need to show the xslt output here?? How??
}
*XSLT:*
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:filter="Filter"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="*">
<name:name version="String" xmlns:name="name">
<xsl:call-template name="main">
<xsl:with-param name="<b>domain*" select="''"/*>*
</xsl:call-template>
</doamin:domain>
</xsl:template>
<xsl:template name="main">
<xsl:variable name="inputValue" select="$domain"/>
<xsl:value-of select="$inputValue" disable-output-escaping="yes"/>
<xsl:if test="string-length($inputValue)>0">
<domainName>
<xsl:value-of select="."/>
</domainName>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-Web-client-test-with-mock-URL-tp5731684p5731726.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: CXF Web client test with mock URL
Posted by Sergey Beryozkin <sb...@gmail.com>.
That said, may be XSLTJaxabProvider can actually support String and wrap
it internally into Document or something else that JAXB will understand,
I'll think about it
Cheers, Sergey
On 04/08/13 22:27, Sergey Beryozkin wrote:
> Yes, you need to do a non JAXB XSLT provider if XSLT XML input is
> represented as String.
>
> Injecting JAX-RS UriInfo context inside that provider will help the
> actual path and query parameters
>
> Cheers, Sergey
> On 03/08/13 04:45, Dev1 wrote:
>> Usecase:
>> url example -
>> http://localhost:port:myserviceMthd/domainNameXYZ/userIDAbc?client=ppp
>> From the above url,I need to get the path and query values and
>> pass them to
>> the xslt that
>> addes the path and query values to a XML string. So the XSLT output -
>> <?xml version="1.0" encoding="UTF-8"?>
>> <domainName>domainNameXYZ</domainName>
>>
>> I need to make use of that xml in the application logic.
>>
>> All this needs to be done at the webservice Impl class
>>
>> Since I am not doing any thing with result of the method, I did not
>> make it
>> as JAXBElement.
>>
>> Instead, I made the method paramater domain as @XMLElement but nothing
>> happens.
>> MyWSImpl:
>>
>> @XmlElement String dmn;
>> public class MyWSServiceImpl implements MyWSService{
>> @GET
>> @Path("/myserviceMthd/{domain}/{userId}")
>> @Produces("text/xml")
>> @WebMethod
>> public String myserviceMthd(@PathParam("domain") String domain,
>> @PathParam("userId") String userId
>> {
>>
>> dmn = domain;
>>
>>
>> }
>>
>>
>> How to get hold of the injected xsltJaxbprovider and execute it with url
>> values (so that I can get the output of the xslt as a XML string)?
>>
>> Instead do you want me to use a custom provider which does NOT use
>> XSLTJaxb
>> databinding?
>>
>>
>>
>> --
>> View this message in context:
>> http://cxf.547215.n5.nabble.com/CXF-Web-client-test-with-mock-URL-tp5731684p5731921.html
>>
>> Sent from the cxf-user mailing list archive at Nabble.com.
>>
>
>
Re: CXF Web client test with mock URL
Posted by Sergey Beryozkin <sb...@gmail.com>.
Yes, you need to do a non JAXB XSLT provider if XSLT XML input is
represented as String.
Injecting JAX-RS UriInfo context inside that provider will help the
actual path and query parameters
Cheers, Sergey
On 03/08/13 04:45, Dev1 wrote:
> Usecase:
> url example -
> http://localhost:port:myserviceMthd/domainNameXYZ/userIDAbc?client=ppp
> From the above url,I need to get the path and query values and pass them to
> the xslt that
> addes the path and query values to a XML string. So the XSLT output -
> <?xml version="1.0" encoding="UTF-8"?>
> <domainName>domainNameXYZ</domainName>
>
> I need to make use of that xml in the application logic.
>
> All this needs to be done at the webservice Impl class
>
> Since I am not doing any thing with result of the method, I did not make it
> as JAXBElement.
>
> Instead, I made the method paramater domain as @XMLElement but nothing
> happens.
> MyWSImpl:
>
> @XmlElement String dmn;
> public class MyWSServiceImpl implements MyWSService{
> @GET
> @Path("/myserviceMthd/{domain}/{userId}")
> @Produces("text/xml")
> @WebMethod
> public String myserviceMthd(@PathParam("domain") String domain,
> @PathParam("userId") String userId
> {
>
> dmn = domain;
>
>
> }
>
>
> How to get hold of the injected xsltJaxbprovider and execute it with url
> values (so that I can get the output of the xslt as a XML string)?
>
> Instead do you want me to use a custom provider which does NOT use XSLTJaxb
> databinding?
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/CXF-Web-client-test-with-mock-URL-tp5731684p5731921.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: CXF Web client test with mock URL
Posted by Dev1 <de...@gmail.com>.
Usecase:
url example -
http://localhost:port:myserviceMthd/domainNameXYZ/userIDAbc?client=ppp
From the above url,I need to get the path and query values and pass them to
the xslt that
addes the path and query values to a XML string. So the XSLT output -
<?xml version="1.0" encoding="UTF-8"?>
<domainName>domainNameXYZ</domainName>
I need to make use of that xml in the application logic.
All this needs to be done at the webservice Impl class
Since I am not doing any thing with result of the method, I did not make it
as JAXBElement.
Instead, I made the method paramater domain as @XMLElement but nothing
happens.
MyWSImpl:
@XmlElement String dmn;
public class MyWSServiceImpl implements MyWSService{
@GET
@Path("/myserviceMthd/{domain}/{userId}")
@Produces("text/xml")
@WebMethod
public String myserviceMthd(@PathParam("domain") String domain,
@PathParam("userId") String userId
{
dmn = domain;
}
How to get hold of the injected xsltJaxbprovider and execute it with url
values (so that I can get the output of the xslt as a XML string)?
Instead do you want me to use a custom provider which does NOT use XSLTJaxb
databinding?
--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-Web-client-test-with-mock-URL-tp5731684p5731921.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: CXF Web client test with mock URL
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
I'm not quite sure what you mean by
"//I need to show the xslt output here?? How??"
inside the method implementation ?
Actually, I've typed and realized why the provider won't be selected.
Your method returns 'String' - XSLTJaxbProvider extends JAXB provider
and expects an actual object be a JAXB bean because it works with JAXB
Marshaller.
Do you have XML as String ? If so wrap it into JAXBElement, or simply
add your own custom provider which will wrap String into StreamSource...
Cheers, Sergey
On 01/08/13 01:38, Dev1 wrote:
> Thank you. I am able to get to connect to the mock url now. I start the
> server and I am testing my service methods from the browser directly. But
> now, I do not see the XSLT being used on the url path params or query params
> - Basically the output of the method does not contain the xslt output. Not
> sure what I am missing here.
>
> When I debugged the xsltjabxprovider related stuff seem not to be picked up.
> I am not sure if I missed any other setting??
>
> Any help is highly appreciated.
>
> Below is the code of the server and interface, Impl class and xslt.
>
> *Server:*
>
> private static void startServer() throws Exception {
> JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
> sf.setResourceClasses(<MyWSServiceInterface>.class);
> List providers = new ArrayList();
> // add custom providers if any
> XSLTJaxbProvider provider = new XSLTJaxbProvider();
> Map xsltMap = new HashMap();
> xsltMap.put("text/xml", "classpath:/xslt/TextToFilterXML.xsl");
> provider.setInMediaTemplates(xsltMap);
> provider.setResolver(new URIResolverImpl());
> providers.add(provider);
> sf.setProviders(providers);
> sf.setResourceProvider(<MyWSServiceInterface>.class, new
> SingletonResourceProvider(
> new MyWSServiceImpl(), true));
> sf.setAddress(http://localhost:9000/);
> server = sf.create();
> }
>
>
> *MyWSServiceInterface:*
>
> public interface MyWSServiceInterface{
> @GET
> @Path("/myserviceMthd/{domain}/{userId}")
> @Produces("text/xml")
> public String myserviceMthd(@PathParam("domain") String domain,
> @PathParam("userId") String userId;
> }
>
>
> *MyWSImpl:*
>
> public interface MyWSServiceImpl{
> @GET
> @Path("/myserviceMthd/{domain}/{userId}")
> @Produces("text/xml")
> public String myserviceMthd(@PathParam("domain") String domain,
> @PathParam("userId") String userId
> {
> //I need to show the xslt output here?? How??
> }
>
>
> *XSLT:*
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="2.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:filter="Filter"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:fn="http://www.w3.org/2005/xpath-functions">
> <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
> <xsl:template match="*">
> <name:name version="String" xmlns:name="name">
> <xsl:call-template name="main">
> <xsl:with-param name="<b>domain*" select="''"/*>*
> </xsl:call-template>
> </doamin:domain>
> </xsl:template>
> <xsl:template name="main">
> <xsl:variable name="inputValue" select="$domain"/>
> <xsl:value-of select="$inputValue" disable-output-escaping="yes"/>
> <xsl:if test="string-length($inputValue)>0">
> <domainName>
> <xsl:value-of select="."/>
> </domainName>
>
> </xsl:if>
>
> </xsl:template>
> </xsl:stylesheet>
>
>
>
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/CXF-Web-client-test-with-mock-URL-tp5731684p5731726.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