xml - Java web service client cdata tag -


is possible in simple way send string inside cdata tag witout escaping chacters? used @xmlcdata tag string , changes value when use marshaller. when want send request soapui it'doesn't add this. when add tag manually (for example in setter) escapes characters.

for example: if use marshaller get:

<?xml version="1.0" encoding="utf-8"?> <getrequest xmlns="pl/nosd/get">     <clientnumber>         <![cdata[<client_number>]]>     </clientnumber> </getrequest> 

and that's correct.

but when want send soapui using service:

sync_customer_service = new sync_customer_service(); customer_porttype customer_porttype = sync_customer_service.getcustomer_httpsport(); getrequest  getrequest = new getrequest(); getrequest.setclientnumber("<client_number>"); customer_porttype.get(getrequest); 

i get:

<s:envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">    <s:body>       <ns2:getrequestmessage xmlns="pl/nosd/get" xmlns:ns2="http://pl/nosd/get/xsd">          <clientnumber>&lt;client_number></clientnumber>       </ns2:getrequestmessage>    </s:body> </s:envelope> 

i added jaxb.properties file with: javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.jaxbcontextfactory

and added @xmlcdata annotation getrequest class:

public class getrequest {     @xmlcdata     @xmlelement(name = "clientnumber", required = true)     protected string clientnumber;     public string getclientnumber() {         return clientnumber;     }     public void setclientnumber(string value) {         this.clientnumber = value;     } 

service , porttype classes generated jdeveloper using web service proxy option.

i found solution. workaround not beauty, works. in client class add handler:

    bindingprovider bp = (bindingprovider)account_porttype;     list<handler> handlerlist = bp.getbinding().gethandlerchain();     requestresponsehandler reqreshelper = null;     handlerlist.add(new headerhandler());     bp.getbinding().sethandlerchain(handlerlist); 

and in handler replace value cdata value:

    public class headerhandler implements soaphandler<soapmessagecontext> {           private static final string system_id = "pl/customer.wsdl";           private static final string node_name = "clientnumber";           public boolean handlemessage(soapmessagecontext context) {      try{         boolean outboundproperty = (boolean) context.get(messagecontext.message_outbound_property);         if (outboundproperty.booleanvalue()) {             object o = context.get(logicalmessagecontext.wsdl_description);             org.xml.sax.inputsource = (org.xml.sax.inputsource)o;             if(is.getsystemid().contains(system_id)){                 soapmessage message = context.getmessage();                 soapbody body = message.getsoapbody();                 node e =getnode(body.getchildnodes());                 cdatasection cdatasection = message.getsoappart().createcdatasection(e.getfirstchild().getnodevalue());                 e.replacechild(cdatasection, e.getfirstchild());             }         }      }catch(exception e){         //todo logować     }       return true;  }  public node getnode(nodelist a){     if(a!=null&&a.getlength()>0){         for(int = 0;i<a.getlength();i++){             node b = a.item(i);             if(b.getnodename()!=null && b.getnodename().contains(node_name)){                 return b;             }             node node = getnode(b.getchildnodes());             if(node!=null){                 return node;             }         }     }      return null; } 

in soapui see:

<ns6:clientnumber>   <![cdata[data]]> </ns6:clientnumber> 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -