-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
197 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" | ||
version="3.0"> | ||
<enterprise-beans> | ||
<session> | ||
<ejb-name>CalculatorImpl</ejb-name> | ||
<business-local>com.ecme.sessionbean.CalculatorLocal</business-local> | ||
<business-remote>com.ecme.sessionbean.CalculatorRemote</business-remote> | ||
<ejb-class>com.ecme.sessionbean.impl.CalculatorImpl</ejb-class> | ||
<session-type>Stateless</session-type> | ||
<transaction-type>Container</transaction-type> | ||
</session> | ||
</enterprise-beans> | ||
</ejb-jar> |
2 changes: 1 addition & 1 deletion
2
backend/webapp/WEB-INF/web.xml → backend/WebContent/WEB-INF/web.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>EJB 3.1</title> | ||
</head> | ||
<body> | ||
<h1>EJB 3.1 - Examples</h1> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.ecme.sessionbean; | ||
|
||
public interface CalculatorLocal { | ||
public int sum(int add1, int add2); | ||
public int multiply(int mul1, int mul2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.ecme.sessionbean; | ||
|
||
public interface CalculatorRemote { | ||
public int sum(int add1, int add2); | ||
public int multiply(int mul1, int mul2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
backend/src/com/ecme/sessionbean/ILibraryStatelessSessionBeanRemote.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
package com.ecme.sessionbean; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.Future; | ||
|
||
import javax.ejb.Remote; | ||
|
||
|
||
@Remote | ||
public interface ILibraryStatelessSessionBeanRemote { | ||
void addBook(String bookName); | ||
Future<String> addBook(String bookName); | ||
List<String> getBooks(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.ecme.sessionbean.impl; | ||
|
||
import com.ecme.sessionbean.CalculatorLocal; | ||
import com.ecme.sessionbean.CalculatorRemote; | ||
|
||
public class CalculatorImpl implements CalculatorLocal, CalculatorRemote { | ||
|
||
public int sum(int add1, int add2) { | ||
return add1 + add2; | ||
} | ||
|
||
public int multiply(int mul1, int mul2) { | ||
return mul1 * mul2; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
106 changes: 106 additions & 0 deletions
106
client/src/main/java/com/ecme/app/CalculatorClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package com.ecme.app; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.util.Properties; | ||
|
||
import javax.naming.InitialContext; | ||
import javax.naming.NamingException; | ||
|
||
import com.ecme.sessionbean.CalculatorRemote; | ||
|
||
public class CalculatorClient { | ||
|
||
BufferedReader brConsoleReader = null; | ||
Properties props; | ||
InitialContext ctx; | ||
{ | ||
props = new Properties(); | ||
InputStream input = null; | ||
try { | ||
String filename = "jndi.properties"; | ||
input = CalculatorClient.class.getClassLoader().getResourceAsStream(filename); | ||
if(input==null){ | ||
System.out.println("Sorry, unable to find " + filename); | ||
} | ||
props.load(input); | ||
} catch (IOException ex) { | ||
ex.printStackTrace(); | ||
} | ||
try { | ||
ctx = new InitialContext(props); | ||
} catch (NamingException ex) { | ||
ex.printStackTrace(); | ||
} | ||
brConsoleReader = | ||
new BufferedReader(new InputStreamReader(System.in)); | ||
} | ||
private void showGUI(){ | ||
System.out.println("**********************"); | ||
System.out.println("Calculator"); | ||
System.out.println("**********************"); | ||
System.out.print("Options \n1. Sum\n2. Multiply \n3. Exit\nEnter Choice: "); | ||
} | ||
|
||
private void testStatelessEjb(){ | ||
|
||
try { | ||
int choice = 1; | ||
int a = 0; | ||
int b = 0; | ||
|
||
CalculatorRemote calculatorRemote = | ||
(CalculatorRemote)ctx.lookup("java:global/ecme-ejb31/CalculatorImpl!com.ecme.sessionbean.CalculatorRemote"); | ||
|
||
while (choice != 3) { | ||
showGUI(); | ||
String strChoice = brConsoleReader.readLine(); | ||
choice = Integer.parseInt(strChoice); | ||
|
||
if (choice == 1) { | ||
System.out.println("Value for a:"); | ||
String strA = brConsoleReader.readLine(); | ||
System.out.println("Value for b:"); | ||
String strB = brConsoleReader.readLine(); | ||
a = Integer.parseInt(strA); | ||
b = Integer.parseInt(strB); | ||
|
||
System.out.println("sum: "+calculatorRemote.sum(a,b)); | ||
} else if (choice == 2) { | ||
System.out.println("Value for a:"); | ||
String strA = brConsoleReader.readLine(); | ||
System.out.println("Value for b:"); | ||
String strB = brConsoleReader.readLine(); | ||
a = Integer.parseInt(strA); | ||
b = Integer.parseInt(strB); | ||
|
||
System.out.println("multiply: "+calculatorRemote.multiply(a,b)); | ||
|
||
} else if (choice == 3) { | ||
break; | ||
} | ||
} | ||
|
||
} catch (Exception e) { | ||
System.out.println(e.getMessage()); | ||
e.printStackTrace(); | ||
}finally { | ||
try { | ||
if(brConsoleReader !=null){ | ||
brConsoleReader.close(); | ||
} | ||
} catch (IOException ex) { | ||
System.out.println(ex.getMessage()); | ||
} | ||
} | ||
} | ||
public static void main(String[] args) { | ||
// TODO Auto-generated method stub | ||
CalculatorClient client = new CalculatorClient(); | ||
client.testStatelessEjb(); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
client/src/main/java/com/ecme/sessionbean/CalculatorRemote.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.ecme.sessionbean; | ||
|
||
public interface CalculatorRemote { | ||
public int sum(int add1, int add2); | ||
public int multiply(int mul1, int mul2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
client/src/main/java/com/ecme/sessionbean/ILibraryStatelessSessionBeanRemote.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
package com.ecme.sessionbean; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.Future; | ||
|
||
import javax.ejb.Remote; | ||
|
||
|
||
@Remote | ||
public interface ILibraryStatelessSessionBeanRemote { | ||
void addBook(String bookName); | ||
Future<String> addBook(String bookName); | ||
List<String> getBooks(); | ||
} |