-
Notifications
You must be signed in to change notification settings - Fork 604
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JAXB Legacy behavior support test is added
- Loading branch information
1 parent
854ae75
commit d3274f0
Showing
5 changed files
with
154 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
73 changes: 73 additions & 0 deletions
73
...ws.jaxb_fat/test-applications/jaxbApp/src/jaxb/xmlnsform/servlet/JaxbSpecTestServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* | ||
*/ | ||
package jaxb.xmlnsform.servlet; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.xml.bind.JAXBContext; | ||
import javax.xml.bind.Unmarshaller; | ||
|
||
/** | ||
* | ||
*/ | ||
@WebServlet("/JaxbSpecTest") | ||
public class JaxbSpecTestServlet extends HttpServlet { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
doWorker(req, resp); | ||
} | ||
|
||
@Override | ||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
doWorker(req, resp); | ||
} | ||
|
||
private void doWorker(HttpServletRequest req, HttpServletResponse resp) { | ||
PrintWriter writer = null; | ||
try { | ||
writer = resp.getWriter(); | ||
File personXml = new File("Person.xml"); | ||
|
||
if (!personXml.exists()) { | ||
writer.write("XML not found"); | ||
return; | ||
} | ||
JAXBContext jaxbContextQualified = JAXBContext.newInstance(jaxb.xmlnsform.qualified.Person.class); | ||
Unmarshaller unmarshallerQualified = jaxbContextQualified.createUnmarshaller(); | ||
jaxb.xmlnsform.qualified.Person qualifiedPerson = (jaxb.xmlnsform.qualified.Person) unmarshallerQualified.unmarshal(personXml); | ||
writeNullStatus(writer, "qpwp", qualifiedPerson.getFirstNameWithPrefix()); // qpwp: Qualified Person With Prefix | ||
writeNullStatus(writer, "qpnp", qualifiedPerson.getLastNameWithOutPrefix()); // qpnp: Qualified Person No Prefix | ||
|
||
JAXBContext jaxbContextUnQualified = JAXBContext.newInstance(jaxb.xmlnsform.unqualified.Person.class); | ||
Unmarshaller unmarshallerUnQualified = jaxbContextUnQualified.createUnmarshaller(); | ||
jaxb.xmlnsform.unqualified.Person unQualifiedPerson = (jaxb.xmlnsform.unqualified.Person) unmarshallerUnQualified.unmarshal(personXml); | ||
writeNullStatus(writer, "upwp", unQualifiedPerson.getFirstNameWithPrefix()); // upwp: Unqualified Person With Prefix | ||
writeNullStatus(writer, "upnp", unQualifiedPerson.getLastNameWithOutPrefix()); // upnp: Unqualified Person No Prefix | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @param key key to mark which assertion it's related to | ||
* @param value value to test if it's null | ||
* @return | ||
*/ | ||
private void writeNullStatus(PrintWriter writer, String key, String value) { | ||
writer.write(key + (value == null ? ":null |" : ":value |")); | ||
} | ||
|
||
} |