Interstage 5 Apworks EJB Application Internet Revision History Edition Date Author Reviewed by Remarks 1 2002/10/11 2 2003/05/19 3 2003/06/18 EJB 4 2003/09/25 Apworks5.1
[ Stateless Session Bean ] ApworksJava, Web Application EJB. EJB, EJB Interstage Deploy. Session Bean ( Stateless Bean ) Deployment Tool Deploy EJB Test. - Interstage Application Server Plus Developer V5.0.1 WAS Interstage Application Server Apworks. PC, EJB Application Remote Deploy. PC O/S. No. Operating System Name Version, level 1 Windows NT(R) Server 4.0(*1) 2 Windows NT(R) Server, Enterprise Edition 4.0(*1) 3 Windows(R) 2000 Server - 4 Windows(R) 2000 Advanced Server - 5 Windows(R) 2000 Professional - 6 Windows(R) XP Professional - Fujitsu Eclipse Board Member Apworks Eclipse.
< Stateless Session Bean > APWORKS.( [ ] [ ] [Interstage Plus] [Apworks] [Apworks]) 1. [ ] [ ] [ ] -> Enterprise JavaBeans Project
2.. ( HelloEJB ) (. ) 3.. Java Library [ ].
4. Code Geneation. [ ]. 5. EJB, Package EJB.( : packagehelloejb EJB : HelloEJB )
6. Transaction Management Type. ( Container ) 7. ejbcreate()..
8.. Business. Business ( add hello().) *) Return Type.
9.. HelloEJBHome.java : HelloEJBRemote.java : Remote HelloEJB.java : EJB ejb-jar.xml : ejb 10. HelloEJB.java. * EJB (ejb-jar.xml) LANG. (1) JNDI import import javax.naming.*;. (2) hello().. public String hello() { } System.out.println("hello Method called ========="); try { Context ic = new InitialContext(); String lang = (String)ic.lookup("java:comp/env/LANG"); if (lang.equalsignorecase("korean")) { return "? EJB"; } else if (lang.equalsignorecase("english")) { return "Hello EJB"; } } catch (Exception e) { } return "???? EJB!!";
11. ejb-jar.xml Bean. Apworks Tree ejb-jar.xml. HelloBean Environment Property Tab LANG KOREAN Setting. *Property Name : LANG *Type : java.lang.string *Value : KOREAN 12. Build. * [ ] [ ] ( F7 ) HelloEJB.jar. BuildjarWAS Deploy. InterstageJ2EE Management Tool EJB Deployment Wizard InterstageDeploy 2.
< Client > Apworks Interstage Interstage Client Package 2. (1) hosts Interstage Server IP. Windows2000 : c:winnt/system32/drivers/etc/hosts Windows95/98: c:windows/hosts ( ). 203.248.112.37 hostname (2) C:INTERSTAGEODWINetcINITHOST. hostname 8002 < Bean 1 : J2EE Management Tool > 1. [ ] [ ] [Interstage Operation Tool]. Interstage IP host. (12000) 2. O/S.
3. J2EE Management Tool. 4. EJBDeployIJServer [Deploy/UnDeploy]. MyServer IJServerEJBDeploy.
5. EJB jar Deploy. ( Deploy Start ) HelloEJB.
< Bean 2 : J2EE Management Tool > 1. [ ] [ ] - [EJB Deployment Wizard]. Next >. 2. DeployEJB, Next>. EJB SOAP Service Application SOAP.
3. Server fileclient Deploy. [ Server ] EJB Application. EJB ContainerDeploy. C:INTERSTAGEJ2EEvardeploymentdeployedejb [ Client ] EJB Client Stub. Test Application. C:INTERSTAGEJ2EEvardeploymentdeployeddistribute 4. Deployment.
5. Remote Install Deploy. (1) Interstage ServerInstall. - C:INTERSTAGEJ2EEvardeploymentdeployedejbHelloEJB Interstage install.shinstall.bat. (2) 3 Remote Install Remote. Option. (: -s [ IJServer] ) administrator Install. ( Solairs root) < : IJServer. > 5. InstallEJB Application. # ejbinfoapfolder -l path: C:InterstageJ2EEvardeploymentdeployedejbapp name type ssl CartBean EB/stateful OFF HelloEJB EB/stateless OFF total 2 EJB application(s) entried
< > 3., Interstage. 1. ejbdstarteb. 2. isstartwu. 3. J2EE Management Tool. 1. ejbdstarteb. ( # ejbstarteb s [IJServer] ) # ejbdstarteb -s MyServer 2.. # isstartwu MyServer 3. J2EE Management Tool. ( Start )
< Test Application > 1. [ ] [ ] [ ] -> Pure Java Project 2. ( : TestHelloEJB )
3.. 4. Interstage J2EE Library
5. Call EJB application from J2EE Application Client. 6. Add External Folders. C:INTERSTAGEJ2EEvardeploymentdeployeddistributeHelloEJBeb ) - orb.properties JDK jrelib. C:INTERSTAGEEJBetcorb.properties C:APWJBK3jdkjrelib. Orb.properties CORBA., ApworksEJB Test Client EJB.
7. EJB Test Client. 8., TestEJB jar.
9. Client type J2EE1.3. 10. TestHelloEJB.java [ ] -> [ ] -> [Java ].
< ( ) : EJB Access jsp application >, HelloEJB Bean jsp. <%@ page contenttype="text/html; charset=euc-kr" %> <%@ page import ="javax.ejb.*,java.io.*" %> <%@ page import ="javax.naming.*" %> <%@ page import ="javax.rmi.*" %> <%@ page import ="PackageHelloEJB.*" %> <% javax.naming.context ic = new javax.naming.initialcontext(); java.lang.object obj = (Object)ic.lookup("java:comp/env/ejb/HelloEJB"); HelloEJBHome home = (HelloEJBHome)javax.rmi.PortableRemoteObject.narrow(obj,HelloEJBHome.class); try{ HelloEJBRemote eb = home.create(); String strhello = eb.hello(); out.println("helloejb Bean' return String : " + strhello + " "); eb.remove(); }catch (java.rmi.remoteexception e) { e.printstacktrace(); }catch (javax.ejb.createexception e) { e.printstacktrace(); }catch(exception e){ } e.printstacktrace(); %> out.println("fighting");
[ Entity Bean ] < TestDB Table > Sample Table. Schema Table Column SCOTT MEMBER NAME ID AGE SALARY Table DB Script [Apworks etccreateoracle.sql. ======================================== CREATE TABLE MEMBER ( NAME CHAR(20), ID NUMBER(5), AGE NUMBER(2), SALARY NUMBER(6), PRIMARY KEY(ID) ) ======================================== The sections below explain how to create an entity bean, with an emphasis on special features of entity beans.
< Entity Bean > 1. [File]>[New]>[Project] Enterprise JavaBeans Project. 2.. ( EntityBean )
3.. Java Library [ ].. Oracle JDBC Entity Bean.
4. [Finish] 5. Bean TypeEJB. BMP
6. Entity Bean Data Source Name. ( : ORACLE )
7. Persistence Field. Add, DB Browse DB. DB.
Table. Persistence field,.
8. EjbCreate. [Next] 9. Finder Method. Add finder.
ejbfindbyage java.util.enumeration short age WHERE @AGE >=?age? ejbfindbysalary java.util.collection long salary WHERE >=?salary? @SALARY EJB Collection. 10. ejbfindbyage method. OK. Note WHERE @, "?". ejbfindbysalary.
. [Next]
File name ejb-jar.xml MemberBmp.java MemberBmpHome.java MemberBmpRemote.java MemberBmpRecord.java MemberBmpPrimaryKey.java Description deployment descriptor file Enterprise bean source Home interface source Remote interface source Record class containing all persistence fields Primary key class
13. ejb-jar.xml.. entity bean session bean, Client Application transaction [Required]. 14.. ( Session Bean ) 15. EJB Deploy. ( Session Bean ) JNDI Data Resource Interstage.
[ Entity Bean ] 1. [File]>[New]>[Project] Pure Java Project. 2.
3.. 4. Interstage J2EE Library
5. Call EJB application from J2EE Application Client. 6. Add External Folders EntityBean.jar. ) - orb.properties JDK jrelib. C:INTERSTAGEEJBetcorb.properties C:APWJBK3jdkjrelib. Orb.properties CORBA., ApworksEJB Test Client EJB.
7. EJB Test Client. 8., TestEJB jar.
9. Client type J2EE1.3. Modify the run method processing for EntityTest.java. package sample; /** * @author * * To change this generated comment, edit the template variable "typecomment": * Window>Preferences>Java>Templates. * To enable and disable the creation of type comments go to * Window>Preferences>Java>Code Generation. */ public class EntityTest { public static boolean bdump; /** * run. * @param args */
public void run(java.lang.string[] args) { // To output operation result to the file, delete the comment marks. // try { // System.setOut(new java.io.printstream( // new java.io.fileoutputstream("log.txt"))); // } // catch (java.io.filenotfoundexception ex) { // ex.printstacktrace(); // System.exit(1); // } // When the operation result is unnecessary, false is set. bdump = true; MemberBmpClient eb1 = new MemberBmpClient(); MemberBmpRecord record = new MemberBmpRecord(); record.name = "Taro Fujitsu"; record.id = 4; record.age = 31; record.salary = 500; eb1.create(record); eb1.findbyage((short)20); eb1.getrecord(); while(eb1.nextelement()!= null) { eb1.getrecord(); } } eb1.findbysalary((long)300); eb1.getrecord(); while(eb1.nextelement()!= null) { eb1.getrecord(); } /** * main. * @param args */ public static void main(java.lang.string[] args) { System.setProperty( "com.fujitsu.interstage.j2ee.deploymentdescriptorclient", "C:APWeclipseworkspaceEntityTestsrcMETA- INFapplication-client.xml"); // System.setProperty("java.naming.factory.initial", // "com.fujitsu.interstage.ejb.jndi.fjcnctxfactoryforclient"); System.setProperty( "java.naming.factory.initial", "com.fujitsu.interstage.j2ee.jndi.initialcontextfactoryforclient"); EntityTest object = new EntityTest(); object.run(args);
} /** * dump. * @param s */ public static void dump(string s) { if (bdump) { System.out.println(s); } } /** * dump. * @param s * @param obj */ public static void dump(string s, Object obj) { if (bdump) { if (obj instanceof sample.memberbmpremote) { sample.memberbmpremote data = (sample.memberbmpremote) obj; EntityTest.dump(s + "{"); EntityTest.dump(" }"); } else if (obj instanceof sample.memberbmprecord) { sample.memberbmprecord data = (sample.memberbmprecord) obj; EntityTest.dump(s + "{"); EntityTest.dump(" NAME=" + data.name); EntityTest.dump(" ID=" + data.id); EntityTest.dump(" AGE=" + data.age); EntityTest.dump(" SALARY=" + data.salary); EntityTest.dump(" }"); } else if (obj instanceof sample.memberbmpprimarykey) { sample.memberbmpprimarykey data = (sample.memberbmpprimarykey) obj; EntityTest.dump(s + "{"); EntityTest.dump(" ID=" + data.id); EntityTest.dump(" }"); } else if (obj instanceof java.util.enumeration) { java.util.enumeration data = (java.util.enumeration) obj; EntityTest.dump(s + "{"); EntityTest.dump(" }"); } else if (obj instanceof java.util.collection) { java.util.collection data = (java.util.collection) obj; EntityTest.dump(s + "{"); EntityTest.dump(" }"); } }
} } 11. Test Client,.