cerulean

2007年12月17日

从上班开始没多久,就开始用Evernote,是portable 2.2版本。
好记性不如烂笔头。真的是做到了随手记,尤其是搜索功能简单易用,用来挖很久以前记下的tips,界面也很简洁,明了、够用。
备份也方便,反正换了电脑,文件夹直接拷贝,数据没丢。

就这样,一用多少年过去了。
如今,“印象笔记”在iphone应用推荐榜的笔记类里一直居高位,图标也早就不是我v2.2的老土模样,如果不是英文名字就叫evernote,我完全对不上号。
人家其实从v3开始就不是老土的本地应用了,都讲究“云”了。

虽然手头的v2.2完全满足我随手记一记的需求,但是,本着与时俱进和稍微保证一下数据的安全性,我还是下了个最近的v4.x的版本,结果发现还是要从v3开始才能导入v2的数据。嗯,看来是落后太久了。
有一点夸奖一下:免费账户的每月上传容量是有限的,但是对于我这种文本笔记,够传3w条的。

——嗯,其实,本来只是个小软件的更新而已,竟然跑到blogjava写上一篇,可能是因为伴随感吧,再有点儿时过境迁的唏嘘。
posted @ 2012-11-22 11:35 cerulean 阅读(418) | 评论 (1)编辑 收藏
春节过后这几天干的活儿就没一件痛痛快快的?
第一天是发现编译环境有异动,我以为是代码有问题,折腾了1天多。。。
第二天是自己机器上的IE8抽疯弄得我以为是build有问题。。。
第三天从TimesTen转到Psql的各种毛病。。。

好吧。言归正传:
1)找一个跟表无关的通用的单纯的select语句作为测试语句不容易啊,
Dual是Oracle自带的表,其他DBS木有的。。不用Dual的话Oracle又不认。

2)Cause: org.postgresql.util.PSQLException: Method org.postgresql.jdbc2.Jdbc2PreparedStatement.setQueryTimeout(int) is not yet implemented.
这个错误,把sqlMapConfig.xml中在settings里配置的defaultStatementTimeout去掉就可以避免了。但是,这个配置对PSQL应该OK啊。。。待查

【续】——
defaultStatementTimeout 确实不是所有的driver都支持的。
但去掉的话,TimesTen又不干了:太囧了。。。
[TimesTen][TimesTen 7.0.5.9.0 CLIENT]Query Timeout must be numeric; if the Network Timeout
is non-zero, the Query Timeout must be greater than zero and less than the Network Timeout, else if the Network Timeout is zero, the Query Timeout must be greater than or equal to zero.
兜兜转转又遇到了这个之前遇到过的问题。这些driver就不能统一统一咩!

posted @ 2012-02-01 17:32 cerulean 阅读(1162) | 评论 (0)编辑 收藏
parseInt(String s, int radix) 
Parses the string argument as a signed integer in the radix specified by the second argument.

今儿头回用,真是……反省ing

posted @ 2012-01-18 17:28 cerulean 阅读(337) | 评论 (0)编辑 收藏
文档写到现在,猛然说不上abbreviation 和 acronym 的区别。。。真是惭愧。。。
abbreviation:单词、语句的缩略形式,缩到短一点儿。
acronym:“首字母”缩写
posted @ 2011-12-05 15:21 cerulean 阅读(459) | 评论 (0)编辑 收藏
之前都没注意过有这么个方法,否则判断日期格式就太不靠谱了。
又是晦涩的单词:setLenient(false),严格匹配日期格式
        SimpleDateFormat df = new SimpleDateFormat("MMddyyyy");
        
/*
         * With lenient parsing, the parser may use heuristics to interpret inputs that 
         * do not precisely match this object's format. 
         * With strict parsing, inputs must match this object's format. 
         
*/
        df.setLenient(
false);
        
try {
            Date a 
= df.parse("23232011");
            System.out.print(
"date: " + a);
        } 
catch (java.text.ParseException e) {
            
// TODO Auto-generated catch block
            e.printStackTrace();
        }

posted @ 2011-07-18 17:23 cerulean 阅读(3181) | 评论 (0)编辑 收藏
i18n,之前在J2EE里,自然用struts来做。但是Web Service里貌似应该不需要这部分,但是实际上,有些操作还是避免不了要支持多国语言。
查了一圈儿,好像WS-i18n还在working draft的阶段,而且好像已经好几年了……也没找到什么开源中间件的实现。
大意是在SOAP header中加上<i18n:international>相关的标签。
因为毕竟是Web Service,利用http header还是不太妥,还是要放在SOAP里面。

记录一下查到的链接,备用。

http://www.coderanch.com/t/224875/Web-Services/java/Web-Services-Internationalization-jax-ws
For a SOAP web service the language/country code should be part of the SOAP request and possibly the SOAP response. You can always base your solution on the above WS-I18N working draft.
Internationalization isn't as big a priority with SOAP web services as it is with web pages as web services are consumed by other applications - not humans. In most cases normalized "generic data" is exchanged which is displayed on the client using the client's locale. SOAP web services exchanging localized text are pretty much in the minority.

http://www.w3.org/TR/ws-i18n/


posted @ 2011-06-15 16:49 cerulean 阅读(256) | 评论 (0)编辑 收藏
这回是更加深深地体会到IDE的重要性了!
想当初要不是eclipse,估计上手过程会很痛苦;
后来myeclipse的官方网站竟然封掉了;
现在,眼巴巴瞅着NetBeans美丽的GUI Builder,假如当年Swing那部分是用NetBeans开发的,或者NetBeans可以不要那个.form的文件直接解析代码,就好了啊!!!
唉……
posted @ 2010-08-11 16:32 cerulean 阅读(292) | 评论 (0)编辑 收藏
繁琐的登陆过程让人抓狂,telnet到第一台机器输入用户名之前,点击SecureCRT里menu->Script->Start recording script,录下接下来的步骤,然后点击Stop recording script,就会提示保存脚本。以后登陆时,选择Run脚本就可以了。
posted @ 2010-07-07 08:54 cerulean 阅读(285) | 评论 (0)编辑 收藏
遍历集合,批量删除时,遇到ConcurrentModificationException
因为操作的集合会在过程中遇到结构性的改变,例如:
HashMap<String, String> testMap = new HashMap<String, String>();
        testMap.put(
"1""a");
        testMap.put(
"2""b");
        testMap.put(
"3""c");
        Set
<Map.Entry<String,String>> enterySet = testMap.entrySet();
        

        
for(Iterator<Map.Entry<String, String>> i = enterySet.iterator(); i.hasNext();){
            Map.Entry
<String, String> entry = i.next();
            
if(entry.getValue().equalsIgnoreCase("a")){
                testMap.remove(entry.getKey());
            }

        }


解决方法:不要在集合上删除,而是在迭代器上删除:i.remove();

p.s.还有另外一个可能性是多线程同时操作该集合了,那需要进行同步来避免。
posted @ 2010-06-11 13:57 cerulean 阅读(348) | 评论 (0)编辑 收藏
引子只是个小问题,JTextArea多行文本,想设置文字的对齐方式为居中对齐,却发现死活没有合适有效的方法,又试了JTextField和JLabel,都不理想。搜了一溜够看到JTextPane的解决方法,其实真是有点儿大材小用了。JTextPane里可以设置style,对齐方式、字体字号、颜色等等,并且还可以设置style的作用范围,挺方便的。另外,想把文字区域背景设为透明的也是在API中找了一通,才发现敢情就是setOpacity,呃,对这个单词实在是太不敏感了。。。。

把在coderanch上搜的例子贴在这里吧,以防以后忘了:
import java.awt.*;  
import javax.swing.*;  
import javax.swing.text.*;  
   
public class Styling  
{  
    
public Styling()  
    
{  
        String text 
= "To refer to locations within the sequence, the " +  
                      
"coordinates used are the location between two " +  
                      
"characters.\nAs the diagram below shows, a location " +  
                      
"in a text document can be referred to as a position, " +  
                      
"or an offset. This position is zero-based.";  
   
        SimpleAttributeSet aSet 
= new SimpleAttributeSet();   
        StyleConstants.setForeground(aSet, Color.blue);  
        StyleConstants.setBackground(aSet, Color.orange);  
        StyleConstants.setFontFamily(aSet, 
"lucida bright italic");  
        StyleConstants.setFontSize(aSet, 
18);  
   
        SimpleAttributeSet bSet 
= new SimpleAttributeSet();  
        StyleConstants.setAlignment(bSet, StyleConstants.ALIGN_CENTER);  
        StyleConstants.setUnderline(bSet, 
true);  
        StyleConstants.setFontFamily(bSet, 
"lucida typewriter bold");  
        StyleConstants.setFontSize(bSet, 
24);  
   
        JTextPane textPane 
= new JTextPane();  
        textPane.setText(text);  
        StyledDocument doc 
= textPane.getStyledDocument();  
        doc.setCharacterAttributes(
105, doc.getLength()-105, aSet, false);  
        doc.setParagraphAttributes(
0104, bSet, false);  
   
        JFrame f 
= new JFrame();  
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
        f.add(
new JScrollPane(textPane));  
        f.setSize(
400,400);  
        f.setLocation(
200,200);  
        f.setVisible(
true);  
    }
  
   
    
public static void main(String[] args)  
    
{  
        
new Styling();  
    }
  
}
  
posted @ 2010-03-10 17:20 cerulean 阅读(7801) | 评论 (1)编辑 收藏
之前用axis2生成代码的时候都没有在意过,一路用default configuration下来。
前一阵子发现以前的代码在生成时选择的data binding不是用默认的adb方式,而是用xmlbeans。
google了一番不同数据绑定的区别,好像也没什么结果,大意就是adb的最简单,但是有局限性;xmlbeans支持的比较全面,但是用起来有点儿复杂。不过,我也没有体会出来xmlbeans强大在哪里……只是知道生成的代码更多了,调用起来更绕弯子而已。。。

server端用xmlbeans生成,client端用adb生成,互通是没有问题的。
client端用xmlbeans生成时,需要把产生于resources里面的所有.class文件打成jar包加到client端的build path里,否则运行client加载类的时候就会报错了,好诡异,太不友好了。
类似这种错误:

ClassNotFoundException : Cannot load SchemaTypeSystem. Unable to load class with name schemaorg_apache_xmlbeans.system.s68C41DB812F52C975439BA10FE4FEE54.TypeSystemHolder. Make sure the generated binary files are on the classpath.


所幸是在官方网站上有说明:http://ws.apache.org/axis2/tools/1_2/CodegenToolReference.html
posted @ 2009-12-30 15:59 cerulean 阅读(662) | 评论 (0)编辑 收藏
一个JNLP文件中的资源必须由同一个证书签名
当需要不同证书时,可以创建多个JNLP文件,并在主JNLP文件中引用之。

遇到过的问题:找不到子JNLP文件中的资源
解决方法:竟然把子JNLP文件放到比主JNLP文件所在目录低一级就可以了?!
posted @ 2009-11-20 15:13 cerulean 阅读(446) | 评论 (0)编辑 收藏

 

JLabel.setText("<html>auto new line</html>");
JLabel.setText("<html>line<br>force new line</html>");

 

posted @ 2009-10-29 11:43 cerulean 阅读(3389) | 评论 (1)编辑 收藏
费了半天劲,敢情Firefox在3.0版本后又支持弹出modal window啦
window.showModalDialog


posted @ 2009-09-22 15:59 cerulean 阅读(312) | 评论 (0)编辑 收藏
HttpClient.getHttpConnectionManager().getParams().setSoTimeout()
HttpClient.getHttpConnectionManager().getParams().setConnectionTimeout()

第一个针对连接建立后,但是没有收到response的超时时间,测试时可将server simulator收到request后等一段时间后再回response。
出错信息:
java.net.SocketTimeoutException: Read timed out

第二个针对连接建立的超时时间,测试时可将目的IP地址设为不存在的IP地址。
出错信息:
org.apache.commons.httpclient.ConnectTimeoutException: The host did not accept the connection within timeout of 8000 ms
        at org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:154)
默认值为0,如果不设置的话大概2分多钟才会得到异常


posted @ 2009-09-10 16:09 cerulean 阅读(5146) | 评论 (1)编辑 收藏
导入了某证书至truststore,建立SSL连接时遇到错误
javax.net.ssl.SSLKeyException: RSA premaster secret error
Caused by: java.security.InvalidKeyException: Illegal key size or default parameters

在windows上双击查看该证书时发现Public Key是4096bit,查了一番后发现Java默认好像不能处理这么长的key,必须要按照JCE的一个Unlimited Strength Jurisdiction Policy
http://java.sun.com/javase/downloads/index_jdk5.jsp里面就有下载,这样貌似就可以处理这种强度比较高的了。


posted @ 2009-09-08 17:24 cerulean 阅读(2042) | 评论 (0)编辑 收藏
打印数组的方法,小地方,却老忘记,来自FindBugs的提示:
The code invokes toString on an array, which will generate a fairly useless result such as [C@16f0472. Consider using Arrays.toString to convert the array into a readable String that gives the contents of the array.

Arrays提供一系列接收不同类型数组作为参数的toString方法

String[] array = new String[]{"a","b","c"};
System.out.println(Arrays.toString(array));

posted @ 2009-08-17 15:17 cerulean 阅读(1126) | 评论 (0)编辑 收藏
FindBugs,http://findbugs.sourceforge.net/
发现代码中潜在bug的工具,有eclipse的插件,安装后右键单击java project name,点击Find Bugs,切换到FindBugs得perspective可以看到结果,速度还比较快,比之前用过的一个(虽然已经记不得名字了)快一些~具体的效果还是要逐个分析。

Bug categories:

Correctness bug
Probable bug - an apparent coding mistake resulting in code that was probably not what the developer intended. We strive for a low false positive rate.
Bad Practice
Violations of recommended and essential coding practice. Examples include hash code and equals problems, cloneable idiom, dropped exceptions, serializable problems, and misuse of finalize. We strive to make this analysis accurate, although some groups may not care about some of the bad practices.
Dodgy
Code that is confusing, anomalous, or written in a way that leads itself to errors. Examples include dead local stores, switch fall through, unconfirmed casts, and redundant null check of value known to be null. More false positives accepted. In previous versions of FindBugs, this category was known as Style.
Multithreaded correctness
     Incorrect lazy initialization and update of static field
     Calls Thread.sleep() with a lock held: better to use wait(lock)
     Synchronization on interned String could deadlock: 最好不用字符串,以免重复
Performance
     invokes inefficient new String() constructor
     concatenates strings using + in a loop: better to use append StringBuffer
     inner class usage


posted @ 2009-08-14 16:04 cerulean 阅读(954) | 评论 (0)编辑 收藏
Server

创建本地证书:

keytool -genkey -alias testserver-keyalg RSA -keystore keystore

其中alias自己起一个别名,keystore为证书库的文件路径

还可以加上-keysize 1024、2048、4096等来指定公钥的大小,由此导出的证书查看时可以看到公钥的大小是与之一致的。keysize越大genkey时耗费时间越长。


会要求键入一个密码,为这个证书库的访问密码

会要求填写一些信息,姓名、单位、地区之类

最后要求键入一个密码,为这条证书别名的密码

导出cert

keytool -export -alias testserver-file testcert.cer -keystore keystore

这里的别名和文件名同上一步


Client

直接导入cert

Truststore文件中存储的是作为client,信任那些server的证书。所以需要将server提供的证书导入进来(当然可以导入n个),client才能信任。

keytool -import -alias testserver-file testcert.cer -keystore truststore

导入时需要输入密码,该密码应该是truststore文件的访问密码,密码正确才能修改其信息。

提示是否信任该证书信息,确认。

查看证书信息:

keytool –list –v –keystore truststore

如果导入过多个,则可以看到多条entry

删除某一个证书entry,通过指定别名来删:

keytool -delete -alias testserver-keystore truststore


上述是自签名的证书,证书链的长度只为
1

真正商用时,需要找相关机构(例如verisign)认证通过才能成为有效的证书:

生成证书签名请求:

keytool -certreq -keyalg RSA -alias testserver -file certreq.csr -keystore keystore

之后能够收到一个证书文件,证书链信息包含了该机构的一些信息,然后再导入。


有两种方法建立
HTTPS连接,

一种是,在java中可以设置相关的4个系统参数,指向相关的keystore,truststore,一旦设置,在运行时就不可改变了。除非一定要使用多个不同的证书库文件,否则可以把多个不同证书都导入到同一个证书库里,这样,设置系统参数为唯一的值也够用,而且也比较简单一些。

另一种是,自己继承相关接口实现自己的证书管理器,这样可以自定义相关行为,也可以load不同的证书库。


如果不设置
password,就认为不检查文件完整性,也能通过。如果设置了password,但是不正确,则会遇到密码错误的异常;如果server证书没有导入到client得信任列表里,则会遇到找不到可信证书的异常。

posted @ 2009-07-16 17:27 cerulean 阅读(541) | 评论 (0)编辑 收藏
一个反编译的好工具,600KB,简单好使又免费,比之前用过的好~
http://java.decompiler.free.fr/?q=jdgui
posted @ 2009-06-24 13:45 cerulean 阅读(273) | 评论 (0)编辑 收藏

MySQL Cluster 不支持windows
之前的说法是max版支持集群,standard版不支持,但是官方下载点里已经看不出任何关于max,standard的标志。官方网站上又说5.0版本已经包含了MySQL Cluster,所以还是下了个5.0的试试,结果是可以的。

基本的安装:
linux下官方网站的安装说明还是挺明确的,一步一步做就是了。
遇到了一个问题与这篇文章一模一样:http://www.91linux.com/html/linux_pub/fedora/20071114/8195.html
按它的方法修改之后再次

cd /usr/local/mysql
bin
/mysqld_safe --user=mysql &


Starting mysqld daemon with databases from /var/lib/mysql
看到上面这一行说明启动成功。

修改密码:

bin/mysqladmin -u root password yourpassword


允许远程访问:

bin/mysql -u root -p
grant all on 
*.* to root@"202.11.10.253" Identified by "dboomysql"

允许地址202.11.10.253上用root用户,密码dboomysql来连接mysql的所有数据库,付给所有权限。
实质上是修改了自带的database:mysql中user这一张表,与PostgreSQL需要修改配置文件相比还是方便一些。
另外就是MySQL的GUI客户端(MySQL Administrator)也比PostgreSQL的漂亮很多。

停止MySQL:
bin/mysqladmin -u root shutdown -p

安装完成后,按照这篇文章配置双机互备
http://hi.baidu.com/%CA%AB%D5%B9/blog/item/3b99dbc48140f7ca38db49f7.html
但是这篇文章有笔误:

四、初始化集群
在Server1中
# ndbd --nodeid=3 --initial
在Server2中
# ndbd --nodeid=4 --iniitial

应该改为——
四、初始化集群
在Server1中
# ndbd --ndb_nodeid=3 --initial
在Server2中
# ndbd --ndb_nodeid=4 --initial

这样的集群配置两台机器都是一样的,所以有2个管理节点,2个SQL节点,2个数据节点。集群的验证:从任何一台机器登上去操作数据都能双写。

ndb_mgm -e show

可以看到集群节点的信息。
从官方网站上看到的例子都是用了多于3台的机器来做的集群,仅用两台来做的方法好像是大家特意这么做的。

尽管集群配置完毕,但是应用程序与数据库建立连接不能使用其中任何一台机器的真实IP,否则一旦该机器网络连接出问题还是不行,所以还是要给DB集群的机器配置虚拟IP以供外部访问。


遇到过的问题:
无法mysqld_safe启动,也找不到日志
解决方法:加启动参数以指定日志

mysqld_safe --log-error=/var/log/mysqld.log

可以查看到错误日志了。

[ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
没辙,google呗,好像是系统数据库mysql里host表的权限有问题什么的,而mysql这个库是之前安装时初始化过的。

解决方法:删除data,重新install_db

rm -rf /usr/local/mysql/data
cd 
/usr/local/mysql
scripts
/mysql_install_db --user=mysql
chown 
-R root .
chown 
-R mysql data
chgrp 
-R mysql .

 

bin/mysqld_safe --log-error=/var/log/mysqld.log --ndb_nodeid=5 --user=mysql &

启动成功了。

btw, mysql官方网的forum好像不能“平板显示”,好不方便。


关闭Cluster,在管理节点所在的机器上:
/usr/local/mysql/ndb_mgm -e shutdown
关闭SQL节点的mysqld服务:
/usr/local/mysql/bin/mysqladmin -uroot shutdown

posted @ 2007-12-17 21:38 cerulean 阅读(589) | 评论 (0)编辑 收藏
java默认的JVM内存占用:初始1MB,最大64MB
可以通过java -Xms256m -Xmx256m ClassName来调整。
xms和xmx的值最好相同,否则调整的效率可能不高。
如果程序运行中,发生内存溢出,那么不会以Exception的形式抛出,而是"Error"
如果没有catch(Error error),那么控制台将显示错误:Exception in thread "main" java.lang.OutOfMemoryError: Java heap space,而且后面的程序也不会执行。
posted @ 2007-12-17 21:26 cerulean 阅读(1101) | 评论 (0)编辑 收藏
虽然RMI已经不大推荐使用了,但是方法还是要记住的。
在产生.class文件的根目录,例如/bin
cd /bin
rmic com.test.RMIImpl

将在/bin/com/test目录下产生RMIImpl_Stub.class文件
cd /bin
jar cvf test.jar com
/test/RMIIntf.class com/test/RMIImpl_Stub.class

将在/bin目录下产生test.jar文件,供RMI客户端调用
posted @ 2007-12-17 21:12 cerulean 阅读(861) | 评论 (0)编辑 收藏

遇到经典的getParameter中文乱码的问题,网上已经有很多总结和讨论了。
在jsp里调用了*.do?param=name,当name本身的值为中文时,在action里获取时有乱码问题。

调用.do的jsp页面头已经设置过

<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>


即便在action里设置了

request.setCharacterEncoding 

也没有效果。

最后的解决方法:

String str = request.getParameter("param");

改为

String str = new String(request.getParameter("param").getBytes("ISO-8859-1"),"GB2312");
posted @ 2007-12-17 21:09 cerulean 阅读(3694) | 评论 (0)编辑 收藏

导航

<2007年12月>
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

统计

常用链接

留言簿(3)

随笔分类

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜