esercizi webservices wsdl

This commit is contained in:
2015-06-29 00:45:45 +02:00
parent 620edb5049
commit 53c280b729
60 changed files with 1741 additions and 2 deletions

73
exam/CD.java Normal file
View File

@@ -0,0 +1,73 @@
package exam;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
* Created by Giovanni on 16/06/2015.
*/
@Entity
@NamedQueries({
@NamedQuery(name = "findid", query = "SELECT c FROM CD c WHERE c.id =?1"),
@NamedQuery(name = "findauthor", query = "SELECT c FROM CD c WHERE c.author =?1"),
@NamedQuery(name = "findall", query = "SELECT c FROM CD c"),
})
public class CD implements Serializable {
@NotNull @Id
private String id;
@NotNull
private String title;
@NotNull
private String author;
@NotNull @DecimalMin("0.0")
private Float price;
public CD (){}
public CD (@NotNull String id_in,@NotNull String title_in,@NotNull String author_in,@NotNull @DecimalMin("0.0") Float price_in){
id = id_in;
title = title_in;
author = author_in;
price = price_in;
}
public @NotNull String getId() {
return id;
}
public @NotNull String getTitle() {
return title;
}
public void setTitle(@NotNull String title) {
this.title = title;
}
public @NotNull @DecimalMin("0.0") Float getPrice() {
return price;
}
public void setPrice(@NotNull @DecimalMin("0.0") Float price) {
this.price = price;
}
public @NotNull String getAuthor() {
return author;
}
public void setAuthor(@NotNull String author) {
this.author = author;
}
}

View File

@@ -0,0 +1,27 @@
package exam;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Iterator;
import java.util.List;
public class ClientPrintAllCDs {
public static void main (String[] args) throws NamingException{
// added method main and signature exception
Context ctx =new InitialContext();
RemoteEJB r = (RemoteEJB) ctx.lookup("java:global/web/EJB!exam.RemoteEJB");
List<CD> l = r.findall();
Iterator<CD> i = l.iterator();
while (i.hasNext()){
CD temp = i.next();
System.out.print(temp.getId() + " " + temp.getTitle() + " " + temp.getAuthor() + " " +temp.getPrice() + "\n");
}
}
}

View File

@@ -0,0 +1,34 @@
package exam;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSContext;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* Created by Giovanni on 31/05/2015.
*/
public class ClientUpdatePrice {
public static void main(String[] args) throws NamingException {
//removed try catch e added signatute exception to main method
Context ctx = new InitialContext();
ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/javaee7/ConnectionFactory");
Destination d = (Destination) ctx.lookup("jms/javaee7/Topic");
try (JMSContext jmsContext = cf.createContext()) {
GeneralMessage gm = new GeneralMessage(args[0],Float.valueOf(args[1]));
jmsContext.createProducer().send(d, gm);
}
}
}

View File

@@ -0,0 +1,40 @@
package exam;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.inject.Inject;
/**
* Created by Giovanni on 16/06/2015.
*/
@Singleton
@Startup
public class DatabaseInitializer {
@Inject
EJB e;
private CD first;
private CD second;
@PostConstruct
protected void initialize(){
first = new CD("001","Title1","Author1",35.0f);
e.createCD(first);
second = new CD("002","Title2","Author2",40.0f);
e.createCD(second);
}
@PreDestroy
protected void deleteall(){
e.removeCD(first);
e.removeCD(second);
}
}

58
exam/EJB.java Normal file
View File

@@ -0,0 +1,58 @@
package exam;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.List;
/**
* Created by Giovanni on 16/06/2015.
*/
@Stateless
@LocalBean
public class EJB implements RemoteEJB{
@PersistenceContext(unitName = "exam")
EntityManager em ;
public void createCD (CD c){
em.persist(c);
}
public void updateCD (CD c) {
em.merge(c);
em.persist(c);
}
public void removeCD (CD c){
em.merge(c);
em.remove(c);
}
public List<CD> findall() {
Query q = em.createNamedQuery("findall");
return (List<CD>) q. getResultList();
}
public List<CD> findauthor(String author_in) {
Query q = em.createNamedQuery("findauthor");
q.setParameter(1,author_in);
return (List<CD>) q. getResultList();
}
public List<CD> findid(String id_in) {
Query q = em.createNamedQuery("findid");
q.setParameter(1,id_in);
return (List<CD>) q. getResultList();
}
}

25
exam/GeneralMessage.java Normal file
View File

@@ -0,0 +1,25 @@
package exam;
import java.io.Serializable;
/**
* Created by Giovanni on 16/06/2015.
*/
public class GeneralMessage implements Serializable{
private String id;
private Float price;
public GeneralMessage (String in_id, Float in_price){
id = in_id;
price = in_price;
}
public String getId() {
return id;
}
public Float getPrice() {
return price;
}
}

43
exam/MDB.java Normal file
View File

@@ -0,0 +1,43 @@
package exam;
import javax.ejb.MessageDriven;
import javax.inject.Inject;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import java.util.Iterator;
import java.util.List;
/**
* Created by Giovanni on 16/06/2015.
*/
@MessageDriven(mappedName = "jms/javaee7/Topic")
public class MDB implements MessageListener {
@Inject
EJB e;
public void onMessage(Message m) {
try {
GeneralMessage gm = m.getBody(GeneralMessage.class);
List<CD> l = e.findid(gm.getId());
Iterator<CD> i = l.iterator();
if (i.hasNext()){
CD temp = i.next();
temp.setPrice(gm.getPrice());
e.updateCD(temp);
}
} catch (JMSException e) { // added try catch for JMSException
e.printStackTrace();
}
}
}

16
exam/RemoteEJB.java Normal file
View File

@@ -0,0 +1,16 @@
package exam;
import javax.ejb.Remote;
import java.util.List;
/**
* Created by Giovanni on 16/06/2015.
*/
@Remote
public interface RemoteEJB {
List<CD> findall();
List<CD> findauthor(String author_in);
List<CD> findid(String id_in);
}

View File

@@ -12,8 +12,8 @@ import javax.inject.Inject;
* Created by Giovanni on 24/05/2015. * Created by Giovanni on 24/05/2015.
*/ */
@Singleton //@Singleton reenable if you need this exercise
@Startup //@Startup
public class InitializeDB { public class InitializeDB {
private Book b1,b2; private Book b1,b2;

View File

@@ -0,0 +1,44 @@
package exercise2_client_ws;
import exercise2_ws.Book;
import exercise2_ws.RemoteInterface;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Iterator;
import java.util.List;
public class ClientPrintAll {
public static void main (String[] args) {
Context ctx = null;
try {
ctx =new InitialContext();
} catch (NamingException e) {
e.printStackTrace();
}
RemoteInterface r = null;
try {
r =(RemoteInterface) ctx.lookup("java:global/web/EJBBook!exercise2_ws.RemoteInterface");
List<Book> l = r.findall();
Iterator<Book> it = l.iterator();
while (it.hasNext()){
Book b = it.next();
System.out.print(b.getIsbn() + " " + b.getTitle() + " " + b.getAuthor() + " " +b.getPrice() + " ");
}
} catch (NamingException e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,37 @@
package exercise2_client_ws;
import exercise2_ws.BookMessage;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSContext;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* Created by Giovanni on 31/05/2015.
*/
public class ClientUpdatePrice {
public static void main(String[] args) throws NamingException {
BookMessage m = new BookMessage("0001",Float.valueOf(10000));
Context jndiContext = new InitialContext();
ConnectionFactory connectionFactory = (ConnectionFactory) jndiContext.lookup("jms/javaee7/ConnectionFactory");
Destination topic = (Destination) jndiContext.lookup("jms/javaee7/Topic");
try (JMSContext jmsContext = connectionFactory.createContext()) {
jmsContext.createProducer().send(topic, m);
}
}
}

Binary file not shown.

View File

@@ -0,0 +1,141 @@
package exercise2_client_ws.clientws;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for book complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="book">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="author" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;element name="isbn" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;element name="price" type="{http://www.w3.org/2001/XMLSchema}float" minOccurs="0"/>
* &lt;element name="title" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "book", propOrder = {
"author",
"isbn",
"price",
"title"
})
public class Book {
protected String author;
protected String isbn;
protected Float price;
protected String title;
/**
* Gets the value of the author property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getAuthor() {
return author;
}
/**
* Sets the value of the author property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setAuthor(String value) {
this.author = value;
}
/**
* Gets the value of the isbn property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getIsbn() {
return isbn;
}
/**
* Sets the value of the isbn property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setIsbn(String value) {
this.isbn = value;
}
/**
* Gets the value of the price property.
*
* @return
* possible object is
* {@link Float }
*
*/
public Float getPrice() {
return price;
}
/**
* Sets the value of the price property.
*
* @param value
* allowed object is
* {@link Float }
*
*/
public void setPrice(Float value) {
this.price = value;
}
/**
* Gets the value of the title property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getTitle() {
return title;
}
/**
* Sets the value of the title property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setTitle(String value) {
this.title = value;
}
}

View File

@@ -0,0 +1,36 @@
<?xml version='1.0' encoding='UTF-8'?><!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is Metro/2.3.1-b419 (branches/2.3.1.x-7937; 2014-08-04T08:11:03+0000) JAXWS-RI/2.2.10-b140803.1500 JAXWS-API/2.2.11 JAXB-RI/2.2.10-b140802.1033 JAXB-API/2.2.12-b140109.1041 svn-revision#unknown. --><!-- Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is Metro/2.3.1-b419 (branches/2.3.1.x-7937; 2014-08-04T08:11:03+0000) JAXWS-RI/2.2.10-b140803.1500 JAXWS-API/2.2.11 JAXB-RI/2.2.10-b140802.1033 JAXB-API/2.2.12-b140109.1041 svn-revision#unknown. --><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://exercise2_ws/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://exercise2_ws/" name="BookWebServiceService">
<types>
<xsd:schema>
<xsd:import namespace="http://exercise2_ws/" schemaLocation="http://localhost:8080/web/services/BookWebService?xsd=1"/>
</xsd:schema>
</types>
<message name="checkbook">
<part name="parameters" element="tns:checkbook"/>
</message>
<message name="checkbookResponse">
<part name="parameters" element="tns:checkbookResponse"/>
</message>
<portType name="wsinterface">
<operation name="checkbook">
<input wsam:Action="http://exercise2_ws/wsinterface/checkbookRequest" message="tns:checkbook"/>
<output wsam:Action="http://exercise2_ws/wsinterface/checkbookResponse" message="tns:checkbookResponse"/>
</operation>
</portType>
<binding name="BookWebServicePortBinding" type="tns:wsinterface">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="checkbook">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="BookWebServiceService">
<port name="BookWebServicePort" binding="tns:BookWebServicePortBinding">
<soap:address location="http://localhost:8080/web/services/BookWebService"/>
</port>
</service>
</definitions>

View File

@@ -0,0 +1,94 @@
package exercise2_client_ws.clientws;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceFeature;
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.2.10-b140803.1500
* Generated source version: 2.2
*
*/
@WebServiceClient(name = "BookWebServiceService", targetNamespace = "http://exercise2_ws/", wsdlLocation = "http://localhost:8080/web/services/BookWebService?wsdl")
public class BookWebServiceService
extends Service
{
private final static URL BOOKWEBSERVICESERVICE_WSDL_LOCATION;
private final static WebServiceException BOOKWEBSERVICESERVICE_EXCEPTION;
private final static QName BOOKWEBSERVICESERVICE_QNAME = new QName("http://exercise2_ws/", "BookWebServiceService");
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("http://localhost:8080/web/services/BookWebService?wsdl");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
BOOKWEBSERVICESERVICE_WSDL_LOCATION = url;
BOOKWEBSERVICESERVICE_EXCEPTION = e;
}
public BookWebServiceService() {
super(__getWsdlLocation(), BOOKWEBSERVICESERVICE_QNAME);
}
public BookWebServiceService(WebServiceFeature... features) {
super(__getWsdlLocation(), BOOKWEBSERVICESERVICE_QNAME, features);
}
public BookWebServiceService(URL wsdlLocation) {
super(wsdlLocation, BOOKWEBSERVICESERVICE_QNAME);
}
public BookWebServiceService(URL wsdlLocation, WebServiceFeature... features) {
super(wsdlLocation, BOOKWEBSERVICESERVICE_QNAME, features);
}
public BookWebServiceService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public BookWebServiceService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
super(wsdlLocation, serviceName, features);
}
/**
*
* @return
* returns Wsinterface
*/
@WebEndpoint(name = "BookWebServicePort")
public Wsinterface getBookWebServicePort() {
return super.getPort(new QName("http://exercise2_ws/", "BookWebServicePort"), Wsinterface.class);
}
/**
*
* @param features
* A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
* @return
* returns Wsinterface
*/
@WebEndpoint(name = "BookWebServicePort")
public Wsinterface getBookWebServicePort(WebServiceFeature... features) {
return super.getPort(new QName("http://exercise2_ws/", "BookWebServicePort"), Wsinterface.class, features);
}
private static URL __getWsdlLocation() {
if (BOOKWEBSERVICESERVICE_EXCEPTION!= null) {
throw BOOKWEBSERVICESERVICE_EXCEPTION;
}
return BOOKWEBSERVICESERVICE_WSDL_LOCATION;
}
}

Binary file not shown.

View File

@@ -0,0 +1,60 @@
package exercise2_client_ws.clientws;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for checkbook complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="checkbook">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="arg0" type="{http://exercise2_ws/}book" minOccurs="0"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "checkbook", propOrder = {
"arg0"
})
public class Checkbook {
protected Book arg0;
/**
* Gets the value of the arg0 property.
*
* @return
* possible object is
* {@link Book }
*
*/
public Book getArg0() {
return arg0;
}
/**
* Sets the value of the arg0 property.
*
* @param value
* allowed object is
* {@link Book }
*
*/
public void setArg0(Book value) {
this.arg0 = value;
}
}

Binary file not shown.

View File

@@ -0,0 +1,54 @@
package exercise2_client_ws.clientws;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for checkbookResponse complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="checkbookResponse">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="return" type="{http://www.w3.org/2001/XMLSchema}boolean"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "checkbookResponse", propOrder = {
"_return"
})
public class CheckbookResponse {
@XmlElement(name = "return")
protected boolean _return;
/**
* Gets the value of the return property.
*
*/
public boolean isReturn() {
return _return;
}
/**
* Sets the value of the return property.
*
*/
public void setReturn(boolean value) {
this._return = value;
}
}

View File

@@ -0,0 +1,27 @@
package exercise2_client_ws.clientws;
/**
* Created by Giovanni on 13/06/2015.
*/
public class ClientSendBook {
public static void main (String[] args) {
Wsinterface bws = new BookWebServiceService().getBookWebServicePort();
Book b = new Book();
b.setTitle("xgiovio president");
b.setPrice(100f);
b.setAuthor("xgiovio");
b.setIsbn("0001s");
System.out.println(bws.checkbook( b));
}
}

Binary file not shown.

View File

@@ -0,0 +1,89 @@
package exercise2_client_ws.clientws;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.namespace.QName;
/**
* This object contains factory methods for each
* Java content interface and Java element interface
* generated in the exercise2_client_ws.clientws package.
* <p>An ObjectFactory allows you to programatically
* construct new instances of the Java representation
* for XML content. The Java representation of XML
* content can consist of schema derived interfaces
* and classes representing the binding of schema
* type definitions, element declarations and model
* groups. Factory methods for each of these are
* provided in this class.
*
*/
@XmlRegistry
public class ObjectFactory {
private final static QName _Checkbook_QNAME = new QName("http://exercise2_ws/", "checkbook");
private final static QName _CheckbookResponse_QNAME = new QName("http://exercise2_ws/", "checkbookResponse");
private final static QName _Book_QNAME = new QName("http://exercise2_ws/", "book");
/**
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: exercise2_client_ws.clientws
*
*/
public ObjectFactory() {
}
/**
* Create an instance of {@link Book }
*
*/
public Book createBook() {
return new Book();
}
/**
* Create an instance of {@link Checkbook }
*
*/
public Checkbook createCheckbook() {
return new Checkbook();
}
/**
* Create an instance of {@link CheckbookResponse }
*
*/
public CheckbookResponse createCheckbookResponse() {
return new CheckbookResponse();
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link Checkbook }{@code >}}
*
*/
@XmlElementDecl(namespace = "http://exercise2_ws/", name = "checkbook")
public JAXBElement<Checkbook> createCheckbook(Checkbook value) {
return new JAXBElement<Checkbook>(_Checkbook_QNAME, Checkbook.class, null, value);
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link CheckbookResponse }{@code >}}
*
*/
@XmlElementDecl(namespace = "http://exercise2_ws/", name = "checkbookResponse")
public JAXBElement<CheckbookResponse> createCheckbookResponse(CheckbookResponse value) {
return new JAXBElement<CheckbookResponse>(_CheckbookResponse_QNAME, CheckbookResponse.class, null, value);
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link Book }{@code >}}
*
*/
@XmlElementDecl(namespace = "http://exercise2_ws/", name = "book")
public JAXBElement<Book> createBook(Book value) {
return new JAXBElement<Book>(_Book_QNAME, Book.class, null, value);
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,42 @@
package exercise2_client_ws.clientws;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.Action;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.2.10-b140803.1500
* Generated source version: 2.2
*
*/
@WebService(name = "wsinterface", targetNamespace = "http://exercise2_ws/")
@XmlSeeAlso({
ObjectFactory.class
})
public interface Wsinterface {
/**
*
* @param arg0
* @return
* returns boolean
*/
@WebMethod
@WebResult(targetNamespace = "")
@RequestWrapper(localName = "checkbook", targetNamespace = "http://exercise2_ws/", className = "exercise2_client_ws.clientws.Checkbook")
@ResponseWrapper(localName = "checkbookResponse", targetNamespace = "http://exercise2_ws/", className = "exercise2_client_ws.clientws.CheckbookResponse")
@Action(input = "http://exercise2_ws/wsinterface/checkbookRequest", output = "http://exercise2_ws/wsinterface/checkbookResponse")
public boolean checkbook(
@WebParam(name = "arg0", targetNamespace = "")
Book arg0);
}

Binary file not shown.

View File

@@ -0,0 +1,2 @@
@javax.xml.bind.annotation.XmlSchema(namespace = "http://exercise2_ws/")
package exercise2_client_ws.clientws;

74
exercise2_ws/Book.java Normal file
View File

@@ -0,0 +1,74 @@
package exercise2_ws;
import javax.persistence.*;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
/**
* Created by Giovanni on 31/05/2015.
*/
@Entity(name="Bookws")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "findbyisbnws", query = "SELECT b FROM Bookws b WHERE b.isbn =?1"),
@NamedQuery(name = "findallws", query = "SELECT b FROM Bookws b")
})
public class Book implements Serializable{
@GeneratedValue @Id
private Long id ;
@NotNull
private String title;
@NotNull
private String author;
@NotNull
private Float price;
@NotNull
private String isbn;
public Book(){}
public Book(@NotNull String in_isbn,@NotNull String in_title,@NotNull String in_author, @NotNull @DecimalMin("0.0") Float in_price){
title = in_title;
author = in_author;
price = in_price;
isbn = in_isbn;
}
public @NotNull String getIsbn() {
return isbn;
}
public void setIsbn(@NotNull String isbn) {
this.isbn = isbn;
}
public @NotNull String getTitle() {
return title;
}
public void setTitle(@NotNull String title) {
this.title = title;
}
public @NotNull String getAuthor() {
return author;
}
public void setAuthor( @NotNull String author) {
this.author = author;
}
public @NotNull @DecimalMin("0.0") Float getPrice() {
return price;
}
public void setPrice(@NotNull @DecimalMin("0.0") Float price) {
this.price = price;
}
}

View File

@@ -0,0 +1,26 @@
package exercise2_ws;
import java.io.Serializable;
/**
* Created by Giovanni on 31/05/2015.
*/
public class BookMessage implements Serializable{
public BookMessage (String in_isbn, Float in_price){
isbn = in_isbn;
price = in_price;
}
private String isbn;
private Float price;
public String getIsbn() {
return isbn;
}
public Float getPrice() {
return price;
}
}

View File

@@ -0,0 +1,18 @@
package exercise2_ws;
import javax.jws.WebService;
/**
* Created by Giovanni on 13/06/2015.
*/
@WebService(endpointInterface ="exercise2_ws.wsinterface")
public class BookWebService implements wsinterface {
public boolean checkbook(Book b) {
if (b.getIsbn() == null)
return false;
return true;
}
}

49
exercise2_ws/EJBBook.java Normal file
View File

@@ -0,0 +1,49 @@
package exercise2_ws;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* Created by Giovanni on 24/05/2015.
*/
@Stateless
@LocalBean
@ws
public class EJBBook implements RemoteInterface {
@PersistenceContext(unitName = "exercise2ws")
EntityManager em ;
public void create_book (@NotNull Book s) {
em.persist(s);
}
public void update_book (@NotNull Book s) {
em.merge(s);
em.persist(s);
}
public void delete_book (@NotNull Book s) {
em.merge(s);
em.remove(s);
}
public @NotNull List<Book> findbyisbn (@NotNull String in_isbn) {
Query Q = em.createNamedQuery("findbyisbnws");
Q.setParameter(1, in_isbn);
return (List<Book>)Q.getResultList();
}
public List<Book> findall () {
Query Q = em.createNamedQuery("findallws");
return (List<Book>)Q.getResultList();
}
}

View File

@@ -0,0 +1,43 @@
package exercise2_ws;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.inject.Inject;
/**
* Created by Giovanni on 24/05/2015.
*/
@Singleton
@Startup
public class InitializeDB {
private Book b1,b2;
@Inject @ws
private EJBBook e;
@PostConstruct
void pupulate (){
b1 = new Book("0001","Titolo1","Author1",10f);
b2 = new Book("0010","Titolo2","Author2",30f);
e.create_book(b1);
e.create_book(b2);
}
@PreDestroy
void delete () {
e.delete_book(b1);
e.delete_book(b2);
}
}

40
exercise2_ws/MDBBook.java Normal file
View File

@@ -0,0 +1,40 @@
package exercise2_ws;
import javax.ejb.MessageDriven;
import javax.inject.Inject;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Logger;
/**
* Created by Giovanni on 31/05/2015.
*/
@MessageDriven(mappedName = "jms/javaee7/Topic")
public class MDBBook implements MessageListener {
@Inject
Logger l;
@Inject @ws
EJBBook e;
public void onMessage(Message message) {
try {
exercise2_ws.BookMessage m = message.getBody(exercise2_ws.BookMessage.class);
l.info("Messaggio: " + m.getIsbn() + " " + m.getPrice());
List<exercise2_ws.Book> lb = e.findbyisbn(m.getIsbn());
Iterator<exercise2_ws.Book>ib = lb.iterator();
if (ib.hasNext()){
Book b = ib.next();
b.setPrice(m.getPrice());
e.update_book(b);
}
} catch (JMSException e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,16 @@
package exercise2_ws;
import javax.ejb.Remote;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* Created by Giovanni on 24/05/2015.
*/
@Remote
public interface RemoteInterface {
@NotNull List<exercise2_ws.Book> findbyisbn(@NotNull String in_isbn);
List<exercise2_ws.Book> findall() ;
}

18
exercise2_ws/ws.java Normal file
View File

@@ -0,0 +1,18 @@
package exercise2_ws;
import javax.inject.Qualifier;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Created by Giovanni on 26/04/2015.
*/
@Qualifier
@Retention(RUNTIME)
@Target({FIELD, TYPE, METHOD})
public @interface ws {
}

View File

@@ -0,0 +1,11 @@
package exercise2_ws;
import javax.jws.WebService;
/**
* Created by Giovanni on 13/06/2015.
*/
@WebService
public interface wsinterface {
boolean checkbook(Book b);
}

17
test5_ws/HelloWorld.java Normal file
View File

@@ -0,0 +1,17 @@
package test5_ws;
import javax.ejb.Stateless;
import javax.jws.WebService;
/**
* Created by Giovanni on 12/06/2015.
*/
@WebService(endpointInterface ="test5_ws.HelloWorldInterface")
@Stateless
public class HelloWorld implements HelloWorldInterface{
public ObjectToPass modifymessage(ObjectToPass o) {
System.out.println("original message " + o.message);
o.message = "modified by server";
return o;
}
}

View File

@@ -0,0 +1,11 @@
package test5_ws;
import javax.jws.WebService;
/**
* Created by Giovanni on 12/06/2015.
*/
@WebService
public interface HelloWorldInterface {
ObjectToPass modifymessage(ObjectToPass o);
}

View File

@@ -0,0 +1,12 @@
package test5_ws;
import javax.xml.bind.annotation.XmlRootElement;
/**
* Created by Giovanni on 12/06/2015.
*/
@XmlRootElement
public class ObjectToPass {
public String message = "def";
}

View File

@@ -0,0 +1,17 @@
package test5_ws_client;
import test5_ws.*;
/**
* Created by Giovanni on 12/06/2015.
*/
public class Client {
public static void main(String[] argv) {
HelloWorldInterface service = new HelloWorldService().getHelloWorldPort();
//invoke business method
ObjectToPass o = new ObjectToPass();
o.message = "jo from the client";
System.out.println(service.modifymessage(o).message);
}
}

Binary file not shown.

View File

@@ -0,0 +1,36 @@
<?xml version='1.0' encoding='UTF-8'?><!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is Metro/2.3.1-b419 (branches/2.3.1.x-7937; 2014-08-04T08:11:03+0000) JAXWS-RI/2.2.10-b140803.1500 JAXWS-API/2.2.11 JAXB-RI/2.2.10-b140802.1033 JAXB-API/2.2.12-b140109.1041 svn-revision#unknown. --><!-- Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is Metro/2.3.1-b419 (branches/2.3.1.x-7937; 2014-08-04T08:11:03+0000) JAXWS-RI/2.2.10-b140803.1500 JAXWS-API/2.2.11 JAXB-RI/2.2.10-b140802.1033 JAXB-API/2.2.12-b140109.1041 svn-revision#unknown. --><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://test5_ws/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://test5_ws/" name="HelloWorldService">
<types>
<xsd:schema>
<xsd:import namespace="http://test5_ws/" schemaLocation="http://localhost:8080/web/services/HelloWorld?xsd=1"/>
</xsd:schema>
</types>
<message name="modifymessage">
<part name="parameters" element="tns:modifymessage"/>
</message>
<message name="modifymessageResponse">
<part name="parameters" element="tns:modifymessageResponse"/>
</message>
<portType name="HelloWorldInterface">
<operation name="modifymessage">
<input wsam:Action="http://test5_ws/HelloWorldInterface/modifymessageRequest" message="tns:modifymessage"/>
<output wsam:Action="http://test5_ws/HelloWorldInterface/modifymessageResponse" message="tns:modifymessageResponse"/>
</operation>
</portType>
<binding name="HelloWorldPortBinding" type="tns:HelloWorldInterface">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="modifymessage">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="HelloWorldService">
<port name="HelloWorldPort" binding="tns:HelloWorldPortBinding">
<soap:address location="http://localhost:8080/web/services/HelloWorld"/>
</port>
</service>
</definitions>

Binary file not shown.

View File

@@ -0,0 +1,42 @@
package test5_ws_client;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.Action;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.2.10-b140803.1500
* Generated source version: 2.2
*
*/
@WebService(name = "HelloWorldInterface", targetNamespace = "http://test5_ws/")
@XmlSeeAlso({
ObjectFactory.class
})
public interface HelloWorldInterface {
/**
*
* @param arg0
* @return
* returns test5_ws_client.ObjectToPass
*/
@WebMethod
@WebResult(targetNamespace = "")
@RequestWrapper(localName = "modifymessage", targetNamespace = "http://test5_ws/", className = "test5_ws_client.Modifymessage")
@ResponseWrapper(localName = "modifymessageResponse", targetNamespace = "http://test5_ws/", className = "test5_ws_client.ModifymessageResponse")
@Action(input = "http://test5_ws/HelloWorldInterface/modifymessageRequest", output = "http://test5_ws/HelloWorldInterface/modifymessageResponse")
public ObjectToPass modifymessage(
@WebParam(name = "arg0", targetNamespace = "")
ObjectToPass arg0);
}

Binary file not shown.

View File

@@ -0,0 +1,94 @@
package test5_ws_client;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceFeature;
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.2.10-b140803.1500
* Generated source version: 2.2
*
*/
@WebServiceClient(name = "HelloWorldService", targetNamespace = "http://test5_ws/", wsdlLocation = "http://localhost:8080/web/services/HelloWorld?wsdl")
public class HelloWorldService
extends Service
{
private final static URL HELLOWORLDSERVICE_WSDL_LOCATION;
private final static WebServiceException HELLOWORLDSERVICE_EXCEPTION;
private final static QName HELLOWORLDSERVICE_QNAME = new QName("http://test5_ws/", "HelloWorldService");
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("http://localhost:8080/web/services/HelloWorld?wsdl");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
HELLOWORLDSERVICE_WSDL_LOCATION = url;
HELLOWORLDSERVICE_EXCEPTION = e;
}
public HelloWorldService() {
super(__getWsdlLocation(), HELLOWORLDSERVICE_QNAME);
}
public HelloWorldService(WebServiceFeature... features) {
super(__getWsdlLocation(), HELLOWORLDSERVICE_QNAME, features);
}
public HelloWorldService(URL wsdlLocation) {
super(wsdlLocation, HELLOWORLDSERVICE_QNAME);
}
public HelloWorldService(URL wsdlLocation, WebServiceFeature... features) {
super(wsdlLocation, HELLOWORLDSERVICE_QNAME, features);
}
public HelloWorldService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public HelloWorldService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
super(wsdlLocation, serviceName, features);
}
/**
*
* @return
* returns HelloWorldInterface
*/
@WebEndpoint(name = "HelloWorldPort")
public HelloWorldInterface getHelloWorldPort() {
return super.getPort(new QName("http://test5_ws/", "HelloWorldPort"), HelloWorldInterface.class);
}
/**
*
* @param features
* A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
* @return
* returns HelloWorldInterface
*/
@WebEndpoint(name = "HelloWorldPort")
public HelloWorldInterface getHelloWorldPort(WebServiceFeature... features) {
return super.getPort(new QName("http://test5_ws/", "HelloWorldPort"), HelloWorldInterface.class, features);
}
private static URL __getWsdlLocation() {
if (HELLOWORLDSERVICE_EXCEPTION!= null) {
throw HELLOWORLDSERVICE_EXCEPTION;
}
return HELLOWORLDSERVICE_WSDL_LOCATION;
}
}

Binary file not shown.

View File

@@ -0,0 +1,60 @@
package test5_ws_client;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for modifymessage complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="modifymessage">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="arg0" type="{http://test5_ws/}objectToPass" minOccurs="0"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "modifymessage", propOrder = {
"arg0"
})
public class Modifymessage {
protected ObjectToPass arg0;
/**
* Gets the value of the arg0 property.
*
* @return
* possible object is
* {@link ObjectToPass }
*
*/
public ObjectToPass getArg0() {
return arg0;
}
/**
* Sets the value of the arg0 property.
*
* @param value
* allowed object is
* {@link ObjectToPass }
*
*/
public void setArg0(ObjectToPass value) {
this.arg0 = value;
}
}

Binary file not shown.

View File

@@ -0,0 +1,62 @@
package test5_ws_client;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for modifymessageResponse complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="modifymessageResponse">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="return" type="{http://test5_ws/}objectToPass" minOccurs="0"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "modifymessageResponse", propOrder = {
"_return"
})
public class ModifymessageResponse {
@XmlElement(name = "return")
protected ObjectToPass _return;
/**
* Gets the value of the return property.
*
* @return
* possible object is
* {@link ObjectToPass }
*
*/
public ObjectToPass getReturn() {
return _return;
}
/**
* Sets the value of the return property.
*
* @param value
* allowed object is
* {@link ObjectToPass }
*
*/
public void setReturn(ObjectToPass value) {
this._return = value;
}
}

Binary file not shown.

View File

@@ -0,0 +1,89 @@
package test5_ws_client;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.namespace.QName;
/**
* This object contains factory methods for each
* Java content interface and Java element interface
* generated in the test5_ws_client package.
* <p>An ObjectFactory allows you to programatically
* construct new instances of the Java representation
* for XML content. The Java representation of XML
* content can consist of schema derived interfaces
* and classes representing the binding of schema
* type definitions, element declarations and model
* groups. Factory methods for each of these are
* provided in this class.
*
*/
@XmlRegistry
public class ObjectFactory {
private final static QName _Modifymessage_QNAME = new QName("http://test5_ws/", "modifymessage");
private final static QName _ObjectToPass_QNAME = new QName("http://test5_ws/", "objectToPass");
private final static QName _ModifymessageResponse_QNAME = new QName("http://test5_ws/", "modifymessageResponse");
/**
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: test5_ws_client
*
*/
public ObjectFactory() {
}
/**
* Create an instance of {@link ModifymessageResponse }
*
*/
public ModifymessageResponse createModifymessageResponse() {
return new ModifymessageResponse();
}
/**
* Create an instance of {@link ObjectToPass }
*
*/
public ObjectToPass createObjectToPass() {
return new ObjectToPass();
}
/**
* Create an instance of {@link Modifymessage }
*
*/
public Modifymessage createModifymessage() {
return new Modifymessage();
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link Modifymessage }{@code >}}
*
*/
@XmlElementDecl(namespace = "http://test5_ws/", name = "modifymessage")
public JAXBElement<Modifymessage> createModifymessage(Modifymessage value) {
return new JAXBElement<Modifymessage>(_Modifymessage_QNAME, Modifymessage.class, null, value);
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link ObjectToPass }{@code >}}
*
*/
@XmlElementDecl(namespace = "http://test5_ws/", name = "objectToPass")
public JAXBElement<ObjectToPass> createObjectToPass(ObjectToPass value) {
return new JAXBElement<ObjectToPass>(_ObjectToPass_QNAME, ObjectToPass.class, null, value);
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link ModifymessageResponse }{@code >}}
*
*/
@XmlElementDecl(namespace = "http://test5_ws/", name = "modifymessageResponse")
public JAXBElement<ModifymessageResponse> createModifymessageResponse(ModifymessageResponse value) {
return new JAXBElement<ModifymessageResponse>(_ModifymessageResponse_QNAME, ModifymessageResponse.class, null, value);
}
}

Binary file not shown.

View File

@@ -0,0 +1,60 @@
package test5_ws_client;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for objectToPass complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="objectToPass">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="message" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "objectToPass", propOrder = {
"message"
})
public class ObjectToPass {
protected String message;
/**
* Gets the value of the message property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getMessage() {
return message;
}
/**
* Sets the value of the message property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setMessage(String value) {
this.message = value;
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,2 @@
@javax.xml.bind.annotation.XmlSchema(namespace = "http://test5_ws/")
package test5_ws_client;