2008年7月30日星期三

(ZT)Java 调用 https webservice

Java 要调用远程Https webservice 必需具用远程服务器提供的客户端信任书及密钥.

将client.keystore和client.truststore拷贝到classes\test目录下.

package test;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class TestEcVoteNotice
{
public static void main(String [] args) throws Exception {
System.setProperty("javax.net.ssl.keyStore", "test\\client.keystore");
System.setProperty("javax.net.ssl.keyStorePassword", "abc");
System.setProperty("javax.net.ssl.trustStore", "test\\client.truststore");
System.setProperty("javax.net.ssl.trustStorePassword", "abc");


String endpoint = "https://localhost:" +"8443"+ "/axis/services/EcVoteNotice";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName("toStringP");
String res = (String) call.invoke( new Object[] {"Box"} );
call.setOperationName("toString");
String res2 = (String) call.invoke( new Object[] {} );

System.out.println( res+"/"+res2 );
}
}

在classes目录下执行.

java -cp %AXISCLASSPATH% test.TestEcVoteNotice

Refrence: http://wwwww.javaeye.com/blog/94854

2008年7月23日星期三

下载文件

下载文件的代码,不论格式,从碰盘将文件读出来,下载

response.setContentType("application/x-download");//设置为下载application/x-download
response.addHeader("Content-Disposition","attachment;filename=" + filePath);
OutputStream outputStream = response.getOutputStream();
String fileRealPath = "";
fileRealPath = siteRealPath + filePath;

InputStream inputStream = new FileInputStream(fileRealPath);
byte[] buffer = new byte[1024];
int i = -1;
while ((i = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, i);
}
outputStream.flush();
outputStream.close();

2008年7月22日星期二

mysql+proxool经常出现数据库连接异常

mysql+proxool经常出现数据库连接异常

原因:
1. 如果一段时间(默认 8 小时)不访问应用(数据库),则 mysql 的连接会自动断开,下次连接的时候,就需要重新建立连接才可以访问

解决方法:
1. 设置 mysql 的默认断开时间, 启动 ini 文件中的 wait_timeout 参数,以秒计,如下表示两小时
wait_timeout = 7200

2. 设置 proxool.xml 文件
a. drive-url 应该增加 autoReconnect 参数,如下:
jdbc:mysql://localhost:3308/secfox_som?autoReconnect=true
b. proxool 结点下应该增加两行,如下:
60000
select CURRENT_DATE
第一个参数以 ms 计,表示多长时间后自动重新连接,以保持连接,本例中表示 60 秒(这个时间应该比 第 1 步中的 wait_timeout 短)
第二个参数,表示用什么 sql 语句来自动连接数据库