From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../src/examples/shop/client/PricerClient.java | 52 +++++++++++++++++++ .../src/examples/shop/client/SetupClient.java | 58 ++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/client/PricerClient.java create mode 100644 Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/client/SetupClient.java (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/client') diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/client/PricerClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/client/PricerClient.java new file mode 100644 index 0000000..0bd285b --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/client/PricerClient.java @@ -0,0 +1,52 @@ +package examples.shop.client; + +import java.net.URL; + +import javax.xml.namespace.QName; +import javax.xml.ws.Service; + +import examples.shop.impl.session.PricerBean; + +/** + * This class is an example of a standalone JAX-RPC client code which uses both + * the static stub and the dynamic proxy approach to get a reference to the + * remote Web Service + */ +public class PricerClient { + static String host = "localhost"; + + static String portType = "PricerBean"; + + static String serviceName = "PricerService"; + + static String serviceEndpointAddress = "http://" + host + ":8080/" + + serviceName; + + static String nameSpace = "urn:session.impl.shop.examples"; + + public static void main(String[] args) throws Exception { + + URL wsdlLocation = new URL(serviceEndpointAddress + "/" + portType + + "?WSDL"); + QName serviceNameQ = new QName(nameSpace, serviceName); + + // dynamic service usage + Service service = Service.create(wsdlLocation, serviceNameQ); + PricerBean pricerPort = service.getPort(PricerBean.class); + + String user = "Gerald"; + + System.out.println("Tax rate: " + pricerPort.getTaxRate()); + System.out.println("Discount for : " + user + " is " + + pricerPort.getPersonalDiscountRate(user)); + + System.out + .println("Discount for 1 item (at $1000,- per piece) for " + user + " is " + + pricerPort.getDiscount(1, 1000, user)); + + System.out + .println("Discount for 5 items (at $1000,- per piece) for " + user + " is " + + pricerPort.getDiscount(5, 5000, user)); + + } +} diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/client/SetupClient.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/client/SetupClient.java new file mode 100644 index 0000000..c1fbc27 --- /dev/null +++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/client/SetupClient.java @@ -0,0 +1,58 @@ +package examples.shop.client; + +import java.util.Iterator; + +import javax.naming.Context; +import javax.naming.InitialContext; + +import examples.shop.impl.entity.Product; +import examples.shop.logic.Catalog; +import examples.shop.logic.UserManager; + +/** + * Client test application on a CMP Entity Bean, Product. + */ +public class SetupClient { + + public static void main(String[] args) throws Exception { + + try { + + Context ctx = new InitialContext(System.getProperties()); + Catalog catalog = (Catalog) ctx.lookup(Catalog.class.getName()); + + /* + * Use the catalog to create Products + */ + catalog.addProduct(new Product().init("123-456-7890", "P4-1.8", + "1.8 GHz Pentium 4", 200)); + catalog.addProduct(new Product().init("123-456-7891", "P4-3", + "3 GHz Pentium 4", 300)); + catalog.addProduct(new Product().init("123-456-7892", "P4-4", + "4 GHz Pentium", 400)); + catalog.addProduct(new Product().init("123-456-7893", "SD-256", + "256 MB SDRAM", 50)); + catalog.addProduct(new Product().init("123-456-7894", "SD-512", + "512 MB SDRAM", 100)); + catalog.addProduct(new Product().init("123-456-7895", "DD-1000", + "1GB MB DDRAM", 200)); + catalog.addProduct(new Product().init("123-456-7896", "MP3-x", + "MP3 Player", 200)); + + /* + * Find a Product, and print out it's description + */ + for (Iterator i = catalog.getProductList().iterator(); i + .hasNext();) { + System.out.println(i.next().getDescription()); + } + + UserManager userManager = + (UserManager) ctx.lookup(UserManager.class.getName()); + userManager.createUser("Gerald", "Gerald Brose", "password", + "D-13509 Berlin, Germany"); + } catch (Exception e) { + e.printStackTrace(); + } + } +} -- cgit v1.2.3