Google Cloud Vision无一例外地崩溃

时间:2018-06-12 04:29:07

标签: google-cloud-vision

我最近遇到了一个令人讨厌的错误,只发生在我们的3个环境中的1个(Amazon EC2是特定的)。当我向Cloud API发送请求以接收有关图片的标签时。该函数崩溃,但我没有看到try catch捕获的任何异常。该功能正常工作,直到6月1日,但我不知道为什么它不再(其他2个环境工作正常)。

以下是代码:

try {
             GoogleCredentials cred = GoogleCredentials.fromStream(new FileInputStream(coreConfig.googleCreds()));
             log.error("GoogleCredentials cred = GoogleCredentials.fromStream(new FileInputStream(coreConfig.googleCreds()));");
             ImageAnnotatorSettings imageAnnotatorSettings =  ImageAnnotatorSettings.newBuilder()
                              .setCredentialsProvider(FixedCredentialsProvider.create(cred))
                              .build();
            ImageAnnotatorClient vision = ImageAnnotatorClient.create(imageAnnotatorSettings);
            log.error("ImageAnnotatorClient vision = ImageAnnotatorClient.create(imageAnnotatorSettings);");
              byte[] data = IOUtils.toByteArray(is);
              ByteString bs = ByteString.copyFrom(data);
              // Builds the image annotation request
              List<AnnotateImageRequest> requests = new ArrayList<>();
              log.error("ByteString bs = ByteString.copyFrom(data);");
              Image img = Image.newBuilder().setContent(bs).build();
              log.error("  Image img = Image.newBuilder().setContent(bs).build();");
              Feature feat = Feature.newBuilder().setType(Type.LABEL_DETECTION).build();
              log.error("Feature feat = Feature.newBuilder().setType(Type.LABEL_DETECTION).build();");
              AnnotateImageRequest request = AnnotateImageRequest.newBuilder()
                  .addFeatures(feat)
                  .setImage(img)
                  .build();
              requests.add(request);
              log.error("requests.add(request);");
              // Performs label detection on the image file
              BatchAnnotateImagesResponse response = vision.batchAnnotateImages(requests);
              log.error("BatchAnnotateImagesResponse response = vision.batchAnnotateImages(requests);");
              List<AnnotateImageResponse> responses = response.getResponsesList();           
              log.error("List<AnnotateImageResponse> responses = response.getResponsesList();");
              for (AnnotateImageResponse res : responses) {
                if (res.hasError()) {
                    throw new ServiceException(ServiceStatus.BAD_REQUEST, res.getError().getMessage());             
                }        
                for (EntityAnnotation annotation : res.getLabelAnnotationsList()) {              
                  tags.append("===" + annotation.getDescription().replaceAll("\\s+",""));
                  log.error("tags.append(\"===\" + annotation.getDescription().replaceAll(\"\\\\s+\",\"\"));");
                }
              } 
              return tags;
        }catch(Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());          
            return null;
//          throw new ServiceException(ServiceStatus.BAD_REQUEST, e.getMessage());
        }

以下是有关它的详细信息:

Here are the details about it

1 个答案:

答案 0 :(得分:1)

似乎旧版本的番石榴(在这种情况下为17.0-jdk)导致了这次崩溃。 您仍然必须删除旧版本,不仅要从pom.xml中删除,还要删除.war文件的lib文件夹。