我正试图在google api中使用google vision,但是我遇到了以下问题:
jun 07,2017 8:50:00 AM io.grpc.internal.ChannelExecutor drain ADVERTÊNCIA:Runnable在ChannelExecutor中抛出异常 java.lang.IllegalArgumentException:Jetty ALPN / NPN还没有 配置正确。在 io.grpc.netty.GrpcSslContexts.selectApplicationProtocolConfig(GrpcSslContexts.java:174) 在io.grpc.netty.GrpcSslContexts.configure(GrpcSslContexts.java:151) 在io.grpc.netty.GrpcSslContexts.configure(GrpcSslContexts.java:139) 在io.grpc.netty.GrpcSslContexts.forClient(GrpcSslContexts.java:109) 在 io.grpc.netty.NettyChannelBuilder.createProtocolNegotiatorByType(NettyChannelBuilder.java:335) 在 io.grpc.netty.NettyChannelBuilder.createProtocolNegotiator(NettyChannelBuilder.java:308) 在 io.grpc.netty.NettyChannelBuilder $ NettyTransportFactory $ DynamicNettyTransportParams.getProtocolNegotiator(NettyChannelBuilder.java:499) 在 io.grpc.netty.NettyChannelBuilder $ NettyTransportFactory.newClientTransport(NettyChannelBuilder.java:448) 在 io.grpc.internal.CallCredentialsApplyingTransportFactory.newClientTransport(CallCredentialsApplyingTransportFactory.java:61) 在 io.grpc.internal.InternalSubchannel.startNewTransport(InternalSubchannel.java:209) 在 io.grpc.internal.InternalSubchannel.obtainActiveTransport(InternalSubchannel.java:186) 在 io.grpc.internal.ManagedChannelImpl $ SubchannelImplImpl.obtainActiveTransport(ManagedChannelImpl.java:806) 在 io.grpc.internal.GrpcUtil.getTransportFromPickResult(GrpcUtil.java:568) 在 io.grpc.internal.DelayedClientTransport.reprocess(DelayedClientTransport.java:296) 在 io.grpc.internal.ManagedChannelImpl $ LbHelperImpl $ 5.run(ManagedChannelImpl.java:724) 在io.grpc.internal.ChannelExecutor.drain(ChannelExecutor.java:87) 在 io.grpc.internal.ManagedChannelImpl $ LbHelperImpl.runSerialized(ManagedChannelImpl.java:715) 在 io.grpc.internal.ManagedChannelImpl $ NameResolverListenerImpl.onUpdate(ManagedChannelImpl.java:752) at io.grpc.internal.DnsNameResolver $ 1.run(DnsNameResolver.java:174) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 在 java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617) 在java.lang.Thread.run(Thread.java:745)
我正在尝试运行api自己的示例代码,如下所示:
public class QuickstartSample {
public static void main(String... args) throws Exception {
// Instantiates a client
ImageAnnotatorClient vision = ImageAnnotatorClient.create();
// The path to the image file to annotate
String fileName = "./resources/wakeupcat.jpg";
// Reads the image file into memory
Path path = Paths.get(fileName);
byte[] data = Files.readAllBytes(path);
ByteString imgBytes = ByteString.copyFrom(data);
// Builds the image annotation request
List<AnnotateImageRequest> requests = new ArrayList<>();
Image img = Image.newBuilder().setContent(imgBytes).build();
Feature feat = Feature.newBuilder().setType(Type.LABEL_DETECTION).build();
AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
requests.add(request);
// Performs label detection on the image file
BatchAnnotateImagesResponse response = vision.batchAnnotateImages(requests);
List<AnnotateImageResponse> responses = response.getResponsesList();
for (AnnotateImageResponse res : responses) {
if (res.hasError()) {
System.out.printf("Error: %s\n", res.getError().getMessage());
return;
}
for (EntityAnnotation annotation : res.getLabelAnnotationsList()) {
annotation.getAllFields().forEach((k, v) -> System.out.printf("%s : %s\n", k, v.toString()));
}
}
}
}
我正在使用以下依赖项:
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-vision</artifactId>
<version>v1-rev357-1.22.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-vision</artifactId>
<version>0.17.2-beta</version>
</dependency>
有没有人遇到过这个问题?
答案 0 :(得分:0)
我实际上发现要运行api,你必须在Web上下文中并且还要在Jetty服务器上运行应用程序