RestClient client = (RestClient) ClientFactory.getNamedClient(RSSConstants.MIDDLETIER_REST_CLIENT);
HttpClientRequest request = HttpClientRequest.newBuilder()
.setVerb(this.restAction)
.setUri(new URI("/"
+ RSSConstants.MIDDLETIER_WEB_RESOURCE_ROOT_PATH
+ this.resourcePath)
)
.setHeaders(headers)
.setEntity(<JSON String>)
.build();
HttpClientResponse response = client.executeWithLoadBalancer(request);
return IOUtils.toString(response.getRawEntity(), Charsets.UTF_8);
Thanks for the speedy reply Ben!
I don't think my code did anything with threads. I simply modified the sample recipes-rss app from netflixOSS to try to issue a post request that has a request body eg json (the example only had query params but no body). Is there a simple way to do that, say using httpclientrequest.newbuilder.setentity(xyz) to do that?
Thanks!
It sounds like your issue is that your code is expecting certain ThreadLocal state, but the run() method is executed on a different thread without that ThreadLocal state.You will need to implement a ConcurrencyStrategy (https://github.com/Netflix/Hystrix/wiki/Plugins#concurrency-strategy) to copy state from the JBoss thread to the Hystrix thread if you're doing anything that relies on ThreadLocal (generally not a pleasant programming model).
--
You received this message because you are subscribed to a topic in the Google Groups "HystrixOSS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/hystrixoss/k-bmcSLAoTs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to hystrixoss+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "HystrixOSS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hystrixoss+...@googlegroups.com.
ERROR 14:41:38,452 Error executing HystrixCommand
java.lang.RuntimeException: Exception
at com.netflix.recipes.rss.hystrix.UserActionsCommand.run(UserActionsCommand.java:143)
at com.netflix.recipes.rss.hystrix.UserActionsCommand.run(UserActionsCommand.java:50)
at com.netflix.hystrix.HystrixCommand.executeCommand(HystrixCommand.java:764)
at com.netflix.hystrix.HystrixCommand.access$1400(HystrixCommand.java:81)
at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:706)
at com.netflix.hystrix.strategy.concurrency.HystrixContextCallable.call(HystrixContextCallable.java:45)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:695)
Caused by: com.netflix.client.ClientException: Unable to execute RestClient request for URI:http://harry.li-ltm:9191/middletier/users
at com.netflix.client.AbstractLoadBalancerAwareClient.generateNIWSException(AbstractLoadBalancerAwareClient.java:256)
at com.netflix.client.AbstractLoadBalancerAwareClient.executeOnSingleServer(AbstractLoadBalancerAwareClient.java:203)
at com.netflix.client.AbstractLoadBalancerAwareClient.executeWithLoadBalancer(AbstractLoadBalancerAwareClient.java:402)
at com.netflix.recipes.rss.hystrix.UserActionsCommand.run(UserActionsCommand.java:139)
... 10 more
Caused by: com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java class org.apache.http.entity.StringEntity, and Java type class org.apache.http.entity.StringEntity, and MIME media type text/html was not found
at com.sun.jersey.api.client.RequestWriter$RequestEntityWriterImpl.<init>(RequestWriter.java:199)
at com.sun.jersey.api.client.RequestWriter.getRequestEntityWriter(RequestWriter.java:248)
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.getHttpEntity(ApacheHttpClient4Handler.java:241)
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.getUriHttpRequest(ApacheHttpClient4Handler.java:197)
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:153)
at com.sun.jersey.api.client.Client.handle(Client.java:648)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:680)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:568)
at com.netflix.niws.client.http.RestClient.execute(RestClient.java:501)
at com.netflix.niws.client.http.RestClient.execute(RestClient.java:418)
at com.netflix.niws.client.http.RestClient.execute(RestClient.java:78)
at com.netflix.client.AbstractLoadBalancerAwareClient.executeOnSingleServer(AbstractLoadBalancerAwareClient.java:192)
... 12 more
WARN 11:58:58,168 EXCEPTION, please implement com.netflix.recipes.rss.netty.NettyHandlerContainer.exceptionCaught() for proper handling.
java.lang.ClassCastException: org.jboss.netty.handler.codec.http.HttpChunk$1 cannot be cast to org.jboss.netty.handler.codec.http.HttpRequest
at com.netflix.recipes.rss.netty.NettyHandlerContainer.messageReceived(NettyHandlerContainer.java:96)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296)
at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:459)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.callDecode(ReplayingDecoder.java:536)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.messageReceived(ReplayingDecoder.java:435)
at org.jboss.netty.handler.execution.ChannelUpstreamEventRunnable.doRun(ChannelUpstreamEventRunnable.java:43)
at org.jboss.netty.handler.execution.ChannelEventRunnable.run(ChannelEventRunnable.java:67)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:695)
This is exactly what I was looking for!! Thanks!! I wish I knew of this repo earlier, could've saved me days and days haha.