Ignore:
Timestamp:
2021-08-03T14:36:14+12:00 (3 years ago)
Author:
davidb
Message:

Add setup file and ANT configuration tasks to allow including the API key and other properties

Location:
gs3-extensions/atea-nlp-tools/trunk/src/koreromaori-proxy
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/atea-nlp-tools/trunk/src/koreromaori-proxy

    • Property svn:ignore set to
      build
  • gs3-extensions/atea-nlp-tools/trunk/src/koreromaori-proxy/src/main/java/org/atea/nlptools/koreromaoriinterface/TranscriptionServlet.java

    r35239 r35240  
    11package org.atea.nlptools.koreromaoriinterface;
    22
     3import java.io.FileInputStream;
    34import java.io.IOException;
    45import java.io.InputStream;
     
    78import java.util.ArrayList;
    89import java.util.List;
     10import java.util.Properties;
    911
    1012import javax.servlet.ServletException;
     
    3436
    3537    private final Gson jsonSerialiser;
    36     private final ReoTuhituhiApiService transcriptionService;
     38
     39    private ReoTuhituhiApiService transcriptionService;
    3740
    3841    public TranscriptionServlet()
    3942    {
    4043        jsonSerialiser = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
    41         this.transcriptionService = new ReoTuhituhiApiService(jsonSerialiser);
     44    }
     45
     46    @Override
     47    public void init()
     48    {
     49        Properties prop = new Properties();
     50
     51        try {
     52            FileInputStream fis = new FileInputStream("../webapps/gs3-koreromaori/config.properties");
     53            prop.load(fis);
     54            fis.close();
     55        } catch (IOException e) {
     56            e.printStackTrace();
     57        }
     58
     59        String apiEndpoint = prop.getProperty("tuhituhi.api.endpoint");
     60        String apiKey = prop.getProperty("tuhituhi.api.key");
     61       
     62        this.transcriptionService = new ReoTuhituhiApiService(jsonSerialiser, apiEndpoint, apiKey);
    4263    }
    4364
  • gs3-extensions/atea-nlp-tools/trunk/src/koreromaori-proxy/src/main/java/org/atea/nlptools/koreromaoriinterface/services/ReoTuhituhiApiService.java

    r35239 r35240  
    2525    private final ExecutorService threadPool;
    2626    private final Gson jsonSerialiser;
     27    private final String apiEndpoint;
     28    private final String apiKey;
    2729
    28     public ReoTuhituhiApiService(Gson jsonSerialiser)
     30    public ReoTuhituhiApiService(Gson jsonSerialiser, String apiEndpoint, String apiKey)
    2931    {
    3032        this.jsonSerialiser = jsonSerialiser;
     33        this.apiEndpoint = apiEndpoint;
     34        this.apiKey = apiKey;
    3135
    3236        threadPool = java.util.concurrent.Executors.newFixedThreadPool(3);
     
    8791        throws Exception
    8892    {
    89         // TODO: Use servlet param for URL
    90         // TODO: Use servlet param for API key
    9193        String jsonResponse = HttpRequestService
    92             .post("https://asr.koreromaori.io/transcribe_with_metadata")
    93             .authorization("Basic ")
     94            .post(apiEndpoint)
     95            .authorization("Basic " + apiKey)
    9496            .send(audioStream)
    9597            .body();
Note: See TracChangeset for help on using the changeset viewer.