Microsoft речь в текст 500 Ошибка HTTP-анализатора сервера - PullRequest
1 голос
/ 20 марта 2019

Java-код работает нормально, когда его нет в веб-сервисе, но когда я попытался создать веб-сервис и веб-метод, я получил 500 (ошибка сервера HTTP Analyzer). Формат файла WAV является правильным, так как я использовал образец от Microsoft. исходный код: https://github.com/Azure-Samples/SpeechToText-REST

@WebService
    public class VoiceCommandWS{
        public VoiceCommandWS() {
            super();
        }

static final String REQUEST_URI = "https://westus.stt.speech.microsoft.com/speech/recognition/conversation/cognitiveservices/v1?language=en-US&format=simple";

private URL buildRequestURL() throws MalformedURLException {
    String url = String.format(REQUEST_URI);

    return new URL(url);
}
@WebMethod
public void getSpeech3(){
        File file = new File("filepath", "xxx.wav");
        byte[] bytes = ReadFully(file);
        InputStream inputstream = new ByteArrayInputStream(bytes);    
try{            
    String result = getResponse(upload(inputstream, connect()));
    System.out.println(result);

}    
 catch(Exception e){
    e.printStackTrace();
}
}

private HttpURLConnection upload(InputStream is, HttpURLConnection connection) throws IOException {
       try (OutputStream output = connection.getOutputStream()) {
           byte[] buffer = new byte[1024];
           int length;
           while ((length = is.read(buffer)) != -1) {
               output.write(buffer, 0, length);
           }
           output.flush();
       } 
       return connection;
   }

private HttpURLConnection connect() throws MalformedURLException, IOException {
    HttpURLConnection connection = (HttpURLConnection) buildRequestURL().openConnection();
    connection.setDoInput(true);
    connection.setDoOutput(true);
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Content-type", "audio/wav; codec=\"audio/pcm\"; samplerate=16000");
    connection.setRequestProperty("Accept", "application/json;text/xml");
    connection.setRequestProperty("Ocp-Apim-Subscription-Key", "mykey");
    //connection.setChunkedStreamingMode(0); // 0 == default chunk size
    connection.connect();
    return connection;
}

private String getResponse(HttpURLConnection connection) throws IOException {
    if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
       throw new RuntimeException(String.format("Something went wrong, server returned: %d (%s)",
                connection.getResponseCode(), connection.getResponseMessage()));
    }
    try (BufferedReader reader =
                new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
        System.out.println(reader.readLine());
    }
}

}

журнал ошибок: 500 (ошибка сервера HTTP Analyzer)

java.lang.RuntimeException: Something went wrong, server returned: 500 (HTTP Analyzer Server Error)
at ph.com.aub.domain.VoiceCommandWS.getResponse(VoiceCommandWS.java:513)
at ph.com.aub.domain.VoiceCommandWS.getSpeech3(VoiceCommandWS.java:472)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at weblogic.wsee.jaxws.WLSInstanceResolver$WLSInvoker.invoke(WLSInstanceResolver.java:92)
at weblogic.wsee.jaxws.WLSInstanceResolver$WLSInvoker.invoke(WLSInstanceResolver.java:74)
at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:151)
at com.sun.xml.ws.server.sei.EndpointMethodHandlerImpl.invoke(EndpointMethodHandlerImpl.java:268)
at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:100)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:866)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:815)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:778)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:680)
at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:403)
at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:532)
at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:253)
at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:140)
at weblogic.wsee.jaxws.WLSServletAdapter.handle(WLSServletAdapter.java:171)
at weblogic.wsee.jaxws.HttpServletAdapter$AuthorizedInvoke.run(HttpServletAdapter.java:708)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:146)
at weblogic.wsee.util.ServerSecurityHelper.authenticatedInvoke(ServerSecurityHelper.java:103)
at weblogic.wsee.jaxws.HttpServletAdapter$3.run(HttpServletAdapter.java:311)
at weblogic.wsee.jaxws.HttpServletAdapter.post(HttpServletAdapter.java:336)
at weblogic.wsee.jaxws.JAXWSServlet.doRequest(JAXWSServlet.java:95)
at weblogic.servlet.http.AbstractAsyncServlet.service(AbstractAsyncServlet.java:99)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:119)
at java.security.AccessController.doPrivileged(Native Method)
at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:315)
at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:442)
at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:103)
at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:171)
at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:139)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)
...