-
- import java.io.BufferedInputStream;
- import java.io.BufferedReader;
- import java.io.ByteArrayOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.OutputStreamWriter;
- import java.net.URI;
- import java.net.URL;
- import java.net.URLConnection;
-
- import org.apache.commons.httpclient.HttpClient;
- import org.apache.commons.httpclient.HttpStatus;
- import org.apache.commons.httpclient.methods.PostMethod;
-
-
-
-
-
- public class TestMeetingInterface {
-
-
-
-
- public static void main(String[] args) {
-
- String url = "http://192.168.0.68/integration/xml";
- TestMeetingInterface tmi = new TestMeetingInterface();
- System.out.println(tmi.post(url,"listSummaryMeeting.xml"));
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
-
-
-
-
-
-
-
-
-
- public String post(String url,String xmlFileName){
-
- System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
- System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
- System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "stdout");
-
-
- HttpClient client = new HttpClient();
-
- PostMethod myPost = new PostMethod(url);
-
- client.setConnectionTimeout(300*1000);
- String responseString = null;
- try{
-
- myPost.setRequestHeader("Content-Type","text/xml");
- myPost.setRequestHeader("charset","utf-8");
-
-
-
-
- InputStream body=this.getClass().getResourceAsStream("/"+xmlFileName);
- myPost.setRequestBody(body);
-
- int statusCode = client.executeMethod(myPost);
- if(statusCode == HttpStatus.SC_OK){
- BufferedInputStream bis = new BufferedInputStream(myPost.getResponseBodyAsStream());
- byte[] bytes = new byte[1024];
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- int count = 0;
- while((count = bis.read(bytes))!= -1){
- bos.write(bytes, 0, count);
- }
- byte[] strByte = bos.toByteArray();
- responseString = new String(strByte,0,strByte.length,"utf-8");
- bos.close();
- bis.close();
- }
- }catch (Exception e) {
- e.printStackTrace();
- }
- myPost.releaseConnection();
- return responseString;
- }
-
-
-
-
-
- public void testPost(String urlStr) {
- try {
- URL url = new URL(urlStr);
- URLConnection con = url.openConnection();
- con.setDoOutput(true);
- con.setRequestProperty("Pragma:", "no-cache");
- con.setRequestProperty("Cache-Control", "no-cache");
- con.setRequestProperty("Content-Type", "text/xml");
-
- OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream());
- String xmlInfo = getXmlInfo();
- System.out.println("urlStr=" + urlStr);
-
- out.write(new String(xmlInfo.getBytes("UTF-8")));
- out.flush();
- out.close();
- BufferedReader br = new BufferedReader(new InputStreamReader(con
- .getInputStream()));
- String line = "";
- for (line = br.readLine(); line != null; line = br.readLine()) {
- System.out.println(line);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- private String getXmlInfo() {
- StringBuilder sb = new StringBuilder();
- sb.append("<?xml version='1.0' encoding='UTF-8'?>");
- sb.append("<Message>");
- sb.append(" <header>");
- sb.append(" <action>readMeetingStatus</action>");
- sb.append(" <service>meeting</service>");
- sb.append(" <type>xml</type>");
- sb.append(" <userName>admin</userName>");
- sb.append(" <password>admin</password>");
- sb.append(" <siteName>box</siteName>");
- sb.append(" </header>");
- sb.append(" <body>");
- sb.append(" <confKey>43283344</confKey>");
- sb.append(" </body>");
- sb.append("</Message>");
-
- return sb.toString();
- }
- }
posted @
2013-06-26 20:17
爱生活,爱编程
阅读(
33665)
评论()
编辑
收藏
举报