From 5226c5f414eda725daaf8d2425d9e7b246f75cda Mon Sep 17 00:00:00 2001 From: Tuan Date: Sat, 24 Dec 2016 00:41:51 +0700 Subject: [PATCH] BAEL-406 (#902) * Change text/xml to application/xml * Revert "Change text/xml to application/xml" This reverts commit b61b82cd2a31831c43df1993d36997c762e21907. * Apache CXF Aegis data bindings * remove else condition * remove else condition * spring retry introduction * remove else condition * remove spring retry, format code * BAEL-315 Removing the unnecessary version on spring session. Renaming the module from spring-cloud-integration to spring-could-bootstrap * add unit test * BAEL-40: Add NDC and JBoss Logging to the demo application (#880) * Add NDC and JBoss Logging to the demo application * NDC for Log4j, Log4j2 and JBoss Logging * Simplify NDC example by making it a single operation instead of two * Make NDC example as RestController, Use JBoss Logging only as a logging bridge * Fix merge conflicts in pull request - log-mdc pom.xml updated * Simulated Annealing algorithm (#900) * @Async and Spring Security * @Async with SecurityContext propagated * Spring and @Async * Simulated Annealing algorithm * Simulated Annealing algorithm * Rebase * Rebase * create intelliJ formatter * fix intelliJ formatter * add unit test * BAEL-36 BAEL-282 Getting file size using Java and apache commons IO api. Also grep in Java (#890) * BAL-36 File size api in java and apache commons IO * BAEL-36 Getting file size using Java and commons IO api. * BAEL-282 Added support for grep functionality. * BAEL-282 Rename the text file extension. * maven fix and small formatting work * BAEL-35: Added test methods using Apache Commons Collections4 * Created README.md and added relevant articles (#901) * Added relevant articles * Added relevant articles * Added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Added relevant articles * Added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Added relevant articles * Created README.md and added relevant articles * Added relevant articles * Added relevant articles * Update README.md * Added relevant articles * Added relevant articles * Added relevant articles * Update README.md * Added relevant articles * Update README.md * Created README.md and added relevant articles * Added relevant articles * Added relevant articles * Added relevant articles * Added relevant articles * Created README.md and added relevant articles * Update README.md * Refactor EJBClient.java * BAEL-282 - Grep in Java after code review (#903) * BAEL-242 Package refactoring after code review for article Grep in Java * BAEL-282 Updated readme file * Update README.md * maven cleanup work * maven cleanup work * Pull Request for "A Guide to Rolling File Appenders" article. (#876) * First test with log4j rolling appenders * small fix * Log4j rolling appender * First set up with rolling file on log4j 2 * Added logback code. * log4j2 more detailed example * log4j2 more detailed example * Improved names and examples * Fixed configurations * improved configs * formatted * Final fix * fixed formatting * Formatting fix * Fix sample apps to avoid try / catch * Fix request to replace files * Fix end lines * maven work * init * cleanup work * cleanup work * Update README.md * set default timezone * Simulated Annnealing fixes (#907) * @Async and Spring Security * @Async with SecurityContext propagated * Spring and @Async * Simulated Annealing algorithm * Simulated Annealing algorithm * Rebase * Rebase * Nashorn (#896) * Simulated Annealing fix (#910) * @Async and Spring Security * @Async with SecurityContext propagated * Spring and @Async * Simulated Annealing algorithm * Simulated Annealing algorithm * Rebase * Rebase * SA further fixes * change tab to space in xml files and add equal, hashcode, toString using apache commons lang * BAEL-315 Adding test class for demonstrating features of Spring Session and Spring Cloud * add integration profile * add live profile * add integration profile * add integration profile * add integration profile * BAEL-127: Spring Security - @PreFilter and @PostFilter (#911) * BAEL-127: simple app with filters * removed data rest dependency, final adjustments * added first live test for the rest api * move filters code to new module * moved to root of module, create service layer, standard pom * added spring-security-core module to root pom * Modified code to reflect the code from the article * Merge changes from branch * BAEL-315 - skipping live test * adding missing modules to parent pom * Advanced Camel article (#905) * - changed test package name from org.baeldung to com.baeldung - streams are added where neccessary - format fixes * Adding Java config for Content Based File Router * Adding Java config for Content Based File Router * Code for Map (#909) * made changes to java reflection * removed redundant method makeSound in Animal abstract class * added project for play-framework article * added project for regex * changed regex project from own model to core-java * added project for routing in play * made changes to regex project * refactored code for REST API with Play project * refactored student store indexing to zero base * added unit tests, removed bad names * added NIO Selector project under core-java module * requested changes made * added project for nio2 * standardized exception based tests * fixed exception based tests * removed redundant files * added network interface project * used UUID other than timestamps * fixed network interface tests * removed filetest change * made changes to NIO2 FileTest names * added project for asyncronous channel apis * added project for NIO2 advanced filesystems APIS * merge conflicts * merged changes to asyncfiletest with future get API * removed while loops from async client and server * added project for java8 optional * fixed merge conflicts in spring-core * fixed optional * fixed optional * fixed asyncechotest * shifted optional to own package * made additional tests to demo filter API * added code for Map * change unit test package dir * minor maven cleanup * Reformat JaxbTest * Added demonstration of @JsonFormat and associated test. (#906) * remove duplicate test * rename tests * delete bool.xml file * remove jaxb * spring retry introduction * remove else condition * remove spring retry, format code --- jaxb/book.xml | 5 - jaxb/pom.xml | 321 ++++++++---------- .../src/main/java/com/baeldung/jaxb/Main.java | 41 --- .../java/com/baeldung/jaxb/test/JaxbTest.java | 35 +- jaxb/{ => src/test/resources}/sample_book.xml | 0 5 files changed, 169 insertions(+), 233 deletions(-) delete mode 100644 jaxb/book.xml delete mode 100644 jaxb/src/main/java/com/baeldung/jaxb/Main.java rename jaxb/{ => src/test/resources}/sample_book.xml (100%) diff --git a/jaxb/book.xml b/jaxb/book.xml deleted file mode 100644 index 605d531b16..0000000000 --- a/jaxb/book.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - Book1 - 2016-12-16T17:28:49.718Z - diff --git a/jaxb/pom.xml b/jaxb/pom.xml index 115a632d7b..b636a4dc82 100644 --- a/jaxb/pom.xml +++ b/jaxb/pom.xml @@ -1,188 +1,167 @@ - 4.0.0 - com.baeldung - jaxb - 0.0.1-SNAPSHOT - jaxb + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + com.baeldung + jaxb + 0.0.1-SNAPSHOT + jaxb - - - org.glassfish.jaxb - jaxb-runtime - ${jaxb.version} - + + + org.glassfish.jaxb + jaxb-runtime + ${jaxb.version} + - - org.glassfish.jaxb - jaxb-core - ${jaxb.version} - + + org.glassfish.jaxb + jaxb-core + ${jaxb.version} + - - - com.sun.istack - istack-commons-runtime - 3.0.2 - + + + com.sun.istack + istack-commons-runtime + 3.0.2 + - - commons-io - commons-io - 2.5 - + + commons-io + commons-io + 2.5 + - - org.slf4j - slf4j-api - ${org.slf4j.version} - + + org.slf4j + slf4j-api + ${org.slf4j.version} + - - ch.qos.logback - logback-classic - ${logback.version} - + + ch.qos.logback + logback-classic + ${logback.version} + - - ch.qos.logback - logback-core - ${logback.version} - - - - junit - junit - ${junit.version} - - - - org.apache.commons - commons-lang3 - 3.5 - - + + ch.qos.logback + logback-core + ${logback.version} + - - jaxb - - - src/main/resources - true - - + + junit + junit + ${junit.version} + - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - org.codehaus.mojo - jaxb2-maven-plugin - [${jaxb2-maven-plugin.version},) - - schemagen - xjc - - - - - - - - - - - - + + org.apache.commons + commons-lang3 + 3.5 + + - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - + + jaxb + + + src/main/resources + true + + - - - org.codehaus.mojo - jaxb2-maven-plugin - ${jaxb2-maven-plugin.version} - - - xjc - - xjc - - - - - - src/main/resources/global.xjb - - - src/main/resources/user.xsd - - ${basedir}/src/main/java - false - - + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.codehaus.mojo + jaxb2-maven-plugin + [${jaxb2-maven-plugin.version},) + + schemagen + xjc + + + + + + + + + + + + - - - - + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + 1.8 + 1.8 + + - - - 2.2.11 + + + org.codehaus.mojo + jaxb2-maven-plugin + ${jaxb2-maven-plugin.version} + + + xjc + + xjc + + + + + + src/main/resources/global.xjb + + + src/main/resources/user.xsd + + ${basedir}/src/main/java + false + + - - 1.7.21 - 1.1.7 + + + + - - 3.5.1 - 2.3 - 4.12 - + + + 2.2.11 - + + 1.7.21 + 1.1.7 + + + 3.5.1 + 2.3 + 4.12 + + + \ No newline at end of file diff --git a/jaxb/src/main/java/com/baeldung/jaxb/Main.java b/jaxb/src/main/java/com/baeldung/jaxb/Main.java deleted file mode 100644 index 46adfb3c60..0000000000 --- a/jaxb/src/main/java/com/baeldung/jaxb/Main.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.jaxb; - -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.util.Date; -import java.util.TimeZone; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; - -public class Main { - public static void marshal() throws JAXBException, IOException { - Book book = new Book(); - book.setId(1L); - book.setName("Book1"); - book.setAuthor("Author1"); - TimeZone.setDefault(TimeZone.getTimeZone("UTC")); - book.setDate(new Date(1481909329718L)); - - JAXBContext context = JAXBContext.newInstance(Book.class); - Marshaller marshaller = context.createMarshaller(); - marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); - marshaller.marshal(book, new File("./book.xml")); - } - - public static Book unMashal() throws JAXBException, IOException { - JAXBContext context = JAXBContext.newInstance(Book.class); - Unmarshaller unmarshaller = context.createUnmarshaller(); - Book book = (Book) unmarshaller.unmarshal(new FileReader("./book.xml")); - return book; - } - - public static void main(String[] args) throws JAXBException, IOException { - marshal(); - Book book = unMashal(); - System.out.println(book.toString()); - } -} diff --git a/jaxb/src/test/java/com/baeldung/jaxb/test/JaxbTest.java b/jaxb/src/test/java/com/baeldung/jaxb/test/JaxbTest.java index 10febabacd..7721490de8 100644 --- a/jaxb/src/test/java/com/baeldung/jaxb/test/JaxbTest.java +++ b/jaxb/src/test/java/com/baeldung/jaxb/test/JaxbTest.java @@ -1,6 +1,16 @@ package com.baeldung.jaxb.test; -import com.baeldung.jaxb.Book; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.Date; +import java.util.TimeZone; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; + import org.apache.commons.io.FileUtils; import org.junit.Assert; import org.junit.Before; @@ -8,15 +18,7 @@ import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.util.Date; -import java.util.TimeZone; +import com.baeldung.jaxb.Book; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class JaxbTest { @@ -37,18 +39,19 @@ public class JaxbTest { public void marshal() throws JAXBException, IOException { Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); - marshaller.marshal(book, new File("./book.xml")); - String sampleBookXML = FileUtils.readFileToString(new File("./sample_book.xml"), "UTF-8"); - String marshallerBookXML = FileUtils.readFileToString(new File("./book.xml"), "UTF-8"); - + marshaller.marshal(book, new File(this.getClass().getResource("/").getPath() + "/book.xml")); + File sampleBookFile = new File(this.getClass().getResource("/sample_book.xml").getFile()); + File bookFile = new File(this.getClass().getResource("/book.xml").getFile()); + String sampleBookXML = FileUtils.readFileToString(sampleBookFile, "UTF-8"); + String marshallerBookXML = FileUtils.readFileToString(bookFile, "UTF-8"); Assert.assertEquals(sampleBookXML, marshallerBookXML); } @Test public void unMashal() throws JAXBException, IOException { Unmarshaller unmarshaller = context.createUnmarshaller(); - Book unMarshallerbook = (Book) unmarshaller.unmarshal(new FileReader("./book.xml")); - + String bookFile = this.getClass().getResource("/book.xml").getFile(); + Book unMarshallerbook = (Book) unmarshaller.unmarshal(new FileReader(bookFile)); Assert.assertEquals(book, unMarshallerbook); } } diff --git a/jaxb/sample_book.xml b/jaxb/src/test/resources/sample_book.xml similarity index 100% rename from jaxb/sample_book.xml rename to jaxb/src/test/resources/sample_book.xml