|
31 | 31 | import java.net.HttpURLConnection;
|
32 | 32 | import java.net.URL;
|
33 | 33 | import java.net.URLEncoder;
|
| 34 | +import java.util.Optional; |
34 | 35 | import javax.xml.parsers.ParserConfigurationException;
|
35 | 36 |
|
36 | 37 | import com.googlecode.junittoolbox.ParallelRunner;
|
37 | 38 | import org.apache.commons.codec.binary.Base64;
|
38 | 39 | import org.eclipse.jetty.http.HttpStatus;
|
| 40 | +import org.exist.EXistException; |
39 | 41 | import org.exist.Namespaces;
|
| 42 | +import org.exist.collections.Collection; |
| 43 | +import org.exist.collections.triggers.TriggerException; |
40 | 44 | import org.exist.dom.memtree.SAXAdapter;
|
| 45 | +import org.exist.dom.persistent.LockedDocument; |
| 46 | +import org.exist.security.PermissionDeniedException; |
| 47 | +import org.exist.storage.BrokerPool; |
| 48 | +import org.exist.storage.DBBroker; |
| 49 | +import org.exist.storage.lock.Lock; |
| 50 | +import org.exist.storage.txn.Txn; |
| 51 | +import org.exist.test.ExistEmbeddedServer; |
41 | 52 | import org.exist.test.ExistWebServer;
|
| 53 | +import org.exist.test.TestConstants; |
42 | 54 | import org.exist.util.ExistSAXParserFactory;
|
| 55 | +import org.exist.util.LockException; |
| 56 | +import org.exist.util.MimeType; |
| 57 | +import org.exist.util.StringInputSource; |
43 | 58 | import org.exist.xmldb.XmldbURI;
|
44 | 59 | import org.junit.runner.RunWith;
|
45 | 60 | import org.xml.sax.InputSource;
|
@@ -237,11 +252,31 @@ private static String getResourceUriPlus() {
|
237 | 252 | return getServerUri() + XmldbURI.ROOT_COLLECTION + "/test//../test/A-Za-z0-9_~!$&'()*+,;=@%20%23%25%27%2F%3F%5B%5Däöü.xml";
|
238 | 253 | }
|
239 | 254 |
|
| 255 | + @ClassRule |
| 256 | + public static final ExistEmbeddedServer existEmbeddedServer = new ExistEmbeddedServer(true, true); |
240 | 257 |
|
241 | 258 | @BeforeClass
|
242 |
| - public static void createCredentials() { |
| 259 | + public static void setup() throws PermissionDeniedException, IOException, TriggerException { |
243 | 260 | credentials = Base64.encodeBase64String("admin:".getBytes(UTF_8));
|
244 | 261 | badCredentials = Base64.encodeBase64String("johndoe:this pw should fail".getBytes(UTF_8));
|
| 262 | + |
| 263 | + //TODO create collection /db/AéB and store doc AéB.xml |
| 264 | + final XmldbURI TEST_XML_DOC_URI = XmldbURI.create("AéB.xml"); |
| 265 | + final XmldbURI TEST_COLLECTION_URI = XmldbURI.create("/db/AéB"); |
| 266 | + final String TEST_XML_DOC = "<foo/>"; |
| 267 | + |
| 268 | + final BrokerPool pool = existEmbeddedServer.getBrokerPool(); |
| 269 | + try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject())); |
| 270 | + final Txn transaction = pool.getTransactionManager().beginTransaction()) { |
| 271 | + try (final Collection col = broker.getOrCreateCollection(transaction, TEST_COLLECTION_URI)) { |
| 272 | + broker.storeDocument(transaction, TEST_XML_DOC_URI, new StringInputSource(TEST_XML_DOC), MimeType.XML_TYPE, col); |
| 273 | + broker.saveCollection(transaction, col); |
| 274 | + } |
| 275 | + |
| 276 | + transaction.commit(); |
| 277 | + } catch (EXistException | SAXException | LockException e) { |
| 278 | + throw new RuntimeException(e); |
| 279 | + } |
245 | 280 | }
|
246 | 281 |
|
247 | 282 | @Test
|
@@ -1036,6 +1071,33 @@ public void execSetUidQueryWithBearerAuth() throws IOException {
|
1036 | 1071 | }
|
1037 | 1072 | }
|
1038 | 1073 |
|
| 1074 | + //test rest server ability to handle encoded characters |
| 1075 | + @Test |
| 1076 | + public void doGetEncodedPath() throws IOException { |
| 1077 | + String DOC_URI = getServerUri() + XmldbURI.ROOT_COLLECTION + "/AéB/AéB.xml"; |
| 1078 | + final HttpURLConnection connect = getConnection(DOC_URI); |
| 1079 | + try { |
| 1080 | + connect.setRequestMethod("GET"); |
| 1081 | + connect.connect(); |
| 1082 | + |
| 1083 | + final int r = connect.getResponseCode(); |
| 1084 | + assertEquals("Server returned response code " + r, HttpStatus.OK_200, r); |
| 1085 | + String contentType = connect.getContentType(); |
| 1086 | + final int semicolon = contentType.indexOf(';'); |
| 1087 | + if (semicolon > 0) { |
| 1088 | + contentType = contentType.substring(0, semicolon).trim(); |
| 1089 | + } |
| 1090 | + assertEquals("Server returned content type " + contentType, "application/xml", contentType); |
| 1091 | + |
| 1092 | + String response = readResponse(connect.getInputStream()); |
| 1093 | + |
| 1094 | + //readResponse is appending \r\n to each line that's why its added the expected content |
| 1095 | + assertEquals("Server returned document content " + response,"<foo/>\r\n",response); |
| 1096 | + } finally { |
| 1097 | + connect.disconnect(); |
| 1098 | + } |
| 1099 | + } |
| 1100 | + |
1039 | 1101 | private void chmod(final String resourcePath, final String mode) throws IOException {
|
1040 | 1102 | final String uri = getCollectionUri() +"?_query=" + URLEncoder.encode(
|
1041 | 1103 | "sm:chmod(xs:anyURI('" + resourcePath + "'), '" + mode + "')",
|
|
0 commit comments