Connection always successful when installed anti-virus application

When I try to use URLConnection to check if a url is accessible using the following code:

try {
    URL url = new URL("http://169.254.169.254/latest");

    URLConnection connection = url.openConnection();
    connection.setConnectTimeout(5000);
    connection.connect();
    System.out.println("Connected successfully using url");
} catch (IOException e) {
        e.printStackTrace();
}

I expected the behavior is: connect should be success if the host is reachable, else throw exception. It works fine without the anti-virus application, but always print “connected successfully” even the host is not reachable. Continue reading “Connection always successful when installed anti-virus application”

基于JavaScript的代码自动生成工具

JavaScript Based Code Generator – codegen

工具主页

http://thelei.sourceforge.net

目的

快速生成程序代码, 比如Struts, Spring, Jdbc/Hibernate所有前后台的代码.

简单介绍

本工具生成代码的思想是读取数据库中表的结构, 使用JavaScript作为脚本语言编写模板, 生成各种代码或者文件, 支持各种格式的文本文件, Java, C#, PHP 等, 只要是文本文件, 都可以生成, 因为生成什么是由你完全自己定义的. 对数据库的访问是通过插件的形式进行的, 所以易于扩充, 目前支持Mysql, 以及支持Ado连接的数据库.

本工具开发于2006年, 经过两年的内部使用, 进行了不断改进, 现在把它公布出来, 希望能有更多的人用它, 提意见, 然后把它做的更好.

什么时候用它

有时候在项目开发过程中有大量的简单重复劳动, 以Struts, Spring, Jdbc/Hibernate为例, 对数据库中的每张表, 都有其相对应的Dao(2), Service(2), Action(Class+Validation2), Jsp(list+edit+add=3), 需要新建10多个文件/目录,  而这个过程是很枯燥的, 但又会花不少时间, Continue reading “基于JavaScript的代码自动生成工具”

Introduce a tool to generate code by writing JavaScript

Java Based Code Generator – jbcgen

home page:

http://sourceforge.net/projects/jbcgen/

Short Description:

This code generator generates files from database and templates written in JavaScript. it supports db plugin, and it’s easy to extend and use. It supports mysql and db which support ado connection(under windows only) for now.

When To Use

It should be used especially when the code logic is similar, but the table is different. It will save much of your time by generating code automatically instead of copy&paste. For example, you want to write 5 files for each table, you only need to write lines of javascript code without coding the files lots of time. Continue reading “Introduce a tool to generate code by writing JavaScript”

集成ACEGI 进行权限控制

一. 简单介绍

1.1 本文目的

集成Acegi到自己的项目中, 并且将用户信息和权限放到数据库, 提供方法允许权限动态变化,变化后自动加载最新的权限

本文介绍Acegi例子的时候采用的是acegi-security-samples-tutorial-1.0.6.war

阅读本文需要对Spring有一定的了解, 如果你还没有接触过, 有些地方可能不容易理解, 这时候可能需要参考本文后附的Spring地址, 先了解一下Spring的基本知识.

本文使用的是Mysql数据库, 如果你使用其他的数据库, 可能需要修改相应的SQL.

本文及所附的全部代码放在http://acegi-test.sourceforge.net/

1.2 安装与配置

项目主页: http://www.acegisecurity.org/
Continue reading “集成ACEGI 进行权限控制”