Author: sadeep
Date: Sun Jul 21 06:25:36 2013
New Revision: 1505282

URL: http://svn.apache.org/r1505282
Log:
SYNAPSE-838: Adding the EJB sample.

Added:
    synapse/trunk/java/modules/samples/services/EJBSampleBeans/
    synapse/trunk/java/modules/samples/services/EJBSampleBeans/pom.xml
    synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/
    synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/
    synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/bean/
    
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/bean/Location.java
    
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/bean/Store.java
    synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/
    
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/ShoppingCart.java
    
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/ShoppingCartBean.java
    
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/StoreLocator.java
    
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/StoreLocatorBean.java
    
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/StoreRegistry.java
    
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/StoreRegistryBean.java
    synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/util/
    
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/util/StoreRegisterUtil.java

Added: synapse/trunk/java/modules/samples/services/EJBSampleBeans/pom.xml
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/samples/services/EJBSampleBeans/pom.xml?rev=1505282&view=auto
==============================================================================
--- synapse/trunk/java/modules/samples/services/EJBSampleBeans/pom.xml (added)
+++ synapse/trunk/java/modules/samples/services/EJBSampleBeans/pom.xml Sun Jul 
21 06:25:36 2013
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~  Licensed to the Apache Software Foundation (ASF) under one
+  ~  or more contributor license agreements.  See the NOTICE file
+  ~  distributed with this work for additional information
+  ~  regarding copyright ownership.  The ASF licenses this file
+  ~  to you under the Apache License, Version 2.0 (the
+  ~  "License"); you may not use this file except in compliance
+  ~  with the License.  You may obtain a copy of the License at
+  ~ 
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~  Unless required by applicable law or agreed to in writing,
+  ~  software distributed under the License is distributed on an
+  ~   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~  KIND, either express or implied.  See the License for the
+  ~  specific language governing permissions and limitations
+  ~  under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+        
+    <version>1.0.0</version>
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>org.apache.synapse.samples</groupId>
+    <artifactId>synapse-samples-ejb</artifactId>
+    <packaging>jar</packaging>
+    <name>Apache Synapse - Samples - EJB</name>
+    <description>Apache Synapse - Samples - EJB</description>
+
+    <repositories>
+        <repository>
+            <id>maven2-repository.dev.java.net</id>
+            <name>Java.net Repository for Maven</name>
+            <url>http://download.java.net/maven/2/</url>
+            <layout>default</layout>
+        </repository>
+    </repositories>
+
+    <build>
+        <sourceDirectory>src</sourceDirectory>
+        <plugins>
+            <plugin>
+               <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>2.3.2</version>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+           <dependency>
+                   <groupId>javax</groupId>
+                   <artifactId>javaee-api</artifactId>
+                   <version>6.0</version>
+           </dependency>
+   </dependencies>
+
+</project>

Added: 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/bean/Location.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/bean/Location.java?rev=1505282&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/bean/Location.java
 (added)
+++ 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/bean/Location.java
 Sun Jul 21 06:25:36 2013
@@ -0,0 +1,48 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package samples.bean;
+
+import java.io.Serializable;
+
+/**
+ * A simple JavaBean class which encapsulates location details.
+ */
+public class Location implements Serializable {
+
+    private float latitude;
+    private float longitude;
+
+    public float getLatitude() {
+        return latitude;
+    }
+
+    public void setLatitude(float latitude) {
+        this.latitude = latitude;
+    }
+
+    public float getLongitude() {
+        return longitude;
+    }
+
+    public void setLongitude(float longitude) {
+        this.longitude = longitude;
+    }
+
+}

Added: 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/bean/Store.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/bean/Store.java?rev=1505282&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/bean/Store.java
 (added)
+++ 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/bean/Store.java
 Sun Jul 21 06:25:36 2013
@@ -0,0 +1,75 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package samples.bean;
+
+import java.io.Serializable;
+
+/**
+ * A simple JavaBean class which encapsulates store details.
+ */
+public class Store implements Serializable {
+
+    private String storeId;
+    private String name;
+    private String address;
+    private String phoneNo;
+
+    public Store(String storeId, String name, String address, String phoneNo) {
+        this.storeId = storeId;
+        this.name = name;
+        this.address = address;
+        this.phoneNo = phoneNo;
+    }
+
+    public Store() { }
+
+    public String getAddress() {
+        return address;
+    }
+
+    public void setAddress(String address) {
+        this.address = address;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getPhoneNo() {
+        return phoneNo;
+    }
+
+    public void setPhoneNo(String phoneNo) {
+        this.phoneNo = phoneNo;
+    }
+
+    public String getStoreId() {
+        return storeId;
+    }
+
+    public void setStoreId(String storeId) {
+        this.storeId = storeId;
+    }
+
+}

Added: 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/ShoppingCart.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/ShoppingCart.java?rev=1505282&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/ShoppingCart.java
 (added)
+++ 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/ShoppingCart.java
 Sun Jul 21 06:25:36 2013
@@ -0,0 +1,37 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package samples.ejb;
+
+import javax.ejb.Remote;
+
+/**
+ * The remote interface of the ShoppingCart stateful session bean: defines 
methods that can be
+ * remotely invoked on the EJB.
+ */
+@Remote
+public interface ShoppingCart {
+
+    public void addItem(String itemId, int count);
+
+    public float getTotal();
+
+    public int getItemCount();
+    
+}

Added: 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/ShoppingCartBean.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/ShoppingCartBean.java?rev=1505282&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/ShoppingCartBean.java
 (added)
+++ 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/ShoppingCartBean.java
 Sun Jul 21 06:25:36 2013
@@ -0,0 +1,56 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package samples.ejb;
+
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+
+/**
+ * Implementation of the shopping cart stateful session bean which keeps an 
state internally.
+ */
+@Stateful
+public class ShoppingCartBean implements ShoppingCart {
+
+    private float total;
+
+    private int itemCount;
+
+    public void addItem(String itemId, int count) {
+        total += getPriceById(itemId) * count;
+        itemCount += count;
+    }
+ 
+    @Remove
+    public float getTotal() {
+        return total;
+    }
+
+    public int getItemCount() {
+        return itemCount;
+    }
+
+    private float getPriceById(String itemId) {
+        try {
+            return Integer.parseInt(itemId.substring(0, itemId.length() - 1));
+        } catch (NumberFormatException e) {
+            return (float) (Math.random() * 100);
+        }
+    }
+}

Added: 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/StoreLocator.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/StoreLocator.java?rev=1505282&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/StoreLocator.java
 (added)
+++ 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/StoreLocator.java
 Sun Jul 21 06:25:36 2013
@@ -0,0 +1,34 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package samples.ejb;
+
+import javax.ejb.Remote;
+import samples.bean.Location;
+
+/**
+ * The remote interface of the StoreLocator stateless session bean: defines 
methods that can be
+ * remotely invoked on the EJB.
+ */
+@Remote
+public interface StoreLocator {
+
+    public String getClosestStore(Location loc);
+    
+}

Added: 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/StoreLocatorBean.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/StoreLocatorBean.java?rev=1505282&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/StoreLocatorBean.java
 (added)
+++ 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/StoreLocatorBean.java
 Sun Jul 21 06:25:36 2013
@@ -0,0 +1,37 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package samples.ejb;
+
+import javax.ejb.Stateless;
+import samples.bean.Location;
+import samples.util.StoreRegisterUtil;
+
+/**
+ * The implementation of the StoreLocator stateless session bean which does 
not keep an internal
+ * state.
+ */
+@Stateless
+public class StoreLocatorBean implements StoreLocator {
+
+    public String getClosestStore(Location loc) {
+        return StoreRegisterUtil.getClosestStore(loc);
+    }
+
+}

Added: 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/StoreRegistry.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/StoreRegistry.java?rev=1505282&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/StoreRegistry.java
 (added)
+++ 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/StoreRegistry.java
 Sun Jul 21 06:25:36 2013
@@ -0,0 +1,34 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package samples.ejb;
+
+import javax.ejb.Remote;
+import samples.bean.Store;
+
+/**
+ * The remote interface of the StoreRegistry stateless session bean: defines 
methods that can be
+ * remotely invoked on the EJB.
+ */
+@Remote
+public interface StoreRegistry {
+
+    public Store getStoreById(String storeId);
+
+}

Added: 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/StoreRegistryBean.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/StoreRegistryBean.java?rev=1505282&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/StoreRegistryBean.java
 (added)
+++ 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/ejb/StoreRegistryBean.java
 Sun Jul 21 06:25:36 2013
@@ -0,0 +1,36 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package samples.ejb;
+
+import javax.ejb.Stateless;
+import samples.bean.Store;
+import samples.util.StoreRegisterUtil;
+
+/**
+ * The implementation of the StoreRegistry stateless session bean which does 
not keep an internal
+ * state.
+ */
+@Stateless
+public class StoreRegistryBean implements StoreRegistry {
+
+    public Store getStoreById(String storeId) {
+        return StoreRegisterUtil.getStoreById(storeId);
+    }
+
+}

Added: 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/util/StoreRegisterUtil.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/util/StoreRegisterUtil.java?rev=1505282&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/util/StoreRegisterUtil.java
 (added)
+++ 
synapse/trunk/java/modules/samples/services/EJBSampleBeans/src/samples/util/StoreRegisterUtil.java
 Sun Jul 21 06:25:36 2013
@@ -0,0 +1,60 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package samples.util;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import samples.bean.Location;
+import samples.bean.Store;
+
+/**
+ * Provides utility methods to be used by the EJB implementations.
+ */
+public class StoreRegisterUtil {
+
+    private static Map<String, Store> stores =
+            new LinkedHashMap<String, Store>();
+
+    static {
+        stores.put("1010", new Store("1010", "Majestic City",
+                "403, Station Road, Colombo 4.", "0112352354"));
+        stores.put("2020", new Store("2020", "Dehiwala",
+                "67, Galle Road, Dehiwala.", "0114789056"));
+        stores.put("3030", new Store("3030", "Kadawatha",
+                "253, Kandy Road, Kadawatha", "0112990789"));
+        stores.put("4040", new Store("4040", "Moratuwa",
+                "33, Galle Road, Rawathawatte", "0117564902"));
+    }
+
+    public static String getClosestStore(Location loc) {
+        int index = (int)(loc.getLongitude() + loc.getLatitude()) %
+                stores.size();
+        return stores.keySet().toArray()[index].toString();
+    }
+
+    public static Store getStoreById(String id) {
+        return stores.get(id);
+    }
+    
+    private static String getStoreNameByLocation(Location loc) {
+       return getStoreById(getClosestStore(loc)).getName();
+    }
+
+}


Reply via email to