Commit 44aae26e authored by edvard's avatar edvard

PrintService

parent 68f0d2b3
......@@ -15,5 +15,6 @@ Any value defined here will override the pom.xml file value but is only applicab
-->
<org-netbeans-modules-maven-jaxws.rest_2e_config_2e_type>ide</org-netbeans-modules-maven-jaxws.rest_2e_config_2e_type>
<org-netbeans-modules-projectapi.jsf_2e_language>JSP</org-netbeans-modules-projectapi.jsf_2e_language>
<org-netbeans-modules-maven-jaxws._5f_S_5f_Printer>file:/home/edvard/edvard/www/aos/Printer.wsdl</org-netbeans-modules-maven-jaxws._5f_S_5f_Printer>
</properties>
</project-shared-configuration>
......@@ -106,9 +106,65 @@
<artifactId>javax.websocket-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
<version>1.1</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>ejb</artifactId>
<version>2.1</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<type>jar</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<dependencies>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>webservices-api</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
<configuration>
<sourceDestDir>${project.build.directory}/generated-sources/jaxws-wsimport</sourceDestDir>
<xnocompile>true</xnocompile>
<verbose>true</verbose>
<extension>true</extension>
<catalog>${basedir}/src/jax-ws-catalog.xml</catalog>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<webResources>
<resource>
<directory>src</directory>
<targetPath>WEB-INF</targetPath>
<includes>
<include>jax-ws-catalog.xml</include>
<include>wsdl/**</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
<finalName>airline</finalName>
</build>
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system">
<system systemId="file:/home/edvard/edvard/www/aos/Printer.wsdl" uri="wsdl/Printer.wsdl"/>
</catalog>
\ No newline at end of file
......@@ -56,7 +56,7 @@ public class DestinationResource {
@POST
@Path("/")
@Consumes(MediaType.APPLICATION_JSON)
@RolesAllowed({"admin"})
@RolesAllowed({"admin"})
public Response saveDestination(Destination data) {
try {
......@@ -86,8 +86,8 @@ public class DestinationResource {
System.out.println(response.toString());
JsonParser parser = new JsonParser();
System.out.println("Testab");
JsonObject rootObj = parser.parse(response.toString()).getAsJsonObject();
System.out.println("Testab");
JsonObject rootObj = parser.parse(response.toString()).getAsJsonObject();
System.out.println(rootObj);
JsonObject locObj = rootObj.getAsJsonArray("results").get(0).getAsJsonObject().getAsJsonObject("geometry").getAsJsonObject("location");
String status = rootObj.get("status").getAsString();
......
......@@ -11,7 +11,8 @@ import javax.ws.rs.core.Response;
import java.util.ArrayList;
/**
* @author rejthedv
* Rozhrani pro praci se zdrojem Flight.
* @author edvard
*/
@Path(value = "flight")
public class FlightResource {
......
......@@ -17,7 +17,8 @@ import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
/**
* @author rejthedv
* Rozhrani pro praci se zdrojem Payment.
* @author edvard
*/
@Path(value = "reservation/{reservation_id}/payment")
public class PaymentResource {
......
......@@ -12,7 +12,8 @@ import java.util.ArrayList;
import javax.annotation.security.RolesAllowed;
/**
* @author rejthedv
* Rozhrani pro praci se zdrojem Reservation.
* @author edvard
*/
@Path(value = "reservation")
public class ReservationResource {
......
......@@ -3,6 +3,7 @@ package cz.aos.api.data;
import java.io.Serializable;
/**
* Nosic dat zdroje Destination. Drzi si informace v lokalnich promennych.
* @author rejthedv
*/
public class Destination implements Serializable {
......
package cz.aos.api.data;
import java.io.Serializable;
import java.util.Date;
/**
* Nosic dat zdroje Flight. Drzi si informace v lokalnich promennych.
* @author rejthedv
*/
public class Flight implements Serializable {
......
......@@ -4,6 +4,7 @@ import java.io.Serializable;
import java.util.Date;
/**
* Nosic dat zdroje Reservation. Drzi si informace v lokalnich promennych.
* @author rejthedv
*/
public class Reservation implements Serializable {
......
......@@ -9,7 +9,7 @@ import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
/**
*
* Rozhrani pro praci se zdrojem Destination.
* @author edvard
*/
@ServerEndpoint("/endpoint")
......@@ -19,7 +19,7 @@ public class MyWSEndpoint {
@OnMessage
public String onMessage(String message) {
System.out.println("Server prijima zpravu: " + message);
//System.out.println("Server prijima zpravu: " + message);
if (message.equals("count")) {
return count + "";
} else {
......
package printer;
import cz.aos.api.data.Reservation;
import java.io.Serializable;
public class MessageWrapper implements Serializable {
private Reservation reservation;
private String email;
public MessageWrapper(Reservation reservation, String email) {
this.reservation = reservation;
this.email = email;
}
public Reservation getReservation() {
return reservation;
}
public String getEmail() {
return email;
}
@Override
public String toString() {
return "ObjectMessage{reservation='" + reservation.toString() + "', email='" + email + "'}";
}
}
package printer;
import cz.aos.api.data.Reservation;
import cz.aos.service.ReservationService;
import javax.activation.DataHandler;
import javax.annotation.Resource;
import javax.jms.*;
import javax.jws.WebService;
import javax.xml.ws.soap.MTOM;
/**
*
* @author edvard
*/
@WebService(serviceName = "Printer")
public class Printer {
@Resource(lookup = "jms/ConnectionFactory")
private ConnectionFactory connectionFactory;
@Resource(lookup = "jms/Topic")
private Topic topic;
// @Override
public void sendTicket(java.lang.String email, long reservation) {
System.out.println("Reservation with ID " + reservation + " will be send to email " + email);
Connection connection = null;
try {
Destination destination = topic;
System.out.println("creating connection");
connection = connectionFactory.createConnection();
System.out.println("creating session");
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
System.out.println("creating producer");
MessageProducer messageProducer = session.createProducer(destination);
// settings
messageProducer.setTimeToLive(10000);
messageProducer.setDeliveryMode(DeliveryMode.PERSISTENT);
connection.start();
// send object message
ReservationService service = new ReservationService();
Reservation res = service.find(Long.parseLong(reservation + ""));
ObjectMessage objectMessage = session.createObjectMessage();
objectMessage.setObject(new MessageWrapper(res, email));
System.out.println("sending message from producer");
messageProducer.send(objectMessage);
System.out.println("message sent");
MessageWrapper wr = (MessageWrapper) objectMessage.getObject();
System.out.println("Odeslu e-mail: " + wr.getEmail() + " o rezervaci: " + wr.getReservation().getId());
} catch (JMSException e) {
System.out.println("JMSE >> " + e.getMessage());
} finally {
if (connection != null) {
try {
connection.close();
} catch (JMSException e) {
System.out.println("JMSE 2 >> " + e.getMessage());
}
}
}
System.out.println("konec producera");
}
}
package printer;
import cz.aos.api.data.Reservation;
import cz.aos.service.ReservationService;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Resource;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.ObjectMessage;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;
/*
@MessageDriven(name = "MessageConsumer", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "jms/Topic"),
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")
})*/
public class PrinterConsumer implements MessageListener {
@Resource(lookup = "jms/ConnectionFactory")
private ConnectionFactory connectionFactory;
@Resource(lookup = "jms/Topic")
private Topic topic;
private final static Logger LOGGER = Logger.getLogger(PrinterConsumer.class.toString());
public void onMessage(Message rcvMessage) {
System.out.println("ON MESSAGE!!!! JOOOOOOOOOOOOOOOOOOOOOOOOO!!!!!!!!!!!!§");
Destination dest = topic;
Connection connection = null;
try {
Destination destination = topic;
System.out.println("creating connection");
connection = connectionFactory.createConnection();
System.out.println("creating session");
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
System.out.println("creating producer");
MessageConsumer consumer = session.createConsumer(dest);
// settings
connection.start();
while (true) {
Message m = consumer.receive(1);
if (m != null) {
if (m instanceof TextMessage) {
ObjectMessage message = (ObjectMessage) m;
MessageWrapper wr = (MessageWrapper) message.getObject();
System.out.println("Odeslu e-mail: " + wr.getEmail() + " o rezervaci: " + wr.getReservation().toString());
} else {
break;
}
}
}
} catch (JMSException e) {
System.out.println("JMSE >> " + e.getMessage());
} finally {
if (connection != null) {
try {
connection.close();
} catch (JMSException e) {
System.out.println("JMSE 2 >> " + e.getMessage());
}
}
}
System.out.println("konec producera");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Resource Definitions //EN" "http://www.sun.com/software/appserver/dtds/sun-resources_1_3.dtd">
<resources>
<admin-object-resource enabled="true" jndi-name="jms/Topic" object-type="user" res-adapter="jmsra" res-type="javax.jms.Topic">
<description/>
<property name="Name" value="defaultName"/>
</admin-object-resource>
<connector-resource enabled="true" jndi-name="jms/myTopic" object-type="user" pool-name="jms/myTopic-Connection-Pool">
<description/>
</connector-resource>
<connector-resource enabled="true" jndi-name="jms/ConnectionFactory" object-type="user" pool-name="jms/ConnectionFactory-Connection-Pool">
<description/>
</connector-resource>
<connector-connection-pool associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-definition-name="javax.jms.TopicConnectionFactory" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="true" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="jms/myTopic-Connection-Pool" pool-resize-quantity="2" resource-adapter-name="jmsra" steady-pool-size="8" validate-atmost-once-period-in-seconds="0"/>
<connector-connection-pool associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-definition-name="javax.jms.TopicConnectionFactory" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="true" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="jms/ConnectionFactory-Connection-Pool" pool-resize-quantity="2" resource-adapter-name="jmsra" steady-pool-size="8" validate-atmost-once-period-in-seconds="0"/>
</resources>
......@@ -7,18 +7,18 @@
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
<security-role-mapping>
<role-name>admin</role-name>
<principal-name>manager</principal-name>
<security-role-mapping>
<role-name>admin</role-name>
<principal-name>manager</principal-name>
</security-role-mapping>
<security-role-mapping>
<role-name>admin</role-name>
<principal-name>test</principal-name>
<security-role-mapping>
<role-name>admin</role-name>
<principal-name>test</principal-name>
</security-role-mapping>
<security-role-mapping>
<role-name>admin</role-name>
<principal-name>admin</principal-name>
<security-role-mapping>
<role-name>admin</role-name>
<principal-name>admin</principal-name>
</security-role-mapping>
</glassfish-web-app>
\ No newline at end of file
</glassfish-web-app>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system">
<system systemId="file:/home/edvard/edvard/www/aos/Printer.wsdl" uri="wsdl/Printer.wsdl"/>
</catalog>
\ No newline at end of file
<?xml version='1.0' encoding='UTF-8'?>
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://printer/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://printer/" name="Printer">
<types/>
<message name="sendTicket">
<part name="email" type="xsd:string"/>
<part name="reservation" type="xsd:long"/>
</message>
<portType name="IPrinterService">
<operation name="sendTicket">
<input message="tns:sendTicket"/>
</operation>
</portType>
<binding name="PrinterServicePortBinding" type="tns:IPrinterService">
<wsp:PolicyReference URI="#PrinterServicePortBinding_MTOM_Policy-PrinterServicePortBinding_MTOM_Policy"/>
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
<operation name="sendTicket">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal" namespace="http://printer/"/>
</input>
</operation>
</binding>
<service name="Printer">
<port name="PrinterServicePort" binding="tns:PrinterServicePortBinding">
<soap:address location="http://localhost:8080/airline/Printer"/>
</port>
</service>
</definitions>
\ No newline at end of file
<?xml version='1.0' encoding='UTF-8'?>
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://printer/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://printer/" name="Printer">
<types/>
<message name="sendTicket">
<part name="email" type="xsd:string"/>
<part name="reservation" type="xsd:long"/>
</message>
<portType name="IPrinterService">
<operation name="sendTicket">
<input message="tns:sendTicket"/>
</operation>
</portType>
<binding name="PrinterServicePortBinding" type="tns:IPrinterService">
<wsp:PolicyReference URI="#PrinterServicePortBinding_MTOM_Policy-PrinterServicePortBinding_MTOM_Policy"/>
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
<operation name="sendTicket">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal" namespace="http://printer/"/>
</input>
</operation>
</binding>
<service name="Printer">
<port name="PrinterServicePort" binding="tns:PrinterServicePortBinding">
<soap:address location="http://localhost:8080/airline/Printer"/>
</port>
</service>
</definitions>
\ No newline at end of file
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