I'll give that a shot.  I've actually worked out a bit of code that lets
me specify it, but oh my, it's not beautiful:

    static <T> T createService(Class<? extends T> impl,
EndpointReference epr) {
        T service = Service.create(findServiceQName(impl))
                .getPort(epr, impl, getEnabledFeatures());

        // the following is to customize the JAXB namespace map.
        org.apache.cxf.service.Service s =
((org.apache.cxf.jaxws.JaxWsClientProxy)
                java.lang.reflect.Proxy.getInvocationHandler(service))
                        .getClient().getEndpoint().getService();

        if (s.getDataBinding() instanceof JAXBDataBinding) {
 
((JAXBDataBinding)s.getDataBinding()).setNamespaceMap(getNamespaceMap())
;
        }

        return service;
    }

Moving into configuration so I can just use JAX-WS would be nice.

-----Original Message-----
From: Daniel Kulp [mailto:[email protected]] 
Sent: Thursday, July 15, 2010 4:49 PM
To: [email protected]
Cc: Vanore, Gregory
Subject: Re: Customize JAXB namespace prefixes for JAXWS API created
endpoints

On Wednesday 14 July 2010 1:02:37 pm Vanore, Gregory wrote:
> Maybe I'm missing something, but I don't see how to get the
> JAXBDataBinding in there.  I'm not creating a jaxws:client or
> jaxws:endpoint declaration in my configuration, so I can't pass the
bean
> into anything.  I've been looking at the beans through the debugger,
and
> at some level there is a bean that holds a ServiceImpl where I could
set
> the JAXBDataBinding, but I don't see a publically accessible way to
> retrieve the field without starting at the CXF API level.  Can I set
> some magic property in the request context?

Doesn't look like a way, no.   I think the only way to do this is either
via 
config or by dropping into CXF api's.

That said, you can use a combination of the @DataBinding interface with 
configuration to ONLY configure a JAXBDataBinding object and not all the

jaxws:client/jaxws:endpoint things and such.   In the config,
create/define 
the object and then in the annotation, use the ref=".." attribute to
refer to 
it by id.

Dan


> 
> -----Original Message-----
> From: Daniel Kulp [mailto:[email protected]]
> Sent: Saturday, July 03, 2010 1:45 PM
> To: [email protected]
> Cc: Vanore, Gregory
> Subject: Re: Customize JAXB namespace prefixes for JAXWS API created
> endpoints
> 
> 
> Any chance you could create a simple testcase that shows this.   It
> should
> definitely be allowed to define (or redefine) the namespace there.
The
> output
> may not be perfectly what you want, but it should work.
> 
> Dan
> 
> On Thursday 01 July 2010 10:50:50 am Vanore, Gregory wrote:
> > I see in the documentation how to use a JAXBDataBinding to customize
> > namespace prefixes for endpoints that I enumerate through the Spring
> > configuration mechanism.  I have a client that is strictly using the
> > JAX-WS API to create services:  Service.create(...) and then
> > service.getPort(...).
> > 
> > When I create a W3CEndpointReference, extra namespaces are injected
> 
> into
> 
> > it:
> > 
> > <EndpointReference xmlns="http://www.w3.org/2005/08/addressing";>
> > 
> >     <Address>http://localhost:8888/test</Address>
> >     <ReferenceParameters>
> >     
> >             <elem xmlns=""
> > 
> > xmlns:ns2="http://www.w3.org/2005/08/addressing";
> > xmlns:wsa="http://www.w3.org/2005/08/addressing";>test</elem>
> > 
> >     </ReferenceParameters>
> >     <Metadata/>
> > 
> > </EndpointReference>
> > 
> > The problem comes when I set this into my request message.  JAXB
tries
> > to utilize ns2, and then declares a collision when it encounters the
> > 
> > endpoint reference, such as:
> >     W3CEndpointReference epr =
> 
>
eprBuilder.address("http://localhost:8888/test";).referenceParameter(e).b
> 
> > uild();
> > 
> >     SubscribeService request = new SubscribeService();
> >     request.setTopic("theTopic");
> >     request.setConsumerReference(epr);
> >     ServiceResponse response = service().subscribeTo(request); //no
> > 
> > luck
> > 
> > javax.xml.ws.soap.SOAPFaultException: The namespace
> > xmlns:ns2="http://service.com/service"; could not be added as a
> 
> namespace
> 
> > to "elem": The namespace prefix "ns2"
> > 
> > I feel the best strategy is to use the namespace mapping to fix
> 
> certain
> 
> > common URLs to specific prefixes.  If you have other ideas I'll
> > certainly listen...
> > 
> > Thanks,
> > Greg

-- 
Daniel Kulp
[email protected]
http://dankulp.com/blog

Reply via email to