首页 \ 问答 \ Azure SDK for Java - 抛出InvalidKeyException的示例程序(Azure SDK for Java - sample program throwing InvalidKeyException)

Azure SDK for Java - 抛出InvalidKeyException的示例程序(Azure SDK for Java - sample program throwing InvalidKeyException)

使用Azure Storage SDK for Java,我尝试在Azure表存储上执行基本的创建,读取,更新,删除操作,如下面的链接所示: https//azure.microsoft.com/en-us/documentation/articles/存储Java的如何使用的表存储/

用于创建表的示例程序:

package com.azure.test;
import java.io.UnsupportedEncodingException;
import com.microsoft.azure.storage.*;
import com.microsoft.azure.storage.table.CloudTable;
import com.microsoft.azure.storage.table.CloudTableClient;
import com.microsoft.windowsazure.core.utils.Base64;

public class App 
{

    public static void main( String[] args ) throws StorageException,    UnsupportedEncodingException
{

    String storageConnectionString =
            "DefaultEndpointsProtocol=http;" +
            "AccountName=accountname;" + 
            "AccountKey=storagekey;"+
           "EndpointSuffix=table.core.windows.net"; 

    try
    {
        // Retrieve storage account from connection-string.
        CloudStorageAccount storageAccount =
           CloudStorageAccount.parse(storageConnectionString);

        CloudTableClient tableClient =               storageAccount.createCloudTableClient();

      //Create the table if it doesn't exist.
       String tableName = "MyTable";
       CloudTable cloudTable = tableClient.getTableReference(tableName);
       cloudTable.createIfNotExists();               

    }
    catch (Exception e)
    {
        // Output the stack trace.
        e.printStackTrace();
        System.out.println(e.getMessage());
        }
    }
}

代码似乎很容易理解。 它将连接到Azure表存储,如果不存在具有给定名称的表,则会创建它。 但我得到一个InvalidKeyException(下面粘贴了完整的异常)。

java.security.InvalidKeyException:Storage Key不是有效的base64编码字符串。
在com.microsoft.azure.storage.StorageCredentials.tryParseCredentials(StorageCredentials.java:68)
在com.microsoft.azure.storage.CloudStorageAccount.tryConfigureServiceAccount(CloudStorageAccount.java:408)
在com.microsoft.azure.storage.CloudStorageAccount.parse(CloudStorageAccount.java:259)
在com.azure.test.App.main(App.java:71)

我很惊讶使用Azure存储的人很少面临这个问题。 我尝试使用连接字符串中的编码密钥对存储密钥进行编码,但仍然没有用。

String encodedKey=Base64.encode(storageKey.getBytes())

String storageConnectionString =
            "DefaultEndpointsProtocol=http;" +
            "AccountName=accountname" + 
            "AccountKey="+encodedKey+
           "EndpointSuffix=table.core.windows.net;"; 

有人可以帮我这个吗? 我在谷歌搜索了很多,我能找到一个用户在铁饼上提出类似的问题,但没有提供答案,或者说答案没有帮助。


Using Azure Storage SDK for Java, I am trying to perform basic create, read, update, delete operations on Azure Table Storage as given in the link below: https://azure.microsoft.com/en-us/documentation/articles/storage-java-how-to-use-table-storage/

Sample program for creating a table:

package com.azure.test;
import java.io.UnsupportedEncodingException;
import com.microsoft.azure.storage.*;
import com.microsoft.azure.storage.table.CloudTable;
import com.microsoft.azure.storage.table.CloudTableClient;
import com.microsoft.windowsazure.core.utils.Base64;

public class App 
{

    public static void main( String[] args ) throws StorageException,    UnsupportedEncodingException
{

    String storageConnectionString =
            "DefaultEndpointsProtocol=http;" +
            "AccountName=accountname;" + 
            "AccountKey=storagekey;"+
           "EndpointSuffix=table.core.windows.net"; 

    try
    {
        // Retrieve storage account from connection-string.
        CloudStorageAccount storageAccount =
           CloudStorageAccount.parse(storageConnectionString);

        CloudTableClient tableClient =               storageAccount.createCloudTableClient();

      //Create the table if it doesn't exist.
       String tableName = "MyTable";
       CloudTable cloudTable = tableClient.getTableReference(tableName);
       cloudTable.createIfNotExists();               

    }
    catch (Exception e)
    {
        // Output the stack trace.
        e.printStackTrace();
        System.out.println(e.getMessage());
        }
    }
}

The code seems to be fairly simple to understand. It would connect to the Azure table storage and if a table with a given name does not exist it will create it. But I am getting a InvalidKeyException(full exception pasted below).

java.security.InvalidKeyException: Storage Key is not a valid base64 encoded string.
at com.microsoft.azure.storage.StorageCredentials.tryParseCredentials(StorageCredentials.java:68)
at com.microsoft.azure.storage.CloudStorageAccount.tryConfigureServiceAccount(CloudStorageAccount.java:408)
at com.microsoft.azure.storage.CloudStorageAccount.parse(CloudStorageAccount.java:259)
at com.azure.test.App.main(App.java:71)

I am surprised that not many people using Azure Storage are facing this issue. I tried to encode the storage key using and used the encoded key in the connection string but still no use.

String encodedKey=Base64.encode(storageKey.getBytes())

String storageConnectionString =
            "DefaultEndpointsProtocol=http;" +
            "AccountName=accountname" + 
            "AccountKey="+encodedKey+
           "EndpointSuffix=table.core.windows.net;"; 

Can anyone please help me with this? I searched in google a lot and I am able to find one user raised a similar issue on discus but there is no answer provided for that or rather that answer was not helpful.


原文:https://stackoverflow.com/questions/39351261
更新时间:2023-08-26 06:08

最满意答案

小记第一:你应该总是将Algolia与数据库结合使用,搜索引擎在数据库引擎应该处理的一些操作上做得很差。


使用Algolia facet排除,它绝对可行:

通过 - 运算符支持否定,为构面值添加前缀。
例如: encodeURIComponent('["category:Book","category:-Movie","author:John Doe"]')

摘自facetFilters的文档


对于您的示例,假设“Name”是attributesForFaceting一部分,您要执行的查询只是:

index.search('query', {
  facetFilters: 'Name:-John'
})

如果您正在使用algoliasearch-helper-js ,则使用的方法是addExcludeRefinement


最后,值得注意的是,如果您的属性是数字,则应使用numericFilters


Small note first: you should always use Algolia in conjunction with a database, a search engine will do a poor job on some operations that your database engine should handle.


Using Algolia facets exclusion, it's definitely doable:

Negations are supported via the - operator, prefixing the facet value.
For example: encodeURIComponent('["category:Book","category:-Movie","author:John Doe"]')

Extract from the documentation of facetFilters


For your example, assuming "Name" is part of attributesForFaceting, the query you want to do is simply:

index.search('query', {
  facetFilters: 'Name:-John'
})

If you're using algoliasearch-helper-js, the method to use is addExcludeRefinement.


Finally, it's worth noting that if your attribute was numerical, you should use numericFilters instead.

相关问答

更多
  • 等于 n == 1 不等于 n != 1 大于 n > 1 小于 n < 1 大于或等于 n >= 1 小于或等于 n <= 1
  • wifi系数据传送方式之一,本地数据指同本地服务器交换嘅数据,例如.com.hk,.edu.hk之类,如果只系.com就有可能系海外服务器数据。wifi可以由不同嘅数据机发出,包括你家用wifi,当你用wifi上网,你系用紧他人嘅数据服务,他要收费或免费或有条件系由他决定,就算你用自家wifi,你其实已经付费,wifi有效范围只得二三十米,原则上系用到就用,用不到就没有计。3g系用手电讯号传送数据,原则上你手电打到电话就可传送数据,用3g上台卡或预付通要付款,电讯商提供多种收费模式方便你选择,其中之一就系无 ...
  • 我用inner join查询,如果where条件用不等于,结果就查不出来,改成等于的话就能查出来,哪 位大虾能给解释一下吗?谢了! 逻辑问题,1对多 join的时候会出现这种情况,可以把某些where条件放到on后面试试
  • 您可以使用相同类型的语法对构面过滤器和标记过滤器执行OR操作。 您可以使用字符串中的括号或使用您编码的数组来执行此操作。 有关详细信息,请参阅REST API文档。 如果您使用API客户端,则实现可能会有所不同。 您应该查看特定的文档页面(例如PHP相关文档 ) You can do OR with facet filters and tag filters using the same kind of syntax. You can do that using parentheses in a strin ...
  • 为了更好地控制返回的数据类型,可以配置索引的attributesToRetrieve和attributesToHighlight 。 在这里查看attributesToRetrieve的文档。 编辑:另外,如果你不想让某个拥有Search API键的人访问某些属性,请使用unretrievableAttributes For better control over what kind of data is returned, you can configure the attributesToRetriev ...
  • 有重复,因为您没有使用objectID来唯一标识您的记录。 通常,主键可以作为objectID正常工作。 如果你没有指定一个,Algolia将自动分配一个,这意味着很难没有重复。 So this is embarrassing. I forgot about a staging server that was also contributing to the index.
  • Snycing Algolia中的数据同步和索引通常在后端完成(例如使用Node.js)。 在同步Cloud Firestore和Algolia的情况下,您需要使用Firestore事件才能听取Firestore中的新更改并在Algolia中进行适当更改(如其全文搜索文档中所述 ,该文档位于Node.js中) 。 搜索 为了在您的Android应用程序中从Algolia搜索您的数据,您需要使用在Android中编写的Algolia移动SDK(请参阅Android 入门 )。 如果您想查询您的Cloud Fi ...
  • 实际上有一种很好的方法可以使用“可选”方面过滤器来实现这种行为(即将发布的高级功能 - 截至2016/12/01)。 “可选构面过滤器”是一个构面过滤器,不需要匹配来检索结果,但是 - 默认情况下 - 确保首先检索具有构面值的命中(感谢Algolia的filters标准 -打破排名公式)。 这正是您想要的:在您想要的每个页面上,首先要检索共享category值的某些结果; 只需使用category:value可选构面过滤器查询Algolia索引。 确保您的category属性是attributesForFa ...
  • 从我可以看到你在status属性中有子属性id 。 所以你的记录看起来像这样: { "objectID": "eyJpZCI6OX0=", ... "status": { "id": 1 } } 正确? 在这种情况下,您还需要在facetFilters指定子属性。 在你的情况下,它看起来像这样: $searchResult = $this->get('algolia.indexer')->rawSearch(Professional, $data, [ 'hitsPerPa ...
  • 目前,这不是你能做的。 Algolia确实有一个deleteByQuery方法,它可以提供更多的灵活性,因为你可以传递过滤器 ,但是没有NOT IN过滤器。 一个解决方案是查询镜像索引的主数据库并从那里获取ID,然后将它们传递给Algolia。 Currently this isn't something you can do. Algolia does have a deleteByQuery method which gives you more flexibility because you can ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)