Accessing Jira Cloud using Unirest Java libraries - httpclient

I would like to use Unirest Java libraries for accessing Jira Cloud.
Can you share any code snippets? Thank you.

First add the Unirest dependency to your pom.xml (for Maven):
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.9</version>
</dependency>
Then use the following syntax to query JIRA Cloud. Replace yourjira with your instance name and replace with your username and password.
HttpResponse<JsonNode> response = Unirest.get("https://yourjira.atlassian.net/rest/api/2/search?jql=").basicAuth("username","password").asJson();
System.out.println(response.getBody());
More specific JIRA Cloud REST API syntax can be found here:
https://docs.atlassian.com/jira/REST/cloud/

Related

Quarkus: MicroProfile metrics and Graphite

Is there a way to send microprofile metrics to graphite directly? The only guide with Quarkus I've found is this https://quarkus.io/guides/microprofile-metrics. I'm looking for something similar to what I'm using with Spring Boot https://micrometer.io/docs/registry/graphite. Do we have the same thing but in the Quarkus context (with native image support)?
The micrometer extension is recommended for metrics, and it has support for Graphite via a quarkiverse extension:
<dependency>
<groupId>io.quarkiverse.micrometer.registry</groupId>
<artifactId>quarkus-micrometer-registry-graphite</artifactId>
</dependency>
That's the quarkus issue that people can follow and give feedback https://github.com/quarkusio/quarkus/issues/10525

keycloak admin client on JBOSS AS 7

I am not able to call keycloak-admin-client from JBOSS AS 7.1 REST endpoint. I am able to call the same service from JUNIT test, but when I try to do the same thing from REST endpoint I am having the error:
Caused by:com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "access_token" (class org.keycloak.representations.AccessTokenResponse), not marked as ignorable
I am having the same error in JUNIT test when I change the dependency from jackson2 -> jackson
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>3.0.7.Final</version>
</dependency>
I guess its somehow connected with Jackson provider, but I tried everything from excluding jackson in deployemnt structure to using different, older version of keycloak admin client and keycloak-adapter-bom (2.5.5 or 3.4.3).
<module name="org.jboss.resteasy.resteasy-jackson-provider"/>
Can anybody provide working pom.xml for keycloak-admin-client for JBOSS AS 7.1 ?
Many thanks
Thank you #ravthiru for your response.
The problem was more prozaic and simple. I have put the rest endpoint inside the war module, which is secured by keycloak adapter and that prevents the calls to any REST endpoint from outside. I have create separate war module for all REST endpoints associated with Keycloak and it works like charm. Before I called the keycloak admin client just via Unit tests, which means inside from war module and therefore I havent encountered the problem. But it cost me few days to realized where is the problem, cause I was sure it was because of jackson2.
My shame. Cheers.

Connect MobileFirst Application with DB2

I am using Mobilefirst 8.0. I wanted to connect my hybrid application to DB2 database and create table in that and retrieve data from this. I just came to know after reading some documents that have to use sql adapter. but
1) how to configure and add external dependancies of JDBC driver?
2) Can I do this from my local developer server?
Please any one can guide me.
You have several questions there...
I wanted to connect my hybrid application to DB2 database and create table in that
To create a DB2 database and table in it, you need to install DB2 and create a table in it. This is not related to IBM MobileFirst. Consult the DB2 documentation.
... and retrieve data from this. I just came to know after reading some documents that have to use sql adapter.
In IBM MobileFirst Foundation 8.0 you can create either a Java adapter or a JavaScript adapter, depending on your proficiency and your project requirements.
In a Java adapter it is expected that you will create and handle the database connection as is standard in Java programming.
Read more about creating Java adapters: https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/adapters/java-adapters/
Read more about SQL in Java adapters: https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/adapters/java-adapters/java-sql-adapter/
In JavaScript adapters, MobileFirst Server takes care of many aspects, but you still need to do some minimal configurations, such as providing the database URL, and the username and password for it.
Read more about JavaScript adapters: https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/adapters/javascript-adapters/
Read more about SQL JavaScript adapters: https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/adapters/javascript-adapters/js-sql-adapter/
About retrieving data and display it, etc, there are plenty of existing questions about this in Stack Overflow. Simply search for some implementation pointers.
How to configure and add external dependancies of JDBC driver
In MobileFirst Foundation 8.0 adapters are actually Maven projects. As such dependencies such as database connectors are handled via the Maven dependencies mechanism.
Learn more about adapters in general: https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/adapters/
Learn how to creating adapters and adding dependencies: https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/adapters/creating-adapters/
Since you're using DB2, you need to search the Maven repository for a DB2 connector and add it to your adapter's pom.xml file, then build the adapter to verify that it manages to pull the connector and that there are no compilation errors.
The example SQL adapter provided in the links above defined a connector for a MySQL database in its pom.xml. You can base your adapter on the changes made in that sample adapter.
For example:
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc</artifactId>
<version>3.8.47</version>
</dependency>
<dependency>
<groupId>com.ibm.db2.jcc</groupId>
<artifactId>db2jcc_license_cu</artifactId>
<version>3.8.47</version>
</dependency>
Can I do this from my local developer server?
This is not related to the server. It is all done in the adapter.

IBM Watson Visual Recognition in Java

I want to use IBM Watson Visual Recognition for my android app and want to call APIs in JAVA but i don't find any example or any reference to the list of methods in JAVA to use this service. You can see the JAVA examples are missing here. Please help me to find few suitable examples or any reference to these methods. Please also tell me what is bluemix platform and is it necessary to use it in order to use IBM Watson Visual Recognition? Thanks in Advance!
Look at the Java SDK, and in particular the Visual Recognition example, which mimics the use case from the demo (node source code/training images for that here).
I am a developer evangelist for IBM Watson Developer Cloud.
You need to:
Install the Java-SDK 3.3.0
Create an instance of the Visual Recognition service in Bluemix.
Update the snippet below with the username and password you get when you create the service in Bluemix.
Code:
public class VisualRecognitionExample {
public static void main(String[] args) {
VisualRecognition service = new VisualRecognition("2016-05-20");
service.setUsernameAndPassword("<username>", "<password>");
System.out.println("Classify using all the classifiers");
options = new ClassifyImagesOptions.Builder()
.images(new File("car.png"))
.build();
result = service.classify(options).execute();
System.out.println(result);
}
}
Check this tutorial (https://developer.ibm.com/recipes/tutorials/estimate-a-childs-age-based-on-photos-using-watson-visual-recognition/).
It uses an outdated version of the Watson Java SDK (https://github.com/watson-developer-cloud/java-sdk) so the code may has changed a little, but it's basically that.
In order to use Visual Recognition, you can use a regular bluemix account, so you can use the Watson Visual Recognition API
update
use this POM
<dependencies>
<dependency>
<groupId>com.ibm.watson.developer_cloud</groupId>
<artifactId>java-sdk</artifactId>
<version>3.0.0-RC1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
I checked with curl first and found solution with java you can use following code:
Used:OkClient3 jar
OkHttpClient client = new OkHttpClient();
File file = new File(String.valueOf(path));
RequestBody formBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("image_file", "images.jpeg", RequestBody.create(MediaType.parse("image/jpeg"), file))
.build();
Request request = new Request.Builder().url(new URL("https://gateway-a.watsonplatform.net/visual-recognition/api/v3/collections/{classifier_id}/find_similar?limit=100&api_key=YOUR_API&version=2016-05-20")).post(formBody).build();
Response response = client.newCall(request).execute();
if (!response.isSuccessful())
throw new Exception("Unexpected code " + response);
System.out.println(response.message());
jsonString = response.body().string().toString();
System.out.println(jsonString);

Adding security to rest api service built with Spring Boot app

I have managed to build a rest api using Spring boot actuator & it works well. I need to now add security to the application and found a link which indicated that all that needs to be done, is to add the following to the pom file:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
I tried that and did not get the expected result which was to see the following in the console;
Using default security password: 7dfsdg4d0-4dfsdfsd93-dsdf9f8-axxe1-xxxxxx
Any suggestions or links to solutions, would be appreciated.
I have done this before and it works although I think some versions of Spring Boot have had an issue with this one feature. I was playing with it a little bit and if you copied any of the samples it is possible that you have some other configuration that you have is overriding it. I think this link has good info. Look to ensure you don't have anything in your properties file like "security.user.password" and that you don't have any annotations like #EnableWebSecurity that override any defaults. Let me know if that is helpful and if not maybe you can send a link to GitHub where your code is for someone to take a look.