This blog records some ideas, notes, and information of my works and studies in information technology.

Monday, November 9, 2009

SCJD Exam with J2SE 5.0--Chapter 4

Current page: p.102
There are three ways in controlling threads:
  1. Waiting
    Implicitly wait for competitive resources
    Explicitly wait by calling myObject.wait();
        
    --> myObject.notify(); or myObject.notifyAll(); can wake up waiting threads
  2. Yielding
    The thread gives up its order to other thread but doesn't release its resources!!
    myThread.yield();
    It's suitable for using it before processing a complicated task!!
  3. Blocking
  4. Sleeping
    Wait for at least a specified amount of time.

Convertz and Jing

Sunday, September 27, 2009

Wednesday, September 16, 2009

graphviz

http://www.graphviz.org/About.php

It's a powerful tool to draw a graph.

Thursday, August 20, 2009

Aptana Home Page

http://aptana.com/

A powerful tool for developing web sites. (PHP, AJAX, Ruby, ...)

Wednesday, July 1, 2009

Enterprise JavaBeans, 3.0 -- Chapter 17

  1. EJB 3.0 沒有定義Authentication的方式,只有定義Authorization的Annotation
    Jboss設定Authentication的方式在Section 36.1~!!
    設定在 %JBOSS_HOME%/server/default/conf/login-config.xml
  2. 範例只有普通文字檔設定的方式,JavaWorld.TW有稍微寫資料庫Mapping的方式
    http://www.javaworld.com.tw/jute/post/view?bid=7&id=244067
    有空試試看....

情境:
1. Database 存著 User <--> Role <--> Function的關係
2. Web Client 提供使用者Login UI,之後使用者的User-Password存在 Http Session中
3. 每當使用者要呼叫 EJB Remote時,應該要從 Http Session 取得 User-Password,放入 Properties,產生 Context,lookup EJB Remote!!

Java Serializable

"並非每個實作了Serializable介面的物件都可以被Serialization,如果這個物件繼承圖上的祖先,有其中一個是不可以被Serialization,那麼這個物件就不可以被Serialization。"


所以繼承一個非Serializable的物件,implements Serializable
仍然不能網路傳輸

Sunday, June 28, 2009

Load Properties in Java

http://www.javaworld.com/javaworld/javaqa/2003-08/01-qa-0808-property.html?page=2
Complete introduction
A simple example~

[Important!]
將設定檔放在Jar包外部執行!
final InputStream inStream = ClassLoader.getSystemResourceAsStream("EJBProp.properties");
取得的方式較簡單
重點在MANIFEST.MF中 設定Class-Path: ./
表示需從 class loader所在的位置搜尋檔案~!!

Eclipse plug-in: Fat Jar

http://www.javaworld.com.tw/jute/post/view?bid=20&id=111801&sty=1&tpg=1&age=0
Experience sharing in JavaWorld.TW

Official Site of Fat-Jar

It really works!!

Thursday, June 25, 2009

SCJD Exam with J2SE 5.0--Chapter 7

  • Socket Server P. 216
     。xxxSocketServer extends Thread:
    1. new DvdSocketServer(dbLocation, port).start();
    2. ServerSocket aServerSocket = new ServerSocket(port);
    3. while (true) {
    Socket aSocket = aServerSocket.accept();
    DbSocketRequest request = new DbSocketRequest(dbLocation, aSocket);
    request.start();
    }
    。xxxSocketRequest implements Runnable:
    1. handle the input and output stream
    2. call executeRequest();
  • Application Protocol 1. Need a "Command" object to perform a protocol

Wednesday, June 24, 2009

JBossWS 2.0.GA - JAX-WS User Guide

http://www.jboss.org/jbossws/docs/jaxws_userguide-2.0/index.html#d0e126
Dynamic Web

EJB

My methods:
  1. It's easy to generate WSDL by writing SessionBean anotated with @WebService. You can find out the URL of the wsdl in the information of the console messages.
    http://localhost:8080/TSMEar-TSMEJB/AdminSDKeyChangeSessionBean?wsdl
  2. Use Eclipse to generate an JBossws client:
    a. New a dynamic web project.
    b. New a Web Service Client associated with the former web project
    --> try to generate specific client stubs!!!
    c. Copy the stubs to your own client project...
    It's better to include JBossws 3.1.2.GA library because it's lighter than JBoss server runtime!!
Another option for Web Services: Axis
It seems better to write client codes!

Java Certification

http://www.sun.com/training/certification/java/index.xml

The whole map...
SCEA is the highest level of java language~!!
SCJD is also a harder challenge~!!

I have gotten SCJP & SCWCD
Now I'm preparing SCBCD~!

A comparison of JAX-RPC & JAX-WS

http://www.ibm.com/developerworks/webservices/library/ws-tip-jaxwsrpc.html

Enterprise JavaBeans, 3.0 -- Chapter 19

EJB 3.0 supports
  • Java API for XML-based Web Services (JAX-WS) 2.0
  • Java API for XML-based RPC (JAX-RPC) 1.1
  • SOAP with Attachments API for Java (SAAJ)
  • Java API for XML Registries (JAXR)
    --access web services registries, UDDI

Tuesday, June 23, 2009

Enterprise JavaBeans, 3.0 -- Chapter 18

  • Http Tunneling
  • SOAP 1.1
  • WSDL 1.1

Saturday, June 20, 2009

J2ME Polish !!

http://www.j2mepolish.org/cms/topsection/home.html

J2ME Polish is a suite of tools and technologies aimed at mobile developers and companies within the mobile space.

Main features of J2ME Polish include:

  • Lush: A UI toolkit that is highly flexible and that can be designed outside of the application's source code.
  • Janus: A toolset for porting mobile application to different handsets and different technology platforms.
  • Touch: Technology for accessing server side content and communicating with remote parties.
  • Trunk: A persistence solution that allows you to load and save complex data with a single line of code.
  • Marjory: Our community maintained device database.

Set up SSL in JBoss

http://polinwei.blogspot.com/2009/02/jboss-jboss-ssl-https.html

Some steps are required!

Friday, June 19, 2009

Enterprise JavaBeans, 3.0 -- Chapter 12

Thursday, June 18, 2009

CVS Converter...

http://sourceforge.net/projects/javacsv/
http://www.csvreader.com/java_csv_samples.php
This is the package I use now.

Apache seems developing a bigger project of CSV...
But the project hasn't been updated since 17 May, 2008.
Is there any hope for this project?

Tuesday, June 16, 2009

How to transfer JSON to JQuery client in Struts 1.x

Other programmer's idea
http://www.junlu.com/msg/322793.html

JSON ORG

JSON-lib

  1. Download JSON-lib and install it into Web project
  2. There is nothing special required to do to pass the parameter to Actions.
    Just follow JQuery's function:
    $.post("/TSMWeb/cardImportAction.do", {actionType: "initAjax", comAccount: issuerSelectValue}, issuerSelectCallBack, "json");
  3. In Struts 2.x, the only thing you need to do is set up the struts.xml to notify the framework packing the response in JSON format.
  4. In Struts 1.x, you should create a JSONObject to transfer your java object into JSON format and use an "almost empty" JSP to send JSON messages:


    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
    ${tsmJSON}

  5. Save your JSON Object with a key name "tsmJSON" by calling request.setAttribute().
  6. That's it! Now you can catch the response in JSON format in your client JSP!

Monday, June 15, 2009

Sunday, June 14, 2009

Tips of JBoss

  1. If your EJB wants to include external libraries, you should pack those libraries with EJB.jar into an Ear file and set up the Class-Path in a MANIFEST.MF file in the META-INF dir of the EJB.jar
    --> Another crude way: set system constant--> JBOSS_CLASSPATH = %HSM's lib path%
    That would set up the classpath of JBoss's class loader(not very good...)

Tips of Eclipse

  1. Windows-->Preferences-->General-->Editors-->Text Editors
    a. Insert spaces for tabs
    b. Show line numbers
  2. Windows-->Preferences-->Java-->Code Style-->Formatter
    a. Set up how to automatically modify the codes.
  3. When you generate a jsp file, remember setting up encoding method in page directive or you can't save what you modify in the file in that encoding. ( Eclipse will generate Encoding Error!)
  4. (Any project) Properties-->Java Compiler-->Building: Output folder can set up what kinds of files you want to copy to the output folder!!

Saturday, June 13, 2009

EJB chapters haven't been read!

high priority: Finished!!
low priority: 6, 7, 8, 20, 21

Now is time to practice the exam...

Friday, June 12, 2009

The introduction of SCBCD

Sun Certified Business Component Developer for the Java Platform, Enterprise Edition 5 (CX-310-091)


EJB 3.0 Overview


  • Identify the uses, benefits, and characteristics of Enterprise JavaBeans technology, for version 3.0 of the EJB specification.
  • Identify the APIs that all EJB 3.0 containers must make available to developers.
  • Identify correct and incorrect statements or examples about EJB programming restrictions.
  • Match the seven EJB roles with the corresponding description of the role's responsibilities.
  • Describe the packaging and deployment requirements for enterprise beans.
  • Describe the purposes and uses of annotations and deployment descriptors, including how the two mechanisms interact, how overriding is handled, and how these mechanisms function at the class, method, and field levels.

Thursday, June 11, 2009

How to save binary data into Database

There are two ways to solve this problem.
  1. Base64: http://en.wikipedia.org/wiki/Base64
    This encoding method can transform binary data into special text format. The encoding method requires some future research!
  2. Hex: Transfer Hex byte into Hex String! The advantage of this encoding method is readable!
    ex: byte[]{00, a0, 30} --> String: "00a030"
Both encoding methods can be found in apache commons codec package!
These are two only ways to transfer binary data into Database.

Wednesday, June 10, 2009

How to set up Log4j parameters in JBoss?

[JBOSS_HOME]\server\default\conf\jboss-log4j.xml
Modify this file!

Sunday, May 10, 2009

How to set up struts 1.1 message pages

  1. Save your messages in ActionMessages.

    final ActionMessages errors = new ActionMessages();
    errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("ControlErrMessage", errMessage));

    a. ActionMessages.GLOBAL_MESSAGE is a special key in ActionMessages mapping, don't change it
    b. ControlErrMessage is the key defined in application.properties
  2. Add ActionMessages Object into HttpServletRequest

    request.setAttribute(Globals.MESSAGE_KEY, errors);

    a. Globals.MESSAGE_KEY is fixed value. It's used in JSP (the id value of html:messages)
  3. Show your message in JSP by using tag

    <html:messages id="message" message="true">
        <bean:write name="message">
    </html:messages>

How to set up Error Message in Struts

http://www.javaworld.com.tw/confluence/pages/viewpage.action?pageId=522

  1. Create application.properties
  2. Add the line:  to specify the location of application.properties (In src/)
  3. Add the setting of , for example
    <exception key="UserLogin.Password" path="/error.jsp" type="iii.tsm.exceptions.TSMException">
  4. Show the message in jsp by <html:error />

Wednesday, May 6, 2009

[TSM] Problems to be solved...

  1. File uploading
    Use org.apache.struts.upload.FormFile to store the uploading file
  2. File downloading
    Extend org.apache.struts.actions.DownloadAction and create your own downloading action.
    a. Save the data from DB to a temporary file.
    b. Link a special id with the generated file.
    c. Return the id.
    Then the actions using this downloading action could generate a hyper link with the id. End users click on the link and system would call downloading action and pass the id. DownloadAction will return FileStreamInfo object.

    POINT: Override the function:
    protected StreamInfo getStreamInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)

  3. Applet File saving (in the database or on the disk?)
    I decided to save applet files in the database. Ray told me that there are one advantages in saving files in the DB:
    You only need to backup DB and all data could be backuped in one step! (Consistence)
    The way to save your files into a DB is using org.apache.commons.codec.binary.Base64, which is in the commons-codec package.
    You should Use Base64 to encode binary data to plain text and save it into the DB.
    If you want to retrieve the data, you can use Base64 to decode the data from DB!

    Why should we use TEXT type to save binary data?

    Ray told me that: If you use Blob to save binary data, the saving way could be different in different DB provider!
    And you also have chances that you can't retrive data by normal "select" ways.
    Flexibility is lost!
  4. Do I have to change the common library in TSMWeb?
    Add new common library in TSMWeb. But keep the old one.
  5. Controlling exception
    Create TSMException, use try-catch to direct system message to error page
  6. Logging system
    Use java.util.logging.* to create a new logging system.
    It's not necessary because Jboss has it's own logging system. (The log file is in jboss-5.0.0.GA\server\default\log\.)
    http://www.jboss.org/community/docs/DOC-11280
    http://java.dzone.com/articles/configuring-logging-jboss
    How to set up Jboss logging system~
  7. TSMWeb call TSMEJB session bean
    Set up development environment
    Use the methods in the Orelly EJB 3 book. The main problem is that if you want to call an EJB remote call, you have to include necessary libraries listed in jboss-5.0.0.GA\client\jbossall-client.jar. Now I decided to put TSMWeb and TSMEJB both on the Jboss Envirnment because the jboss-javaee.jar conflicts with Servlet.class in Tomcat server.
  8. How to show Constant String from Constant Integer in JSP?
    Implement SimpleTagSupport libaray!!!!
  9. UserLoginFilter is waiting for being finished!!
    Finished
  10. Modify the primary key of CardSet and KeyProfile tables
    I decided to use UUID as primary keys of CardSet and KeyProfile tables

Monday, February 23, 2009

SCJD Exam with J2SE 5.0--Chapter 3

All the essential requirements are:
  1. Executable JAR
  2. Executable server-specific JAR
  3. src contains all the source codes
  4. The original files provided by SCJD examinator
  5. docs contains:
    a. Javadocs for API
    b. End user documentation
    c. Design decision documents

SCJD Exam with J2SE 5.0--Chapter 2

  1. Organizing a project
    a. Suggested Directory Structure
        src/
        classes/
        bkp/ --backup files
        tst/ -- source files for unit-testing
        tmp/
        log/
        doc/
            I.     Javadocs
            II.   End-user docs
            III. design desicions docs
            IV. version.txt
  2. Design Decisions Document
  3. Assertions
  4. Logging
    java.util.logging.Logger Logger  myLogger = Logger.getLogger("example.com.testApplication"); 
    java.util.logging.Handler  myLogger.addHandler(new FileHandler("temp.log")); 
    java.util.logging.FileHandler  myFileHandler.setFormatter(new SimpleFormatter());--Set the format of log files