Commit b0213636 authored by Stefano's avatar Stefano
Browse files

servlet queue

parent 78172e6b
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="demo">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/ear-resources"/>
......@@ -23,12 +26,14 @@
<dependent-module archiveName="demo-web.war" deploy-path="/" handle="module:/resource/demo-web/demo-web">
<dependency-type>uses</dependency-type>
</dependent-module>
</wb-module>
......
......@@ -32,23 +32,7 @@
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
......
......@@ -5,26 +5,22 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.ejb.LocalBean;
import javax.ejb.Singleton;
import uy.edu.fing.tse.demo.jpa.Node;
@Singleton
public class NodeSingleton implements NodeSingletonRemote, NodeSingletonLocal {
@LocalBean
public class NodeSingleton implements NodeSingletonLocal {
private Map<Integer,Node> nodes = null;
/**
* Default constructor.
*/
public NodeSingleton() {
nodes = new HashMap<>();
try {
newNode("default","Evaluador");
} catch (NodeTypeInvalidException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
nodes = new HashMap<Integer,Node>();
}
public void newNode(String name, String type) throws NodeTypeInvalidException {
......
package uy.edu.fing.tse.demo;
import java.util.ArrayList;
import javax.ejb.Local;
import uy.edu.fing.tse.demo.jpa.Node;
@Local
public interface NodeSingletonLocal {
public void newNode(String name, String type) throws NodeTypeInvalidException;
public ArrayList<Node> searchNode(String nodeToSearch);
public ArrayList<Node> listNodes();
}
package uy.edu.fing.tse.demo;
import java.util.ArrayList;
import javax.ejb.Remote;
import uy.edu.fing.tse.demo.jpa.Node;
@Remote
public interface NodeSingletonRemote {
public void newNode(String name, String type) throws NodeTypeInvalidException;
public ArrayList<Node> searchNode(String nodeToSearch);
public ArrayList<Node> listNodes();
}
......@@ -27,6 +27,7 @@
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/demo-ejb">
......@@ -34,22 +35,5 @@
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8
......@@ -110,6 +110,20 @@
<artifactId>arquillian-protocol-servlet</artifactId>
<scope>test</scope>
</dependency>
<!-- JMS -->
<dependency>
<groupId>org.jboss.spec.javax.jms</groupId>
<artifactId>jboss-jms-api_2.0_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Annotations -->
<dependency>
<groupId>org.jboss.spec.javax.annotation</groupId>
<artifactId>jboss-annotations-api_1.3_spec</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
......
......@@ -13,7 +13,7 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import uy.edu.fing.tse.demo.NodeSingletonRemote;
import uy.edu.fing.tse.demo.NodeSingleton;
import uy.edu.fing.tse.demo.jpa.Node;
......@@ -24,7 +24,7 @@ import uy.edu.fing.tse.demo.jpa.Node;
public class NodeRestApi {
@EJB private NodeSingletonRemote singleton;
@EJB private NodeSingleton singleton;
public NodeRestApi() throws NamingException {
......
......@@ -6,14 +6,14 @@ import javax.ejb.EJB;
import javax.jws.WebMethod;
import javax.jws.WebService;
import uy.edu.fing.tse.demo.NodeSingletonRemote;
import uy.edu.fing.tse.demo.NodeSingleton;
import uy.edu.fing.tse.demo.jpa.Node;
@WebService
public class NodeSOAP {
@EJB private NodeSingletonRemote singleton;
@EJB private NodeSingleton singleton;
@WebMethod
public Boolean addNode(String name, String type) {
......
package uy.edu.fing.tse.demo.servlet;
import javax.enterprise.context.ApplicationScoped;
import javax.faces.annotation.FacesConfig;
/**This bean is required to activate JSF 2.3.
* See https://github.com/eclipse-ee4j/mojarra#user-content-activating-cdi-in-jakarta-faces-30
*
* Remove this class if you don't need JSF.
*/
@ApplicationScoped
@FacesConfig(version = FacesConfig.Version.JSF_2_3)
public class Jsf23Activator {
}
\ No newline at end of file
package uy.edu.fing.tse.demo.servlet;
import java.io.IOException;
import javax.annotation.Resource;
import javax.ejb.EJB;
import javax.inject.Inject;
import javax.jms.Destination;
import javax.jms.JMSContext;
import javax.jms.JMSDestinationDefinition;
import javax.jms.JMSDestinationDefinitions;
import javax.jms.JMSProducer;
import javax.jms.Queue;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import uy.edu.fing.tse.demo.NodeSingleton;
@JMSDestinationDefinitions(
value = {
@JMSDestinationDefinition(
name = "java:/queue/AddNode",
interfaceName = "javax.jms.Queue",
destinationName = "AddNode"
)
}
)
@WebServlet("/MDBServlet")
public class MDBServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@EJB NodeSingleton nodeHandler;
@Inject
private JMSContext context;
@Resource(lookup = "java:/queue/AddNode")
private Queue queue;
/**
* @see HttpServlet#HttpServlet()
*/
public MDBServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String name = request.getParameter("nodeName");
if(name.isBlank()) {
request.setAttribute("added", false);
request.setAttribute("reason", "Nombre no puede ser vacio");
request.getRequestDispatcher("index.jsp").forward(request, response);
}
String type = request.getParameter("nodeType");
try {
String message = "name=" + name + "|" + "type+" + type;
Destination destination = queue;
JMSProducer producer = context.createProducer();
producer.send(destination, message);
request.setAttribute("added", "true");
request.getRequestDispatcher("success.jsp").forward(request, response);
} catch (Exception e) {
request.setAttribute("added", "false");
request.setAttribute("reason", e.getMessage());
request.getRequestDispatcher("index.jsp").forward(request, response);
}
}
}
......@@ -10,7 +10,7 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import uy.edu.fing.tse.demo.NodeSingletonRemote;
import uy.edu.fing.tse.demo.NodeSingleton;
import uy.edu.fing.tse.demo.jpa.Node;
......@@ -21,7 +21,7 @@ import uy.edu.fing.tse.demo.jpa.Node;
public class NodeServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@EJB NodeSingletonRemote nodeHandler;
@EJB NodeSingleton nodeHandler;
/**
* @see HttpServlet#HttpServlet()
*/
......@@ -55,24 +55,7 @@ public class NodeServlet extends HttpServlet {
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String name = request.getParameter("nodeName");
if(name.isBlank()) {
request.setAttribute("added", false);
request.setAttribute("reason", "Nombre no puede ser vacio");
request.getRequestDispatcher("index.jsp").forward(request, response);
}
String type = request.getParameter("nodeType");
try {
nodeHandler.newNode(name,type);
request.setAttribute("added", "true");
request.getRequestDispatcher("success.jsp").forward(request, response);
} catch (Exception e) {
request.setAttribute("added", "false");
request.setAttribute("reason", e.getMessage());
request.getRequestDispatcher("index.jsp").forward(request, response);
}
// nada
}
}
\ No newline at end of file
......@@ -12,7 +12,7 @@
<div class="column">
<h2>Agregar un nodo:</h2>
<form action="node" method="POST">
<form action="MDBServlet" method="POST">
Tipo de Nodo Periferico: <select name="nodeType">
<option value="Evaluador">Evaluador</option>
<option value="Organizacion">Organizacion</option>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment