Is it possible to alter the HTTP client timeout period (cpp-netlib)? - c++

I'm using cpp-netlib (v0.11.0) to send HTTP requests.
I'd like to know if it's possible to alter the timeout period when sending an HTTP POST request.
I'm running some unit tests, one of which sends an HTTP request to an address where there is no server running. An attempt to pull information from the response times-out after about 90s with the error "Operation timed out".

When the constructor for the client class is invoked, you can pass an options class that you can set the timeout in. See the docs for the client class constructors (and then scroll down a bit) for more specific information.

Related

How to force HTTP2 client to reconnect to server?

It is needed to make a HTTP2-response, which will force a client to reconnect to the same server to the same address.
In case of HTTP/1.1 it could be done sending 307 Temporary Redirect response with Connection: close header.
In HTTP/2 Connection: close header is ignored and redirect is performed without reconnection, which brings to redirect loop error.
Also, I've tried to send 421 Misdirected Request response to client with the same url, but Chrome browser is do nothing after receiving this response.
What is the most proper way to force a HTTP/2 client to reconnect? Which server response can be send? Maybe some kind of GOAWAY frame?
Following the graceful shutdown procedure that RFC 7540 recommends should result in a reconnection:
A server that is attempting to gracefully shut down a connection
SHOULD send an initial GOAWAY frame with the last stream identifier
set to 2^31-1 and a NO_ERROR code. This signals to the client that
a shutdown is imminent and that initiating further requests is
prohibited. After allowing time for any in-flight stream creation
(at least one round-trip time), the server can send another GOAWAY
frame with an updated last stream identifier. This ensures that a
connection can be cleanly shut down without losing requests.
Regarding 421 handling in Chrome, this bug https://bugs.chromium.org/p/chromium/issues/detail?id=546991 was opened to have Chrome re-open a new connection to the server, it's seen some activity recently.
Yes, the way on HTTP/2 to ask a client to reconnect for further requests is to send a GOAWAY frame to it. How this works depends on your server side implementation or framework for HTTP/2 support. E.g. a framework could intercept your Connection: close header and treat it as a request to close the connection after the request. But I guess most HTTP/2 implementations wouldn't like to do that, since they guess the header targets only the current request scope and not the whole connection. Alternatively the framework could provide a way in the request handler to not only access the request and response data but also to get a reference to the HTTP/2 connection, which can be used to send the GOAWAY.
This may help you Google HTTP2

Asynchronous Web Service & Web Service without response?

The concept of Asynchronous Web Service is a web service where the client does not have to wait to receive a response from the server. in AJAX this is implemented by having a callback function to process the response. So the server indeed still sends the response to the client.
Is it possible to have an Asynchronous Web Service without response? Is there any platform that provide this?
Thank you.
I have done asynch web services in the past. They are very useful. YOu do not need a detailed response but you at least need an HTTP response, like 200 OK. If the client that makes the request provides some sort of ID or key for that request, then the client can use the same ID/key to later on query for the result/response of the request.
As far as frameworks that provide this, I do not know of any. In the past I would just have a shared memory store, like Memcache, to store the state and result of the request. As long as the state is shared across all nodes, any node can then process the call back request.
EDIT: Providing a key in the request can be done in either REST or SOAP environment. HTTP provides multiple places where a key can be communicated.
GET query param (REST)
HTTP header (SOAP/REST)
Added to the message body of a POST request. This can be done through two ways.
param in the message body (REST)
variable or attribute in serialized object (SOAP/REST))

Blackberry Httpconnection Request Timeout issue

I am facing issue related to Httpconnection request timeout (not response timeout).
When i am trying to connect with the server via application i am getting response code 408 or 502 but the same url is working on the blackberry default browser (plz not that this happen only in the 3G network).
And this issue not reprodusing each and every time but it occurs 70 % times.
From Wikipedia http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
408 Request Timeout
The server timed out waiting for the request.[2] According to W3 HTTP specifications: "The client did not produce a request within the time that the server was prepared to wait. The client MAY repeat the request without modifications at any later time."
502 Bad Gateway
The server was acting as a gateway or proxy and received an invalid response from the upstream server.
So I am guessing some sort of proxy/gateway needs to be set in your application (as may be set in your default BB browser).
Cheers!

What is WS-Addressing good for?

I am just getting started with SOAP web services and stumbled across WS-Addressing.
I have read the Wikipedia page, but I'm having a hard time understanding just what the point of WS-Addressing is.
According to Wikipedia and various sources on the web, WS-Addressing allows to put "addressing information" or "routing information" into the header of a SOAP request.
Why is this useful? If I send a request via HTTP (or even via SMTP or UDP), then the address I send to is the address of the server which will process my request, and the server can simply reply by the same channel. So why is addressing/routing information needed?
I'd be particularly interested in some real-world (more or less) example where WS-Addressing is helpful.
I've found WS-Addressing particularly useful in situations where the SOAP response can't be served immediately. Either the resources to form the response are not available right away or the result itself takes a long time to be generated.
That can happen when your business process involves "a human touch" for example (processes like the ones WS-HumanTask is targeting). You can stick web services in front of your business, but sometimes business takes time. It might be a subscription that must be manually verified, something to be approved, whatever, but it takes days to do it. Are you going to keep the connection opened all that time? Are you going to do nothing else than wait for the response? No! That is inefficient.
What you need is a notification process. The client makes a requests but does not wait for the response. It instead instructs the server where to send the response by use of a "reply to" address. Once the response is available, the server connects to that address and sends the response.
And voila... asynchronous interactions between web services, decoupling the lifetime of the communication process from the lifetime of the HTTP connection. Very useful...
But wait... HTTP connection? Why should I care about that? What if I want the response sent back on another type of protocol? (which SOAP kindly provides as it is not tied to any protocol).
With normal request/response flow, the response comes on the same channel as the request 'cose it's a connection you know.... So for example you have a HTTP connection... that means HTTP in and HTTP out.
But with WS-Addressing you are not tied to that. You can demand the response on another type of channel. Request comes on HTTP for example, but you can instruct the server to send the response back over SMTP, for example.
In this way WS-Addressing defines standard ways
to route a message over multiple transports. As the wiki page is saying:
instead of relying on network-level transport to convey routing information,
a message utilizing WS-Addressing may contain its own dispatch metadata in a standardized SOAP header.
and as for your observation:
and the server can simply reply by the same channel
... what works for some, might not work for others, and for others we have WS-Addressing :D.

How to create a web wervice in java/Axis2 which should keep publishing data

I am a new to Axis2 and SOAP. I recently working on a Axis2 SOAP project, I have create a SOAP server and SOAP client by using java and axis2 implementing session scope. The problem is when I send a request, it returns response back only once. I am unable to make web service keep publishing data periodically untill the session end. Can any body help me...
Thanks in advance
I might be wrong, but I think since you work with HTTP you can't make the
response permanent until you make your client perform calls permanently / periodically.
Permanent Requests --> Permanent Responses
I echo KB22's response - HTTP has a request-response flow, so your service is receiving a single request and sending back a single response. Implementing session scope means that you have a logical session for multiple request/responses to be tied together. You have a few options here:
Make the client wait until you have all the data to send back in one response. However, if this takes too long you may well get timeout issues on the client.
Change your model, so that you send in multiple requests and get back the data in pieces.
Change your model to a polling style, where you keep sending requests (and receive empty responses) until all the data is ready to be sent back.
Change your protocol to something that is asynchronous (e.g. JMS) so that you send in a request to a queue and at some later time the response turns up on the queue for your client to read.