开发者

how to post xml over https web service in java

how can i post xml to https web service and get the xml in response... 开发者_开发知识库the requirement is this..

The web service accepts a parameter payload in which we can pass xml and i will be getting response xml.

the url looks like this: https://servername/aaa/bbb/us/ws.do?


        private static final String CERT_FILE_LOC = "/aaa/bbb/ccffdd.jks";
        System.setProperty("javax.net.ssl.trustStore", CERT_FILE_LOC);


        HostnameVerifier hv = new HostnameVerifier() {
            public boolean verify(String urlHostName, SSLSession session) {
                System.out.println("Warning: URL Host: "+urlHostName+" vs. "+session.getPeerHost());

                return true;
            }
        };

        HttpsURLConnection.setDefaultHostnameVerifier(hv);

        URL url = new URL(inputUrl);
        HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();

        connection.setDoOutput(true);

        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String line;

        while ((line = in.readLine()) != null) {
            responseXml=responseXml+line;
            }
        in.close();
        System.out.println("responseXml");


Get the webservice definition (WSDL) and use a wsdl2java client to generate java client for the WSDL. Use the generated client code to invoke the webservice. Webservice framework that you choose will take care of constructing and parsing SOAP request/response for you. Example , refer Apache Axis


Get the WSDL for the web service, and use it for your tooling. A good place to start is the Web Service Explorer in Eclipse Java EE.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜