⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sendmessage.java

📁 《JAVA WEB服务应用开发详解》代码
💻 JAVA
字号:
    //samples.messaging.SendMessage.java
    package samples.messaging;
    
    import java.io.*;
    import java.net.*;
    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    import org.xml.sax.*;
    import org.apache.soap.*;
    import org.apache.soap.messaging.*;
    import org.apache.soap.transport.*;
    import org.apache.soap.util.xml.*;
    
    /**
     * This class sends a message by taking in an XML file that has a full
     * SOAP envelope in it and dumping it to the given message router URL.
     * Any content from the response is dumped to stdout.
     *
     * @author Sanjiva Weerawarana <sanjiva@watson.ibm.com>
     */
    public class SendMessage {
      public static void main (String[] args) throws Exception {
        if (args.length != 2) {
          System.err.println ("Usage: java " + SendMessage.class.getName () +
                              " SOAP-router-URL envelope-file");
          System.exit (1);
        }
    
        // get the envelope to send
        FileReader fr = new FileReader (args[1]);
        DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilder();
        Document doc = xdb.parse (new InputSource (fr));
        if (doc == null) {
      throw new SOAPException (Constants.FAULT_CODE_CLIENT, "parsing error");
        }
        Envelope msgEnv = Envelope.unmarshall (doc.getDocumentElement ());
    
        // send the message
        Message msg = new Message ();
        msg.send (new URL (args[0]), "", msgEnv);
    
        // receive whatever from the transport and dump it to the screen
        System.out.println ("RESPONSE:");
        System.out.println ("--------");
        SOAPTransport st = msg.getSOAPTransport ();
        BufferedReader br = st.receive ();
        String line;
        while ((line = br.readLine ()) != null) {
          System.out.println (line);
        }
      }
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -