java - JAX-WS: Consuming WSSE Secured Web Services -


so i'm trying consume wsse secured (usernametoken) webservice, created soaphandler i'm not seeing getting invoked (i stuffed handler breakpoints , not stopping there), aside of course fact i'm getting soap error (see below). idea i'm messing up?

  • in commonconstants pasted whole wsse header soapui
  • in integrationbean i'm (in theory) binding handler wsi generated proxy , invoking secured service
  • in wssehandler i'm doing black magic. capturing soap headers , appending wsse one. place that's filled breakpoints not getting hit.

soap fault

 javax.xml.ws.soap.soapfaultexception: no username available 

commonconstants.java

public static string wsse_usename_token_header = "<wsse:security xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">\n"         + "         <wsse:usernametoken>\n"         + "            <wsse:username>**username**</wsse:username>\n"         + "            <wsse:password type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#passwordtext\">**password**</wsse:password>\n"         + "         </wsse:usernametoken>\n"         + "</wsse:security>"; 

integrationbean.java

public string testmethod() throws exception {     string result = "";     cischannelport cischannel = new channelservice().getcischannelport();      binding binding = ((bindingprovider) cischannel).getbinding();      list<handler> handlerlist = binding.gethandlerchain();     handlerlist.add(new wssehandler());     binding.sethandlerchain(handlerlist);      try {         list<channel> response = cischannel.getallchannels(null).getchannels().getchannel();          (channel c : response) {             result += c.getnamechannel() + " -- ";             log.info(package + "found channel: " + c.getnamechannel());         }      } catch (exception ex) {         log.info(package + "error consumiendo el servicio");         log.error(package + ex.getmessage());         throw new exception("error consumiendo el servicio");     }      return result; } 

wssehandler.java

public class wssehandler implements soaphandler<soapmessagecontext> {  private static final string package = "[co.com.tigo.test.integration.ejb.impl.wssehandler] ";  public wssehandler() {  }  @override public set<qname> getheaders() {     return collections.emptyset(); }  @override public boolean handlemessage(soapmessagecontext context) {     commonconstants.log.info(package + "begin handlemessage");     boolean outboundproperty = (boolean) context.get(messagecontext.message_outbound_property);     if (outboundproperty) {         commonconstants.log.info(package + "outbound message detected");         try {             addsecurityheader(context);         } catch (exception ex) {             commonconstants.log.info(package + "error while setting wsse headers");             commonconstants.log.error(package + ex.getclass().getcanonicalname() + " - " + ex.getmessage());             return false;         }      }     return true; }  @override public boolean handlefault(soapmessagecontext context) {     return true; }  @override public void close(messagecontext context) {  }  private void addsecurityheader(soapmessagecontext messagecontext) throws soapexception, saxexception, ioexception {     log.info(package + "adding security header");     soapheader header = messagecontext.getmessage().getsoappart().getenvelope().getheader();     if (header == null) {         header = messagecontext.getmessage().getsoappart().getenvelope().addheader();     }      domparser parser = new domparser();     parser.parse(new inputsource(new java.io.stringreader(commonconstants.wsse_usename_token_header)));     node doc = (node) parser.getdocument();     header.appendchild(doc);  } 

}


Comments