我正在尝试使用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上进行任何配置吗?请帮忙。

最佳答案

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

另外,您应该更喜欢ByteSource Payload而不是FileInputStream,因为前者允许jclouds重试逻辑起作用。您可以使用Files.asByteSource(File)创建一个。

关于java - 无法使用JClouds将文件从Microsoft Windows Azure VM上传到Azure BLOB,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22707077/

10-10 23:57