httparty cant find timeout value in request , how to see all request information sent - httparty

Hello I making an api call and set timeout, I want to check request info and when I look response.request.last_uri I don't see timeout value , how timeout is sent how I can see it ?

Related

Jaxrs ability to set a global timeout (connect + read)

In Jaxrs (WebClient for instance) we can set a connect timeout and a read timeout.
ClientConfiguration c = WebClient.getConfig(client);
HTTPConduit http = c.getHttpConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(timeout);
httpClientPolicy.setReceiveTimeout(timeout);
httpClientPolicy.setAllowChunking(false);
http.setClient(httpClientPolicy);
I would like to set a timeout that includes both, I don't really care how much time is spent in connecting or in receiving, my requirement is to get a response in X seconds or just discard the search.
There is no way with CXF to set a maximum timeout for a request that consider both connection and receive durations. The maximum timeout for a request will be:
maximum_timeout = connection_timeout + receive_timeout
See this similar question for Apache HTTP client. The workaround could be to set a timer in a separate Thread to abort the connection when the desired maximum timeout expires

Camel RabbitMQ creates a generated queue in addition to the routing the msg to the queue

I have an exchange setup amq.topic and in there I have a routing key that is pointing to my key.
I have a route defined with a rest endpoint. I make a call to that endpoint with a body as json {"sample" : "sample"}.
rest("myendpoint")
.post()
.route()
.routeId(ROUTE_ID)
.log(ROUTE_ID + " started.")
.convertBodyTo(String.class)
.log("Receiving request with body=${body}")
.to("rabbitmq://rabbiturl:port/amq.topic?connectionFactory=rabbitmqConnectionFactory&autoDelete=false&routingKey=myroutingkey&declare=false&exchangeType=topic")
.log(ROUTE_ID + " ended.")
.end();
This accomplishes what I want to: the body of my rest call will be sent to the topic exchange of which will go to my queue based on the routing key.
The problem: It also create an auto-generated queue
[ qtp86171426-28] RabbitMQProducer INFO Starting reply manager service RabbitMQReplyManagerTimeoutChecker[amq.topic]
[ qtp86171426-28] ReplyManagerSupport INFO Using temporary queue name: amq.gen-JGF0CKioQ6_MLA9uBNIOOQ
[ qtp86171426-28] CorrelationTimeoutMap INFO in putIfAbsent with key Camel-ID-L-VC-10050-58983-1467158153454-0-3
[nagerTimeoutChecker[amq.topic]] TemporaryQueueReplyHandler INFO in onTimeout with correlationId= Camel-ID-L-VC-10050-58983-1467158153454-0-3
[nagerTimeoutChecker[amq.topic]] ReplyManagerSupport WARN Timeout occurred after 20000 millis waiting for reply message with correlationID [Camel-ID-L-VC-10050-58983-1467158153454-0-3] on destination amq.gen-JGF0CKioQ6_MLA9uBNIOOQ. Setting ExchangeTimedOutException on (MessageId: ID-L-VC-10050-58983-1467158153454-0-2 on ExchangeId: ID-L-VC-10050-58983-1467158153454-0-1) and continue routing.
I have tried skipqueuedeclare & skipexchangedeclare and am running out of ideas of why it is generating the queue. Does anyone have any ideas?
Set ExchangePattern to InOnly.
The temporary and reply queue is because the route expects a reply back so creates the temporary queue to wait for a response.
So if your rest endpoint does not return anything set the ExchangePattern to Inonly at the rest call and it should be ok. Alternatively set it at .to().

mod_perl error returning 202 Apache2::Const::HTTP_ACCEPTED

I am trying to build a simple asynchronous web service with Apache and mod_perl. But every time I try to return HTTP status 202 (Accepted), I get an error.
Below a very simple example (non-asynchronous):
package MyHandler;
use Apache2::Const '-compile' => qw 'OK HTTP_ACCEPTED HTTP_OK';
use Apache2::RequestRec;
use CGI;
sub handler {
my $r = shift;
print "Hallo";
$r->content_type('text/plain');
$r->status(Apache2::Const::HTTP_ACCEPTED);
return Apache2::Const::HTTP_ACCEPTED;
}
1;
I get the error
calling the handler in my browser on localhost, I get the output but also an error:
Hallo
Accepted
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, [no address given] and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
I also get an error with Apache2::Const::HTTP_OK, the only one that works without error is Apache2::Const::OK.
My apache error log makes no mention of this error.
With mod_perl2 you do not return HTTP status codes (this is why it is necessary to use $r->status() so set the HTTP status code.
Instead, you return a value depending on what you want the server to do. The most common would be Apache2::Const::OK. This tells the server your handler has finished successfully. This constant, if I recall correctly, has an integer value of 0, not 200.
Returning an HTTP status code from a mod_perl handler will be interpreted as an error.
https://perl.apache.org/docs/2.0/user/handlers/intro.html#Handler_Return_Values
Different handler groups are supposed to return different values.
Make sure that you always explicitly return a wanted value and don't rely on the result of last expression to be used as the return value -- things will change in the future and you won't know why things aren't working anymore.
The only value that can be returned by all handlers is Apache2::Const::OK, which tells Apache that the handler has successfully finished its execution.
Apache2::Const::DECLINED is another return value that indicates success, but it's only relevant for phases of type RUN_FIRST.
HTTP handlers may also return Apache2::Const::DONE which tells Apache to stop the normal HTTP request cycle and fast forward to the PerlLogHandler, followed by PerlCleanupHandler. HTTP handlers may return any HTTP status, which similarly to Apache2::Const::DONE will cause an abort of the request cycle, by also will be interpreted as an error. Therefore you don't want to return Apache2::Const::HTTP_OK from your HTTP response handler, but Apache2::Const::OK and Apache will send the 200 OK status by itself.
Try NOT printing anything BEFORE you set your content-type header.

Read Timed Out : sychronous query via Bigquery java API

We are using the big query JAVA API to retrieve results for our analytics reporting frontend. We are trying to retrieve the results synchronously. A lot of times we get Read timed out error, even before the query timeout as specified in the parameters. Here's the stack trace for a sample fail:
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at com.sun.net.ssl.internal.ssl.InputRecord.readFully(InputRecord.java:293)
at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:331)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:830)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:787)
at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:697)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:640)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1195)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:379)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:318)
at com.google.api.client.http.javanet.NetHttpResponse.<init>(NetHttpResponse.java:36)
at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:94)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:965)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
I am not able to retrieve the job id of the resulting job as the error occurs before I can retrieve a JobReference object. The timeout specified in this case was 300 sec. The query failed well before it. The query contains three JOIN's and several GROUP EACH BY clauses. Can you suggest us a possible way to debug this ?
Adding the code snippet:
QueryRequest queryInfo = new QueryRequest().setQuery(sql)
.setTimeoutMs(timeOutInSec * 1000);
// get project id
BQGameConnectionDetails details = Config
.getBQConnectionDetails(gameId);
String projectId = details.getProjectId();
Bigquery.Jobs.Query queryRequest = getInstance(gameId).jobs()
.query(projectId, queryInfo);
QueryResponse response = queryRequest.execute();
There are two timeouts involved. The first timeout is in the HTTP request you've sent to bigquery. The second is in the bigquery request timeout. It sounds like you've set the latter to a large value, but the former is likely the timeout that you're hitting. If the HTTP request times out before the BigQuery timeout, the connection will be closed and BigQuery won't have a chance to respond.
There are two options: First is to increase the HTTP request timeout (which depends on the libraries you're using, but this page here may be helpful). The second is to decrease the bigquery timeout. This means you'll have to use jobs.getQueryResults() to read the actual results, but this is a more robust method because it doesn't matter how long the query takes, you can just call getQueryResults() in a loop. I would post a link to a good java sample that does this, but I don't know that one exists, unfortunately.

unable to receive and process snmp packets having RequestID 0

I have a snmp enabled device whose monitoring i want to do.
But this device gives response with Request-ID 0 for all the get request. snmp4j library
discards these received packets because it sends get request with some Request-ID value other than 0. On receiving the response it matches the sent "Request-ID" value with the received "Request-ID" value and on finding mismatch it just discards the received packet and returns "null" value to response.
If I set the Request-ID to 0 in snmp packet before sending get request then response snmp packet can be processed.
For this snmp4j library contains the "setRequestID(Integer32 (value))" function to set the desired Request-ID of any snmp packet, but this function cannot set the Request-ID value to 0. When I set the value to 0, this function replaces this value to some random Request-ID value.
If any one having solution then please give response.
Thank you.
The request-id field is used to identify the response when it arrives back to the client. So, if the device you are querying at is returning all requests with a request-id value of 0 instead of the supplied value, then the client (snmp4j) is correctly discarding the response because it is invalid. The request-id in the response packet must always match the request-id in the original request. The device has a buggy SNMP stack. If you change your code to force the requests to always have a request-id of 0 you are breaking functionality to enable compatibility with a non-standard agent and I would advise against it.