【问题标题】:Soap message retrieval肥皂消息检索
【发布时间】:2013-02-03 00:54:05
【问题描述】:

我们正在实现一项 JAX-WS Web 服务,该服务需要检索 SOAP 标头元素中的用户名和密码,并将其用于进一步使用/处理。 当我们检索用户名/密码时,它将为空。请帮忙。

  if (Boolean.FALSE.equals(context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY))) {      
             try {
                 SOAPMessage sm = context.getMessage();
                 //SOAPEnvelope envelope = context.getMessage().getSOAPPart().getEnvelope();
                 SOAPEnvelope envelope = sm.getSOAPPart().getEnvelope();
                 SOAPHeader sh = envelope.getHeader();

                System.out.println("Message: "+envelope);
                System.out.println("Envelope: "+envelope);
                 System.out.println("Header: "+sh.toString());
                 Iterator it = sh.examineAllHeaderElements();
                 while(it.hasNext()){
                     System.out.println(it.next());
                 }

           String username;
            username = sh.getAttribute("Username");
           // username  = sh.getAttributeValue("Username");
            //String password =  sh.getAttribute("Password");
                 System.out.println("uid:"+username);
                 //System.out.println("pass: "+password);
                context.put("Username", username);
                //context.put("Passsword", password);
                // default scope is HANDLER (i.e., not readable by SEI
                // implementation)
                context.setScope("Username", MessageContext.Scope.APPLICATION);

【问题讨论】:

    标签: java soap jax-ws message


    【解决方案1】:

    试试这个:

    public boolean handleMessage(SOAPMessageContext context) { 
        try { 
            SOAPMessage message = context.getMessage(); 
            SOAPHeader header = message.getSOAPHeader();             
            if (header != null) { 
                Iterator i = header.getChildElements();
                //Navigate through header elements to get the username and password
            } 
        } catch (Exception e) { 
            //Handle exception 
        } 
        return true; 
    }
    

    另请参阅:

    【讨论】:

    • 示例
      docs.oasis-open.org/wss/2004/01/…"> docs.oasis-open.org/wss/2004/01/…"> TestUser wsse:Username> docs.oasis-open.org/wss/2004/01/…>
    • 那么您的消息根本不包含标题。你确定那个标题是它应该在的地方吗?
    • 其实用户名和密码并不是soap头元素的属性(它们是嵌套元素)。
    猜你喜欢
    • 2017-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    相关资源
    最近更新 更多