Hi Gabo
You can probably try to have a single XSLT stylesheet transforming a WADL with some fixed namespace into per-service specific WADL
with the right namespace. The only thing this stylesheet will do is to capture say all http://yournamespace:* elements and copy them
to http://someservice:*, where "http://someservice" can be provided by configuring a transform engine. You can have this stylesheet
running in a ResponseHandler out filter, after the WADLGenerator has produced a WADL
So you might have
<jaxrs:server id="service1">
<jaxrs:serviceBeans>
<ref bean="myResourceClass"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="wadlPostProcessor1"/>
</jaxrs:providers>
</jaxrs:server>
<jaxrs:server id="service2">
<jaxrs:serviceBeans>
<ref bean="myResourceClass"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="wadlPostProcessor2"/>
</jaxrs:providers>
</jaxrs:server>
<bean id="wadlPostProcessor1" class="org.foo.bar.WadlPostProcessor">
<property name="customNamespace" value="http://service1"/>
</bean>
<bean id="wadlPostProcessor1" class="org.foo.bar.WadlPostProcessor">
<property name="customNamespace" value="http://service2"/>
</bean>
WadlPostProcessor is a generic custom ResponeHandler which can be written like
this :
...
private String customNamespace;
private Templates customXsltTemplate;
@Context UriInfo uriInfo;
if (uriInfo.getQueryParameters().get("_wadl") != null) {
String wadlXmlString = (String)Response.getEntity();
// create transform engine, set a parameter called "custom namespace" on it
and execute customXsltTemplate
///
}
The result can be outputed into the CashedOutputStream and then copied back
into a new Response this filter will produce.
Given that WADL queries are not most oftne executed requests it should not affect the performance. Alrternatively, you can have
@Context HttpServletResponse injected and direct the transfrom engine to write directlly into response.getOutputStream()...
hope it helps, Sergey
Hi Sergey,
Thanks for the update, but if I understood the class property correctly, this only allows one to use the other but does not
necessary replace. Also, it does not seem to affect the wadl generated. I added the following:
<bean class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
<property name="inTransformElements">
<map>
<entry key="http://custom.domain"
value="http://class.registered.domain" />
</map>
</property>
<property name="outTransformElements">
<map>
<entry key="http://class.registered.domain"
value="http://custom.domain" />
</map>
</property>
</bean>
The custom.domain is not mentioned anywhere in the wadl generated.
Is something similar available to JAX-WS?
It's just a nice to have. :)
Gabo
Sergey Beryozkin wrote:
Hi,
Is it JAXRS or JAXWS ?
I think you can probably rely on the custom XMLStreamReaders/Writers to
translate between diff namespaces.
If it is JAXRS then you might also want to try to configure a
JAXBElementProvider, starting from 2.2.5, ex, say you need to have
{http://bar}bar converted into {http://baz}bar both ways.
So you can configure JAXBElementProvider with outElementsMap and inElementsMap
map properties, containing
{http://bar}bar:{http://baz}bar
and
{http://baz}bar:{http://bar}bar
pairs respectively.
This approach is a bit limited at the moment in that no wildcards for local names are supported, thus it would well for schemas
with only the root element being explicitly qualified, and would be more cumbersome in other cases as it would require users to
list all the elements, but it would be easy to fix.
XSLTJaxbProvider wiull also work both ways
cheers, Sergey
----- Original Message ----- From: "Gabo Manuel" <[email protected]>
To: <[email protected]>
Sent: Thursday, December 10, 2009 4:01 AM
Subject: [CXF-2.2.5][Java1.5] Define namespace by configuration
Hi All,
To explain the scenario, we provide back-end support for service providers. The end client therefore should have no knowledge we
exist. Is there a way to configure from a text file the namespace to be used by the service classes and objects involved? This
way there would be no need to recompile the entire project for each client.
Thanks in advance.
Gabo