2016-04-14 9 views
5

मैं CXF 3.0.8 उपयोग कर रहा हूँ एक वेब सेवा का उपयोग करने निकालने का तरीका:xmlns = "" 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; 

} 

और वस्तु मैं सेवा अनुरोध में भेज है:

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

जब मैं सेवा को कॉल, साबुन शरीर इस प्रकार भेज दिया जाता है, गलत 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> 

अगर मैं xmlns = "हटा" और sopui में इस साबुन अनुरोध करते थे, सेवा ठीक काम करता है, तो मैं इस xmlns = निकालने का तरीका जानना चाहता हूँ "अनुरोध" से कोड मैं उपयोग कर रहा हूँ, निम्नानुसार है:

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

कृपया इसे ठीक करने के लिए सलाह दें, धन्यवाद।

+0

आप ट्यूटोरियल का अनुसरण कर सकते हैं https://recalll.co/app/?q=How%20to%20remove%20namespace%20in%20XML%20through%20java? – SkyWalker

उत्तर

-1

हम अवांछित xmlns = "" अनुरोध से interceptors का उपयोग कर सकते हैं।

0

डिफ़ॉल्ट रूप से, जेएक्स-डब्ल्यूएस (और इस प्रकार सीएक्सएफ) अयोग्य स्कीमा और संदेश उत्पन्न करता है।
इस प्रकार, केवल मूल तत्व नामस्थान योग्य है और उप तत्व नहीं होंगे। यदि आप @WebParam में नेमस्पेस विशेषता जोड़ते हैं, तो उस पैरामीटर के लिए इसे बदल देगा। योग्य रूप में तत्वों के लिए मजबूर करने

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

:

वैकल्पिक रूप से, की तरह कुछ के साथ एक package-info.java जोड़ें।

संबंधित मुद्दे