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

📄 get.java

📁 基于eclipse环境下开发的cxf例程
💻 JAVA
字号:
package demo.hw.client;import java.io.ByteArrayOutputStream;import java.io.InputStream;import java.net.HttpURLConnection;import java.net.URL;import java.util.Properties;import javax.xml.transform.OutputKeys;import javax.xml.transform.Source;import javax.xml.transform.Transformer;import javax.xml.transform.TransformerFactory;import javax.xml.transform.stream.StreamResult;import javax.xml.transform.stream.StreamSource;public final class Get {    private Get() {    }     public static void main(String args[]) throws Exception {        String target = null;        URL url = null;        HttpURLConnection httpConnection = null;        InputStream in = null;        StreamSource source = null;        // Sent HTTP GET request to invoke greetMe FAULT        target = "http://localhost:9000/SoapContext/SoapPort/greetMe/me/CXF";        url = new URL(target);        httpConnection = (HttpURLConnection) url.openConnection();        httpConnection.connect();        System.out.println("Invoking server through HTTP GET to invoke greetMe");        try {            in = httpConnection.getInputStream();            source = new StreamSource(in);            printSource(source);        } catch (Exception e) {            System.err.println("GreetMe Fault: " + e.getMessage());        }        InputStream err = httpConnection.getErrorStream();        source = new StreamSource(err);        printSource(source);        // Sent HTTP GET request to invoke greetMe        target = "http://localhost:9000/SoapContext/SoapPort/greetMe/requestType/"+args[1];        url = new URL(target);        httpConnection = (HttpURLConnection) url.openConnection();        httpConnection.connect();        System.out.println("Invoking server through HTTP GET to invoke greetMe");        in = httpConnection.getInputStream();        source = new StreamSource(in);        printSource(source);    }    private static void printSource(Source source) {        try {            ByteArrayOutputStream bos = new ByteArrayOutputStream();            StreamResult sr = new StreamResult(bos);            Transformer trans = TransformerFactory.newInstance().newTransformer();            Properties oprops = new Properties();            oprops.put(OutputKeys.OMIT_XML_DECLARATION, "yes");            trans.setOutputProperties(oprops);            trans.transform(source, sr);            System.out.println();            System.out.println("**** Response ******");            System.out.println();            System.out.println(bos.toString());            bos.close();            System.out.println();        } catch (Exception e) {            e.printStackTrace();        }    }    }

⌨️ 快捷键说明

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