Merge remote-tracking branch 'origin/master'
# Conflicts: # ejb/ejb-client/pom.xml # ejb/ejb-remote/pom.xml # ejb/pom.xml
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<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>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>algorithms</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<junit.version>4.12</junit.version>
|
||||
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
||||
<exec-maven-plugin.version>1.5.0</exec-maven-plugin.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<defaultGoal>install</defaultGoal>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.baeldung.algorithms.dijkstra;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
public class Dijkstra {
|
||||
|
||||
public static Graph calculateShortestPathFromSource(Graph graph, Node source) {
|
||||
|
||||
source.setDistance(0);
|
||||
|
||||
Set<Node> settledNodes = new HashSet<>();
|
||||
Set<Node> unsettledNodes = new HashSet<>();
|
||||
unsettledNodes.add(source);
|
||||
|
||||
while (unsettledNodes.size() != 0) {
|
||||
Node currentNode = getLowestDistanceNode(unsettledNodes);
|
||||
unsettledNodes.remove(currentNode);
|
||||
for (Entry<Node, Integer> adjacencyPair : currentNode
|
||||
.getAdjacentNodes()
|
||||
.entrySet()) {
|
||||
Node adjacentNode = adjacencyPair.getKey();
|
||||
Integer edgeWeigh = adjacencyPair.getValue();
|
||||
|
||||
if (!settledNodes.contains(adjacentNode)) {
|
||||
CalculateMinimumDistance(adjacentNode, edgeWeigh, currentNode);
|
||||
unsettledNodes.add(adjacentNode);
|
||||
}
|
||||
}
|
||||
settledNodes.add(currentNode);
|
||||
}
|
||||
return graph;
|
||||
}
|
||||
|
||||
private static void CalculateMinimumDistance(Node evaluationNode, Integer edgeWeigh, Node sourceNode) {
|
||||
Integer sourceDistance = sourceNode.getDistance();
|
||||
if (sourceDistance + edgeWeigh < evaluationNode.getDistance()) {
|
||||
evaluationNode.setDistance(sourceDistance + edgeWeigh);
|
||||
LinkedList<Node> shortestPath = new LinkedList<>(sourceNode.getShortestPath());
|
||||
shortestPath.add(sourceNode);
|
||||
evaluationNode.setShortestPath(shortestPath);
|
||||
}
|
||||
}
|
||||
|
||||
private static Node getLowestDistanceNode(Set<Node> unsettledNodes) {
|
||||
Node lowestDistanceNode = null;
|
||||
int lowestDistance = Integer.MAX_VALUE;
|
||||
for (Node node : unsettledNodes) {
|
||||
int nodeDistance = node.getDistance();
|
||||
if (nodeDistance < lowestDistance) {
|
||||
lowestDistance = nodeDistance;
|
||||
lowestDistanceNode = node;
|
||||
}
|
||||
}
|
||||
return lowestDistanceNode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.baeldung.algorithms.dijkstra;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class Graph {
|
||||
|
||||
private Set<Node> nodes = new HashSet<>();
|
||||
|
||||
public void addNode(Node nodeA) {
|
||||
nodes.add(nodeA);
|
||||
}
|
||||
|
||||
public Set<Node> getNodes() {
|
||||
return nodes;
|
||||
}
|
||||
|
||||
public void setNodes(Set<Node> nodes) {
|
||||
this.nodes = nodes;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.baeldung.algorithms.dijkstra;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Node {
|
||||
|
||||
private String name;
|
||||
|
||||
private LinkedList<Node> shortestPath = new LinkedList<>();
|
||||
|
||||
private Integer distance = Integer.MAX_VALUE;
|
||||
|
||||
private Map<Node, Integer> adjacentNodes = new HashMap<>();
|
||||
|
||||
public Node(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void addDestination(Node destination, int distance) {
|
||||
adjacentNodes.put(destination, distance);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Map<Node, Integer> getAdjacentNodes() {
|
||||
return adjacentNodes;
|
||||
}
|
||||
|
||||
public void setAdjacentNodes(Map<Node, Integer> adjacentNodes) {
|
||||
this.adjacentNodes = adjacentNodes;
|
||||
}
|
||||
|
||||
public Integer getDistance() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
public void setDistance(Integer distance) {
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
public List<Node> getShortestPath() {
|
||||
return shortestPath;
|
||||
}
|
||||
|
||||
public void setShortestPath(LinkedList<Node> shortestPath) {
|
||||
this.shortestPath = shortestPath;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package algorithms;
|
||||
|
||||
import com.baeldung.algorithms.dijkstra.Dijkstra;
|
||||
import com.baeldung.algorithms.dijkstra.Graph;
|
||||
import com.baeldung.algorithms.dijkstra.Node;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class DijkstraAlgorithmTest {
|
||||
|
||||
@Test
|
||||
public void whenSPPSolved_thenCorrect() {
|
||||
|
||||
Node nodeA = new Node("A");
|
||||
Node nodeB = new Node("B");
|
||||
Node nodeC = new Node("C");
|
||||
Node nodeD = new Node("D");
|
||||
Node nodeE = new Node("E");
|
||||
Node nodeF = new Node("F");
|
||||
|
||||
nodeA.addDestination(nodeB, 10);
|
||||
nodeA.addDestination(nodeC, 15);
|
||||
|
||||
nodeB.addDestination(nodeD, 12);
|
||||
nodeB.addDestination(nodeF, 15);
|
||||
|
||||
nodeC.addDestination(nodeE, 10);
|
||||
|
||||
nodeD.addDestination(nodeE, 2);
|
||||
nodeD.addDestination(nodeF, 1);
|
||||
|
||||
nodeF.addDestination(nodeE, 5);
|
||||
|
||||
Graph graph = new Graph();
|
||||
|
||||
graph.addNode(nodeA);
|
||||
graph.addNode(nodeB);
|
||||
graph.addNode(nodeC);
|
||||
graph.addNode(nodeD);
|
||||
graph.addNode(nodeE);
|
||||
graph.addNode(nodeF);
|
||||
|
||||
graph = Dijkstra.calculateShortestPathFromSource(graph, nodeA);
|
||||
|
||||
List<Node> shortestPathForNodeB = Arrays.asList(nodeA);
|
||||
List<Node> shortestPathForNodeC = Arrays.asList(nodeA);
|
||||
List<Node> shortestPathForNodeD = Arrays.asList(nodeA, nodeB);
|
||||
List<Node> shortestPathForNodeE = Arrays.asList(nodeA, nodeB, nodeD);
|
||||
List<Node> shortestPathForNodeF = Arrays.asList(nodeA, nodeB, nodeD);
|
||||
|
||||
for (Node node : graph.getNodes()) {
|
||||
switch (node.getName()) {
|
||||
case "B":
|
||||
assertTrue(node
|
||||
.getShortestPath()
|
||||
.equals(shortestPathForNodeB));
|
||||
break;
|
||||
case "C":
|
||||
assertTrue(node
|
||||
.getShortestPath()
|
||||
.equals(shortestPathForNodeC));
|
||||
break;
|
||||
case "D":
|
||||
assertTrue(node
|
||||
.getShortestPath()
|
||||
.equals(shortestPathForNodeD));
|
||||
break;
|
||||
case "E":
|
||||
assertTrue(node
|
||||
.getShortestPath()
|
||||
.equals(shortestPathForNodeE));
|
||||
break;
|
||||
case "F":
|
||||
assertTrue(node
|
||||
.getShortestPath()
|
||||
.equals(shortestPathForNodeF));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
<properties>
|
||||
<auto-service.version>1.0-rc2</auto-service.version>
|
||||
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
|
||||
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -13,6 +13,11 @@
|
||||
|
||||
<artifactId>annotation-user</artifactId>
|
||||
|
||||
<properties>
|
||||
<junit.version>4.12</junit.version>
|
||||
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
@@ -24,7 +29,7 @@
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -37,7 +42,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
## Relevant Articles:
|
||||
- [Introduction to Apache CXF Aegis Data Binding](http://www.baeldung.com/aegis-data-binding-in-apache-cxf)
|
||||
@@ -0,0 +1,20 @@
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>cxf-aegis</artifactId>
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>apache-cxf</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<properties>
|
||||
<cxf.version>3.1.8</cxf.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-databinding-aegis</artifactId>
|
||||
<version>${cxf.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.baeldung.cxf.aegis;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Course {
|
||||
private int id;
|
||||
private String name;
|
||||
private String instructor;
|
||||
private Date enrolmentDate;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getInstructor() {
|
||||
return instructor;
|
||||
}
|
||||
|
||||
public void setInstructor(String instructor) {
|
||||
this.instructor = instructor;
|
||||
}
|
||||
|
||||
public Date getEnrolmentDate() {
|
||||
return enrolmentDate;
|
||||
}
|
||||
|
||||
public void setEnrolmentDate(Date enrolmentDate) {
|
||||
this.enrolmentDate = enrolmentDate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.baeldung.cxf.aegis;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface CourseRepo {
|
||||
String getGreeting();
|
||||
void setGreeting(String greeting);
|
||||
Map<Integer, Course> getCourses();
|
||||
void setCourses(Map<Integer, Course> courses);
|
||||
void addCourse(Course course);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.baeldung.cxf.aegis;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CourseRepoImpl implements CourseRepo {
|
||||
private String greeting;
|
||||
private Map<Integer, Course> courses = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public String getGreeting() {
|
||||
return greeting;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGreeting(String greeting) {
|
||||
this.greeting = greeting;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, Course> getCourses() {
|
||||
return courses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCourses(Map<Integer, Course> courses) {
|
||||
this.courses = courses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCourse(Course course) {
|
||||
courses.put(course.getId(), course);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<mappings>
|
||||
<mapping>
|
||||
<property name="instructor" ignore="true"/>
|
||||
</mapping>
|
||||
</mappings>
|
||||
@@ -0,0 +1,5 @@
|
||||
<mappings xmlns:ns="http://courserepo.baeldung.com">
|
||||
<mapping name="ns:Baeldung">
|
||||
<property name="greeting" style="attribute"/>
|
||||
</mapping>
|
||||
</mappings>
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.baeldung.cxf.aegis;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLOutputFactory;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
|
||||
import org.apache.cxf.aegis.AegisContext;
|
||||
import org.apache.cxf.aegis.AegisReader;
|
||||
import org.apache.cxf.aegis.AegisWriter;
|
||||
import org.apache.cxf.aegis.type.AegisType;
|
||||
|
||||
public class BaeldungTest {
|
||||
private AegisContext context;
|
||||
private String fileName = "baeldung.xml";
|
||||
|
||||
@Test
|
||||
public void whenMarshalingAndUnmarshalingCourseRepo_thenCorrect() throws Exception {
|
||||
initializeContext();
|
||||
CourseRepo inputRepo = initCourseRepo();
|
||||
marshalCourseRepo(inputRepo);
|
||||
CourseRepo outputRepo = unmarshalCourseRepo();
|
||||
Course restCourse = outputRepo.getCourses().get(1);
|
||||
Course securityCourse = outputRepo.getCourses().get(2);
|
||||
assertEquals("Welcome to Beldung!", outputRepo.getGreeting());
|
||||
assertEquals("REST with Spring", restCourse.getName());
|
||||
assertEquals(new Date(1234567890000L), restCourse.getEnrolmentDate());
|
||||
assertNull(restCourse.getInstructor());
|
||||
assertEquals("Learn Spring Security", securityCourse.getName());
|
||||
assertEquals(new Date(1456789000000L), securityCourse.getEnrolmentDate());
|
||||
assertNull(securityCourse.getInstructor());
|
||||
}
|
||||
|
||||
private void initializeContext() {
|
||||
context = new AegisContext();
|
||||
Set<Type> rootClasses = new HashSet<Type>();
|
||||
rootClasses.add(CourseRepo.class);
|
||||
context.setRootClasses(rootClasses);
|
||||
Map<Class<?>, String> beanImplementationMap = new HashMap<>();
|
||||
beanImplementationMap.put(CourseRepoImpl.class, "CourseRepo");
|
||||
context.setBeanImplementationMap(beanImplementationMap);
|
||||
context.setWriteXsiTypes(true);
|
||||
context.initialize();
|
||||
}
|
||||
|
||||
private CourseRepoImpl initCourseRepo() {
|
||||
Course restCourse = new Course();
|
||||
restCourse.setId(1);
|
||||
restCourse.setName("REST with Spring");
|
||||
restCourse.setInstructor("Eugen");
|
||||
restCourse.setEnrolmentDate(new Date(1234567890000L));
|
||||
Course securityCourse = new Course();
|
||||
securityCourse.setId(2);
|
||||
securityCourse.setName("Learn Spring Security");
|
||||
securityCourse.setInstructor("Eugen");
|
||||
securityCourse.setEnrolmentDate(new Date(1456789000000L));
|
||||
CourseRepoImpl courseRepo = new CourseRepoImpl();
|
||||
courseRepo.setGreeting("Welcome to Beldung!");
|
||||
courseRepo.addCourse(restCourse);
|
||||
courseRepo.addCourse(securityCourse);
|
||||
return courseRepo;
|
||||
}
|
||||
|
||||
private void marshalCourseRepo(CourseRepo courseRepo) throws Exception {
|
||||
AegisWriter<XMLStreamWriter> writer = context.createXMLStreamWriter();
|
||||
AegisType aegisType = context.getTypeMapping().getType(CourseRepo.class);
|
||||
XMLStreamWriter xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(new FileOutputStream(fileName));
|
||||
writer.write(courseRepo, new QName("http://aegis.cxf.baeldung.com", "baeldung"), false, xmlWriter, aegisType);
|
||||
xmlWriter.close();
|
||||
}
|
||||
|
||||
private CourseRepo unmarshalCourseRepo() throws Exception {
|
||||
AegisReader<XMLStreamReader> reader = context.createXMLStreamReader();
|
||||
XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(new FileInputStream(fileName));
|
||||
CourseRepo courseRepo = (CourseRepo) reader.read(xmlReader, context.getTypeMapping().getType(CourseRepo.class));
|
||||
xmlReader.close();
|
||||
return courseRepo;
|
||||
}
|
||||
}
|
||||
@@ -4,15 +4,18 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>cxf-introduction</artifactId>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>apache-cxf</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<cxf.version>3.1.6</cxf.version>
|
||||
<cxf.version>3.1.8</cxf.version>
|
||||
<surefire.version>2.19.1</surefire.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
@@ -24,7 +27,7 @@
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.19.1</version>
|
||||
<version>${surefire.version}</version>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
@@ -33,6 +36,7 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
### Relevant Articles:
|
||||
- [Apache CXF Support for RESTful Web Services](http://www.baeldung.com/apache-cxf-rest-api)
|
||||
@@ -4,17 +4,20 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>cxf-jaxrs-implementation</artifactId>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>apache-cxf</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<cxf.version>3.1.7</cxf.version>
|
||||
<cxf.version>3.1.8</cxf.version>
|
||||
<httpclient.version>4.5.2</httpclient.version>
|
||||
<surefire.version>2.19.1</surefire.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
@@ -26,7 +29,7 @@
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.19.1</version>
|
||||
<version>${surefire.version}</version>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
@@ -35,6 +38,7 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>${javax.servlet-api.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
<version>${maven-war-plugin.version}</version>
|
||||
<configuration>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
</configuration>
|
||||
@@ -66,7 +66,7 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.cargo</groupId>
|
||||
<artifactId>cargo-maven2-plugin</artifactId>
|
||||
<version>1.4.19</version>
|
||||
<version>${cargo-maven2-plugin.version}</version>
|
||||
<configuration>
|
||||
<container>
|
||||
<containerId>tomcat8x</containerId>
|
||||
@@ -121,9 +121,13 @@
|
||||
</profiles>
|
||||
|
||||
<properties>
|
||||
<cxf.version>3.1.6</cxf.version>
|
||||
<spring.version>4.3.1.RELEASE</spring.version>
|
||||
<cxf.version>3.1.8</cxf.version>
|
||||
<spring.version>4.3.4.RELEASE</spring.version>
|
||||
<javax.servlet-api.version>3.1.0</javax.servlet-api.version>
|
||||
|
||||
<maven-war-plugin.version>2.6</maven-war-plugin.version>
|
||||
<surefire.version>2.19.1</surefire.version>
|
||||
<cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
||||
+13
-3
@@ -5,19 +5,29 @@
|
||||
<artifactId>apache-cxf</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>cxf-introduction</module>
|
||||
<module>cxf-spring</module>
|
||||
<module>cxf-jaxrs-implementation</module>
|
||||
<module>cxf-aegis</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<junit.version>4.12</junit.version>
|
||||
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
||||
<exec-maven-plugin.version>1.5.0</exec-maven-plugin.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<defaultGoal>install</defaultGoal>
|
||||
<pluginManagement>
|
||||
@@ -25,7 +35,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
@@ -34,7 +44,7 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.5.0</version>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
|
||||
+12
-30
@@ -67,7 +67,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.xmlgraphics</groupId>
|
||||
<artifactId>fop</artifactId>
|
||||
<version>1.1</version>
|
||||
<version>${fop.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.avalon.framework</groupId>
|
||||
@@ -83,18 +83,18 @@
|
||||
<dependency>
|
||||
<groupId>avalon-framework</groupId>
|
||||
<artifactId>avalon-framework-api</artifactId>
|
||||
<version>4.2.0</version>
|
||||
<version>${avalon-framework.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>avalon-framework</groupId>
|
||||
<artifactId>avalon-framework-impl</artifactId>
|
||||
<version>4.2.0</version>
|
||||
<version>${avalon-framework.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.dbdoclet</groupId>
|
||||
<artifactId>dbdoclet</artifactId>
|
||||
<version>8.0.2</version>
|
||||
<version>${dbdoclet.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -108,7 +108,7 @@
|
||||
<dependency>
|
||||
<groupId>net.sf.jtidy</groupId>
|
||||
<artifactId>jtidy</artifactId>
|
||||
<version>r938</version>
|
||||
<version>${jtidy.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
@@ -187,40 +187,22 @@
|
||||
</profiles>
|
||||
|
||||
<properties>
|
||||
<!-- persistence -->
|
||||
<hibernate.version>4.3.11.Final</hibernate.version>
|
||||
<mysql-connector-java.version>5.1.38</mysql-connector-java.version>
|
||||
|
||||
<!-- marshalling -->
|
||||
<jackson.version>2.7.2</jackson.version>
|
||||
|
||||
<fop.version>1.1</fop.version>
|
||||
<avalon-framework.version>4.3</avalon-framework.version>
|
||||
<dbdoclet.version>8.0.2</dbdoclet.version>
|
||||
<jtidy.version>r938</jtidy.version>
|
||||
<!-- logging -->
|
||||
<org.slf4j.version>1.7.9</org.slf4j.version>
|
||||
<logback.version>1.1.2</logback.version>
|
||||
|
||||
<!-- various -->
|
||||
<hibernate-validator.version>5.1.3.Final</hibernate-validator.version>
|
||||
|
||||
<!-- util -->
|
||||
<guava.version>19.0</guava.version>
|
||||
<commons-lang3.version>3.3.2</commons-lang3.version>
|
||||
<org.slf4j.version>1.7.21</org.slf4j.version>
|
||||
<logback.version>1.1.7</logback.version>
|
||||
|
||||
<!-- testing -->
|
||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
<mockito.version>1.10.19</mockito.version>
|
||||
|
||||
<httpcore.version>4.4</httpcore.version>
|
||||
<httpclient.version>4.4</httpclient.version>
|
||||
|
||||
<rest-assured.version>2.9.0</rest-assured.version>
|
||||
|
||||
<!-- maven plugins -->
|
||||
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
|
||||
<maven-war-plugin.version>2.6</maven-war-plugin.version>
|
||||
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
||||
<maven-resources-plugin.version>2.7</maven-resources-plugin.version>
|
||||
<cargo-maven2-plugin.version>1.4.18</cargo-maven2-plugin.version>
|
||||
|
||||
</properties>
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
*.docx
|
||||
@@ -0,0 +1,41 @@
|
||||
<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>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>apache-poi</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
<poi.version>3.15</poi.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>${poi.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.baeldung.poi.word;
|
||||
|
||||
import org.apache.poi.util.Units;
|
||||
import org.apache.poi.xwpf.usermodel.*;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class WordDocument {
|
||||
public static String logo = "logo-leaf.png";
|
||||
public static String paragraph1 = "poi-word-para1.txt";
|
||||
public static String paragraph2 = "poi-word-para2.txt";
|
||||
public static String paragraph3 = "poi-word-para3.txt";
|
||||
public static String output = "rest-with-spring.docx";
|
||||
|
||||
public void handleSimpleDoc() throws Exception {
|
||||
XWPFDocument document = new XWPFDocument();
|
||||
|
||||
XWPFParagraph title = document.createParagraph();
|
||||
title.setAlignment(ParagraphAlignment.CENTER);
|
||||
XWPFRun titleRun = title.createRun();
|
||||
titleRun.setText("Build Your REST API with Spring");
|
||||
titleRun.setColor("009933");
|
||||
titleRun.setBold(true);
|
||||
titleRun.setFontFamily("Courier");
|
||||
titleRun.setFontSize(20);
|
||||
|
||||
XWPFParagraph subTitle = document.createParagraph();
|
||||
subTitle.setAlignment(ParagraphAlignment.CENTER);
|
||||
XWPFRun subTitleRun = subTitle.createRun();
|
||||
subTitleRun.setText("from HTTP fundamentals to API Mastery");
|
||||
subTitleRun.setColor("00CC44");
|
||||
subTitleRun.setFontFamily("Courier");
|
||||
subTitleRun.setFontSize(16);
|
||||
subTitleRun.setTextPosition(20);
|
||||
subTitleRun.setUnderline(UnderlinePatterns.DOT_DOT_DASH);
|
||||
|
||||
XWPFParagraph image = document.createParagraph();
|
||||
image.setAlignment(ParagraphAlignment.CENTER);
|
||||
XWPFRun imageRun = image.createRun();
|
||||
imageRun.setTextPosition(20);
|
||||
Path imagePath = Paths.get(ClassLoader.getSystemResource(logo).toURI());
|
||||
imageRun.addPicture(Files.newInputStream(imagePath), XWPFDocument.PICTURE_TYPE_PNG, imagePath.getFileName().toString(), Units.toEMU(50), Units.toEMU(50));
|
||||
|
||||
XWPFParagraph sectionTitle = document.createParagraph();
|
||||
XWPFRun sectionTRun = sectionTitle.createRun();
|
||||
sectionTRun.setText("What makes a good API?");
|
||||
sectionTRun.setColor("00CC44");
|
||||
sectionTRun.setBold(true);
|
||||
sectionTRun.setFontFamily("Courier");
|
||||
|
||||
XWPFParagraph para1 = document.createParagraph();
|
||||
para1.setAlignment(ParagraphAlignment.BOTH);
|
||||
String string1 = convertTextFileToString(paragraph1);
|
||||
XWPFRun para1Run = para1.createRun();
|
||||
para1Run.setText(string1);
|
||||
|
||||
XWPFParagraph para2 = document.createParagraph();
|
||||
para2.setAlignment(ParagraphAlignment.RIGHT);
|
||||
String string2 = convertTextFileToString(paragraph2);
|
||||
XWPFRun para2Run = para2.createRun();
|
||||
para2Run.setText(string2);
|
||||
para2Run.setItalic(true);
|
||||
|
||||
XWPFParagraph para3 = document.createParagraph();
|
||||
para3.setAlignment(ParagraphAlignment.LEFT);
|
||||
String string3 = convertTextFileToString(paragraph3);
|
||||
XWPFRun para3Run = para3.createRun();
|
||||
para3Run.setText(string3);
|
||||
|
||||
FileOutputStream out = new FileOutputStream(output);
|
||||
document.write(out);
|
||||
out.close();
|
||||
document.close();
|
||||
}
|
||||
|
||||
public String convertTextFileToString(String fileName) {
|
||||
try (Stream<String> stream = Files.lines(Paths.get(ClassLoader.getSystemResource(fileName).toURI()))) {
|
||||
return stream.collect(Collectors.joining(" "));
|
||||
} catch (IOException | URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 782 B |
@@ -0,0 +1 @@
|
||||
I published the first REST with Spring tutorials over four years ago, and after 300,000 readers and over a thousand personal questions over email, I am finally realizing that there is a huge education gap in the ecosystem.
|
||||
@@ -0,0 +1,2 @@
|
||||
I had to learn what makes a good API is the hard way, and I couldn’t find anything out there to help me speed things up.
|
||||
It took me 3 years, more than 10 production grade APIs built from scratch and a decent number of mistakes to get to a mature understanding of how an API should really be done well.
|
||||
@@ -0,0 +1,3 @@
|
||||
Sure, there were tutorials and random code samples out there, but nothing coherent.
|
||||
Nothing start to finish to act as a guide through the challenges of building a mature API with Spring.
|
||||
The educational gap between beginner and the API professional remains vast.
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.baeldung.poi.word;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFRun;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class WordTest {
|
||||
static WordDocument wordDocument;
|
||||
|
||||
@BeforeClass
|
||||
public static void generateMSWordFile() throws Exception {
|
||||
WordTest.wordDocument = new WordDocument();
|
||||
wordDocument.handleSimpleDoc();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenParsingOutputDocument_thenCorrect() throws Exception {
|
||||
Path msWordPath = Paths.get(WordDocument.output);
|
||||
XWPFDocument document = new XWPFDocument(Files.newInputStream(msWordPath));
|
||||
List<XWPFParagraph> paragraphs = document.getParagraphs();
|
||||
document.close();
|
||||
|
||||
XWPFParagraph title = paragraphs.get(0);
|
||||
XWPFRun titleRun = title.getRuns().get(0);
|
||||
assertEquals("Build Your REST API with Spring", title.getText());
|
||||
assertEquals("009933", titleRun.getColor());
|
||||
assertTrue(titleRun.isBold());
|
||||
assertEquals("Courier", titleRun.getFontFamily());
|
||||
assertEquals(20, titleRun.getFontSize());
|
||||
|
||||
assertEquals("from HTTP fundamentals to API Mastery", paragraphs.get(1).getText());
|
||||
assertEquals("What makes a good API?", paragraphs.get(3).getText());
|
||||
assertEquals(wordDocument.convertTextFileToString(WordDocument.paragraph1), paragraphs.get(4).getText());
|
||||
assertEquals(wordDocument.convertTextFileToString(WordDocument.paragraph2), paragraphs.get(5).getText());
|
||||
assertEquals(wordDocument.convertTextFileToString(WordDocument.paragraph3), paragraphs.get(6).getText());
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -121,12 +121,11 @@
|
||||
|
||||
<properties>
|
||||
<source.version>1.8</source.version>
|
||||
<aspectj.version>1.6.11</aspectj.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<aspectj.version>1.8.9</aspectj.version>
|
||||
<org.slf4j.version>1.7.21</org.slf4j.version>
|
||||
<logback.version>1.1.7</logback.version>
|
||||
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
|
||||
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
</properties>
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user