0

这是我发送到部署在 WAS 8.5 中的 WS 的示例 SOAP 请求

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://xmlns.scania.com/logistics/schema/transport/v1">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-37" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>username</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">
password
</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<v1:TransportInformationRequest>
         <!--1 or more repetitions:-->
         <v1:ChassisNumber>2105909</v1:ChassisNumber>
      </v1:TransportInformationRequest>
   </soapenv:Body>
</soapenv:Envelope>

我想要的是检索在上述请求中发送的用户名和密码。我翻阅了 Java EE api,但找不到正确的方法来做同样的事情。我在SOAPHandler中写了一段痛苦的代码,如下所示:

@Override
    public boolean handleMessage(SOAPMessageContext context) {
        // TODO Auto-generated method stub

        Boolean isOutbound = (Boolean) context
                .get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

        log.info("In TransportHandler.handleMessage(...) " + isOutbound);

        if (!isOutbound) {

            SOAPMessage soapMsg = context.getMessage();
            SOAPEnvelope soapEnv;
            try {
                soapEnv = soapMsg.getSOAPPart().getEnvelope();
                SOAPHeader soapHeader = soapEnv.getHeader();

                Iterator<SOAPElement> securityHeaderElements = soapHeader
                        .getChildElements(new QName(
                                "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
                                "Security", "wsse"));

                if (securityHeaderElements.hasNext()) {
                    SOAPElement securityHeaderElement = securityHeaderElements
                            .next();
                    log.info("*****securityHeaderElement : "
                            + securityHeaderElement + " type is "
                            + securityHeaderElement.getClass().getName());

                    Iterator<Node> securityHeaderChildren = securityHeaderElement
                            .getChildElements();

                    while (securityHeaderChildren.hasNext()) {

                        Node securityElement = securityHeaderChildren.next();

                        log.info("*****securityElement : "
                                + securityElement.getClass().getName());

                        if (securityElement instanceof com.ibm.ws.webservices.engine.xmlsoap.SOAPElement) {
                            com.ibm.ws.webservices.engine.xmlsoap.SOAPElement securitySOAPElement = (com.ibm.ws.webservices.engine.xmlsoap.SOAPElement) securityElement;

                            log.info("*****securitySOAPElement "
                                    + securitySOAPElement);

                            Iterator<Node> securitySOAPElementChildren = securitySOAPElement
                                    .getChildElements();

                            while (securitySOAPElementChildren.hasNext()) {
                                Node securitySOAPElementChild = securitySOAPElementChildren
                                        .next();

                                log.info("*****securitySOAPElementChild : "
                                        + securitySOAPElementChild);

                                if (securitySOAPElementChild instanceof com.ibm.ws.webservices.engine.xmlsoap.SOAPElement) {
                                    com.ibm.ws.webservices.engine.xmlsoap.SOAPElement securitySOAPChildElement = (com.ibm.ws.webservices.engine.xmlsoap.SOAPElement) securitySOAPElementChild;

                                    log.info("*****securitySOAPChildElement "
                                            + securitySOAPChildElement);
                                }
                            }

                        }
                    }
                }

            } catch (SOAPException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        log.info("Returning from TransportHandler.handleMessage(...)");

        return true;

    }

获取用户名和密码的有效方法是什么?

4

0 回答 0