Невозможно загрузить файлы из виртуальной машины Microsoft Windows Azure в Azure BLOB с помощью JClouds

Я пытаюсь загрузить файлы в Azure BLOB с помощью Jclouds. Среда, в которой работает сервер, — это виртуальная машина Microsoft Windows Azure, работающая в частной сети. Через брандмауэр открыты порты 80 и 443. Следующий код используется для загрузки файлов. Тот же код работает, если я запускаю его со своего ПК:

@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, чтобы это работало? Пожалуйста помоги.


person Rahul Bobhate    schedule 28.03.2014    source источник
comment
возможный дубликат Ошибка создания BlobContext с использованием jclouds в Spring MVC приложение   -  person Andrew Gaul    schedule 08.04.2014


Ответы (1)


Вы используете jclouds 1.6.x или 1.7.0 с Java 7u51? Если это так, возможно, вы столкнулись с https://issues.apache.org/jira/browse/JCLOUDS-427 . Вы можете обойти это, понизив версию до Java 7u45 или обновив ее до jclouds 1.7.1.

Также вы должны предпочесть ByteSource Payload вместо FileInputStream, так как первый позволяет работать логике повторных попыток jclouds. Вы можете создать его с помощью Files.asByteSource(File).

person Andrew Gaul    schedule 08.04.2014