Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2001 Systek Java 2 Enterprise Edition Workshop STEP-Platformen i praksis Johannes Brodwall, Systek.

Similar presentations


Presentation on theme: "Copyright © 2001 Systek Java 2 Enterprise Edition Workshop STEP-Platformen i praksis Johannes Brodwall, Systek."— Presentation transcript:

1 Copyright © 2001 Systek Java 2 Enterprise Edition Workshop STEP-Platformen i praksis Johannes Brodwall, Systek

2 Copyright © 2001 Systek Program Oversikt over STEP Installasjon av programmer Tomcat MySQL JBoss Installasjon av devSTEP referanseprosjekt

3 Copyright © 2001 Systek Programmer som inngår Installeres separat MySQL – SQL database JBoss – EJB-container Tomcat – Servlet-container Inkludert i prosjektet: Ant – byggeverktøy JUnit – testverktøy – HTTPUnit

4 Copyright © 2001 Systek MySQL Resource JDBC Integration JBoss Logic Tomcat Presentation Internet Explorer Internet Explorer Client Servlet Container J2EEs fem-lags arkitektur Web- Browser Windows Client Java Swing Client Java Swing Client Java Server Pages XML Servlet Template, Etc. EJB Container Session Bean Entity Bean Message Driven B Relational Database OO Database Third Party System JDBC CORBA XML JMS

5 Copyright © 2001 Systek Oversikt over utviklingsprosessen Skriv kode i valgfri editor Bygg med Ant Test med JUnit Deploy i JBoss

6 Copyright © 2001 Systek Ant på 5 minutter

7 Copyright © 2001 Systek ant j2ee-build C:\java\projects\devSTEP>ant j2ee-build Buildfile: build.xml prepare: compile: [mkdir] Created dir: C:\java\projects\devSTEP\build\classes [javac] Compiling 17 source files to C:\java\projects\devSTEP\build\classes ejb: [mkdir] Created dir: C:\java\projects\devSTEP\build\lib [ejbjar] building bmpexample.jar with 4 files [ejbjar] building cmpexample.jar with 4 files [ejbjar] building sessionbeans.jar with 7 files login-war: [war] Building war: C:\java\projects\devSTEP\build\lib\tomcatlogin.war hello-war: [war] Building war: C:\java\projects\devSTEP\build\lib\hellotomcat.war j2ee-build: BUILD SUCCESSFUL Total time: 6 seconds C:\java\projects\devSTEP>ant j2ee-build Buildfile: build.xml prepare: compile: [mkdir] Created dir: C:\java\projects\devSTEP\build\classes [javac] Compiling 17 source files to C:\java\projects\devSTEP\build\classes ejb: [mkdir] Created dir: C:\java\projects\devSTEP\build\lib [ejbjar] building bmpexample.jar with 4 files [ejbjar] building cmpexample.jar with 4 files [ejbjar] building sessionbeans.jar with 7 files login-war: [war] Building war: C:\java\projects\devSTEP\build\lib\tomcatlogin.war hello-war: [war] Building war: C:\java\projects\devSTEP\build\lib\hellotomcat.war j2ee-build: BUILD SUCCESSFUL Total time: 6 seconds

8 Copyright © 2001 Systek JUnit på 5 minutter public class TestCalculator extends junit.framework.TestCase { public TestCalculator(String testName) { super(testName); } public void testPlus() throws CalculatorInputException { Calculator calculator = new Calculator(); assertEquals(1 + 3, calculator.calculate("1 plus 3")); } public class TestCalculator extends junit.framework.TestCase { public TestCalculator(String testName) { super(testName); } public void testPlus() throws CalculatorInputException { Calculator calculator = new Calculator(); assertEquals(1 + 3, calculator.calculate("1 plus 3")); } public class Calculator { public int calculate(String expression) throws CalculatorInputException { StringTokenizer tokenizer = new StringTokenizer(expression); int firstOperand = parseInt(tokenizer.nextToken()); String operator = tokenizer.nextToken().trim(); int secondOperand = parseInt(tokenizer.nextToken()); if ( operator.equalsIgnoreCase("plus") ) return firstOperand + secondOperand; } public class Calculator { public int calculate(String expression) throws CalculatorInputException { StringTokenizer tokenizer = new StringTokenizer(expression); int firstOperand = parseInt(tokenizer.nextToken()); String operator = tokenizer.nextToken().trim(); int secondOperand = parseInt(tokenizer.nextToken()); if ( operator.equalsIgnoreCase("plus") ) return firstOperand + secondOperand; }

9 Copyright © 2001 Systek JUnit på 5 minutter – kjøring

10 Copyright © 2001 Systek JBoss start

11 Copyright © 2001 Systek sessionbeans.jar >jar tf sessionbeans.jar META-INF/MANIFEST.MF META-INF/ejb-jar.xml no/systek/devSTEP/sessionbeans/Demo.class no/systek/devSTEP/sessionbeans/DemoBean.class no/systek/devSTEP/sessionbeans/DemoHome.class no/systek/devSTEP/sessionbeans/InterestBean.class no/systek/devSTEP/sessionbeans/Interest.class no/systek/devSTEP/sessionbeans/InterestHome.class public interface Demo extends EJBObject { public String demoSelect() throws RemoteException; } public interface DemoHome extends EJBHome { public Demo create() throws RemoteException, CreateException; } public class DemoBean implements SessionBean { public String demoSelect() {return "Hello World"; } public void ejbCreate() {} public void ejbActivate() {} public void ejbRemove() {} public void ejbPassivate() {} public void setSessionContext(SessionContext ctx){} }

12 Copyright © 2001 Systek no.systek.devSTEP.sessionbeans.ATestSession public class ATestSession extends TestCase { public ATestSession(String testCase) { super(testCase); System.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); System.setProperty("java.naming.provider.url", "localhost:1099"); System.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces"); } public void testDemo() throws CreateException, RemoteException, NamingException { InitialContext ctx = new InitialContext(); DemoHome home = (DemoHome)PortableRemoteObject.narrow(ctx.lookup("Demo"), DemoHome.class); Demo demo = home.create(); String answer = demo.demoSelect(); assertEquals(answer, "Hello World"); }

13 Copyright © 2001 Systek Installasjon av Tomcat Last ned og pakk ut TomcatTomcat Last ned catalina-service.jar og plasser i JBoss’s lib/extcatalina-service.jar Rediger konfigurasjon for JBoss Legg til Tomcat's classpath i JBoss's conf/default/jboss.conf fil Legg til JDK's tools.jar i JBoss's conf/default/jboss.conf fil Legg til EmbeddedCatalinaServiceSX i JBoss's conf/default/jboss.jcml fil Restart JBoss

14 Copyright © 2001 Systek hellotomcat.war >jar tf build\lib\hellotomcat.war index.jsp META-INF/MANIFEST.MF WEB-INF/classes/no/systek/devSTEP/hellotomcat/HelloTomcat.class WEB-INF/classes/no/systek/devSTEP/hellotomcat/HelloTomcat2.class WEB-INF/apps-hellotomcat.xml WEB-INF/web.xml public class HelloTomcat extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println(" "); out.println(" My first Servlet "); out.println(”..."); }

15 Copyright © 2001 Systek Tomcat sikkerhet under Jboss Legg til users.properties og roles.properties i JBoss's conf/default Deploy tomcatlogin.war Test med no.systek.devSTEP.tomcatlogin.ATestServletLogin Legg merke til at autentisering under JBoss ikke fungerer 100%, jeg skal forsøke å finne ut hva som er problemet

16 Copyright © 2001 Systek CMP kode public class CmpDemoBean implements EntityBean { public Integer id; public String name; public String zip; public Integer getId() { return id; } public String getName() { return name; } public void setName(String newName){ this.name = newName; } public String getZipCode() { return zip; } public void setZipCode(String newZip) { this.zip = newZip; } } Container java.lang.Integer id name zip id... public interface CmpDemoHome extends EJBHome { public CmpDemo create() throws...; public CmpDemo findByPrimaryKey(Integer id) throws...; public Collection findByName(String name) throws...; public Collection findByZip(String zip) throws...; public Collection findAll() throws...; } public interface CmpDemo extends EJBObject { public Integer getId() throws...; public String getName() throws...; public void setName(String newName) throws...; public String getZipCode() throws...; public void setZipCode(String newZip) throws...; }

17 Copyright © 2001 Systek Container Managed Persistance >jar tf cmpexample.jar META-INF/MANIFEST.MF META-INF/ejb-jar.xml no/systek/devSTEP/cmpexample/CmpDemoBean.class no/systek/devSTEP/cmpexample/CmpDemo.class no/systek/devSTEP/cmpexample/CmpDemoHome.class

18 Copyright © 2001 Systek MySQL Last ned mysql win.zip og kjør setup.exemysql win.zip Last ned JDBC-driveren og legg den til i JBoss's lib/ext katalogJDBC-driveren Start MySQL service under Windows: net start mysql Legg til databasen 'step' med brukeren 'step' og passord 'step-by-step' i MySQL Sett opp JBoss Endre datakilde i jboss.jcml : Driver ( JdbcProvider ), URL, JDBCUser og Password Bruk type-mapping "mySQL" i standardjaws.xml Restart Jboss

19 Copyright © 2001 Systek MySQL eksempel

20 Copyright © 2001 Systek Bean Managed Persistance public Integer ejbCreate(String name, String zip) { this.name = name; this.zip = zip; Connection conn = datasource.getConnection(); String idQuery = "SELECT Max(id)+1 FROM BmpDemoBean"; ResultSet rs = conn.createStatement().executeQuery(idQuery); rs.next(); this.id = new Integer(rs.getInt(1)); String query = "INSERT INTO BmpDemoBean (ID, NAME, ZIP) VALUES (?, ?, ?)"; PreparedStatement stmt = conn.prepareStatement(query); stmt.setInt(1, id.intValue()); stmt.setString(2, this.name); stmt.setString(3, this.zip); stmt.execute(); conn.close(); return id; } public Collection ejbFindByName(String name) { Connection conn = datasource.getConnection(); String query = "SELECT id FROM BmpDemoBean WHERE NAME = ?"; PreparedStatement stmt = conn.prepareStatement(query); stmt.setString(1, name); ResultSet rs = stmt.executeQuery(); Collection result = new ArrayList(); while ( rs.next() ) { result.add(new Integer(rs.getInt(1))); } conn.close(); return result; } public void ejbStore() { Connection conn = datasource.getConnection(); String query = "UPDATE BmpDemoBean SET name = ?, zip = ? " + "WHERE id = ?"; PreparedStatement stmt = conn.prepareStatement(query); stmt.setString(1, this.name); stmt.setString(2, this.zip); stmt.setInt(3, this.id.intValue()); stmt.execute(); conn.close(); } CREATE TABLE BmpDemoBean ( id INTEGER NOT NULL PRIMARY KEY, name VARCHAR (32), zip VARCHAR(5) );

21 Copyright © 2001 Systek Ant acceptance


Download ppt "Copyright © 2001 Systek Java 2 Enterprise Edition Workshop STEP-Platformen i praksis Johannes Brodwall, Systek."

Similar presentations


Ads by Google