Archive for the ‘Java’ Category
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, 2008Dalam 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);
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, 2008Chain 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.


**** Info: In Kürze gibt es ein erstes Update der n-tv mobil Applikation. Der Startvorgang wird durch eine überarbeitete Startseite erheblich beschleunig...
Finde heraus, ob du über das Thema Sex wirklich Bescheid weißt.
Anhand dieses Tests kannst du überprüfen, ob du tatsächlich so viel über Sex weißt,...
Du kannst den tollsten virtuellen Hund entwickeln und ihn deinen Freunden und der ganzen Welt zeigen!
Adoptiere deinen eigenen streichelbaren, liebenswer...
PLEASE NOTE: This is the free version of the Unblock Me game with a limited puzzles and difficult levels. The following features are available only in the ...
Mit MobileTV von T-Mobile haben Sie beste TV-Unterhaltung jederzeit auf Ihrem iPhone 3G/3GS.
T-Mobile bietet Ihnen eine breite Auswahl an Kanälen an:
? d...
Unter dem Motto ?Entdecke Deinen Ort? bietet DasÖrtliche nun auch auf dem iPhone die gewerblichen und privaten Verzeichniseinträge Deutschlands in gewohn...
Sarkasmus pur...
Deutschland steckt in der Krise und das iPhone verkauft sich wie geschnitten Brot.
Da liegt es doch nahe, sich auf dem iPhone anzusehen,...
Roll-out with the FREE TRANSFORMERS digital BUMBLEBEE action figure! Touch, swipe and drag Bumblebee to change from vehicle to robot mode and back again. P...
Connect two iPhones 3G via Bluetooth to build an endless racing track.
The Endless Racing Game is one of the first multiplayer games, where the game acti...
Think you have a good vocabulary? Take on your iPhone or a friend in this chalkboard classic and find out how good your vocabulary really is.
Hangman Fre...