In Azure Cosmo DocumentDB in my application, Am getting following error
2018-03-27 14:42:057 ERROR c.h.m.s.CosmosDBFruiteService - Could not add Fruites to Customer Reference : 11416e34-3620-45a4-b3be-b845bbf41762
Message: {"Errors":["Resource with specified id or name already exists."]} ActivityId: 1b70b944-d581-4640-8785-819400433bb4, Request URI: /apps/8d13f597-c7e4-4d60-8713-8a0e9abaa9ac/services/ce0d287f-0125-482b-b32c-22108b5b0ed3/partitions/42c80a49-8042-4032-8cfd-9937ecea8dcc/replicas/131662740073245648p, RequestStats: , SDK: Microsoft.Azure.Documents.Common/1.21.0.0, StatusCode: Conflict 2018-03-27 14:42:058 ERROR c.h.m.a.e.GlobalExceptionHandler - Exception: class org.apache.catalina.connector.ClientAbortException Message: java.io.IOException: An existing connection was forcibly closed by the remote host 2018-03-27 14:42:058 WARN o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - Failed to invoke @ExceptionHandler method: public java.util.Map com.hm.myfeed.api.exception.GlobalExceptionHandler.handleException(java.lang.Exception,org.springframework.web.context.request.WebRequest,javax.servlet.http.HttpServletRequest) org.apache.catalina.connector.ClientAbortException: java.io.IOException: An existing connection was forcibly closed by the remote host at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:356) at org.apache.catalina.connector.OutputBuffer.flushByteBuffer(OutputBuffer.java:815) at org.apache.catalina.connector.OutputBuffer.append(OutputBuffer.java:720) at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:391) at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:369) at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:96) at org.springframework.security.web.util.OnCommittedResponseWrapper$SaveContextServletOutputStream.write(OnCommittedResponseWrapper.java:639)
I do not understand this one bit. The exception is occuring in the code that first checks if the collection exists (it does) then if it does not creates it. Clearly the create will fail, the collection exists!!
Create function
try {
fruitesDocument = documentClient.createDocument(getCollectionLink(), fruitesDocument , null, false).getResource();
} catch (DocumentClientException e) {
LOG.error("Could not add fruits for Customer Reference: " + fruitesModel.getId() + " " + e.getMessage());
}
Update Function :
try {
fruitesDocument = documentClient.replaceDocument(fruitesDocument , null).getResource();
} catch (DocumentClientException e) {
LOG.error("Error while updating fruites: " + e.getMessage());
}
Am getting issue while creating document.