Aggiunto l'esempio del capitolo su SOAP Web Service (JAX-WS)
This commit is contained in:
1
.idea/compiler.xml
generated
1
.idea/compiler.xml
generated
@@ -12,6 +12,7 @@
|
||||
<module name="beanvalidationdemo" />
|
||||
<module name="jmsdemo" />
|
||||
<module name="xmlandjsondemo" />
|
||||
<module name="jaxwsdemoservice" />
|
||||
<module name="ejbdemo" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
|
||||
1
.idea/encodings.xml
generated
1
.idea/encodings.xml
generated
@@ -4,6 +4,7 @@
|
||||
<file url="file://$PROJECT_DIR$/beanvalidationdemo" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/cdidemo" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/ejbdemo" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/jaxwsdemo-service" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/jmsdemo" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/jpademo" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/xmlandjsondemo" charset="UTF-8" />
|
||||
|
||||
3
.idea/misc.xml
generated
3
.idea/misc.xml
generated
@@ -1,6 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="FrameworkDetectionExcludesConfiguration">
|
||||
<file type="web" url="file://$PROJECT_DIR$/jaxwsdemo-service" />
|
||||
</component>
|
||||
<component name="GOROOT" path="/usr/lib/go" />
|
||||
<component name="Kotlin2JsCompilerArguments">
|
||||
<option name="sourceMapEmbedSources" />
|
||||
|
||||
2
jaxwsdemo-service/jaxwsdemoservice.iml
Normal file
2
jaxwsdemo-service/jaxwsdemoservice.iml
Normal file
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4" />
|
||||
72
jaxwsdemo-service/pom.xml
Normal file
72
jaxwsdemo-service/pom.xml
Normal file
@@ -0,0 +1,72 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jaxwsdemo-service</artifactId>
|
||||
<name>jaxwsdemo-service</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<parent>
|
||||
<artifactId>jeedemo</artifactId>
|
||||
<groupId>it.plague.jeedemo</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.7</maven.compiler.source>
|
||||
<maven.compiler.target>1.7</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.main.extras</groupId>
|
||||
<artifactId>glassfish-embedded-all</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>3.2.2</version>
|
||||
<configuration>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>2.12.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>integration-test</id>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
package it.plague.jeedemo;
|
||||
|
||||
import javax.jws.WebService;
|
||||
|
||||
@WebService(endpointInterface = "it.plague.jeedemo.Validator")
|
||||
public class CardValidator implements Validator {
|
||||
|
||||
@Override
|
||||
public boolean validate(CreditCard creditCard) {
|
||||
Character lastDigit = creditCard.getNumber().charAt(creditCard.getNumber().length() - 1);
|
||||
return Integer.parseInt(lastDigit.toString()) % 2 == 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package it.plague.jeedemo;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class CreditCard {
|
||||
|
||||
@XmlAttribute(required = true)
|
||||
private String number;
|
||||
|
||||
@XmlAttribute(name = "expiry_date", required = true)
|
||||
private String expiryDate;
|
||||
|
||||
@XmlAttribute(name = "control_number", required = true)
|
||||
private Integer controlNumber;
|
||||
|
||||
@XmlAttribute(required = true)
|
||||
private String type;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package it.plague.jeedemo;
|
||||
|
||||
import javax.jws.WebService;
|
||||
|
||||
@WebService
|
||||
public interface Validator {
|
||||
|
||||
boolean validate(CreditCard creditCard);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package it.plague.jeedemo;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.ws.Endpoint;
|
||||
import javax.xml.ws.Service;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class CardValidatorIT {
|
||||
|
||||
private static Endpoint endpoint;
|
||||
|
||||
private static Validator cardValidator;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws MalformedURLException {
|
||||
final String url = "http://localhost:8081/cardValidator";
|
||||
|
||||
// Publishes the SOAP Web Service
|
||||
endpoint = Endpoint.publish(url, new CardValidator());
|
||||
|
||||
// Needed properties to access the web service
|
||||
URL wsdlDocumentLocation = new URL(url + "?wsdl");
|
||||
String namespaceURI = "http://jeedemo.plague.it/";
|
||||
String servicePart = "CardValidatorService";
|
||||
String portName = "CardValidatorPort";
|
||||
QName serviceQn = new QName(namespaceURI, servicePart);
|
||||
QName portQn = new QName(namespaceURI, portName);
|
||||
|
||||
// Creates a service instance
|
||||
Service service = Service.create(wsdlDocumentLocation, serviceQn);
|
||||
cardValidator = service.getPort(portQn, Validator.class);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() {
|
||||
if (endpoint != null) {
|
||||
endpoint.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldBePublished() {
|
||||
assertTrue(endpoint.isPublished());
|
||||
assertEquals("http://schemas.xmlsoap.org/wsdl/soap/http", endpoint.getBinding().getBindingID());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCheckCreditCardValidity() {
|
||||
CreditCard creditCard = new CreditCard("12341234", "10/10", 1234, "VISA");
|
||||
assertTrue("Credit card should be valid", cardValidator.validate(creditCard));
|
||||
|
||||
creditCard.setNumber("12341233");
|
||||
assertFalse("Credit card should not be valid", cardValidator.validate(creditCard));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package it.plague.jeedemo;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CardValidatorTest {
|
||||
|
||||
@Test
|
||||
public void shouldCheckCreditCardValidity() {
|
||||
CardValidator cardValidator = new CardValidator();
|
||||
|
||||
CreditCard creditCard = new CreditCard("12341234", "10/10", 1234, "VISA");
|
||||
assertTrue("Credit card should be valid", cardValidator.validate(creditCard));
|
||||
|
||||
creditCard.setNumber("12341233");
|
||||
assertFalse("Credit card should not be valid", cardValidator.validate(creditCard));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user