<%@ page language="java" import="java.util.*,java.net.*,java.io.*" pageEncoding="GBK"%>
<%@ page import="java.util.Enumeration" %>
<%
try {
//应用服务器地址
//ResourceBundle pro = ResourceBundle.getBundle("ctii-unicall");
//String ipaddrs=ParamServiceImpl.getInstance().getConfValue(pro.getString("PortalWeb_IP"));
// String[] szServers={"10.10.16.238:8080"};
String[] szServers={"10.10.4.102:8100","10.10.4.122:8100","10.10.4.102:8200","10.10.4.122:8200"};
String HKServerAddr = request.getRemoteAddr();
//if((HKServerAddr == null)||(!HKServerAddr.trim().equals("202.82.183.163"))) {
if((HKServerAddr == null)) {
out.println("0");
out.println("RemoteIP: " + HKServerAddr);
System.out.println("RemoteIP: " + HKServerAddr);
return;
}
String method = request.getParameter("method");
String username = request.getParameter("username");
String billno = request.getParameter("id");
/***********************/
//并发送给各个的服务器(包括自己)
URL destURL;
HttpURLConnection urlConn;
String myPostParam;
for(int i=0; i<szServers.length; i++) {
if(billno != null ) {
//out.println("<br>IP: " + java.net.InetAddress.getLocalHost().getHostAddress() + "; servers:" + szServers[i] + "<br>");
}
try{
// Send HK current login user SESSION_ID & HK current login account to SZ Host
String HKmethod = "method="+method.toString();
// Can Modify to get UserID from http-session
// String HKAccount = "&mcd="+URLEncoder.encode("1001209", "UTF-8");
String HKusername = "&username="+username.toString();
String HKid = "&id="+billno.toString();
myPostParam = HKmethod + HKusername + HKid;
System.out.println(szServers[i]);
destURL = new URL("http://"+szServers[i]+"/bc/application/openToAllServers.jsp");
urlConn = (HttpURLConnection)destURL.openConnection();
urlConn.setRequestMethod("POST");
urlConn.setDoOutput(true); // 需要向服务器写数据
urlConn.setDoInput(true); //
urlConn.setUseCaches(false); // 获得服务器最新的信息
urlConn.setAllowUserInteraction(false);
urlConn.setRequestProperty("Content-type","application/x-www-form-urlencoded");
// 必须告诉服务器你发送的数据大小. 这也同样告诉
urlConn.setRequestProperty("Content-length", ""+myPostParam.length());
// Open an output stream so you can send the info you are posting
DataOutputStream outStream = new DataOutputStream(urlConn.getOutputStream());
// Write out the actual request data
outStream.writeBytes(myPostParam);
outStream.flush();
BufferedReader inReader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String sRet;
//int iii = 0;
while ((sRet = inReader.readLine()) != null) {
if(billno != null) {
out.print(sRet);
} else if(!sRet.trim().equals("")) break;
}
outStream.close();
inReader.close();
}catch(Exception e){
System.out.println("openOrunopen.jsp 同步 application Error:"+e);
//out.println("0");
//out.println("<br>同步 application 错误:" + e);
return;
}
} // end for
} catch (Exception e1) {
out.println("0");
out.println("error:<br>" + e1);
return;
}
%>