@Override public void deploy(AppConfig appConfig) { this.completed = 0; onStatusChange(0, "Installing..."); super.deploy(appConfig); onStatusChange(100, "Installation Complete"); if (databaseClient != null) { //Below is telemetry metric code for tracking successful dhf installs //TODO: when more uses of telemetry are defined, change this to a more e-node based method ServerEvaluationCall eval = databaseClient.newServerEval(); String query = "xdmp:feature-metric-increment(xdmp:feature-metric-register(\"datahub.core.install.count\"))"; try { eval.xquery(query).eval().close(); } catch (FailedRequestException e) { logger.error("Failed to increment feature metric telemetry count: " + query, e); e.printStackTrace(); } } }
@Override public Response intercept(Chain chain) throws IOException { Request request = chain.request(); String authValue; try { authValue = "Negotiate " + buildAuthorizationHeader("HTTP/" + host); } catch (Exception e) { throw new FailedRequestException(e.getMessage(), e); } Request authenticatedRequest = request.newBuilder().header("Authorization", authValue).build(); return chain.proceed(authenticatedRequest); } }
protected void loadSchemasIntoSchemasDatabase(CommandContext context) { AppConfig config = context.getAppConfig(); DatabaseClient client = config.newSchemasDatabaseClient(); SchemasLoader schemasLoader = buildSchemasLoader(context, client); try { String schemasPath = config.getSchemasPath(); logger.info("Loading schemas from path: " + schemasPath); schemasLoader.loadSchemas(schemasPath); logger.info("Finished loading schemas from: " + schemasPath); } catch (FailedRequestException fre) { if (fre.getMessage().contains("NOSUCHDB")) { logger.warn("Unable to load schemas because no schemas database exists; cause: " + fre.getMessage()); } else { throw fre; } } finally { client.release(); } }
@Ignore public void testErrorOnNonREST() throws ForbiddenUserException { DatabaseClient badClient = DatabaseClientFactory.newClient(Common.HOST, 8001, new DigestAuthContext(Common.USER, Common.PASS)); ServerConfigurationManager serverConfig = badClient .newServerConfigManager(); try { serverConfig.readConfiguration(); } catch (FailedRequestException e) { assertEquals( "Local message: config/properties read failed: Not Found. Server Message: Server (not a REST instance?) did not respond with an expected REST Error message.", e.getMessage()); assertEquals(404, e.getFailedRequest().getStatusCode()); assertEquals("UNKNOWN", e.getFailedRequest().getStatus()); } finally { badClient.release(); } }
docMgr.write(docUri, handle); } catch (FailedRequestException e) { exception = e.toString(); statusCode = e.getFailedRequest().getMessageCode(); expCode = e.getFailedRequest().getStatusCode();
w3.start(); } catch (FailedRequestException ex) { msgEx.append(ex.toString());
docMgr.write(desc, contentHandle); } catch (FailedRequestException e) { FailedRequest failreq = e.getFailedRequest(); if (failreq != null) statusCode = failreq.getStatusCode(); docMgr.write(documentUri, contentHandle); } catch (FailedRequestException e) { FailedRequest failreq = e.getFailedRequest(); if (failreq != null) statusCode = failreq.getStatusCode(); docMgr.write(desc, contentHandle); } catch (FailedRequestException e) { FailedRequest failreq = e.getFailedRequest(); if (failreq != null) statusCode = failreq.getStatusCode(); docMgr.delete(desc); } catch (FailedRequestException e) { FailedRequest failreq = e.getFailedRequest(); if (failreq != null) statusCode = failreq.getStatusCode();
assertEquals( "Local message: /config/query write failed: Bad Request. Server Message: RESTAPI-INVALIDCONTENT: (err:FOER0000) Invalid content: Operation results in invalid Options: Operator or constraint name \"blah\" is used more than once (must be unique).", e.getMessage()); assertEquals(400, e.getFailedRequest().getStatusCode()); assertEquals("Bad Request", e.getFailedRequest().getStatus()); assertEquals("RESTAPI-INVALIDCONTENT", e.getFailedRequest() .getMessageCode());
@Test public void testInvalidUserAuth() { // create the client DatabaseClient client = DatabaseClientFactory.newClient( Common.HOST, Common.PORT, new DigestAuthContext("MyFooUser", "x")); String expectedException = "com.marklogic.client.FailedRequestException: " + "Local message: write failed: Unauthorized. Server Message: Unauthorized"; String exception = ""; String docId = "/example/text.txt"; TextDocumentManager docMgr = client.newTextDocumentManager(); try { // make use of the client connection so we get an auth error StringHandle handle = new StringHandle(); handle.set("A simple text document"); docMgr.write(docId, handle); // the next line will only run if write doesn't throw an exception docMgr.delete(docId); } catch (FailedRequestException e) { exception = e.toString(); } finally { client.release(); } assertEquals(expectedException, exception); } }
public HTTPKerberosAuthInterceptor(String host, Map<String,String> krbOptions) { this.host = host; this.krbOptions = krbOptions; try { buildSubjectCredentials(); } catch (LoginException e) { throw new FailedRequestException(e.getMessage(), e); } }
} catch (FailedRequestException e) { e.printStackTrace();
@Test public void test_582_need_privilege() throws Exception{ try { assertEquals("hello", adminClient.newServerEval() .xquery("'hello'").eval().next().getString()); fail("a FailedRequestException should have been thrown since rest_admin doesn't have eval privileges"); } catch (FailedRequestException fre) { assertTrue(fre.getMessage().contains("SEC-PRIV: Need privilege: http://marklogic.com/xdmp/privileges/xdbc-eval")); } }
@Override public String advanceLsqt(RequestLogger reqlog, String temporalCollection, long lag) { if (logger.isDebugEnabled()) logger.debug("Advancing LSQT in temporal collection {}", temporalCollection); logRequest(reqlog, "wiped %s document", temporalCollection); RequestParameters params = new RequestParameters(); params.add("result", "advance-lsqt"); if ( lag > 0 ) params.add("lag", String.valueOf(lag)); Map<String,List<String>> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); postResource(reqlog, "temporal/collections/" + temporalCollection, null, params, null, null, "advanceLsqt", headers); List<String> values = headers.get(HEADER_ML_LSQT); if ( values != null && values.size() > 0 ) { return values.get(0); } else { throw new FailedRequestException("Response missing header \"" + HEADER_ML_LSQT + "\""); } }
@Override public void run() { Transaction t2 = writeclient.openTransaction(); try { System.out.println("In ExecuteAskSecondThreadFalse run method"); SPARQLQueryManager sparqlQmgrTh = writeclient.newSPARQLQueryManager(); StringBuffer sparqlQueryTh = new StringBuffer(); sparqlQueryTh.append("ASK FROM <rdfxml> where { <http://example.org/kennedy/person1> <http://purl.org/dc/elements/1.1/title> \"Person\'s title\"@en }"); SPARQLQueryDefinition qdefTh = sparqlQmgrTh.newQueryDefinition(sparqlQueryTh.toString()); // Verify result in t2 transaction. boolean bAskInTransT2 = sparqlQmgrTh.executeAsk(qdefTh, t2); System.out.println("Method ExecuteAskSecondThreadFalse Run result is " + bAskInTransT2); assertFalse("Class ExecuteAskSecondThreadFalse Run result is incorrect. No Records should be returned.", bAskInTransT2); setbCompleted(true); } catch (ForbiddenUserException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FailedRequestException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (t2 != null) { t2.rollback(); t2 = null; } } } }
assertTrue(e.getMessage().contains("TEMPORAL-GTLSQT"));
private void checkStatus(Response response, int status, String operation, String entityType, String path, ResponseStatus expected) { if (!expected.isExpected(status)) { FailedRequest failure = extractErrorFields(response); if (status == STATUS_NOT_FOUND) { throw new ResourceNotFoundException("Could not " + operation + " " + entityType + " at " + path, failure); } if ("RESTAPI-CONTENTNOVERSION".equals(failure.getMessageCode())) { throw new FailedRequestException("Content version required to " + operation + " " + entityType + " at " + path, failure); } else if (status == STATUS_FORBIDDEN) { throw new ForbiddenUserException("User is not allowed to " + operation + " " + entityType + " at " + path, failure); } throw new FailedRequestException("failed to " + operation + " " + entityType + " at " + path + ": " + getReasonPhrase(response), failure); } }
protected EvalResultIterator runInDatabase(String query, String databaseName) { ServerEvaluationCall eval; switch(databaseName) { case HubConfig.DEFAULT_STAGING_NAME: eval = stagingClient.newServerEval(); break; case HubConfig.DEFAULT_FINAL_NAME: eval = finalClient.newServerEval(); break; case HubConfig.DEFAULT_MODULES_DB_NAME: eval = stagingModulesClient.newServerEval(); break; case HubConfig.DEFAULT_JOB_NAME: eval = jobClient.newServerEval(); break; default: eval = stagingClient.newServerEval(); break; } try { return eval.xquery(query).eval(); } catch(FailedRequestException e) { logger.error("Failed run code: " + query, e); e.printStackTrace(); throw e; } }
throw new FailedRequestException("search failed: " + getReasonPhrase(response), extractErrorFields(response));
@Override public Object run() { try { Oid krb5Mechanism = new Oid("1.2.840.113554.1.2.2"); Oid krb5PrincipalNameType = new Oid("1.2.840.113554.1.2.2.1"); final GSSManager manager = GSSManager.getInstance(); final GSSName clientName = manager.createName(clientPrincipalName, krb5PrincipalNameType); final GSSCredential clientCred = manager.createCredential(clientName, 8 * 3600, krb5Mechanism, GSSCredential.INITIATE_ONLY); final GSSName serverName = manager.createName(serverPrincipalName, krb5PrincipalNameType); final GSSContext context = manager.createContext(serverName, krb5Mechanism, clientCred, GSSContext.DEFAULT_LIFETIME); byte[] inToken = new byte[0]; byte[] outToken = context.initSecContext(inToken, 0, inToken.length); context.requestMutualAuth(true); outputToken.append(new String(Base64.getEncoder().encode(outToken))); context.dispose(); } catch (GSSException exception) { throw new FailedRequestException(exception.getMessage(), exception); } return null; } }
throw new FailedRequestException( "Service unavailable and maximum retry period elapsed: "+ Math.round((System.currentTimeMillis() - startTime) / 1000)+ + type, extractErrorFields(response)); if (status != ClientResponse.Status.NO_CONTENT) throw new FailedRequestException("delete failed: " + status.getReasonPhrase(), extractErrorFields(response)); response.close();