Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.marklogic.client.DatabaseClientFactory;
import com.marklogic.client.DatabaseClientFactory.SSLHostnameVerifier;
import com.marklogic.client.DatabaseClientFactory.SecurityContext;
import com.marklogic.client.MarkLogicIOException;
import com.marklogic.client.ResourceNotFoundException;
import com.marklogic.client.Transaction;
import com.marklogic.client.alerting.RuleDefinition;
Expand All @@ -46,6 +47,7 @@
import com.marklogic.client.query.ValuesDefinition;
import com.marklogic.client.query.ValuesListDefinition;
import org.custommonkey.xmlunit.exceptions.XpathException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
Expand Down Expand Up @@ -167,35 +169,18 @@ public X509Certificate[] getAcceptedIssuers() {
}


@Test
public void testDatabaseClientConnectionInvalidPort() throws IOException
{
System.out.println("Running testDatabaseClientConnectionInvalidPort");

String filename = "facebook-10443244874876159931";

DatabaseClient client = newDatabaseClientBuilder().withPort(8033).build();

String expectedException = null;
String exception = "";
if (IsSecurityEnabled())
expectedException = "Failed to connect";
else
expectedException = "com.marklogic.client.MarkLogicIOException";

// write doc
try {
writeDocumentUsingStringHandle(client, filename, "/write-text-doc/", "Text");
} catch (Exception e) {
exception = e.toString();
System.out.println("Exception is " + exception);
}

assertTrue(exception.contains(expectedException));
@Test
void invalidPort() {
int assumedInvalidPort = 60123;
DatabaseClient client = newDatabaseClientBuilder().withPort(assumedInvalidPort).build();

// release client
client.release();
}
MarkLogicIOException ex = Assertions.assertThrows(MarkLogicIOException.class, () -> client.checkConnection());
String expected = "Error occurred while calling http://localhost:60123/v1/ping; java.net.ConnectException: " +
"Failed to connect to localhost/127.0.0.1:60123 ; possible reasons for the error include " +
"that a MarkLogic app server may not be listening on the port, or MarkLogic was stopped " +
"or restarted during the request; check the MarkLogic server logs for more information.";
assertEquals(expected, ex.getMessage());
}

@Test
public void testDatabaseClientConnectionInvalidUser() throws IOException, KeyManagementException, NoSuchAlgorithmException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,13 @@ private Response sendRequestOnce(Request request) {
try {
return getConnection().newCall(request).execute();
} catch (IOException e) {
throw new MarkLogicIOException(e);
String message = String.format(
"Error occurred while calling %s; %s: %s " +
"; possible reasons for the error include that a MarkLogic app server may not be listening on the port, " +
"or MarkLogic was stopped or restarted during the request; check the MarkLogic server logs for more information.",
request.url(), e.getClass().getName(), e.getMessage()
);
throw new MarkLogicIOException(message, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,9 @@ public void testSSLAuth() throws NoSuchAlgorithmException, KeyManagementExceptio
assertEquals(handle.get(), "A simple text document by SSL connection");
docMgr.delete(docId);
} catch (MarkLogicIOException e) {
String exception = e.toString();
String message = exception.toLowerCase();

boolean foundExpected = false;

String[] expectedClasses = {"javax.net.ssl.SSLException", "java.net.UnknownServiceException"};
String[] expectedMessages = {"unrecognized ssl message", "unable to find acceptable protocols"};
for (int i=0; i < expectedClasses.length; i++) {
String expectedException = "com.marklogic.client.MarkLogicIOException: " + expectedClasses[i] +": ";
if (exception.startsWith(expectedException) && message.contains(expectedMessages[i])) {
foundExpected = true;
break;
}
}
if (!foundExpected) {
fail("unexpected exception for SSL over HTTPS or HTTP connection:\n"+exception);
}
String message = e.getMessage();
assertTrue(message.contains("java.net.UnknownServiceException: Unable to find acceptable protocols"),
"Unexpected message: " + message);
}
}

Expand Down