Azure에서 DocumentDB에 개체를 저장하는 기능을 작성하려고합니다.자바 - DocumentDB 무단 액세스
public void saveEvent(Event event) throws DocumentClientException {
Document document = new Document(JsonCreator.createJson(event));
//check if document already exists
FeedOptions feedOptions = new FeedOptions();
feedOptions.setEnableCrossPartitionQuery(true);
FeedResponse<Document> eventDocument = documentClient.queryDocuments(COLLECTION_LINK, String.format(SELECT_DOCUMENT, event.getId()), feedOptions);
// if there is a document with the ID then replace
if (eventDocument.getQueryIterator().hasNext()) {
//documentClient.replaceDocument(COLLECTION_LINK, document, null);
documentClient.replaceDocument(COLLECTION_LINK, document, null);
}
else {
documentClient.createDocument(COLLECTION_LINK, document, null, false);
}
}
가 event
경우 존재 (event
의 id
와 데이터베이스에 대한 기록이 없음을 의미)하지 않는 다음 createDocument
가 호출 :
나는 코드의 다음 조각을 가지고있다. 레코드가 데이터베이스에 이미 존재하면 replaceDocument
이 호출됩니다.
createDocument
가 문제없이 호출 및 문서가 데이터베이스에 작성됩니다replaceDocument
발생com.microsoft.azure.documentdb.DocumentClientException: The input authorization token can't serve the request. Please check that the expected payload is built as per the protocol, and check the key being used. Server used the following payload to sign: 'put colls dbs/sporteventsdb/colls/sportevents sun, 26 mar 2017 08:32:41 gmt
전체 스택
StatusCode: Unauthorized exception
상수 :
SELECT_DOCUMENT = "SELECT * FROM " + DATABASE_ID + " WHERE " + DATABASE_ID + ".id = \"%d\"";
COLLECTION_LINK = "dbs/" + DATABASE_ID + "/colls/" + COLLECTION_ID";
나는Java 8
와Ubuntu
에IntelliJ IDEA
에Spring
프레임 워크를 개발하고 있어요.
고마워! 그게 내가 잘못하고있는 일 이었어. –