Firebase Dynamics Links java client connection - java

Recently I had some task to integrate open source url short service.
I had choose firebase dynamic links by google , i did not managed to find some decent how to tutorial or quick start.
I have managed to execute the service and get the answer.
I would like to get some improvement suggestions for client initialization.
gradle dependency used
compile 'com.google.apis:google-api-services-firebasedynamiclinks:v1-rev860-1.25.0'
code
FirebaseDynamicLinks.Builder builder = new FirebaseDynamicLinks.Builder(GoogleNetHttpTransport.newTrustedTransport(),
JacksonFactory.getDefaultInstance(), null);
FirebaseDynamicLinksRequestInitializer firebaseDynamicLinksRequestInitializer = new FirebaseDynamicLinksRequestInitializer(
"***WEB_API_KEY***");
builder.setApplicationName("***Fire_Bass_Dummy_App***");
builder.setFirebaseDynamicLinksRequestInitializer(firebaseDynamicLinksRequestInitializer);
FirebaseDynamicLinks firebasedynamiclinks = builder.build();
CreateShortDynamicLinkRequest createShortLinkRequest = new CreateShortDynamicLinkRequest();
createShortLinkRequest.setLongDynamicLink("***Dynamic_Links_domain***?link=***long_link***");
Suffix suffix = new Suffix();
suffix.setOption("SHORT");
createShortLinkRequest.setSuffix(suffix);
FirebaseDynamicLinks.ShortLinks.Create request = firebasedynamiclinks.shortLinks().create(createShortLinkRequest);
CreateShortDynamicLinkResponse createShortDynamicLinkResponse = request.execute();

Related

Creating EKS cluster by using Java application

everyone I am new to AWS SDK. I am trying to create an EKS cluster from my java application.
I have used this eksctl create cluster command to create a cluster and I have also done this by using cluster templates.
I have tried to use AWS SDK to create clusters but that didn't work and have no idea how to go with it.
If anyone of you has a good sample code or explanation of using AWS SDK for creating a cluster using cluster template or anything which can help me to reach there would be helpful.
here i provide you a sample of Java code. i wish its serve your purpose on eks cluster creation:
String accessKey = "your_aws_access_key";
String secretKey = "your_aws_secret_key";
AWSCredentials credentials = new BasicAWSCredentials (accessKey, secretKey);
ClientConfiguration clientConfig = new ClientConfiguration ();
clientConfig.setProtocol (Protocol.HTTPS);
clientConfig.setMaxErrorRetry (DEFAULT_MAX_ERROR_RETRY);
clientConfig.setRetryPolicy (new RetryPolicy (PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION,
DEFAULT_BACKOFF_STRATEGY, DEFAULT_MAX_ERROR_RETRY, false));
AmazonEKS amazonEKS = AmazonEKSClientBuilder.standard ()
.withClientConfiguration (clientConfig)
.withCredentials (new AWSStaticCredentialsProvider (credentials))
.withRegion ("us-east-1") //replace your region name
.build ();
CreateClusterResult eksCluster = amazonEKS.createCluster (
new CreateClusterRequest ().withName ("cluster-name") //with other param
);

How to know if a reindex from remote task is sucessful or failed in elasticsearch using the java high level rest API

I'm using the ElasticSeach highlevel rest api client to do some custom reindexing from another cluster.
ReindexRequest reindexRequest = new ReindexRequest()
.setMaxDocs(3000)
.setDestIndex("my-new-index")
.setTimeout(TimeValue.timeValueHours(1))
.setRemoteInfo(
new RemoteInfo("http", "otherhost", 9200, "/",
new BytesArray(selectQuery.toString()), "user",
"password",
Map.of()), TimeValue.timeValueSeconds(30),
TimeValue.timeValueSeconds(30)))
.setSourceIndices("old-index")
.setScript(new Script(ScriptType.STORED, null, "add_sc_id", Map.of("sc_id", some-id)));
TaskSubmissionResponse task = esClient.submitReindexTask(reindexRequest, RequestOptions.DEFAULT);
I periodically check the task to see if it's done or not using the task API
Optional<GetTaskResponse> getTaskResponse =
esClient.tasks().get(new GetTaskRequest(nodeId, taskId), RequestOptions.DEFAULT);
Using this, I can see if the task is completed with getTaskResponse.get().isCompleted() but I don't see anyway to check if it's successful or not.
By doing the GET _taks/nodeId:taskId with curl, I see there is a response.failures field.
Is there a way to retrieve this field with the Java High level rest api client? Or is there another way to achieve this?
Please check List Task API.
You can use below Java code for geeting task Failure information:
ListTasksRequest request = new ListTasksRequest();
request.setActions("cluster:*");
request.setNodes("nodeId1", "nodeId2");
request.setParentTaskId(new TaskId("parentTaskId", 42));
ListTasksResponse responseTask = client.tasks().list(request,RequestOptions.DEFAULT);
List<TaskOperationFailure> taskFailures = response.getTaskFailures();

How to verify that a queue exist on azure in java?

We have a service that receive the queue name and if the queue exist push data on the queue.
I'm looking to find a way to check if the queue exist on azure in java.
So far, using IQueueClient I can onl know if the queue exist when sending data via sendAsync with return a exception.
I want to found out when the client is created or even before.
The best answer I've found so far is using the NamespaceManager.
in this fashion:
Uri uri = ServiceManagementHelper.GetServiceUri();
TokenProvider tokenProvider = ServiceManagementHelper.GetTokenProvider(uri);
NamespaceManager nm = new NamespaceManager(uri, tokenProvider);
if (!nm.QueueExists("TestQueue")) return;
source:
http://www.cloudcasts.net/devguide/Default.aspx?id=12018
https://www.pmichaels.net/2017/06/11/reading-message-azure-service-bus-queue/
However this class seem not to be part of azure-core or azure-servicebus librairy and I can seem to find which lib to add to the project to have access to those class.
However this class seem not to be part of azure-core or azure-servicebus librairy and I can seem to find which lib to add to the project to have access to those class.
You mentioned code is related to .net SDK. For Java sdk we could use the following code check if the queue exist. ManagementClient seems only available in the 2.0.0-PREVIEW version. We also could get the source code from GitHub.
String connectionString = "Endpoint=sb://xxxx.servicebus.windows.net/;SharedAccessKeyName=SharedAccessKeyName;SharedAccessKey=xxxxxxxx=";
ConnectionStringBuilder connectionStringBuilder = new ConnectionStringBuilder(connectionString);
ManagementClient client = new ManagementClient(connectionStringBuilder);
boolean isExist = client.queueExists("queueName");
System.out.println(isExist);
Test Result:

XStorable storeToURL and WebDav

I have seen multiple threads regarding the use of XStorable.storeToURL and vnd.sun.star.webdav://domain:8080//path/to/document_library to save OO documents to a webdav library folder. However, I have not seen a posting where someone has successfully used this in Java. While the use of the UCB vnd.sun.star.webdav://domain:8080//path/to/document_library/doc.odt works when using the File, Save menu options within OO Writer, I am prompted for a username and password. Supplying user and password via vnd.sun.star.webdav://user:password#domain:8080/ has not worked for me. I need to use this method from within a Java class to save a OO document. Has anyone had success using the following or something similar?
xStorable.storeToURL("vnd.sun.star.webdav://domain:8080/path/to/document_library/doc.odt", storeProps)
In the OO Developer's Guide, there is a paragraph regarding WebDav authentication:
DAV resources that require authentication are accessed using the interaction handler mechanism of the UCB. The DAV content calls an interaction handler supplied by the client to let it handle an authentication request. The implementation of the interaction handler collects the user name or password from a location, for example, a login dialog, and supplies this data as an interaction response.
Maybe this is related to the issue? If so, how to use an interaction handler for the authentication when trying to storeToURL via webdav?
Adding InteractionHandler was the issue. With this added, documents can be saved via storeToURL and passing the handler in as an argument:
String oooExeFolder = "C:/OpenOffice/program";
XComponentContext xLocalContext = BootstrapSocketConnector.bootstrap(oooExeFolder);
Object serviceManager = xLocalServiceManager.createInstanceWithContext("com.sun.star.task.InteractionHandler", xLocalContext);
XInteractionHandler xHandler = (XInteractionHandler)UnoRuntime.queryInterface( XInteractionHandler.class, serviceManager);
PropertyValue[] storeProps = new PropertyValue[1];
storeProps[0] = new PropertyValue();
storeProps[0].Name = "InteractionHandler";
storeProps[0].Value = xHandler;
xStorable.storeToURL("vnd.sun.star.webdav://domain:8080/path/to/document_library/doc.odt", storeProps);

Getting java.lang.RuntimeException: Unable to complete the HTTP request while uploading document

I am getting timeout error while I am trying to upload document using com.google.gdata.client.docs.DocsService
here is the code I am using:
DocumentListEntry documentEntry = new DocumentEntry();
documentEntry.setTitle(new PlainTextConstruct("new document"));
documentEntry.setMediaSource(new MediaByteArraySource(out.toByteArray(), mimeType));
DocumentListEntry uploadedEntry = service.insert(new URL("https://docs.google.com/feeds/default/private/full/"), documentEntry); <-- timeout at this point.
Timeout while fetching: https://docs.google.com/feeds/default/private/full/
I am running application in debug mode using app engine sdk in eclipse.
I think it is a very old thread, but just saw it while replying another question. I hope you have resolved it by now.
If not, then is your service authenticated and are you able to create a simple document e.g.
String title = "Doc Create Test";
DocumentListEntry newEntry = new DocumentEntry();
newEntry.setTitle(new PlainTextConstruct(title));
newEntry = service.insert(feedUrl, newEntry);

Categories

Resources