algorithmiaio / algorithmia-java Goto Github PK
View Code? Open in Web Editor NEWJava Client for Algorithmia Algorithms and Data API
Home Page: https://algorithmia.com/
License: MIT License
Java Client for Algorithmia Algorithms and Data API
Home Page: https://algorithmia.com/
License: MIT License
I have been unable to connect to Algorithmia after many different attempts. I even created a new key with full access. The call below throws the exception below.
final AlgorithmiaClient client = Algorithmia.client("MY_KEY");
Exception in thread "main" java.lang.NoSuchFieldError: DEFAULT
at org.apache.http.impl.nio.client.HttpAsyncClientBuilder.build(HttpAsyncClientBuilder.java:666)
at com.algorithmia.client.HttpClient.(HttpClient.java:79)
at com.algorithmia.AlgorithmiaClient.(AlgorithmiaClient.java:19)
at com.algorithmia.Algorithmia.client(Algorithmia.java:49)
at com.steele.algorithmia.DataAPI.main(DataAPI.java:19)
In this builder chain, the call to useSystemProperties()
effectively results in ignoring the values set by setMaxConnTotal(maxConnections)
and setMaxConnPerRoute(maxConnections)
. And this isn't order-dependent, because the actual properties used by the underlying client are determined during the call to build
with this code in the upstream Apache client
So I see basically 3 choices:
Stop calling useSystemProperties()
. This will require figuring out how to go back and add proxy support that motivated useSystemProperties
.
Explicitly call System.setProperty("http.keepAlive", "true")
and System.setProperty("http.maxConnections", maxConnections)
before building the client. (Somebody with a bit more java mastery wanna weigh in on the side affects of setting properties like this? Any risks to creating multiple AlgorithmiClient
instances with different connection pooling?). This also means that we have to accept that maxConnTotal
is always 2x the maxConnPerRoute
.
PR to try and convince upstream to replace that block with one where it only uses the system properties for those values if they weren't explicitly set. (I presume we could use the 2nd option in the meantime of waiting for such a PR to land.)
Wanna weigh in @kennydaniel, since I believe you green-lighted the useSystemProperties
change?
I get these errors when including the algorithmia jar in my pom file:
[WARNING] The POM for org.xerial.sbt:sbt-sonatype:jar:1.1 is missing, no dependency information available
[WARNING] The POM for com.jsuereth:sbt-pgp:jar:1.0.0 is missing, no dependency information available
This causes any maven build (compile/install/package etc) to fail when Algorithmia is included in the JAR, on machines with empty local .m2
repositories.
Upon further inspection, those two jars seem to be intended for deploying/publishing jar files to various repos. I don't think they're actually meant to be part of the library?
The main issue is that these libraries are unavailable on Maven's central repo. In fact xerial/sbt-pack#37 explicitly mentions that the library is not intended to support maven integration. So fresh Maven builds are unable to find the JAR and thus can't finish the build.
Currently I'm able to bypass this issue by manually excluding the two libraries:
<exclusion>
<groupId>org.xerial.sbt</groupId>
<artifactId>sbt-sonatype</artifactId>
</exclusion>
<exclusion>
<groupId>com.jsuereth</groupId>
<artifactId>sbt-pgp</artifactId>
</exclusion>
This doesn't seem to break anything and disables the warning. Again, my assumption is these two libraries aren't actually used in the Algorithmia code itself, and are only used in the deploy process. Hence, when they are mistakenly included as actual dependencies, maven builds will crash after being unable to find them. But, manually excluding them doesn't cause any problems since the classes aren't actually used.
I'm not sure if anything is actually wrong here, maybe this is intended. But I would really appreciate a second look since the exclusion workaround is not ideal!
Inside the https://algorithmia.com/algorithms/tags/AutoTagURL/edit algorithm, we have:
final String content = Algorithmia.algo("/util/Url2Text").pipe(url).as(new TypeToken(){});
(asJSonString behaves the same)
with UTF-8 characters, when we return content, we get �����������������.
Repro with: http://www.asahi.com/articles/ASH9C73RQH9CUTNB01W.html?iref=com_alist_6_01
I'm getting this exception while executing the example code found on your website.
Exception in thread "main" com.algorithmia.APIException: 308 unexpected API response:
at com.algorithmia.algo.Algorithm.pipeRequest(Algorithm.java:145)
at com.algorithmia.algo.Algorithm.pipe(Algorithm.java:96)
Have tried the same using cURL and everything works fine, even with python so my guessing it has something to do with HttpClient or Java itself.
[Details]
Thanks for any help you can provide.
Tomás.
In order to truly make more than 2 simultaneous async calls, must create multiple Algorithmia clients due to a limitation in the default httpasyncclient.
Current:
if(result.isFailure(){
AlgorithmException e = ((AlgoFailure)result).error
e.getMessage();
e.printStackTrace();
}
This isn't a good experience and does not surface all of the available data in the response
Needed:
if(result.isFailure(){
AlgoFailure fail = (AlgoFailure)result;
fail.getMessage();
fail.getStacktrace();
fail.getMetadata().getDuration();
fail.getMetadata().getStdout();
}
File file = Algorithmia.file(imageUrl).getFile();
Better error message needed for:
File file = Algorithmia.file(imageUrl).getFile();
throws:
Error: java.lang.IllegalArgumentException: Prefix string too short
java.lang.IllegalArgumentException: Prefix string too short
at java.io.File.createTempFile(File.java:2001)
at java.io.File.createTempFile(File.java:2070)
at com.algorithmia.data.DataFile.getFile(DataFile.java:47)
at algorithmia.sfw.NudityDetectionHelper.ObjectDetectionWithModels.apply(ObjectDetectionWithModels.java:39)
at algorithmia.sfw.NudityDetectionHelper.NudityDetectionHelper.apply(NudityDetectionHelper.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at algorithmia.runners.JavaRunner$.applyInput(JavaRunner.scala:234)
at algorithmia.runners.JavaRunner$.algorithmia$runners$JavaRunner$$tryNativeApply(JavaRunner.scala:185)
at algorithmia.runners.JavaRunner$$anonfun$applyString$1.apply(JavaRunner.scala:30)
at algorithmia.runners.JavaRunner$$anonfun$applyString$1.apply(JavaRunner.scala:27)
at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
at algorithmia.runners.JavaRunner$.applyString(JavaRunner.scala:27)
at algorithmia.runners.JarRunner.run(JarRunner.scala:52)
at algorithmia.runners.AlgoRunner$$anonfun$invoke$1.apply$mcV$sp(AlgoRunner.scala:27)
at algorithmia.runners.AlgoRunner$$anonfun$invoke$1.apply(AlgoRunner.scala:23)
at algorithmia.runners.AlgoRunner$$anonfun$invoke$1.apply(AlgoRunner.scala:23)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
If you use a dropbox or s3 connector, toString
will return a URI like data://s3://foo/bar
This line fails:
Algorithmia.client().file("data://.my/This is a valid filename ☘.txt").put("hi");
The client should perform a URLEncode operation prior to sending HTTP requests for data_uris
this simple call doesn't seem to work anymore:
AlgorithmiaClient cli = Algorithmia.client(GlobalVariables.ALGORITHMIA_KEY);
getting an error:
com.algorithmia.APIException: Host name 'api.algorithmia.com' does not match the certificate subject provided by the peer (CN=*.algorithmia.com)
at com.algorithmia.client.HttpClient.execute(HttpClient.java:244)
at com.algorithmia.client.HttpClient.execute(HttpClient.java:211)
at com.algorithmia.client.HttpClient.put(HttpClient.java:163)
at com.algorithmia.data.DataFile.put(DataFile.java:154)
at com.algorithmia.data.DataFile.put(DataFile.java:165)
at com.algorithmia.data.DataDirectory.putFile(DataDirectory.java:90)
It would be nice if the documentation for DataFile mentioned that these methods are blocking.
Also, I'm not sure what the intended usage of the put methods are. InputStreams are typically read from, whereas with the put method we are trying to write to the file. It seems much more "usual" to use an OutputStream, but you're clearly using an API that wants an InputStream.
Not sure how to write to a file using this API, and the documentation doesn't explain much.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.