繁体   English   中英

如何在Java中打印SOAP Header

[英]How to print SOAP Header in java

我可以知道如何在Java中使用syso打印soap标头吗

这是我的示例代码:

       Envelope soapEnvelope = cesSOAPRequestBuilder.getSOAPEnvelope();
    URL url = new URL(getCesUrl());
    Message soapMessage = new Message();
    SOAPHTTPConnection connection = new SOAPHTTPConnection();
    connection.setTimeout(Integer.parseInt(EZSPProperties.getProperty("sp.commonProxy.defaultTimeout")));
    soapMessage.setSOAPTransport(connection);

    soapMessage.send(url, "", soapEnvelope);
    SOAPTransport soapTransport = soapMessage.getSOAPTransport();
    BufferedReader brResponse = soapTransport.receive();


       public Envelope getSOAPEnvelope() throws Exception{      
    //TODO when we start using WAS 5.1 and J2EE 1.4 perhaps it would be cleaner to replace all of this logic
    //with javax.xml.soap classes....see the Chapter 13 (SAAJ) http://java.sun.com/webservices/docs/1.3/tutorial/doc/index.html
    DOMImplementation dom = DOMImplementationImpl.getDOMImplementation();
    Document doc = dom.createDocument("doc","doc",null); 

    Vector soapHeaderEntries = new Vector();                                 

    Element messageInformationElement = doc.createElement("MessageInformation");
    soapHeaderEntries.add(messageInformationElement);   
    Element CESInformationElement = doc.createElement("CESInformation");
    soapHeaderEntries.add(CESInformationElement);       

    Element nextElement = doc.createElement("UniquePayloadId");
    Text txt = doc.createTextNode(uniquePayloadId);
    nextElement.appendChild(txt);             
    messageInformationElement.appendChild(nextElement); 

    nextElement = doc.createElement("MetName");
    txt = doc.createTextNode(metName);
    nextElement.appendChild(txt);    
    messageInformationElement.appendChild(nextElement);

    nextElement = doc.createElement("UserId");
    txt = doc.createTextNode(userId);
    nextElement.appendChild(txt);    
    CESInformationElement.appendChild(nextElement);

    nextElement = doc.createElement("ClientSystem");
    txt = doc.createTextNode(clientSystem);
    nextElement.appendChild(txt);    
    CESInformationElement.appendChild(nextElement);

    if (!"".equals(transactionMode)) {
        nextElement = doc.createElement("TransactionMode");
        txt = doc.createTextNode(transactionMode);
        nextElement.appendChild(txt);    
        CESInformationElement.appendChild(nextElement);
    }

    if (!"".equals (subCtxIdentifier)) {
        nextElement = doc.createElement("SubscriberContextIdentifier");
        txt = doc.createTextNode(subCtxIdentifier);
        nextElement.appendChild(txt);    
        CESInformationElement.appendChild(nextElement);
    }

    Header soapHeader = new Header();
    soapHeader.setHeaderEntries(soapHeaderEntries);

    Vector soapBodyEntries = new Vector();
    //in a document style SOAP service, the namespace of the first child element within the SOAP body points to the
    //name of the service (CEService) and the name of the first child element is the method that is executed within
    //the service(e.g. updateSubscriber). See "Writing Message Clients" within the SOAP User's guide at ws.apache.org    
    nextElement = doc.createElementNS("CEService", "m:"+service);       

    StringReader sr = new StringReader(enrollmentString);
    InputSource is = new InputSource(sr); 
    DOMParser domParser = new DOMParser();
    domParser.parse(is);                     
    Document enrollmentDoc = domParser.getDocument(); 
    Node importedNode = doc.importNode(enrollmentDoc.getFirstChild(),true);     
    nextElement.appendChild(importedNode);   

    soapBodyEntries.add(nextElement);

    Body soapBody = new Body();
    soapBody.setBodyEntries(soapBodyEntries); 

    Envelope envelope = new Envelope();      
    envelope.setHeader(soapHeader);
    envelope.setBody(soapBody); 

    return envelope; 
}

谁能帮我打印标题信息和正文。

SOAPTransport具有getResponseSOAPContext()方法,该方法返回SOAPContext对象 您应该可以从那里继续。

SOAPContext ctx = soapTransport.getResponseSOAPContext();
java.util.Enumeration en = ctx.getRootPart().getAllHeaders();
//iterate and display the headers

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM