How to remove xmlns = "" from an xml request

I am using CXF 3.0.8 to call a web service:

@WebService(targetNamespace = "http://tempuri.org/", name = "INotificationGateway") @XmlSeeAlso({ObjectFactory.class, com.microsoft.schemas._2003._10.serialization.ObjectFactory.class, org.datacontract.schemas._2004._07.notificationsgateway.ObjectFactory.class, com.microsoft.schemas._2003._10.serialization.arrays.ObjectFactory.class}) public interface INotificationGateway { @WebResult(name = "SendSMSResult", targetNamespace = "http://tempuri.org/") @Action(input = "http://tempuri.org/INotificationGateway/SendSMS", output = "http://tempuri.org/INotificationGateway/SendSMSResponse", fault = {@FaultAction(className = INotificationGatewaySendSMSEAICustomErrorFaultFaultMessage.class, value = "http://tempuri.org/INotificationGateway/SendSMSEAICustomErrorFault")}) @RequestWrapper(localName = "SendSMS", targetNamespace = "http://tempuri.org/", className = "org.tempuri.SendSMS") @WebMethod(operationName = "SendSMS", action = "http://tempuri.org/INotificationGateway/SendSMS") @ResponseWrapper(localName = "SendSMSResponse", targetNamespace = "http://tempuri.org/", className = "org.tempuri.SendSMSResponse") public org.datacontract.schemas._2004._07.notificationsgateway.NotificationResponse sendSMS( @WebParam(name = "SendSMSNotificationRequest") org.datacontract.schemas._2004._07.notificationsgateway.SendSMSNotificationRequest sendSMSNotificationRequest ) throws INotificationGatewaySendSMSEAICustomErrorFaultFaultMessage; } 

and the object that I am sending in the service request:

 @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "SendSMSNotificationRequest", propOrder = { "isArabic", "mobileNo", "refrenceId", "templateCode", "templateValues" }) public class SendSMSNotificationRequest { @XmlElementRef(name = "IsArabic", namespace = "http://schemas.datacontract.org/2004/07/NotificationsGateway", type = JAXBElement.class, required = false) protected JAXBElement<Boolean> isArabic; @XmlElementRef(name = "MobileNo", namespace = "http://schemas.datacontract.org/2004/07/NotificationsGateway", type = JAXBElement.class, required = false) protected JAXBElement<String> mobileNo; @XmlElementRef(name = "RefrenceId", namespace = "http://schemas.datacontract.org/2004/07/NotificationsGateway", type = JAXBElement.class, required = false) protected JAXBElement<String> refrenceId; @XmlElementRef(name = "TemplateCode", namespace = "http://schemas.datacontract.org/2004/07/NotificationsGateway", type = JAXBElement.class, required = false) protected JAXBElement<String> templateCode; @XmlElementRef(name = "TemplateValues", namespace = "http://schemas.datacontract.org/2004/07/NotificationsGateway", type = JAXBElement.class, required = false) protected JAXBElement<ArrayOfstring> templateValues; 

when I call the service, the soap body is sent as follows, with the prefix of the incorrect xmlns = "" :

 <MobileNo xmlns="" xmlns:ns5="http://schemas.datacontract.org/2004/07/NotificationsGateway">0000000000</MobileNo> <RefrenceId xmlns="" xmlns:ns5="http://schemas.datacontract.org/2004/07/NotificationsGateway">123</RefrenceId> <TemplateCode xmlns="" xmlns:ns5="http://schemas.datacontract.org/2004/07/NotificationsGateway">123</TemplateCode> 

if I deleted xmlns = " and used this soap request in sopui, the service works fine, so I want to know how to remove this xmlns =" ​​" from the request, the code that I use is as follows:

 JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean(); factoryBean.setServiceClass(INotificationGateway.class); factoryBean.setAddress("https://localhost:4431/NotificationsGateway/NotificationGateway.svc"); INotificationGateway port = (INotificationGateway) factoryBean.create(); Client client = ClientProxy.getClient(port); client.getInInterceptors().add(new LoggingInInterceptor()); client.getOutInterceptors().add(new LoggingOutInterceptor()); HTTPConduit http = (HTTPConduit) client.getConduit(); http.getAuthorization().setUserName("myuser"); http.getAuthorization().setPassword("mypass"); TLSClientParameters tlsCP = new TLSClientParameters(); if (ignoreSSL) tlsCP.setTrustManagers(createIgnoredTrustManager()); tlsCP.setDisableCNCheck(true); http.setTlsClientParameters(tlsCP); Endpoint cxfEndpoint = client.getEndpoint(); Map<String, Object> outProps = new HashMap<String, Object>(); outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN); outProps.put(WSHandlerConstants.USER, "myuser"); outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT); outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordCallback.class.getName()); WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps); cxfEndpoint.getOutInterceptors().add(wssOut); port.sendSMS(sendSMSNotificationRequest); 

please advise how to fix this, thanks.

+5
source share
2 answers

By default, JAX-WS (and therefore CXF) creates unqualified schemas and messages.
Thus, only the root element is a namespace, and there will be no subelements. If you add a namespace attribute to @WebParam, this will change it for this parameter.

Alternatively add package-info.java with something like:

 @javax.xml.bind.annotation.XmlSchema( namespace = "http://apache.org/hello_world_soap12_http/types", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) 

to force items into a qualified form.

0
source

We can use interceptors to remove the unwanted xmlns = "" request.

-1
source

Source: https://habr.com/ru/post/1247127/


All Articles