Changeset 35248 for gs3-extensions


Ignore:
Timestamp:
2021-08-04T11:30:42+12:00 (3 years ago)
Author:
davidb
Message:

Improve logging and error handling

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

Legend:

Unmodified
Added
Removed
  • gs3-extensions/atea-nlp-tools/trunk/src/koreromaori-proxy/src/main/java/org/atea/nlptools/koreromaoriinterface/TranscriptionServlet.java

    r35247 r35248  
    7878            throws ServletException, IOException
    7979    {
    80         logger.trace("POST request received.");
    81 
    82         response.setContentType("application/json; charset=UTF-8");
    83         PrintWriter writer = response.getWriter();
    84 
    85         String audioFileKeysParameter = request.getParameter("audioFileKeys");
    86         if (audioFileKeysParameter == null) {
    87             response.sendError(400, "Form data was incorrect: missing audioFileKeys part.");
    88             return;
    89         }
    90         String[] audioFileKeys = audioFileKeysParameter.split("\\|");
    91 
    92         // Create our own representation of each part
    93         ArrayList<AudioFilePart> audioFileParts = new ArrayList<AudioFilePart>(audioFileKeys.length);
    94         for (String audioFileKey : audioFileKeys)
    95         {
    96             Part p = request.getPart(audioFileKey);
    97             AudioFilePart audioFilePart = AudioFilePart.fromPart(p);
    98             audioFileParts.add(audioFilePart);
    99         }
    100 
    10180        try
    10281        {
     82            logger.trace("POST request received.");
     83
     84            response.setContentType("application/json; charset=UTF-8");
     85            PrintWriter writer = response.getWriter();
     86   
     87            // Attempt to get the key of every audio file part
     88            String audioFileKeysParameter = request.getParameter("audioFileKeys");
     89            if (audioFileKeysParameter == null)
     90            {
     91                response.sendError(400, "Form data was incorrect: missing audioFileKeys part.");
     92                logger.trace("Request rejected due: Form data was missing the audioFileKeys part.");
     93                return;
     94            }
     95            String[] audioFileKeys = audioFileKeysParameter.split("\\|");
     96   
     97            // Create our own representation of each part
     98            ArrayList<AudioFilePart> audioFileParts = new ArrayList<AudioFilePart>(audioFileKeys.length);
     99            for (String audioFileKey : audioFileKeys)
     100            {
     101                // Attempt to get the part that this key specifies should be present
     102                Part p = request.getPart(audioFileKey);
     103                if (p == null) {
     104                    response.sendError(400, "Form data was incorrect: a part key listed in the audioFileKeys was not found.");
     105                    logger.trace("Request rejected due: Form data was missing a client-specified part.");
     106                    return;
     107                }
     108
     109                AudioFilePart audioFilePart = AudioFilePart.fromPart(p);
     110                audioFileParts.add(audioFilePart);
     111            }
     112
     113            // Transcribe each part
    103114            List<AudioFilePart> results = transcriptionService.getTranscriptions(audioFileParts);
    104115
     116            // Transform the Tuhituhi response into our own format
    105117            List<MyTranscriptionResponse> responses = new ArrayList<MyTranscriptionResponse>(results.size());
    106118            for (AudioFilePart result : results) {
     
    108120            }
    109121
     122            // Send our result to the client
    110123            String json = jsonSerialiser.toJson(responses, transcriptionListType);
    111124            writer.append(json);
  • gs3-extensions/atea-nlp-tools/trunk/src/koreromaori-proxy/src/main/java/org/atea/nlptools/koreromaoriinterface/models/AudioFilePart.java

    r35241 r35248  
    1111
    1212    public final String fileName;
    13     public final InputStream dataStream;
     13    public final InputStream dataStream; // TODO: Use a buffered input stream here? Need to check docs on what type of stream a Part uses
    1414
    1515    public AudioFilePart(String fileName, InputStream dataStream)
  • gs3-extensions/atea-nlp-tools/trunk/src/koreromaori-proxy/src/main/java/org/atea/nlptools/koreromaoriinterface/services/ReoTuhituhiApiService.java

    r35246 r35248  
    11package org.atea.nlptools.koreromaoriinterface.services;
    22
     3import java.io.IOException;
    34import java.io.InputStream;
    45import java.util.LinkedList;
     
    6768     */
    6869    public TranscriptionResult getTranscription(InputStream audioStream)
    69         throws HttpRequestException, JsonSyntaxException, ReoTuhituhiException
     70        throws HttpRequestException, JsonSyntaxException, ReoTuhituhiException, IOException
    7071    {
     72        logger.trace("Performing request to tuhituhi API. Audio bytes available to pass through: " + audioStream.available());
     73
    7174        HttpRequestService request = HttpRequestService
    7275            .post(apiEndpoint)
     
    100103        }
    101104
     105        logger.trace("Tuhituhi API returned a successful result. Beginning deserialisation...");
     106
    102107        TranscriptionResult res = jsonSerialiser.fromJson(request.body(), TranscriptionResult.class);
     108
     109        logger.trace("Tuhituhi response successfully deserialised");
    103110
    104111        return res;
  • gs3-extensions/atea-nlp-tools/trunk/src/koreromaori-proxy/src/main/webapp/WEB-INF/log4j2.xml

    r35247 r35248  
    99  </Appenders>
    1010  <Loggers>
    11     <Root level="debug">
     11    <Root level="trace">
    1212      <AppenderRef ref="FileOutput"/>
    1313    </Root>
Note: See TracChangeset for help on using the changeset viewer.