Reputation: 5563
I am playing around with Azure's DocumentIntelligence service and I am trying to create a simple example using their Java SDK as mentioned in this piece of documentation. I have created a very minimal code example just to get a feel for it, only attempting to get paragraphs out of the document in question. The code sample is the following:
public class DocumentIntelligenceApp {
private static final String ENDPOINT = System.getenv("DOCUMENT_INTELLIGENCE_ENDPOINT");
private static final String KEY = System.getenv("DOCUMENT_INTELLIGENCE_KEY");
private static final String MODEL_ID = "prebuilt-layout";
public static void main(String... args) {
try {
var client = new DocumentIntelligenceClientBuilder()
.credential(new AzureKeyCredential(KEY))
.endpoint(ENDPOINT)
.buildClient();
var request = new AnalyzeDocumentRequest().setUrlSource("https://s29.q4cdn.com/175625835/files/doc_downloads/test.pdf");
var poller = client.beginAnalyzeDocument(MODEL_ID,
null,
null,
null,
null,
null,
null,
request);
var res = poller.getFinalResult();
res.getParagraphs().forEach(documentParagraph -> {
System.out.println("Paragraph: ");
System.out.println(documentParagraph.getContent());
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
Whenever I try to run this though I am met with the following exception:
com.azure.core.exception.ResourceNotFoundException: Status code 404, "{"error":{"code":"404","message":"Resource not found"}}"
at com.azure.core.implementation.http.rest.RestProxyBase.instantiateUnexpectedException(RestProxyBase.java:398)
at com.azure.core.implementation.http.rest.SyncRestProxy.ensureExpectedStatus(SyncRestProxy.java:133)
at com.azure.core.implementation.http.rest.SyncRestProxy.handleRestReturnType(SyncRestProxy.java:210)
at com.azure.core.implementation.http.rest.SyncRestProxy.invoke(SyncRestProxy.java:86)
at com.azure.core.implementation.http.rest.RestProxyBase.invoke(RestProxyBase.java:124)
at com.azure.core.http.rest.RestProxy.invoke(RestProxy.java:95)
at jdk.proxy2/jdk.proxy2.$Proxy3.analyzeDocumentSync(Unknown Source)
at com.azure.ai.documentintelligence.implementation.DocumentIntelligenceClientImpl.analyzeDocumentWithResponse(DocumentIntelligenceClientImpl.java:304)
at com.azure.ai.documentintelligence.implementation.DocumentIntelligenceClientImpl.lambda$beginAnalyzeDocumentWithModel$6(DocumentIntelligenceClientImpl.java:511)
at com.azure.core.util.polling.SyncPoller.lambda$createPoller$0(SyncPoller.java:227)
at com.azure.core.util.polling.SimpleSyncPoller.<init>(SimpleSyncPoller.java:92)
at com.azure.core.util.polling.SyncPoller.createPoller(SyncPoller.java:196)
at com.azure.core.util.polling.SyncPoller.createPoller(SyncPoller.java:240)
at com.azure.ai.documentintelligence.implementation.DocumentIntelligenceClientImpl.beginAnalyzeDocumentWithModel(DocumentIntelligenceClientImpl.java:510)
at com.azure.ai.documentintelligence.DocumentIntelligenceClient.beginAnalyzeDocument(DocumentIntelligenceClient.java:186)
at com.ariskourt.DocumentIntelligenceApp.main(DocumentIntelligenceApp.java:23)
I have tried searching for this online but I haven't found anything relevant yet. For reference I am using the latest version of the SDK com.azure:azure-ai-documentintelligence:1.0.0-beta.3
.
Any ideas would be welcome.
Upvotes: 1
Views: 175
Reputation: 2766
For me the problem was having my resource in the wrong location.
With the Python SDK "Sweden Central" worked just fine, but with the Java Preview version I had to create a new resource in "West Europe", as mentioned in the "MS-Q&A" thread linked by Venkatesen.
Upvotes: 0
Reputation: 10455
Azure DocumentIntelligence Java SDK returning 404
I followed this MS-Document and downloaded the dependency with same package azure-ai-documentintelligence:1.0.0-beta.3
.
Pom.xml
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-ai-documentintelligence</artifactId>
<version>1.0.0-beta.3</version>
</dependency>
Using the below code with same PDF URL
, I can be able to analyze the pdf url using Azure DocumentIntelligence
Java SDK.
Code:
public class App {
private static final String ENDPOINT = "https://venkatintelligence1.cognitiveservices.azure.com/";
private static final String KEY = "401a3644aca64c90976298576f79cc0b";
private static final String MODEL_ID = "prebuilt-layout";
public static void main(String... args) {
try {
DocumentIntelligenceClient documentIntelligenceClient = new DocumentIntelligenceClientBuilder()
.credential(new AzureKeyCredential(KEY))
.endpoint(ENDPOINT)
.buildClient();;
SyncPoller<AnalyzeResultOperation, AnalyzeResult> Poller =
documentIntelligenceClient.beginAnalyzeDocument(MODEL_ID,
null,
null,
null,
null,
null,
null,
new AnalyzeDocumentRequest().setUrlSource("https://s29.q4cdn.com/175625835/files/doc_downloads/test.pdf"));
AnalyzeResult analyzeResult = Poller.getFinalResult();
analyzeResult.getParagraphs().forEach(documentParagraph -> {
System.out.println("Paragraph: ");
System.out.println(documentParagraph.getContent());
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
Output:
Paragraph:
This is a test PDF document. If you can read this, you have Adobe Acrobat Reader installed on your computer.
Reference:
Check this MS-Q&A by VasaviLankipalle-MSFT for similar 404 error.
Upvotes: 0