@@ -203,6 +203,12 @@ public class RESTServiceTest {
203
203
204
204
private static final XmldbURI TEST_XML_DOC_WITH_XSLPI_URI = XmldbURI .create ("test-with-xslpi.xml" );
205
205
206
+ private static final String XML_WITH_XMLDECL =
207
+ "<?xml version=\" 1.1\" encoding=\" ISO-8859-1\" standalone=\" yes\" ?>\n " +
208
+ "<bookmap id=\" bookmap-2\" />" ;
209
+
210
+ private static final XmldbURI TEST_XMLDECL_COLLECTION_URI = XmldbURI .ROOT_COLLECTION_URI .append ("rest-test-xmldecl" );
211
+ private static final XmldbURI TEST_XML_DOC_WITH_XMLDECL_URI = XmldbURI .create ("test-with-xmldecl.xml" );
206
212
207
213
private static String credentials ;
208
214
private static String badCredentials ;
@@ -231,6 +237,10 @@ private static String getResourceWithDocTypeUri() {
231
237
return getServerUri () + TEST_DOCTYPE_COLLECTION_URI .append (TEST_XML_DOC_WITH_DOCTYPE_URI );
232
238
}
233
239
240
+ private static String getResourceWithXmlDeclUri () {
241
+ return getServerUri () + TEST_XMLDECL_COLLECTION_URI .append (TEST_XML_DOC_WITH_XMLDECL_URI );
242
+ }
243
+
234
244
/* About path components of URIs:
235
245
236
246
** reserved characters # http://tools.ietf.org/html/rfc3986#section-2.2
@@ -319,6 +329,11 @@ public static void setup() throws PermissionDeniedException, IOException, Trigge
319
329
broker .saveCollection (transaction , col );
320
330
}
321
331
332
+ try (final Collection col = broker .getOrCreateCollection (transaction , TEST_XMLDECL_COLLECTION_URI )) {
333
+ broker .storeDocument (transaction , TEST_XML_DOC_WITH_XMLDECL_URI , new StringInputSource (XML_WITH_XMLDECL ), MimeType .XML_TYPE , col );
334
+ broker .saveCollection (transaction , col );
335
+ }
336
+
322
337
transaction .commit ();
323
338
} catch (EXistException | SAXException | LockException e ) {
324
339
throw new RuntimeException (e );
@@ -1386,6 +1401,82 @@ public void getDocWithXslPi_twice() throws IOException {
1386
1401
getDocWithXslPi ();
1387
1402
}
1388
1403
1404
+ @ Test
1405
+ public void getXmlDeclDefault () throws IOException {
1406
+ final HttpURLConnection connect = getConnection (getResourceWithXmlDeclUri ());
1407
+ try {
1408
+ connect .setRequestMethod ("GET" );
1409
+ connect .connect ();
1410
+
1411
+ final int r = connect .getResponseCode ();
1412
+ assertEquals ("Server returned response code " + r , HttpStatus .OK_200 , r );
1413
+ String contentType = connect .getContentType ();
1414
+ final int semicolon = contentType .indexOf (';' );
1415
+ if (semicolon > 0 ) {
1416
+ contentType = contentType .substring (0 , semicolon ).trim ();
1417
+ }
1418
+ assertEquals ("Server returned content type " + contentType , "application/xml" , contentType );
1419
+
1420
+ final String response = readResponse (connect .getInputStream ());
1421
+
1422
+ assertEquals ("<bookmap id=\" bookmap-2\" />\r \n " , response );
1423
+
1424
+ } finally {
1425
+ connect .disconnect ();
1426
+ }
1427
+ }
1428
+
1429
+ @ Test
1430
+ public void getXmlDeclNo () throws IOException {
1431
+ final HttpURLConnection connect = getConnection (getResourceWithXmlDeclUri () + "?_omit-xml-declaration=no&_omit-original-xml-declaration=no" );
1432
+ try {
1433
+ connect .setRequestMethod ("GET" );
1434
+ connect .connect ();
1435
+
1436
+ final int r = connect .getResponseCode ();
1437
+ assertEquals ("Server returned response code " + r , HttpStatus .OK_200 , r );
1438
+ String contentType = connect .getContentType ();
1439
+ final int semicolon = contentType .indexOf (';' );
1440
+ if (semicolon > 0 ) {
1441
+ contentType = contentType .substring (0 , semicolon ).trim ();
1442
+ }
1443
+ assertEquals ("Server returned content type " + contentType , "application/xml" , contentType );
1444
+
1445
+ final String response = readResponse (connect .getInputStream ());
1446
+
1447
+ assertEquals ("<?xml version=\" 1.1\" encoding=\" ISO-8859-1\" standalone=\" yes\" ?>\r \n " +
1448
+ "<bookmap id=\" bookmap-2\" />\r \n " , response );
1449
+
1450
+ } finally {
1451
+ connect .disconnect ();
1452
+ }
1453
+ }
1454
+
1455
+ @ Test
1456
+ public void getXmlDeclYes () throws IOException {
1457
+ final HttpURLConnection connect = getConnection (getResourceWithXmlDeclUri () + "?_omit-xml-declaration=yes&_omit-original-xml-declaration=yes" );
1458
+ try {
1459
+ connect .setRequestMethod ("GET" );
1460
+ connect .connect ();
1461
+
1462
+ final int r = connect .getResponseCode ();
1463
+ assertEquals ("Server returned response code " + r , HttpStatus .OK_200 , r );
1464
+ String contentType = connect .getContentType ();
1465
+ final int semicolon = contentType .indexOf (';' );
1466
+ if (semicolon > 0 ) {
1467
+ contentType = contentType .substring (0 , semicolon ).trim ();
1468
+ }
1469
+ assertEquals ("Server returned content type " + contentType , "application/xml" , contentType );
1470
+
1471
+ final String response = readResponse (connect .getInputStream ());
1472
+
1473
+ assertEquals ("<bookmap id=\" bookmap-2\" />\r \n " , response );
1474
+
1475
+ } finally {
1476
+ connect .disconnect ();
1477
+ }
1478
+ }
1479
+
1389
1480
private void chmod (final String resourcePath , final String mode ) throws IOException {
1390
1481
final String uri = getCollectionUri () +"?_query=" + URLEncoder .encode (
1391
1482
"sm:chmod(xs:anyURI('" + resourcePath + "'), '" + mode + "')" ,
0 commit comments