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);
Related
I want to add a web service to an already existing web application. This application runs on a specific version of Apache TomEE (apache-tomee-web-profile-1.7.2) and an upgrade is not possible.
I'm trying to deploy this sample application on this TomEE, just to try it. I see no errors in the logs
I manage to see the home page of the application :
This is the code for the ressource :
#Path("/pojo")
public class SimpleRESTPojo {
#GET
public String pojo() {
return "pojo ok # " + new Date().toString();
}
}
And the code of the rest application :
#ApplicationPath("/rest-prefix")
public class ApplicationConfig extends Application {
#Override
public Set<Class<?>> getClasses() {
return new HashSet<Class<?>>(Arrays.asList(SimpleRESTPojo.class, SimpleRESTEJB.class));
}
}
So far I've tried :
base/rest-prefix/pojo,
base/rest-prefix/pojo/pojo, base/pojo all giving me 404 errors
base is the url where I manage to see the home page
I managed to find a solution which I'm quite happy with. Turns out what I wanted to do is pretty much impossible. As mentionned in
this other stackoverflow post Web Profile is a subset of Java EE that usually does not contains the required libraries to create a REST WS.
I ran the Rest Sample application on a TomEE jaxrs version and it works as expected. I then copied the few libs that are included in TomEE-jaxrs and not in TomEE-webprofile into my original server lib folder.
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/
I am developing an app with JAX-RS. The app is running fine on my local Liberty 8.5 Server. It fails when I package and push the server to bluemix. When I try to access my method I get the error:
"NetworkError: 415 Unsupported Media Type"
The system cannot find any method in the class that consumes null media type.
My web.xml looks like the following:
<!-- Enable features -->
<featureManager>
<feature>jsp-2.2</feature>
<feature>localConnector-1.0</feature>
<feature>jdbc-4.0</feature>
<feature>cdi-1.0</feature>
<feature>json-1.0</feature>
<feature>jaxrs-1.1</feature>
<feature>jpa-2.0</feature>
</featureManager>
I searched a lot. Somebody had the same question said it's problem about jaxrs-1.1 which should be updated to jaxrs-2.0, but I don't know how to update it. It's default in Liberty 8.5 Server.
Can anybody help me? It's the first time I ask in stackover
Sorry, I'm not good at English.
Somebody had the same question said it's problem about jaxrs-1.1 which should be updated to jaxrs-2.0, but I don't know how to update it. It's default in Liberty 8.5 Server.
I hope this will be useful for you.
Using JAX-RS 2 Client API in Liberty and Bluemix
Removing JAX-RS feature from Websphere Application Server 8.5
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.
Is there anyway to use google-cloud-storage APIs in VS 2008?
It shows Google.Apis.dll was built by newer version so can not run on my project when i trying to build my project.
I was trying to test the APIs from Google Cloud Storage.
var googleClientService = new BaseClientService.Initializer();
googleClientService.ApiKey = "ABcdefghUSftzxcvbnmEhLmGcZnfcE_12345678";
var storageService = new StorageService(googleClientService);
var getRequest = storageService.Buckets.List("demotest");
Sorrry, I don't believe there's a pre-built .NET client available for early versions of .NET. The source code of the library is public, though. You could perhaps try and build it, if you feel like a challenge. Alternately, the library is simply a small wrapper around a public, RESTful API. You could also invoke the Google Cloud Storage API directly with standard HTTP libraries, although you'll have to handle authorization.