| 发表于:2007-07-25 13:48:51 楼主 |
大家好! 感谢进来帮我解决问题! 问题陈述: 我在使用ca认证遇上一个问题, 由于ca认证的时候要和ca服务器有一个交互. 而且ca服务器限定web程序的客户端不能直接和ca服务器交互, 只能有web服务端进行交互.所以ca发出验证信息必须通过web服务器做一个中转. 在web客户端发出验证的时候(通过访问ca服务器的一个地址, 比如说 http://aaa:8080/a.asp), 我是在web服务器段做了一个转发的请求(也就是把http://aaa:8080/a.asp先通过web服务器, 在有web服务器转发出去, 具体看后面的代码), 但是客户端发出请求的时候是带有参数的, 我通过我的方法导致ca服务器那边的参数获取不到. 请大家指点; 代码: 就是把原来请求ca服务器的连接先指向web服务器的一个连接 /** * 处理ceb验证跳转 * pack, unpack, stamp, print * @param pmapping * @param pform * @param prequest * @param presponse * @return * @throws oaexception */ public actionforward dealvalidateforward(actionmapping pmapping, actionform pform, httpservletrequest prequest, httpservletresponse presponse) throws oaexception{ string opervalidate = prequest.getparameter( "opervalidate "); string cebserverpath = cebvalidateconstant.property.getproperty( "cebserverpath "); string validatepage = " "; boolean dooutput = true; //是否需要印章服务器返回数据 if(opervalidate.equals( "packvalidate ")){ validatepage = cebserverpath + cebvalidateconstant.property.getproperty( "packvalidateurl "); }else if(opervalidate.equals( "unpackvalidate ")){ validatepage = cebserverpath + cebvalidateconstant.property.getproperty( "unpackvalidateurl "); }else if(opervalidate.equals( "stampvalidate ")){ validatepage = cebserverpath + cebvalidateconstant.property.getproperty( "stampvalidateurl "); }else{ validatepage = cebserverpath + cebvalidateconstant.property.getproperty( "printvalidateurl "); } try { cebvalidateconstant.invokeremote(validatepage, dooutput, prequest, presponse); } catch (exception e) { e.getmessage(); throw new oaexception( "印章校验出错! "); } return null; } 下面的方法是转发数据包, 和获取返回的数据 /** * 访问印章服务器 * @param url 要访问的地址 * @param dooutput 是否需要印章服务器返回信息 * @param request httpservletrequest请求包 * @param response httpservletresponse响应包 * @return string 被访问的服务器的返回信息 * @throws ioexception 如果连接印章服务器失败则抛出ioexception * @throws malformedurlexception */ public static string invokeremote(string url,boolean dooutput,httpservletrequest request,httpservletresponse response) throws ioexception,malformedurlexception{ string retval = null; bytearrayoutputstream baos = new bytearrayoutputstream(); url server = new url(url); httpurlconnection conn = (httpurlconnection)server.openconnection(); conn.setdooutput(dooutput); conn.setdoinput(true); conn.setusecaches(false); //weicd conn.setrequestmethod( "post "); conn.setrequestproperty( "cache-control ", "no-cache "); datainputstream in = null; if(dooutput){//需要接收客户端数据包 //读取包 in = new datainputstream(new bufferedinputstream(request.getinputstream())); int ch = in.read(); while(ch!=-1){ baos.write(ch); ch = in.read(); } in.close(); //system.out.println(baos.tostring()); byte[] content = baos.tobytearray(); baos.close(); //转发数据包 dataoutputstream outtostampserver = new dataoutputstream(new bufferedoutputstream(conn.getoutputstream())); outtostampserver.write(content); outtostampserver.flush(); outtostampserver.close(); int response_code = conn.getresponsecode(); system.out.println( "response_code " + response_code); system.out.println( "conn.getresponsemessage() " + conn.getresponsemessage()); system.out.println( "conn.getcontentlength() " + conn.getcontentlength()); system.out.println( "conn.getcontenttype() " + conn.getcontenttype()); /*log( "cebseal.java 272 response code: "+response_code); log( "cebseal.java 273 response message: "+conn.getresponsemessage()); log( "cebseal.java 274 response length: "+conn.getcontentlength()); log( "cebseal.java 275 response contenttype: "+conn.getcontenttype());*/ } //读取公章服务器的执行结果 in = new datainputstream(new bufferedinputstream(conn.getinputstream())); int ch = -1; ch = in.read(); while(ch!=-1){ baos.write(ch); ch = in.read(); } in.close(); byte[] content = baos.tobytearray(); baos.close(); retval = new string(content); system.out.println( "返回值: " + retval); if(dooutput){ dataoutputstream outtoclient = new dataoutputstream(response.getoutputstream()); outtoclient.write(content); } conn.disconnect(); return retval; /*string createid = request.getparameter( "createid "); string issueid = request.getparameter( "issueid "); request.getattributenames(); map reqmap = request.getparametermap(); string paramin = " "; for (iterator iter = reqmap.keyset().iterator(); iter.hasnext();) { string param = (string) iter.next(); string paramstr = param + "= " + ((string[]) reqmap.get(param))[0]; paramin = paramin + paramstr + "& "; } string s1=sendpost(url,paramin); return s1;*/ }//invokeremote() 问题就是通过这种方式, 导致ca服务器那边有的参数获取不到, 但是客户端直接连ca服务器验证是好的, 请大家帮帮忙.... |
|
|
|
|