Azure table storage service exception - java

I am trying to log some of my data to Azure table storage service and it was working fine till now. I am logging to Azure table storage using Java.
Suddenly from yesterday I am getting the error as below:
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
com.microsoft.azure.storage.table.TableServiceException
I read some articles on google https://github.com/Azure/azure-storage-net/issues/171 and it talks about blobs. I could not find anything related to table storage.
Can someone help me on this one? Code to access table is usual as below.
private CloudTable GetCloudTableContainer(String tableName) {
CloudTable table = null;
try {
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.parse(config.CONNECTION_STRING);
// Create the blob client.
CloudTableClient tableClient = storageAccount.createCloudTableClient();
// Retrieve a reference to a container.
table = tableClient.getTableReference(tableName);
table.createIfNotExists();
} catch (Exception ex) {
ex.printStackTrace();
}
return table;
}

Are you using shared acces signature(SAS)? Maybe it has expired?

Related

Facebook Java SDK | Marketing API Error #803

I am currently trying to use the Facebook Java SDK to publish ads automatically.
I am just attempting to test my API Authentication using the basic facebook demo code they have provided: https://developers.facebook.com/docs/business-sdk/getting-started/
Here is where I define my APIContext so that I can instantiate my AdAccount:
public static final APIContext context = new APIContext(
"{App Auth Token}",
"{App Secret}"
);
When I execute System.out.println(context.getAppID()); I am returned the ID of the App I have set up within developers.facebook. At this point I think everything is working as intended...?
I then attempt to execute the following code:
AdAccount account = new AdAccount("act_{10405322}", context);
try {
APINodeList<Campaign> campaigns = account.getCampaigns().requestAllFields().execute();
for(Campaign campaign : campaigns) {
System.out.println(campaign.getFieldName());
}
} catch (Exception e) {
e.printStackTrace();
}
}
My application keeps failing with this response:
com.facebook.ads.sdk.APIException$FailedRequestException: {"error":{"message":"(#803) Some of the
aliases you requested do not exist:
act_{10405322}","type":"OAuthException","code":803,"fbtrace_id":"A3uiRKVWUVQyMqZO9GIfWAY"}}
Could someone explain to me why this is the case? act_{10405322} is the ad account I am attempting to reach, so I am not sure why the "alias does not exist"
Thanks!
After rigorous testing, I found two issues that solved my error.
I was using a App Token rather than a Page Access Token
I changed act_{10405322} to act_10405322 and I finally got a successful response.

external LDAP connection using JpsContextFactory

I am trying to connect to an external weblogic embeded LDAP in Oracle ADF.
I've just found a good sample code that uses JpsContextFactory class, it doesnt get any url, username and password. it seems that it connects to local weblogic ldap by defult. I could not figure out how to set a connection to an external weblogic ldap using this class.
the sample code :
private void initIdStoreFactory() {
JpsContextFactory ctxFactory;
try {
ctxFactory = JpsContextFactory.getContextFactory();
JpsContext ctx = ctxFactory.getContext();
LdapIdentityStore idStoreService = (LdapIdentityStore) ctx.getServiceInstance(IdentityStoreService.class);
ldapFactory = idStoreService.getIdmFactory();
storeEnv.put(OIDIdentityStoreFactory.RT_USER_SEARCH_BASES, USER_BASES);
storeEnv.put(OIDIdentityStoreFactory.RT_GROUP_SEARCH_BASES, GROUP_BASES);
storeEnv.put(OIDIdentityStoreFactory.RT_USER_CREATE_BASES, USER_BASES);
storeEnv.put(OIDIdentityStoreFactory.RT_GROUP_CREATE_BASES, GROUP_BASES);
storeEnv.put(OIDIdentityStoreFactory.RT_GROUP_SELECTED_CREATE_BASE, GROUP_BASES[0]);
storeEnv.put(OIDIdentityStoreFactory.RT_USER_SELECTED_CREATE_BASE, USER_BASES[0]);
} catch (JpsException e) {
e.printStackTrace();
throw new RuntimeException("Jps Exception encountered", e);
}
}
any suggestion how to use this code to connect to external ldap will be appreciated.
JpsContextFactory is utilised to retrieve the current information of the identity store(s) inside weblogic. In order to use it with an external LDAP, you need first to add a new security provider in Weblogic and declare it as required in order for your application to utilise the new external ldap.
Check this old article of how to do it (http://www.itbuzzpress.com/weblogic-tutorials/securing-oracle-weblogic/configuring-oracle-weblogic-security-providers.html)

Check MongoDB server is running and credentials are valid in Java

I am programming an UI where a user should be able to put in the URL and port to check whether a mongoDB server is running. Furthermore he should be able to provide credentials when necessary.
If the server is not running or the credentials are wrong, I want to provide a message for each case. Similar questions have been answered here:
Check MongoDB authentication with Java 3.0 driver
how to check from a driver, if mongoDB server is running
Unfortunately they use older versions of the Java driver for mongo. I'm using the 3.2+ version of the MongoDB java driver, where i.e. getDB() is deprecated.
My "solution" for the problem looks somewhat like this:
try {
String database = "test";
MongoClient client = null;
if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) {
MongoCredential credentials = MongoCredential.createCredential(username, database, password.toCharArray());
client = new MongoClient(new ServerAddress(url, Integer.parseInt(port)), Arrays.asList(credentials));
}
else {
client = new MongoClient(url, Integer.parseInt(port));
}
MongoDatabase db = client.getDatabase(database);
db.listCollectionNames().first();
client.close();
return true;
}
catch (MongoCommandException | MongoSecurityException e) {
// program does not get in here when credentials are wrong,
// only when no credentials are provided, but necessary
}
catch (MongoSocketOpenException | MongoTimeoutException e) {
// only get in here after db.listCollectionNames().first() caused a timeout
}
How can I manage to:
Find out when mongoDB server is not running?
Find out that credentials are correct, when necessary?
Edit:
When credentials are wrong (username and/or password) the method catches only the MongoTimeoutException. It's the same when the the wrong URL or port or database is provided. To be clear there are other exceptions printed out, but not caught. Only difference is, when providing no password and no username, even though the database requires them, then the MongoCommandException is caught

Inserting data that is returned by calling a web service into SQL Server

I have created a web service client that calls the web service and returns the response. Now I have to insert that data into SQL server db. I am new to java and so need suggestions on how to do it. Can someone please share the link to a example or other procedures that explains this.
Edit:(Adding snippet from my code)
try {
stub = new WebServiceStub();
res6 = stub.getFile(getFile);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ArrayOfAttachmentData attach = res6.getFileResult().getAttachmentData();
AttachmentData[] attachment = attach.getAttachmentData();
for(int i=0;i<attachment.length;i++){
System.out.println("Attachment:" + i);
System.out.println("DateCreated:" + attachment[i].getCreateDate());
System.out.println("FileName:" + attachment[i].getFilename());
System.out.println("FileSize" + attachment[i].getFileSize());
System.out.println("FileSequence" + attachment[i].getSequence());
System.out.println("FileType" + attachment[i].getType());
}
Now how can i add all the dates,filenames,fileseqs,filetypes in my SQL Server table?
Thanks
This is little big for comment, You have to create Database, if you not already in sql server, and Table Structure to store data which you received from Web Service in Database. Create connection in your Java program and Follow article to go through.
Inserting data into an SQL database table with JDBC is a simple two-step process. Just
(1) create a Statement object, and
(2) use the object to run your normal SQL INSERT commands.
As per my suggestion, do some research. if you are new in programming.

Does SolrJ perform caching?

I'm using Solr in my web application as search engine. I use the DataImportHandler to automatically import data from my database into the search index. When the DataImportHandler adds new data, the data is successfully added to the index, but it isn't returned when I query the index using SolrJ: I have to restart my application server for the data to be found by SolrJ. Is there some kind of caching going on? I used SolrJ in embedded mode. Here's my SolrJ code:
private static final SolrServer solrServer = initSolrServer();
private static SolrServer initSolrServer() {
try {
CoreContainer.Initializer initializer = new CoreContainer.Initializer();
coreContainer = initializer.initialize();
EmbeddedSolrServer server = new EmbeddedSolrServer(coreContainer, "");
return server;
} catch (Exception ex) {
logger.log(Level.SEVERE, "Error initializing SOLR server", ex);
return null;
}
}
Then to query I do the following:
SolrQuery query = new SolrQuery(keyword);
QueryResponse response = solrServer.query(query);
As you can see, my SolrServer is declared as static. Should I create a new EmbeddedSolrServer for each query instead? I'm afraid that will incur a big performance penalty.
Standard configuration of Solr Server doesn't provide auto-commit. If you have solrconfig.xml file, look for the commented tag "autoCommit". If not, then after each document added you can call server.commit();, although with large stream of documents this could prove a big performance issue (as commit is relatively heavy operation).
If you are using it in a web application, I'd advise using solr-x.x.war in your deploy instead of EmbeddedSolrServer. This will provide you with rich Http interface for updating, administrating and searching the index.

Categories

Resources