Skip to content

Commit 6f0251f

Browse files
committed
fix #582 - handle gracefully a null failure.getMessageCode()
1 parent 94b1d50 commit 6f0251f

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/main/java/com/marklogic/client/impl/JerseyServices.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4268,7 +4268,7 @@ private void checkStatus(ClientResponse response,
42684268
+ " " + entityType + " at " + path,
42694269
failure);
42704270
}
4271-
if (failure.getMessageCode().equals("RESTAPI-CONTENTNOVERSION")) {
4271+
if ("RESTAPI-CONTENTNOVERSION".equals(failure.getMessageCode())) {
42724272
throw new FailedRequestException("Content version required to " +
42734273
operation + " " + entityType + " at " + path, failure);
42744274
} else if (status == ClientResponse.Status.FORBIDDEN) {

src/test/java/com/marklogic/client/test/EvalTest.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import static org.junit.Assert.assertArrayEquals;
1919
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertTrue;
21+
import static org.junit.Assert.fail;
2022

2123
import java.io.IOException;
2224
import java.math.BigInteger;
@@ -44,6 +46,7 @@
4446
import com.marklogic.client.DatabaseClient;
4547
import com.marklogic.client.DatabaseClientFactory;
4648
import com.marklogic.client.DatabaseClientFactory.Authentication;
49+
import com.marklogic.client.FailedRequestException;
4750
import com.marklogic.client.Transaction;
4851
import com.marklogic.client.admin.ExtensionLibrariesManager;
4952
import com.marklogic.client.document.DocumentWriteSet;
@@ -67,11 +70,11 @@
6770
public class EvalTest {
6871
private static GregorianCalendar septFirst = new GregorianCalendar(TimeZone.getTimeZone("CET"));
6972
private static ExtensionLibrariesManager libMgr;
73+
private static DatabaseClient adminClient = Common.newAdminClient();
7074

7175
@BeforeClass
7276
public static void beforeClass() {
73-
Common.connectAdmin();
74-
libMgr = Common.client.newServerConfigManager().newExtensionLibrariesManager();
77+
libMgr = adminClient.newServerConfigManager().newExtensionLibrariesManager();
7578
Common.connectEval();
7679

7780
septFirst.set(2014, Calendar.SEPTEMBER, 1, 0, 0, 0);
@@ -80,6 +83,7 @@ public static void beforeClass() {
8083
}
8184
@AfterClass
8285
public static void afterClass() {
86+
adminClient.release();
8387
Common.release();
8488
}
8589

@@ -449,5 +453,16 @@ public void test_171() throws Exception{
449453
t1.rollback();
450454
}
451455
}
452-
}
456+
}
457+
458+
@Test
459+
public void test_582_need_privilege() throws Exception{
460+
try {
461+
assertEquals("hello", adminClient.newServerEval()
462+
.xquery("'hello'").eval().next().getString());
463+
fail("a FailedRequestException should have been thrown since rest_admin doesn't have eval privileges");
464+
} catch (FailedRequestException fre) {
465+
assertTrue(fre.getMessage().contains("SEC-PRIV: Need privilege: http://marklogic.com/xdmp/privileges/xdbc-eval"));
466+
}
467+
}
453468
}

0 commit comments

Comments
 (0)