cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <sberyoz...@gmail.com>
Subject Re: Removing namespaces from CXF client messages
Date Mon, 02 May 2011 15:43:21 GMT
Hi

I've updated the docs on how to configure TransformFeature from the
code, please see

https://cwiki.apache.org/confluence/display/CXF20DOC/TransformationFeature#TransformationFeature-JAXWS

in your case you need to configure an outTransformElements property,
the following should work:

Key is {"http://cxf/"}*
Value is '*'

Let us know please if it works

Sergey


On Mon, May 2, 2011 at 1:21 PM, dan_emsat <dan@emsatcorp.com> wrote:
> Hi There,
>
> I have searched the forums for an answer to this question and have made some
> headway but I have yet to find a solution.
>
> I have developed a CXF client to call a .NET service from a 3rd party. I
> want to remove the namespaces from the call to the web service by either
> using an interceptor or by configuring JAXB within the method but I have not
> been able to do so. I am purely using CXF 2.3.3 and JDK6 without any other
> frameworks to keep it simple.
>
> Here is the client code:
>
>                JaxWsProxyFactoryBean proxyFactory = new
> JaxWsProxyFactoryBean();
>                proxyFactory.setServiceClass(cxf.Service.class);
>                proxyFactory.setAddress("http://localhost:14623/Demo/ServerService.svc");
>                cxf.Service port = (cxf.Service) proxyFactory.create();
>                // Set up Authentication
>                Authenticator.setDefault(new MyAuthenticator());
>                Client client = ClientProxy.getClient(port);
>
>                // Out interceptor to remove namespaces
>                client.getOutInterceptors().add(new MyOutInterceptor());
>
>                // Set up HTTP client parameters to allow NTLM authentication
>                HTTPConduit http = (HTTPConduit) client.getConduit();
>                HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
>                httpClientPolicy.setConnectionTimeout(36000);
>                httpClientPolicy.setAllowChunking(false);
>                httpClientPolicy.setReceiveTimeout(32000);
>                http.setClient(httpClientPolicy);
>
>                // Object factory to generate objects for service call
>                ObjectFactory factory = new ObjectFactory();
>                ServerSchemas newSchemas = factory.createServerSchemas();
>                Demo newDemo = factory.createSchemasDemo();
>                newDemo.setName("New name");
>                newDemo.setDescription("New description");
>                newDemo.setValue(926);
>                newSchemas.getEmsatDemo().add(newDemo);
>
>                // Convert objects to xml string
>                JAXBContext context = JAXBContext.newInstance(ServerSchemas.class);
>                Marshaller marshaller = context.createMarshaller();
>                marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
>                StringWriter output = new StringWriter();
>                XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(output);
>                MyStreamWriter teamsWriter = new MyStreamWriter(writer);
>
>                marshaller.marshal(newSchemas, teamsWriter);
>                final String xmlPayload = output.toString();
>
>                Success reply = port.thirdPartyServerService("DemoImport", xmlPayload,
> null);
>                System.out.println("Server said: " + reply.getSuccessMessages());
>
> The out interceptor looks like this:
>
> public class MyOutInterceptor extends AbstractPhaseInterceptor {
>
>        public MyOutInterceptor() {
>        super(Phase.MARSHAL);
>    }
>
>    public void handleMessage(Message outMessage) {
>        XMLStreamWriter writer = new
> MyStreamWriter(StaxUtils.createXMLStreamWriter(outMessage.getContent(OutputStream.class)));
>        outMessage.setContent(MyStreamWriter.class, writer);
>    }
>
> }
>
> MyStreamWriter implements XMLStreamWriter. I originally extended the
> DelegatingXMLStreamWriter but when it did not work I tried implementing the
> Stream writer myself.
>
> http://svn.apache.org/repos/asf/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/DelegatingXMLStreamWriter.java
>
> Each time I call the web service the XML generated includes namespaces as in
> :
>
> <ns3:ThirdPartyServerService
> xmlns:ns2="http://schemas.datacontract.org/2004/07/SourceEdge.BAEntities"
> xmlns:ns3="http://cxf/"
> xmlns:ns4="http://schemas.microsoft.com/2003/10/Serialization/Arrays"
> xmlns:ns5="http://schemas.datacontract.org/2004/07/SourceEdge.BAStudio.BARuntimeModel"
> xmlns:ns6="http://schemas.microsoft.com/2003/10/Serialization/">
>
> Basically I want to remove the ns3 from the beginning of the call here and
> the namespaces are not necessary either to they can be removed as well but
> the main thing it to get rid of the ns3 as the .NET service does not like
> it.
>
> I see there is a TransformFeature in CXF but I do not see any examples on
> how to configure this in my client method above. Also my Out interceptor
> does not seem to have any effect on the outgoing message.
>
> Any pointers, help, pointers to examples are appreciated. If you need any
> further information let me know.
>
> Thanks in advance.
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Removing-namespaces-from-CXF-client-messages-tp4364564p4364564.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>



-- 
Sergey Beryozkin

Application Integration Division of Talend
http://sberyozkin.blogspot.com

Mime
View raw message