2016-04-14 22 views
5

sto usando CXF 3.0.8 per richiamare un servizio Web:Come rimuovere xmlns = “” dalla richiesta XML

@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; 

} 

e l'oggetto i inviare nella richiesta il servizio è:

@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; 

quando chiamo il servizio, il corpo sapone viene inviato come segue, con prefisso sbagliate 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> 

se ho rimosso il xmlns = "" e usato questa richiesta sapone in sopui, il servizio funziona bene, quindi voglio sapere come rimuovere questo xmlns = "" dalla richiesta, il codice che sto usando è il seguente:

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); 

si prega di avvisare come risolvere il problema, grazie.

+0

È possibile seguire il tutorial https://recalll.co/app/?q=How%20to%20remove%20namespace%20in%20XML%20through%20java? – SkyWalker

risposta

-1

È possibile utilizzare interceptors per rimuovere gli indesiderati xmlns = "" dalla richiesta.

0

Per impostazione predefinita, JAX-WS (e quindi CXF) produce schemi e messaggi non qualificati.
Quindi, solo l'elemento radice è qualificato come spazio dei nomi e gli elementi secondari non dovrebbero essere . Se si aggiunge l'attributo namespace a @WebParam, quello cambierebbe per quel parametro.

In alternativa, aggiungere un package-info.java con qualcosa di simile:

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

per forzare gli elementi in forma qualificato.

Problemi correlati