SOAP Header Elements from response java -


i attempting add header elements values depending on output of response in soap:

my messagehandler class:

public class messagehandler implements soaphandler<soapmessagecontext> {      private static final logger log = logger.getlogger("simlogger");      customheader cust =  new customheader();       @override     public boolean handlemessage(soapmessagecontext messagecontext) {         try {             soapmessage message = messagecontext.getmessage();             soapheader header = message.getsoapheader();             soapenvelope envelope = message.getsoappart().getenvelope();             if (header == null) {                 header = envelope.addheader();             }             qname qoutputheader = new qname("http://www.w3.org/2001/xmlschema-instance/", "outputheader");             soapheaderelement outputheader = header.addheaderelement(qoutputheader);              qname qhasreturnmessage = new qname("http://www.w3.org/2001/xmlschema-instance/", "hasreturnmessage");             soapheaderelement hasreturnmessage = header.addheaderelement(qhasreturnmessage);             hasreturnmessage.addtextnode(cust.gethasreturnmessage());              qname qlasttransactioncall = new qname("http://www.w3.org/2001/xmlschema-instance/", "lasttransactioncall");             soapheaderelement lasttransactioncall = header.addheaderelement(qlasttransactioncall);             lasttransactioncall.addtextnode(cust.getlasttransactioncall());              qname qrefreshaccounts = new qname("http://www.w3.org/2001/xmlschema-instance/", "refreshaccounts");             soapheaderelement refreshaccounts = header.addheaderelement(qrefreshaccounts);             refreshaccounts.addtextnode("false");              qname qreturncode = new qname("http://www.w3.org/2001/xmlschema-instance/", "returncode");             soapheaderelement returncode = header.addheaderelement(qreturncode);             returncode.addtextnode(cust.getreturncode());              qname qreturnmessage = new qname("http://www.w3.org/2001/xmlschema-instance/", "returnmessage");             soapheaderelement returnmessage = header.addheaderelement(qreturnmessage);             returnmessage.addtextnode(cust.getreturnmessage());              qname qstatus = new qname("http://www.w3.org/2001/xmlschema-instance/", "status");             soapheaderelement status = header.addheaderelement(qstatus);             status.addtextnode(cust.getstatus());              outputheader.addchildelement(hasreturnmessage);             outputheader.addchildelement(lasttransactioncall);             outputheader.addchildelement(refreshaccounts);             outputheader.addchildelement(returncode);             outputheader.addchildelement(returnmessage);             outputheader.addchildelement(status);              message.savechanges();          } catch (soapexception e) {             log.error("error occurred while adding credentials soap header.", e);         }           log(messagecontext);         return true;     }        @override     public set<qname> getheaders() {         return new treeset();     }      @override     public boolean handlefault(soapmessagecontext messagecontext) {         return true;     }      @override     public void close(messagecontext context) {      } } 

my request:

 @webresult(name = "statisticcode")     @webmethod(operationname = "getstatisticcodes")     public list<statisticcode> getstatisticcodes() {      customheader header = new customheader();//getter setter class         list<statisticcode> codes = new arraylist<statisticcode>();         statisticcode c1 = new statisticcode();         c1.setcode("000");         c1.setdescription("transaction posted successfully");         codes.add(c1);          statisticcode c2 = new statisticcode();         c2.setcode("911");         c2.setdescription("card issuer/ cbc service timed out");         codes.add(c2);          statisticcode c3 = new statisticcode();         c3.setcode("909");         c3.setdescription("system malfunction");         codes.add(c3);          statisticcode c4 = new statisticcode();         c4.setcode("907");         c4.setdescription("cbc services down");         codes.add(c4);         if (codes != null) {             header.sethasreturnmessage("true");             header.setlasttransactioncall(new date().tostring());             header.setrefreshaccounts("false");             header.setreturncode("0");             header.setreturnmessage("success");             header.setstatus("ok");         } else {             header.sethasreturnmessage("true");             header.setlasttransactioncall(new date().tostring());             header.setrefreshaccounts("true");             header.setreturncode("1");             header.setreturnmessage("an error occured while fetching statistic codes");             header.setstatus("error");         }         return codes;      } 

i still getting nullpointerexception. @ point should set values elements response able t pick them?


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -