Search By Google
Komentar
    Kalender
    Nopember 2009
    S S R K J S M
    « Feb    
     1
    2345678
    9101112131415
    16171819202122
    23242526272829
    30  
    Ngobrol Yuks
    Category
    Buy Your Wordpress E-commerce Theme. Buy Now



    Proactol







    UniqueHoodia



    PenisHealth



    MoreNiche



    SizeGenetics



    AppStore Charts

    Archive for the ‘Java’ Category

    JAVA SCRIPT : Java Script example

    Selasa, Januari 6th, 2009

    Disini ada beberapa contoh p

    Contoh java script code

    JAVA : Call EJB3 from jetty

    Kamis, Nopember 27th, 2008

    
    FYI I got the injection to work. When I was putting together a demonstration the injection started working. The problem has to do with dependencies in the pom.xml. I am not sure if there was something extra causing the problem or perhaps the order of the jars in the classpath. I am uploading an example

    By the way this example demonstrations embedding openEJB in Jetty. The important piece of the puzzle is in the WAR/pom.xml:


    <plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>maven-jetty-plugin</artifactId>
    <configuration>
    <scanIntervalSeconds>5</scanIntervalSeconds>
    <contextPath>/example</contextPath>
    <systemProperties>
    <systemProperty>
    <name>java.naming.factory.initial</name>
    <value>org.apache.openejb.client.LocalInitialContextFactory</value>
    </systemProperty>
    <systemProperty>
    <name>java.naming.factory.url.pkgs</name>
    <value>org.mortbay.naming</value>
    </systemProperty>
    </systemProperties>
    </configuration>
    <dependencies>
    </dependencies>
    </plugin>

    

    The system property “java.naming.factory.url.pkgs” is the key. From what I can tell openEJB’s IvmContext will attempt to do JNDI lookups and if it fails will look for additional ObjectFactories and delegate to them. By adding the “org.morbay.naming” system property IvmContext finds the Jetty JNDI context. Without this setting the jetty plugin will fail with the error: “javax.naming.NameNotFoundException: Name “java:comp” not found.”

    source : http://www.nabble.com/Re:-Tomcat—Injection:-No-such-property-p16421933.html

    JAVA : How to use Grizzly framework

    Rabu, Nopember 19th, 2008

    Dalam artikel ini akan dijelaskan bagaimana menggunakan Grizzly. Grizzly mempermudah kita dalam managemen NIO.

    1. Membuat class GrizzlyConnectionListener, bertugas me-listen pesan pada port tertentu apabila ada pesan yang
    masuk.

    public class GrizzlyConnectionListener {
    private static final int PORT=8000;
    /**
    * Init
    */
    public void init() {

    System.out.println(”listening for incomming TCP Connections on port : ” + f_port);
    try {
    //[1].
    Controller controller = new Controller();
    TCPSelectorHandler tcpSelectorHandler = new TCPSelectorHandler();
    tcpSelectorHandler.setPort(PORT); // TODO: abstract to JMX configuration

    Pipeline pipeline = new DefaultPipeline();
    pipeline.setMaxThreads(5); // TODO: abstract to JMX configuration
    controller.setPipeline(pipeline);

    // we need to create a listener that will not impose a timeout value, hence a BaseSelectionKeyHandler object is defined
    // refer to: http://www2.sebastiendionne.ca:8282/grizzly/grizzly-migration-guide-part-3/print.html
    BaseSelectionKeyHandler keyHandler = new BaseSelectionKeyHandler();
    tcpSelectorHandler.setSelectionKeyHandler(keyHandler);
    controller.addSelectorHandler(tcpSelectorHandler);

    final ProtocolChain protocolChain = new DefaultProtocolChain();

    protocolChain.addFilter(new TacProtocolFilter());
    //protocolChain.addFilter(new TacManagerFilter());
    protocolChain.addFilter(new TacValidatorFilter());
    ((DefaultProtocolChain)protocolChain).setContinuousExecution(true);

    ProtocolChainInstanceHandler pciHandler = new DefaultProtocolChainInstanceHandler() {
    public ProtocolChain poll() {
    return protocolChain;
    }

    public boolean offer(ProtocolChain instance) {
    return true;
    }
    };

    controller.setProtocolChainInstanceHandler(pciHandler);

    try {
    controller.start();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }

    public static void main(String[] args) {
    System.out.println(”Starting Grizzly Listener …. on port “+PORT);
    System.out.println(”Waiting for connection ……!”);
    init();
    }

    Sedikit penjelasan tentang code diatas, lihat comment number :
    [1]. Start grizzly untuk listen pesan yang datang melalui koneksi TCP.

    Controller controller = new Controller();
    TCPSelectorHandler tcpSelectorHandler = new TCPSelectorHandler();
    tcpSelectorHandler.setPort(f_port);
    controller.addSelectorHandler(tcpSelectorHandler);

    Jika ingin menggunakan koneksi UDP atau SSL tambahkan SelectorHandler baru.
    Grizzly menangani beberapa protocol handler : TCPSelectorHandler, UDPSelectorHandler, SSLSelectorHandler. Kita juga bisa membuatt handler sendiri jika diinginkan dengan cara implements SelectorHandler.

    I said that Grizzly came with lot of default settings that will do the job for most of us. One of these settings is the build in ThreadPool. In Grizzly it’s called : Pipeline. You can change the Pipeline in the controller with a few lines.

    Pipeline pipeline = new DefaultPipeline();
    pipeline.setMaxThreads(5);
    controller.setPipeline(pipeline);

    Secara default SelectionKeyHandler pada Grizzly mempunyai timeout koneksi. Kita bisa mengubah timeout koneksi ini sesuai dengan yang kita inginkan, atau membuat permanen koneksi dengan server.
    Gunakan kode di bawah ini bila ingin mengubah nilai timeout :

    DefaultSelectionKeyHandler keyHandler = new DefaultSelectionKeyHandler();
    //keep connection for 30 minutes
    keyHandler.setTimeout(30 * 1000 * 60);

    tcpSelectorHandler.setSelectionKeyHandler(keyHandler);

    Pada contoh class listener di atas menciptakan koneksi yang permanen, tidak menggunakan timeout jadi harus menggunakan handler : BaseSelectionKeyHandler.

    tcpSelectorHandler.setSelectionKeyHandler(new BaseSelectionKeyHandler());

    2. Bagaimana kita membaca pesan dari client dan bagaimana kita memberi respon kepada mereka.
    ada 3 langkah :

    Pertama : buat sebuah class ParserProtocolFilter : Class filter ini akan mem-parse pesan yang datang dari client dan meng-extract kueri yang valid.

    Kedua : buat sebuah class ProtocolFilter : Class filter ini akan menerima kueri yang dikirimkan oleh filter sebelumnya dan akan memproses kueri.

    Ketiga : buat sebuah class ProtocolHandler yang akan menangani filter sebelumnya dan menentukan urutan

    final ProtocolChain protocolChain = new DefaultProtocolChain();

    protocolChain.addFilter(new ParserProtocolFilter());
    //protocolChain.addFilter(new TacManagerFilter());
    protocolChain.addFilter(new ProtocolFilter());
    ((DefaultProtocolChain)protocolChain).setContinuousExecution(true);

    ProtocolChainInstanceHandler pciHandler = new DefaultProtocolChainInstanceHandler() {
    public ProtocolChain poll() {
    return protocolChain;
    }

    public boolean offer(ProtocolChain instance) {
    return true;
    }
    };

    controller.setProtocolChainInstanceHandler(pciHandler);

    (lagi…)

    Struts: Iterasi Map menggunakan tag

    Kamis, Nopember 13th, 2008

    How to get the information data from Map or SortedMap in your JSP page.
    Here is the example :

    1. Set iterator value with map.entrySet(), will get all the value set. Remember that the Set type is not sorted.


    2. This is how to get the key of Map.

    3. This is how to get the value of Map.

    Complete code :



    Struts : Perbedaan Tipe Result Chain dan Redirect action

    Rabu, Nopember 12th, 2008

    Chain result type is used for Action Chaining which means that the source result invokes an entire other action, complete with it’s own interceptor stack and result.

    Redirect Action result type is used to redirect to another Action which means making your source Action, after it has successfully executed, result in a redirect.

    As a rule, Action Chaining is not recommended. Redirect Result or the Redirect Action Result is preferred over Chain Result.