On Monday, May 02, 2011 8:21:19 AM dan_emsat 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.

This looks like your Service.class isn't properly or fully annotated.   Most 
likely, if you add a @WebService annotation on there with a targetNamespace of 
what you need, it would change significantly.

Dan


> 
> 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(Output
> Stream.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/a
> pache/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.BARu
> ntimeModel"
> 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-messag
> es-tp4364564p4364564.html Sent from the cxf-user mailing list archive at
> Nabble.com.

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

Reply via email to