Hi Paul
I did some work on weekends and I added two system tests confirming
XSLTJaxbProvider works fine.
I fixed the issue with template parameters not being injected on the client side. With proxies, template parameters can ne quite
easily deducted from the annotations.
WebClient does not know if any template parameters have been handled by UriBuilder or not, it only sees actual URI/path values, for
ex in client.path("/story/1") it can't deduce '1' might be a parameter. Likewise, if say UriBuilder was originally used to handle
template parameters :
URI uri = UriBuilder.fromUri("http://stories/{id}").buildFromEncoded(1);
WebClient client = WebClient.create(uri);
then the client still can't figure out if '1' has been a parameter.
Last week I added a new WebClient method,
path(String relativePath, Object... values)
which does what the UriBuilder code above does and I also updated it a bit yesterday to capture the template parameters, if any, so
one can use this method once 2.2.3 gets released (hopefully in the end of the month or so).
Here's a test case.
1. BookWrapper :
http://svn.apache.org/repos/asf/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookWrapper.java
2. BookStore getWrappedBook :
@GET
@Path("/books/wrapper/{bookId}/")
@Produces("application/xml")
public BookWrapper getWrappedBook(@PathParam("bookId") Long id) throws
BookNotFoundFault {
BookWrapper bw = new BookWrapper();
Book b = new Book("CXF in Action", 99999L);
bw.setBook(b);
return bw;
}3. Client Test : @Test
public void testWebClientUnwrapBookWithXslt() throws Exception {
XSLTJaxbProvider provider = new XSLTJaxbProvider();
provider.setInTemplate("classpath:/org/apache/cxf/systest/jaxrs/resources/unwrapbook.xsl");
WebClient wc =
WebClient.create("http://localhost:9080/bookstore/books/wrapper",
Collections.singletonList(provider));
wc.path("{id}", 123);
Book book = wc.get(Book.class);
assertNotNull(book);
assertEquals(123L, book.getId());
}
4. http://svn.apache.org/repos/asf/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/resources/unwrapbook.xsl (removes
'wrapper' element. capitalizes 'book' and sets 'id' to '123' as expectd by the client)
Note that query params still can not be injected on the client side (on the
trunk), I'll fix it in time for 2.2.3.
I also have a similar test for proxies but I had to disable it as I was not able to figure out how to bypass the JAXB optimization
for that test only...
If you do need to have some parameters injected right now then you have a
couple of options.
One option is to inject hard-coded in parameters map using 'inParameters' property - this might work if some parameters are common
across multiple invocations.
Another option might be to register a CXF in interceptor (say, RECEIVE phase) which will add MultivaluedMap<String, String> map to
the message, keyed by UriTemplate.TEMPLATE_PARAMETERS. This interceptor can be created on start up and have the knowledge of what
bits of URI can be treated as parameters...
thanks, Sergey
----- Original Message -----
From: "Paul Wilton" <[email protected]>
To: <[email protected]>
Cc: <[email protected]>
Sent: Monday, July 06, 2009 9:54 AM
Subject: RE: trying to use XSLTJaxbProvider with WebClient (JAX_RS)
Hi Sergey
I have copied the XSLTJaxbProvider code into my client, and can confirm
it does work okay with WebClient if the entire MessageContext code block
is commented out (lines 230 - 256)
(obviously I am then ignoring UriInfo and transformer parameters)
Regards
Paul
-----Original Message-----
From: Sergey Beryozkin [mailto:[email protected]]
Sent: 03 July 2009 17:02
To: [email protected]
Subject: Re: trying to use XSLTJaxbProvider with WebClient (JAX_RS)
Hi,
It is a bug - it's probably trying to get the UriInfo from the wrong
message
object when it's used on the client side. I have to investigate. I'm
about
to sign off but I'll get back to you on Monday at the latest.
If you don't mind, you might want to copy that provider source and have
a
client-side version which does not attempt to inject UriInfo details.
thanks for posting a test case - it will help me to get started fast
cheers, Sergey
Paul Wilton wrote:
Hi
I am trying to use the new XSLTJaxbProvider as a provider for the
JAX-RS
WebClient.
I am getting some null pointer exceptions thrown inside the
createTemplates() method of the provider , due to the
ui.getPathParameters() and the ui.getQueryParameters() both
returning null
Below is some test code (not spring wired) - is there something I am
missing, that would ensure the MessageContext creates a UriInfo object
correctly? - or is this simply a bug... if possible do you have
an
example of using XSLTJaxbProvider with WebClient (HttpCentric) to
consume a webservice.
Thanks, Paul
WebClient webClient;
@Before
public void setup(){
Map<String,String> mediaTemplates = new
HashMap<String,String>();
mediaTemplates.put("text/xml","classpath:/story-transform.xsl");
XSLTJaxbProvider xsltJaxbProvider = new XSLTJaxbProvider();
xsltJaxbProvider.setConsumeMediaTypes(new
ArrayList<String>(Arrays.asList("text/xml")));
xsltJaxbProvider.setInMediaTemplates(mediaTemplates);
xsltJaxbProvider.setInParameters(new
HashMap<String,Object>());
List providers = new ArrayList();
providers.add(xsltJaxbProvider);
webClient = WebClient.create(STORY_SERVICE_URL, providers);
//
= URL to RESTful webservice to consume
StoryClient = new StoryClient();
StoryClient.setWebClient(webClient);
}
@Test
public void getStory() {
// assume Story object is annotated to be unmarshalled with
JAXB
on the transofrmed XML
webClient.path("/story").type("text/xml").accept("text/xml");
webClient.query("story","storyId");
Story story = webClient.get(Story.class);
assertTrue(Story!=null);
// assert more stuff
}
This e-mail (and any attachments) is confidential and may contain
personal
views which are not the views of the BBC unless specifically stated.
If
you have received it in error, please delete it from your system. Do
not
use, copy or disclose the information in any way nor act in reliance
on it
and notify the sender immediately.
Please note that the BBC monitors e-mails sent or received. Further
communication will signify your consent to this
This e-mail has been sent by one of the following wholly-owned
subsidiaries of the BBC:
BBC Worldwide Limited, Registration Number: 1420028 England,
Registered
Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ
BBC World News Limited, Registration Number: 04514407 England,
Registered
Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ
BBC World Distribution Limited, Registration Number: 04514408,
Registered
Address: BBC Media Centre, 201 Wood Lane, London, W12 7TQ
--
View this message in context:
http://www.nabble.com/trying-to-use-XSLTJaxbProvider-with-WebClient--%28
JAX_RS%29-tp24324012p24325370.html
Sent from the cxf-user mailing list archive at Nabble.com.