1public static boolean updateUserMessageActions(String authorization, String unityIp)
2 throws HttpConnectionException {
3 boolean flag = false;
4 byte[] bArray = null; // buffer for reading response from
5 Socket socket = null; // socket to cupi server
6 OutputStream out = null; // output stream to server
7 InputStream in = null; // input stream from server
8 String sAXLSOAPRequest = "";
9 // HTTPS header and SOAP payload
10 // will hold only the SOAP payload
11 String sAXLRequest = null;
12 // base64 encoding of the username and password
13 authorization = new sun.misc.BASE64Encoder().encode(authorization
14 .getBytes());
15 16 sAXLSOAPRequest = "POST /vmrest/users/5695fb7a-c46a-4d78-9af9-025a209d30af HTTP/1.0\r\n";
17 sAXLSOAPRequest += "Host:localhost:8443\r\n";
18 sAXLSOAPRequest += "Authorization: Basic " + authorization + "\r\n";
19 sAXLSOAPRequest += "Accept: application/*\r\n";
20 sAXLSOAPRequest += "Content-type: application/xml\r\n";
21 sAXLSOAPRequest += "Content-length: ";
22 23 sAXLRequest = "";
24// sAXLRequest += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>";
25 sAXLRequest += "<MessageHandler>";
26 sAXLRequest += "<VoicemailAction>3</VoicemailAction>";
27 sAXLRequest += "<EmailAction>1</EmailAction>";
28 sAXLRequest += "<FaxAction>1</FaxAction>";
29 sAXLRequest += "<DeliveryReceiptAction>1</DeliveryReceiptAction>";
30 sAXLRequest += "<RelayAddress>guochao@wafersystems.com</RelayAddress>";31 sAXLRequest += "</MessageHandler>";
32 33 // finish the HTTPS Header
34 sAXLSOAPRequest += sAXLRequest.length();
35 sAXLSOAPRequest += "\r\n\r\n";
36 sAXLSOAPRequest += sAXLRequest;
37 38 // Implement the certificate-related stuffs required for sending request
39 // via https
40 try {
41 X509TrustManager xtm = new MyTrustManager();
42 TrustManager[] mytm = { xtm };
43 SSLContext ctx;
44 ctx = SSLContext.getInstance("SSL");
45 ctx.init(null, mytm, null);
46 SSLSocketFactory sslFact = (SSLSocketFactory) ctx
47 .getSocketFactory();
48 socket = (SSLSocket) sslFact.createSocket(unityIp, 8443);
49 in = socket.getInputStream();
50 51 // send the request to the server
52 // read the response from the server
53 StringBuffer sb = new StringBuffer(2048);
54 bArray = new byte[2048];
55 int ch = 0;
56 int sum = 0;
57 out = socket.getOutputStream();
58 out.write(sAXLSOAPRequest.getBytes());
59 while ((ch = in.read(bArray)) != -1) {
60 sum += ch;
61 sb.append(new String(bArray, 0, ch));
62 }
63 socket.close();
64 65 // output the response to the standard output
66 logger.info(sb.toString());
67 flag = true;
68 69 } catch (Exception e) {
70 logger.error(" connect error " + e.getMessage());
71 throw new HttpConnectionException();
72 }
73 74 return flag;
75 76 }