Commit 9ef2762f authored by gspbirel56's avatar gspbirel56
Browse files

restReadDocShow endpoint should work now

parent d35b5f48
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@ package edu.psu.MarkLogic.demo.controller;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import edu.psu.MarkLogic.demo.model.ConfidenceFitness;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.net.URI;
@@ -59,11 +61,14 @@ public class MLRestController {
            Credentials credentials = new UsernamePasswordCredentials("admin", "admin");  // provide username & password
            provider.setCredentials(AuthScope.ANY, credentials);
            HttpClient httpClient = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
            String uri = "";          // provide the REST API URI
            String uri = "http://192.168.56.200:8000/LATEST/documents?uri=" + doc_uri;          // provide the REST API URI
            System.out.println(uri);
            HttpGet get = new HttpGet(uri);
            HttpResponse response = httpClient.execute(get);

            // ba = ???               // provide the code to get byte[]
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            response.getEntity().writeTo(baos);
             ba = baos.toByteArray();              // provide the code to get byte[]
            
            headers.set("Content-Type", response.getEntity().getContentType().getValue());
            
@@ -71,6 +76,7 @@ public class MLRestController {
            headers.set("Content-Disposition", "filename=" + fileName);          
        } catch (IOException ex) {
            Logger.getLogger(MLRestController.class.getName()).log(Level.SEVERE, null, ex);
            ex.printStackTrace();
        }
        return new ResponseEntity<>(ba, headers, HttpStatus.OK);
    }