1

我正在尝试使用 Jclouds 将文件上传到 Azure BLOB。服务器运行的环境是 Microsoft Windows Azure VM,它在专用网络上运行。它通过防火墙打开了端口 80 和 443。以下代码用于上传文件。如果我从我的 PC 执行相同的代码:

@SuppressWarnings("nls")
public boolean upload(final String path) 
{
    final File file = new File(path);

    FileInputStream fis = null;
    BlobStoreContext context =null;
    try
    {
        fis = new FileInputStream(file);

        context = ContextBuilder.newBuilder("azureblob").credentials(this.store, this.key).buildView(BlobStoreContext.class);

        final BlobStore store = context.getBlobStore();

        Payload payload = new InputStreamPayload(fis);
        payload.getContentMetadata().setContentLength(fis.getChannel().size());

        final Blob blob = store.blobBuilder(file.getName()).payload(payload).build();

        context.getBlobStore().putBlob("js-uc-osprey", blob);
        return true;
    }
    catch (Exception e) 
    {
        e.printStackTrace();
    }
    finally
    {
        if(context!=null)
        context.close();            
    }

    return false;
}

我得到以下异常:

com.google.inject.CreationException: Guice creation errors:

1) org.jclouds.rest.RestContext<org.jclouds.azureblob.AzureBlobClient, A> cannot be used as a key; It is not fully specified.

1 error
        at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:435)
        at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:154)
        at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:106)
        at com.google.inject.Guice.createInjector(Guice.java:95)
        at org.jclouds.ContextBuilder.buildInjector(ContextBuilder.java:321)
        at org.jclouds.ContextBuilder.buildInjector(ContextBuilder.java:261)
        at org.jclouds.ContextBuilder.buildView(ContextBuilder.java:521)
        at org.jclouds.ContextBuilder.buildView(ContextBuilder.java:501)
        at com.ct.jsix.storage.service.impl.StorageServiceImpl.upload(StorageServiceImpl.java:147)
        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:606)
        at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:180)
        at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
        at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:193)
        at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:102)
        at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
        at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:94)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:271)
        at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
        at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:355)
        at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:319)
        at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72)
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1040)
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:976)
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
        at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
        at org.eclipse.jetty.server.Server.handle(Server.java:363)
        at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:483)
        at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:931)
        at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:992)
        at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:856)
        at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
        at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
        at org.eclipse.jetty.io.nio.SslConnection.handle(SslConnection.java:196)
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628)
        at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
        at java.lang.Thread.run(Thread.java:744)

是否需要在 Azure VM 上进行任何配置才能使其正常工作?请帮忙。

4

1 回答 1

1

您是在使用 Java 7u51 运行 jclouds 1.6.x 还是 1.7.0?如果是这样,您可能遇到过https://issues.apache.org/jira/browse/JCLOUDS-427。您可以通过降级到 Java 7u45 或升级到 jclouds 1.7.1 来解决这个问题。

此外,您应该更喜欢 aByteSource Payload而不是,FileInputStream因为前者允许 jclouds 重试逻辑工作。您可以使用Files.asByteSource(File).

于 2014-04-08T05:52:56.883 回答