2017-03-26 4 views
1

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 경우 존재 (eventid와 데이터베이스에 대한 기록이 없음을 의미)하지 않는 다음 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

: 코드에서 사용 http://pastebin.com/YVGwqLkH

상수 :

  • SELECT_DOCUMENT = "SELECT * FROM " + DATABASE_ID + " WHERE " + DATABASE_ID + ".id = \"%d\"";
    • COLLECTION_LINK = "dbs/" + DATABASE_ID + "/colls/" + COLLECTION_ID";나는 Java 8UbuntuIntelliJ IDEASpring 프레임 워크를 개발하고 있어요.

    답변