From 6671f13cf19dcef5bd344fc4c059852020a9cdb3 Mon Sep 17 00:00:00 2001 From: codeforkjeff Date: Fri, 21 Feb 2025 21:24:32 -0800 Subject: [PATCH] VIAF now requires the Accept http header instead of query parameter --- .../java/com/codefork/refine/viaf/VIAF.java | 4 +++- .../controllers/VIAFControllerTest.java | 22 +++++++++---------- .../controllers/VIAFProxyControllerTest.java | 8 +++---- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/codefork/refine/viaf/VIAF.java b/src/main/java/com/codefork/refine/viaf/VIAF.java index e949d01..664dc24 100644 --- a/src/main/java/com/codefork/refine/viaf/VIAF.java +++ b/src/main/java/com/codefork/refine/viaf/VIAF.java @@ -131,10 +131,12 @@ public List search(SearchQuery query) throws Exception { return Collections.emptyList(); } - String url = String.format("https://www.viaf.org/viaf/search?query=%s&sortKeys=holdingscount&maximumRecords=%s&httpAccept=application/xml", + String url = String.format("https://www.viaf.org/viaf/search?query=%s&sortKeys=holdingscount&maximumRecords=%s", UriUtils.encodeQueryParam(cql, "UTF-8"), query.getLimit()); HttpURLConnection conn = getConnectionFactory().createConnection(url); + conn.setRequestProperty("Accept", "application/xml"); + InputStream response = conn.getInputStream(); SAXParser parser = spf.newSAXParser(); diff --git a/src/test/java/com/codefork/refine/controllers/VIAFControllerTest.java b/src/test/java/com/codefork/refine/controllers/VIAFControllerTest.java index fca577f..6afd93e 100644 --- a/src/test/java/com/codefork/refine/controllers/VIAFControllerTest.java +++ b/src/test/java/com/codefork/refine/controllers/VIAFControllerTest.java @@ -89,10 +89,10 @@ public void testServiceMetadata() throws Exception { @Test public void testSearchMultiple() throws Exception { mockConnectionFactoryHelper.expect(connectionFactory, - "https://www.viaf.org/viaf/search?query=local.personalNames%20all%20%22wittgenstein%22&sortKeys=holdingscount&maximumRecords=3&httpAccept=application/xml", + "https://www.viaf.org/viaf/search?query=local.personalNames%20all%20%22wittgenstein%22&sortKeys=holdingscount&maximumRecords=3", "/wittgenstein_personalnames.xml"); mockConnectionFactoryHelper.expect(connectionFactory, - "https://www.viaf.org/viaf/search?query=local.personalNames%20all%20%22shakespeare%22&sortKeys=holdingscount&maximumRecords=3&httpAccept=application/xml", + "https://www.viaf.org/viaf/search?query=local.personalNames%20all%20%22shakespeare%22&sortKeys=holdingscount&maximumRecords=3", "/shakespeare.xml"); String json = "{\"q0\":{\"query\": \"shakespeare\",\"type\":\"/people/person\",\"type_strict\":\"should\"},\"q1\":{\"query\":\"wittgenstein\",\"type\":\"/people/person\",\"type_strict\":\"should\"}}"; @@ -136,7 +136,7 @@ public JsonNode doSearchSingle(String queryValue) throws Exception { @Test public void testSearchSingleWithText() throws Exception { mockConnectionFactoryHelper.expect(connectionFactory, - "https://www.viaf.org/viaf/search?query=local.mainHeadingEl%20all%20%22wittgenstein%22&sortKeys=holdingscount&maximumRecords=3&httpAccept=application/xml", + "https://www.viaf.org/viaf/search?query=local.mainHeadingEl%20all%20%22wittgenstein%22&sortKeys=holdingscount&maximumRecords=3", "/wittgenstein.xml"); JsonNode root = doSearchSingle("wittgenstein"); @@ -171,7 +171,7 @@ public void testSearchSingleWithText() throws Exception { public void testSearchSingleWithJson() throws Exception { mockConnectionFactoryHelper.expect(connectionFactory, - "https://www.viaf.org/viaf/search?query=local.personalNames%20all%20%22wittgenstein%22&sortKeys=holdingscount&maximumRecords=3&httpAccept=application/xml", + "https://www.viaf.org/viaf/search?query=local.personalNames%20all%20%22wittgenstein%22&sortKeys=holdingscount&maximumRecords=3", "/wittgenstein_personalnames.xml"); String json = "{\"query\": \"wittgenstein\",\"type\":\"/people/person\",\"type_strict\":\"should\"}"; @@ -207,7 +207,7 @@ public void testSearchSingleWithJson() throws Exception { public void testSearchPersonalName() throws Exception { mockConnectionFactoryHelper.expect(connectionFactory, - "https://www.viaf.org/viaf/search?query=local.personalNames%20all%20%22wittgenstein%22&sortKeys=holdingscount&maximumRecords=3&httpAccept=application/xml", + "https://www.viaf.org/viaf/search?query=local.personalNames%20all%20%22wittgenstein%22&sortKeys=holdingscount&maximumRecords=3", "/wittgenstein_personalnames.xml"); String json = "{\"q0\":{\"query\": \"wittgenstein\",\"type\":\"/people/person\",\"type_strict\":\"should\"}}"; @@ -249,7 +249,7 @@ public void testSearchNoParticularType() throws Exception { // This is when you get when you choose "Reconcile against no particular type" in OpenRefine mockConnectionFactoryHelper.expect(connectionFactory, - "https://www.viaf.org/viaf/search?query=local.mainHeadingEl%20all%20%22steinbeck%22&sortKeys=holdingscount&maximumRecords=3&httpAccept=application/xml", + "https://www.viaf.org/viaf/search?query=local.mainHeadingEl%20all%20%22steinbeck%22&sortKeys=holdingscount&maximumRecords=3", "/steinbeck_no_type.xml"); String json = "{\"q0\":{\"query\": \"steinbeck\",\"type_strict\":\"should\"}}"; @@ -291,7 +291,7 @@ public void testSearchWithSource() throws Exception { // Also chose "Reconcile against no particular type" for this one mockConnectionFactoryHelper.expect(connectionFactory, - "https://www.viaf.org/viaf/search?query=local.mainHeadingEl%20all%20%22nabokov%22%20and%20local.sources%20%3D%20%22nsk%22&sortKeys=holdingscount&maximumRecords=3&httpAccept=application/xml", + "https://www.viaf.org/viaf/search?query=local.mainHeadingEl%20all%20%22nabokov%22%20and%20local.sources%20%3D%20%22nsk%22&sortKeys=holdingscount&maximumRecords=3", "/nabokov_nsk.xml"); String json = "{\"q0\":{\"query\": \"nabokov\",\"type_strict\":\"should\"}}"; @@ -332,7 +332,7 @@ public void testSearchWithSource() throws Exception { public void testSearchWithExactMatch() throws Exception { mockConnectionFactoryHelper.expect(connectionFactory, - "https://www.viaf.org/viaf/search?query=local.personalNames%20all%20%22Shakespeare,%20William,%201564-1616.%22&sortKeys=holdingscount&maximumRecords=3&httpAccept=application/xml", + "https://www.viaf.org/viaf/search?query=local.personalNames%20all%20%22Shakespeare,%20William,%201564-1616.%22&sortKeys=holdingscount&maximumRecords=3", "/shakespeare_exact.xml"); String json = "{\"q0\":{\"query\": \"Shakespeare, William, 1564-1616.\",\"type\":\"/people/person\",\"type_strict\":\"should\"}}"; @@ -373,7 +373,7 @@ public void testSearchWithExactMatch() throws Exception { public void testSearchWithNoResults() throws Exception { mockConnectionFactoryHelper.expect(connectionFactory, - "https://www.viaf.org/viaf/search?query=local.mainHeadingEl%20all%20%22ncjecerence%22&sortKeys=holdingscount&maximumRecords=3&httpAccept=application/xml", + "https://www.viaf.org/viaf/search?query=local.mainHeadingEl%20all%20%22ncjecerence%22&sortKeys=holdingscount&maximumRecords=3", "/nonsense.xml"); String json = "{\"q0\":{\"query\": \"ncjecerence\",\"type_strict\":\"should\"}}"; @@ -393,7 +393,7 @@ public void testSearchWithNoResults() throws Exception { public void testCache() throws Exception { mockConnectionFactoryHelper.expect(connectionFactory, - "https://www.viaf.org/viaf/search?query=local.personalNames%20all%20%22Shakespeare,%20William,%201564-1616.%22&sortKeys=holdingscount&maximumRecords=3&httpAccept=application/xml", + "https://www.viaf.org/viaf/search?query=local.personalNames%20all%20%22Shakespeare,%20William,%201564-1616.%22&sortKeys=holdingscount&maximumRecords=3", "/shakespeare_exact.xml"); String json = "{\"q0\":{\"query\": \"Shakespeare, William, 1564-1616.\",\"type\":\"/people/person\",\"type_strict\":\"should\"}}"; @@ -421,7 +421,7 @@ public void testCache() throws Exception { @Test public void testExpireCache() throws Exception { mockConnectionFactoryHelper.expect(connectionFactory, - "https://www.viaf.org/viaf/search?query=local.personalNames%20all%20%22Shakespeare,%20William,%201564-1616.%22&sortKeys=holdingscount&maximumRecords=3&httpAccept=application/xml", + "https://www.viaf.org/viaf/search?query=local.personalNames%20all%20%22Shakespeare,%20William,%201564-1616.%22&sortKeys=holdingscount&maximumRecords=3", "/shakespeare_exact.xml", 2); String json = "{\"q0\":{\"query\": \"Shakespeare, William, 1564-1616.\",\"type\":\"/people/person\",\"type_strict\":\"should\"}}"; diff --git a/src/test/java/com/codefork/refine/controllers/VIAFProxyControllerTest.java b/src/test/java/com/codefork/refine/controllers/VIAFProxyControllerTest.java index f19ff35..503f43b 100644 --- a/src/test/java/com/codefork/refine/controllers/VIAFProxyControllerTest.java +++ b/src/test/java/com/codefork/refine/controllers/VIAFProxyControllerTest.java @@ -48,7 +48,7 @@ public void testProxyMetaData() throws Exception { public void testSearchProxyModeLC() throws Exception { mockConnectionFactoryHelper.expect(connectionFactory, - "https://www.viaf.org/viaf/search?query=local.personalNames%20all%20%22Shakespeare,%20William,%201564-1616.%22%20and%20local.sources%20%3D%20%22lc%22&sortKeys=holdingscount&maximumRecords=3&httpAccept=application/xml", + "https://www.viaf.org/viaf/search?query=local.personalNames%20all%20%22Shakespeare,%20William,%201564-1616.%22%20and%20local.sources%20%3D%20%22lc%22&sortKeys=holdingscount&maximumRecords=3", "/shakespeare_lc.xml"); String json = "{\"q0\":{\"query\": \"Shakespeare, William, 1564-1616.\",\"type\":\"/people/person\",\"type_strict\":\"should\"}}"; @@ -90,7 +90,7 @@ public void testSearchProxyModeLC() throws Exception { public void testSearchProxyModeBNF() throws Exception { mockConnectionFactoryHelper.expect(connectionFactory, - "https://www.viaf.org/viaf/search?query=local.personalNames%20all%20%22Shakespeare,%20William,%201564-1616.%22%20and%20local.sources%20%3D%20%22bnf%22&sortKeys=holdingscount&maximumRecords=3&httpAccept=application/xml", + "https://www.viaf.org/viaf/search?query=local.personalNames%20all%20%22Shakespeare,%20William,%201564-1616.%22%20and%20local.sources%20%3D%20%22bnf%22&sortKeys=holdingscount&maximumRecords=3", "/shakespeare_bnf.xml"); String json = "{\"q0\":{\"query\": \"Shakespeare, William, 1564-1616.\",\"type\":\"/people/person\",\"type_strict\":\"should\"}}"; @@ -132,7 +132,7 @@ public void testSearchProxyModeBNF() throws Exception { public void testSearchProxyModeBNFMissingID() throws Exception { mockConnectionFactoryHelper.expect(connectionFactory, - "https://www.viaf.org/viaf/search?query=local.personalNames%20all%20%22Jean-Fran%C3%A7ois%20Alexandre%201804%201874%22%20and%20local.sources%20%3D%20%22bnf%22&sortKeys=holdingscount&maximumRecords=3&httpAccept=application/xml", + "https://www.viaf.org/viaf/search?query=local.personalNames%20all%20%22Jean-Fran%C3%A7ois%20Alexandre%201804%201874%22%20and%20local.sources%20%3D%20%22bnf%22&sortKeys=holdingscount&maximumRecords=3", "/alexandre.xml"); String json = "{\"q0\":{\"query\": \"Jean-François Alexandre 1804 1874\",\"type\":\"/people/person\",\"type_strict\":\"should\"}}"; @@ -175,7 +175,7 @@ public void testSearchProxyModeBNFMissingID() throws Exception { public void testSearchProxyModeDNB() throws Exception { mockConnectionFactoryHelper.expect(connectionFactory, - "https://www.viaf.org/viaf/search?query=local.personalNames%20all%20%22hegel%22%20and%20local.sources%20%3D%20%22dnb%22&sortKeys=holdingscount&maximumRecords=3&httpAccept=application/xml", + "https://www.viaf.org/viaf/search?query=local.personalNames%20all%20%22hegel%22%20and%20local.sources%20%3D%20%22dnb%22&sortKeys=holdingscount&maximumRecords=3", "/shakespeare_dnb.xml"); String json = "{\"q0\":{\"query\": \"hegel\",\"type\":\"/people/person\",\"type_strict\":\"should\"}}";