use of javax.xml.parsers.DocumentBuilderFactory in project jersey by jersey.
the class ExtendedWadlWebappOsgiTest method checkWadl.
private void checkWadl(String wadl, URI baseUri) throws Exception {
DocumentBuilderFactory bf = DocumentBuilderFactory.newInstance();
bf.setNamespaceAware(true);
bf.setValidating(false);
DocumentBuilder b = bf.newDocumentBuilder();
Document document = b.parse(new ByteArrayInputStream(wadl.getBytes(Charset.forName("UTF-8"))));
XPath xp = XPathFactory.newInstance().newXPath();
xp.setNamespaceContext(new SimpleNamespaceResolver("wadl", "http://wadl.dev.java.net/2009/02"));
String val = (String) xp.evaluate("/wadl:application/wadl:resources/@base", document, XPathConstants.STRING);
assertEquals(baseUri.toString(), val.endsWith("/") ? val.substring(0, val.length() - 1) : val);
val = (String) xp.evaluate("count(//wadl:resource)", document, XPathConstants.STRING);
assertEquals("Unexpected number of resource elements.", val, "4");
val = (String) xp.evaluate("count(//wadl:resource[@path='items'])", document, XPathConstants.STRING);
assertEquals("Unexpected number of resource elements with 'items' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='{id}'])", document, XPathConstants.STRING);
assertEquals("Unexpected number of resource elements with '{id}' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='try-hard'])", document, XPathConstants.STRING);
assertEquals("Unexpected number of resource elements with 'try-hard' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='value/{value}'])", document, XPathConstants.STRING);
assertEquals("Unexpected number of resource elements with 'value/{value}' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='{id}']/wadl:method)", document, XPathConstants.STRING);
assertEquals("Unexpected number of methods in resource element with '{id}' path.", "2", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='{id}']/wadl:method[@id='getItem']" + "/wadl:doc[contains(., 'Typically returns the item if it exists.')])", document, XPathConstants.STRING);
assertEquals("Unexpected documentation of getItem resource method at '{id}' path", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='try-hard']/wadl:method)", document, XPathConstants.STRING);
assertEquals("Unexpected number of methods in resource element with 'try-hard' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='try-hard']/wadl:method[@id='getItem']" + "/wadl:doc[contains(., 'Tries hard to return the item if it exists.')])", document, XPathConstants.STRING);
assertEquals("Unexpected documentation of getItem resource method at 'try-hard' path", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='items']/wadl:method)", document, XPathConstants.STRING);
assertEquals("Unexpected number of methods in resource element with 'items' path.", "4", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='value/{value}']/wadl:method)", document, XPathConstants.STRING);
assertEquals("Unexpected number of methods in resource element with 'value/{value}' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:application/wadl:doc)", document, XPathConstants.STRING);
assertEquals("Unexpected number of doc elements in application element.", "3", val);
}
use of javax.xml.parsers.DocumentBuilderFactory in project jersey by jersey.
the class ExtendedWadlWebappTest method checkWadl.
private void checkWadl(String wadl, URI baseUri) throws Exception {
DocumentBuilderFactory bf = DocumentBuilderFactory.newInstance();
bf.setNamespaceAware(true);
bf.setValidating(false);
// if (!SaxHelper.isXdkDocumentBuilderFactory(bf)) {
// bf.setXIncludeAware(false);
// }
DocumentBuilder b = bf.newDocumentBuilder();
Document document = b.parse(new ByteArrayInputStream(wadl.getBytes(Charset.forName("UTF-8"))));
XPath xp = XPathFactory.newInstance().newXPath();
xp.setNamespaceContext(new SimpleNamespaceResolver("wadl", "http://wadl.dev.java.net/2009/02"));
String val = (String) xp.evaluate("/wadl:application/wadl:resources/@base", document, XPathConstants.STRING);
assertEquals(baseUri.toString(), val.endsWith("/") ? val.substring(0, val.length() - 1) : val);
val = (String) xp.evaluate("count(//wadl:resource)", document, XPathConstants.STRING);
assertEquals("Unexpected number of resource elements.", val, "4");
val = (String) xp.evaluate("count(//wadl:resource[@path='items'])", document, XPathConstants.STRING);
assertEquals("Unexpected number of resource elements with 'items' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='{id}'])", document, XPathConstants.STRING);
assertEquals("Unexpected number of resource elements with '{id}' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='try-hard'])", document, XPathConstants.STRING);
assertEquals("Unexpected number of resource elements with 'try-hard' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='value/{value}'])", document, XPathConstants.STRING);
assertEquals("Unexpected number of resource elements with 'value/{value}' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='{id}']/wadl:method)", document, XPathConstants.STRING);
assertEquals("Unexpected number of methods in resource element with '{id}' path.", "2", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='{id}']/wadl:method[@id='getItem']" + "/wadl:doc[contains(., 'Typically returns the item if it exists.')])", document, XPathConstants.STRING);
assertEquals("Unexpected documentation of getItem resource method at '{id}' path", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='try-hard']/wadl:method)", document, XPathConstants.STRING);
assertEquals("Unexpected number of methods in resource element with 'try-hard' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='try-hard']/wadl:method[@id='getItem']" + "/wadl:doc[contains(., 'Tries hard to return the item if it exists.')])", document, XPathConstants.STRING);
assertEquals("Unexpected documentation of getItem resource method at 'try-hard' path", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='items']/wadl:method)", document, XPathConstants.STRING);
assertEquals("Unexpected number of methods in resource element with 'items' path.", "4", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='value/{value}']/wadl:method)", document, XPathConstants.STRING);
assertEquals("Unexpected number of methods in resource element with 'value/{value}' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:application/wadl:doc)", document, XPathConstants.STRING);
assertEquals("Unexpected number of doc elements in application element.", "3", val);
}
use of javax.xml.parsers.DocumentBuilderFactory in project quickstarts by jboss-switchyard.
the class TypeTransformationTest method loadXML.
private Document loadXML(String path) throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
return db.parse(getClass().getClassLoader().getResourceAsStream(path));
}
use of javax.xml.parsers.DocumentBuilderFactory in project jersey by jersey.
the class DocumentBuilderFactoryInjectionProvider method get.
@Override
public DocumentBuilderFactory get() {
DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
f.setNamespaceAware(true);
if (!isXmlSecurityDisabled()) {
f.setExpandEntityReferences(false);
}
return f;
}
use of javax.xml.parsers.DocumentBuilderFactory in project jersey by jersey.
the class MultiPartWebAppTest method testApplicationWadl.
@Test
public void testApplicationWadl() throws Exception {
final WebTarget target = target().path("application.wadl");
final Response response = target.request().get();
assertEquals(200, response.getStatus());
final File tmpFile = response.readEntity(File.class);
final DocumentBuilderFactory bf = DocumentBuilderFactory.newInstance();
bf.setNamespaceAware(true);
bf.setValidating(false);
if (!SaxHelper.isXdkDocumentBuilderFactory(bf)) {
bf.setXIncludeAware(false);
}
final DocumentBuilder b = bf.newDocumentBuilder();
final Document d = b.parse(tmpFile);
final XPath xp = XPathFactory.newInstance().newXPath();
xp.setNamespaceContext(new SimpleNamespaceResolver("wadl", "http://wadl.dev.java.net/2009/02"));
String val = (String) xp.evaluate("//wadl:resource[@path='part']/wadl:method[@name='POST']/wadl:request/wadl:representation/@mediaType", d, XPathConstants.STRING);
assertEquals("multipart/form-data", val);
}
Aggregations