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
最满意答案
小记第一:你应该总是将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 isaddExcludeRefinement
.
Finally, it's worth noting that if your attribute was numerical, you should use
numericFilters
instead.
相关问答
更多-
python语言中的n不等于1[2023-10-25]
等于 n == 1 不等于 n != 1 大于 n > 1 小于 n < 1 大于或等于 n >= 1 小于或等于 n <= 1 -
咩叫本地数据,,等不等于wifi??[2022-02-06]
wifi系数据传送方式之一,本地数据指同本地服务器交换嘅数据,例如.com.hk,.edu.hk之类,如果只系.com就有可能系海外服务器数据。wifi可以由不同嘅数据机发出,包括你家用wifi,当你用wifi上网,你系用紧他人嘅数据服务,他要收费或免费或有条件系由他决定,就算你用自家wifi,你其实已经付费,wifi有效范围只得二三十米,原则上系用到就用,用不到就没有计。3g系用手电讯号传送数据,原则上你手电打到电话就可传送数据,用3g上台卡或预付通要付款,电讯商提供多种收费模式方便你选择,其中之一就系无 ... -
inner join的条件不可以用不等于吗?[2022-02-18]
我用inner join查询,如果where条件用不等于,结果就查不出来,改成等于的话就能查出来,哪 位大虾能给解释一下吗?谢了! 逻辑问题,1对多 join的时候会出现这种情况,可以把某些where条件放到on后面试试 -
Algolia或条件(Algolia OR Condition)[2022-12-13]
您可以使用相同类型的语法对构面过滤器和标记过滤器执行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 ...
-
Algolia重复(Algolia Duplicates)[2023-08-28]
有重复,因为您没有使用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 ...
-
Algolia条件搜索(Algolia conditional search)[2023-03-28]
从我可以看到你在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 ...