Recently,I use google cloud vision api for detecting image label ,follow this
,I set up the credentials for my application to authenticate its identity to the service and obtain authorization to perform task,then follow the API Documentation ,write code like this:
ImageAnnotatorClient vision= ImageAnnotatorClient.create();
ByteString imgBytes = ByteString.readFrom(new FileInputStream("my_image_path.jpg"));
List<AnnotateImageRequest> requests = new ArrayList<AnnotateImageRequest>();
Image img = Image.newBuilder().setContent(imgBytes).build();
Feature feat = Feature.newBuilder().setType(Type.LABEL_DETECTION).build();
AnnotateImageRequest request = AnnotateImageRequest.newBuilder()
.addFeatures(feat)
.setImage(img)
.build();
requests.add(request);
BatchAnnotateImagesResponse response = vision.batchAnnotateImages(requests);
List<AnnotateImageResponse> responses = response.getResponsesList();
for (AnnotateImageResponse res : responses) {
if (res.hasError()) {
System.out.printf("Error: %s\n", res.getError().getMessage());
return;
}
for (EntityAnnotation annotation : res.getLabelAnnotationsList()) {
annotation.getAllFields().forEach((k, v)->System.out.printf("%s : %s\n", k, v.toString()));
}
}
I get error :
Exception in thread "main" com.google.api.gax.grpc.ApiException: io.grpc.StatusRuntimeException: DEADLINE_EXCEEDED
at com.google.api.gax.grpc.ExceptionTransformingCallable$ExceptionTransformingFuture.onFailure(ExceptionTransformingCallable.java:109)
at com.google.api.gax.core.ApiFutures$1.onFailure(ApiFutures.java:52)
at com.google.common.util.concurrent.Futures$6.run(Futures.java:1310)
at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:457)
at com.google.common.util.concurrent.ExecutionList.executeListener(ExecutionList.java:156)
at com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:145)
at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:202)
at io.grpc.stub.ClientCalls$GrpcFuture.setException(ClientCalls.java:466)
at io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:442)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:481)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$600(ClientCallImpl.java:398)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:513)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:52)
at io.grpc.internal.SerializingExecutor$TaskRunner.run(SerializingExecutor.java:154)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
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)
Caused by: io.grpc.StatusRuntimeException: DEADLINE_EXCEEDED
at io.grpc.Status.asRuntimeException(Status.java:545)
... 13 more
why?
Related
I have this web service
HttpHost proxy = new HttpHost("10.2.0.111", 3128);
Unirest.setProxy(proxy);
HttpResponse<String> response = Unirest.post(service+this.user)
.header("Authorization", "Bearer "+this.token)
.header("Content-Type", "application/xml")
.body(getXML(invoice))
.asString();
When I test it I got the following error :
org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: org/apache/http/nio/conn/NHttpClientConnectionManager
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:982)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
I have included httpasyncclient-4.0-beta4.jar in my Java Build Path in Eclipse but it doesnt change anything. Any idea how to solve the problem ?
I have written the following rule in sbt to delete a directory but the code doesn't delete the directory. What I am doing wrong?
def clearOldUiBuild(implicit dir:File):Boolean = {
println(s"Deleting ui directory. Implicit directory ${dir}")
val uiBuildDirectory = dir / "public/ui"
println(s"ui build path ${uiBuildDirectory}")
val directoryExists = uiBuildDirectory.exists() && uiBuildDirectory.isDirectory()
println(s"ui exists? ${directoryExists}")
if(directoryExists){
println(s"deleting directory ${uiBuildDirectory}")
val retExecutable = uiBuildDirectory.setExecutable(true)
val retRead = uiBuildDirectory.setReadable(true)
val retWrite = uiBuildDirectory.setWritable(true)
println(s"set executable result ${retExecutable}, ${retRead}, ${retWrite}")
val ret = uiBuildDirectory.delete()
println(s"delete result ${ret}")
ret
} else {
println(s"directory doesn't exist")
true
}
}
output
[IJ][projectname] $ clear-old-ui-build
Deleting ui directory. Implicit directory C:\...frontend\web
ui build path C:\...\frontend\web\public\ui
ui exists? true
deleting directory C:\..\ui
set executable result true, true, false
delete result false
[trace] Stack trace suppressed: run 'last *:clearOldUiBuild' for the full output.
[error] (*:clearOldUiBuild) java.lang.Exception: Oops! UI Build crashed.
[error] Total time: 0 s, completed 08-Jan-2021 18:26:44
[IJ][myproject] $ last *:clearOldUiBuild
java.lang.Exception: Oops! UI Build crashed.
at $6ac9788b23c613fff84d$$anonfun$$sbtdef$1.apply(C:\...\frontend\web\build.sbt:341)
at $6ac9788b23c613fff84d$$anonfun$$sbtdef$1.apply(C:\...\build.sbt:339)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
at sbt.std.Transform$$anon$4.work(System.scala:63)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
at sbt.Execute.work(Execute.scala:237)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
[error] (*:clearOldUiBuild) java.lang.Exception: Oops! UI Build crashed.
So I have an app which writes sensor data to a csv file via FileOutputStream in MODE_PRIVATE
FileOutputStream fos = null;
try {
fos = context.openFileOutput(FILE_NAME,Context.MODE_PRIVATE);
for(int i = 0; i< signalList.size(); i++){
Signal s = signalList.get(i);
fos.write(s.toString().getBytes());
}
Log.d("WRITESTATUS","Success");
}
Now I wanted to share this file with other apps (whatsapp,email etc.). To achieve that, I am using the code below to share the intent. I was trying to use MODE_WORLD..something but that didn't work because it was deprecated so I learned through the other stackoverflow questions that we need to use FileProvider to make that happen but that didn't work either.
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("*/*");
File file = getFileStreamPath(FILE_NAME);
Uri uri = FileProvider.getUriForFile(this,"com.example.writefile",file);
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(sharingIntent, "Share SENSOR Data"));
<provider
android:authorities="com.example.writefile"
android:name="androidx.core.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_path"/>
</provider>
ERROR LOG
2020-06-22 16:27:34.047 6578-6578/? E/ample.writefil: Unknown bits set in runtime_flags: 0x8000
2020-06-22 16:27:34.147 6578-6578/com.example.writefile E/libc: Access denied finding property "vendor.iop.enable_uxe"
2020-06-22 16:27:36.043 6578-6578/com.example.writefile E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.writefile, PID: 6578
java.lang.IllegalStateException: Could not execute method for android:onClick
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:402)
at android.view.View.performClick(View.java:7158)
at android.view.View.performClickInternal(View.java:7135)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27373)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:235)
at android.app.ActivityThread.main(ActivityThread.java:7441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:397)
at android.view.View.performClick(View.java:7158)
at android.view.View.performClickInternal(View.java:7135)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27373)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:235)
at android.app.ActivityThread.main(ActivityThread.java:7441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
Caused by: java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.example.writefile/files/sensor.csv
at androidx.core.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:744)
at androidx.core.content.FileProvider.getUriForFile(FileProvider.java:418)
at com.example.writefile.MainActivity.Clicked(MainActivity.java:266)
at java.lang.reflect.Method.invoke(Native Method)
at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:397)
at android.view.View.performClick(View.java:7158)
at android.view.View.performClickInternal(View.java:7135)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27373)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:235)
at android.app.ActivityThread.main(ActivityThread.java:7441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
Change this and it will work- I have taken hint from here and tried different configuration and this works, I don't know why.
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path
name="sensor"
path="."/>
</paths>
I am trying to do a contract upgrade after I successfully authorised, I try to initiate the upgrade flow, but the counterparty is hitting an exception. So I'm wondering when/why this is happening.
At the springboot API
val states = queryUnconsumed<ObligationV1>
// Initiate upgrade contract flow.
states.forEach {
val flowInitiate = services.startFlow({ stateAndRef, upgrade -> ContractUpgradeFlow.Initiate(stateAndRef, upgrade) }, it , ObligationContractV2::class.java)
val resultInitiate = flowInitiate.returnValue.getOrThrow()
}
In ContractUpgradeHandler
// Wouldn't this tx always be of type upgrade tx?
val oldStateAndRef = ourSTX!!.tx.outRef<ContractState>(proposal.stateRef.index)
But in SignedTransaction.kt
** Returns the contained [WireTransaction], or throws if this is a notary change or contract upgrade transaction. */
val tx: WireTransaction get() = coreTransaction as WireTransaction
[WARN ] 2018-08-20T10:25:03,573Z [Node thread-1] flow.[fe5bf9ea-fafc-40b6-9b51-31caaa4ee513].run - Terminated by unexpected exception {}
java.lang.ClassCastException: net.corda.core.transactions.ContractUpgradeWireTransaction cannot be cast to net.corda.core.transactions.WireTransaction
at net.corda.core.transactions.SignedTransaction.getTx(SignedTransaction.kt:62) ~[corda-core-corda-3.0.jar:?]
at net.corda.node.services.ContractUpgradeHandler.verifyProposal(CoreFlowHandlers.kt:57) ~[corda-node-corda-3.0.jar:?]
at net.corda.core.flows.AbstractStateReplacementFlow$Acceptor.call(AbstractStateReplacementFlow.kt:149) ~[corda-core-corda-3.0.jar:?]
at net.corda.core.flows.AbstractStateReplacementFlow$Acceptor.call(AbstractStateReplacementFlow.kt:129) ~[corda-core-corda-3.0.jar:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:96) [corda-node-corda-3.0.jar:?]
at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:44) [corda-node-corda-3.0.jar:?]
at co.paralleluniverse.fibers.Fiber.run1(Fiber.java:1092) [quasar-core-0.7.9-jdk8.jar:0.7.9]
at co.paralleluniverse.fibers.Fiber.exec(Fiber.java:788) [quasar-core-0.7.9-jdk8.jar:0.7.9]
at co.paralleluniverse.fibers.RunnableFiberTask.doExec(RunnableFiberTask.java:100) [quasar-core-0.7.9-jdk8.jar:0.7.9]
at co.paralleluniverse.fibers.RunnableFiberTask.run(RunnableFiberTask.java:91) [quasar-core-0.7.9-jdk8.jar:0.7.9]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_181]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_181]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_181]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:1.8.0_181]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_181]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_181]
at net.corda.node.utilities.AffinityExecutor$ServiceAffinityExecutor$1$thread$1.run(AffinityExecutor.kt:62) [corda-node-corda-3.0.jar:?]
The error message is pretty straight forward that it looks like you are trying to cast a ContractUpgradeWireTransaction to WireTransaction somewhere in your code.
Here is our recent tutorial on how to implement a contract upgrade on Corda: https://medium.com/corda/contract-upgrades-and-constraints-in-corda-425055a9a47f
and here is the video tutorial: https://www.youtube.com/watch?v=rWyJRaoWNhc
I have an embedded video playing in the background of a web page, pretty much like how it is in www.airbnb.com
<div class="fullwidthbanner">
<video id="#myvideo" loop="loop" muted="muted" autoplay="autoplay">
<source th:src="#{/videos/cignme.mp4}" type="video/mp4" />
</video>
</div>
However after an initial play of may 10 seconds or so, the video blacks out and page goes unresponsive, and I see the following logs
2015-03-28 17:17:33.854 WARN 5109 --- [tp1590404373-40] org.eclipse.jetty.server.HttpChannel : /videos/cignme.mp4
java.io.IOException: java.util.concurrent.TimeoutException: Idle timeout expired: 30002/30000 ms
at org.eclipse.jetty.util.SharedBlockingCallback$Blocker.block(SharedBlockingCallback.java:234)
at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:133)
at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:347)
at org.springframework.util.StreamUtils.copy(StreamUtils.java:124)
at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.writeContent(ResourceHttpRequestHandler.java:407)
at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:240)
at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:51)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:800)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:186)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1125)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1059)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:497)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:248)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:620)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:540)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.concurrent.TimeoutException: Idle timeout expired: 30002/30000 ms
at org.eclipse.jetty.io.IdleTimeout.checkIdleTimeout(IdleTimeout.java:156)
at org.eclipse.jetty.io.IdleTimeout$1.run(IdleTimeout.java:50)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
... 1 common frames omitted
2015-03-28 17:17:33.856 WARN 5109 --- [tp1590404373-40] org.eclipse.jetty.server.HttpChannel : Could not send response error 500: java.io.IOException: java.util.concurrent.TimeoutException: Idle timeout expired: 30002/30000 ms
I am using Callable for asynchronous request for the home page, but that's about it, a call to the root context "/" is returned with home page without any other operations which has amongst other things this embedded video.
#Controller
public class HomeController {
#Resource
private Environment environment;
#RequestMapping(method = RequestMethod.GET, value = "/")
public Callable<String> home() {
return new Callable<String>() {
#Override
public String call() throws Exception {
return "home-new";
}
};
}
Do I have to implement a RTSP or RTMP for this? Or Am I missing configuration or annotation that could take care of, making timeout 0 for all URLs under path /videos/ ?
In production I will be using Cloudfront to serve this video, so is it more of a problem for my local setup?